Skip to content

test: run layered QA subprocess tests after the in-process ones - #5251

Merged
RealKai42 merged 1 commit into
mainfrom
test/layered-qa-split
Nov 23, 2026
Merged

RealKai42 merged 1 commit into
mainfrom
test/layered-qa-split

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Layered QA 的 Windows 任务(contracts (windows-2025))会偶发超时,和 PR 本身改了什么无关。#5202 的那次运行里有两处超时:parity 的第一条用例超过 30 秒,conversation-events 的 beforeAll 超过 10 秒。这个 PR 之后,这两处不会再因为同一批里起子进程的测试而超时。

Bug Reproduction Steps

parity 的 30 秒超时在本机复现不了:10 核机器上开 30 个空转进程,pnpm qa:layers 跑了 6 遍全部通过,parity 第一条最长 6.2 秒。依据来自 CI 日志,见下一节。

conversation-events 的钩子超时可以直接复现:

cd packages/app-client
pnpm exec vitest run test/conversation-events.test.ts --hookTimeout=1

改前在第 62 行报 Hook timed out in 1ms,19 条全部跳过,和 CI 上失败时的样子一样;改后 19 条全部通过。

Root Cause

parity 被起子进程的测试挤占。 qa:layers 原来一次并行跑 7 个文件。其中 server-restart 和 cold-recovery 各起两个 KAP 子进程,子进程用 tsx 从 TS 源码现场编译整个 CLI(testkit 默认 TESTKIT_CLI_BUILD=source),是这个任务里最吃 CPU 的部分。我按时间戳统计了 Layered QA 至今 39 次运行的 Windows 日志:

Windows 运行 parity 第一条 和 cold-recovery 重叠 全程 transform
parity 第一条通过的 35 次 1.3–5.7 秒 0 秒 27–55 秒
#5202 失败的那次 41.7 秒(30 秒超时) 32 秒 107.5 秒

失败那台机器整体慢了一倍,transform 是其他运行最慢那次的 2 倍。parity 第一条在 cold-recovery 开始前已经跑了约 10 秒还没结束;cold-recovery 开始起子进程后,又被拖了 20 多秒,最终超时。其余运行里,这条用例和 cold-recovery 都没有重叠,macOS 和 Ubuntu 的 74 次也一样。

conversation-events 的冷编译受钩子预算约束。 #5138 为了把冷编译挪出第一条用例的 5 秒预算,加了 beforeAll(compileClientModules),但这个钩子受 vitest 默认 10 秒的钩子预算约束。编译耗时取决于机器速度,以及同时有多少文件在编译。Windows 上整个文件正常要 4–9 秒;失败那次钩子超过了 10 秒,当时正好是 server-restart 起第一个子进程的时候。

之前的「vi.fn() 被调用 3 次」是同类超时引起的连锁失败,出现在 #5138 之前的版本里。第一条用例在冷编译时超时,vitest 只是不再等它,用例函数本身还在跑。编译完后它接着调用 sendPrompt,而客户端每次都经全局的 deps 取 API,这时取到的是第三条用例的 mock,第三条就多出一次调用。我用临时副本恢复旧写法、把第一条的超时设为 300 毫秒,本机 3 次都复现了同样的报错和行号。只要第一处超时不再发生,这个问题就不会出现,所以这里不改。

这是根本修复:进程内的用例不再和起子进程的用例同时运行,冷编译也不再受任何钩子或用例预算约束。没有调高任何超时,也没有加重试。

另有一类 Windows 失败不在这个 PR 范围内:vitest 报 Worker exited unexpectedly,正在运行的进程内 KAP 测试文件中途消失(两次是 scenarios/replay.test.ts,一次是 kap-parity.test.ts),其中一次是 main 上 11 月 22 日的夜间运行。它的触发条件是服务端关闭后文件监听还没关、测试就删了目录,在 #5250 里单独修。

Code Changes

 pnpm qa:layers
-  vitest run  7 个文件一起并行
+  pnpm run qa:layers:in-process      scenarios/replay、app-core/replay、apiSurface、kap-parity、conversation-events
+  && pnpm run qa:layers:subprocess   app-core/reconnect(server-restart)、scenarios/cold-recovery

两段用 && 连接,和 test:smoke 的写法一致。第二段的两个文件之间仍然并行,它们各自的预算(120 秒、90 秒)本来就是按起子进程定的。

-beforeAll(compileClientModules);
+await compileClientModules();

客户端模块改为在文件加载时编译,耗时计入 vitest 的导入阶段。导入阶段不设超时,和其他测试文件的静态导入一样。之后每条用例在 vi.resetModules() 后重新导入,用的仍是已编译的结果,所以第一条用例照旧不承担冷编译。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
pnpm qa:layers 的执行方式 7 个文件一次并行 先并行跑 5 个进程内的文件,再并行跑 2 个起子进程的文件 Layered QA 工作流(三个系统)和在本地运行它的开发者 两段各有脚本,可以单独运行
第一段失败时 7 个文件都跑完再汇报 这次不再跑第二段 看 Layered QA 结果的人 单独运行 pnpm qa:layers:subprocess
pnpm qa:layers 的总时长(缓存已热) 本机约 12 秒 本机约 18–19 秒 同上 无
conversation-events 的客户端模块编译 在 beforeAll 里,受 10 秒钩子预算约束 在文件加载时编译,不受超时约束 无 无

没有改产品代码、测试断言、超时数值、CI 工作流和契约文件。用例总数不变:第一段 31 条,第二段 3 条,共 34 条。这个 PR 只改测试和根目录脚本,不需要 changeset。

验证

本机(macOS):

  • pnpm qa:layers:两段依次运行,31 + 3 条全部通过。
  • 加负载:10 核机器上开 30 个空转进程,两段各跑 6 遍。第一段 6 遍全部通过,parity 第一条 1.4–3.4 秒;拆分前在同样的负载下是 1.4–6.2 秒。第二段前 5 遍通过;第 6 遍时本机另有一组 vitest 在跑,负载均值约 56,cold-recovery 的 KAP 子进程没能在 30 秒内打出就绪行。第二段的用例和预算这个 PR 都没有改。
  • 上面的 --hookTimeout=1 对照:改前失败,改后通过。
  • pnpm lint:guards 这一步在这个检出目录里失败。oxlint 1.94.0 用 --print-config 打印出的 jsPlugins 顺序随检出目录变化,在这个目录里和基线相反,和本 PR 无关;main 上的 CI 是通过的,修复见 #5249。其余各步单独运行都通过。

Windows:本机没法运行,以这个 PR 上 Layered QA 的结果为准。这类超时在 39 次 Windows 运行里只出现过 1 次,一次全绿说明不了多少;可靠的依据是日志里第二段在第一段结束之后才开始。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

On a slow Windows runner the in-process contract tests timed out while
the two tests that start KAP child processes were transpiling the CLI
from source in parallel with them. Run qa:layers in two phases: the
five in-process files first, then server-restart and cold-recovery.

Also compile the client modules of conversation-events when the file
loads instead of in a beforeAll hook, so the cold compile no longer
runs under the 10 s hook budget.
@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a50b991

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T04:45:25.189027Z a50b991 PR opened
🔒 Security Review ✅ Completed 2026-11-23T04:45:54.540198Z a50b991 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 23, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@a50b991
npx https://pkg.pr.new/@moonshot-ai/kimi-code@a50b991

commit: a50b991

@RealKai42
RealKai42 merged commit c106716 into main Nov 23, 2026
29 checks passed
@RealKai42
RealKai42 deleted the test/layered-qa-split branch November 23, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant