Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "tests/session_recording/codex/test_hook_adapter.py の共有マニフェストパスをテスト間で分離し、Node-backed hook tests を並列 pytest 実行下でも決定論的に PASS させる"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: N/A(単独改善のため親 Issue なし)
- Desired Destination: N/A
Current Validated Scope
scripts/session-recording/write-codex-session-manifest.mjsのwriteCodexSessionManifestにマニフェスト書き込み先ディレクトリの override 経路を追加するscripts/session-recording/codex-hook-adapter.mjsのrunManifestFlowが環境変数からマニフェストルートの override を読み取りwriteCodexSessionManifestに渡すtests/session_recording/codex/test_hook_adapter.pyが各テストで pytest のtmp_pathを使い、上記 override 経由でテスト固有のマニフェストディレクトリを adapter サブプロセスに渡す.github/workflows/ci.ymlのnode-backed-hook-testsjob にtests/session_recording/codex/test_hook_adapter.pyを実行する専用 step を追加し、.github/ci/python-test-plan.jsonのsecondary_coverage.dedicated_lanesにそのカバレッジ提供元を登録して、CI のci_test_selection/v1G1 gate(uncovered changed test file 検出)を満たす
Remaining Parent Gaps
なし
Outcome
scripts/session-recording/write-codex-session-manifest.mjs と scripts/session-recording/codex-hook-adapter.mjs にマニフェスト書き込み先の override 経路が追加され、tests/session_recording/codex/test_hook_adapter.py の各テストがリポジトリ共有の tmp/session-manifests/codex/ ではなくテスト固有の一時ディレクトリを使うよう更新され、python3 -m pytest tests/session_recording/codex/test_hook_adapter.py -n4 を含む並列 pytest 実行でも 36 件全てが安定して PASS し、かつ .github/workflows/ci.yml の node-backed-hook-tests job(pnpm install 済みで Node 実行環境を持つ job)で tests/session_recording/codex/test_hook_adapter.py が実行され、CI の python-test / node-backed-hook-tests 両 job の ci_test_selection/v1 G1 gate(uncovered changed test file 検出)が実行証跡(collect-only の実 nodeid)で通り、manifestRoot override が realpath 検証済みで symlink・許可外パスへの書き込みを拒否し、evidence_ref が実際の書き込み先を反映し、CI が xdist 並列実行で元の競合を回帰検査し、環境変数未設定時のフォールバック挙動もテストされている状態。
In Scope
write-codex-session-manifest.mjsのwriteCodexSessionManifestにmanifestRoot(または同等の)オプション引数を追加し、指定時はそのディレクトリ配下に書き込むcodex-hook-adapter.mjsのrunManifestFlow/produceManifest呼び出し経路で、環境変数(例:CODEX_HOOK_MANIFEST_ROOT)が設定されている場合にそれをwriteCodexSessionManifestの override として渡す。未設定時は既存のrepoRootベースの既定パスを維持し、本番の hook 実行経路の挙動を変えないtests/session_recording/codex/test_hook_adapter.pyのsetup_functionによるグローバルMANIFEST_ROOT(REPO_ROOT/tmp/session-manifests/codex)へのshutil.rmtreeを削除し、各テストがtmp_pathfixture 由来のテスト固有ディレクトリをrun_adapterのenv引数(既存のenv=Noneパラメータ)経由で adapter サブプロセスに渡すよう更新する- 上記変更後、
test_positive_fixture_writes_private_manifest_and_returns_continue_true等マニフェストファイル件数を検査するテストが、他テストの並行書き込み・削除と無関係に自テスト専用ディレクトリのみを検査するようにする .github/workflows/ci.ymlのnode-backed-hook-testsjob に、既存のpytest node-backed hook testsstep とは独立した新規 step(tests/session_recording/codex/test_hook_adapter.py -p no:xdistを実行)を追加する。既存の固定 2 nodeid(.claude/hooks/tests/test_generate_session_manifest_from_hook.pyの 2 テスト)の disjointness / exact-match invariant には触れない.github/ci/python-test-plan.jsonのsecondary_coverage.dedicated_lanesにprovider_job: node-backed-hook-tests/paths: ["tests/session_recording/codex/test_hook_adapter.py"]の新規エントリを追加し、generate_ci_test_selection_artifact.pyの G1 gate(uncovered_changed_test_files)でこの PR の変更差分が uncovered と判定されないようにする(targets配列には追加しない。python-testjob はpnpm installを実行しないため、この Node-backed hook test をtargetsに入れると node_modules 欠如で壊れる).github/workflows/ci.ymlの node-backed hook selection artifact 生成 step(--collect-onlyを実行する箇所)がtests/session_recording/codex/test_hook_adapter.pyの実 nodeid も収集するよう対象を拡張し、secondary_coverage.dedicated_lanesの宣言だけに依存せず実行証跡(collected nodeids)で uncovered 判定を回避する。これに伴い、既存の「固定 2 nodeid のみ」という invariant アサーションは、その 2 nodeid のサブセットに対してのみ適用されるよう限定し、job 全体の不変条件としては扱わないwrite-codex-session-manifest.mjsにmanifestRootoverride の検証(realpathSyncを用いた symlink 拒否・許可パス外拒否)を追加するcodex-hook-adapter.mjsのevidence_refを、書き込み前に固定生成した文字列ではなくwriteCodexSessionManifestの戻り値(実際の書き込み先)から構築するよう修正する.github/workflows/ci.ymlの node-backed-hook-tests job にtests/session_recording/codex/test_hook_adapter.pyを-n 4 --dist loadで実行する step を追加する(既存の-p no:xdistシリアル step は維持してよい)test_hook_adapter.pyに環境変数未設定時の既定パスへの書き込みを検証するテストを追加する
Out of Scope
scripts/agent-guards/git_mutation_command_policy.pyや publish lane 関連の変更(Issue 実装: PreToolUse remote_write_requires_approval を publish lane 証跡で通過可能にする #1408 のスコープ)tests/session_recording/codex/test_metrics_and_secret_scan.pyを CI 実行対象へ追加すること(本 Issue で変更しないファイルのため).github/ci/python-test-plan.jsonのtargets配列への追加(python-testjob には node 実行環境が無いため不採用)docs/dev/test-lane-policy.mdの Node-backed hook tests 定義そのものの見直し(follow-up Issue で対応)- manifest の内容・schema(
schemas/agent-session-manifest相当)の変更 runManifestFlow/writeCodexSessionManifestの依存性注入(DI)への全面リファクタリング(CODEX_HOOK_MANIFEST_ROOT環境変数を廃止し producer/writer を注入可能にする設計変更)。本 Issue では env var を維持しつつ realpath 検証で安全化する最小修正を採用するtest_stop_event_scrubs_producer_failure_stderrの producer path fallback ロジック見直し(実際の失敗 producer を起動させる修正、follow-up Issue で対応)
Acceptance Criteria
- AC1:
writeCodexSessionManifestが override 引数を受け取った場合、そのディレクトリ配下(<override>/<eventName>/)にマニフェストを書き込む - AC2:
codex-hook-adapter.mjsが環境変数CODEX_HOOK_MANIFEST_ROOT未設定時は既存のrepoRootベースのtmp/session-manifests/codex/<event>/に書き込む(後方互換維持) - AC3:
test_hook_adapter.pyの各テストがtmp_path由来のテスト固有ディレクトリを使い、setup_functionのグローバルMANIFEST_ROOTへのshutil.rmtree呼び出しが削除されている - AC4:
python3 -m pytest tests/session_recording/codex/test_hook_adapter.py -n4が 36 件全て PASS する - AC5:
python3 -m pytest tests/session_recording/codex/test_hook_adapter.py -p no:xdistが 36 件全て PASS する(既存のシリアル実行の回帰なし) - AC6:
.github/workflows/ci.ymlのnode-backed-hook-testsjob でtests/session_recording/codex/test_hook_adapter.pyを実行する step が存在する - AC7:
.github/ci/python-test-plan.jsonのsecondary_coverage.dedicated_lanesにprovider_job: node-backed-hook-testsのエントリが追加され、tests/session_recording/codex/test_hook_adapter.pyがそのpathsに含まれる(targets配列への追加ではない) - AC8:
.github/workflows/ci.ymlの「node-backed hook selection artifact」生成 step(--collect-only)がtests/session_recording/codex/test_hook_adapter.pyの実 nodeid を収集対象に含み、宣言(secondary_coverage.dedicated_lanes)だけに依存せず実行証跡で uncovered 判定を回避する - AC9:
write-codex-session-manifest.mjsがmanifestRootoverride をrealpathSync等で検証し、symlink 経由や許可外ディレクトリへの書き込みを拒否する - AC10:
codex-hook-adapter.mjsがwriteCodexSessionManifestの戻り値をmanifestWriteResultという変数名で受け取り、manifest.secret_policy.runtime_boundary.evidence_refをmanifestWriteResult.relativePath(実際の書き込み先)から再構築する。書き込み前に固定生成されたevidenceSourceRef文字列をそのままevidence_refに使わない - AC11:
.github/workflows/ci.ymlの node-backed-hook-tests job がtests/session_recording/codex/test_hook_adapter.pyを--dist loadを用いた xdist 並列実行で回帰検査する(-p no:xdistのシリアル実行のみに依存しない) - AC12:
test_hook_adapter.pyに、CODEX_HOOK_MANIFEST_ROOT環境変数が未設定の場合にマニフェストが既定パス(<repoRoot>/tmp/session-manifests/codex/<event>/)へ書き込まれることを検証するテスト(test_manifest_written_to_default_root_when_env_unset)が存在する
Verification Commands
# baseline-expect: fail
$ rg -n "manifestRoot" scripts/session-recording/write-codex-session-manifest.mjs # AC1
# baseline-expect: fail
$ rg -n "CODEX_HOOK_MANIFEST_ROOT" scripts/session-recording/codex-hook-adapter.mjs # AC2
# baseline-expect: pass
$ rg -c "shutil.rmtree\(MANIFEST_ROOT" tests/session_recording/codex/test_hook_adapter.py # AC3
# baseline-expect: deferred
$ python3 -m pytest tests/session_recording/codex/test_hook_adapter.py -n4 # AC4
# baseline-expect: pass
$ python3 -m pytest tests/session_recording/codex/test_hook_adapter.py -p no:xdist # AC5
# baseline-expect: fail
$ rg -n "tests/session_recording/codex/test_hook_adapter.py" .github/workflows/ci.yml # AC6
# baseline-expect: fail
$ rg -n "\"provider_job\": \"node-backed-hook-tests\"" .github/ci/python-test-plan.json # AC7
# baseline-expect: deferred
$ rg -U "collect-only.{0,400}test_hook_adapter" .github/workflows/ci.yml # AC8
# baseline-expect: fail
$ rg -n "realpathSync" scripts/session-recording/write-codex-session-manifest.mjs # AC9
# baseline-expect: fail
$ rg -n "manifestWriteResult.relativePath" scripts/session-recording/codex-hook-adapter.mjs # AC10
# baseline-expect: fail
$ rg -n "dist load" .github/workflows/ci.yml # AC11
# baseline-expect: fail
$ rg -n "test_manifest_written_to_default_root_when_env_unset" tests/session_recording/codex/test_hook_adapter.py # AC12Allowed Paths
scripts/session-recording/write-codex-session-manifest.mjsscripts/session-recording/codex-hook-adapter.mjstests/session_recording/codex/test_hook_adapter.py.github/ci/python-test-plan.json.github/workflows/ci.yml
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Node.js(
node:fs/node:pathを使うマニフェスト書き込みロジック) - Python / pytest(
tmp_pathfixture、subprocess.runのenv引数)
Required Design References
docs/dev/test-lane-policy.md(Node-backed hook tests のレーン定義).claude/skills/ci-test-performance/SKILL.md(xdist worker 間の fixture scope / 非決定性に関する注意)
Delivery Rule
1 Issue = 1 PR- Dedicated worktree を作成して実装する
- Draft PR 既定
Scope Delta(任意)
| 項目 | 内容 |
|---|---|
| 発見経緯(1回目) | PR #1421 の pr-review-judge レビューで、CI 必須チェック python-test / node-backed-hook-tests が generate_ci_test_selection_artifact.py の G1 gate(uncovered_changed_test_files)で fail することが判明した |
| 発見経緯(2回目) | 1回目の Scope Delta で .github/ci/python-test-plan.json の targets に登録して G1 gate 自体は通ったが、再検証で python-test job 側の pytest 実行が 5 件 fail(ajv and ajv-formats must be installed as devDependencies 等)。原因調査の結果、python-test job は pnpm install を実行しない Python 専用レーンであり、Node の子プロセスを起動する Node-backed hook test をそこに加えると node_modules 欠如で壊れることが判明した |
| 変更 | .github/ci/python-test-plan.json の targets 登録を撤回し、代わりに (1) .github/workflows/ci.yml の node-backed-hook-tests job(pnpm install 済み)に実行 step を追加、(2) .github/ci/python-test-plan.json の secondary_coverage.dedicated_lanes に provider_job: node-backed-hook-tests としてカバレッジ登録、の2点に修正した。AC6/AC7 として反映し、Allowed Paths に .github/workflows/ci.yml を追加した |
| 影響範囲 | .github/workflows/ci.yml の node-backed-hook-tests job に新規 step 1つを追加(既存の固定 2 nodeid の disjointness/exact-match invariant には触れない)。.github/ci/python-test-plan.json は secondary_coverage.dedicated_lanes への 1 エントリ追加のみ |
| 注意 | .github/workflows/ci.yml の編集は .github/CLAUDE.md により PR レビューで人間承認必須。マージ判断は人間が行う |
| 発見経緯(3回目) | PR #1421 に対する人間経由の外部アドバーサリアルレビュー(issuecomment-4940413442)で、2件の P1 blocker が指摘された: (1) secondary_coverage.dedicated_lanes の宣言のみで実行証跡が伴わず、node-backed-hook-tests job の新規 step が削除・rename・skip されても G1 gate が検出できない false-green リスク、(2) CODEX_HOOK_MANIFEST_ROOT が本番 adapter 経路で無検証の ambient environment 変数として機能し、任意パスへの書き込み・監査証跡(evidence_ref)と実書き込み先の不一致を許してしまう安全性の欠陥。加えて P2 として、CI の xdist 回帰検査が -p no:xdist(xdist 無効化)のみで元の競合を再現していないこと、環境変数未設定時のフォールバック挙動が動作テストされていないことが指摘された |
| 変更(3回目) | AC8-AC12 を追加。CI selection artifact の実行証跡化、manifestRoot の realpath 検証、evidence_ref の実書き込み先反映、xdist 並列 CI 回帰検査の追加、フォールバックパステストの追加を行う。P2(stderr redaction テストの実効性)と P3(docs/dev/test-lane-policy.md 等のドキュメント同期)は本 PR のブロッカーとせず、別途 follow-up Issue で対応する(レビューコメントもこの扱いを許容している) |
Notes for Reviewer
- 本 Issue は Issue 実装: PreToolUse remote_write_requires_approval を publish lane 証跡で通過可能にする #1408 の baseline VC preflight(
ensure_contract_snapshot.py/baseline_vc_preflight.py)がtests/session_recording/codex/test_hook_adapter.pyを並列実行環境下でフレーキーにhuman_judgment判定させたため、そのブロッカー解消として起票された。-n2での再現実験でMANIFEST_ROOT(REPO_ROOT/tmp/session-manifests/codex)の共有とsetup_functionのshutil.rmtreeがテスト間競合の原因であることを確認済み。 - AC6 の追加は PR fix: MANIFEST_ROOT を xdist 並列実行から分離する #1421 の pr-review-judge REQUEST_CHANGES を受けた Scope Delta である。
- AC8-AC12 は fix: MANIFEST_ROOT を xdist 並列実行から分離する #1421 (comment) の P1/P2 blocker を受けた Scope Delta である。AC8 の検証は
.github/workflows/ci.ymlの静的な marker 検査に加え、実際に生成された CI 実行後のci_test_selection_v1.json/ci_test_selection_summary_v1.jsonartifact(node-backed-hook-testsjob の run から取得可能)でcollected_test_filesにtests/session_recording/codex/test_hook_adapter.pyの nodeid が含まれ、cross_job_covered_test_filesが空であることを pr-review-judge が確認すること。 - レビューコメントが挙げた P2「stderr redaction テストが実際の失敗 producer を起動していない」(
test_stop_event_scrubs_producer_failure_stderr)と P3「docs/dev/test-lane-policy.md/ci-test-performance/SKILL.mdの記述が現行 workflow と乖離」は、本 Issue の Allowed Paths 外または追加調査を要するため、本 PR では対応せず follow-up Issue を別途起票する。
Activity
squne121 commentedon Jul 10, 2026
Contract Review Result
squne121 commentedon Jul 10, 2026
implement-issue: 実装完了 (2026-07-10)
.claude/worktrees/issue-1420-codex-manifest-root-xdistworktree-issue-1420-codex-manifest-root-xdist-n4を 4 回連続実行して 36 件全て安定 PASS を確認、-n2でも別途確認)squne121 commentedon Jul 10, 2026
Contract Review Result (Scope Delta AC6 追加後の再検証)
fix: register test_hook_adapter.py in python-test-plan targets (#1420)
squne121 commentedon Jul 10, 2026
Contract Review Result (Scope Delta 2回目: AC6/AC7 CI レーン修正後の再検証)
fix: move test_hook_adapter.py to dedicated node-backed-hook-tests la…
squne121 commentedon Jul 10, 2026
Contract Review Result (Scope Delta 3回目: AC8-AC12 外部レビュー対応後の再検証)
fix: PR review adversarial指摘の解消 (#1420 fix_delta 3)
squne121 commentedon Jul 11, 2026
fix_delta 3 完了報告(AC8-AC12, 外部アドバーサリアルレビュー対応)
外部レビュー(#1421 (comment) )の P1 blocker 2件・P2 3件(内1件対応)を Scope Delta 3(AC8-AC12)として実装しました。commit:
759f495a対応内容
node-backed-hook-testsjob の collect-only 対象にtests/session_recording/codex/test_hook_adapter.py(37 nodeid)を追加し、G1 gate(uncovered_changed_test_files)が declaredsecondary_coverageだけでなく実行証跡を独立に確認できるようにした。既存の固定2 nodeid の disjointness / exact-match invariant はfixed_hook_wrapper_nodeidsとして分離集計し維持。CODEX_HOOK_MANIFEST_ROOToverride 時、書き込み先ディレクトリのrealpathSyncが OStmpdir()の realpath 配下であることを検証し、symlink 経由の任意パス書き込みを fail-closed で拒否するようにした(mkdirSync後にrealpathSyncする順序でディレクトリ置換 symlink も検出)。codex-hook-adapter.mjsのrunManifestFlowがresolveManifestWriteTarget()をproduceManifest()呼び出し前に実行し、実際の書き込み先を反映したrelativePathをevidence_refに使うよう修正。manifestRootがrepoRoot外(テスト isolation のtmp_path)の場合は<event>/<file>形式にフォールバックし、generate-session-manifest.mjsの secret-leak guard(Secret pattern detected: absolute path detected)誤検知を回避した。node-backed-hook-testsjob に-n 4 --dist loadの xdist 並列実行 step を追加(既存の-p no:xdiststep はそのまま維持)。CODEX_HOOK_MANIFEST_ROOT未設定時に本番既定パス(<repoRoot>/tmp/session-manifests/codex/stop/)へ書き込まれることを確認する回帰テストtest_manifest_written_to_default_root_when_env_unsetを追加。検証結果
ESLint(変更2ファイル): エラーなし。
node --check(変更2ファイル): エラーなし。.github/workflows/ci.ymlの YAML パース: OK。CI_TEST_PERFORMANCE_DECISION_V1
.claude/skills/ci-test-performance/SKILL.mdを確認の上、PR #1421 にコメントとして投稿しました: #1421 (comment)実装過程で見つけた追加の設計調整(AC10 の派生対応)
resolveManifestWriteTarget()のrelativePathを素朴にrelative(repoRoot, absolutePath)にすると、テストのmanifestRoot(tmp_path経由、repoRoot外)override 時に../../../.../tmp/...という traversal 文字列が生成され、generate-session-manifest.mjsの secret-leak guard にError: Secret pattern detected: absolute path detected.として拒否され、4テストがstderr非空で fail していました。manifestRootが指定されている場合は<event>/<file>形式(repoRoot非依存)にフォールバックすることで解消しています(本番のmanifestRoot未指定パスは既存のtmp/session-manifests/codex/<event>/<file>形式のまま変更なし)。Refs #1420
PR: #1421
fix: MANIFEST_ROOT を xdist 並列実行から分離する (#1421)
実装: Codex Stop/SubagentStop session manifest の canonical output root …