修复 hook 隔离用例把探针自身写入当成被测行为 #523

Merged
suzmii merged 2 commits from fix/git-hooks-index-snapshot into master 2026-09-28 12:03:55 +08:00
Member

问题

npm run check:repository-ci 在 scripts/git-hooks.test.mjs:246「hook fixtures do not mutate the calling linked worktree or its index」稳定失败;在干净的 origin/master 独立 worktree 上同样复现,属既有问题。

根因

用例在调用 git status --porcelain 之前读取索引做快照,而 git status 会刷新并重写索引里的 stat 缓存(macOS 与部分 git 版本上字节必然变化),于是断言到的是探针自身的副作用,而不是 hook fixture 的污染。

修复

  • 先跑完会写索引的探针,再取索引快照;被测行为(fixture 是否污染调用方)的断言不变。
  • 验证:node --test scripts/git-hooks.test.mjs 4/4 通过;bash scripts/check-repository-ci.sh origin/master 退出码 0(此前同一条用例必失败)。
## 问题 `npm run check:repository-ci` 在 `scripts/git-hooks.test.mjs:246`「hook fixtures do not mutate the calling linked worktree or its index」稳定失败;在干净的 `origin/master` 独立 worktree 上同样复现,属既有问题。 ## 根因 用例在调用 `git status --porcelain` **之前**读取索引做快照,而 `git status` 会刷新并重写索引里的 stat 缓存(macOS 与部分 git 版本上字节必然变化),于是断言到的是探针自身的副作用,而不是 hook fixture 的污染。 ## 修复 - 先跑完会写索引的探针,再取索引快照;被测行为(fixture 是否污染调用方)的断言不变。 - 验证:`node --test scripts/git-hooks.test.mjs` 4/4 通过;`bash scripts/check-repository-ci.sh origin/master` 退出码 0(此前同一条用例必失败)。
suzmii added 1 commit 2026-09-27 23:01:47 +08:00
修复 hook 隔离用例把探针自身的索引写入当成被测行为
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m9s
Project CI / Backend tests (pull_request) Failing after 14s
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m7s
Project CI / Frontend tests (pull_request) Successful in 2m0s
Project CI / Repository checks (pull_request) Failing after 15s
Project CI / AI game creator shell web tests (pull_request) Successful in 1m41s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 9m40s
Project CI / Native shell tests (pull_request) Successful in 5m26s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 8m45s
89a51cfd5b
- 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 全绿
suzmii added 1 commit 2026-09-28 11:45:11 +08:00
Merge branch 'master' into fix/git-hooks-index-snapshot
Project CI / AI game creator shell Rust crates (pull_request) Successful in 1m3s
Project CI / AI game creator shell Rust smoke (pull_request) Successful in 1m30s
Project CI / Backend tests (pull_request) Successful in 3m58s
Project CI / Frontend tests (pull_request) Successful in 2m4s
Project CI / Native shell tests (pull_request) Successful in 6m2s
Project CI / AI game creator shell Rust lane 1/2 (pull_request) Successful in 8m29s
Project CI / AI game creator shell Rust lane 2/2 (pull_request) Successful in 8m23s
Project CI / AI game creator shell web tests (pull_request) Successful in 1m57s
Project CI / Repository checks (pull_request) Successful in 2m35s
053c57974e
suzmii merged commit 8f59c034f5 into master 2026-09-28 12:03:55 +08:00
suzmii deleted branch fix/git-hooks-index-snapshot 2026-09-28 12:03:55 +08:00
Sign in to join this conversation.