Skip to content

fix(verify-cli): 失敗ヘッダの矛盾と analysis bundle の integrityValid を直す (#217 #219) - #263

Merged
shinyaoguri merged 1 commit into
mainfrom
fix/verify-cli-p3-output-and-bundle
Aug 15, 2026
Merged

fix(verify-cli): 失敗ヘッダの矛盾と analysis bundle の integrityValid を直す (#217 #219)#263
shinyaoguri merged 1 commit into
mainfrom
fix/verify-cli-p3-output-and-bundle

Conversation

@shinyaoguri

Copy link
Copy Markdown
Owner

目的

2026-08 レビュー (#243) の残件のうち、verify-cli の低コスト指摘 2 件を解消する。どちらも exit code には影響しない「読み手に嘘をつく」系。

#217 — スクショ改竄のみの失敗で矛盾したヘッダが出る

修正前 (実行して再現)

✗ Verification FAILED
  Error: All hashes verified successfully (including PoSW)
  ...
Screenshots: FAILED (1/8 tampered — hash mismatch or not backed by the chain)

総合 valid は screenshotsValid で false になる一方、errorMessage は shared のものを素通しするため、チェーンが健全だと成功メッセージが失敗理由として出ていた。

修正後

✗ Verification FAILED
  Screenshots failed: 1/8 tampered — hash mismatch or not backed by the chain

既存の examBindingFailedOnly 分岐と同型で screenshotsFailedOnly を追加。exam 束縛とスクショが同時に落ちる場合 (exam proof の ZIP でスクショも改竄) は片方に潰さず両方出す。

result.valid の計算は変更していない — 表示のみの修正で、機械ゲート (exit 1) の挙動は不変。

#219 — analysis bundle の integrityValid が ADR-0024 の契約違反

buildAnalysisBundle の契約は「派生元 proof が整合性検証を通ったか」だが、gate 込みの result.valid を渡していた。--require-root-anchor で落ちただけの proof が integrityValid: false かつ同じレコードの assurance.integrity: 'proven' という自己矛盾したバンドルになる。

assurance.integrity !== 'failed' に変更した。

=== 'proven' にしなかった理由: PR #253 (ADR-0031) で IntegrityLevel'partial' が入り fast モードが 'partial' になる。'partial' は「実施していない検査がある」であって「整合性が失敗した」ではないので、ここで false に潰すと #214 で直した overclaim の裏返し (underclaim) になる。

なお Issue 本文の「採点者が集めたコホート分布が歪む」という影響記述は事実と異なることを確認した。packages/shared/src/analysis/cohort.tsintegrityValid を一切参照していない。実害は契約違反とレコードの誤情報に限られる。

テスト可能にする小リファクタ

cli.ts は読み込み時に main() が走るためテストから import できない。写像を純関数 toBundleIntegrityValid(assurance) として verify.ts へ切り出した (CLIVerificationResult / assurance を組み立てている当事者で、副作用がない)。

確認方法

テストを先に書き、実装前に赤くなることを実測してから仕上げた (6 failed / 21 passed → 27 passed)。

テスト 修正前 目的
スクショのみ改竄 → 改竄枚数が出る (3 ケース) 🔴 実出力が Error: All hashes verified successfully であることを diff で確認 本命
toBundleIntegrityValid の 3 値 (proven/partial/failed → true/true/false) 🔴 is not a function 本命
チェーン自体が失敗 → Error: Hash mismatch at event 3 🟢 退行防止
exam 束縛のみ失敗 → Exam binding failed: 🟢 退行防止
npm run lint && npm run test:run --workspaces --if-present && npm run build

すべて green (verify-cli は 27 tests)。packages/verify-cli/CLAUDE.md の該当節にも今回の判断を追記した。

Closes #217
Closes #219

#217: スクリーンショットだけが改竄された proof を検証すると、ヘッダに
「Error: All hashes verified successfully (including PoSW)」というチェーンの
成功メッセージが失敗理由として出ていた。総合 valid は screenshotsValid で
false になる一方、errorMessage は shared のものを素通しするため。exam 束縛の
み失敗と同型の矛盾なので、既存の examBindingFailedOnly と同じ形で
screenshotsFailedOnly を足し、改竄枚数を失敗理由として出す。両方落ちたときは
両方出す。exit code の計算 (result.valid) は変えていない。

#219: --analysis-bundle の integrityValid に gate 込みの総合 valid を渡して
いた。buildAnalysisBundle の契約 (ADR-0024) は「派生元 proof が整合性検証を
通ったか」であり、--require-root-anchor で落ちただけの proof が
integrityValid: false かつ assurance.integrity: 'proven' という自己矛盾した
レコードになっていた。assurance.integrity !== 'failed' に変える。'proven' の
完全一致にしないのは、ADR-0031 (#253) で 'partial' が入り fast モードが
'partial' になるため — 「検査を省略した」を「整合性が失敗した」に潰さない。

写像は cli.ts から純関数 toBundleIntegrityValid として verify.ts へ切り出した
(cli.ts は読み込み時に main() が走りテストから import できないため)。

Closes #217
Closes #219

Assisted-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation pkg:verify packages/verify + verify-cli labels Aug 15, 2026
@github-actions

Copy link
Copy Markdown

🚀 Preview Deployment

Name URL
Preview https://6806e480.typedcode.pages.dev

Deployed from commit 1a9410c
API: staging Workers

@shinyaoguri
shinyaoguri merged commit b9b48dc into main Aug 15, 2026
8 checks passed
@shinyaoguri
shinyaoguri deleted the fix/verify-cli-p3-output-and-bundle branch August 15, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation pkg:verify packages/verify + verify-cli

Projects

None yet

1 participant