Skip to content

実装: hooks tests の CI 取りこぼしを防ぐ(directory 実行 + 未登録検出) #682

Closed

Description

@squne121

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: code

Parent Issue

#646

Parent Goal Ref

  • Goal: guard-japanese-prose と関連 hook のテストが CI で自動実行される状態にする
  • Desired Destination: .claude/hooks/tests/ 配下の hook test が、許可された例外を除いて python-test job と ci_test_selection/v1 artifact の両方で同一 collection args により扱われ、PR レビュー時に CI_CHECK_RUN_SCOPED 証跡として参照できる

Current Validated Scope

  • .github/workflows/ci.yml の python-test job で .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

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-test job に 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 実行方式の再設計
  • #646 parent の shadow / replay 証跡要求の完了

Acceptance Criteria

  • AC1: .github/workflows/ci.yml の python-test job に 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.yml

Allowed 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

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

  1. added
    enhancement
    phase/implementation
    agent/implementer
    area/ai-ops
    on Jun 5, 2026
  2. squne121 commented on Jun 7, 2026

    @squne121
    OwnerAuthor

    判定: #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 検出」ステップを追加してください。

    python3 - <<'PY'
    from pathlib import Path
    import re
    
    ci = Path(".github/workflows/ci.yml").read_text(encoding="utf-8")
    all_hook_tests = sorted(Path(".claude/hooks/tests").glob("test_*.py"))
    
    allowed_unregistered = {
        ".claude/hooks/tests/test_secret_boundary_contract.py",
    }
    
    missing = []
    for p in all_hook_tests:
        s = p.as_posix()
        if s in allowed_unregistered:
            continue
        if s not in ci:
            missing.append(s)
    
    if missing:
        raise SystemExit("Unregistered hook tests in CI:\n" + "\n".join(missing))
    PY

    Blocker 2: AC7 の対象が曖昧、実装者がスクリプト本体を壊す余地がある

    #682 は「generate_ci_test_selection_artifact.py の --pytest-args にも 6 ファイルを追記」と書いていますが、現行スクリプトは --pytest-args を受け取る CLI であり、テストファイル一覧は主に ci.yml 側の呼び出し引数です。スクリプト本体にハードコードして追記する実装を誘発すると、責務が逆流します。([GitHub]4)

    修正すべき AC はこうです。

    AC7: .github/workflows/ci.yml の Generate ci_test_selection/v1 artifact ステップで generate_ci_test_selection_artifact.py --pytest-args に、CI で実行する hook test と同一集合が渡されている。スクリプト本体にテストファイル一覧をハードコードしてはならない。

    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 案:

    AC9: .claude/hooks/tests/test_*.py のうち、CI 未登録が許されるのは test_secret_boundary_contract.py のみであることを CI で検査する。許容例外は allowed_unregistered として 1 箇所に明示する。

    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 の完了条件には少なくとも以下を入れるべきです。

    - #676 の AC2/4/5/6/8/10/11/12/14 に対応する hook tests が CI_CHECK_RUN_SCOPED になること
    - ci_test_selection/v1 artifact の collected_test_files に対象 hook tests が含まれること
    - #646 parent closure の shadow/replay 証跡要求は #657 側に残し、本 PR では請け負わないことを明記する
    

    実装修正方針

    最小修正なら、#682 の 6 ファイルを python-test job に追加し、Generate ci_test_selection/v1 artifact の --pytest-args にも同じ 6 ファイルを追加します。ただし、推奨は次です。

    - name: Run Claude hook tests
      run: |
        uv run --locked pytest .claude/hooks/tests/ -q \
          --ignore=.claude/hooks/tests/test_secret_boundary_contract.py

    さらに ci_test_selection artifact の --pytest-args もディレクトリ指定へ寄せます。pytest はディレクトリ指定で標準 discovery を行えるため、この方が新規 test_*.py の取りこぼしに強いです。([docs.pytest.org]7)

    #682 に貼るべきコメント案

    ## Review: REQUEST_CHANGES
    
    #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 自己申告に落ちていたため、CI_CHECK_RUN_SCOPED 証跡を確保する follow-up は必要です。
    
    ただし、現契約の「6 ファイルを個別に追記する」だけでは不十分です。#602 と同じく、根本原因は `.github/workflows/ci.yml` が `.claude/hooks/tests/` を discovery せず、個別ファイル列挙に依存していることです。pytest は `test_*.py` / `*_test.py` を標準 discovery し、ディレクトリ指定で実行できます。したがって、可能なら `uv run --locked pytest .claude/hooks/tests/ -q --ignore=.claude/hooks/tests/test_secret_boundary_contract.py` へ寄せてください。
    
    最低限、次を AC に追加してください。
    
    1. `.claude/hooks/tests/test_*.py` のうち CI 未登録が許されるのは `test_secret_boundary_contract.py` のみであることを CI で検査する。
    2. `generate_ci_test_selection_artifact.py` 本体にテスト一覧をハードコードしない。`ci.yml` の `Generate ci_test_selection/v1 artifact` ステップの `--pytest-args` に、CI 実行対象と同一集合を渡す。
    3. #682 本文の「CI 登録済みは 2 ファイルのみ」という現状認識を最新 main に合わせて更新する。
    4. #646 parent の shadow/replay 運用証跡は #657 側の責務として残し、本 Issue は #676 の hook test CI 証跡確保に限定する。
    
    この修正なしに実装すると、今回の6ファイルは塞げても、次の hook test 追加で同じ CI 未登録事故が再発します。

    結論として、#682 は そのまま実装は No-Go。実装 PR を出す前に、AC を「6 ファイル追加」から「hooks test の CI 取りこぼしを検出・防止する契約」に格上げしてください。

  3. changed the title [-]実装: CI workflow に未登録の hooks テストファイル 6 件を登録(test_guard_tmp_draft_passthrough / test_guard_graphql_mutation 等)[/-] [+]実装: hooks tests の CI 取りこぼしを防ぐ(directory 実行 + 未登録検出)[/+] on Jun 7, 2026
  4. squne121 commented on Jun 7, 2026

    @squne121
    OwnerAuthor

    Contract Snapshot (2026-06-07T12:36:24Z)

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: 2026-06-07T12:36:24Z
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/682
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 5
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 0
          vc_skipped: 0
          classifications:
            - ac: AC1
              command: rg -n "uv run --locked pytest \.claude/hooks/tests/ -q --ignore=\.claude/hooks/tests/test_secret_boundary_contract\.py" .github/workflows/ci.yml
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC2
              command: rg -n "Check unregistered hook tests" .github/workflows/ci.yml
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC3
              command: rg -n "allowed_unregistered|test_secret_boundary_contract\.py" .github/workflows/ci.yml
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC4
              command: rg -n "^\s+\.claude/hooks/tests/ \\$" .github/workflows/ci.yml
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
            - ac: AC5
              command: rg -n -- "--ignore=\.claude/hooks/tests/test_secret_boundary_contract\.py" .github/workflows/ci.yml
              exit_code: 1
              category: expected_baseline_fail
              scope_class: baseline_fail_expected
              confidence: high
              evidence:
                stdout_excerpt: ""
                stderr_excerpt: ""
              decision: go
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
          conditions:
            docs_product_requires_spec_evidence:
              status: pass
              evidence: []
            tasks_md_not_direct_source:
              status: pass
              evidence: []
            specify_not_canonical:
              status: pass
              evidence: []
            diff_first_rationale_present:
              status: pass
              evidence: []
            generated_task_trace_present:
              status: pass
              evidence: []
            task_dependencies_materialized:
              status: pass
              evidence: []
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings: []
    body_sha256: sha256:221825b4175c7f62420d39a54c2db8a8375a708a922a1baa0a9eb6c2315da60f
    • Outcome: hooks tests を directory discovery で CI 実行し、未登録 test の再発を workflow 側で検出できる状態にする
    • Acceptance Criteria: AC1-AC5
    • Verification Commands: rg 5 本とも baseline fail expected を確認済み
    • Allowed Paths: .github/workflows/ci.yml
    • Worktree: .claude/worktrees/issue-682-hook-test-discovery
    • Branch: worktree-issue-682-hook-test-discovery
    • VC preflight: baseline fail = 5, 想定外 pass = 0, 実行不可 = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerarea/ai-opsenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions