Skip to content

Commit 301310e

Browse files
committed
Add golden file snapshot tests for report regression detection (D-2)
13 tests in GoldenFileSnapshotTests: 10 structural validation tests for doc/samples/diff_report.md (sections, ordering, counts, tables) and 3 regeneration snapshot tests that generate deterministic reports and compare against stored .snapshot files. Supports UPDATE_SNAPSHOTS env var for snapshot updates. https://claude.ai/code/session_014v4R8NahVRpg3EWuGrgBEe
1 parent 68dc3e7 commit 301310e

3 files changed

Lines changed: 546 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1717

1818
- **Jest unit tests for HTML report JavaScript (`diff_report.js`)** — Added 47 Jest/jsdom tests in [`JsTests/diff_report.test.js`](JsTests/diff_report.test.js) covering all major client-side functions: `formatTs` date formatting, `collectState` with filter-ID exclusion, `autoSave` localStorage persistence, `getFileTypeCategory` extension classification (20 cases including case-insensitivity and null/undefined), `applyFilters` file-type/importance/unchecked-only/search filtering with associated diff-row sibling hiding, `resetFilters` default restoration, `decodeDiffHtml` base64 UTF-8 decoding (including multibyte characters), `collapseAll` details folding, `clearAll` input reset with confirm guard, DOMContentLoaded state restore from `__savedState__` and localStorage, reviewed-mode read-only enforcement, `verifyIntegrity` null-guard, and `setupLazyDiff` lazy decode/insert with no-duplicate guard. Infrastructure: [`package.json`](package.json) with Jest/jsdom devDependencies, [`jest.config.js`](jest.config.js), [`JsTests/`](JsTests/) directory. Run: `npm run test:js`. Updated [`TESTING_GUIDE.md`](doc/TESTING_GUIDE.md) scope maps (EN+JA).
1919

20+
- **Golden file snapshot tests for report regression detection** — Added 13 tests in [`GoldenFileSnapshotTests`](FolderDiffIL4DotNet.Tests/Services/GoldenFileSnapshotTests.cs) that validate report output against golden files and detect regressions. Two categories: (1) **Structural validation** (10 tests) — validates `doc/samples/diff_report.md` for section existence, section ordering, section-count-vs-Summary-table consistency, disassembler availability table format, importance levels in modified files, legend tables (Diff Detail + Change Importance), IL Cache Stats completeness, header metadata fields, warning types (SHA256Mismatch + timestamp regression). (2) **Regeneration snapshots** (3 tests) — generates deterministic reports from known test data (timestamps disabled) and compares against stored `.snapshot` files in `FolderDiffIL4DotNet.Tests/Snapshots/`. Supports `UPDATE_SNAPSHOTS=true` environment variable to regenerate snapshots. Covers Markdown basic, Markdown with semantic changes (High/Medium/Low importance), and HTML basic reports. Uses `[SkippableFact]`-based `Skip.If` for first-run snapshot creation. Updated test count in [`TESTING_GUIDE.md`](doc/TESTING_GUIDE.md) from 641 to 654 and added "Golden file snapshots" row to scope maps (EN+JA).
21+
2022
- **CA1031 catch-all fallback path tests** — Added 5 tests to improve coverage quality for `#pragma warning disable CA1031` best-effort error handling paths. In [`AssemblyMethodAnalyzerTests`](FolderDiffIL4DotNet.Tests/Services/AssemblyMethodAnalyzerTests.cs): `Analyze_TruncatedPEFile_ReturnsNull` (MZ header with truncated PE data), `Analyze_EmptyFile_ReturnsNull` (zero-byte file), `Analyze_CorruptPEWithValidHeader_ReturnsNull` (real assembly with corrupted metadata tables), `Analyze_OneValidOneCorrupt_ReturnsNull` (asymmetric valid-vs-corrupt pair). In [`FileDiffServiceUnitTests`](FolderDiffIL4DotNet.Tests/Services/FileDiffServiceUnitTests.cs): `FilesAreEqualAsync_WhenSemanticAnalysisThrows_LogsWarningAndDoesNotCrash` (verifies `TryAnalyzeAssemblySemanticChanges` CA1031 catch-all logs a warning without affecting the diff result). Updated test count in [`TESTING_GUIDE.md`](doc/TESTING_GUIDE.md) from 636 to 641.
2123

