Skip to content

feat(vrt): required CI の snapshot write を拒否する - #1930

Merged
squne121 merged 7 commits into
mainfrom
worktree-issue-1388-vrt-snapshot-policy
Aug 1, 2026
Merged

squne121 merged 7 commits into
mainfrom
worktree-issue-1388-vrt-snapshot-policy

Conversation

@squne121

@squne121 squne121 commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • required CI の Playwright snapshot update を none に固定し、明示的な local/manual candidate producer を追加しました。
  • workflow、local composite action、到達可能な package script の既知 snapshot-write 経路を fail-closed で検査します。
  • candidate producer、canonicalization authority、reviewed PR による persistence の責務境界を VRT 台帳に明記しました。

受け入れ条件の達成状況

  • AC1: test:vrt:update:e2e を明示的な Playwright update mode の local/manual candidate generation 用入口として追加し、validator が required CI からの直接・間接到達を拒否します。
  • AC2: playwright.config.ts は CI で updateSnapshots: 'none' を解決し、flag がない missing snapshot write も防止します。
  • AC3: Playwright/Vitest の write-capable mode と update package script 呼出しを validator が拒否する pytest を実行済みです。
  • AC4: workflow、参照される local composite action、bounded package script の到達経路を構造解析する pytest を実行済みです。
  • AC5: safe mode、通常 command、python -u、YAML comment を許可する pytest を実行済みです。
  • AC6: unresolved interpolation、malformed YAML、validator CI wiring 欠落を fail-closed にする pytest を実行済みです。
  • AC7: registry は candidate producer、canonicalization authority、persistence、repository-side enforcement limitation と既存 review checklist を保持します。
  • AC8: baseline PNG は変更せず、focused policy tests、policy validator、typecheck、lint、test、build は current head で PASS です。

検証コマンド結果

  • rg -n "test:vrt:update:e2e" package.json — AC1 の明示入口を確認。
  • rg -n "updateSnapshots.*none" playwright.config.ts — AC2 の CI read-only 設定を確認。
  • uv run --locked pytest scripts/tests/test_check_vrt_snapshot_policy.py::test_rejects_write_capable_playwright_and_vitest_modes -q — AC3 PASS。
  • uv run --locked pytest scripts/tests/test_check_vrt_snapshot_policy.py::test_rejects_indirect_package_script_and_composite_action_paths -q — AC4 PASS。
  • uv run --locked pytest scripts/tests/test_check_vrt_snapshot_policy.py::test_allows_safe_modes_python_u_and_comment_text -q — AC5 PASS。
  • uv run --locked pytest scripts/tests/test_check_vrt_snapshot_policy.py::test_fails_closed_for_interpolation_malformed_yaml_and_missing_wiring -q — AC6 PASS。
  • rg -n "baseline 変更 PR のレビュー checklist" docs/dev/visual-baseline-registry.md — AC7 PASS。
  • uv run --locked pytest scripts/tests/test_check_vrt_snapshot_policy.py -q — 4 passed。
  • uv run --locked python scripts/check-vrt-snapshot-policy.py — PASS。
  • pnpm typecheck、pnpm lint、pnpm test(105 files、1794 tests)、pnpm build — independent test-runner と current-head CI で PASS。
  • pnpm lint:docs、uv run --locked ruff check scripts/check-vrt-snapshot-policy.py scripts/tests/test_check_vrt_snapshot_policy.py、python-test plan lane-union guard — PASS。
  • 各コマンドは対応する受け入れ条件を直接検証し、失敗時に成功扱いへ変換する経路はありません。

Allowed Paths 遵守

main...5ee2ce07bf7abb818e5168531555641ece2d52da の changed paths は、Issue #1388 の Allowed Paths に列挙された次の7パスだけです。

  • package.json
  • playwright.config.ts
  • scripts/check-vrt-snapshot-policy.py
  • scripts/tests/test_check_vrt_snapshot_policy.py
  • .github/ci/python-test-plan.json
  • .github/workflows/ci.yml
  • docs/dev/visual-baseline-registry.md
  • 上記以外の変更はなく、許可範囲外のパスは commit に含まれていません。

