Skip to content

chore(ci): test_pr_body_validator.py を python-test plan に登録し #1156 を unblock する (#1164) - #1168

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-1164-test-pr-body-validator-py-python-test-pl
Jun 26, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-1164-test-pr-body-validator-py-python-test-pl

Conversation

@squne121

Copy link
Copy Markdown
Owner

Summary

test_pr_body_validator.py を python-test plan に登録し、#1156 のブロッカーを解消します。

変更ファイル(3 ファイル)

  • .github/ci/python-test-plan.json: targets 配列に "scripts/tests/test_pr_body_validator.py" を exactly once 追加。targets 以外(ignore/deselect/xdist/parallel_exclude/notes 等)は変更なし。
  • scripts/ci/tests/test_python_test_plan.py: test_real_plan_includes_pr_body_validator_exactly_once を追加。plan["targets"].count(path) == 1 および scope_argv(plan).count(path) == 1 を検証。
  • .claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.py: test_generate_artifact_pr_body_validator_is_covered を追加。scripts/tests/test_pr_body_validator.py を changed_files に含めた時に generator が正しく収集・カバレッジを確認することを回帰テスト。

テスト証跡

AC1/AC2: uv run --locked pytest -q scripts/ci/tests/test_python_test_plan.py
53 passed in 0.18s

AC3: uv run --locked pytest --collect-only -q scripts/tests/test_pr_body_validator.py
scripts/tests/test_pr_body_validator.py::test_wrapper_emits_error_code_for_parse_failure
scripts/tests/test_pr_body_validator.py::test_wrapper_schema_change_flag_mismatch
scripts/tests/test_pr_body_validator.py::test_wrapper_success_path_outputs_json_only
scripts/tests/test_pr_body_validator.py::test_wrapper_emits_error_code_for_missing_safety_claim_matrix
scripts/tests/test_pr_body_validator.py::test_wrapper_schema_change_flag_requires_inventory_when_body_decision_invalid
5 tests collected in 0.01s

AC4: uv run --locked pytest -n 4 --dist loadscope -q scripts/tests/test_pr_body_validator.py
5 passed in 0.42s

AC5/AC7/AC8: uv run --locked pytest -q scripts/ci/tests/test_python_test_plan.py .claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.py
67 passed in 0.21s

この PR は #1164 を解決します(Closes #1164)。関連 PR: #1138, #1156 参照。

Checks

全ての必須 VC を worktree で実行し通過を確認しました。

  • uv run --locked pytest -q scripts/ci/tests/test_python_test_plan.py — 53 passed(AC1/AC2)
  • uv run --locked pytest --collect-only -q scripts/tests/test_pr_body_validator.py — 5 tests collected(AC3)
  • uv run --locked pytest -n 4 --dist loadscope -q scripts/tests/test_pr_body_validator.py — 5 passed(AC4)
  • uv run --locked pytest -q scripts/ci/tests/test_python_test_plan.py .claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.py — 67 passed(AC5/AC7/AC8)
  • pnpm typecheck — テスト/JSON のみ変更のため省略(TypeScript 非対象)
  • pnpm lint — テスト/JSON のみ変更のため省略
  • pnpm test — テスト/JSON のみ変更のため省略
  • pnpm build — テスト/JSON のみ変更のため省略

Schema Change Applicability

スキーマ変更はありません(テストファイルと plan JSON のみ)。

  • decision: not_schema_change
  • 補足: スキーマ変更なし

Schema Consumer Inventory

スキーマ変更がないため、Consumer Inventory は不要です(N/A)。

Safety Claim Matrix

安全性に影響するパスの変更はありません(テストファイルと plan JSON のみ)。

Claim Implemented? Not controlled Evidence Follow-up
python-test plan の targets にテストを追加することで CI が回帰テストを実行する yes - 全 pytest VC pass(53/5/5/67) -

Notes

🤖 Claude Code により生成 — Claude Code

