Skip to content

refactor(diff): migrate diff command to shared loading and reporting - #103

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

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

Conversation

@TFM-HITESH

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

Copy link
Copy Markdown
Contributor

Closes #97

Summary

Migrate vaar diff to the shared source, analysis, diff-engine, application, and output boundaries while preserving existing behavior.

Why

The diff command previously performed direct filesystem reads and invoked raw-byte compatibility wrappers. This change aligns it with the architecture defined in Discussion #58 and makes the CLI a thin application boundary.

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 internal/application/diff to coordinate source loading, analysis conversion, snapshot creation, inventory comparison, and error normalization.
  • Updated internal/cli/diff.go to delegate loading and comparison while retaining argument validation, flags, output writing, and exit-code mapping.
  • Removed obsolete raw-byte and parsed-file wrappers from internal/diff.
  • Preserved path labels, output formats, operational errors, --quiet, --json, conflict handling, and existing exit behavior.
  • Added typed dotenv loading errors to preserve source-path context and compatibility error messages.
  • Updated engine, application, source, and CLI tests.

User-visible changes

None.

The command syntax, output formats, flags, path handling, and exit behavior remain unchanged.

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 lint
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-cli-windows-final.exe ./cmd/vaar
git diff --check

go run ./cmd/vaar lint ... was not run because this ticket does not change lint behavior.

Tests

  • Added tests
  • Updated existing tests
  • No tests needed

Documentation

  • Updated documentation
  • Not applicable

Updated affected package comments and API documentation.

Release notes

Migrates vaar diff to the shared source and analysis pipeline without changing user-visible behavior.

Reviewer notes

Please pay particular attention to:

  • The new internal/application/diff orchestration boundary.
  • Shared dotenv loading and analysis snapshot construction.
  • Preservation of user-supplied relative, absolute, and space-containing path labels.
  • Preservation of operational error messages and exit codes.
  • Removal of obsolete raw-byte and parsed-file compatibility wrappers.
  • Continued value non-disclosure.
  • Cross-platform Windows compatibility.
  • No introduction of an engines package or unrelated query functionality.

Checklist

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

Summary by CodeRabbit

  • New Features

    • Added dotenv file comparison through a unified application workflow.
    • Added clearer error messages for missing files, directories, and unsupported file types.
    • Preserved the relevant file paths in comparison results and loading errors.
  • Bug Fixes

    • The comparison command now stops immediately when its context is canceled.
    • Improved handling and reporting of failures when loading multiple dotenv files.

@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: 30f8c6ac-13bc-4da0-9bbf-cf8907b881b2

📥 Commits

Reviewing files that changed from the base of the PR and between e6220ec and f753182.

📒 Files selected for processing (8)
  • internal/application/diff/application.go
  • internal/application/diff/application_test.go
  • internal/cli/diff.go
  • internal/cli/diff_test.go
  • internal/diff/diff.go
  • internal/diff/diff_test.go
  • internal/source/dotenv/loader.go
  • internal/source/dotenv/loader_test.go
💤 Files with no reviewable changes (1)
  • internal/diff/diff.go

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


📝 Walkthrough

Walkthrough

The diff command now uses a shared dotenv loader, analysis conversion, and inventory comparison service. The CLI delegates comparison and output rendering. The loader returns typed errors with preserved display paths. Legacy raw-byte comparison wrappers were removed.

Changes

Diff command migration

Layer / File(s) Summary
Shared dotenv loader contracts
internal/source/dotenv/loader.go, internal/source/dotenv/loader_test.go
The loader validates directories and non-regular files before opening them. LoadMany returns typed errors that preserve display paths and underlying causes.
Application diff flow
internal/application/diff/*, internal/diff/*
The new application service loads both operands, converts them into analysis snapshots, and compares key inventories. Legacy raw-byte comparison wrappers were removed. Tests cover shared loading, cancellation, labels, key presence, and value non-disclosure.
CLI application boundary
internal/cli/diff.go, internal/cli/diff_test.go
The CLI delegates loading and comparison to the application service and delegates rendering to internal/output/diff. Boundary tests reject direct lower-level imports.

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

Merge Risk: ⚪ Minimal · up to f7531

The diff command now uses shared dotenv loading and analysis-backed comparison while preserving key-only results and path-aware loading errors. No actionable merge-blocking risk is identified.

Sequence Diagram(s)

sequenceDiagram
  participant DiffCLI
  participant ApplicationDiffService
  participant LoadMany
  participant Analysis
  participant DiffEngine
  DiffCLI->>ApplicationDiffService: Run(leftPath, rightPath)
  ApplicationDiffService->>LoadMany: Load both dotenv paths
  LoadMany-->>ApplicationDiffService: Return dotenv documents
  ApplicationDiffService->>Analysis: Build analysis snapshots
  Analysis-->>ApplicationDiffService: Return key inventories
  ApplicationDiffService->>DiffEngine: CompareInventories
  DiffEngine-->>ApplicationDiffService: Return diff result
  ApplicationDiffService-->>DiffCLI: Return result or error
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 7 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 describes the migration of the diff command to shared loading and reporting, which is the primary change.
Linked Issues check ✅ Passed The changes satisfy issue #97: the CLI delegates loading, analysis conversion, diff comparison, and text or JSON reporting to the shared boundaries; obsolete wrappers and direct file-reading orchestra…
Out of Scope Changes check ✅ Passed The changes remain within issue #97. Loader validation and typed errors support the required shared-loading migration, while the remaining changes update orchestration and tests without changing comma…
  • 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
TFM-HITESH merged commit 9a7fbbe 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): migrate the diff command to shared loading and reporting

1 participant