Skip to content

Json output#51

Open
Dragyx wants to merge 6 commits intomainfrom
json-output
Open

Json output#51
Dragyx wants to merge 6 commits intomainfrom
json-output

Conversation

@Dragyx
Copy link
Collaborator

@Dragyx Dragyx commented Jan 30, 2026

Adds an optional feature that allows to output the diffs as JSON instead of printing the normal report.

This PR is still in its early stages and the outputted format is subject to change.

Depends on #50.

Implements #41.

@Dragyx Dragyx self-assigned this Jan 30, 2026
Copilot AI review requested due to automatic review settings January 30, 2026 15:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an optional JSON output feature to the dix tool, allowing users to get structured output suitable for programmatic processing. The PR also implements a significant refactoring of the store backend to support multiple fallback mechanisms (direct database queries, immutable database access, and command-line tools).

Changes:

  • Adds JSON serialization support for diff output with serde/serde_json dependencies
  • Refactors store backend into a trait-based architecture with lazy, eager, and command-based implementations
  • Introduces new CLI flag --json-output to enable JSON output mode
  • Adds --force-correctness flag to prefer correctness over performance

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
Cargo.toml Adds serde and serde_json dependencies with optional json feature (enabled by default)
Cargo.lock Lock file updates for new dependencies
src/version.rs Adds Serialize derive for Version struct when json feature is enabled
src/store/queries.rs Extracts SQL queries into constants (refactored from store.rs)
src/store/nix_command.rs New fallback backend using nix commands for querying store data
src/store/db_lazy.rs New lazy database connection implementation with streaming results
src/store/db_eager.rs New eager database connection that collects all results upfront
src/store/db_common.rs Common database utilities shared between lazy and eager backends
src/store.rs Major refactoring introducing StoreBackend trait and CombinedStoreBackend for fallback support
src/main.rs Adds CLI arguments for json-output and force-correctness flags
src/lib.rs Exposes json module and path_to_canonical_string utility function
src/json.rs New module implementing JSON serialization and output for diffs
src/diff.rs Updates to support new backend abstraction and expose helper functions
Comments suppressed due to low confidence (1)

src/main.rs:161

  • The error message formatting has an unusual line break. The string literal should either be on a single line or use proper multi-line string formatting with backslash continuation or raw strings.
    anyhow!(
      "failed to get closure size due to thread
  error"
    )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 43 to 45
let references = Command::new("nix-store").args(args).output();

let query = references?;
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command execution does not check if the command succeeded (via status code). The code should verify that the command exited successfully before attempting to parse the output. Consider checking the output status and returning an error if the command failed, including stderr in the error message for debugging.

Copilot uses AI. Check for mistakes.
src/json.rs Outdated
Comment on lines 69 to 71
pub fn serialize_diffs(diffs: &[Diff]) -> Result<String> {
serde_json::to_string(&diffs).map_err(|e| e.into())
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The json module lacks test coverage. Given that the repository has comprehensive tests for diff.rs and store.rs, tests should be added for the JSON serialization functionality, including: (1) testing that serialize_diffs produces valid JSON, (2) testing that the JSON structure matches expectations, and (3) verifying that all necessary fields are serialized correctly.

Copilot uses AI. Check for mistakes.
@Dragyx Dragyx force-pushed the json-output branch 4 times, most recently from 6a8c9fa to 38ce02b Compare January 30, 2026 17:13
Prints the internal Vec<Diff> as json. We
might want to fix some format in the future, since
the output is currently quite verbose.
@RGBCube
Copy link
Collaborator

RGBCube commented Feb 1, 2026

Good stuff, mostly some code style nits & better flag naming

@Dragyx
Copy link
Collaborator Author

Dragyx commented Feb 8, 2026

Thanks @RGBCube for having a look at the code!

let stderr = String::from_utf8_lossy(&cmd_res.stderr);
bail!(
"nix command exited with non-zero status {}: {}",
cmd_res.status,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer keyword arguments here too, foo = foo.bar() and do {foo} in format strings. Do it on all of these, there are others in the diff too.

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.

2 participants