fix(plugin-audit): stop charging a cold module load to one test's timeout (#4186) - #4193
Merged
Merged
Conversation
…eout (#4186) audit-writers.test.ts resolved @objectstack/core and its translation bundle with `await import(...)` inside the first localized test's helper, so that single test paid the whole cold-start cost — resolution plus vite transform of a large barrel — while every later case ran warmed in ~1ms. That is real work billed to a per-test timeout budget. The file already carried a { timeout: 20_000 } override for exactly this reason (its comment measured the cold start at ~5s on a 4-vCPU runner). Under a full-repo `pnpm test`, where a dozen packages' vitest workers compete, the cold start grew past that bound too and the case failed at 20s — reproducibly under load, never in isolation, which is the worst shape a red test can have: it tracks machine load rather than code. Both imports are now static, so the same work happens during collection, which no single test's timeout is charged for. The previously failing case runs in 1ms and the timeout override is gone — the default timeout is an honest bound again, and a case that exceeds it is a real hang. No cycle motivated the lazy form: plugin-audit depends on @objectstack/core normally, and this package's own audit-plugin.ts already imports it statically. Closes #4186 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014DQuJBNpwStpJvo3owBw2B
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
📓 Docs Drift CheckNo hand-written docs reference the 0 changed package(s). ✅ |
os-zhuang
marked this pull request as ready for review
July 30, 2026 15:04
This was referenced Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4186。
问题
audit-writers.test.ts的makeI18n()里用await import(...)取@objectstack/core和翻译包,于是全文件第一个调用它的用例独自承担了整个冷启动代价(解析 + 一个大 barrel 的 vite transform),而其后调用同一 helper 的用例都是热的、约 1ms。这是把真实工作量记在单个用例的超时预算上。在全仓
pnpm test(十几个包的 vitest worker 互相抢 CPU)下,该用例耗时 20094ms 撞上超时,在负载下可复现、单独跑必过——这是红灯最糟糕的一种形态:它反映的是机器负载,不是代码。这不是第一次
文件里原本就有一段注释和一个
{ timeout: 20_000 }覆盖,写明:也就是说当年已经诊断对了,处置是放宽超时。现在冷启动在更高并行度下涨过了 20s,这个 band-aid 被撑破。再放宽一次只会重复同一循环,所以这次拔根因。
改动
两个 import 提为顶层静态;删掉 timeout 覆盖;
makeI18n随之变为同步函数,5 处调用点去掉await。顶层留了注释说明为何必须保持静态,防止后人改回懒加载。为什么静态是安全的(动手前查过,动机不是规避循环依赖):
plugin-audit的package.json里正常依赖@objectstack/core;core 不反向依赖 plugin-audit;且本包自己的生产源码audit-plugin.ts本来就静态 import 它。验证
改后单跑该文件(
--reporter=verbose):机制吻合诊断:冷启动成本原封不动地转移到了 collection 阶段的 import/transform,而那部分不计入任何单个用例的超时预算,所以用例本身回到 1ms。
plugin-audit全包 4 文件 / 46 用例通过。全仓pnpm test在并行压力下的复验正在跑,结果会跟评论补上。顺带扫了一遍:全仓没有第二个测试文件同时具备"timeout 覆盖 + 动态导入"这一组合,是孤例,不需要成规模整改。(测试里裸用
await import()常常是合法的模块 mock 手法,所以有意义的信号是它与放宽超时的共现,而该集合为空。)🤖 Generated with Claude Code
https://claude.ai/code/session_014DQuJBNpwStpJvo3owBw2B
Generated by Claude Code