Skip to content

feat: implement pretty report generator with golden tests - #6

Merged
pfrederiksen merged 1 commit into
mainfrom
feat/pretty-report
Jan 16, 2026
Merged

pfrederiksen merged 1 commit into
mainfrom
feat/pretty-report

Conversation

@pfrederiksen

Copy link
Copy Markdown
Owner

Summary

Implement human-friendly pretty report generator with comprehensive golden tests for output validation.

Features

Report Generation

  • Summary Statistics: Count of changes by type (added, removed, modified, moved)
  • Detailed Listings: Each change with symbol, path, and values
  • Configurable Output: Compact vs detailed, show/hide values, value length limits

Smart Value Formatting

Numbers:    42 (whole), 3.14 (decimal)
Strings:    "hello"
Objects:    {...} (2 keys)
Arrays:     [...] (5 items)
Null:       null
Truncated:  "this i... (when exceeds max length)

Change Symbols

+  Added
-  Removed
~  Modified
↔  Moved

Output Modes

Detailed (default):

Summary: +1 added, -1 removed, ~1 modified (3 total)

Changes:
  + /spec/replicas = 5

  ~ /spec/image: "nginx:1.19" → "nginx:1.20"

  - /metadata/annotations/deprecated (was: "true")

Compact:

Summary: +2 added, -1 removed (3 total)
Changes:
  + /newKey
  + /another
  - /oldKey

API

// Use default detailed report (auto-generated in Result)
result, _ := configdiff.DiffYAML(oldYAML, newYAML, opts)
fmt.Println(result.Report)

// Generate custom reports
report.Generate(changes, report.Options{
    Compact:        false,
    ShowValues:     true,
    MaxValueLength: 80,
})

// Convenience functions
report.GenerateCompact(changes)   // Minimal output
report.GenerateDetailed(changes)  // Full output

Golden Tests

10 golden test files validate output:

  • empty.txt - No changes
  • single_add.txt - Single addition
  • single_remove.txt - Single removal
  • single_modify.txt - Single modification
  • multiple_changes.txt - Mixed changes
  • complex_values.txt - Objects and arrays
  • compact_format.txt - Compact mode
  • without_values.txt - Values hidden
  • value_truncation.txt - Long value handling
  • number_formatting.txt - Number display

Run go test ./report/... -update to regenerate golden files.

Integration

  • Automatically generates detailed report in DiffTrees()
  • Result.Report field now populated
  • Users get pretty output by default

Test Coverage

Report Package: 93.8%
Overall Project: 84.8%

Test Categories

  • ✅ Golden file tests (all output formats)
  • ✅ Summary generation and formatting
  • ✅ Change formatting with all types
  • ✅ Value formatting (all node types)
  • ✅ Truncation handling
  • ✅ Number formatting (whole vs decimal)
  • ✅ Compact vs detailed modes

Example Output

See golden files in testdata/report/ for exact formatting.

Test Plan

  • All tests pass locally
  • Golden tests validate output
  • Race detector passes
  • Coverage exceeds 80% threshold (84.8%)
  • Linting passes
  • Integration with main API verified

🤖 Generated with Claude Code

Add human-friendly report generation:
- Summary statistics (added, removed, modified, moved)
- Detailed change listings with symbols (+, -, ~, ↔)
- Value display with before/after for modifications
- Configurable options (compact, show values, max length)
- Number formatting (whole numbers vs decimals)
- Object/array summarization ({...} N keys, [...] N items)
- Value truncation for long strings

Features:
- Generate(): Full report with customizable options
- GenerateCompact(): Minimal output without values
- GenerateDetailed(): Full output with all values
- DefaultOptions(): Sensible defaults
- formatValue(): Smart value formatting by type

Golden Tests:
- 10 golden test files in testdata/report/
- Tests for all change types and formats
- Value truncation and formatting tests
- Compact vs detailed output tests
- Run with -update flag to regenerate

Integration:
- Wire up in DiffTrees() to populate Result.Report
- Automatic detailed report generation

Testing:
- Comprehensive test suite with 93.8% coverage
- Golden file tests for output validation
- Unit tests for all formatting functions
- Overall project coverage: 84.8%

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@pfrederiksen
pfrederiksen merged commit 6cc6f16 into main Jan 16, 2026
5 of 6 checks passed
@pfrederiksen
pfrederiksen deleted the feat/pretty-report branch January 16, 2026 23:02
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.

1 participant