Repository navigation
impl(#974): worktree_scope_guard に LOCAL_MAIN_SCRATCH_ALLOW_V1 を追加 - #979
Conversation
Preview URLPreview removed (PR #979 closed). |
|
これは差分・関連 Issue/PR/comment・公式ドキュメントに基づく敵対的レビューです。手元で PR head の pytest/CI を再実行したわけではありません。 判定REQUEST CHANGES。Draft 継続は妥当だが、ready-for-review / merge は不可です。 PR #979 は Issue #974 の方向性には概ね沿っています。 ただし、現状は Issue #974 の AC を満たしていない、かつ branch 判定が contract より広すぎる ため、例外が “local main scratch” ではなく “main っぽいブランチ上の scratch allow” になっています。これは guard 例外としては危険です。 関連仕様の読み取りIssue #974 の正本は、local main context を この設計は #960 / PR #971 の worktree guard を緩める例外です。#960 は active issue worktree 外への Write/Edit/MultiEdit と mutating Bash を PreToolUse hook で fail-closed block する契約で、PR #971 側では realpath/commonpath、bounded stderr、secret boundary guard 先行、mutating Bash classifier などがレビュー済みでした。 Claude Code の PreToolUse hook は tool 実行前に動き、blocking decision に使われます。exit code 2 / block は実際に tool call を止める enforcement point なので、ここに入る allow 例外は単なる利便性ではなく policy そのものです。([Claude Code]1) ブロッカー1. AC11 未充足。PR 本文の “14 tests pass” は Issue #974 の要求より少ないIssue #974 の AC11 は、 実際の追加テストは、allow が 不足している最低限のテスト:
修正要求: Issue #974 の AC11 に列挙された全ケースを追加してください。特に 2. branch 判定が contract より広い。
|
- _MAIN_BRANCH_RE から develop/development を除去 - _repo_default_branch() を symbolic-ref 経由に修正し _is_local_main_context() に組み込む - test_block_global_gitignore_only_match を core.excludesFile + .git/info/exclude を実際に設定して検証する形に修正 - block_write_inside_dot_git_even_if_ignored を追加(AC11 補完) - block_write_inside_claude_worktrees_even_if_ignored を追加(AC11 補完) - block_git_add_force_ignored_scratch_file を追加(AC9 regression 固定) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
PR レビュー判定 (iteration 1) — Issue #974
検証サマリー
Allowed Paths Gate (review_subagent 独立再計算)
- contract_snapshot_url: #974 (comment)
- expected_contract_fingerprint:
sha256:f02fb5a89fd34567398cfec708f1dd0ca13ed71ba51dd47fea234f38780f8f1f - base_sha:
17892bb3808018dc1c397b268016479e3cdb6982 - head_sha:
60233b44f7a99bc92fbb73281b75a53a3773c933
changed files (gh pr diff --name-only):
.claude/hooks/tests/test_local_main_scratch_allow.py.claude/hooks/worktree_scope_guard.py.gitignore
Allowed Paths (contract):
.claude/hooks/worktree_scope_guard.py.claude/hooks/tests/test_local_main_scratch_allow.py.gitignore
全 changed files が Allowed Paths 内に収まる。gate: ok
AC 充足状況
AC1 — _is_local_main_context() が 3 条件(cwd==project_root, branch in main/master/trunk + repo_default, worktree 外)を検証。iteration-0 blockerだった develop/development は _MAIN_BRANCH_RE = re.compile(r"^(main|master|trunk)$") から除去済み。_repo_default_branch() が git symbolic-ref refs/remotes/origin/HEAD 経由でリポジトリ実 default を追加。充足
AC2 — playwright-report/, test-results/ への gitignored & untracked Write を allow するテスト2本が存在し pass 済み。充足
AC3 — safe-prefix 外、tracked、global-only ignore、sensitive path、symlink を含む target の block テスト群が存在。充足
AC4 — _is_under_safe_prefix() が os.path.normpath + top_component membership で component boundary 照合。artifacts_evil/ および artifacts/../README.md ブロックテスト存在。充足
AC5 — _has_symlink_component() が safe_root 存在・非 symlink + path component 各段の islink チェックを実施。3テスト(safe_root symlink / parent symlink / target symlink)が存在。充足
AC6 — _SENSITIVE_PATTERNS 正規表現が .env*, *.pem/key/p12/pfx, *token*/*secret*/*credential*, .npmrc, .pypirc, .netrc, .ssh/**, .config/gh/** を網羅。テスト2本存在。充足
AC7 — _is_git_tracked() が git ls-files --error-unmatch で判定。テスト存在。充足
AC8 — _is_repo_local_gitignore() が git check-ignore -v 出力の source を project_root 内かつ .git/ 外に限定。iteration-0 blocker: test_block_global_gitignore_only_match は core.excludesFile + .git/info/exclude を実際に設定する形に修正済み。新規 test_block_git_info_exclude_only_match も追加。充足
AC9 — Bash ツールへの scratch 例外は Phase 1 スコープ外(AC10)。test_block_git_add_force_ignored_scratch_file は tool: "Bash" ペイロードで git add -f が block されることを検証(Bash の git mutation block は既存ガードが担う)。充足
AC10 — local_main_scratch_allow_v1() 冒頭で if tool_name not in WRITE_TOOLS: return False により Write/Edit/MultiEdit に限定。充足
AC11 — 17 required tests すべて実装済み(test_block_git_info_exclude_only_match は bonus 18 本目)。control-plane 実行: 18/18 pass。充足
iteration-0 blockers 解消確認:
block_write_inside_dot_git_even_if_ignored/block_write_inside_claude_worktrees_even_if_ignored/block_git_add_force_ignored_scratch_file— 追加済み、presentdevelop/development除去 —_MAIN_BRANCH_RE = r"^(main|master|trunk)$"確認済みtest_block_global_gitignore_only_match非 proving 問題 —core.excludesFile実設定 +.git/info/exclude設定で修正済み
CI 状況
| ジョブ | 結果 |
|---|---|
| typecheck | SUCCESS |
| lint | SUCCESS |
| test | SUCCESS |
| build | SUCCESS |
| actionlint | SUCCESS |
| PR Body Japanese Check | SUCCESS |
| python-test | IN_PROGRESS (実行中) |
| e2e | IN_PROGRESS (実行中) |
python-test / e2e は IN_PROGRESS のため merge_state_status は BLOCKED。CI 完了後に MERGEABLE になることを想定。
LOOP_VERDICT_V2:
verdict: APPROVE
merge_ready: false
merge_state_status: BLOCKED
reviewed_head_sha: "60233b44f7a99bc92fbb73281b75a53a3773c933"
required_auto_actions:
- action: wait_ci
reason: "python-test / e2e が IN_PROGRESS。完了後に merge_ready = true を期待する。"
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
changed_files:
- .claude/hooks/tests/test_local_main_scratch_allow.py
- .claude/hooks/worktree_scope_guard.py
- .gitignore
contract_allowed_paths:
- .claude/hooks/worktree_scope_guard.py
- .claude/hooks/tests/test_local_main_scratch_allow.py
- .gitignore
contract_source_kind: issue_comment
contract_source_id: "https://github.com/squne121/loop-protocol/issues/974#issuecomment-4735850281"
expected_contract_fingerprint: "sha256:f02fb5a89fd34567398cfec708f1dd0ca13ed71ba51dd47fea234f38780f8f1f"
blockers: []
comments: >
iteration-0 の 3 blockers(AC11 不足 / develop 過広 branch 判定 / global_gitignore_only_match 非 proving)
はすべて iteration-1 (commit 60233b44) で解消済み。
AC1..AC11 全充足。changed files は Allowed Paths に完全準拠。
CI は python-test / e2e が完了次第 merge 可。
概要
Issue #974 の実装。
worktree_scope_guard.pyにLOCAL_MAIN_SCRATCH_ALLOW_V1判定関数を追加し、ローカル main コンテキスト(cwd == project_rootかつbranch == mainかつ issue worktree 外)からの safe_scratch_prefix 配下への Write/Edit/MultiEdit のみを許可する例外を実装する。この PR は #974 を解決する(Closes #974)。
変更内容
.claude/hooks/worktree_scope_guard.pyLOCAL_MAIN_SCRATCH_ALLOW_V1関数を追加(AC1 から AC10)SAFE_SCRATCH_PREFIXES:artifacts/、playwright-report/、test-results/、coverage/、.cache/_is_local_main_context(): 3 条件(cwd が project_root と等しい、ブランチが main、worktree 外)を検証_is_sensitive_path(): 機密パスの除外リスト(.env*、*.pem/key、*token*/*secret*、.npmrc、.ssh/**、.config/gh/**)_is_under_safe_prefix(): コンポーネント境界照合(os.path.commonpathを使用)_is_git_tracked():git ls-files --error-unmatchによる追跡済みファイルの判定_is_repo_local_gitignore():git check-ignore -vのソースがリポジトリローカルの.gitignore由来かを検証(相対パスは project_root を基準に解決)_has_symlink_component(): safe_root 自身および path コンポーネント内のシンボリックリンクを検出_decide_write()に LOCAL_MAIN_SCRATCH_ALLOW_V1 チェックを統合(ターゲットが worktree 外の場合にのみ実行).claude/hooks/tests/test_local_main_scratch_allow.pyAC11 準拠の behavioral harness(14 テスト、全件合格):
許可ケース(AC2):
allow_local_main_write_to_repo_ignored_untracked_playwright_report— playwright-report への書き込みを許可allow_local_main_write_to_repo_ignored_untracked_test_results— test-results への書き込みを許可ブロックケース(AC3 から AC8):
block_safe_prefix_not_in_repo_gitignore— リポジトリ gitignore にない場合はブロック(AC8)block_global_gitignore_only_match— グローバル gitignore のみの一致はブロック(AC8)block_tracked_file_under_safe_prefix— インデックス追跡済みファイルはブロック(AC7)block_artifacts_prefix_sibling_artifacts_evil— コンポーネント境界外の siblings はブロック(AC4)block_artifacts_dotdot_readme—../によるパス逸脱はブロック(AC4)block_symlink_safe_root_to_outside— safe_root がシンボリックリンクの場合はブロック(AC5)block_symlink_parent_component— 親コンポーネントがシンボリックリンクの場合はブロック(AC5)block_existing_target_symlink— ターゲット自体がシンボリックリンクの場合はブロック(AC5)block_sensitive_dotenv_under_artifacts— .env ファイルはブロック(AC6)block_sensitive_npmrc_under_cache— .npmrc ファイルはブロック(AC6)block_write_when_cwd_inside_issue_worktree— issue worktree 内からの書き込みはブロック(AC1)block_write_when_branch_is_issue_branch_not_main— issue ブランチからの書き込みはブロック(AC1).gitignoresafe_scratch_prefix の 5 エントリを追加:
artifacts/playwright-report/test-results/coverage/.cache/検証結果
uv run pytest .claude/hooks/tests/test_local_main_scratch_allow.py -vuv run pytest .claude/hooks/tests/ --ignore=...test_local_main_scratch_allow.pypnpm typecheckpnpm lintpnpm testpnpm buildPhase 2 スコープ外
Bash への書き込み例外(AC9 の一部)は Issue #963 が未対応のため Phase 2 の follow-up issue に分離する。
Allowed Paths 準拠
変更対象ファイル:
.claude/hooks/worktree_scope_guard.py: 変更あり.claude/hooks/tests/test_local_main_scratch_allow.py: 新規追加.gitignore: 変更ありallowed_paths_compliance: true