Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#1138"
goal_ref: "legacy E501 を base/head の SHA 固定・merge-base 差分・AST 同値性・suppression 禁止・テスト保全を一体で強制する単一 verify-diff エントリポイントとして提供し、後続の領域別 child が安全に E501 を ratchet 解消できる検証 tooling を導入する"
change_kind: codeParent Issue
Parent Goal Ref
- Goal:
.claude/scripts/scripts/schemas/.claude/skillsの E501 diagnostic を AST 同値性・テスト保全・suppression 禁止を保証しながら 0 件にし、最終的に CI Ruff gate を--select E,F --ignore E402へ移行する - Desired Destination: base/head AST 同値性・Python テスト保全・suppression 禁止・SHA 固定された再現可能 inventory を 一体で検証する共有 tooling が導入され、後続の領域別 cleanup child(E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 Child 2〜4)と final gate child(Child 5)がこれを利用して安全に E501 を解消できる状態(parent scope)
Current Validated Scope
本 Issue は OWNER REQUEST_CHANGES(#issuecomment-4776476010)の 9 Blocker を反映し、「独立した 4 補助スクリプト」設計を廃し、単一 verify-diff 主コマンドが全検査を一体・fail-closed で実行する設計へ改訂する。
scripts/e501_migration_guard.pyを新規追加し、唯一の合否判定エントリポイントverify-diffを提供する。verify-diffは次を順番に実行し、途中エラーを fail-closed で扱う:--base-ref/--head-refを不変 SHA へ解決する- merge-base を解決する(無い場合は fail。
HEAD^等へ fallback しない) - changed-file manifest を
git diff --name-status -z(merge-base 基準の三点差分)で一度だけ生成し、NUL 区切りバイト列として解析する(splitlines()禁止) - status / scope 検査(対象 Python は
Mのみ許可、A/D/R/C/T/U・scope 外・guard 自身の変更を拒否) - 全変更 Python ファイルの encoding-aware decode・
compile()・type_comments=TrueAST 同値性検証 - suppression / config 検査(現行 Ruff の全 suppression 形式 + 関連 config の新規追加・広域化検出)
- base / head の Ruff 実行(
--isolated+ 固定設定、exit 1 と exit 2 を区別) - per-file および scope 合計の ratchet
- 単一の machine-readable report(
e501-migration-guard/v1)を stdout に JSON のみで出力(人間向けログは stderr)
- 内部ステップ(baseline / ast-equiv / suppression-scan / ratchet)はサブコマンドとして残してもよいが、合否判定は必ず
verify-diffを一体実行した証跡で行う。 scripts/tests/test_e501_migration_guard.pyを新規追加し、各ステップの正常系・異常系に加え、一時 Git リポジトリを用いた E2E mutation test(PR 実装(#1133): staged Ruff E/F gate を green 化 (E501/E402 除外) #1136 型のテスト破壊を含む)で検証する。
Remaining Parent Gaps
- 領域別 cleanup(E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 Child 2:
.claude/scripts/ Child 3:scripts/ Child 4:.claude/skills)は本 Issue では行わない - Child 2〜4 の Allowed Paths から
scripts/e501_migration_guard.py/scripts/tests/test_e501_migration_guard.pyを明示除外する(後続 PR が同一 diff で guard 自身を弱体化して自己検証する trust-boundary 欠陥の防止)。この除外契約は各 child 起票時に反映する - CI ワークフロー組み込み(
.github/workflows/ci.yml)は本 Issue では行わない。final gate child(E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 Child 5)でfetch-depth: 0または対象 base SHA の明示 fetch を必須変更として明記する(現行actions/checkout@v6は追加設定なしで shallow checkout のため merge-base が取得できない可能性がある) - CI Ruff gate の
--ignoreから E501 を外す最終切替は E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 Child 5 で行う
Outcome
scripts/e501_migration_guard.py の verify-diff が、base/head の SHA 固定・merge-base 差分・M 限定・AST 同値性・suppression 禁止・per-file/合計 ratchet・版付き report 出力を一体・fail-closed で実行し、scripts/tests/test_e501_migration_guard.py(PR #1136 型 mutation E2E を含む)が全件 pass し、後続 cleanup child がこの単一コマンドで安全性を機械検証できる状態。
In Scope
scripts/e501_migration_guard.pyのverify-diff主コマンド実装(ref→SHA 固定 / merge-base / NUL 区切り manifest / status・scope 検査 / AST 同値性 / suppression 検査 / Ruff 実行 / ratchet / 版付き report を一体 fail-closed 実行)- 版付き report スキーマ
e501-migration-guard/v1の実装(SHA 群・uv_lock_sha256・Python/Ruff/guard version・argv・per-file diagnostics・全判定結果を含み、path/diagnostics はソート、stdout は JSON のみ) - AST 同値性検査(
ast.parse(..., type_comments=True)+compile(..., dont_inherit=True)+tokenize.detect_encoding相当の encoding 尊重、Python 3.12 固定・version 記録、SyntaxError/UnicodeDecodeError/compile error は tool error) - suppression-scan(
# noqa/# ruff: noqa/# flake8: noqa/# ruff: ignore[...]/# ruff: disable[...]/# ruff: enable[...]/# ruff: file-ignore[...]のコメント系をtokenizeで、lint.ignore/lint.extend-ignore/lint.per-file-ignores/lint.extend-per-file-ignores/exclude/extend-exclude/line-length/lint.pycodestyle.max-line-length/lint.pycodestyle.ignore-overlong-task-comments/lint.task-tagsの config 系をtomllibで解析し、CLI--config/--ignore/--extend-ignore/--per-file-ignores/--exit-zero/--add-noqaも対象に、base/head 正規化済み意味を比較して新規追加・広域化を検出) - Ruff 実行(
--isolated --select E501 --line-length 120 --target-version py312 --no-preview --ignore-noqa --no-respect-gitignore --no-cache --output-format json、外側はuv run --locked起動、絶対パス・version・argv・uv.lockhash を report 記録、exit 0/1/2 を区別し exit 2/timeout/JSON decode 失敗を「0 件」扱いしない) - ratchet(NUL 区切り manifest・merge-base 三点差分・対象 Python は
M限定、per-filehead_count <= base_count、scope 合計head_total <= base_total、cleanup modehead_total < base_total、completion modehead_total == 0) - guard 自己改変防止(
verify-diffがscripts/e501_migration_guard.py/scripts/tests/test_e501_migration_guard.pyが merge-base と同一 blob であることを確認、または信頼済み base SHA から取り出した guard を実行) scripts/tests/test_e501_migration_guard.pyの追加(各ステップ正常系・異常系 + 一時 Git リポジトリ E2E mutation suite: assertion/test body 削除・file delete/rename/add・1 ファイル増 / 別ファイル減・generic# noqa広域化・ruff: disablerange 追加・nested.ruff.toml・Ruff exit 2・malformed JSON・missing base ref / merge-base・unusual filename・type comment 変更・parse 通過するが compile 不可・guard 自身の変更。特に PR 実装(#1133): staged Ruff E/F gate を green 化 (E501/E402 除外) #1136 事故の縮小再現として通常 pytest が green でもverify-diffが fail するケースを含める)- 実装規約(
shell=True禁止 / subprocess timeout / stderr サイズ上限 / path containment 検証 / symlink・非 regular Git mode 拒否 / 一時ディレクトリ確実 cleanup / 解析不能時 fail-closed)
Out of Scope
- 既存
*.pyの E501 行分割そのもの(E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 Child 2〜4) .github/workflows/ci.ymlの変更(E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 Child 5。fetch-depth追加は Child 5 の必須変更として Remaining Parent Gaps に記載)pyproject.toml/uv.lock/ nestedruff.toml/.ruff.toml/exclude設定の変更- 別 PyPI package / 独立 wheel 化(リポジトリローカルの stdlib 主体 CLI として配置し、Ruff のみ既存
uv.lockから供給) - 非 Python ファイルの変更
Acceptance Criteria
- AC1:
verify-diffが唯一の合否判定エントリポイントであり、ref 解決→merge-base→manifest→status/scope→AST→suppression→Ruff→ratchet→report を一体で実行し、途中エラーを fail-closed で扱う - AC2:
verify-diffが--base-ref/--head-refを不変 SHA へ固定し、merge-base とgit diff --name-status -zによる NUL 区切り changed-file manifest を生成する(merge-base 不在時は fail、HEAD^fallback しない) - AC3: 対象 Python 変更は
Mのみを許可し、A/D/R/C/T/U・scope 外変更・guard 自身(scripts/e501_migration_guard.py/ その test)の変更を拒否して非ゼロ終了する - AC4: 全変更ファイルについて encoding-aware decode・
compile(..., dont_inherit=True)・ast.parse(..., type_comments=True)ベースの AST 同値性を検証し、空白/改行のみ差は equal、文字列値や呼び出し差は not-equal、SyntaxError/UnicodeDecodeError/compile error は tool error として区別する - AC5: 現行 Ruff の全 suppression 形式(コメント系
# noqa/# ruff: noqa/# flake8: noqa/# ruff: ignore|disable|enable|file-ignore[...]、config 系lint.ignore/extend-ignore/per-file-ignores/extend-per-file-ignores/exclude/extend-exclude/line-length/lint.pycodestyle.max-line-length/ignore-overlong-task-comments/task-tags、CLI--config/--ignore/--extend-ignore/--per-file-ignores/--exit-zero/--add-noqa)について、base 比の新規追加・広域化を検出して非ゼロ終了する - AC6: Ruff 実行が
--isolated+ 固定設定(--line-length 120 --target-version py312 --no-preview --ignore-noqa --no-respect-gitignore --no-cache --output-format json)で行われ、exit 1(診断あり)と exit 2(設定・内部エラー)を区別し、exit 2/timeout/JSON decode 失敗を「0 件」扱いしない - AC7: ratchet が per-file(
head_count <= base_count)と scope 合計(head_total <= base_total)の両方を検証し、cleanup mode で最低 1 件減少、completion mode で 0 件を要求できる - AC8: report
e501-migration-guard/v1が base/head/merge-base SHA・uv_lock_sha256・Python/Ruff/guard version・Ruff argv・全ファイル診断・全判定結果を含み、path/diagnostics はソートされ、stdout には JSON 以外を出力しない - AC9: PR 実装(#1133): staged Ruff E/F gate を green 化 (E501/E402 除外) #1136 型のテスト破壊(assertion/test body 削除等)を含む E2E mutation suite を pass し、通常 pytest が green でも
verify-diffが当該 mutation を fail として検出する - AC10:
uv run --locked pytest scripts/tests/test_e501_migration_guard.pyが全件 pass する - AC11: 新規 2 ファイル(
scripts/e501_migration_guard.py/scripts/tests/test_e501_migration_guard.py)がruff check --select E,F --ignore E402で診断 0 件であることを、当該 ruff 実行を subprocess で起動する pytest テストが検証する - AC12:
pnpm typecheckが exit 0 - AC13:
pnpm lintが exit 0 - AC14:
pnpm testが exit 0 - AC15:
pnpm buildが exit 0
Verification Commands
# AC1
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_verify_diff_runs_all_checks_fail_closed# AC2
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_verify_diff_pins_sha_and_builds_nul_manifest# AC3
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_verify_diff_rejects_non_modified_and_guard_self_change# AC4
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_ast_equiv_type_comments_and_compile# AC5
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_suppression_scan_detects_all_forms# AC6
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_ruff_exec_isolated_distinguishes_exit2# AC7
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_ratchet_per_file_and_scope_total# AC8
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_report_v1_schema_complete# AC9
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_e2e_mutation_pr1136_test_destruction# AC10
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py# AC11
# baseline-expect: fail
$ uv run --locked pytest scripts/tests/test_e501_migration_guard.py::test_guard_files_clean_under_ruff_ef# AC12
# baseline-expect: pass
$ pnpm typecheck# AC13
# baseline-expect: pass
$ pnpm lint# AC14
# baseline-expect: pass
$ pnpm test# AC15
# baseline-expect: pass
$ pnpm buildAllowed Paths
scripts/e501_migration_guard.pyscripts/tests/test_e501_migration_guard.py
Runtime Verification Applicability
- decision: not_applicable
- reason: 本 Issue は Python 検証 tooling(verify-diff 一体実行)の追加であり、ブラウザやゲーム実行を伴わない。検証は pytest(E2E mutation suite を含む)と静的 lint で行う。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(
e501-migration-guard/v1スキーマのキー集合・型定義、verify-diff の主コマンド契約)の変更が必要になった場合 - 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープ(Child 2〜4 の Allowed Paths 除外、Child 5 の
fetch-depth)への波及で本 Issue 単体では完結できないと判明した場合 - nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 検証 tooling 自体が E501 / E/F に違反し、
pyproject.toml設定変更なしに解消できない場合
Required Skills
- Python
- Ruff
- Python
ast/tokenize/tomllibモジュール - Git(merge-base /
diff --name-status -z/ blob 同一性)
Scope Delta(任意)
OWNER REQUEST_CHANGES(#issuecomment-4776476010)を反映し、独立 4 サブコマンド設計から単一 verify-diff 一体実行設計へ改訂。版付き report スキーマ e501-migration-guard/v1、SHA 固定・merge-base・NUL 区切り manifest、M 限定 status 検査、type_comments=True + compile() AST 同値性、全 suppression 形式 + config + CLI 検出、--isolated 固定 Ruff 実行 + exit 区別、per-file/合計 ratchet、guard 自己改変防止、PR #1136 型 E2E mutation suite、AC/VC 完全一致(pnpm 4 ゲート + Ruff E/F + pytest)を追加。Allowed Paths(2 ファイル)は不変。
Activity
squne121 commentedon Jun 23, 2026
判定: REQUEST_CHANGES — 現契約では実装開始不可
方向性は妥当ですが、現在の #1144 は「検証部品を4つ置く」契約に留まり、後続PRについて 正しいbase/head・正しい変更ファイル集合・同一Ruff設定で、全検査を必ず一体実行したことを証明できません。
親 #1138 は、base SHA・merge-base・uv.lock SHA・ファイル別inventory、PythonファイルのM限定、AST同値性、suppression禁止、対象テスト保全まで要求しています。一方 #1144 のACは、その重要部分をかなり落としています。
これは理論上の懸念ではありません。PR #1136 では、CIがgreenで一度は自動レビュー上APPROVEされたにもかかわらず、テスト本体・assertionが大量削除されていたため、後からREQUEST_CHANGESになりました。独立した小テストがpassすることでは、検証能力そのものの破壊を防げません。
Blocker 1 — 4サブコマンドが独立しており、検証チェーンを強制できない
現在は baseline、ast-equiv、suppression-scan、ratchet が独立しています。この設計では次が可能です。
ratchet だけ実行し、AST検査を省略する
AST検査に実際の変更ファイルとは別の2ファイルを渡す
baselineとratchetで異なるbase ref、scope、Ruff設定を使う
一部のchanged fileだけを渡す
suppression-scanの失敗を無視して他の結果だけ証跡化する
必須修正: verify-diff という単一の主コマンドを追加し、4機能を内部ステップとして一体実行してください。
uv run --locked python scripts/e501_migration_guard.py verify-diff
--base-ref "$BASE_SHA"
--head-ref "$HEAD_SHA"
--scope scripts
--report artifacts/e501-migration-guard-v1.json
このコマンド自身が次を順番に実施し、途中エラーをfail-closedで扱う必要があります。
refを不変SHAへ解決
merge-base解決
changed-file manifestを一度だけ生成
status・scope検査
全変更Pythonファイルのcompile・AST比較
suppression/config検査
base/headのRuff実行
per-fileおよび合計ratchet
単一のmachine-readable report出力
Blocker 2 — baselineスキーマが親Issueの再現性要件を満たさない
#1144 のbaseline出力は ruff_version、ディレクトリ別件数、total、exit_code だけです。しかし親レビューでは以下が必要とされています。
base SHA
head SHA
merge-base SHA
uv.lock SHA
ファイル別件数
machine-readable diagnostics
実行コマンド
Ruff version
command exit code
現在のAC1では、別コミット・別lockfile・別Ruff設定で生成したJSONでも同じ証跡に見えます。
最低限、次の版付きスキーマにしてください。
{
"schema": "e501-migration-guard/v1",
"guard_version": "1",
"python_version": "3.12.x",
"ruff": {
"path": "...",
"version": "0.15.18",
"argv": []
},
"git": {
"base_ref": "...",
"base_sha": "...",
"head_sha": "...",
"merge_base_sha": "..."
},
"repository": {
"uv_lock_sha256": "...",
"dirty": false
},
"policy": {
"line_length": 120,
"target_version": "py312",
"preview": false
},
"files": [
{
"path": "scripts/x.py",
"status": "M",
"base_count": 2,
"head_count": 0,
"base_diagnostics": [],
"head_diagnostics": []
}
],
"result": "pass"
}
パスと診断はソートし、stdoutにはJSON以外を出さず、人間向けログはstderrへ送るべきです。
Blocker 3 — Ruff実行が環境依存で、baselineの比較可能性がない
Issue記載の裸の ruff 実行は、PATH、現在ディレクトリ、ユーザー設定、親・子ディレクトリの設定ファイル、gitignore等の影響を受けます。Ruffはファイルごとに最寄りの設定を探索でき、CLI設定は設定ファイルより優先されます。
このリポジトリは pyproject.toml 上では ruff>=0.5 と広く指定していますが、現在の uv.lock はRuff 0.15.18を固定しています。
検査時は設定探索を無効化し、意味に関係する設定をCLIで固定してください。
ruff check
--isolated
--select E501
--line-length 120
--target-version py312
--no-preview
--ignore-noqa
--no-respect-gitignore
--no-cache
--output-format json
-- "${FILES[@]}"
外側のエントリポイントは必ず uv run --locked で起動し、実際に使用したRuffの絶対パス、version、argv、uv.lock hashをレポートへ記録します。
Ruffの終了コードも区別が必要です。
Ruff 0: 正常実行、診断なし
Ruff 1: 正常実行、診断あり
Ruff 2: 設定・CLI・内部エラー
Ruff 2、timeout、JSON decode失敗を「0件」として扱ってはなりません。
Blocker 4 — suppression-scanが現行Ruffの抑制体系を網羅していない
AC3は本文とも親Issueとも一致していません。本文にある exclude、extend-exclude、nested configすらAC3から抜けています。また親 #1138 にある lint.pycodestyle.ignore-overlong-task-comments も落ちています。
現行Ruffには少なくとも以下のコメント抑制があります。
noqa
ruff: noqa
flake8: noqa
ruff: ignore[...]
ruff: disable[...] / # ruff: enable[...]
ruff: file-ignore[...]
Ruff内部でもfile、single/range disable、ignoreは別の抑制種別として処理されています。
設定側も次を対象にすべきです。
lint.ignore / lint.extend-ignore
lint.per-file-ignores
lint.extend-per-file-ignores
exclude / extend-exclude
line-length
lint.pycodestyle.max-line-length
lint.pycodestyle.ignore-overlong-task-comments
lint.task-tags
CLIの --config, --ignore, --extend-ignore, --per-file-ignores
--exit-zero, --add-noqa
単純な正規表現では文字列literal内の "--exit-zero" 等を誤検出します。Pythonコメントは tokenize、TOMLは tomllib で解析し、base/headの正規化された意味を比較してください。
さらに、次の2系統を併用すべきです。
headに新規または広域化されたdirectiveがないこと
通常実行と --ignore-noqa 実行の差がbaseより増えていないこと
--ignore-noqa は現行Ruffではline/file/range suppressionを含むNoqa処理を無効化します。しかし最終CIの予定コマンドには --ignore-noqa がないため、scannerが新しい抑制構文を見落とすと、最終ゲートを迂回できます。
Blocker 5 — AST同値性がPythonソース同値性として過小定義されている
ast.parse(src) のデフォルトではtype commentを保持しません。また、AST parseが成功しても、そのコードが実際にcompile可能とは限りません。Python公式もparse成功とcompile可能性を分けています。
比較は少なくとも次としてください。
base_tree = ast.parse(
base_source,
filename=path,
mode="exec",
type_comments=True,
)
head_tree = ast.parse(
head_source,
filename=path,
mode="exec",
type_comments=True,
)
compile(base_source, path, "exec", dont_inherit=True)
compile(head_source, path, "exec", dont_inherit=True)
equal = ast.dump(base_tree, include_attributes=False) == ast.dump(
head_tree,
include_attributes=False,
)
追加要件:
tokenize.detect_encoding 相当でencoding cookieを尊重
Python 3.12で固定しversionを記録
SyntaxError、UnicodeDecodeError、compile errorはtool error
regular comment、directive、inspect.getsource()、file、traceback行番号等はAST同値性の保証外であることを明記
親Issueが述べている通り、AST同値性は必要条件であって十分条件ではありません。対象テストとsuppression/comment検査を省略できません。
Blocker 6 — ratchetは容易に迂回できる
現在の「changed-fileの件数が増えなければpass」だけでは、次を防げません。
.py を削除して件数を0にする
.py を .txt へrenameする
1ファイルで増やし、別ファイルで減らして合計だけ維持する
都合のよいbase refを指定する
一部ファイルだけをchanged-fileとして渡す
Ruff異常終了を0件として扱う
E501を1件も減らさずpassする
Git差分は git diff --name-status -z でNUL区切り解析し、merge-base基準の三点差分を用いるべきです。GitはA/D/M/R/C/T/U等のstatusを持つため、このmigrationでは対象Pythonファイルの M 以外を明示的に拒否してください。
判定条件は以下です。
全変更Pythonファイル: status == M
各ファイル: head_count <= base_count
scope合計: head_total <= base_total
cleanup mode: head_total < base_total
completion mode: head_total == 0
ファイル名は改行や空白を含み得るため、splitlines() ではなく -z 出力をバイト列として解析してください。
Blocker 7 — guard自身を書き換えて自己検証できる
親 #1138 のChild 3は scripts 配下のcleanupを予定しています。#1144のguardとtestも scripts/ に置かれるため、後続cleanup PRが以下を同一diffで実行できる構造になります。
scripts/e501_migration_guard.py の判定を弱める
guardのtestを弱める
弱めたhead版guardで自分自身を検証する
これは親契約から導けるtrust-boundary上の欠陥です。
必須修正:
Child 2〜4のAllowed Pathsから次を明示的に除外
scripts/e501_migration_guard.py
scripts/tests/test_e501_migration_guard.py
verify-diff 自身も、この2ファイルがmerge-baseと同一blobであることを確認
あるいはhead版ではなく、信頼済みbase SHAから取り出したguardを実行
後続childの安全性根拠になるコードは、検査対象PRから変更不能でなければなりません。
Blocker 8 — ACとVerification Commandsが一致していない
明確な契約不整合があります。
AC3は本文で列挙した検出項目を網羅していない
AC6は pnpm typecheck/lint/test/build の4件を要求するが、VCは pnpm typecheck しか実行しない
新規Python実装自身に対するRuff E/F検査がない
AC1のVCはファイルの存在しか確認せず、JSON schemaや異常系を証明しない
個別pytestだけで、実際のgit diffから全検査するE2Eテストがない
修正版VCは最低限次です。
uv run --locked pytest scripts/tests/test_e501_migration_guard.py
uv run --locked ruff check
--select E,F
--ignore E402
scripts/e501_migration_guard.py
scripts/tests/test_e501_migration_guard.py
pnpm typecheck
pnpm lint
pnpm test
pnpm build
pytestには一時Gitリポジトリを使ったE2E mutation testが必要です。
assertion/test body削除
Python file delete/rename/add
1ファイル増加・別ファイル減少
generic # noqa への広域化
ruff:disable range追加
nested .ruff.toml
Ruff exit 2
malformed JSON
missing base ref / merge-base
unusual filename
type comment変更
parseは通るがcompileできないソース
guard自身の変更
特にPR #1136の事故を縮小再現し、通常pytestがgreenでもverify-diffが失敗するテストをACにしてください。
Blocker 9 — 将来のCI組み込みに必要なGit履歴が現在のcheckoutにない
現行CIは actions/checkout@v6 を追加設定なしで利用しています。
checkout actionは既定では単一コミットだけを取得するため、merge-baseを必要とするguardはshallow checkout上で動かない可能性があります。全履歴を使う場合は fetch-depth: 0、または対象base refの明示fetchが必要です。
#1144でCIファイルを変更しない方針自体は維持できますが、少なくとも次を契約化してください。
merge-baseがない場合はfail。HEAD^ 等へfallbackしない
shallow clone異常系をunit/E2E testする
Child 5の必須変更として fetch-depth またはbase SHA fetchを明記する
推奨する配布・実装形態
現スコープでは、別PyPI packageや独立wheelにする必要はありません。リポジトリローカルのstdlib主体CLIとして配置し、Ruffだけを既存uv.lockから供給する方が単一のversion authorityを維持できます。
設計上は、diff-quality系ツールのように「比較ref・差分抽出・閾値判定・machine-readable report」を一つのコマンドにまとめる構成が適しています。
一方、Ruffのpre-commit配布はRuff本体のversionとrevを一致させ、prebuilt wheelを利用する方式です。今回それを模倣して別配布物を増やすより、uv run --lockedと版付きレポートスキーマを配布契約にする方が、このリポジトリには適合します。
実装規約も既存リポジトリに合わせ、以下を要求すべきです。
shell=True 禁止
subprocess timeout
stderrサイズ上限
path containment検証
symlink・非regular Git mode拒否
一時ディレクトリの確実なcleanup
解析不能時はfail-closed
既存のworktree guardも、path containment、wrapper解析、timeout、解析不能時fail-closedを明示しています。
改訂すべきAcceptance Criteria
verify-diff が唯一の合否判定エントリポイントである。
base/headをSHAへ固定し、merge-baseとNUL区切りchanged-file manifestを生成する。
対象Python変更はMのみ。add/delete/rename、scope外変更、guard自身の変更を拒否する。
全変更ファイルについてencoding-aware decode、compile、type_comments=True AST同値性を検証する。
現行Ruffの全suppression形式と関連設定について、新規追加・広域化を検出する。
Ruff実行はlocked・isolated・固定設定で、exit 1とexit 2を区別する。
ratchetはper-fileとscope合計の両方を検証し、cleanupでは最低1件減少、完了時は0件を要求できる。
report v1にSHA、lock hash、Python/Ruff/guard version、argv、全ファイル診断、全判定結果を含める。
PR #1136型のテスト破壊を含むE2E mutation suiteをpassする。
pytest、Ruff E/F、4つのpnpm gateをVCとして完全一致させる。
IssueのStop Conditionsには「固定スキーマ・キー集合の変更が必要なら停止」とあります。今回まさにbaseline/report schemaと主CLI契約の変更が必要です。したがって、現在のIssue本文を改訂してから実装へ進むのが契約上も正しい処理です。現状のまま実装すると、#1144は後続Child 2〜4の安全性を証明するguardではなく、任意に組み合わせ可能な補助スクリプトに留まります。
squne121 commentedon Jun 23, 2026
issue-refinement-loop 完了 — approved / impl_ready
OWNER REQUEST_CHANGES(#issuecomment-4776476010)の 9 Blocker を本文へ反映し、決定論的レビュー approve・contract-review
status: goを確認しました。反映内容(Blocker → 本文)
verify-diffを唯一の合否判定エントリポイント化。ref→SHA 固定→merge-base→manifest→status/scope→AST→suppression→Ruff→ratchet→report を一体・fail-closed 実行(AC1)。e501-migration-guard/v1を定義。base/head/merge-base SHA・uv_lock_sha256・Python/Ruff/guard version・argv・per-file diagnostics・全判定を含み、path/diagnostics ソート・stdout は JSON のみ(AC8)。--isolated+ 固定設定(--line-length 120 --target-version py312 --no-preview --ignore-noqa --no-respect-gitignore --no-cache --output-format json)、外側uv run --locked、exit 1 と exit 2 を区別し exit 2/timeout/JSON decode 失敗を「0 件」扱いしない(AC6)。# noqa/# ruff: noqa|ignore|disable|enable|file-ignore/# flake8: noqa)をtokenize、config 系(per-file-ignores/extend-ignore/exclude/line-length/pycodestyle.max-line-length/ignore-overlong-task-comments/task-tags等)をtomllib、CLI(--config/--ignore/--exit-zero/--add-noqa等)を対象に base/head 正規化比較で新規追加・広域化を検出(AC5)。ast.parse(..., type_comments=True)+compile(..., dont_inherit=True)+ encoding cookie 尊重。SyntaxError/UnicodeDecodeError/compile error を tool error として区別。AST 同値性は必要条件であり十分条件でないことを明記(AC4)。git diff --name-status -zの NUL 区切りバイト解析・merge-base 三点差分・対象 Python はM限定(A/D/R/C/T/U拒否)・per-file と scope 合計の両判定・cleanup/completion mode(AC2/AC3/AC7)。verify-diffが guard 2 ファイルの merge-base blob 同一性を確認(または信頼済み base SHA から実行)。Child 2〜4 の Allowed Paths から guard 2 ファイルを明示除外する契約を Remaining Parent Gaps に記録(AC3)。actions/checkout@v6はfetch-depth未指定で merge-base 取得不可の懸念。fetch-depth: 0または base SHA fetch を Child 5 の必須変更として Remaining Parent Gaps に記録。merge-base 不在時は fail しHEAD^fallback しないことを AC2 に固定。Allowed Paths は 2 ファイル(
scripts/e501_migration_guard.py/scripts/tests/test_e501_migration_guard.py)のまま不変。Blocker 7/9 の sibling/parent(Child 2〜4・Child 5)波及は本 Issue では起票せず Remaining Parent Gaps に記録(#1138 の child は #1144 マージ後に起票する方針)。検証結果
check_issue_contract.py): approve(C1〜C13 pass。残る warning は CVS/In Scope token overlap の非ブロッキング 1 件のみで、改訂理由を Scope Delta に記載済み)run_contract_review_once.py --mode execute):status: go— readiness go / blockers pass / product_spec pass / vc_preflight passexpected_baseline_fail(exit 4、対象 test/file 未実装)→ gopnpm test1073 passed)→ gosha256:04f771eae0d57a2f7cb5a84365c4504481ab6ce0afc5e9b1dc11d82c5308e158次アクション:
impl-review-loop 1144(人間マージ判断は不要、本 Issue は実装着手可能)。squne121 commentedon Jun 23, 2026
Contract Review Result
squne121 commentedon Jun 23, 2026
実装完了 — Draft PR 起票
verify-diff一体検証エントリポイント(scripts/e501_migration_guard.py)と subprocess 駆動の behavioral テスト(scripts/tests/test_e501_migration_guard.py、PR #1136 型 E2E mutation suite を含む)を実装しました。検証結果
uv run --locked pytest scripts/tests/test_e501_migration_guard.py全件 pass(各 AC の named test を含む)ruff check --select E,F --ignore E402で診断 0 件Allowed Paths(2 ファイル)厳守。後続の領域別 cleanup child は本
verify-diffで安全性を機械検証できます。fix(#1144): adversarial review hardening — ruff-cmd production lock /…
実装: E501 migration guard tooling — verify-diff 一体検証(#1138 Child 1) (#…