…unblock する (#1164)

- .github/ci/python-test-plan.json: targets に scripts/tests/test_pr_body_validator.py を exactly once 追加
- scripts/ci/tests/test_python_test_plan.py: exactly-once 回帰テストを追加
- .claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.py: generator 回帰テストを追加

Closes #1164
Refs #1138, #1156

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions

github-actions Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1168/

The preview will be removed when this PR is closed.

@squne121

Copy link
Copy Markdown
Owner Author

PR Review: #1168 — test_pr_body_validator.py を python-test plan に登録

レビュー対象: #1168
Contract Snapshot: #1164 (comment)

Allowed Paths Gate(review_subagent 独立計算)

変更ファイル(実測): .github/ci/python-test-plan.json, scripts/ci/tests/test_python_test_plan.py, .claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.py

全 3 ファイルが Allowed Paths 内。スコープ外ファイル: なし。gate: ok

contract binding: body_sha256=sha256:3dccdb547e3fcc8dcb1ff7803588c0207ba978f6f925884dd9936bc4338bd462(issuecomment-4804461466)

AC 結果

AC1 pass — test_real_plan_includes_pr_body_validator_exactly_once が存在, count(path)==1 両軸 assert, 53 passed
AC2 pass — loader path validation, 53 passed
AC3 pass — control-plane VC: 5 tests collected
AC4 pass — control-plane VC: -n 4 --dist loadscope 5 passed
AC5 pass — test_generate_artifact_pr_body_validator_is_covered が 6 フィールド全 assert, 67 passed
AC6 pass — CI check-run python-test conclusion=success(review_subagent API 直接確認)
AC7 pass — JSON パッチは targets への 1 行追加のみ、他フィールド変更なし
AC8 pass — base SHA は main(#1160 マージ済み)から正しく分岐

CI チェック(全 success)

python-test, test, build, typecheck, lint, node-backed-hook-tests, check-hook-integrity, validate-generated-artifact, PR Body Japanese Check, actionlint, e2e, ci-verdict-summary — 全て success

ブロッカー

なし。

LOOP_VERDICT_V2:
verdict: APPROVE
merge_ready: true
merge_state_status: BEHIND
mergeable: MERGEABLE
required_auto_actions: []
blockers: []
pr_number: 1168
head_sha: 08b9512
reviewed_head_sha: 08b9512
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
contract_source_kind: issue_comment
contract_source_id: 4804461466
expected_contract_fingerprint: sha256:3dccdb547e3fcc8dcb1ff7803588c0207ba978f6f925884dd9936bc4338bd462
out_of_scope_files: []

@squne121

Copy link
Copy Markdown
Owner Author

結論

総合判定は REQUEST_CHANGES / merge_ready: false です。

ただし、判定を分解すると次の通りです。

  • 3ファイルの実装差分そのものには、現在のCI実行を壊す P0/P1 の不具合は見つかりませんでした。
  • 変更された回帰テストには、将来の配線不良を偽陰性にできる P2 の弱点があります。小さい修正で補強できます。
  • マージ証跡は現時点で成立していません。既存の APPROVE コメントは旧HEAD 08b9512… に結び付いていますが、現在HEADは 9fe8723… です。さらに現在HEADの配布済み ci_verdict_summary_v2 artifact 自身が stale_head_sha を返しています。PRは現在もDraftです。

Findings

P1 — マージ判定artifactと緑のcheckが矛盾している

現在HEAD 9fe8723… の全workflowはGitHub上で success になっています。

一方、同じrunから実際に配布された ci_verdict_summary_v2.json を解析すると、次の状態でした。

expected_head_sha: 9fe8723fff42033c4e199237c26d05614e89ad0f
head_sha: null
overall_status: stale_head_sha
next_action: refresh_head_sha
artifact_refs: []

さらに全required jobが success であるにもかかわらず、head_sha=null のためblocking扱いです。node-backed-hook-tests は classification=unknown となり、failure_reason=gh_error になっています。

[解析対象のcurrent-head verdict artifact](sandbox:/mnt/data/pr-1168-ci-verdict-summary-9fe8723.zip)
[解析結果を正規化したJSON](sandbox:/mnt/data/pr-1168-adversarial-review-evidence.json)

これは偶発的なrun不良ではなく、現行実装から必然的に発生します。

  1. workflowは各jobについて needs.<job>.result だけをgeneratorへ渡し、--pr-head-sha は渡していません。artifactを一度uploadした後、artifact ID・URL・digestを付けてローカルJSONを再生成していますが、その再生成版は再uploadしていません。
  2. generatorは needs_result_synthetic のcheckについて、意図的に head_sha=None とします。required/evidence checkが success でも head_sha=None なら stale_head_sha と判定します。したがって、現在のworkflow入力方式では正常runでも merge_ready に到達できません。
  3. generatorのmain()は overall_status に関係なく常に終了コード0を返します。そのため、artifactが stale_head_sha や gh_error でも ci-verdict-summary check自体は緑になります。
  4. node-backed-hook-tests はworkflowの needs に追加されていますが、CLASSIFICATION_MAP に存在しません。未登録checkは unknown となり、保守的に gh_error でblockingになります。
  5. artifact-id、URL、SHA-256 digestはupload完了後に初めて得られます。また現行のupload-artifactでは作成済みartifactはimmutableです。そのため、同じartifact内に自分自身の最終digestを後から埋め戻す現在の設計は成立しません。 ([GitHub]1)

Issue #898 は本来、AIによるmerge-ready判定の誤読を減らし、head SHA一致やartifact refsを機械可読化する目的でした。しかし、現在の配布物はその目的と逆の状態です。

修正方針

これは #1168 の3ファイル差分で直すべきではなく、独立Issueに切り出すべきです。

  • ("ci", "node-backed-hook-tests") を evidence または required として登録し、必要なら REQUIRED_CHECKS にも追加する。
  • needs.result を使うなら、「同一workflow runに属するjob結果を当該PR headとmerge SHAへ結び付ける」というprovenanceを明示的に定義する。あるいはGitHub APIから実check/job metadataを取得する。
  • schemaには少なくとも pr_head_sha と merge_sha を分離して保持する。PR workflowはmerge refをcheckoutするため、両者は異なるのが正常です。 ([GitHub Docs]2)
  • generatorを report と gate の2モードに分ける。gateとして使う場合は、merge_ready 以外で非0終了にする。report専用なら、緑のcheckをmerge-ready証拠として扱わないことを名称・consumer契約で明示する。
  • artifactを二段構成にする。
ci-verdict-payload
  └─ 判定本体。自己参照するartifact ID/digestは含めない

ci-verdict-envelope
  ├─ payload artifact-id
  ├─ payload artifact-url
  ├─ payload artifact-digest
  ├─ pr_head_sha
  └─ merge_sha

この構成ならimmutable artifactと整合します。


P2 — 追加されたgenerator回帰テストがcollector配線の破損を検出できない

追加テストは、get_pytest_collected_tests を次のようなstubへ差し替えています。

monkeypatch.setattr(
    gen,
    "get_pytest_collected_tests",
    lambda argv: (
        [changed_file],
        [invented_nodeids...],
        success_status,
    ),
)

このlambdaは受け取った argv を検査せず、常に対象ファイルが収集されたことにします。したがって将来、次のような不具合が入ってもこのテストは緑のままです。

  • generatorがplan由来のargvをcollectorへ渡さなくなる
  • collectorへ誤ったargvを渡す
  • --ignore / --deselect の組み立てで対象ファイルが実際には収集されなくなる
  • 対象ファイルがpytest上で0 nodeidになる

最後の

assert artifact["pytest_argv"].count(changed_file) == 1

は、artifactに文字列が含まれることしか確認しておらず、そのargvで収集したことまでは証明しません。

最低限、stubが受け取ったargvを捕捉してartifactとの同一性を固定すべきです。

seen: dict[str, list[str]] = {}

def fake_collect(argv):
    seen["argv"] = list(argv)
    assert seen["argv"].count(changed_file) == 1

    nodeids = [
        f"{changed_file}::test_wrapper_emits_error_code_for_parse_failure",
        f"{changed_file}::test_wrapper_schema_change_flag_mismatch",
        f"{changed_file}::test_wrapper_success_path_outputs_json_only",
        f"{changed_file}::test_wrapper_emits_error_code_for_missing_safety_claim_matrix",
        f"{changed_file}::test_wrapper_schema_change_flag_requires_inventory_when_body_decision_invalid",
    ]
    return (
        [changed_file],
        nodeids,
        {
            "returncode": 0,
            "timed_out": False,
            "error": None,
            "nodeid_count": len(nodeids),
            "stderr_tail": "",
            "ok": True,
        },
    )

monkeypatch.setattr(gen, "get_pytest_collected_tests", fake_collect)

rc = gen.generate_artifact(args)
artifact = json.loads(out.read_text())

assert rc == 0
assert seen["argv"] == artifact["pytest_argv"]
assert seen["argv"].count(changed_file) == 1
assert artifact["collection_status"]["nodeid_count"] == 5
assert artifact["collected_test_files"] == [changed_file]
assert artifact["uncovered_changed_test_files"] == []

また、個別テストではなくCIの共通invariantとして、明示的なファイルtargetについて次を検証する方が堅牢です。

plan内の明示ファイルtarget
    ⊆
実際に1件以上のnodeidを生成したcollected_test_files

pytestはファイル・ディレクトリ・nodeidをCLIで選択でき、pytest --collect-only -q の出力を選択リストとして使うことを公式にサポートしています。したがって、このinvariantはpytestの公開動作に沿っています。 ([pytest ドキュメント]3)


P3 — 変更テスト検出がrenameを無視する

既存generatorは次のコマンドで変更テストを取得しています。

git diff base...head --name-only --diff-filter=ACM

ACM は追加・コピー・変更のみで、renameの R を含みません。

Git公式仕様でも R は独立したstatusです。したがって、ディレクトリtarget配下のテストが計画外へrenameされた場合などに、変更テストとして検出されずfalse-greenになる余地があります。 ([Git]4)

これは #1168 が導入した問題ではなく、別follow-upでの対応が妥当です。

git diff \
  --find-renames \
  --name-status -z \
  --diff-filter=ACMR \
  base...head

あわせて以下のnegative testが必要です。

  • plan内からplan外へのrename
  • plan外からplan内へのrename
  • file targetのrename
  • directory target内でのrename

なお base...head 自体は、両者のmerge baseからhead側までを比較するGitの正規の三点diffです。 (Git)


P3 — PR本文の分類が不正確

PR本文では #1138 と #1156 を「関連PR」としていますが、両方ともIssueです。実際の関連実装PRには少なくとも #1159、#1151、#1160、#766 があります。

また、「安全性に影響するパスの変更はありません」という説明は強すぎます。.github/ci/python-test-plan.json は製品runtimeの安全境界ではありませんが、どの回帰テストをmerge gateで実行するかを決めるCI control planeです。

より正確な記載は次です。

runtime_product_safety_boundary:
  modified: false

ci_workflow_gate:
  modified: true
  change: additive_test_target_only
  targets_removed: []
  ignore_or_deselect_changed: false
  xdist_configuration_changed: false
  evidence:
    - real-plan exact-once test
    - current-head ci_test_selection artifact
    - current-head JUnit manifest

Current-headで確認できた正常点

実装差分

planへの変更は対象ファイル1行の追加だけです。plan構造、ignore、deselect、xdist、parallel exclusionにはPR差分上の変更がありません。

real-plan testも、targets と scope_argv の両方についてexactly onceを確認しています。

実際のselection artifact

current-headの配布artifactを解析した結果は次の通りです。

pr_head_sha: 9fe8723fff42033c4e199237c26d05614e89ad0f
checked_out_sha: 581ec59d74fcfef990d8c7484347af3b0e7bf475
merge_sha: 581ec59d74fcfef990d8c7484347af3b0e7bf475

collection_status:
  ok: true
  nodeid_count: 4496

target:
  pytest_argv_count: 1
  present_in_collected_test_files: true
  collected_nodeids: 5

uncovered_changed_test_files: []

artifactはcurrent headに紐付き、GitHub上のSHA-256 digestとダウンロードZIPのSHA-256が一致しました。

[ci_test_selection current-head artifact](sandbox:/mnt/data/pr-1168-ci-test-selection-9fe8723.zip)

実際のJUnit

current-headのJUnitでは、対象ファイルの実在する5テストがすべて成功しています。

python_test_manifest:
  parallel_junit_testcases: 4496
  serial_junit_testcases: 0
  executed_total: 4496
  scope_collected_nodeids: 4496
  union_equals_scope: true

xdist:
  resolved_workers: 4
  configured_workers: 4
  scheduler: loadscope
  xdist_version: 3.8.0

test_pr_body_validator:
  passed: 5
  failed: 0
  errors: 0

GitHub artifactのdigestとも一致しました。

[python-test JUnit current-head artifact](sandbox:/mnt/data/pr-1168-python-test-junit-9fe8723.zip)

loadscope は関数テストをmodule単位でまとめ、同一groupを同一workerで実行するschedulerです。対象テストは一時ファイルをテストごとに作り、subprocessでwrapperを呼ぶ構造で、実測でも4 worker実行を通過しています。 ([pytest-xdist]5)

uv run --locked は uv.lock が最新で変更不要であることを要求し、欠落・更新必要時にはエラーにするため、依存関係再現性の指定として妥当です。 ([Astral Docs]6)

head SHAとmerge SHAの差異

artifactの

pr_head_sha   = 9fe8723…
checked_out   = 581ec59…
merge_sha     = 581ec59…

は異常ではありません。pull_request workflowではGitHubがPR merge refを既定checkoutし、GITHUB_SHA はmerge commit、PR branch先端は github.event.pull_request.head.sha になります。 ([GitHub Docs]2)


関連Issue・PRの因果関係

このPRの背景は妥当です。

  1. PR feat: add pr body validator wrapper (#469) #766 で scripts/pr_body_validator.py と scripts/tests/test_pr_body_validator.py が追加されました。
  2. PR 実装: python-test を pytest-xdist 並列化(plan SSOT / serial 統合 / generator fail-close)(#1064) #1151 でpython-test対象が .github/ci/python-test-plan.json のSSOTへ移され、xdist実行と ci_test_selection fail-closeが導入されました。
  3. Issue 実装: scripts の E501 cleanup(既存 *.py の行分割のみ・#1138 Child 3) #1156 / PR fix: scripts/ の E501 diagnostic を行分割で解消(#1138 Child 3)(#1156) #1159 のE501 cleanupで、このテストがplan未登録であるため変更後の回帰検証を保証できないことがブロッカーになりました。
  4. Issue chore(ci): test_pr_body_validator.py を python-test plan に登録し #1156 を unblock する #1164 の初期レビューは、planへの1行追加だけでは changed_test_files に対象が現れず、ACがfalse-passし得るとして、ファイル固有のgenerator回帰テストを要求しました。今回のPRはその要求を実装しています。
  5. PR test(#1141): debounce wall-clock非依存化・serial quarantine解消 #1160 でdebounceテストのserial quarantine解除とnode-backed job追加が行われています。#1168がそのplan状態を保持していること自体は確認できました。

したがって、対象テストをplanへ登録する変更の必要性と方向性は正しいです。


最終レビュー判定

ADVERSARIAL_REVIEW:
  pr_number: 1168
  reviewed_head_sha: 9fe8723fff42033c4e199237c26d05614e89ad0f

  verdict: REQUEST_CHANGES
  merge_ready: false

  code_assessment:
    current_runtime_behavior: pass
    p0_findings: 0
    p1_code_findings: 0
    p2_findings:
      - generator regression stub does not bind collection to the supplied pytest argv

  merge_evidence:
    current_head_ci: success
    prior_approve_head_sha: 08b9512738b5285c10bf5c3c72cd86e2481cad0c
    prior_approve_is_current: false
    distributed_ci_verdict:
      overall_status: stale_head_sha
      next_action: refresh_head_sha
      artifact_refs_present: false

  required_before_merge:
    - strengthen the changed generator regression test so collector argv is asserted
    - rerun CI after that change
    - issue a fresh review bound to the resulting current head SHA

  separate_followups:
    - repair ci_verdict_summary_v2 provenance, classification, exit semantics, and artifact envelope design
    - include renamed tests in changed-test detection

検査資料

  • [Selection artifact](sandbox:/mnt/data/pr-1168-ci-test-selection-9fe8723.zip)
  • [JUnit artifact](sandbox:/mnt/data/pr-1168-python-test-junit-9fe8723.zip)
  • [Verdict artifact](sandbox:/mnt/data/pr-1168-ci-verdict-summary-9fe8723.zip)
  • [統合検査結果JSON](sandbox:/mnt/data/pr-1168-adversarial-review-evidence.json)

ローカルcheckoutによる独立再実行は実行環境の外向き通信制約で行っていません。代わりに、current-headのGitHub Actions配布artifactを取得し、JSON・JUnit XML・manifest・xdist metadata・ZIP SHA-256を直接検査しています。

OWNER REQUEST_CHANGES P2 対応:
- test_generate_artifact_pr_body_validator_is_covered の stub を
  lambda から fake_collect 関数へ変更
- fake_collect が受け取った argv を seen["argv"] に保存し、
  changed_file が exactly once 含まれることを即時 assert
- 実際の test_pr_body_validator.py の 5 nodeid(実名)を使用
- artifact["collection_status"]["nodeid_count"] == 5 を追加
- artifact["collected_test_files"] == [changed_file] を厳密な等価へ変更
- seen["argv"] == artifact["pytest_argv"] を assert(argv バインド証明)

これにより、generator が collector に誤った argv を渡すバグを
テストが偽陰性にできなくなる。
@squne121

squne121 commented Jun 25, 2026 •

Copy link
Copy Markdown
Owner Author

PR #1168 iter1 レビュー — review_subagent / Sonnet 4.6

Allowed Paths Gate

変更ファイル(実測 git diff base..head):

  • .github/ci/python-test-plan.json
  • scripts/ci/tests/test_python_test_plan.py
    .claude/skills/pr-review-judge/scripts/tests/test_generate_ci_test_selection_fail_close.py
    全 3 ファイルが Allowed Paths 内。スコープ外: なし。gate: ok
    Contract fingerprint: sha256:3dccdb547e3fcc8dcb1ff7803588c0207ba978f6f925884dd9936bc4338bd462

AC 結果

iter0 全 AC pass 確認済み(head 08b9512 でレビュー済み)。P2 Blocker のみ残存。
iter1 P2 fix: test_generate_artifact_pr_body_validator_is_covered の stub を
lambda から fake_collect 関数へ変更。argv capture + pytest_argv binding 両立。

CI チェック(head 94d6c17 時点 全 success)

python-test, test, build, typecheck, lint, e2e, node-backed-hook-tests, ci-verdict-summary,
validate-generated-artifact, PR Body Japanese Check — 全て success

総合判定: APPROVE

P2 Blocker 解消確認。全 AC pass。ブロッカーなし。merge_ready: true
LOOP_VERDICT_V2:
verdict: APPROVE
merge_ready: true
merge_state_status: CLEAN
mergeable: MERGEABLE
required_auto_actions: []
blockers: []
pr_number: 1168
head_sha: 94d6c17
reviewed_head_sha: 94d6c17
contract_source_kind: issue_comment
contract_source_id: "4804461466"
expected_contract_fingerprint: "sha256:3dccdb547e3fcc8dcb1ff7803588c0207ba978f6f925884dd9936bc4338bd462"
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
out_of_scope_files: []
iter: 1
iteration_delta: P2 fix stub argv capture plus pytest_argv binding assertion

@squne121
squne121 marked this pull request as ready for review June 26, 2026 13:06
@squne121
squne121 merged commit 2c280ce into main Jun 26, 2026
18 checks passed
@squne121
squne121 deleted the worktree-issue-1164-test-pr-body-validator-py-python-test-pl branch June 26, 2026 13:06
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.

chore(ci): test_pr_body_validator.py を python-test plan に登録し #1156 を unblock する

1 participant