Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
goal_ref: "`scripts/` 配下の既存 `*.py` の E501 diagnostic(34 件)を行分割のみで解消し、AST 同値性・suppression 禁止・テスト保全を guard tooling で証明する(#1138 Child 3)"
change_kind: cleanup
parent_issue: "1138"
related_issues:
- "1144"
- "1149"Parent Issue
Parent Goal Ref
- Goal: E501 (line-too-long) を line-length=120 基準で段階的に cleanup し、CI gate を有効化する
- Desired Destination: 全領域の E501 diagnostic が 0 件(ruff --select E501 --ignore-noqa)かつ CI gate が有効
Summary
PR #1148(Child 1, #1144 実装)で導入した scripts/e501_migration_guard.py verify-diff tooling を使い、scripts/ 配下の既存 *.py の E501 (34 件)を行分割のみで解消する。変更は split のみ(add/delete/rename/suppression 禁止)。
- scope:
scripts/配下の既存*.py - E501 fresh count: 34 件(実装: E501 migration guard tooling — baseline 再生成 + changed-file ratchet + AST 同値性 + suppression 検出(#1138 Child 1) #1144 マージ後再測定)
- tooling:
scripts/e501_migration_guard.py verify-diff --scope scripts --mode completion(実装: E501 migration guard tooling — baseline 再生成 + changed-file ratchet + AST 同値性 + suppression 検出(#1138 Child 1) #1144 で導入済み) - 前提: 実装: E501 migration guard tooling — baseline 再生成 + changed-file ratchet + AST 同値性 + suppression 検出(#1138 Child 1) #1144(guard tooling)および 実装: .claude/scripts の E501 cleanup(既存 *.py の行分割のみ・#1138 Child 2) #1149(.claude/scripts cleanup)のマージ後に着手
Goal
scripts/ 配下の ruff check --select E501 --ignore-noqa scripts/ が exit 0 になること。
Outcome
scripts/配下の E501 diagnostic が 0 件- 変更された全 Python ファイルの base/head AST が同値
- 新規 suppression(noqa / per-file-ignores / exclude / line-length 変更)なし
- 変更対象テスト(
scripts/tests/)が全 pass
Desired Destination
scripts/配下の既存*.pyの E501 diagnostic が 0 件(ruff check --select E501 --ignore-noqa scripts/で確認)- 変更は行分割のみ。コメント・docstring・文字列値・shebang・encoding cookie・file mode 変更なし
In Scope
scripts/配下の既存*.pyの E501 diagnostic を行分割のみで解消する(status: M のみ、add/delete/rename 禁止)scripts/e501_migration_guard.py verify-diffを使って AST 同値性・suppression 禁止・テスト保全を証明する
Out of Scope
pyproject.toml/uv.lock/ruff.tomlの変更exclude/extend-exclude/line-lengthの変更.claude/scripts/配下の cleanup(実装: .claude/scripts の E501 cleanup(既存 *.py の行分割のみ・#1138 Child 2) #1149 で完了).claude/skills/配下の cleanup(Child 4 で予定)- CI gate 有効化(Child 5 で予定)
Current Validated Scope
- 対象ディレクトリ:
scripts/のみ - line-length baseline: 120(
pyproject.tomlで指定済み、変更しない) - E501 fresh measurement(HEAD a20691b, ruff 0.15.18, --ignore-noqa):
e501_measurement: command: "uv run --locked ruff check --select E501 --ignore-noqa --output-format json scripts/" total_diagnostics: 34 per_file: "scripts/agent-guards/local_main_branch_guard.py": 2 "scripts/agent-ops/materialize_cleanup_contract.py": 1 "scripts/check-visual-artifact-pipeline.py": 4 "scripts/check_claude_codex_agent_parity.py": 9 "scripts/check_codex_agent_config.py": 5 "scripts/check_local_main_branch_state.py": 1 "scripts/check_subagent_launch_ledger.py": 1 "scripts/context_mode_storage_probe.py": 3 "scripts/pr_body_validator.py": 3 "scripts/tests/test_milestone_rollup.py": 2 "scripts/tests/test_pr_body_validator.py": 3 historical_baseline_note: "E501 baseline は実装着手時に main HEAD の SHA で再測定すること(#1144/#1149 マージ後 HEAD が変わった)。"
- 変更禁止:
pyproject.toml/uv.lock/ nestedruff.toml/.ruff.toml/exclude/extend-exclude
Decisions Fixed
- E501 (line-too-long) の段階導入 — line-length=120 基準で残 343 件を cleanup #1138 の Phase Handoff Contract を継承: cleanup child は担当領域の既存
*.pyの変更のみ(add/delete/rename 禁止) - AST 同値性(
ast.dump(ast.parse(src), include_attributes=False)比較)を全変更 Python ファイルで必須とする - 新規
# noqa/per-file-ignores/exclude/extend-exclude/line-length変更 /--exit-zero/--add-noqaを禁止する - guard tooling(
scripts/e501_migration_guard.py verify-diff)を使用して証跡を生成する
Remaining Parent Gaps
- Child 4(
.claude/skillsE501 cleanup 313 件)未着手 - Child 5(全領域再検証 + CI gate 有効化)未着手
Allowed Paths
scripts/agent-guards/local_main_branch_guard.py(status: M のみ)scripts/agent-ops/materialize_cleanup_contract.py(status: M のみ)scripts/check-visual-artifact-pipeline.py(status: M のみ)scripts/check_claude_codex_agent_parity.py(status: M のみ)scripts/check_codex_agent_config.py(status: M のみ)scripts/check_local_main_branch_state.py(status: M のみ)scripts/check_subagent_launch_ledger.py(status: M のみ)scripts/context_mode_storage_probe.py(status: M のみ)scripts/pr_body_validator.py(status: M のみ)scripts/tests/test_milestone_rollup.py(status: M のみ)scripts/tests/test_pr_body_validator.py(status: M のみ)
status M のみ(追加/削除/リネームを含まない)
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 行分割が import side effect / registration / 文字列値を破壊する場合
- suppression(noqa 等)が必要な場合
- Python テストが構造的に破壊される(test function / class / assertion 削除が必要)場合
Required Skills
- Python / Ruff
Runtime Verification Applicability
- decision: not_applicable
- reason: Python lint(E501)の行分割 cleanup のみ。ブラウザやゲーム実行を伴う runtime 動作検証の対象ではない。検証は静的 lint / AST / pytest で行う。
Acceptance Criteria
- AC1: 実装開始時の base SHA /
uv.lockSHA /ruff --version/scripts/E501 JSON inventory を記録する(guard verify-diffのuv_lock_sha256フィールドで確認) - AC2:
uv run --locked ruff check --select E501 --ignore-noqa scripts/が exit 0(E501 = 0件) - AC3:
uv run --locked ruff check --select E,F --ignore E402 scripts/が exit 0 - AC4: 変更 Python ファイルは modified のみで add/delete/rename を含まない(
guard verify-diffのchecks.status_scope.okで確認) - AC5: base/head の AST が全変更 Python ファイルで同一(
guard verify-diffのchecks.ast_equivで確認) - AC6: 新規 noqa / per-file-ignore / exclude / line-length 変更 /
--exit-zero/--add-noqaを含まない(guard verify-diffのchecks.suppression.okで確認) - AC7:
scripts/tests/の全 Python test が pass(uv run pytest scripts/tests/)、および関連 CI テストが pass - AC8: test function / class / assertion の削除を含まない(
guard verify-diffの AST 同値性検証で確認) - AC9:
pnpm typecheck/pnpm lint/pnpm test/pnpm buildが exit 0
Verification Commands
# AC1
# baseline-expect: fail
# preflight-scope: pr_review_only
$ env -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMD uv run --locked python scripts/e501_migration_guard.py verify-diff --base-ref "$PR_BASE_SHA" --head-ref "$PR_HEAD_SHA" --scope scripts --mode completion# AC2
# baseline-expect: fail
# preflight-scope: pr_review_only
$ uv run --locked ruff check --select E501 --ignore-noqa scripts/# AC3
# baseline-expect: pass
# preflight-scope: pr_review_only
$ uv run --locked ruff check --select E,F --ignore E402 scripts/# AC4
# baseline-expect: fail
# preflight-scope: pr_review_only
$ env -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMD uv run --locked python scripts/e501_migration_guard.py verify-diff --base-ref "$PR_BASE_SHA" --head-ref "$PR_HEAD_SHA" --scope scripts --mode completion# AC5
# baseline-expect: fail
# preflight-scope: pr_review_only
$ env -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMD uv run --locked python scripts/e501_migration_guard.py verify-diff --base-ref "$PR_BASE_SHA" --head-ref "$PR_HEAD_SHA" --scope scripts --mode completion# AC6
# baseline-expect: fail
# preflight-scope: pr_review_only
$ env -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMD uv run --locked python scripts/e501_migration_guard.py verify-diff --base-ref "$PR_BASE_SHA" --head-ref "$PR_HEAD_SHA" --scope scripts --mode completion# AC7
# baseline-expect: pass
$ uv run --locked pytest scripts/tests/test_milestone_rollup.py scripts/tests/test_pr_body_validator.py .claude/hooks/tests/test_local_main_branch_guard.py# AC8
# テスト関数が削除されていないことを確認(base の test 定義数以上を head でも確認)
# baseline-expect: pass
# preflight-scope: pr_review_only
$ env -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMD uv run --locked python scripts/e501_migration_guard.py verify-diff --base-ref "$PR_BASE_SHA" --head-ref "$PR_HEAD_SHA" --scope scripts --mode completion# AC9
# baseline-expect: pass
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildNotes
- AC1/AC2/AC4/AC5/AC6 は
guard verify-diff一体実行で証跡生成(複数 AC を単一コマンドで網羅) guard verify-diffはenv -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMDを付与してデフォルト ruff を使用すること- 高リスク行(文字列値・regex・f-string・fixture data)は行分割後に対象テストで動作確認すること
ruff format補助は可だが、完了判定は E501 diagnostic 0 件で行う- guard hardening 前提条件(B2/B3/B4):
scripts/e501_migration_guard.pyの以下の修正が先行 PR(guard hardening)でマージ済みであること:E501_GUARD_ALLOW_TEST_RUFF/E501_GUARD_RUFF_CMD環境変数が production 実行で fail になる- suppression scanner が Ruff 公式 grammar(
#noqa空白なし / block disable-enable scope)に準拠 - file mode の base == head 同一性チェックを追加
guard verify-diff実行時はenv -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMDを付与する(VC 参照)- PR review 時は immutable PR SHA(
$PR_BASE_SHA/$PR_HEAD_SHA)を使用する - AC7 除外テスト(pre-existing failure):
tests/test_agent_parity.py::TestB4RealRepoParity::test_real_repo_parityおよびtests/test_codex_agent_bridge_contract.py::test_python_cli_passes_on_fixture_repoは.claude/agents/web-researcher.mdの route token 不整合(実装:scriptsの E501 cleanup(既存*.pyの行分割のみ・#1138 Child 3) #1156 スコープ外)により baseline で失敗中。E501 cleanup の影響外のため AC7 VC から除外。
Source
dedupe_key: "child:squne121/loop-protocol:#1138:child-3"
parent_issue: 1138
child_number: 3Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 25, 2026
判定
REQUEST_CHANGES — 現契約のまま実装開始不可。
方向性は妥当ですが、PR差分の取り方、guardの信頼境界、suppression検査、テスト範囲に偽陽性・偽陰性を作れる穴があります。特に以下のBlocker 1〜4は、#1156のAllowed Paths外にあるguard自体の修正を要するため、先行hardening PRが必要です。
Blocking findings
1.
HEAD~1はPR全体ではなく最後の1コミットしか検証しないAC1/4/5/6のVerification Commandはすべて、
を使っています。Gitの
~1はfirst-parentを1世代だけ遡る指定であり、PRのbaseではありません。2コミットPRなら最初のcleanupを丸ごと検査対象外にできます。main取り込みのmerge commitが最後にあれば、検証対象がmerge差分だけになる場合もあります。実際、直前のSibling PR #1152は2コミット構成で、PR本文では正しくimmutableなPR base/head SHAによるout-of-band検証を要求していました。([Git]1)必須修正: 全コマンドをGitHub上の不変なPR base/head SHAへ変更する。
さらにreportの
refs.base_shaとrefs.head_shaが指定SHAと完全一致することを機械的にassertすべきです。2. 現行guardは環境変数経由の任意Ruffを「trusted」と判定する
現行実装は、次の2環境変数が設定されると任意コマンドを
shlex.split()してRuffとして実行します。しかも
trusted_ruffは、command sourceがenv_test_overrideなら真になります。つまり、Ruffのversion出力と空JSONを返す偽スクリプトでguardのE501判定を偽造できます。テスト自身もこの経路でfake Ruffを注入しています。これはPR #1148の修正コメントにある「非信頼cmdはpass不可」という説明とも矛盾します。([GitHub]2)
#1156のNotesには
env -uを付けるとありますが、実際のVerification Commandには付いておらず、そもそも呼出側の環境衛生を信頼境界にしてはいけません。必須修正:
3. suppression scannerがRuff公式の構文・作用域を再現していない
現在のscannerは
# noqaや# ruff:など、空白を固定したprefixに対してstartswith()し、ファイル全体を「blanketの有無」と「codeの集合」へ集約しています。テストも空白入りの代表8形式しか検証していません。しかしRuff公式仕様では次が有効です。
#noqaのように#直後の空白なし#ruff:/#flake8:の空白なしdisable/enableの位置、インデント、code順によるrange形成特にblock suppressionは位置と対応する
enableによって作用域が決まります。([Astral Docs]3)現在の集合比較では、例えばbaseに既に
# noqa: E501が1個あれば、headで同じdirectiveを別の行へ追加してもcode集合が変わらず検出されません。またdisableを前方へ移動して抑制範囲を広げても、集合が同じならpassし得ます。必須修正:
--ignore-noqa実行の診断差もbase/headで比較する。4. 「コメント・shebang・encoding cookie・file mode不変」を証明していない
#1156はコメント、shebang、encoding cookie、file modeを変更しないと明記していますが、guardのAST比較ではそれらを保証できません。
ast.dump(..., include_attributes=False)は行番号・列番号を含めず、通常コメントやshebangもASTに入りません。([Python documentation]4)さらにguardのfile mode検査は、baseとheadがそれぞれ
100644または100755であることしか確認せず、両者が同一かを比較していません。したがって、E501を修正しながら実行ビットを変更してもpassできます。必須修正:
base_mode == head_modegit diff --summary "$BASE_SHA" "$HEAD_SHA"が空5.
--scope scriptsはIssueのAllowed Pathsを証明しないguardのstatus checkは、「
scripts/配下」「.py」「status M」であれば、Issueに列挙されていないPythonファイルも受理します。一方、#1156は11ファイルを列挙した後に、
scripts/tests/全体もAllowed Pathsへ追加しています。「テスト実行参照用」と書かれていても、契約上は同ディレクトリ内の任意ファイル変更を許可する形です。またcompletion modeのRuff測定対象は、
changed_manifestから得た変更ファイルだけです。34件のうち1ファイルを変更せず残しても、guard単体のhead_total == 0は成立し得ます。必須修正:
scripts/tests/というディレクトリ許可を削除。changed_files == expected_inventory_filesMscripts/全体へE501を実行する。6. AC7のテスト範囲が変更対象をカバーしていない
uv run pytest scripts/tests/だけでは不十分です。変更対象には、直接対応するテストが別ディレクトリにあるものが複数あります。local_main_branch_guard.py:.claude/hooks/tests/test_local_main_branch_guard.pyとtests/codex/test_local_main_branch_guard.pycheck_claude_codex_agent_parity.py:tests/test_agent_parity.pycheck_codex_agent_config.py:tests/test_codex_agent_bridge_contract.pymaterialize_cleanup_contract.py:.claude/hooks/tests/test_worktree_scope_guard.pyとの統合境界pnpm testはpackage.json上ではVitestであり、Pythonテストの代替にはなりません。現在のCIでもCodex guard testは専用laneで個別実行されています。AC7には、変更ファイルから対応テストを決定する明示的なtest matrixが必要です。
7. AC8の
rg -c "def test_"はテスト保全の証拠にならないこのコマンドにはbase/head比較も期待値assertもありません。以下を検出できません。
async def test_*や動的生成testscripts/tests/外のテスト削除親#1138は、PR #1136で「CI greenのままテスト本体が大量削除された」事例を理由に、この種の表面的な検証を明示的に否定しています。([GitHub]5)
AC8の
rgは削除し、immutable SHAを使ったAST比較と、実pytestの収集・実行結果へ置き換えるべきです。その他の契約不整合
uv run pytestで--lockedが欠落しています。--lockedはlockfileが欠落・更新必要ならエラーにする再現性オプションです。([Astral Docs]6)typecheck / lint / test / buildの4件ですが、Verification Commandsはpnpm typecheckしかありません。a20691...を参照していますが、同PRは別のsquash merge commitでmainへ統合されています。実装開始時の実base SHAで再測定し、現在値として更新すべきです。ruff formatを包括的に許可すると、E501対象行以外のformat churnを作れます。このIssueではbaseline diagnosticsに対応するhunk以外の変更を禁止する方が安全です。必要な修正順序
guard hardening用の先行Issue/PRを作成
hardening PRのmerge後、mainの不変SHAで34件inventoryを再生成
#1156のAllowed Pathsを再生成したinventoryの正確なファイル集合へ固定
Verification Commandsをimmutable PR SHA使用へ置換
修正版Verificationの中核
最終結論: #1156単独の文面修正だけでは不十分です。現guardのenv trust、suppression scope、file mode/lexical invariantsを先に修正し、そのmerge後のSHAを新しいbaseとして#1156を再baseline化する必要があります。
squne121 commentedon Jun 25, 2026
CONTRACT_REVIEW_RESULT_V1
status: go — 全チェック pass。
implement-issueへの handoff 可能。Issue
#1156 — 実装:
scriptsの E501 cleanup(既存*.pyの行分割のみ・#1138 Child 3)Checks
state/needs-humanなし)worktree-issue-1156-*未使用)implement_issueVC Preflight 集計
guard verify-diff --scope scripts --mode completionruff check --select E501 --ignore-noqa scripts/ruff check --select E,F --ignore E402 scripts/guard verify-diffguard verify-diffguard verify-diffuv run --locked pytest scripts/tests/... hooks/tests/...guard verify-diffpnpm typecheckpnpm lintpnpm testpnpm buildsummary: expected_fail=0, unexpected_pass=0, blocked=0, skipped=7, expected_pass=5
Contract Snapshot
scripts/配下の E501 diagnostic が 0 件・AST 同値・suppression 禁止・テスト保全scripts/配下の既存 11 ファイル(status: M のみ)worktree-issue-1156-scripts-e501-cleanup(競合なし)sha256:75ae3aae9addb14d48c651a4a6cf9460acb0c374e16f78bf8a2b6eee33647882Acceptance Criteria(再掲)
ruff check --select E501 --ignore-noqa scripts/exit 0ruff check --select E,F --ignore E402 scripts/exit 0scripts/tests/全 Python test passpnpm typecheck/pnpm lint/pnpm test/pnpm buildexit 0注意事項
guard verify-diffはpreflight-scope: pr_review_onlyのため PR review 時に検証env -u E501_GUARD_ALLOW_TEST_RUFF -u E501_GUARD_RUFF_CMDを付与することtests/test_agent_parity.py::TestB4RealRepoParity::test_real_repo_parityおよびtests/test_codex_agent_bridge_contract.py::test_python_cli_passes_on_fixture_repoは baseline で失敗中(Issue スコープ外)generated by issue-contract-review skill — 2026-06-25T10:44:00Z
squne121 commentedon Jun 25, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
scriptsの E501 cleanup(既存*.pyの行分割のみ・#1138 Child 3) #1156approvedfix(#1156): B1 guard.py 差し戻し + B2 test plan エントリ追加
fix(#1156): scope 縮小 — guard out_of_scope + CI uncovered 制約により 2 ファイル…
chore(ci): test_pr_body_validator.py を python-test plan に登録し #1156 を …