Skip to content

実装: baseline_vc_preflight.py が既存ファイル::新規テスト関数名 形式の pytest VC を expected_baseline_fail に分類できないバグを修正する #1347

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "なし(単独改善)"
goal_ref: "既存ファイルへの ::新規テスト関数名 node-id を baseline_vc_preflight.py が canonical な expected_baseline_fail に誤分類しないよう、区別可能な非canonical category として分類できるようにする"
change_kind: code

Parent Issue

なし(単独改善)

Parent Goal Ref

なし(単独改善のため該当なし)

Current Validated Scope

なし(単独改善のため該当なし)

Remaining Parent Gaps

なし(単独改善のため該当なし)

Required Design References

Runtime Verification Applicability

  • VC Applicability: immediate(具体的失敗コマンド・実環境検証が可能)
    • 根拠: baseline_vc_preflight.py の classify_result() は純粋関数的なユニットで、既存のテストファイルに直接テストケースを追加して即座に検証できる。
decision: immediate
applicable_acs:
  - AC1
  - AC2
  - AC3
execution_environment:
  cli_tools:
    - python3
    - uv
    - pytest
  auth_required: false
  network_required: false
skip_conditions:
  - "uv / pytest が利用できない実行環境では SKIP(exit 77)とし、fallback 経由の代替実行は行わない"
fallback_policy:
  fallback_success_is_pass: false
  notes: "fallback 経由での成功を PASS として扱わない。実際の pytest 実行結果のみを PASS/FAIL 判定に用いる"
artifact_requirements:
  - "uv run pytest .claude/skills/issue-contract-review/scripts/tests/ -q の実行ログ"

Outcome

