Skip to content

feat(cli): v0.4.1 CLI polish — fail-on, stats counts, coverage gate, JSON schemas#177

Merged
avrabe merged 4 commits intomainfrom
feat/v041-cli-polish
Apr 22, 2026
Merged

feat(cli): v0.4.1 CLI polish — fail-on, stats counts, coverage gate, JSON schemas#177
avrabe merged 4 commits intomainfrom
feat/v041-cli-polish

Conversation

@avrabe
Copy link
Copy Markdown
Contributor

@avrabe avrabe commented Apr 22, 2026

Summary

Four small CLI polish items, one commit each:

  1. rivet validate --fail-on <severity> — exit 1 when any diagnostic at or above the given severity is emitted. Defaults to error (current behavior); --fail-on warning lets a project tighten its gate over time without having to promote every warning in the schema.
  2. rivet stats --format json includes diagnostic counts — new fields errors, warnings, infos (same as rivet validate --format json). Removes the need for consumers to make two calls just to build a dashboard or CI summary. Existing fields unchanged — additive only.
  3. rivet coverage --fail-under gate polish — flag already existed; hardened JSON output (new threshold: { fail_under, passed } block, added "command": "coverage" envelope), cleaner text output on pass, and dedicated CI-gate tests.
  4. JSON schemas for --format json outputs — ships draft-2020-12 JSON Schemas under schemas/json/ for validate, stats, coverage, list. Two new commands: rivet schema list-json enumerates them and rivet schema get-json <name> prints the path (or content with --content). Schemas are hand-written; rivet has no schemars dependency today and pulling it in for four small hand-maintained schemas wasn't worth the transitive cost.

New fields added to JSON output

  • stats: errors, warnings, infos
  • coverage: command: "coverage", threshold: { fail_under, passed } (only when --fail-under set)

Schemars vs hand-written

schemars was not available in the workspace (grep of every Cargo.toml returned zero hits). The four schemas are hand-written.

Test plan

  • cargo clippy -p rivet-cli --all-targets -- -D warnings — clean
  • cargo test -p rivet-cli --test cli_commands — 50/50 pass (13 new tests added across the 4 commits)
  • New tests cover: --fail-on (three cases), stats diagnostic counts match validate, coverage --fail-under three cases, JSON schema self-consistency (shipped files are valid JSON, every required field is emitted by the CLI)

Commits

  • 00e1a77 feat(cli): add --fail-on flag to validate
  • aef9d8c feat(cli): include errors/warnings/infos in stats JSON output
  • 35ff164 feat(cli): polish coverage --fail-under gate
  • a284339 feat(cli): publish JSON schemas for --format json outputs

🤖 Generated with Claude Code

avrabe and others added 4 commits April 22, 2026 00:27
New flag on `rivet validate`: --fail-on error (default, current
behavior), --fail-on warning, --fail-on info. Exit code 1 when any
diagnostic at or above the given severity is emitted. Lets CI tighten
the traceability gate over time without forcing every warning to be
promoted in the schema.

Tests cover all three outcomes: default --fail-on error on a
warning-only project exits 0, --fail-on warning on the same project
exits 1, and an invalid value is rejected with a clear error message.

Implements: REQ-007

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`rivet stats --format json` now exposes the same severity breakdown
as `rivet validate --format json` (new fields: errors, warnings,
infos). Removes the need for consumers to make a second validate
call just to get diagnostic counts when rendering a dashboard or
CI summary. Existing fields (total, types, orphans, broken_links)
are unchanged — additive only, backward-compatible.

The text output gains a trailing "Diagnostics: N error(s), ..."
summary line so the human-readable form agrees with JSON.

Tests: one asserting the new fields are present and numeric; a
cross-command test asserting stats and validate agree on the
counts for the current project.

Implements: REQ-007

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The --fail-under flag already gated exit code on overall coverage.
This commit hardens and documents the CI-gate use case:

- JSON output echoes a new `threshold: { fail_under, passed }`
  block when the flag is set, so consumers can distinguish a clean
  run from a gated failure without parsing stderr.
- Text output prints a "✔ coverage N.N% meets threshold M.M%" line
  on success to match the existing failure message.
- JSON output now carries `"command": "coverage"` for consistency
  with the rest of the --format json envelopes.

Tests: --fail-under 0 passes, --fail-under 101 fails, no flag is
report-only, and JSON carries the threshold echo.

Implements: REQ-007

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds draft-2020-12 JSON Schemas describing every `--format json` CLI
output so downstream consumers can validate against a machine-readable
contract instead of reverse-engineering field layouts:

  schemas/json/validate-output.schema.json
  schemas/json/stats-output.schema.json
  schemas/json/coverage-output.schema.json
  schemas/json/list-output.schema.json

Schemas are hand-written (rivet has no `schemars` dependency today —
grep of workspace Cargo.toml files returned zero hits — and pulling
it in just for four small schemas is heavier than the schemas
themselves).

Two new subcommands under `rivet schema` surface the schemas:

  rivet schema list-json          # enumerate shipped schemas + paths
  rivet schema get-json <name>    # print path for one
  rivet schema get-json <name> --content   # print schema content

Tests cover:
- every shipped schema file is valid JSON with required metadata
- `schema list-json --format json` lists all four, all files exist
- `schema get-json <name>` round-trips path-and-content for all four
- an unknown name is rejected with a helpful error
- the actual `rivet validate` / `rivet stats` JSON output contains
  every `required` field declared in the corresponding schema — so
  future field drift fails CI instead of silently breaking consumers

Implements: REQ-007

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@avrabe avrabe force-pushed the feat/v041-cli-polish branch from a284339 to 88c7f37 Compare April 22, 2026 05:27
@avrabe avrabe merged commit f46fb62 into main Apr 22, 2026
1 check passed
@avrabe avrabe deleted the feat/v041-cli-polish branch April 22, 2026 05:32
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rivet Criterion Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 88c7f37 Previous: a24c1b9 Ratio
store_lookup/1000 24926 ns/iter (± 80) 19264 ns/iter (± 61) 1.29
diff/1000 719897 ns/iter (± 15853) 593193 ns/iter (± 3478) 1.21
diff/10000 10557718 ns/iter (± 424327) 7940709 ns/iter (± 870929) 1.33
query/1000 6834 ns/iter (± 16) 5527 ns/iter (± 12) 1.24

This comment was automatically generated by workflow using github-action-benchmark.

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