独立 Allowed Paths gate は ok であり、baseline PNG、#1389 の component VRT、repository settings は変更していません。

Checks

  • focused policy pytest(4 passed)
  • policy validator と python-test lane verifier
  • typecheck、lint、test、build の current-head evidence
  • すべての確認結果は対象 head に結び付いており、既知の失敗は残っていません。

Schema Change Applicability

  • decision: not_schema_change
  • reason: JSON Schema、外部 API、永続データ形式は変更せず、既存 CI 実行経路への静的 policy とテスト対象を追加するため。

Schema Consumer Inventory

Consumer ファイル 更新有無 備考
.github/workflows/ci.yml yes required CI validator を常設配線
.github/ci/python-test-plan.json yes validator unit test を python-test plan に登録
scripts/check-vrt-snapshot-policy.py yes workflow、local composite action、package script の bounded validator

互換性判断 (Compatibility Decision)

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: 既存 schema のキー、型、意味論は変更していません。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
required CI の既知 Playwright/Vitest write mode と E2E update script 到達経路を拒否する yes arbitrary shell interpreter の完全解析 focused pytest、policy validator、current-head CI #1380
candidate artifact は canonical baseline ではなく、reviewed PR の commit/merge だけが persistence となる partial repository rules、CODEOWNERS、required review の強制 VRT registry の境界記述 #1380

CI テスト性能判断 (CI Test Performance Decision)

CI_TEST_PERFORMANCE_DECISION_V1:
  schema: CI_TEST_PERFORMANCE_DECISION_V1
  issue_number: 1388
  pr_number: 1930
  decision_scope: ci_change
  changed_paths:
    - package.json
    - playwright.config.ts
    - scripts/check-vrt-snapshot-policy.py
    - scripts/tests/test_check_vrt_snapshot_policy.py
    - .github/ci/python-test-plan.json
    - .github/workflows/ci.yml
    - docs/dev/visual-baseline-registry.md
  lane_classification:
    fast_static:
      applicable: true
      evidence: ["typecheck と lint が current head で PASS"]
      required_commands: ["pnpm typecheck", "pnpm lint"]
    python_unit:
      applicable: true
      evidence: ["focused policy pytest: 4 passed"]
      required_commands: ["uv run --locked pytest scripts/tests/test_check_vrt_snapshot_policy.py -q"]
    contract_artifact:
      applicable: true
      evidence: ["policy validator と CI wiring が PASS"]
      required_commands: ["uv run --locked python scripts/check-vrt-snapshot-policy.py"]
    integration:
      applicable: true
      evidence: ["Playwright required-CI config に対する build/test が PASS"]
      required_commands: ["pnpm test", "pnpm build"]
  baseline_inputs:
    ci_runtime_baseline_v1_available: false
    run_count: 0
    p50_p95_ready: false
  artifact_consistency:
    ci_test_selection_v1_checked: true
    missing_pytest_args: []
  risk_flags:
    - "validator は既知の bounded execution path のみを解析し、arbitrary shell interpreter は対象外"
  reviewer_gate:
    approve_allowed: false
    required_evidence: [CI_CHECK_RUN_SCOPED]
  follow_up_required: []

Notes

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1930/

The preview will be removed when this PR is closed.

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。現状ではマージ非推奨です。

PRはDraftのままopenで、取得できた会話コメントはpreview botのみです。PR本文上の検証とGitHub Actionsはgreenですが、新設validatorのテストが実装と同じ盲点を共有しており、「required CIをfail-closedでsnapshot read-onlyにする」という中心的な保証が成立していません。

ブロッカー

P0-1. 公式に存在するwrite-capable CLIが複数素通りする

実装はPlaywrightについて長形式の--update-snapshotsしか検査しておらず、playwright test -uを検出しません。Vitestもvitest runまたはvitest watchに限定しているため、次の正規コマンドが素通りします。

playwright test -u
vitest -u
vitest --update
vitest --update=all
vitest --update=new

