Skip to content

feat: make the validated artifact the canonical CLI contract - #26

Merged
nia-sg-bot merged 5 commits into
mainfrom
nia/issue-23-canonical-contract
Aug 12, 2026
Merged

feat: make the validated artifact the canonical CLI contract#26
nia-sg-bot merged 5 commits into
mainfrom
nia/issue-23-canonical-contract

Conversation

@nia-sg-bot

@nia-sg-bot nia-sg-bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • centralize DiffGraph v2 schema loading, version compatibility, and fail-closed validation
  • build and validate one canonical artifact per invocation, then pass the same sealed artifact to JSON, terminal, and HTML consumers
  • make canonical HTML deterministic, self-contained, and offline while retaining deprecated legacy-html for one compatibility release
  • package a complete local-only golden artifact and document output/error/compatibility behavior

Contract behavior

  • schema_version must use MAJOR.MINOR
  • unknown majors and structurally invalid artifacts are rejected
  • supported additive 2.x artifacts are accepted only when valid against the packaged consumer schema
  • canonical output does not require AI credentials or network access
  • JSON writes are atomic and machine-readable stdout remains uncontaminated

Verification

  • python3 -m pytest -q — 94 passed
  • python3 -m compileall -q diffgraph tests mcp_server.py build.py
  • git diff --check

Follow-up compatibility

Companion extension compatibility PR: WildestAI/wildest-vscode-ext#24. It vendors this exact golden fixture and exercises the same version policy in extension CI. The broader JSON-backed Webview migration remains scoped to wildest-vscode-ext#17.

Closes #23

Summary by CodeRabbit

  • New Features

    • Added deterministic, offline artifact generation with validation and canonical JSON output.
    • Added self-contained canonical HTML reports with embedded data, sorted results, warnings, metadata, and summaries.
    • Added JSON, terminal, HTML, and legacy HTML output options with format-specific defaults.
    • Added schema compatibility checks and clearer validation errors.
  • Improvements

    • Diff reports now default to canonical HTML.
    • Terminal output includes clearer no-change messaging and updated change statistics.
    • Reports and artifacts are written safely without replacing existing files on failure.
  • Documentation

    • Expanded usage, formats, exit codes, offline behavior, compatibility, and report documentation.

Make schema versioning and fail-closed validation reusable by producers and consumers. Add a packaged structural golden artifact and compatibility tests as the first bounded step toward issue #23.
Build and validate local DiffGraph data once before routing the same object to JSON or terminal consumers. Define offline output, conflict, no-change, cancellation, and atomic-write behavior while preserving the legacy HTML path.
Make the default HTML report a self-contained offline consumer of the once-built validated artifact. Keep the former AI report behind an explicit deprecated legacy mode for one compatibility release.
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e42a2b31-e463-4ee5-8633-32d321cd14d9

📥 Commits

Reviewing files that changed from the base of the PR and between be6e4ae and 970ff11.

📒 Files selected for processing (8)
  • README.md
  • diffgraph/cli.py
  • diffgraph/contract.py
  • diffgraph/structural.py
  • tests/test_artifact_dispatch.py
  • tests/test_contract.py
  • tests/test_html_formatter.py
  • tests/test_structural.py
🚧 Files skipped from review as they are similar to previous changes (6)
  • tests/test_contract.py
  • README.md
  • tests/test_artifact_dispatch.py
  • tests/test_html_formatter.py
  • diffgraph/contract.py
  • tests/test_structural.py

Walkthrough

The CLI now creates one validated, versioned DiffGraph artifact and routes it to canonical JSON, terminal, and HTML outputs. Canonical reports are deterministic, local, and atomically written. AI HTML remains available only through explicit legacy-html compatibility mode.

Changes

Canonical DiffGraph artifact

Layer / File(s) Summary
Artifact contract and schema
diffgraph/contract.py, diffgraph/structural.py, diffgraph/schema/..., setup.py, tests/test_contract.py, tests/test_structural.py
Adds validated-artifact wrapping, schema-version compatibility checks, packaged schema loading, fail-closed validation, canonical schema examples, and deterministic line statistics.
Artifact construction and JSON output
diffgraph/artifact.py, tests/test_artifact_dispatch.py
Builds and validates one local artifact, renders stable JSON, and atomically writes JSON output.
CLI artifact dispatch
diffgraph/cli.py, README.md, tests/test_artifact_dispatch.py, tests/test_structural.py
Adds canonical html, terminal, and json formats, validates option combinations, reuses one validated artifact per invocation, defines output and cancellation behavior, and retains explicit legacy-html compatibility mode.
Canonical report formatters
diffgraph/formatters/html.py, diffgraph/formatters/terminal.py, tests/test_html_formatter.py, tests/test_terminal_formatter.py
Adds deterministic self-contained HTML rendering and atomic writes. Terminal rendering accepts validated artifacts, reports empty snapshots, and uses direct line-addition and line-removal fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

