Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "pytest baseline-fail VC を canonical form へ決定論的に正規化し、contract-review の VC 表現往復を削減する"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: Issue author が最初から canonical な baseline-fail VC を生成できる状態にする
- Desired Destination: VC shape 起因の contract-review 往復ゼロ化
Current Validated Scope
.claude/skills/issue-contract-review/scripts/vc_baseline_shape_compiler.py(新規)で pytest baseline-fail command を canonical form に変換.claude/skills/edit-issue/scripts/issue_contract_hygiene_autofix.pyの autofix 対象に VC baseline shape を追加.claude/skills/create-issue/references/body-authoring.mdに canonical table を追記- compiler のテスト追加
Remaining Parent Gaps
- reviewer_claim_replay の taxonomy parity は別 Issue で扱う
- Issue metadata mutation の controlled executor 化は別 Issue で扱う
Runtime Verification Applicability
- decision: not_applicable
- reason: 静的検証(typecheck / lint / unit test / build)のみで完結し、プロセス起動・通信・I/O は不要(compiler script 追加、AST 静的解析、unit test 追加、docs 追記のみ)
Outcome
pytest baseline-fail VC の非 canonical 形(既存 test file への -k <未作成関数> 指定、既存 file への missing node-id 指定)が vc_baseline_shape_compiler.py により machine-readable な rewrite hint(未作成 test file の node-id 形式)へ決定論的に変換され、compiler テストが CI で PASS している状態。
Background
#1277 の contract-review では VC 表現だけで 3 回の修正往復が発生した。既存ファイルに対する -k <未作成関数> は pytest exit 5 で vc_no_tests_collected として hard block、既存ファイルへの missing node-id は判定不能、最終的に「まだ存在しない新規 test file の node-id」で expected baseline fail になった。baseline_vc_preflight.py は pytest exit 4 かつ stderr が file or directory not found に一致する場合のみ expected baseline fail とする。この保守的挙動は維持し、author 側が canonical form を最初から生成できるよう compiler を追加する。
Scope Clarifications
baseline_vc_preflight.pyの pytest exit code contract は変更しない。- exit 4 +
file or directory not foundのみ expected baseline fail。 - exit 5
no tests collectedはvc_no_tests_collectedhard block のまま。
- exit 4 +
- 既存テスト
test_pytest_exit5_no_tests_collected_expected_fail(exit 5 を expected_baseline_fail/go と期待)は現行baseline_vc_preflight.pyの実装(exit 5 を常に vc_no_tests_collected/blocked に分類)と矛盾しているため、本 Issue の実装スコープ内で現行契約に合わせて更新・削除する。 -krewrite は単一 baretest_*identifier のみを対象にする。- boolean expression(
and/or/not)/ class selector / parametrized selector / quoted complex expression はnot_autofixableとして rewrite しない。
- boolean expression(
- existing file の missing node-id 判定は pytest 実行に依存せず、
ast.parse()による静的解析(top-leveldef test_*/class Test*)に限定する。class/method や parametrization はnot_autofixableとする。 - suggested missing-file node-id は、baseline で存在しない・Allowed Paths 内・
*.py::test_*形式の場合のみ生成する。安全な候補を作れない場合は rewrite しない。既存候補と衝突する場合は deterministic suffix を付与する。
In Scope
vc_baseline_shape_compiler.py新規追加。禁止形(existing_test_file +-k新規テスト名 / existing_test_file::missing_test_function)を検出し、canonical 形(missing_new_test_file.py::test_name)のsuggested_commandを machine-readable JSON で返すissue_contract_hygiene_autofix.pyの autofix 対象へ VC baseline shape 変換を追加body-authoring.mdに短い canonical table(禁止形 / 推奨形 / 理由)を追記- compiler の unit テスト追加(既存 CI target set である
.github/ci/python-test-plan.jsonに既に含まれるディレクトリ配下に配置するため追加登録は不要)
Out of Scope
baseline_vc_preflight.pyの exit code 判定契約の変更(exit 5 hard block は維持)- issue-author SubAgent 定義自体の書き換え
- pytest 以外の VC 種別(rg / diff 等)の正規化
Acceptance Criteria
- AC1:
existing_test_file.py -k test_new_nameは、test_new_nameが単一 bare identifier の場合のみ、Allowed Paths 内の missing-file node-id への rewrite hint(suggested_command)を返す - AC2:
existing_test_file.py::test_missing_nameは、AST 静的解析で missing と確認できる単純 function node-id の場合のみ canonical missing-file node-id への rewrite hint を返す - AC3: complex
-kexpression(boolean / class selector / parametrized selector)または Allowed Paths 外候補の場合はnot_autofixableを返し、body を変更しない - AC4:
missing_new_test_file.py::test_nameはalready_canonicalと判定され、hygiene autofix は no-op になる - AC5:
issue_contract_hygiene_autofix.py経由で VC shape rewrite が適用され、2 回目実行は sha256 guard によりno_changeになる - AC6:
body-authoring.mdに markerpytest_baseline_fail_canonical_rulesを持つ canonical table が追加される - AC7: exit 5 を expected fail と見なす stale test(
test_pytest_exit5_no_tests_collected_expected_fail)が更新・削除され、baseline_vc_preflight.pyの exit 5 hard block 契約が regression しない
Verification Commands
# AC1
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pytest_vc_baseline_shape_compiler.py::test_ac1_dash_k_new_test_name_rewritten -q
# AC2
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pytest_vc_baseline_shape_compiler.py::test_ac2_missing_node_id_on_existing_file_rewritten -q
# AC3
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pytest_vc_baseline_shape_compiler.py::test_ac3_not_autofixable_complex_expression -q
# AC4
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pytest_vc_baseline_shape_compiler.py::test_ac4_missing_file_node_id_already_canonical -q
# AC5
$ uv run --locked pytest .claude/skills/issue-contract-review/tests/test_pytest_vc_baseline_shape_compiler.py::test_ac5_hygiene_autofix_applies_vc_shape_then_no_change -q
# AC6
$ rg -c "pytest_baseline_fail_canonical_rules" .claude/skills/create-issue/references/body-authoring.md
# 補足: 本 Issue 実装後は旧テスト名が更新/削除される想定。実装前は現行ファイルへの参照として baseline 実行する
# AC7
$ uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k test_pytest_exit5_no_tests_collected_expected_fail -qAllowed Paths
- .claude/skills/issue-contract-review/scripts/vc_baseline_shape_compiler.py
- .claude/skills/issue-contract-review/tests/
- .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py
- .claude/skills/edit-issue/scripts/issue_contract_hygiene_autofix.py
- .claude/skills/edit-issue/tests/
- .claude/skills/create-issue/references/body-authoring.md
- .claude/skills/issue-contract-review/scripts/tests/fixtures/pytest_exit5_no_tests.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
なし
Scope Delta(任意)
- 追加日: 2026-07-03
- 追加パス:
.claude/skills/issue-contract-review/scripts/tests/fixtures/pytest_exit5_no_tests.md - 理由: AC7 で stale test
test_pytest_exit5_no_tests_collected_expected_failを更新・削除する際、その専用フィクスチャ(main に feat: scope rollup result を self-validating 化し verify を 1 コマンドに集約する #850 由来で既存)も不要になり削除が必要だったため。Scope Clarifications で既に許可されている stale test 更新に直接付随する削除であり、Allowed Paths への列挙漏れを補うもの。
Notes for Reviewer
- compiler は advisory でなく hygiene autofix に配線するところまでを本 Issue の完了条件とする
baseline_vc_preflight.pyの既存判定(exit 4 + not-found stderr のみ expected_baseline_fail)は変更しない- Allowed Paths から
scripts/python-test-plan.jsonを削除した。既存 CI target SSOT である.github/ci/python-test-plan.jsonには.claude/skills/issue-contract-review/tests/、.claude/skills/issue-contract-review/scripts/tests/、.claude/skills/edit-issue/tests/test_issue_contract_hygiene_autofix.pyが既に含まれており、追加登録は不要である。
compiler output schema(固定):
{
"schema": "vc_baseline_shape_compiler/v1",
"status": "changed | already_canonical | not_autofixable | invalid_input",
"rewrites": [
{
"ac": "AC1",
"line_number": 12,
"reason_code": "pytest_dash_k_new_test_on_existing_file",
"original_command": "...",
"suggested_command": "...",
"confidence": "high"
}
],
"errors": [],
"warnings": []
}Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jul 3, 2026
判定: REQUEST_CHANGES
#1285 の方向性は正しいです。
pytest baseline-fail VCの表現ゆれを author 側で canonical 化し、contract-review の往復を減らす狙いは妥当です。Issue 本文も、baseline_vc_preflight.pyの保守的契約を変えず、author 側に compiler を追加する方針を明示しています。コメントは現時点で 0 件でした。ただし、この Issue のまま実装に流すと、Allowed Paths / CI 登録 / pytest selector 解釈 / hygiene autofix 境界で破綻する可能性が高いです。実装前に Issue 本文を修正すべきです。
Blocking findings
1.
scripts/python-test-plan.jsonは危険な誤パス#1285 は
scripts/python-test-plan.jsonの登録を要求していますが、実在する python-test plan の SSOT は.github/ci/python-test-plan.jsonです。このファイル自身も「python-test job の pytest target set の SSOT。変更時はこのファイルを編集」と説明しています。さらに、その SSOT にはすでに
.claude/skills/issue-contract-review/tests/、.claude/skills/issue-contract-review/scripts/tests/、.claude/skills/edit-issue/tests/test_issue_contract_hygiene_autofix.pyが含まれています。新規テストをこの既存ディレクトリ配下に置くなら、追加登録は不要な可能性が高いです。修正: Issue から
scripts/python-test-plan.jsonを削除する。CI plan の変更が本当に必要なら、Allowed Paths に.github/ci/python-test-plan.jsonを追加し、なぜ既存 target では足りないのかを明記する。2. pytest exit code 契約は正しいが、Issue は stale test との矛盾を潰していない
pytest 公式では exit code 4 は command line usage error、exit code 5 は no tests collected です。pytest は
-kに keyword expression を使い、node-id はfile.py::test_funcのような形式を取ります。([pytestドキュメント]1) ([pytestドキュメント]2)現行
baseline_vc_preflight.pyは、pytest exit 4 かつfile or directory not foundだけをexpected_baseline_fail/goにし、pytest exit 5 はvc_no_tests_collected/blockedにしています。これは #1285 の背景説明と一致します。一方で、既存テスト側には
test_pytest_exit5_no_tests_collected_expected_failという、exit 5 をexpected_baseline_fail/goと期待するテストが残って見えます。これは現行 classifier と矛盾します。修正: #1285 に「exit5 expected_fail を期待する stale test が残っていれば更新・削除する」を明記する。ここを放置すると、実装者が古いテストに合わせて
baseline_vc_preflight.pyを逆戻りさせるリスクがあります。3.
-k <未作成関数>の rewrite 条件が粗すぎるpytest の
-kは単一関数名ではなく keyword expression です。-k "test_new and not slow"、-k "foo or bar"、-k "ClassName and method"のような表現を compiler が勝手に node-id 化すると、意味を壊します。pytest 公式も-kを “keyword expression” として説明しています。([pytestドキュメント]2)修正: compiler の対象を strict subset に限定する。
-k test_<identifier>の単一 bare identifier のみand/or/not/ parentheses / quotes / wildcard 風文字列 / class 名 / parameterized selectorstatus=not_autofixable,reason_code=complex_k_expression4. existing file の missing node-id 判定は、pytest 実行でなく静的解析に寄せるべき
#1285 は「existing file への missing node-id 指定を rewrite」としていますが、ここを pytest 実行で判定すると、テスト import の副作用、依存欠落、環境差で compiler が不安定になります。現行 preflight は
shlex.splitで argv 化しshell=Falseで実行しているため、安全境界を強く意識しています。修正:
vc_baseline_shape_compiler.pyは原則として実行系にしない。既存.pyfile はast.parse()で top-leveldef test_*とclass Test*を静的に読む。今回の AC2 はまずexisting_file.py::test_missing_funcの単純形だけに限定し、class/method や parametrization はnot_autofixableにする。5. canonical missing-file path の生成規則が未定義
「未作成 test file の node-id 形式へ rewrite」とありますが、どの missing file を作るのかが未定義です。compiler が勝手に
tests/test_foo.pyを作る提案を出すと、Allowed Paths 外・既存ファイル衝突・命名不整合を起こします。修正: suggested path の規則を明示する。
推奨規則:
ただし、以下を必須条件にする。
*.py::test_*test_<slug>_<8char_command_hash>_contract.py::test_<name>のように deterministic suffix を使う6. hygiene autofix は現状 C4/C9 専用で、VC shape 修正を入れる境界が足りない
issue_contract_hygiene_autofix.pyは現状、C4$ prefixと C9 Runtime Verification Applicability の deterministic autofix だけを扱う設計です。exit code も repaired / no_change / not_autofixable の三値に近い契約です。main flow も、non-C4/C9 blocker check → C4 repair → C9 repair → sha256 guard という順序です。ここに VC shape compiler を雑に差し込むと、非 C4/C9 blocker の文字列 filter と干渉します。
修正: VC shape 修正は独立ステップにする。
推奨順序:
追加すべき hygiene tests:
-kは exit 2 not_autofixable7. machine-readable JSON schema が Issue にない
#1285 は “machine-readable JSON” と書いていますが、schema がありません。これでは downstream が
suggested_commandだけ拾う実装になり、複数 VC・部分 rewrite・非 autofixable 理由・source span を扱えません。修正: compiler output を固定する。
{ "schema": "vc_baseline_shape_compiler/v1", "status": "changed | already_canonical | not_autofixable | invalid_input", "rewrites": [ { "ac": "AC1", "line_number": 12, "reason_code": "pytest_dash_k_new_test_on_existing_file", "original_command": "uv run --locked pytest existing.py -k test_new -q", "suggested_command": "uv run --locked pytest missing_contract_file.py::test_new -q", "confidence": "high" } ], "errors": [], "warnings": [] }関連 Issue / PR からの品質基準
#1277 → PR #1278 の流れは、この種の workflow 修正の品質基準として有用です。PR #1278 は producer 契約を壊さず builder 境界で projection し、投影不能要素を fail-closed にし、end-to-end schema validation と fail-closed tests を追加しています。
#1285 も同じ基準に揃えるべきです。つまり「preflight の exit code 契約を変えない」「author/hygiene 側で deterministic projection する」「不明な selector は silent rewrite しない」「compiler 単体テストだけでなく hygiene 経由の body rewrite test を持つ」が最低ラインです。
Issue 本文への修正案
#1285 は以下を追記・修正してください。
改訂 Acceptance Criteria
AI エージェント向け修正プロンプト
この Issue は「実装してよいが、Issue 本文を先に直すべき」です。特に
python-test-planパス誤りと exit5 stale test 矛盾は、後で PR レビュー往復を増やす直接原因になります。squne121 commentedon Jul 3, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 3, 2026
Contract Review Result
squne121 commentedon Jul 3, 2026
implement-issue: 実装完了 (2026-07-04)
.claude/worktrees/issue-1285-vc-baseline-canonicalworktree-issue-1285-vc-baseline-canonicalfix: CI 指摘の Ruff E501 / Japanese Check 違反を解消 (#1285)
fix: pytest_exit5 fixture を Allowed Paths 内の tests/fixtures に移動 (#1285)
squne121 commentedon Jul 3, 2026
Contract Review Result (re-materialized after Scope Delta)
fix: PR #1305 review iteration 4 の実装欠陥を解消する (#1285)
feat: VC baseline-fail pytest command を canonical form に正規化する compile…
fix: baseline_vc_preflight.py の既存ファイル missing node-id 誤分類を修正 (#1366)
feat: baseline_vc_preflight に baseline-expect:fail escape hatch を追加する (…