Playwright公式CLIでは-uが--update-snapshotsの短縮形です。Vitest公式CLIも、サブコマンドなしのvitest -uと--updateを正式にサポートしています。([Playwright]1)

現行コードのrunner認識と正規表現、およびテストケースは、それぞれ長形式のPlaywrightとvitest run --updateしかカバーしていません。これはIssue #1388のAC3を直接満たしていません。

必須修正: Playwrightの-u、Vitestのサブコマンドなし・run・watch等を認識し、公式の全modeをテーブル駆動テストにしてください。


P0-2. package scriptの到達解析がshell実行と等価ではない

_referenced_pnpm_scripts()は空白と一部記号を分割する独自正規表現であり、shellのquote・line continuation・動的値を解釈しません。少なくとも次が回避経路になります。

pnpm run "test:vrt:update:e2e"

pnpm run \
  test:vrt:update:e2e

pnpm run ${{ matrix.script }}

1つ目はGitHub Actions上では通常どおりupdate scriptを実行しますが、抽出されたscript名に引用符が残るためvalidatorの許可文字列に一致しません。2つ目は候補script名として\を取得します。3つ目はliteralなPlaywright・Vitest・update script名を含まないため、interpolation検査自体が起動しません。

local composite actionにも同じ問題があります。

# action.yml
inputs:
  script:
    required: true
runs:
  using: composite
  steps:
    - shell: bash
      run: pnpm run ${{ inputs.script }}
# ci.yml
- uses: ./.github/actions/vrt
  with:
    script: test:vrt:update:e2e

GitHub Actionsはcomposite inputとreusable workflowを正式にサポートしていますが、現在の実装はcallerのwithをaction側へ伝播せず、reusable workflowのjobs.<job>.usesも解析しません。([GitHub Docs]2)

必須修正: 任意shell parserを作る必要はありませんが、対応対象を明示したbounded parserに置き換え、quoteとline continuationを正規化してください。command positionやscript名に未解決expressionが現れた場合は無条件にfail-closedとし、composite inputは値を伝播するか「動的入力は非対応」として拒否すべきです。


P0-3. 「validator wiring欠落をfail-closed」は自己参照になっている

現在のwiring検査は、ci.ymlのraw textに次の文字列が含まれるかを見るだけです。

if WIRING_COMMAND not in workflow_text:
    errors.append(...)

したがって、実行stepを削除してコメントだけ残しても検査上はwiringありになります。

# uv run --locked python scripts/check-vrt-snapshot-policy.py

さらに本質的には、validatorを呼ぶstep自体が削除された場合、そのvalidatorはそもそも実行されません。現在のpytestは一時fixtureに対して「wiringがない場合にエラーを返す関数」をテストするだけで、実リポジトリのcheck_policy(REPO_ROOT)は実行していません。

このためAC6の「validator CI wiring欠落をfail-closed」は未達です。

必須修正:

def test_current_repository_policy_passes():
    assert check_policy(REPO_ROOT).errors == []

のような独立したrepository integration testを既存python-test laneから実行してください。そのうえで、wiringはYAML AST上の実run stepとして検証し、コメント、echo、env値、if: falseのstepをwiring扱いしないことが必要です。


P1-1. Playwright configを「実効値」ではなく文字列で確認している

_validate_ci_config()は次の文字列パターンがどこかにあればpassします。

updateSnapshots: process.env.CI ? 'none' :

そのため、次のようなconfigでもvalidatorはpassします。

// updateSnapshots: process.env.CI ? 'none' :
export default defineConfig({
  updateSnapshots: 'all',
})

また、後続spreadや別configによるoverrideも評価できません。

Playwrightの既定値はmissingであり、none以外ではsnapshotを書き得ます。Playwright自身も、resolved configurationを確認する場合はFullConfigを使用するよう案内しています。(Playwright)

修正案: CI=trueでPlaywright configを実際にloadし、reporter等からFullConfig.updateSnapshots === 'none'を検証してください。少なくともコメント・複数定義・unsafe overrideの否定テストが必要です。


