Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "PR #585 レビューで提起された optional follow-up — cleanup-pr 時に残存する preview URL コメントの削除または無効化"
change_kind: workflowParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: gh-pages ブランチへのデプロイで main 共有 URL と PR preview URL の両方を手動プレイテストに提供する(元 Issue 実装: gh-pages branch デプロイで main 共有 URL と PR preview URL の両方を手動プレイテストに提供する #582 の目標)
- Desired Destination: PR クローズ時の cleanup-pr ジョブが preview URL コメントも合わせて「Preview removed」状態に更新する
Current Validated Scope
.github/workflows/deploy-pages.ymlのcleanup-prジョブにactions/github-scriptステップを追加し、クローズ済み PR の preview URL コメントを「Preview removed」メッセージに更新する
Remaining Parent Gaps
なし
Outcome
.github/workflows/deploy-pages.yml の cleanup-pr ジョブが更新され、PR close 時に gh-pages 上の pr-<N>/ を削除した後、deploy-pr が投稿した preview URL bot コメントを削除せず「Preview removed」状態へ更新する。
対象コメントは <!-- loop-protocol-pr-preview --> marker を含む GitHub Actions bot コメントに限定し、人間コメントや marker のないコメントは変更しない。
pnpm typecheck / pnpm lint / pnpm test / pnpm build が全て PASS している。
In Scope
.github/workflows/deploy-pages.ymlのcleanup-prジョブにactions/github-scriptstep を追加cleanup-prジョブへの same-repository PR guard 追加(fork PR / Dependabot PR での close event をスキップ)- preview comment の更新ロジック
github.paginate(github.rest.issues.listComments, { per_page: 100 })を使うuser.login === 'github-actions[bot]'かつ<!-- loop-protocol-pr-preview -->marker を含むコメントのみ対象- 対象コメントがない場合は no-op(新規コメントを作成しない)
- コメント削除は禁止。既存コメントを
Preview removedに更新する
cleanup-prジョブへのpull-requests: write追加(contents: writeを維持したまま)
Out of Scope
deploy-prの preview comment 作成/upsert ロジック変更- main デプロイ(
deploy-mainジョブ)への変更 - SHA pinning / actionlint CI 導入(chore(ci): GitHub Actions workflow の SHA pin / actionlint 統合 #280 で追跡)
- docs 更新
pull_request_targetへの変更- PAT / GitHub App token の導入
Acceptance Criteria
- AC1:
cleanup-prjob にactions/github-scriptstep が存在する - AC2:
cleanup-prjob の if 条件にgithub.event.pull_request.head.repo.full_name == github.repositoryが含まれる(same-repository guard) - AC3:
cleanup-prjob のactions/github-scriptステップはgithub.paginate(github.rest.issues.listComments, ...)を使用する - AC4:
cleanup-prjob のactions/github-scriptステップはuser.login === 'github-actions[bot]'かつ<!-- loop-protocol-pr-preview -->marker を含むコメントのみを更新対象とする - AC5: 対象コメントがある場合、削除ではなく
Preview removed本文へ更新される(updateCommentを使用しdeleteCommentは使用しない) - AC6: 対象コメントがない場合、新規コメントを作成しない(no-op)
- AC7:
cleanup-prジョブの permissions にcontents: writeとpull-requests: writeの両方が設定されている - AC8:
pnpm typecheck/pnpm lint/pnpm test/pnpm buildが全て PASS - AC9:
cleanup-prのactions/github-scriptステップ内にcreateCommentの呼び出しがない
Verification Commands
# AC1
# baseline: FAIL — "Preview removed" テキストは cleanup-pr 実装前は存在しない
$ rg -n "Preview removed" .github/workflows/deploy-pages.yml# AC2
# baseline: FAIL — cleanup-pr の if 条件は現在 'closed' で終わっており && がない
$ rg -n "action == 'closed' &&" .github/workflows/deploy-pages.yml# AC3
# baseline: FAIL — cleanup-pr スクリプトに per_page: 100 は現在存在しない(deploy-pr は未指定)
$ rg -n "per_page: 100" .github/workflows/deploy-pages.yml# AC4
# baseline: FAIL — "Preview removed" テキストは cleanup-pr 実装前は存在しない
$ rg -n "Preview removed" .github/workflows/deploy-pages.yml# AC5
# baseline: FAIL — "Preview removed" テキストは cleanup-pr の updateComment 実装前は存在しない
$ rg -n "Preview removed" .github/workflows/deploy-pages.yml# AC6
# preflight-scope: pr_review_only
# reviewer: cleanup-pr ブロック内に createComment の呼び出しがないことを diff で目視確認する# AC7
# preflight-scope: pr_review_only
# reviewer: PR の diff で cleanup-pr ジョブの permissions ブロックに
# contents: write と pull-requests: write の両方があることを確認する# AC8
$ pnpm typecheck# AC8
$ pnpm lint# AC8
$ pnpm test# AC8
$ pnpm build# AC9
# preflight-scope: pr_review_only
# reviewer: cleanup-pr ブロック内に createComment の呼び出しがないことを diff で目視確認するAllowed Paths
.github/workflows/deploy-pages.yml
Protected Path Exception
.github/workflows/deploy-pages.ymlの変更は本 Issue の明示スコープとして人間承認済み。- 既存 workflow のうち
deploy-pages.yml以外は変更不可。 - 実装 PR には Safety Claim Matrix を必須とする。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- GitHub Actions(
actions/github-scriptステップ / octokit.rest.issues API / github.paginate)
Scope Delta(任意)
N/A
Delivery Rule
1 Issue = 1 PR- Draft PR 既定
- worktree:
git worktree add ../loop-protocol-issue-<N> -b issue-<N>
Background
PR #585 で追加した .github/workflows/deploy-pages.yml は、PR の opened/synchronize/reopened 時に pr-<N>/ へデプロイし当該 PR に preview URL をコメントする。PR closed 時の cleanup-pr ジョブは gh-pages の pr-<N>/ ディレクトリ削除のみを行うが、投稿済みの preview URL コメントは残存する。
deploy-pr ジョブは既に <!-- loop-protocol-pr-preview --> marker を持つ bot コメントの upsert を実装済みであるため、cleanup-pr では同 marker を使って対象コメントを特定し「Preview removed」状態に更新する。コメントを削除すると手動プレイテスト導線の証跡が失われるため、更新のみを行う。
fork PR / Dependabot PR では deploy-pr が same-repo guard でスキップされるため preview comment は存在しない。同様に cleanup-pr も same-repo guard でスキップして権限エラーを回避する。
Runtime Verification Applicability
- decision: deferred
- reason: GitHub Actions のライブ動作を検証するには実際の PR クローズイベントが必要なため、動作確認は deploy 後の手動確認に延期する。
- deferred_destination: M1 手動プレイテストフェーズ(実際の PR クローズイベント発生時)
- deferred_verification_condition: cleanup-pr ジョブが実行され、対象 PR の preview URL コメントが「Preview removed」に更新されていること
Source
PR #585 のレビューで提起された follow-up として自動起票。
dedupe_key: follow-up:squne121/loop-protocol:pr/585:3
source: PR #585 review (pr-review-judge)
Activity
squne121 commentedon Jun 2, 2026
判定: BLOCK / Issue 契約を修正してから実装すべき
Issue #586 の目的自体は妥当です。PR #585 のレビューでも「cleanup-pr 実行後に preview URL コメントが残存する可能性」は任意改善として明示され、follow-up issue request も生成されています。([GitHub]1)
ただし、現 Issue #586 のまま実装させると、誤削除・権限退行・検証不能・fork PR での失敗を誘発する可能性が高いです。
主要ブロッカー
1. 「削除または更新」が広すぎる。削除は証跡を失う
Issue #586 は「preview URL コメントを削除または
Preview removedに更新」としており、AC2 も削除・更新のどちらでも PASS する契約です。([GitHub]2)しかし PR #585 のコメントは手動プレイテスト導線の証跡でもあります。実装でコメントを削除すると「どの URL が一時的に存在し、いつ無効化されたか」の監査情報が消えます。
推奨: 削除ではなく 既存 bot コメントの本文を更新に固定するべきです。コメント本文には次を残すべきです。
GitHub REST API は issue / PR コメントの update と delete の両方を提供しますが、PR コメントは issue comment として扱われます。([GitHub Docs]3) この用途では delete より update が安全です。
2. 対象コメントの特定条件が曖昧で、人間コメントを巻き込む余地がある
Issue #586 は「preview URL を含むコメント(
deploy-prが投稿したもの)を特定」と書いています。([GitHub]2)これは危険です。人間がレビューコメントで preview URL を引用していた場合、実装次第では人間コメントを更新・削除できます。
PR #585 の実装は既に
<!-- loop-protocol-pr-preview -->marker を持ち、c.user.type === 'Bot'かつ marker を含むコメントを upsert 対象にしています。([GitHub]4)Issue #586 はこの既存仕様を契約に取り込むべきです。
修正すべき条件:
加えて、該当コメントがない場合は 新規コメントを作らず no-op とするべきです。close 後に「Preview removed」だけを新規投稿すると、ノイズが増えます。
3.
listCommentsのページネーション未指定は 31件目以降を取り逃がすIssue #586 の Verification Commands は
rg -n "listComments"だけで AC2 を満たす設計です。([GitHub]2)これは静的文字列確認でしかなく、正しいコメントを見つけられる保証がありません。
GitHub REST の issue comments list はデフォルト
per_page: 30、最大100でページネーション対象です。([GitHub Docs]3)PR に bot やレビュー支援のコメントが多い場合、preview comment が 31 件目以降に落ち、cleanup が成功してもコメント更新に失敗します。
実装契約に入れるべき要件:
actions/github-scriptは pre-authenticated Octokit client と pagination plugins を提供します。([GitHub]5)4.
cleanup-prの権限契約が壊れやすいIssue #586 の AC3 は「
cleanup-prジョブの権限ブロックにpull-requests: writeが設定されている」と書いています。([GitHub]2)しかし PR #585 の既存 workflow は top-level permissions として
contents: write/pull-requests: writeを付けています。([GitHub]4)ここで実装者が
cleanup-prjob に job-level permissions を追加し、pull-requests: writeだけを指定すると、GitHub Actions の仕様上、未指定 permission はnoneになります。([GitHub Docs]6)その結果、既存の
git pushに必要なcontents: writeが消え、gh-pages cleanup が壊れます。AC3 は次のどちらかに修正すべきです。
または
「コメント操作権限」だけを見て
pull-requests: writeに寄せるのは不十分です。cleanup-pr は gh-pages branch への push も行います。5. fork PR / Dependabot PR での close event を考慮していない
PR #585 の
deploy-prには same-repository PR guard が入っています。([GitHub]4)一方、
cleanup-prはgithub.event.action == 'closed'だけで実行されます。([GitHub]4)GitHub Actions では fork 由来の
pull_requestworkflow のGITHUB_TOKENは通常 write 権限を付与できず、write は read-only に落とされます。Dependabot PR も fork 相当として read-only token で動きます。([GitHub Docs]6)そもそも fork PR では preview を作らない設計なので、cleanup-pr も同じ条件で skip すべきです。
修正案:
これを AC に入れないと、fork PR close 時に不要な cleanup failure が出ます。
6.
.github/workflows/は保護パスなのに、Protected Path Exception がないIssue #9 では
.github/workflows/が「CI 定義(AI による無断改変禁止)」として保護対象に入っています。([GitHub]7)Issue #582 は protected path exception を明示していましたが、Issue #586 には同等の明示がありません。([GitHub]8)
Issue #586 は
.github/workflows/deploy-pages.ymlの変更だけを許可しているため、protected path 例外を明記しないと、実装エージェント・レビューエージェント・hook 方針の間で契約衝突します。追加すべき文言:
修正版 Issue 契約案
Outcome 修正案
In Scope 修正案
Out of Scope 修正案
pull_request_targetは権限面では強いですが、fork PR の untrusted code と混ぜると危険です。今回の改善は既存pull_requestworkflow の範囲で完結させるべきです。Acceptance Criteria 修正案
追加すべき Verification Commands
推奨コメント本文
この修正を入れれば、Issue #586 は「任意 UX 改善」から「安全に実装可能な workflow 改修」に格上げできます。
squne121 commentedon Jun 2, 2026
コントラクトレビュー結果: BLOCKED (2026-06-03T00:00:00Z)
生成者: issue-contract-review スキル
不足項目の概要
AC7 の Verification Commands に 2 つのブロッカーがあります。これを修正してください。
ブロッカー 1: コマンドとして誤認識される非コマンド行
"Preview removed" VC 実装後に diff で確認という行は行頭に#がないため、preflight スクリプトがコマンドとして解釈し command_not_allowed でブロックされます。修正方法: 行頭に#を追加してコメント行にしてください。ブロッカー 2: baseline で pass してしまう rg コマンド
rg -n "contents: write" .github/workflows/deploy-pages.ymlというコマンドは、contents: writeがすでにcleanup-prジョブの L164 に存在するため、実装前でも exit 0 になります。これは baseline fail を証明できない VC です。pull-requests: writeもdeploy-prの L78 に既存なので、単純なrgでは cleanup-pr 専用の追加を確認できません。修正方法: AC7 の VC 全体を
# preflight-scope: pr_review_only形式に変更し、PR diff 確認に切り替えてください。VC Preflight の全結果
AC1〜AC5 および AC8 はすべて go です。AC7 の 2 件のみブロックされています。
その他のチェック: テンプレート準拠は pass、ブロッカーは存在しない、product_spec_check は not_applicable、worktree の衝突もなし。
推奨アクション
Issue 本文の
## Verification Commands内 AC7 ブロックを上記の修正案に変更したうえで、issue-contract-reviewを再実行してください。squne121 commentedon Jun 2, 2026
コントラクトスナップショット (2026-06-03T00:00:00Z)
実装計画の概要
cleanup-prジョブが PR close 時に<!-- loop-protocol-pr-preview -->marker を含む bot コメントを「Preview removed」に更新する.github/workflows/deploy-pages.ymlのみ.claude/worktrees/issue-586-cleanup-pr-preview-urlworktree-issue-586-cleanup-pr-preview-urlsqune121 commentedon Jun 2, 2026
implement-issue: 実装完了(2026-06-03T06:38:00Z)
.claude/worktrees/issue-586-cleanup-pr-preview-urlworktree-issue-586-cleanup-pr-preview-urlsqune121 commentedon Jun 2, 2026
impl-review-loop 完了報告 (2026-06-03T00:00:00Z)
fix(#586): add dependabot[bot] guard to cleanup-pr job
feat(#586): cleanup-pr 実行後に preview URL コメントを「Preview removed」へ更新 (#593)
squne121 commentedon Jun 2, 2026
マージ後クリーンアップ完了 (2026-06-03T00:00:00Z)