fix(frontend): unknown JSON の型キャストを zod safeParse に置き換え (#114) - #130
Merged
Conversation
…114) - Add diff-summary-schema.ts with zod schemas for FileChanges, BomChanges, CheckEntry, ArtifactChanges - Rewrite parseDiffSummary to use field-level safeParse instead of type guards - Add parseApiErrorMessage helper for API error extraction - Replace as casts in run-detail-content.tsx and create-token-dialog.tsx - Remove unused DiffSummary interface from schema-types.ts - Strip replaced type guards from guards.ts (keep isRecord for other consumers)
- Return null when checks object has entries but all fail safeParse - Use result.data from safeParse for type-safe parsed values - Add vitest and comprehensive test suite for parseDiffSummary
When parseDiffSummary returns null for checks (malformed data), the summary card now shows 'data format not recognized' instead of silently dropping the section. Refs #114
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
OpenAPI schema 上で
unknownとして扱われるdiff.summaryフィールドや API エラーのパースに使われていた危険なas型キャストを、zodsafeParseベースの実装へ置き換えるリファクタリングです。Closes #114
背景・要件
run-detail-content.tsxでdiffError as Record<string, unknown>/diffError as Record<string, { message?: string }>のキャストが使われていたcreate-token-dialog.tsxでerr as { error?: { message?: string } }のキャストが使われていたguards.tsの手動 type guard 4関数 (isFileChanges,isBomChanges,isCheckEntry,isArtifactChanges) を宣言的な zod schema に置き換える調査結果
diff.summary as DiffSummaryのキャストは実装前から既にゼロ件(parseDiffSummary(raw: unknown)に移行済み)asキャストは API error の2箇所のみguards.tsの type guard 4関数はdiff-summary.tsからのみ呼ばれていた(isRecordは3コンポーネントで使用中のため残存)DiffSummaryinterface は import 0件で未使用実装概要
変更ファイル一覧(9件)
boardflow/src/lib/domain/diff-summary-schema.tsFileChangesSchema/BomChangesSchema/CheckEntrySchema/ArtifactChangesSchemaの zod schemaboardflow/src/lib/domain/diff-summary.tsparseDiffSummaryをsafeParseベースに書き換え。checks の全 entry 不正時にnull返却boardflow/src/lib/domain/guards.tsisRecordのみ残存boardflow/src/lib/api/error.tsparseApiErrorMessage(err: unknown): string | nullhelperboardflow/src/components/run-detail/run-detail-content.tsxas Record<...>→parseApiErrorMessageに置換boardflow/src/components/tokens/create-token-dialog.tsxas { error?: ... }→parseApiErrorMessageに置換boardflow/src/lib/api/schema-types.tsDiffSummaryinterface 削除boardflow/src/lib/domain/__tests__/diff-summary.test.tsboardflow/src/components/run-detail/run-diff-summary-card.tsxnull時の "Checks: data format not recognized" fallback 追加設計方針
parseDiffSummaryのシグネチャ (raw: unknown → ParsedDiffSummary) は不変 → 消費側コンポーネントの変更不要safeParse: 1フィールド不正でも他は正常に返る既存挙動を維持parseApiErrorMessageは zod ではなく軽量 typeof チェック helper として実装(API error の構造が OpenAPI に未定義のため、zod import のコスト増を避けた)nullを返して "Data format not recognized" fallback を表示(silent drop を防止)テスト結果
pnpm lintpnpm typecheckpnpm build更新ドキュメント
docs/logs/114/worklog.md— 作業ログ(research / plan / impl / review 2ラウンド / docs 確認)docs/external/zod-v4-safeparse-unknown-json.md— zod v4 safeParse の外部調査メモ外部調査メモ
safeParseAPI は v3 と互換。result.success/result.data/result.errorの構造は変更なしsafeParseを適用して部分的 fallback を維持する方針は妥当と確認残リスク
diff-summary-schema.tsの zod schema とdiff-summary.tsの TypeScript interface が並存。将来z.infer<typeof Schema>に統一可能{ error: { message: string } }は OpenAPI schema に未定義。backend 変更時はparseApiErrorMessageがnullを返し fallback メッセージが表示される(安全側に倒れる)isRecordの将来移動:guards.tsにisRecordのみが残っている状態。必要に応じてutils.ts等に移動検討可能README.mdの lint 記述不整合:pnpm lintの説明が「ESLint 実行」だが実装はbiome check(今回の変更起因ではない既存不整合)review / docs OK 判定
pr_ready: true(2ラウンドの指摘を修正後)docs_ready: true