2224
#### Changed
@@ -589,6 +591,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
589591

590592
- **HTML レポート JavaScript (`diff_report.js`) の Jest ユニットテスト** — [`JsTests/diff_report.test.js`](JsTests/diff_report.test.js) に 47 件の Jest/jsdom テストを追加。主要なクライアントサイド関数をカバー: `formatTs` 日付フォーマット、`collectState` フィルタ ID 除外、`autoSave` localStorage 永続化、`getFileTypeCategory` 拡張子分類(20 ケース、大文字小文字無視・null/undefined 含む)、`applyFilters` ファイル種別/重要度/未チェックのみ/検索フィルタリングと関連 diff-row の非表示、`resetFilters` デフォルト復元、`decodeDiffHtml` base64 UTF-8 デコード(マルチバイト文字含む)、`collapseAll` details 折りたたみ、`clearAll` 入力リセットと confirm ガード、DOMContentLoaded 状態復元、レビュー済みモード読み取り専用化、`verifyIntegrity` null ガード、`setupLazyDiff` 遅延デコード/挿入と重複防止。基盤: [`package.json`](package.json)、[`jest.config.js`](jest.config.js)、[`JsTests/`](JsTests/) ディレクトリ。実行: `npm run test:js`。[`TESTING_GUIDE.md`](doc/TESTING_GUIDE.md) 範囲マップ(EN+JA)を更新。
591593

594+
- **ゴールデンファイルスナップショットテストによるレポートリグレッション検出** — [`GoldenFileSnapshotTests`](FolderDiffIL4DotNet.Tests/Services/GoldenFileSnapshotTests.cs) に 13 テストを追加し、レポート出力をゴールデンファイルと照合してリグレッションを検出する。2 カテゴリ: (1) **構造検証**(10 テスト)— `doc/samples/diff_report.md` のセクション存在・セクション順序・セクション件数と Summary テーブルの整合・逆アセンブラ利用可否テーブル形式・Modified ファイルの重要度レベル・凡例テーブル(Diff Detail + Change Importance)・IL Cache Stats メトリクスの網羅性・ヘッダーメタデータフィールド・警告タイプ(SHA256Mismatch + タイムスタンプ回帰)を検証。(2) **再生成スナップショット**(3 テスト)— 決定論的テストデータ(タイムスタンプ無効)からレポートを生成し、`FolderDiffIL4DotNet.Tests/Snapshots/` の `.snapshot` ファイルと比較。`UPDATE_SNAPSHOTS=true` 環境変数でスナップショット再生成に対応。Markdown 基本・Markdown セマンティック変更付き(High/Medium/Low 重要度)・HTML 基本の 3 パターンをカバー。初回実行時は `[SkippableFact]` ベースの `Skip.If` でスナップショット作成。[`TESTING_GUIDE.md`](doc/TESTING_GUIDE.md) のテスト件数を 641 → 654 に更新し、範囲マップ(EN+JA)に「ゴールデンファイルスナップショット」行を追加。
595+
592596
- **CA1031 catch-all フォールバックパスのテスト** — `#pragma warning disable CA1031` のベストエフォートエラーハンドリングパスのカバレッジ品質向上のため 5 テストを追加。[`AssemblyMethodAnalyzerTests`](FolderDiffIL4DotNet.Tests/Services/AssemblyMethodAnalyzerTests.cs): `Analyze_TruncatedPEFile_ReturnsNull`(MZ ヘッダー付き切り詰め PE データ)、`Analyze_EmptyFile_ReturnsNull`(0 バイトファイル)、`Analyze_CorruptPEWithValidHeader_ReturnsNull`(メタデータテーブル破損の実アセンブリ)、`Analyze_OneValidOneCorrupt_ReturnsNull`(正常と破損の非対称ペア)。[`FileDiffServiceUnitTests`](FolderDiffIL4DotNet.Tests/Services/FileDiffServiceUnitTests.cs): `FilesAreEqualAsync_WhenSemanticAnalysisThrows_LogsWarningAndDoesNotCrash`(`TryAnalyzeAssemblySemanticChanges` の CA1031 catch-all が差分結果に影響せず警告ログのみ出力されることを検証)。[`TESTING_GUIDE.md`](doc/TESTING_GUIDE.md) のテスト件数を 636 → 641 に更新。
593597

594598
#### Changed

0 commit comments

Comments
 (0)