Skip to content

feat(cli): cg diff drift check (exit 0 clean, 1 drift, 2 error) - #465

Merged
nightmoose merged 1 commit into
stagingfrom
feat/cg-diff-exit-code
Nov 26, 2026
Merged

nightmoose merged 1 commit into
stagingfrom
feat/cg-diff-exit-code

Conversation

@nightmoose

Copy link
Copy Markdown
Owner

What

Adds cg diff, a read-only drift check: each local contract YAML is compared with the latest stable version on the gateway. It exits non-zero on drift so a scheduled job or PR check can fail on it.

Correction to the brief: cg diff did not exist before this PR (RFC-015 reserved the name and deferred it), so there was no earlier exit code to change and nothing in CI or elsewhere called it. This PR adds the command.

Exit Meaning
0 No drift
1 Drift: a file differs from the deployed stable version, or is not deployed (a deployed contract with no local file counts only with --fail-on-remote-only)
2 The check could not run (nothing matched, unparseable file, gateway unreachable or key rejected, --name matched nothing). Error wins over drift

Matches cg test and cg synth (0 clean, 1 findings, 2 harness problem). A missing key still exits 11 and a bad config 10, as for push and pull.

Flags: --dir, --name, --fail-on-remote-only, --json.

Notes

  • Comparison is on file text ignoring line endings and trailing whitespace, the same text cg pull writes and cg push sends. Field-level changes are listed using the POST /contracts/diff logic.
  • To share that logic with the CLI, the pure diff moved from src/infer_diff.rs to src/contract_diff.rs (library). infer_diff re-exports it; the HTTP endpoint is unchanged and its 9 unit tests still pass.
  • No migrations, no server behavior change.
  • Callers checked: nothing in .github/, actions/, scripts/, integrations/, examples/ or the SDKs calls diff.
  • Not in 0.4.2; ships with the next release.

Tests

  • tests/cli_diff.rs: 13 tests against an in-process stub gateway (no drift, whitespace-only, changed field, comment-only, not deployed, no stable version (the real 409), remote-only with and without the flag, --name, bad file, error beats drift, gateway 500, unreachable, empty dir).
  • Unit tests in src/cli/commands/diff.rs.
  • Manual run against staging (read-only, demo org): pull then diff gives exit 0; a one-field edit gives exit 1 with required_changed; an undeployed file gives exit 1; bad key gives exit 2; no key gives exit 11.

Docs: docs/cg-diff-reference.md, docs/STATUS.md entry, RFC-015 note. (The repo has no root CHANGELOG; release notes are generated from PRs.)

…oyed stable version

Exit 0 no drift, 1 drift or not deployed, 2 check could not run. Reads only.
Moves the pure field diff to src/contract_diff.rs so the CLI and
POST /contracts/diff share it. Tests: tests/cli_diff.rs. Docs:
docs/cg-diff-reference.md.
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
contractgate Ready Ready Preview Nov 26, 2026 7:29pm UTC

Request Review

@nightmoose
nightmoose merged commit e3080ba into staging Nov 26, 2026
26 checks passed

This branch was successfully deployed

1 active deployment
Preview — 40e57f95 Deployed Nov 26, 2026 by vercel[bot]
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