Skip to content

refactor(diff): compare analysis key inventories - #102

Merged
TFM-HITESH merged 1 commit into
envaar:mainfrom
TFM-HITESH:refactor/diff-analysis
Sep 8, 2026
Merged

TFM-HITESH merged 1 commit into
envaar:mainfrom
TFM-HITESH:refactor/diff-analysis

Conversation

@TFM-HITESH

@TFM-HITESH TFM-HITESH commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #96

Summary

Move diff key comparison onto the analysis-owned key inventory while preserving the existing diff result and compatibility behavior.

Why

Discussion #58 defines analysis as the normalized fact boundary consumed by command engines. Diff should compare analysis key inventories instead of deriving private key sets directly from parser-owned files.

Type

  • Bug fix
  • New rule
  • Parser change/fix
  • Reporter change/fix
  • Documentation
  • CI / Release
  • Build
  • Performance improvement/change
  • Internal refactor
  • Hotfix

Breaking change

  • No
  • Yes (describe required migration)

Changes

  • Added diff.CompareInventories for comparing two analysis.KeyInventory values.
  • Preserved diff.Result, HasDifferences, deterministic missing-key ordering, case sensitivity, empty assignments, duplicate handling, malformed-line filtering, and value non-disclosure.
  • Updated CompareFiles to convert parsed documents into value-free analysis inventories before comparison.
  • Retained Compare and CompareFiles as temporary compatibility wrappers for the later diff CLI migration in refactor(diff): migrate the diff command to shared loading and reporting #97.
  • Added focused inventory comparison tests.

User-visible changes

None.

The diff CLI, output formats, exit behavior, and command syntax are unchanged. CLI migration is intentionally deferred to #97.

Validation

Commands run:

  • gofmt -w <touched Go files>
  • make lint
  • go test ./...
  • go run ./cmd/vaar lint ...

Additional commands:

GOCACHE=/tmp/vaar-go-cache go test -count=1 ./...
GOCACHE=/tmp/vaar-go-cache go vet ./...
GOCACHE=/tmp/vaar-go-cache make build
GOCACHE=/tmp/vaar-go-cache GOOS=windows GOARCH=amd64 go vet ./...
GOCACHE=/tmp/vaar-go-cache GOOS=windows GOARCH=amd64 go build -buildvcs=false -o /tmp/vaar-diff-windows.exe ./cmd/vaar
git diff --check

go run ./cmd/vaar lint ... was not run because this ticket does not modify the lint command.

Tests

  • Added tests
  • Updated existing tests
  • No tests needed

Tests cover matching inventories, missing keys, deterministic ordering, empty assignments, duplicate declarations, case-sensitive comparison, bare and malformed declarations, HasDifferences, labels, and value non-disclosure.

Documentation

  • Updated documentation
  • Not applicable

Added API and compatibility-wrapper documentation describing the analysis boundary and the temporary migration seam.

Release notes

Moves diff key comparison onto value-free analysis inventories without changing current CLI behavior.

Reviewer notes

Please pay particular attention to:

  • CompareInventories depending only on analysis.KeyInventory.
  • Preservation of existing diff.Result and HasDifferences behavior.
  • Sorted and case-sensitive missing-key results.
  • Empty assignments counting as present keys.
  • Duplicate declarations collapsing to one inventory entry.
  • Bare keys and malformed declarations remaining excluded.
  • No value comparison or value disclosure.
  • Compare and CompareFiles remaining temporary compatibility wrappers for refactor(diff): migrate the diff command to shared loading and reporting #97.
  • No CLI, reporter, filesystem, or output changes in this ticket.

The legacy internal/envfile wrapper remains intentionally until the diff command migration in #97.

Checklist

  • PR title follows Conventional Commits
  • Code is formatted
  • Tests pass
  • Documentation is updated
  • Release note added
  • No real secrets, credentials or sensitive data is included

Summary by CodeRabbit

  • Bug Fixes
    • Improved comparison results to consistently identify missing keys, including when files contain empty assignments.
    • Preserved clear left/right labels when displaying differences, including comparisons involving empty files.
    • Duplicate keys are handled consistently, while bare or malformed declarations are excluded from comparison results.
    • Comparison output continues to show key differences without exposing assigned values.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0fbb97f2-1a05-451d-81c3-e81d5b046e4b

📥 Commits

Reviewing files that changed from the base of the PR and between f29356f and de4c317.

📒 Files selected for processing (2)
  • internal/diff/diff.go
  • internal/diff/inventory_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The diff package now compares analysis.KeyInventory values through CompareInventories. CompareFiles converts parsed files into inventories and delegates to the new function. Tests cover ordering, presence semantics, malformed declarations, duplicate keys, differences, and value non-disclosure.

Changes

Diff inventory comparison

Layer / File(s) Summary
Inventory comparison API and validation
internal/diff/diff.go, internal/diff/inventory_test.go
CompareInventories compares shared key inventories and returns sorted missing-key lists. Tests verify labels, key presence rules, case sensitivity, duplicate handling, malformed declarations, differences, and value non-disclosure.
Parsed-file compatibility adapter
internal/diff/diff.go
CompareFiles converts envfile.File lines into analysis.Line records and delegates to CompareInventories. The existing Compare wrapper is marked as temporary compatibility code.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to de4c3

Diff comparison now uses analysis-owned key inventories while retaining existing file-based behavior. Missing-key results remain deterministic and value-free, with no current merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: refactoring diff comparison to use analysis key inventories.
Linked Issues check ✅ Passed The implementation satisfies issue #96. It adds inventory-based comparison, preserves result behavior and ordering, handles presence semantics, excludes invalid declarations, avoids value disclosure, …
Out of Scope Changes check ✅ Passed The changes remain within issue #96. The implementation and tests directly support the inventory-based diff refactor and do not introduce unrelated CLI, filesystem, reporter, or value-comparison chang…
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@TFM-HITESH

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@TFM-HITESH
TFM-HITESH merged commit e6220ec into envaar:main Sep 8, 2026
7 checks passed
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.

refactor(diff): compare analysis key inventories

1 participant