Skip to content

fix(#606): guard gh api comment patch mutations - #652

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-606-gh-api-comment-body-patch-mutation
Jun 4, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-606-gh-api-comment-body-patch-mutation

Conversation

@squne121

@squne121 squne121 commented Jun 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

この PR は Issue #606 の契約に沿って、REST comment PATCH 経路だけを対象に guard の欠落を埋める変更です。

  • gh api --input の REST comment PATCH endpoint を issue comment / PR review comment まで分類対象に広げました。
  • hook が comment endpoint から既存 body を gh api ... --jq .body で取得し、delta check を fail-closed で行うようにしました。
  • comment PATCH 専用の hook smoke test / validator unit test を追加し、PATCH 限定分類、GET・DELETE・implicit/explicit POST pass、non-string body fail-closed、導入: guard-japanese-prose と issue contract authoring boundary の統合修正 #646 代表の authoring-boundary ケースを固定しました。

受け入れ条件の達成状況

  • AC1: BODY_MUTATION_ISSUE_COMMENT:<owner>:<repo>:<comment_id> を返す分類を追加しました。
  • AC2: BODY_MUTATION_PR_REVIEW_COMMENT:<owner>:<repo>:<comment_id> を返す分類を追加しました。
  • AC3: issue comment の old body を gh api repos/{owner}/{repo}/issues/comments/{comment_id} --jq .body で取得する分岐を追加しました。
  • AC4: PR review comment の old body を gh api repos/{owner}/{repo}/pulls/comments/{comment_id} --jq .body で取得する分岐を追加しました。
  • AC5: payload parse failure / endpoint parse failure / old body fetch failure / non-string body の fail-closed を comment PATCH 経路で固定しました。
  • AC6: GET / DELETE / body key absent / implicit POST / explicit POST / POST comment creation は pass のまま維持しました。
  • AC7: 英語 prose 差分は block し、ask に落とさない挙動を comment PATCH 経路で確認しました。
  • AC8: code fence / identifier / URL / enum 相当の差分に加え、英語見出しを含む authoring-boundary 代表ケースが pass することを comment PATCH 経路で確認しました。
  • AC9: fake gh の PATH prepend を使う hook smoke test を追加しました。
  • AC10: validator unit test で comment endpoint 分類と non-body / non-mutation / GET / DELETE を固定しました。

Checks

標準ゲートは worktree 上で順番実行し、Issue 契約で要求された型検査・lint・test・build をすべて通しています。

  • pnpm typecheck 実行済み
  • pnpm lint 実行済み
  • pnpm test 実行済み
  • pnpm build 実行済み

検証コマンド結果

  • rg -n "BODY_MUTATION_ISSUE_COMMENT" .claude/skills/create-issue/scripts/validate_japanese_content.py
  • rg -n "BODY_MUTATION_PR_REVIEW_COMMENT" .claude/skills/create-issue/scripts/validate_japanese_content.py
  • rg -n "issues/comments|comment_old_body_fetch_failed" .claude/hooks/guard-japanese-prose.sh
  • rg -n "pulls/comments|comment_old_body_fetch_failed" .claude/hooks/guard-japanese-prose.sh
  • uv run pytest .claude/hooks/tests/test_guard_api_comment_input.py -q -k "english_prose or structured_deny or ask"
  • uv run pytest .claude/hooks/tests/test_guard_api_comment_input.py -q -k "code_fence or identifier or url or enum"
  • uv run pytest .claude/hooks/tests/test_guard_api_comment_input.py -q
  • uv run pytest .claude/skills/create-issue/scripts/tests/test_validate_api_comment_mutation.py -q -k "non_mutation or no_body or get or delete"
  • uv run pytest .claude/skills/create-issue/scripts/tests/test_validate_api_comment_mutation.py -q
  • 追加回帰確認: uv run pytest .claude/hooks/tests/test_guard_api_input.py -q、uv run pytest .claude/skills/create-issue/scripts/tests/test_validate_japanese_content.py -q

Allowed Paths 遵守

  • 変更ファイルは .claude/hooks/guard-japanese-prose.sh、.claude/skills/create-issue/scripts/validate_japanese_content.py、.claude/hooks/tests/test_guard_api_comment_input.py、.claude/skills/create-issue/scripts/tests/test_validate_api_comment_mutation.py の 4 ファイルのみです。
  • .github/workflows/ci.yml、POST comment creation、GraphQL / -f body= / -F body= route matrix には触れていません。

Schema Change Applicability

この変更は外部 contract や生成物 schema を増減させず、hook 内部の経路分類と既存 body 取得分岐だけを拡張するものです。

  • decision: not_schema_change
  • reason: producer-consumer 境界をまたぐ schema 変更ではなく、hook 内部の mutation 分類文字列と comment PATCH 分岐の追加に留まるため。

Schema Consumer Inventory

schema 変更はありませんが、validator 必須セクションとして inventory を明示し、影響範囲が comment PATCH 関連の内部 consumer に閉じることを残します。

変更対象 schema: N/A

before/after 差分:

# before
N/A

# after
N/A

Consumer 列挙(rg コマンド例と結果):

rg -l "BODY_MUTATION_ISSUE_COMMENT|BODY_MUTATION_PR_REVIEW_COMMENT|comment_old_body_fetch_failed" .
.claude/hooks/guard-japanese-prose.sh
.claude/hooks/tests/test_guard_api_comment_input.py
.claude/skills/create-issue/scripts/tests/test_validate_api_comment_mutation.py
.claude/skills/create-issue/scripts/validate_japanese_content.py

Consumer 更新状況:

Consumer ファイル 更新有無 備考
N/A 不要(schema 変更なし) not_schema_change

Compatibility Decision

互換性判断としても、既存の issue / PR body mutation 判定を壊さずに comment PATCH 経路だけを追加するため、移行作業は不要です。

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: schema 自体は変更していません。

Safety Claim Matrix

下表は、この PR が何を制御し、何を明示的に対象外へ残したかを日本語で固定するための確認表です。

Claim Implemented? Not controlled Evidence Follow-up
REST comment PATCH body mutation は issue comment / PR review comment まで guard 対象になった yes uv run pytest .claude/hooks/tests/test_guard_api_comment_input.py -q N/A
old body fetch failure / payload parse failure / endpoint parse failure / non-string body は fail-closed で止まる yes uv run pytest .claude/hooks/tests/test_guard_api_comment_input.py -q N/A
PATCH 以外の comment route と broader route matrix はこの PR では guard 対象にしない partial POST /issues/{issue_number}/comments、POST /pulls/{pull_number}/comments、reply endpoint、broader public mutation route matrix は未対応 Issue #606 の Out of Scope と uv run pytest .claude/skills/create-issue/scripts/tests/test_validate_api_comment_mutation.py -q #646

Notes

補足事項として、parent/related issue と今回の対象範囲をここにまとめます。#646 で問題化している authoring-boundary については、Machine-Readable Contract / Acceptance Criteria 見出しを含む representative case を今回の hook smoke test に追加しました。

Extend gh api --input mutation classification to issue comment and PR review comment PATCH endpoints, fetch old comment bodies via gh api for delta checking, and add comment-specific regression tests.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions

github-actions Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #652 closed).

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

Mergeability

  • mergeable=MERGEABLE, merge_state_status=CLEAN

Evidence Check

  • AC coverage: Issue 606 の AC1-AC10 は PR 本文の達成状況と diff で対応しています。
  • Allowed Paths: gh pr diff --name-only の結果は issue contract の 4 ファイルのみでした。
  • CI Verification: current head e1e306b で PR Body Japanese Check、actionlint、build、deploy-pr、lint、python-test、test、e2e、typecheck、validate-generated-artifact が success です。TEST_VERDICT_MACHINE コメントは無いため、current head に紐づく CI check run とローカル再実行証跡で判定しました。
  • Verification rerun: updated head 同期後に guard_api_comment_input 9 passed、validate_api_comment_mutation 6 passed、pnpm typecheck/lint/test/build pass を確認しました。

Blockers

  • なし

Non-blockers(任意改善)

  • なし

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: e1e306bc00eaee5185760e99dd4971f1563c5101
merge_ready: true
mergeability:
  mergeable: MERGEABLE
  merge_state_status: CLEAN
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []

@squne121

squne121 commented Jun 4, 2026

Copy link
Copy Markdown
Owner Author

静的レビューです。ローカルでCI再実行はしていません。公開GitHub上のPR/Issue/差分とGitHub公式ドキュメントに基づきます。

結論: REQUEST_CHANGES

PR #652 の方向性は妥当です。#606 が要求している「gh api --input による Issue comment / PR review comment の REST PATCH edit を、既存bodyとの差分で日本語ガードする」目的には沿っています。PR本文も、Issue comment / PR review comment の PATCH を対象にし、GET/DELETE/non-body/POST create は通すと主張しています。([GitHub]1)

ただし、現状は 契約と実装の境界がまだ曖昧 です。このまま APPROVE は危険です。

ブロッカー 1: 「PATCHのみ」の契約に対し、実装は method 非依存に近い

#606 のAcceptance Criteriaは、Issue comment と PR review comment の --method PATCH + body をdelta検査対象にし、POST/GET/body absent は通す、という境界を置いています。#600でも comment / PR review / GraphQL comment は意図的にde-scopeされていたため、今回のPRはその穴を REST PATCH editに限定して埋める ものです。([GitHub]2)

しかし実装側では、validate_japanese_content.py が endpoint と body の有無で BODY_MUTATION_ISSUE_COMMENT / BODY_MUTATION_PR_REVIEW_COMMENT を返す構造で、分類自体は PATCH に限定されていません。さらに method 抽出は --input があり明示methodがない場合に POST と扱うため、method policy と route classification が分離していて、契約上の「PATCH editのみ guarded」がコードで強く表現されていません。([GitHub]3)

GitHub CLI公式仕様でも、gh api は --input でrequest bodyをファイルから読み、--method でHTTP methodを上書きできます。つまり、このPRでは「method + route + payload」を一体で分類しないと、誤検知・過剰ブロック・仕様逸脱の温床になります。([GitHub CLI]4)

要求修正:

  • BODY_MUTATION_ISSUE_COMMENT / BODY_MUTATION_PR_REVIEW_COMMENT は method == PATCH の場合だけ返す。
  • POST /repos/{owner}/{repo}/issues/{issue_number}/comments などの作成系は明示的に NOT_BODY_MUTATION。
  • POST や method未指定で edit endpoint に --input した場合は、仕様として「pass」なのか「malformedとしてfail-closed」なのかを 実装: gh api による comment body PATCH mutation の guard 対象追加 #606/PR本文/Safety Matrix に明記する。
  • その挙動をhook-level smoke testで固定する。

ブロッカー 2: AC3を満たすテストが弱い

追加テストは、Issue comment PATCH と PR review comment PATCH の英語proseブロック、および code fence / identifier / URL / enum の許容を確認しています。これは有効です。([GitHub]5)

一方で、AC3の「POST / GET / body absent pass」をhook全体で十分に証明していません。unit test側には POST create endpoint や GET/DELETE method抽出のテストがありますが、実際のPreToolUse hookとして「POST createが通る」「GET/DELETEが通る」「body absentが通る」を保証するテストではありません。([GitHub]6)

要求修正:

最低限、以下をhook-levelで追加してください。

PASS: gh api repos/O/R/issues/123/comments --method POST --input payload.json
PASS: gh api repos/O/R/issues/comments/456 --method GET
PASS: gh api repos/O/R/pulls/comments/789 --method DELETE
PASS or FAIL-CLOSED明記: gh api repos/O/R/issues/comments/456 --input payload.json
PASS or FAIL-CLOSED明記: gh api repos/O/R/pulls/comments/789 --method POST --input payload.json
PASS: payloadにbody keyなし
FAIL-CLOSED: payload invalid JSON
FAIL-CLOSED or NOT_BODY_MUTATION明記: bodyがstring以外

特に --input method未指定ケースは、GitHub CLIのdefault method挙動と絡むため、テストで固定しないと将来また境界が崩れます。([GitHub CLI]4)

ブロッカー 3: #646 の「AI作業阻害」リスクに対する回帰テストが不足

関連Issue #646 は、guard強化によってIssue契約文・テンプレート見出し・machine-readable contract・tmp drafts などのAI作業コンテキストが誤って止まるリスクを明示しています。#646の目的は、公開mutationはguardしつつ、契約作成や内部ドラフトのような authoring context を壊さないことです。([GitHub]7)

PR #652 は comment patch をguard対象に広げるため、このリスクを直接増やします。現状の許容テストは code fence / identifier / URL / enum が中心で、#646で問題化している「Machine-Readable Contract」「Acceptance Criteria」「Desired Destination」等を含む実運用コメントが誤ブロックされないことを示していません。([GitHub]1)

要求修正:

ブロッカー 4: body型エラーの扱いが仕様化されていない

GitHubのPR review comment update endpointは PATCH /repos/{owner}/{repo}/pulls/comments/{comment_id} で、body文字列が必須です。Issue commentも同様にcomment update APIとして扱われます。([GitHub Docs]8)

現在の分類はpayloadに body keyがあれば mutation扱いし、その後hook側でbody抽出に失敗するとfail-closedします。fail-closed自体は安全寄りですが、body: null / body: 123 / body: [] / body: {} のようなケースが「非body mutation」なのか「不正body mutation」なのか、契約とテストで固定されていません。([GitHub]9)

要求修正:

  • body keyあり・非stringは INVALID_BODY_TYPE のような明示分類にする。
  • hookの出力理由も api_input_body_extract_failed ではなく、review可能なpolicy reasonに寄せる。
  • non-string bodyのテストを追加する。

良い点

  • #600でde-scopeされていた Issue comment / PR review comment patch に踏み込んだ点は正しいです。#606の穴埋めとして妥当な方向です。([GitHub]2)
  • 既存bodyを gh api ... --jq .body で取得し、新bodyとの差分だけを検査する設計は、issue/PR body guardの既存設計と整合しています。([GitHub]9)
  • 英語proseをブロックしつつ、code fence / identifier / URL / enum を通すテストを追加している点は、過剰ブロック低減として価値があります。([GitHub]5)

推奨する実装方針

shell側に判定を散らすより、validatorに分類を寄せたほうが安全です。

{
  "kind": "REST_ISSUE_COMMENT_PATCH",
  "method": "PATCH",
  "owner": "O",
  "repo": "R",
  "comment_id": "456",
  "body_present": true,
  "body_type": "string",
  "fetch_path": "repos/O/R/issues/comments/456"
}

このように method + route + payload type + fetch_path を単一JSONで返し、shellは kind だけで分岐してください。これで、POST create、GET、DELETE、body absent、body non-string、GraphQL、未知routeをそれぞれ明示分類できます。

GitHubレビューコメント案

REQUEST_CHANGES

目的は妥当ですが、このPRはまだ #606 の契約境界をコードとテストで固定できていません。

#606 は Issue comment / PR review comment の REST PATCH edit を guarded にし、POST/GET/body absent を pass とする契約です。一方、現在の実装は endpoint + body の分類が method と十分に結合しておらず、`--input` method未指定や PATCH以外の edit endpoint がどう扱われるかが仕様化されていません。

修正要求:

1. `BODY_MUTATION_ISSUE_COMMENT` / `BODY_MUTATION_PR_REVIEW_COMMENT` は `method == PATCH` の場合だけ返す。
2. POST create endpoint、GET、DELETE、body absentをhook-level smoke testでpass確認する。
3. `--input` method未指定 + comment edit endpoint の挙動を pass / fail-closed のどちらかに仕様化し、テストで固定する。
4. `body` keyあり・非stringの扱いを明示分類し、テストを追加する。
5. #646 の authoring-boundary regression 代表ケース、または未検証である旨をSafety Matrixに明記する。

現状のままでは、REST PATCH comment editを守るPRではなく、comment endpoint周辺のmethod境界が曖昧なguard拡張になっています。merge前に契約・分類・hook-levelテストを揃えるべきです。

@squne121
squne121 marked this pull request as ready for review June 4, 2026 11:28
@squne121
squne121 merged commit 57cbdae into main Jun 4, 2026
15 checks passed
@squne121
squne121 deleted the worktree-issue-606-gh-api-comment-body-patch-mutation branch June 4, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant