Skip to content

fix(plugin-audit): stop charging a cold module load to one test's timeout (#4186) - #4193

Merged
os-zhuang merged 1 commit into
mainfrom
claude/plugin-ordering-convention-t9ylrz
Jul 30, 2026
Merged

fix(plugin-audit): stop charging a cold module load to one test's timeout (#4186)#4193
os-zhuang merged 1 commit into
mainfrom
claude/plugin-ordering-convention-t9ylrz

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

Closes #4186

问题

audit-writers.test.tsmakeI18n() 里用 await import(...)@objectstack/core 和翻译包,于是全文件第一个调用它的用例独自承担了整个冷启动代价(解析 + 一个大 barrel 的 vite transform),而其后调用同一 helper 的用例都是热的、约 1ms。

这是把真实工作量记在单个用例的超时预算上。在全仓 pnpm test(十几个包的 vitest worker 互相抢 CPU)下,该用例耗时 20094ms 撞上超时,在负载下可复现、单独跑必过——这是红灯最糟糕的一种形态:它反映的是机器负载,不是代码。

这不是第一次

文件里原本就有一段注释和一个 { timeout: 20_000 } 覆盖,写明:

the FIRST localized case pays the one-off cost of dynamically importing @objectstack/core + the shipped translation bundle … On a shared 4-vCPU CI runner that cold start alone was measured at ~5s … 20s bounds the cold start without masking a real hang.

也就是说当年已经诊断对了,处置是放宽超时。现在冷启动在更高并行度下涨过了 20s,这个 band-aid 被撑破。再放宽一次只会重复同一循环,所以这次拔根因。

改动

两个 import 提为顶层静态;删掉 timeout 覆盖;makeI18n 随之变为同步函数,5 处调用点去掉 await。顶层留了注释说明为何必须保持静态,防止后人改回懒加载。

为什么静态是安全的(动手前查过,动机不是规避循环依赖):plugin-auditpackage.json 里正常依赖 @objectstack/core;core 不反向依赖 plugin-audit;且本包自己的生产源码 audit-plugin.ts 本来就静态 import 它

验证

改后单跑该文件(--reporter=verbose):

✓ … localizes verb + object label to the workspace locale (zh-CN)  1ms      ← 原 20094ms(超时)
✓ … localizes the generic update fallback                          0ms
Duration 3.89s (transform 2.87s, import 3.67s, tests 23ms)

机制吻合诊断:冷启动成本原封不动地转移到了 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

…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
@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
objectstack Ignored Ignored Jul 30, 2026 2:50pm

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling size/s labels Jul 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

No hand-written docs reference the 0 changed package(s). ✅

@os-zhuang
os-zhuang marked this pull request as ready for review July 30, 2026 15:04
@os-zhuang
os-zhuang merged commit a946efd into main Jul 30, 2026
17 checks passed
@os-zhuang
os-zhuang deleted the claude/plugin-ordering-convention-t9ylrz branch July 30, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/s tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-audit 的 zh-CN 本地化用例在全仓并行下必然超时:冷 import('@objectstack/core') 撞 20s testTimeout

2 participants