Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#646"
goal_ref: "hooks tests の CI 取りこぼしを防ぎ、未登録 hook test が追加されても CI_CHECK_RUN_SCOPED 証跡から漏れない状態にする"
change_kind: codeParent Issue
Parent Goal Ref
- Goal:
guard-japanese-proseと関連 hook のテストが CI で自動実行される状態にする - Desired Destination:
.claude/hooks/tests/配下の hook test が、許可された例外を除いてpython-testjob とci_test_selection/v1artifact の両方で同一 collection args により扱われ、PR レビュー時に CI_CHECK_RUN_SCOPED 証跡として参照できる
Current Validated Scope
.github/workflows/ci.ymlのpython-testjob で.claude/hooks/tests/をディレクトリ指定で実行し、test_secret_boundary_contract.pyのみを明示的に除外する- 同じ hook test collection args を
Generate ci_test_selection/v1 artifactステップの--pytest-argsに渡す .claude/hooks/tests/test_*.pyのうち CI 未登録が許されるのはtest_secret_boundary_contract.pyのみであることを workflow 内で検査する
Remaining Parent Gaps
-
test_secret_boundary_contract.pyの pre-existing failure 解消と CI 登録は別 Issue で扱う -
#646parent の shadow / replay 運用証跡要求は 実装(#646): guard-japanese-prose に shadow / enforce mode と replay 証跡(R1〜R7)を追加 #657 側で継続する
Outcome
.github/workflows/ci.yml に Run Claude hook tests ステップと Check unregistered hook tests ステップが追加され、python-test job が uv run --locked pytest .claude/hooks/tests/ -q --ignore=.claude/hooks/tests/test_secret_boundary_contract.py で hooks tests を実行する。さらに Generate ci_test_selection/v1 artifact ステップの --pytest-args も同一のディレクトリ指定と ignore 指定に揃い、test_guard_tmp_draft_passthrough.py / test_guard_graphql_mutation.py / test_guard_api_input.py / test_guard_api_comment_input.py / test_guard_borderline_repair.py / test_generate_session_manifest_from_hook.py を含む hook tests が、個別ファイル列挙漏れではなく directory discovery により CI_CHECK_RUN_SCOPED 証跡へ載る状態になる。
Background
PR #676(#655 実装)のレビューでは、.claude/hooks/tests/test_guard_tmp_draft_passthrough.py と .claude/hooks/tests/test_guard_graphql_mutation.py が CI 未登録だったため、複数 AC が PR body 自己申告に落ち、PR_BODY_SELF_REPORT_ONLY_APPROVE_PROHIBITED に抵触した。Issue #602 も .claude/hooks/tests/test_guard_api_input.py が同じ理由で CI から漏れた follow-up であり、本 Issue で吸収する。
現行 main の .github/workflows/ci.yml では test_session_recording_policy_guard.py / test_guard_delta_mode.py / test_guard_shadow_mode.py / test_replay_scenarios.py / test_shadow_log.py が個別登録済みだが、.claude/hooks/tests/ 全体を discovery しないため、新規 test_*.py が追加されても自動では CI に入らない。test_secret_boundary_contract.py は pre-existing failure があるため今回の対象外とし、許容例外として 1 箇所に明示する。
In Scope
.github/workflows/ci.ymlのpython-testjob に hooks tests 用のディレクトリ実行ステップを追加する.github/workflows/ci.ymlに、.claude/hooks/tests/test_*.pyの未登録を検出するステップを追加する.github/workflows/ci.ymlのGenerate ci_test_selection/v1 artifactステップで、hooks tests に対して CI 実行と同一の collection args を--pytest-argsに渡すCloses #602(test_guard_api_input.pyの CI 登録 follow-up を本 Issue に統合する)
Out of Scope
test_secret_boundary_contract.pyの failure 修正および CI 登録.claude/skills/pr-review-judge/scripts/generate_ci_test_selection_artifact.py本体の変更- hooks tests 以外の Python test 実行方式の再設計
#646parent の shadow / replay 証跡要求の完了
Acceptance Criteria
- AC1:
.github/workflows/ci.ymlのpython-testjob にRun Claude hook testsステップがあり、uv run --locked pytest .claude/hooks/tests/ -q --ignore=.claude/hooks/tests/test_secret_boundary_contract.pyを実行している - AC2:
.github/workflows/ci.ymlにCheck unregistered hook testsステップがあり、.claude/hooks/tests/test_*.pyを走査して CI 未登録 test を検出できる - AC3: AC2 の許容例外は
.claude/hooks/tests/test_secret_boundary_contract.pyのみで、allowed_unregisteredとして workflow 内に明示されている - AC4:
Generate ci_test_selection/v1 artifactステップのgenerate_ci_test_selection_artifact.py --pytest-argsに.claude/hooks/tests/が渡されている - AC5: AC4 の
--pytest-argsには--ignore=.claude/hooks/tests/test_secret_boundary_contract.pyも渡され、hook tests の collection args が AC1 と一致している
Verification Commands
# AC1
$ rg -n "uv run --locked pytest \.claude/hooks/tests/ -q --ignore=\.claude/hooks/tests/test_secret_boundary_contract\.py" .github/workflows/ci.yml
# AC2
$ rg -n "Check unregistered hook tests" .github/workflows/ci.yml
# AC3
$ rg -n "allowed_unregistered|test_secret_boundary_contract\.py" .github/workflows/ci.yml
# AC4
$ rg -n "^\s+\.claude/hooks/tests/ \\$" .github/workflows/ci.yml
# AC5
$ rg -n -- "--ignore=\.claude/hooks/tests/test_secret_boundary_contract\.py" .github/workflows/ci.ymlAllowed Paths
.github/workflows/ci.yml
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(CI workflow の step 名・collection args・許容例外集合)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- YAML(GitHub Actions workflow 構文)
- Python(pytest CLI 引数と未登録検出スクリプト)
Scope Delta(任意)
N/A
Delivery Rule
- 1 Issue = 1 PR
- Draft PR で開始、レビュー後にマージ
Closes #602#646parent の shadow / replay 証跡要求は 実装(#646): guard-japanese-prose に shadow / enforce mode と replay 証跡(R1〜R7)を追加 #657 側に残し、本 Issue では請け負わない
Source(dedupe_key)
follow-up:squne121/loop-protocol:pr/676:hook-test-discovery-and-registration-guard
Runtime Verification Applicability
rva_schema_version: v1
applicability: not_applicable
decision: not_applicable
reason: "CI workflow 設定の変更のみ。runtime 動作検証は不要で、検証は workflow 記述の静的確認で足りる。"
Activity
squne121 commentedon Jun 7, 2026
判定: #682 は 必要だが、現状の契約のままでは不十分
#682 の目的自体は妥当です。#676 のレビューで、
test_guard_tmp_draft_passthrough.pyとtest_guard_graphql_mutation.pyが CI 未登録のため、AC2/4/5/6/8/10/11/12/14 が PR body 自己申告に落ち、PR_BODY_SELF_REPORT_ONLY_APPROVE_PROHIBITEDに抵触していました。これは #682 が塞ぐべき正当な follow-up です。([GitHub]1)ただし、#682 は「6 ファイルを名指しで追加する」契約になっており、根本原因である
.claude/hooks/tests/の新規テストが CI に自動で入らない構造 を温存しています。#602 でも同じ原因、つまり.github/workflows/ci.ymlが個別ファイル列挙で auto-discovery しないためtest_guard_api_input.pyが CI から漏れた、と記録されています。([GitHub]2)Blocker 1: 「6 ファイル追記」は再発防止になっていない
pytest は標準で
test_*.py/*_test.pyを発見し、ディレクトリ単位で実行できます。つまり、このケースではpytest .claude/hooks/tests/という設計が自然です。個別ファイル列挙を続けると、次の hook テスト追加時に同じ follow-up Issue がまた発生します。([docs.pytest.org]3)#682 は Out of Scope で「自動 discovery 方式への変更」を外していますが、これは敵対的に見ると不適切です。今回の障害の本質は「6 件が漏れた」ことではなく、「漏れる CI 設計」です。最低限、次のどちらかを AC に入れるべきです。
# 推奨: hooks tests は原則ディレクトリ実行に寄せる uv run --locked pytest .claude/hooks/tests/ -q \ --ignore=.claude/hooks/tests/test_secret_boundary_contract.pyまたは、個別列挙を維持するなら、CI に「未登録 hook test 検出」ステップを追加してください。
Blocker 2: AC7 の対象が曖昧、実装者がスクリプト本体を壊す余地がある
#682 は「
generate_ci_test_selection_artifact.pyの--pytest-argsにも 6 ファイルを追記」と書いていますが、現行スクリプトは--pytest-argsを受け取る CLI であり、テストファイル一覧は主にci.yml側の呼び出し引数です。スクリプト本体にハードコードして追記する実装を誘発すると、責務が逆流します。([GitHub]4)修正すべき AC はこうです。
Blocker 3: #682 本文の現状認識が stale になっている
#682 本文では「CI 登録済みは
test_session_recording_policy_guard.pyとtest_guard_delta_mode.pyの 2 ファイルのみ」とありますが、現行 main のci.ymlには少なくともtest_guard_shadow_mode.py/test_replay_scenarios.py/test_shadow_log.pyも登録されています。対象 6 件の追加自体はまだ必要ですが、Issue 本文の “Current Validated Scope” は最新 main に合わせて更新しないと、実装者が古い前提で作業します。([GitHub]5)Blocker 4:
test_secret_boundary_contract.py除外の扱いが弱いtest_secret_boundary_contract.pyを pre-existing failure として今回対象外にする判断は理解できます。#682 もその点を明記しています。([GitHub]5)ただし、「対象外」とするなら、例外の存在を CI で明示的に検査すべきです。そうしないと、今後さらに未登録テストが増えても「secret boundary と同じ扱い」として曖昧に見逃されます。
追加 AC 案:
Blocker 5: #676 のブロッカー解消だけでなく、#646 親ゴールとの接続が弱い
親 Issue #646 は、hook / validator / checker / loop dry-run の分類 SSOT、公開 mutation route matrix、shadow/replay 証跡まで含む delivery-rollup です。#682 は #676 の CI 証跡欠落を塞ぐだけで、#646 の parent closure に必要な「運用証跡」の保証までは扱っていません。([GitHub]6)
#682 の scope を広げすぎる必要はありませんが、PR の完了条件には少なくとも以下を入れるべきです。
実装修正方針
最小修正なら、#682 の 6 ファイルを
python-testjob に追加し、Generate ci_test_selection/v1 artifactの--pytest-argsにも同じ 6 ファイルを追加します。ただし、推奨は次です。さらに
ci_test_selectionartifact の--pytest-argsもディレクトリ指定へ寄せます。pytest はディレクトリ指定で標準 discovery を行えるため、この方が新規test_*.pyの取りこぼしに強いです。([docs.pytest.org]7)#682 に貼るべきコメント案
結論として、#682 は そのまま実装は No-Go。実装 PR を出す前に、AC を「6 ファイル追加」から「hooks test の CI 取りこぼしを検出・防止する契約」に格上げしてください。
[-]実装: CI workflow に未登録の hooks テストファイル 6 件を登録(test_guard_tmp_draft_passthrough / test_guard_graphql_mutation 等)[/-][+]実装: hooks tests の CI 取りこぼしを防ぐ(directory 実行 + 未登録検出)[/+]squne121 commentedon Jun 7, 2026
Contract Snapshot (2026-06-07T12:36:24Z)
rg5 本とも baseline fail expected を確認済み.github/workflows/ci.yml.claude/worktrees/issue-682-hook-test-discoveryworktree-issue-682-hook-test-discoverytest: install node deps in python-test (#682)
test: tighten hook discovery evidence (#682)
fix: unblock ci_test_selection artifact args (#682)
test: hooks tests の CI 取りこぼしを防ぐ (#682) (#763)