Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
goal_ref: "baseline_vc_preflight.py の classify_result に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加し、pytest baseline preflight が human_judgment 落ちしないようにする"
change_kind: feat
parent_issue: 244
runtime_verification_applicability:
decision: not_applicable
rationale: "classifier 関数の追加で UI / Canvas / systems 層に影響しない。単体テスト + baseline_vc_preflight 再実行で完結"Parent Issue
Parent Goal Ref
#244 は Issue/PR body authoring を validate_issue_body.py / validate_pr_body.py / baseline_vc_preflight.py で機械検証し、AI に最小コンテキストを渡す構想の親トラッカー。本 Issue は Track B であり、baseline_vc_preflight.py の分類器品質改善を通じて pytest baseline fail を正しく認識させることで、preflight が human_judgment 落ちを避けることが目標。
Current Validated Scope
.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py の classify_result() 関数に対し、以下を追加:
- pytest invocation を argv/token ベースで検出(
shlex.split()+ unwrap uv run) - exit 4 +
ERROR: file or directory not found:→expected_baseline_fail / go - exit 5 + (no tests ran | no tests collected | collected 0 items) →
expected_baseline_fail / go - negative test で pytest invocation 外、CLI usage error ケースを excluded とし、過度な緩和を防ぐ
Remaining Parent Gaps
#244 closure 時点で以下が pending:
- Track A (実装: validate_issue_body.py を実装し GitHub Issue body を起票前に機械検証する — #244-A #327):
validate_issue_body.py/validate_pr_body.pyprewrite hook (merged in PR feat(#327): implement validate_issue_body.py with pre-write hook #367) - Track B (改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する #366):
baseline_vc_preflight.pyclassifier 拡張(本 Issue) - Track C (TBD): contract snapshot 自動取得・Schema Validation
Outcome
classify_result() が pytest invocation を argv 検出し、exit 4 (file not found) / exit 5 (no tests collected) を expected_baseline_fail/go に分類するよう拡張される。新カテゴリは追加せず既存 expected_baseline_fail を再利用。pytest fixture テストで positive (exit 4/5) + negative (CLI usage error / non-pytest command) ケースが全件 PASS する状態。top-level status / summary / result.decision が全体で status == pass / human_judgment == 0 を満たす。
Background
#327 (validate_issue_body.py 実装) の preflight で、未実装テストファイルを参照する pytest VC が exit 4 + ERROR: file or directory not found: を返し、現行 classifier は unknown / human_judgment に分類していた。impl-review-loop の前提を満たすため一時的に main で local patch を当てて preflight を pass させて先行実装に進んでいる。
ただし、pytest 公式ドキュメント (exit code reference) に従うと、exit 4 は command line usage error、exit 5 は no tests collected である。したがって、exit 4 + file not found と exit 5 + no tests collected を分離して扱うべき。
本 Issue では以下を反映:
- pytest exit code semantics を公式仕様に基づいて修正
- 実ログを fixture として取り込み(stash 参照ではなく)
- negative test を追加し、CLI usage error / non-pytest command による誤った go 判定を防ぐ
- argv ベース検出により
shlex.split()後の token を見て pytest invocation を判定
実際の stderr ログ(fixture化対象):
ERROR: file or directory not found: tests/nonexistent_test.py
In Scope
classify_result()内での pytest invocation 検出(argv/token ベース)- exit 4 +
ERROR: file or directory not found:のexpected_baseline_fail / go分類 - exit 5 + (no tests ran | no tests collected | collected 0 items) の
expected_baseline_fail / go分類 - positive test + negative test の新規追加(fixture ベース)
- top-level status / summary / result への影響検証(full preflight fixture)
- 既存 test regression なし
Out of Scope
- pytest 以外の test runner (nose, unittest, vitest 等)
expected_baseline_fail以外の新カテゴリ追加- 既存 classifier 構造の大規模リファクタリング
compute_confidence()の変更- fragment / summary 計算ロジックの変更
Acceptance Criteria
- AC1:
classify_result()は pytest invocation を argv/token ベースで検出。対象:pytest,python -m pytest,uv run pytest,uv run python -m pytest,uv run --locked pytest,uv run --with pytest pytestを含む。 - AC2: pytest invocation + exit 4 +
ERROR: file or directory not found:→classification == expected_fail,category == expected_baseline_fail,decision == go - AC3: pytest invocation + exit 5 + (
no tests ran|no tests collected|collected 0 items) →expected_baseline_fail / go - AC4: pytest invocation + exit 4 + CLI usage error (
unrecognized arguments, bad option 等) はexpected_baseline_fail / goにならない (negative test) - AC5: non-pytest command + exit 4 +
file or directory not foundはexpected_baseline_fail / goにならない (negative test) - AC6: pytest command + exit 0 は既存どおり
unexpected_pass / blockedのままで変わらない (regression check) - AC7: full preflight fixture で top-level
status == pass,summary.expected_fail >= 1,summary.human_judgment == 0,results[0].classification == expected_failを assert する - AC8: 既存
test_baseline_vc_preflight.py全件が pass する
Verification Commands
$ test -f .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py # AC1
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k pytest_invocation_detect # AC1
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k pytest_exit4_missing_file_expected_fail # AC2
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k pytest_exit5_no_tests_collected_expected_fail # AC3
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k pytest_exit4_usage_error_not_expected # AC4
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k non_pytest_exit4_not_expected # AC5
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k pytest_unexpected_pass_unchanged # AC6
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py -k full_preflight_pytest_baseline_fail_status_pass # AC7
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/ # AC8Required Skills
- none
Allowed Paths
.claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py.claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py.claude/skills/issue-contract-review/scripts/tests/fixtures/.github/workflows/ci.yml(iter 2 amend — 新規scripts/tests/を CI python-test job の merge gate に組み込むための不可分修正。pr-reviewer G1 ガード結果に従う)
Runtime Verification Applicability
decision: not_applicable
rationale: classifier 関数の追加で UI / Canvas / systems 層に影響しない。単体テスト完結。
Stop Conditions
- max_iterations: 3
- timebox_minutes: 60
- error_threshold: 2
- scope_creep: In Scope section の範囲を超える編集要求が発生した場合に停止
- security_signal: secret / auth 関連の変更が要求された場合に停止
- ambiguity: pytest exit code / argv parsing semantics が不明瞭な場合は停止して人間判断を仰ぐ
Delivery Rule
- 1 Issue = 1 PR を原則
- worktree:
.claude/worktrees/issue-366-pytest-classifier - PR format: Draft PR, linked to Issue 改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する #366
- Merge condition: all AC pass, existing test regression なし, code review approved
Source
- parent_issue: 導入: Issue/PR body authoring 機械検証化 親トラッカー — validator・linter・preflight スクリプトによる体系的品質保証 #244
- anchor_comment: 改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する #366 (comment)
- anchor_author: squne121 (OWNER)
- dedupe_key: classifier-pytest-exit4-5-2026-05
- generated_by: issue-refinement-loop anchor-application (2026-05-24)
Activity
squne121 commentedon May 24, 2026
Verdict: REQUEST_CHANGES
#366 の問題意識は妥当です。
baseline_vc_preflight.pyの現行classify_resultはpytestの exit 4 を扱っておらず、現状だと該当ケースは最終的にunknown / human_judgmentに落ちます。実際、現在の分類ロジックはexit_code == 0をunexpected_pass、rg/grepexit 1 やtest -f/-dexit 1 を expected 系に寄せ、それ以外をunknownにしています。ただし、Issue #366 の本文のまま実装すると分類器が危険に緩みます。 特に「pytest exit 4 (no-collection)」という表現が不正確です。pytest 公式ドキュメントでは exit code 4 は command line usage error、exit code 5 は no tests collected です。したがって、
exit 4 + no tests ranを一括で “expected baseline fail” にするのではなく、exit 4 + ERROR: file or directory not foundとexit 5 + no tests collected/no tests ranを分離して扱うべきです。([pytestドキュメント]1)関連 Issue / PR から見た位置づけ
#366 は #244 の Track B、つまり
baseline_vc_preflight.pyの分類器品質改善です。#244 は Issue/PR body authoring をvalidate_issue_body.py/validate_pr_body.py/baseline_vc_preflight.pyで機械検証し、AI に最小コンテキストを渡す構想の親トラッカーです。#329 / PR #354 が
baseline_vc_preflight.pyの正本実装です。#329 は VC を AC 別に抽出し、expected_fail/unexpected_pass/blocked/human_judgment、およびcategory/decision/confidenceを JSON で返す設計を固定しています。PR #354 はこれを merged 済みです。#327 / PR #367 は trigger です。#327 は
validate_issue_body.pyとcreate_issue_txn.pypre-write hook の実装であり、baseline_vc_preflight.py自体は out of scope と明記しています。PR #367 は #327 を merged 済みですが、#366 の対象である classifier 分岐は現在のbaseline_vc_preflight.pyにはまだ入っていません。#366 本体は open、コメント 0 です。本文には #327 の preflight で pytest exit 4 +
ERROR: file or directory not foundがunknown / human_judgmentになったため、local patch で先行したと書かれています。Blockers
B1. “pytest exit 4 (no-collection)” という仕様名が誤っている
pytest exit 4 は no-collection ではなく usage error です。missing test file を明示指定した場合の
ERROR: file or directory not foundは exit 4 になり得ますが、これは “no collection” ではなく “明示された test target が存在しない” ケースです。一方、テスト探索対象は存在するが収集件数 0 の場合は pytest 公式上 exit 5 です。([pytestドキュメント]1)修正方針:
exit 4 + no tests ranだけでgoにするのは広すぎます。exit 4は usage error なので、unrecognized arguments、bad option、plugin/CLI usage failure まで expected 扱いする危険があります。B2. positive test だけでは classifier を過剰緩和できてしまう
#366 の AC は positive path と exit 0 regression だけです。これだと実装者が
if "pytest" in command and exit_code == 4: expected_baseline_failのような雑な分岐を入れても AC を満たせます。現行 classifier はすでに"rg " in commandのような文字列依存があり、ここに同種の雑な pytest 判定を追加すると分類器の信頼性がさらに下がります。最低限、以下の negative fixture / unit test が必要です。
B3. Verification Commands と Allowed Paths の test path が間違っている
#366 は
uv run pytest .claude/skills/issue-contract-review/tests/ ...を指定していますが、実際の既存テストは.claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py配下です。fixtures もscripts/tests/fixtures/にあります。修正すべき path:
したがって Allowed Paths も以下に直すべきです。
B4.
git stash@{0}は実装コンテキストとして再現不能#366 は local patch が
git stash@{0}にあると書いていますが、これは他の実装者・CI・レビュワーから参照できません。Issue 本文に以下を貼るべきです。
最低でも、
ERROR: file or directory not found: ...を含む実ログを fixture 化してください。stash 参照だけでは issue contract として弱いです。B5. top-level status / summary / fragment への影響が検証されていない
#366 の AC は
categoryとdecisionだけを見ています。しかしimpl-review-loopは contract snapshot 内のvc_preflight.statusを見て stop / continue を決める設計です。PR #354 でも contract snapshot 内vc_preflightを参照し重複実行しない設計が入っています。したがって、単一 result が
decision: goになるだけでは不十分です。fixture 全体で以下を assert してください。実装方針
classify_resultにベタな substring 判定を足すのではなく、shlex.split()後の argv を見て pytest invocation を判定してください。既存スクリプトは command 実行時にshlex.split+shell=Falseを使っており、この設計と整合します。推奨する判定対象:
追加する分類は、新カテゴリを増やさず
expected_baseline_failを再利用するのがよいです。compute_confidence()は既にexpected_baseline_failを high confidence として扱うため、fragment 側の追加修正を最小化できます。擬似コード:
分類分岐:
この分岐は
exit_code == 0のunexpected_pass判定より後、unknownに落ちる前に置くのが自然です。修正版 Acceptance Criteria 案
修正版 Verification Commands:
最終判断
#366 は 実装すべき follow-up です。#327 / PR #367 の実装時に、Track A の validator preflight が Track B の classifier 不足で止まるという実害が出ており、#244 の「機械検証で AI に最小コンテキストを渡す」方針にも合っています。
ただし、現状の #366 は pytest exit code semantics、test path、negative tests、再現可能な証跡 が不足しています。本文を修正してから実装に入るべきです。特に
exit 4 == no-collectionという前提は公式仕様とズレているため、そのまま実装すると classifier が “human_judgment を減らす” 代わりに “誤った go を増やす” 可能性があります。[-]改善: baseline_vc_preflight.py classifier に pytest exit 4 (no-collection) を expected_baseline_fail として認識させる[/-][+]改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する[/+]squne121 commentedon May 24, 2026
Issue Body Revised (edit-issue refinement)
Anchor: #366 (comment)
Changes:
git stash@{0}reference. Added concrete stderr fixture example.New Sections:
All AC now include checkbox format. Verification Commands formatted as atomic fenced bash block with AC markers per pytest official guidance.
Status: ready for implement-issue.
squne121 commentedon May 24, 2026
issue-refinement-loop: 完了 (2026-05-24T10:42Z)
反映内容
.claude/skills/issue-contract-review/scripts/tests/に修正git stash@{0}言及削除、fixture 化方針に置換$prefix 追加 (review-issue C4 check 準拠)次アクション: impl-review-loop へ。
squne121 commentedon May 24, 2026
Contract Snapshot (2026-05-24T10:45Z)
Issue Contract 要旨
classify_resultに_is_pytest_invocation(argv ベース pytest 検出) と exit 4 + ENOENT / exit 5 + no-tests-collected 二分岐を追加。新カテゴリ未追加でexpected_baseline_failを再利用。fixture テストで positive + negative 全件 PASS。$prefix, atomic, AC ⇔ VC 1:1)。baseline_vc_preflight.py、scripts/tests/test_baseline_vc_preflight.py、scripts/tests/fixtures/。.claude/worktrees/issue-366-pytest-classifierworktree-issue-366-pytest-classifierPreflight 結果
state/needs-human不在)status: blockedだが分類根拠は 改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する #366 自身が修正対象の bug(pytest exit 5 + "no tests collected" → 現 classifier が human_judgment 判定)。実装後は本 Issue 修正により expected_baseline_fail/go に変わるHandoff
implement-issueを本 Issue 番号 + 上記 contract snapshot URL で実行generated_by: issue-contract-review (main thread, manual snapshot composition with documented override)
squne121 commentedon May 24, 2026
Allowed Paths amend (2026-05-24T10:55Z, iter 2)
.github/workflows/ci.ymlを Allowed Paths に追加。理由
pr-reviewer Opus (G1 CI test path coverage gate, #371 systemic prevention の先取り適用) が
.claude/skills/issue-contract-review/scripts/tests/が CI python-test job に組み込まれていないことを検出。本 Issue が追加する 10 件の test 関数は実装の merge gate になっていない。ci.yml の python-test job に
uv run --locked pytest .claude/skills/issue-contract-review/scripts/tests/行を追加するのは、AC7/AC8 の merge gate 性を満たすための直接的な下流影響であり scope creep ではない。fix(#366): add pytest issue-contract-review/scripts/tests/ to CI pyth…
feat(#366): add pytest invocation detection and exit 4/5 baseline-fai…
fix(#366): add pytest issue-contract-review/scripts/tests/ to CI pyth…
feat(#366): add pytest invocation detection and exit 4/5 baseline-fai…
squne121 commentedon May 24, 2026
post-merge-cleanup: 完了 (2026-05-24T11:20Z)
grep -v "^"除外)を禁止ルールとして追記する #301 / 改善: pr-review-judge に check_pr_review_gates.py + PR_REVIEW_GATE_RESULT_V1 を実装し SKILL.md 行数中立で deterministic gate を強化する — #244 follow-up #371 OPEN のため)実施内容
.claude/worktrees/issue-366-pytest-classifierを削除worktree-issue-366-pytest-classifierを削除parent #244 ステータス
grep -v "^"除外)を禁止ルールとして追記する #301 / 改善: pr-review-judge に check_pr_review_gates.py + PR_REVIEW_GATE_RESULT_V1 を実装し SKILL.md 行数中立で deterministic gate を強化する — #244 follow-up #371Follow-up
merged PR 本文 / コメントに follow-up セクションなし → 追加起票なし
残存(本 cleanup 範囲外、人間判断推奨)
worktree-issue-281-game-thesis: remote gone だが local commit が main に未含。本 Issue 改善: baseline_vc_preflight.py classifier に pytest invocation 検出と exit 4/5 baseline-fail 分類を追加する #366 とは無関係の stale ローカル branch。必要なら別途人間がgit branch -Dで削除判断