From 89a51cfd5be1fbdd8ab7ffbea770c5b787ec067c Mon Sep 17 00:00:00 2001 From: suzmii Date: Sun, 27 Sep 2026 23:01:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20hook=20=E9=9A=94=E7=A6=BB?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=8A=8A=E6=8E=A2=E9=92=88=E8=87=AA=E8=BA=AB?= =?UTF-8?q?=E7=9A=84=E7=B4=A2=E5=BC=95=E5=86=99=E5=85=A5=E5=BD=93=E6=88=90?= =?UTF-8?q?=E8=A2=AB=E6=B5=8B=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - git-hooks.test.mjs 的隔离用例改为先跑会写索引的探针(git status 会刷新并重写索引的 stat 缓存),再取索引快照,避免把自身副作用断言成 hook fixture 的污染 - 该用例在 macOS 与部分 git 版本上必然失败(干净 origin/master worktree 上同样复现),修后 scripts/git-hooks.test.mjs 4/4 通过、npm run check:repository-ci 全绿 --- scripts/git-hooks.test.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/git-hooks.test.mjs b/scripts/git-hooks.test.mjs index fded755c8..b1a78ef16 100644 --- a/scripts/git-hooks.test.mjs +++ b/scripts/git-hooks.test.mjs @@ -277,11 +277,13 @@ test('hook fixtures do not mutate the calling linked worktree or its index', () writeFileSync(join(worktree, 'sentinel.txt'), 'unstaged\n'); const gitDir = git(worktree, 'rev-parse', '--absolute-git-dir').trim(); const indexPath = join(gitDir, 'index'); + // `git status` 会刷新并重写索引里的 stat 缓存(macOS 与部分 git 版本上字节必然变化), + // 所以先跑完会写索引的探针再取快照,否则断言的是探针自身的副作用而不是被测行为。 const before = { refs: git(outerRepo, 'show-ref'), config: readFileSync(join(outerRepo, '.git', 'config'), 'utf8'), - index: readFileSync(indexPath), status: git(worktree, 'status', '--porcelain'), + index: readFileSync(indexPath), }; const result = spawnSync( process.execPath,