Possibly related PRs

  • WildestAI/DiffGraph-CLI#11: This PR replaces the earlier JSON export path with canonical artifact construction, validation, and dispatch.
  • WildestAI/DiffGraph-CLI#24: This PR builds on the structural extraction and CLI path with shared artifact contracts and formatters.
  • WildestAI/DiffGraph-CLI#19: This PR updates the existing terminal formatter and CLI integration to consume canonical validated artifacts.

Suggested labels: roadmap

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.35% which is insufficient. The required threshold is 80.00%. 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 states the primary change: making the validated artifact the canonical CLI contract.
Linked Issues check ✅ Passed The changes implement the linked issue objectives for one validated artifact, schema compatibility, canonical outputs, offline behavior, and legacy support [#23].
Out of Scope Changes check ✅ Passed The code, schema, documentation, packaging, and tests directly support the linked issue objectives.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nia/issue-23-canonical-contract

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@diffgraph/cli.py`:
- Around line 329-336: Update the browser-launch block guarded by no_open in the
CLI to catch OSError from os.startfile and subprocess calls, emit a warning to
stderr, and check returncode for the macOS open and Linux xdg-open commands,
warning when either exits nonzero instead of reporting successful launch.
- Around line 254-270: Add validation alongside the existing option checks in
the CLI command handling around structural_json, output_format, and
format_was_explicit: reject --debug-env when structural_json is set,
output_format is json or terminal, or output_format is explicitly html. Raise a
click.UsageError before debug_environment() can run, while preserving existing
behavior for legacy HTML and non-canonical formats.

In `@diffgraph/contract.py`:
- Around line 33-40: Update ValidatedArtifact.from_value() and the value access
path to prevent post-validation mutation: retain an immutable representation or
a private deep copy, and return defensive copies if the value remains exposed as
a dictionary. Ensure trusted consumers such as TerminalFormatter cannot observe
changes made through the original artifact or artifact.value.

In `@diffgraph/formatters/terminal.py`:
- Around line 316-317: Update analyze_local_diff to include accurate lines_added
and lines_removed values for each changed file so the terminal formatter’s
existing fallback reports real statistics instead of zeroes. Add an integration
test covering the producer output and verifying these fields are emitted
correctly.

In `@README.md`:
- Line 58: Update the README option description for --api-key to mark it as
legacy-only, explicitly stating that it applies only when using --format
legacy-html.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 89cf217d-bd18-441f-a58a-8b6ef3d02a36

📥 Commits

Reviewing files that changed from the base of the PR and between 5663dce and be6e4ae.

📒 Files selected for processing (14)
  • README.md
  • diffgraph/artifact.py
  • diffgraph/cli.py
  • diffgraph/contract.py
  • diffgraph/formatters/html.py
  • diffgraph/formatters/terminal.py
  • diffgraph/schema/diffgraph-v2.structural.example.json
  • diffgraph/structural.py
  • setup.py
  • tests/test_artifact_dispatch.py
  • tests/test_contract.py
  • tests/test_html_formatter.py
  • tests/test_structural.py
  • tests/test_terminal_formatter.py

Comment thread diffgraph/cli.py
Comment thread diffgraph/cli.py Outdated
Comment thread diffgraph/contract.py Outdated
Comment thread diffgraph/formatters/terminal.py
Comment thread README.md Outdated
Keep canonical artifact output isolated from environment diagnostics, preserve successful HTML generation when browser launch fails, and populate deterministic file line statistics. Clarify that API credentials belong only to the deprecated legacy renderer and cover each behavior with regression tests.
@nia-sg-bot
nia-sg-bot merged commit 3b6b483 into main Aug 12, 2026
4 checks passed
@nia-sg-bot
nia-sg-bot deleted the nia/issue-23-canonical-contract branch August 12, 2026 18:03
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.

Make one validated, versioned DiffGraph artifact the canonical CLI contract

1 participant