fix(git): 行数封顶后不再累加输出 + 用注入式子进程确定性钉住两道上限

CI 在 ubuntu 上抓到 new 用例红:`stops producing once the NUL field cap is reached`
断言 2500 < 2500 不成立。查下来是**产品语义与断言不符**,不只是测试问题:

- `runGit` 在 `fieldCapped` 置位并 kill 子进程之后,仍然继续把后续 chunk 累加进
  `stdout`。子进程早已把整份输出写进管道时(125 KB 的 status 在 CI 上就是如此),
  被「封顶」的调用会原样返回全部 2500 行——「封顶」只约束了 kill,没有约束调用方
  拿到的东西。现在置位后忽略后续 chunk,保留量真正有界(封顶值 + 至多一个跨越
  封顶的 chunk)。
- 真 git 那条用例的 `toBeLessThan` 本质是竞态(kill 与子进程写完谁先到),把文件名
  加长到「一个 64 KiB chunk 至多携带约 500 个字段」让上界成立,并在注释里写明这条
  推理;**kill 本身**改由 `tests/git-spawn.spec.ts` 的注入式子进程确定性钉住
  (跨过封顶的 chunk + 封顶之后才到达的尾巴 + kill 恰好一次),另补字节上限的
  rejects 用例。撤掉产品守卫该用例当场红(kill 被调两次且尾巴进了结果)。

本地门禁:typecheck / lint 干净,全量 210 文件 / 2524 通过。
This commit is contained in:
Menghuan1918 committed 2026-10-16 00:28:41 +08:00
1 parent da0d294948
commit a628bdd1e9
3 files changed
+77 -3

No files matched your search

+7
View File
@@ -305,6 +305,13 @@ export function runGit(cwd: string, args: string[], timeoutMs = 30_000, options:
reject(new GitCommandError(`git ${args[0] ?? ''} timed out after ${timeoutMs}ms`, 'git-error', args.join(' ')))
}, timeoutMs)
child.stdout.on('data', (chunk: Buffer) => {
// The caller's row cap already decided the answer: ignore everything
// that arrives afterwards. Without this guard the retained output kept
// growing by whatever the killed child had already buffered into the
// pipe, so "capped" was only a claim about the kill and not a bound on
// what the caller receives (CI: a 125 KB answer plus a fast child made
// the capped call return all 2,500 rows).
if (fieldCapped) return
stdout += chunk.toString('utf8')
outBytes += chunk.length
if (outBytes > maxBytes) {