Repository navigation
github_metadata_assert で GitHub milestone metadata の安全な exit code assertion 経路を追加する (#942) - #953
Conversation
GitHub milestone metadata の readback を raw `gh api` 一般解禁なしで exit code assertion として VC に書けるよう github_metadata_assert を追加する。 - classify_static_command の dispatch を実装に接続(dead code 解消)。 allowed な github_metadata_assert は run_command でリテラル実行せず _check_github_metadata_assertion を呼び exit code で分類する。 - exit 0 → expected_pass/go、exit 1 → expected_fail/go、 exit 2..8(gh 不在/auth/404/rate limit/timeout/invalid JSON)は github_metadata_assert_environment_error として human_judgment にし false pass にしない。 - endpoint は repos/<owner>/<repo>/milestones/<number> のみ許可。 危険な flags と mutating method は block。 - classify→execute の wiring を fake gh で end-to-end 検証する test を追加。 各 AC の -k substring が 1 件以上 collect する命名に整える。 - body-authoring.md / SKILL.md / vc-preflight.md に authoring guidance 追記。 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-953/ The preview will be removed when this PR is closed. |
squne121
left a comment
There was a problem hiding this comment.
レビュー判定: APPROVE(correctness / contract 充足)
impl-review-loop の最終 judge として、linked issue #942 の contract と PR diff・証跡を照合した。self-authored PR のため --comment で記録する。
contract 照合(control-plane が worktree で独立実行して確認)
| AC | 内容 | 検証結果 |
|---|---|---|
| AC1 | github_metadata_assert を first-class command として認識・分類 |
PASS(-k github_metadata_assert_recognized 6 passed) |
| AC2 | endpoint subset 限定(絶対URL/query/traversal/placeholder を reject) | PASS(6 passed) |
| AC3 | not_contains: present→非0 / absent→0 |
PASS(2 passed) |
| AC4 | contains: present→0 / absent→非0 |
PASS(2 passed) |
| AC5 | dangerous flags / graphql を block | PASS(17 passed) |
| AC6 | mutating method(POST/PATCH/PUT/DELETE・-X・大小混在)を block |
PASS(11 passed) |
| AC7 | 環境エラーを present/absent と別分類し false pass にしない | PASS(7 passed) |
| AC8 | 既存 gh_api_is_blocked 等が regression しない |
PASS(full suite 242 passed) |
| AC9 | docs 3ファイルに github_metadata_assert 同期 |
PASS(2 / 3 / 4 件) |
| AC10 | pnpm typecheck / lint / test |
PASS(CI 上で全 green) |
設計面の確認
- raw
gh apiの一般 allowlist は一切緩めていない。github_metadata_assert経由のみ、内部で固定 argvgh api --method GET repos/<owner>/<repo>/milestones/<number>(shell=False)を実行する。入力 flags に関係なく実行 argv は固定で、defense in depth になっている。 - execution wiring が実在することを確認した。
classify_static_commandが allowed を返した github_metadata_assert コマンドはrun_commandのリテラル実行を回避し_check_github_metadata_assertionに dispatch され、exit code で分類される(前任の dead code 問題は解消済み)。 - 環境エラー(gh 不在 / auth / 404 / rate limit / timeout / invalid JSON)は
decision: human_judgmentに分類され、exit 0(go)の false pass にならないことを end-to-end テストで担保している。 - commit は Allowed Paths の 5 ファイルちょうどに限定されている。
マージ前に人間が確認すべき残課題(#942 とは無関係)
e2eチェックが fail しているが、原因は MCR(mcr.microsoft.com/playwright)の Docker pull がtoomanyrequests/unauthorizedになる CI インフラのレート制限である。本 PR はsrc// render / e2e を一切変更しておらず、e2e の失敗は #942 のコードに起因しない。MCR のレート制限が解消したタイミングでe2eを再実行すれば green になる見込み。- それ以外の必須チェック(build / lint / test / typecheck / python-test / actionlint / PR Body Japanese Check 等)はすべて pass している。
以上より、コードと contract の観点では APPROVE。最終マージは、上記 e2e インフラフレークの再実行を含め人間の判断に委ねる。
判定: REQUEST_CHANGES / BLOCK方向性は妥当です。raw ただし、現 diff には false pass を作れる穴が残っています。特に「存在しない field を 良い点PR は #942 の主目的である「GitHub milestone metadata を deterministic / non-mutating / exit-code based assertion として preflight で扱う」方向に沿っています。#942 は raw
内部実行が
BLOCKER 1: 存在しない field が
|
…LOCKER 1-3) レビュー指摘の false pass 穴を塞ぐ: - BLOCKER1: field を `description` allowlist 化し typo を classify 時に reject。 response に field 不在(schema drift)は absent 扱いせず exit 9(env error)にする。 - BLOCKER2: コマンドを exactly 5 argv に限定。flags/余分な positional を全 reject (graphql・dangerous flags・mutating method も arity で自然に block)。 - BLOCKER3: 未知の gh 非0失敗を raw exit 1 で返さず exit 8(env error)に分類し、 semantic assertion failure(exit 1) と混同しない。 - docs(SKILL/body-authoring/vc-preflight)を field=description 固定・exact-4-args に同期。 - negative tests 追加(field typo / missing field / extra positional / unknown gh failure)。 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
996c9bd to
ee7b355
Compare
squne121
left a comment
There was a problem hiding this comment.
レビュー対応報告(REQUEST_CHANGES → 修正済み)
的確な指摘に感謝します。BLOCKER 1-3 と MAJOR 1/2 を ee7b3553 で修正しました。各点への対応は以下です。
BLOCKER 1: missing / typo field の false pass
fieldを allowlist 化(_ALLOWED_GITHUB_METADATA_FIELDS = {"description"})し、descriptonのような typo は validator が classify 時に reject するようにした。_check_github_metadata_assertionは response に field が存在しない場合field_value = ""(absent)にせずexit 9(schema/environment error)を返す。wiring 側でexit 9はhuman_judgmentに分類され、not_containsの false pass にならない。- 追加テスト:
test_github_metadata_assert_field_typo_rejected/test_github_metadata_assert_missing_field_is_not_absent_pass(response に description が無いケースでresult == 9を確認)。
BLOCKER 2: extra argv の許容と実行時無視
github_metadata_assertをlen(argv) == 5(exactly 4 引数) に限定し、余分な positional / flags を全て reject。validator の flag 走査ループは削除した。- flag surface を一切受け付けないため、dangerous flags・
graphql・mutating method(--method POST/...、-X、--method=、大小混在)は arity 規則だけで漏れなく block される(MAJOR 1 の case-sensitive 問題も解消)。 - docstring / docs の
[flags...]・<field>一般化を削除し drift を解消。 - 追加テスト:
test_github_metadata_assert_exactly_five_argv_rejects_extra_positional。
BLOCKER 3: 未知の gh 失敗 exit 1 の誤分類
_check_github_metadata_assertionがexit 1を返すのは「API 成功 + JSON parse 成功 + assertion 不成立」の場合のみに限定した。- 既知でない
gh非0失敗(5xx・403 secondary rate limit・ネットワーク/DNS/TLS 失敗・gh version drift・空 stderr 等)は raw returncode をそのまま返さずexit 8(environment error)にする。 - 追加テスト:
test_github_metadata_assert_unknown_gh_failure_is_environment_error(500 / connection reset / could not resolve host / x509 の 4 variant でresult == 8)と空 stderr ケース。
MAJOR 2: field surface
- 上記 allowlist により初回は
description固定。docs もdescription固定・exactly 4 引数に統一した。将来 field を拡張する場合は field ごとの assertion semantics 明文化が必要、という点も docs に反映余地として残している。
MAJOR 3: CI(e2e)
- e2e は
mcr.microsoft.com/playwrightimage の Docker pull がtoomanyrequests/unauthorizedで落ちる CI インフラのレート制限であり、本 PR(src/ render / e2e 不変の tooling 変更)に起因しない。typecheck/lint/test/build/python-test等のコード関連チェックは pass している。新しい push 後に e2e を再実行し、MCR 制限が解消していれば green になる見込み。required check として残る場合は green までマージしない判断とする。
検証
- full suite 250 passed(新規 hardening 8 件追加)。AC1-7 各
-kが collect ≥ 1 で pass、AC8(gh_api_is_blocked)regression なし、AC9 docs 同期、AC10(typecheck/lint/test、CI=true)pass。 - commit は Allowed Paths の 5 ファイルちょうど。
MAJOR 4(自己承認の弱さ)については、本 REQUEST_CHANGES が独立レビュー証跡になっており、上記修正後の再レビューをお願いします。
概要
Issue #942 を実装する。GitHub milestone metadata(特に
description)の forbidden phrase の有無を、rawgh apiを一般解禁することなく、baseline_vc_preflightが exit code で判定できる first-class assertiongithub_metadata_assertとして VC に記述できるようにする。raw
gh apiは一般解禁していないraw
gh apiは従来どおり allowlist でcommand_not_allowedとして block されたままである。本 PR はgh apiの一般 allowlist を一切緩めていない。github_metadata_assert経由でのみ、内部で固定 argv の read-only な GET 呼び出しを行う。許可された endpoint / method / flags の exact subset
許可される呼び出しは以下の subset のみに限定する。
contains/not_containsのみgh api --method GET repos/<owner>/<repo>/milestones/<number>、shell=False)repos/<owner>/<repo>/milestones/<number>のみ。絶対 URL・query string?・path traversal../・placeholder<...>・milestone 以外の resource は reject するdeny テスト一覧(dangerous flags / mutating method)
危険な flags と mutating method を block することをテストで担保する。
-f/-F/--field/--raw-field/--input/--header(-H)/--include(-i)/--paginate/--slurp/--cache/--template/--preview/graphqlを block--method POST/PATCH/PUT/DELETE、-X <method>、--method=...、大文字小文字混在 variant を blockclassify_static_command経由の両方で deny されることを検証する環境エラー分類(present/absent と別、false pass にしない)
gh 不在 / auth 失敗 / 404 / rate limit / timeout / invalid JSON は、assertion の present/absent(pass/fail)とは別の
github_metadata_assert_environment_errorカテゴリに分類し、decision: human_judgmentとする。環境エラーを exit 0(go)の false pass として扱わないことを end-to-end テストで担保する。execution wiring を追加した
前任の部分実装では
_check_github_metadata_assertion(exit code 変換の実体)が実行パスから一度も呼ばれない dead code であった。本 PR はmain()の dispatch を実装に接続する。classify_static_commandが allowed(static_result is None)を返し、かつgithub_metadata_assertコマンドである場合、run_commandによるリテラル実行(No such file or directoryになる)を回避し、shlex.splitした argv から_check_github_metadata_assertionを呼び、その exit code で分類する。fakeghを PATH に注入して classify→execute の経路を end-to-end で検証するテストを追加した。レビュー指摘への対応(false pass の穴を塞ぐ)
第三者レビュー(REQUEST_CHANGES)で指摘された false pass の穴を塞いだ。
fieldを allowlist(初回はdescriptionのみ)化し、typo や未知 field は classify 時に reject する。さらに API response に field が存在しない場合(schema drift)は absent 扱いにせず、exit 9の schema/environment error としてhuman_judgmentに分類する。not_containsが field 欠落で exit 0 になる経路を排除した。github_metadata_assertを exactly 4 引数(assertion_type field literal endpoint)に限定し、余分な positional や flags を全て reject する。flag surface を一切受け付けないため、dangerous flags・graphql・mutating method は arity 規則だけで漏れなく block される(大文字小文字 variant 含む)。docstring と docs の[flags...]/<field>一般化も解消した。gh失敗 exit 1 を assertion failure と誤分類):_check_github_metadata_assertionは API 成功 + JSON parse 成功 + assertion 不成立の場合のみexit 1を返す。未知のgh非0失敗(ネットワーク障害・5xx・403 secondary rate limit・DNS/TLS 失敗等)はexit 8の environment error にし、semantic な assertion failure と混同しない。クローズ対象
本 PR をマージすると Issue #942 はクローズされる。
Closes #942