P1-2. 新しいbaseline candidate生成scriptがclean checkoutで自己完結しない

追加されたscriptはbuildを実行せず、既存のdistをPlaywrightのpreview serverで使用します。

"test:vrt:update:e2e":
  "LOOP_VRT_LANE=true playwright test ... --update-snapshots=all"

一方、既存のtest:vrtは先にVITE_E2E_MODE=true pnpm buildを実行しています。playwright.config.ts自身も、Viteのenvはbuild-timeであり、別worktreeや別commit由来のstale buildを再利用してはならないと説明しています。LOOP_VRT_LANE=trueが保証するのはserverの再利用禁止だけで、distの再生成ではありません。

したがって現在のscriptには次の2つの失敗モードがあります。

  • clean checkoutではdist不在で失敗する
  • 開発中のstale distが存在すると、現在のsourceと異なる画面をbaselineとして生成する

このリポジトリでは既に、Playwrightと同じdigest-pinned Docker環境でbuild・snapshot更新を行った実績があります。また、ローカル生成画像とCI画像のfont rasterizationが大きく乖離した前例もあります。

修正案:

"test:vrt:update:e2e":
  "VITE_E2E_MODE=true pnpm build && LOOP_VRT_LANE=true playwright test ... --update-snapshots=all"

を最低条件としてください。より堅牢なのは、CIと同一digestのPlaywright containerを使うmanual candidate producerです。candidateを自動canonical化する必要はありませんが、生成環境は再現可能であるべきです。


P1-3. AC5のfalse-positive回避テストが不足している

現在のcommentテストは、行頭が#のfull-line commentだけです。scannerはcommand line内の文字列をshell構文として解釈しないため、次の説明文を実コマンドと誤認します。

echo "playwright test --update-snapshots=all"
printf '%s\n' 'vitest --update=all'

またVitest公式仕様では、CIにおけるupdate: falseはnone相当ですが、現在のvalidatorはvitest run --update=falseをwrite-capableとして拒否します。 (Vitest)

Issue #1388は「YAML comment・説明文を許可する」と明記していますが、現在の4テストではこの意味論を検証できていません。

評価できる点

設計の方向自体は適切です。

  • CI時のupdateSnapshots: 'none'はPlaywrightの既定missingを上書きする正しい防御です。 (Playwright)
  • candidate producer、canonicalization authority、persistenceを分離したドキュメント変更は、過去のCI artifact採用運用と整合しています。
  • snapshot policyを既存visual artifact validatorへ混入させず、専用scriptへ分離した判断は妥当です。
  • #1389のcomponent VRTを混入させず、baseline PNGを変更していない点もIssue契約どおりです。#1387は完了済み、#1389は引き続きopenです。

承認に必要な最小修正

  1. Playwright -uとVitestの全正式entrypoint・modeを検査する。
  2. quote、line continuation、動的package script名を安全に扱い、解析不能なcommand positionはfail-closedにする。
  3. composite action inputとlocal reusable workflowを解析するか、明示的に拒否する。
  4. 実リポジトリに対する独立integration testを追加し、wiringをYAML構造として検証する。
  5. Playwright configのresolved FullConfig.updateSnapshotsをCI環境で検証する。
  6. candidate生成scriptにbuildを含め、可能ならCIと同一のdigest-pinned Playwright環境を使用する。
  7. 上記の全回避例とfalse-positive例をparameterized testへ追加する。

現状のgreen CIは、validatorの安全性を証明していません。validatorが認識できるケースだけをfixture化してgreenになっている状態です。

GitHubへのレビュー投稿やPR変更は行っていません。

@squne121
squne121 marked this pull request as ready for review August 1, 2026 13:04
@squne121
squne121 merged commit 71f6a26 into main Aug 1, 2026
26 checks passed
@squne121
squne121 deleted the worktree-issue-1388-vrt-snapshot-policy branch August 1, 2026 13:04
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.

実装: required CI を snapshot read-only に固定し baseline canonicalization を reviewed PR 境界に限定する

1 participant