Skip to content

fix(test): codex-hooks-config 在 .codex/ 不存在时自适应跳过 (closes #3 Gap 2) - #7

Merged
libz-renlab-ai merged 4 commits into
mainfrom
fix/codex-hooks-skipif
May 15, 2026
Merged

fix(test): codex-hooks-config 在 .codex/ 不存在时自适应跳过 (closes #3 Gap 2)#7
libz-renlab-ai merged 4 commits into
mainfrom
fix/codex-hooks-skipif

Conversation

@libz-renlab-ai

Copy link
Copy Markdown
Owner

fix(test): codex-hooks-config 在 .codex/ 不存在时自适应跳过 (issue #3 Gap 2)

根因

PR #4 dogfood Ubuntu CI 的 pnpm test 跑出 7 failed / 3526 passed / 49 skipped(3582 总)。7 个 fail 全在一个文件:packages/cli/src/__tests__/codex-hooks-config.test.ts,错误一致:

Error: ENOENT: no such file or directory, open '/home/runner/work/Matrix/Matrix/.codex/hooks.json'

这套测试来自上游 TeamBrain 的 issue #290(Codex CLI hook adapter contract)。Matrix baseline(2026-05-14 history-stripped fork)没把 .codex/ 目录带过来,target 文件不存在 → ENOENT。

(本地 Windows 21 个 fail 是另一波 —— install-rollback / session-start-input-shape / symphony,Ubuntu 上不复现;那 3 类是 Windows-only 问题,本 PR 不在范围。)

修复(10 行)

按 memory [Matrix is independent]:Matrix 自走、不反向 merge TeamBrain,不该把 .codex/ 拉回来。改用 vitest describe.skipIf:

+ const codexHooksExist = existsSync(hooksJsonPath);
- describe(".codex/hooks.json (issue #290)", () => {
+ describe.skipIf(!codexHooksExist)(".codex/hooks.json (issue #290)", () => {

行为:

  • Matrix(.codex/ 不存在) → 整个 describe block 跳过,7 tests skipped
  • 上游 TeamBrain(.codex/ 存在) → 测试照常激活,contract 不丢
  • 以后 Matrix 决定接 Codex hooks → 自动重新生效,无须改测试

本地验证

$ vitest run packages/cli/src/__tests__/codex-hooks-config.test.ts
Test Files: 1 skipped
      Tests: 7 skipped (7)

预期 dogfood —— 仓库第一次真全自动合

本 PR 一开,pr-review.yml 跑应该:

标准 结果
repro-pass ✅(spec.ci.skip 豁免,PR #4 修)
tests-and-merge-clean (NEW —— 0 fail)

→ verdict: pass 🎉

can-auto-merge.ts 所有门控通过(state=OPEN, base=main, !draft, !fork, !do-not-merge, !visual-proof, reviewVerdictState=success, mergeable=MERGEABLE)

auto-merge.yml 触发 gh pr merge --squash --delete-branch —— 本仓库历史首次完全自动合

关联

🤖 Generated with Claude Code

PR #4 dogfood 后跑 Ubuntu CI 的 pnpm test 报 7 个 fail,全在
packages/cli/src/__tests__/codex-hooks-config.test.ts 一个文件里,
错误一致:

  Error: ENOENT: no such file or directory, open
  '/home/runner/work/Matrix/Matrix/.codex/hooks.json'

根因:这套测试来自 TeamBrain(issue #290 Codex CLI hook adapter),
Matrix baseline(2026-05-14 history-stripped fork)没把 .codex/ 目录
带过来。target 文件不存在 → ENOENT。

按内存 [Matrix is independent]:Matrix 自走、不反向 merge TeamBrain,
不该把 .codex/ 拉回来。改用 vitest describe.skipIf:

  const codexHooksExist = existsSync(hooksJsonPath);
  describe.skipIf(!codexHooksExist)('.codex/hooks.json ...', () => { ... })

行为:
  - Matrix(.codex/ 不存在) → 整个 describe block 跳过,7 tests skipped
  - 上游 TeamBrain(.codex/ 存在) → 测试照常激活
  - 以后 Matrix 决定接 Codex hooks → 自动重新生效,无须改测试

本地验证(`vitest run` 单文件):
  Test Files: 1 skipped
        Tests: 7 skipped (7)

至此 issue #3 Gap 2 收尾。理论上下一次 pr-review.yml 跑应该:
  - repro-pass: pass(豁免,PR #4 修)
  - tests-and-merge-clean: pass(0 failed)
  → verdict: pass
  → can-auto-merge: 全部门控过 → 自动 squash merge
  这将是仓库第一次真全自动合 PR。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 15, 2026

Copy link
Copy Markdown

✅ 远程评审 verdict: pass

commit 8d292a7 · workflow run · 2026-05-15T08:54:18Z

标准 结果 简述
repro-pass 豁免 — all-specs-ci-skip: fixtures/repro-specs/hook-moment-block.ts (需 $TA_DEMO_STAGE 下 home-empty/home-loaded 两份知识库目录预置 + 录 GIF 仅 Win32 可行)
tests-and-merge-clean tests pass + tree clean

liboze2026 and others added 3 commits May 15, 2026 16:11
…init 流程产物

PR #7(Gap 2)dogfood 第一次跑暴露第二个 sub-gap:
codex-hooks-config 的 skipIf 修复让 pnpm test 真过(3526 / 56 skip
/ 0 fail),但 tests job 仍 failure。根因是后一个 step「Working tree
must be clean」检测到 untracked 文件:

  ##[error]tests 跑完后工作树不干净:
  ?? .claude/hooks/check-teamagent.sh

`teamagent init` 是 pnpm test 链路里跑的(测试产物之一)。它生成:
  - .teamagent/required.json(已被 .teamagent/ ignore)
  - .claude/hooks/check-teamagent.sh(漏了)

两个是同一 "Required 模式产物" pipeline 的输出,语义一致 → 加进
.gitignore。

至此 PR #7 应能让 tests-and-merge-clean 真翻绿,verdict=pass,
触发首次完全自动 squash-merge。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PR #7 v2 dogfood 第三个 sub-gap:tests + tree-clean 都修过后,verdict
job 在 'Post comment + set status' step 仍崩:

  Error: update comment 失败: gh: Not Found (HTTP 404)

根因(本 session PR #2 引入的 post-pr-comment.ts bug):
  - line 71: `gh pr view --json comments` 返回 GraphQL node ID(IC_kwDOI...)
  - line 81: `gh api repos/.../issues/comments/{id}` PATCH 要 REST integer id
  - 不匹配 → PATCH 404

为什么 PR #2 / #4 没炸:每个 PR 只跑过一次 verdict → 没现成评论可更新 →
只走 CREATE 路径(line 87 `gh pr comment`)→ 没暴露。PR #7 是本仓库
第一个 multi-commit PR:v1 (2798a32) 创了评论 → v2 (1aa98e3) 想更新 → 404。

修复:
  - 列评论改用 `gh api repos/.../issues/{pr}/comments` —— 返回 REST id,
    跟 PATCH 端点格式一致
  - CREATE 也改走 REST POST(对称;新评论的 id 直接是 REST 制式,下次能
    正确 UPDATE)

这是 dogfood 的核心价值 —— 第一次真有 multi-commit PR 跑流水线就揪出了
首次 ship 时遗漏的 code path bug。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PR #7 v3 dogfood 全部 review 翻绿后,auto-merge.yml workflow 真触发
(workflow_run on PR Review success),但本身崩在 setup-node 那步:

  ##[error]Unable to locate executable file: pnpm.

根因:actions/setup-node@v5 默认 package-manager-cache=true,看到
pnpm-lock.yaml 就要找 pnpm 来计算 cache 目录;auto-merge.yml 没在
setup-node 之前先 pnpm/action-setup → setup-node 找不到 pnpm 报错。

setup-repo composite action 顺序是对的(pnpm 先,node 后);auto-merge.yml
没复用 composite,自己 inline 两行,顺序错了。

修复:加 pnpm/action-setup@v5 在 setup-node@v5 之前,并显式 cache: pnpm。

至此 PR #7 应能真触发 auto-merge.yml + 真合 main。这条路径要等本 commit
进 main 之后下一个 PR 才能真测。本 PR(#7)自己的 auto-merge 还会用 main
上现有的(broken)auto-merge.yml,所以 PR #7 仍要 human-merge 一次。

链式 dogfood 揪 bug 数累计:4 个。所有 4 个都是本 session 之前
ship 时未被多 commit / 第一个真 SHA 路径覆盖到的盲区。

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@libz-renlab-ai
libz-renlab-ai merged commit 606faa4 into main May 15, 2026
12 checks passed
@libz-renlab-ai
libz-renlab-ai deleted the fix/codex-hooks-skipif branch May 15, 2026 08:55
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.

2 participants