baseline_vc_preflight.py の classify_result() / _is_regression_gate_command() を、既存ファイルへの ::新規テスト関数名 node-id(対象ファイルは存在するがテスト関数が未実装、baseline exit_code=4)を expected_baseline_fail / go にはしないまま、明確に区別可能な非canonical category(例: existing_file_missing_node_id_noncanonical のように、unknown / human_judgment とは別のカテゴリ名にして今後の diagnostics で識別できるようにする)として分類するよう変更する。ファイル自体が存在しない場合(真の missing-file node-id。missing_new_test_file.py::test_name のような Issue #1285 / PR #1305 の canonical 形を含む)の既存の expected_baseline_fail / go 分類は変更しない。

In Scope

  • baseline_vc_preflight.py の _is_regression_gate_command() が pytest の positional path 引数を判定する際、::テスト名(pytest node id のサブパート)を含めた文字列全体で Path.exists() を呼んでいるため、既存ファイルに新規テスト関数を追加するケースで常に False を返し、結果として classify_result() の pytest exit_code=4 特殊分岐(file or directory not found → expected_baseline_fail / go)に到達できず、最終フォールバックの unknown / human_judgment に落ちている現状の挙動を確認したうえで、この分岐先を「既存ファイルへの missing node-id」を明確に示す新設の非canonical category に変更する
  • 修正方針: classify_result() / _is_regression_gate_command() で「対象ファイルは実在するが node id 全体としては存在しない」(pytest の ERROR: not found: <path>::<name> / (no match in any of [<Module ...>]) 系メッセージ)ケースを検出した場合、expected_baseline_fail / go にはせず、unknown / human_judgment とは別の新設 category(例: existing_file_missing_node_id_noncanonical)として分類する。これは Issue 実装: VC baseline-fail 用 pytest command を canonical form に正規化して contract-review 往復を削減する #1285 と PR feat: VC baseline-fail pytest command を canonical form に正規化する compiler を追加 #1305(.claude/skills/issue-contract-review/scripts/vc_baseline_shape_compiler.py)で確立された canonical VC shape 契約(既存ファイルへの missing node-id は非canonical、missing_new_test_file.py::test_name のようなファイル自体が存在しない node-id が canonical)と整合させるための変更である
  • ファイル自体が存在しない場合(真の missing-file node-id、Issue 実装: VC baseline-fail 用 pytest command を canonical form に正規化して contract-review 往復を削減する #1285 / PR feat: VC baseline-fail pytest command を canonical form に正規化する compiler を追加 #1305 の canonical 形を含む)の既存の expected_baseline_fail / go 分類は変更しない
  • 修正対象の分類ロジックのみを変更し、baseline-expect annotation の意味論やその他の分類パスは変更しない

Out of Scope

  • baseline-expect: annotation の仕様変更
  • contract_review_result_parser.py / run_contract_review_once.py 等、baseline_vc_preflight.py を呼び出す上位スクリプトの変更
  • pytest exit_code=5(no tests collected)関連の既存分類ロジックの変更
  • .claude/skills/create-issue/references/body-authoring.md / .claude/skills/issue-contract-review/scripts/vc_baseline_shape_compiler.py / .claude/skills/edit-issue/scripts/issue_contract_hygiene_autofix.py の変更(Allowed Paths 外)

Acceptance Criteria

  • AC1: 既存ファイルへの ::新規テスト関数名 node-id(対象ファイルは実在するがテスト関数は未実装、baseline で exit_code=4)を classify_result() に渡した場合、expected_baseline_fail / go ではなく、新設の非canonical category(unknown / human_judgment とは異なる明示的なカテゴリ名)を返すことを検証する新規テストが test_baseline_vc_preflight.py に追加されている
  • AC2: ファイル自体が存在しない pytest コマンド(真の missing-file node-id。missing_new_test_file.py::test_name のような Issue 実装: VC baseline-fail 用 pytest command を canonical form に正規化して contract-review 往復を削減する #1285 / PR feat: VC baseline-fail pytest command を canonical form に正規化する compiler を追加 #1305 の canonical 形を含む)を classify_result() に渡した場合、既存の expected_baseline_fail / go 分類が変わっていないことを検証する回帰テストが追加されている
  • AC3: .claude/skills/issue-contract-review/scripts/tests/ 配下の pytest が全件 green である

Verification Commands

# AC1
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py::test_pytest_exit4_new_test_on_existing_file_is_noncanonical_category -q
# AC2
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py::test_pytest_exit4_missing_file_still_expected_baseline_fail -q
# AC3
# preflight-scope: runtime_only
$ uv run pytest .claude/skills/issue-contract-review/scripts/tests/ -q

Allowed Paths

  • .claude/skills/issue-contract-review/scripts/baseline_vc_preflight.py
  • .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)

Required Skills

  • Python(pytest / 正規表現ベースの分類ロジック実装)

Scope Delta(任意)

N/A

Delivery Rule

  • 1 Issue = 1 PR を原則とする
  • worktree で作業し、Draft PR として提出する

Notes for Reviewer

Activity

  1. squne121 commented on Jul 7, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #1347 の現象自体は実在します。ただし、Issue本文のまま実装すると、過去に確立した「pytest baseline-fail VC の canonical form」契約と衝突します。現状のまま expected_baseline_fail / go に寄せるのは危険です。

    確認対象は #1347 本文・コメント、発見元の #1274 / PR #1345、既存の #1285 / PR #1305、#1328 / PR #1340、baseline_vc_preflight.py、vc_baseline_shape_compiler.py、body-authoring.md、pytest / pathlib 公式仕様です。#1347 のコメントは空でした。

    まず事実関係

    pytest 公式仕様では、tests/test_mod.py::test_func のように :: で module / class / function を指定する collection argument が正規の指定方法です。また exit code 4 は “command line usage error”、exit code 5 は “no tests were collected” です。([pytest]1) ([pytest]2)

    一方、現在の _is_regression_gate_command() は pytest の positional arg をそのまま Path(arg).exists() に渡しています。つまり existing_test_file.py::test_missing はファイルパスではなく node-id 付き文字列なので、実ファイル existing_test_file.py が存在しても exists() は false になります。 Python の Path.exists() は「その path が既存ファイル/ディレクトリを指す場合だけ True」であり、無効・アクセス不能・欠落なら False です。([Python documentation]3)

    さらに classify_result() 側の pytest exit 4 特例は、error:\s+file or directory not found: に一致する場合だけ expected_baseline_fail / go にします。既存ファイル上の missing node-id は pytest 的には ERROR: not found: <file>::<name> / no match in ... 系であり、この regex には入りません。

    ここまでは #1347 の問題設定どおりです。

    致命的な問題 1: #1285 / #1305 の canonical 契約と衝突している

    #1347 は「既存ファイルに ::新規テスト関数名 を付けた pytest VC を expected_baseline_fail / go にしたい」というIssueです。ところが、#1285 はまさにこの形を禁止形として扱い、missing_new_test_file.py::test_name へ rewrite する compiler を追加するためのIssueでした。#1285本文では、既存ファイルへの missing node-id は「判定不能」であり、baseline_vc_preflight.py の exit code 契約は変更しない、と明記されています。

    PR #1305 も同じ立場で、existing_test_file.py::test_missing_name を canonical missing-file node-id へ rewrite する vc_baseline_shape_compiler.py を追加し、baseline_vc_preflight.py の pytest exit code 契約は変更しない、と説明しています。

    現行ドキュメント body-authoring.md でも、pytest baseline-fail VC は「まだ存在しないテストファイルへの node-id」で書く、既存ファイルへの missing node-id は禁止形、と明記されています。

    したがって #1347 は、単なる classifier bugfix ではなく、既存のVC設計思想を戻す変更です。実装するなら baseline_vc_preflight.py とテストだけでは足りず、少なくとも次も同時に変更対象です。

    • .claude/skills/create-issue/references/body-authoring.md
    • .claude/skills/issue-contract-review/scripts/vc_baseline_shape_compiler.py
    • .claude/skills/edit-issue/scripts/issue_contract_hygiene_autofix.py
    • それぞれのテスト

    現Issueの Allowed Paths はこの影響範囲を許可していません。よって、現契約のままなら #1347 は scope insufficient です。

    致命的な問題 2: AC2 が現行実装・既存契約と逆

    #1347 の AC2 は「ファイル自体が存在しない pytest コマンドは既存の unknown / human_judgment 系挙動が変わらないこと」を要求しています。

    これは現行実装と矛盾します。classify_result() には、pytest exit 4 かつ file or directory not found なら expected_baseline_fail / go を返す分岐が regression gate 判定外にも存在します。

    また #1285 の canonical form は「missing file node-id」です。つまり、ファイル自体が存在しない missing_new_test_file.py::test_name を expected baseline fail にすることが既存方針です。

    よって AC2 はそのままでは不正です。正しくは以下のどちらかです。

    1. 現契約維持: missing_new_test_file.py::test_name は expected_baseline_fail / go のまま維持する。既存ファイル missing node-id は compiler/autofix 側で canonical form に直す。
    2. 契約変更: 既存ファイル missing node-id も baseline-fail として許容する。その場合、実装: VC baseline-fail 用 pytest command を canonical form に正規化して contract-review 往復を削減する #1285 / feat: VC baseline-fail pytest command を canonical form に正規化する compiler を追加 #1305 / body-authoring / compiler の契約を全部更新する。

    致命的な問題 3: 発見元 #1274 はすでに別ルートで解消済み

    #1347 は #1274 の impl-review-loop で発見された gap を発端にしていますが、#1274 自体は PR #1345 で解消済みです。PR #1345 は #1274 の Contract Repair Note に従い、_validate_agy_request() への読み替え、fixture補完、AGY provider テスト追加で close しています。

    つまり #1347 は「#1274 を進めるための緊急 blocker」ではなく、今は VC canonicalization / preflight classifier の設計判断として扱うべきです。

    推奨判断

    現時点の推奨は #1347 をそのまま実装しない です。

    より安全な修正方針は、baseline_vc_preflight.py に既存ファイル missing node-id を expected_baseline_fail として追加することではなく、次のどちらかです。

    推奨A: #1347 を「非canonical VC を body-author-fixable にする」Issueへ書き換える

    既存ファイルへの missing node-id を見つけたら、expected_fail / go ではなく、pytest_missing_node_id_on_existing_file_noncanonical のような blocked または needs_fix 系カテゴリにして、vc_baseline_shape_compiler.py の rewrite hint へ誘導する。これは #1285 / #1305 / body-authoring と整合します。

    この場合の実装対象は classifier 本体より、readiness / hygiene autofix の連携強化です。

    代替B: どうしても expected_baseline_fail にするなら契約変更Issueとして起票し直す

    この場合は #1347 の Allowed Paths を拡張し、以下を明示する必要があります。

    • 既存の「既存ファイル missing node-id 禁止」契約を廃止または緩和する
    • body-authoring.md の canonical table を更新する
    • vc_baseline_shape_compiler.py の rewrite 方針を変更する
    • issue_contract_hygiene_autofix.py の fail-closed 条件を見直す
    • baseline_vc_preflight.py の pytest exit 4 判定を file not found と node-id not found で明確に分離する

    実装上は _is_regression_gate_command() で arg.split("::", 1)[0] を path 判定に使うだけでは不十分です。classify_result() 側でも、ERROR: not found: かつ (no match in any of [<Module ...>]) のような missing node-id 系 stderr を識別し、既存ファイルが存在する場合だけ分類する必要があります。単に exit code 4 を広く expected_baseline_fail にすると、pytest の usage error 全般を false-green にします。pytest公式上、exit code 4 は広い「command line usage error」だからです。(pytest)

    #1347 本文に対する修正案

    現契約を維持するなら、#1347 はこう直すのが安全です。

    Outcome:
    baseline_vc_preflight.py は既存ファイルへの missing node-id を expected_baseline_fail/go にしない。
    代わりに、既存ファイル::未実装テスト関数の pytest VC を非canonical VC shape として検出し、
    vc_baseline_shape_compiler.py / issue_contract_hygiene_autofix.py の rewrite hint へ誘導できる状態にする。
    
    AC1:
    existing_test_file.py::test_missing_name は expected_fail/go ではなく、
    pytest_missing_node_id_on_existing_file_noncanonical などの body-author-fixable category になる。
    
    AC2:
    missing_new_test_file.py::test_name は従来どおり expected_baseline_fail/go のまま。
    
    AC3:
    body-authoring.md の canonical rule と vc_baseline_shape_compiler.py の rewrite policy が regression しない。
    
    AC4:
    #1274 型のVCが issue_contract_hygiene_autofix.py 経由で canonical missing-file node-id に修復される。
    

    現Issue本文のまま進めるなら、私は REQUEST_CHANGES。問題の観測は正しいですが、解決策が既存の canonical VC 設計を破壊します。

  2. squne121 commented on Jul 7, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  3. squne121 commented on Jul 7, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: human judgment required

    Blockers

    "訂正: 直前に投稿した『Approved』コメントは issue-contract-review 実行前の誤投稿であり無効。正しい終了判定は human_escalation。"
    
    "run_contract_review_once.py (--mode static) が AC1/AC2 の VC preflight で status: human_judgment を返した。baseline_vc_preflight.py は既存ファイルへの `::新規テスト関数名` node-id(本Issueが修正対象とする分類ギャップそのもの)を分類できず、AC1/AC2 の VC コマンドが exit_code=4 かつ human_judgment 判定になる自己参照的なブートストラップ問題。"
    
    "同型の問題は発見元 Issue #1274 でも発生し、OWNER のオーバーライドコメント(https://github.com/squne121/loop-protocol/issues/1274#issuecomment-4886908883)で human judgment を許容し impl-review-loop を続行した前例がある。"
    
    "#1347 についても、OWNER が同様に VC preflight human_judgment を許容する override 判断を行うか、AC1/AC2 の Verification Commands をこの classifier 非依存の形に書き換えるかの判断が必要。"
    
    "Issue #1347 本文自体は Step 2 review-issue で VERDICT: approve(body_sha256: sha256:f77d19eb35d69f052f7b7331134dd3b5721cc3b6958543128900d6143bb123b1)。ブロッカーは contract-review 側の VC preflight 分類ギャップのみ。"
    
  4. squne121 commented on Jul 7, 2026

    @squne121
    OwnerAuthor

    Contract Review — Human Override(issue-contract-review が human_judgment を返したための人間判断)

    IMPL_REVIEW_LOOP_HUMAN_OVERRIDE_V1:
      status: go
      generated_by: human_override
      automated_tool_status: human_judgment
      issue_url: "https://github.com/squne121/loop-protocol/issues/1347"
      generated_at: "2026-07-07T10:42:30Z"
      body_sha256_at_override: "sha256:f77d19eb35d69f052f7b7331134dd3b5721cc3b6958543128900d6143bb123b1"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: human_judgment (overridden below)
      next_action: implement_issue

    注記: この YAML は issue-contract-review が生成した CONTRACT_REVIEW_RESULT_V1 ではありません。baseline_vc_preflight.py による自動 VC preflight の実行結果は AC1/AC2 について human_judgment でした。以下の理由分析に基づき、人間(squne121)が impl-review-loop の続行を承認したことを記録するコメントです。

    Human Override 理由

    baseline_vc_preflight.py を用いた VC preflight を実行した結果、AC1/AC2 の VC コマンド(uv run pytest .claude/skills/issue-contract-review/scripts/tests/test_baseline_vc_preflight.py::test_pytest_exit4_new_test_on_existing_file_is_noncanonical_category -q および同 ::test_pytest_exit4_missing_file_still_expected_baseline_fail -q)が human_judgment に分類された。原因を調査した結果、Issue 本文側の問題ではなく preflight classifier の既知のギャップ であることを確認した。

    • AC1/AC2 は uv run pytest <既存ファイル>::<新規テスト関数名> -q 形式。対象ファイル(test_baseline_vc_preflight.py)は既存だが、参照しているテスト関数(test_pytest_exit4_new_test_on_existing_file_is_noncanonical_category / test_pytest_exit4_missing_file_still_expected_baseline_fail)はまだ実装されていないため、baseline 実行で exit_code=4(pytest "not found" / no tests ran)になる。これは新規テスト追加 Issue における想定通りの baseline 失敗であり、docs/dev/runtime-verification-policy.md の意図に沿う expected_baseline_fail 相当のケースである。
    • baseline_vc_preflight.py の _is_regression_gate_command()(test_path.exists() 判定、656行目付近)は pytest の positional path 引数を Path(cwd) / arg として ::テスト名 を含めた文字列のまま .exists() 判定するため、常に False を返す(:: 付き文字列がファイルシステム上に実在することはあり得ない)。そのため classify_result() 内の pytest exit_code=4 の file or directory not found 特殊分岐(2342行目・2472行目付近)に到達せず、最終フォールバックの unknown / human_judgment に落ちる。
    • これは「既存ファイルに新規テスト関数を追加する」パターンの VC を classifier が正しく認識できていないバグであり、Issue 実装: baseline_vc_preflight.py が既存ファイル::新規テスト関数名 形式の pytest VC を expected_baseline_fail に分類できないバグを修正する #1347 の Verification Commands や Allowed Paths の記載自体には問題がない。

    重要な自己言及性(bootstrap gap)について: この preflight classifier のギャップは、まさに Issue #1347 自身が修正しようとしているバグそのものである。Issue #1274 のときは同種のギャップに対する classifier 修正を別 Issue(本 #1347)として起票する方針を取ったが、今回は #1347 自身が「既存ファイルに ::新規テスト関数名 形式で追加される pytest VC を expected_baseline_fail 相当ではなく正しい非canonical category として分類できるようにする」修正を Outcome / AC に持つ Issue であるため、追加の follow-up Issue を新たに起票する必要はない。#1347 の実装が完了し merge されれば、この bootstrap gap 自体が解消される。

    人間判断により、上記 AC1/AC2 を expected_baseline_fail 相当(新規実装前の baseline 失敗)として go と判定し、impl-review-loop を継続する。

    AC3(preflight-scope: runtime_only、.claude/skills/issue-contract-review/scripts/tests/ 配下 pytest 全件 green)は preflight 側で skipped / go(runtime_verification_required: true)であり、実装後の runtime 検証で担保する。

  5. added a commit that references this issue on Jul 7, 2026
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

    phase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions