Skip to content

feat(cli): apic check, verify live responses against contracts - #108

Merged
rizukirr merged 4 commits into
mainfrom
feat/apic-check
Nov 14, 2026
Merged

rizukirr merged 4 commits into
mainfrom
feat/apic-check

Conversation

@rizukirr

Copy link
Copy Markdown
Owner

Adds apic check, which sends contracts' requests and compares the live responses with the documented ones. It's meant for agent loops and CI.

apic check [-f QUERY] [--env NAME] [--var NAME=VALUE]... [--status CODE] [--unsafe] [--timeout SECS] [--json]

Behaviour

  • Targets resolve like validate: no -f checks every contract, dir/ checks a folder, and any other query checks one contract.
  • The live status must be documented, and must equal --status when given. The reply passes if it matches any documented response with that status.
  • Body shape is inferred from the example: example keys must exist with the same JSON type, extra keys are fine, and null on either side matches. Arrays are compared against the first example element. Only types are compared, never values.
  • Headers marked required must be present, in any case.
  • Folder and whole-project runs send only GET, HEAD and OPTIONS unless --unsafe is given. A single contract is always sent.
  • Exit 5 (new kind mismatch) if any contract mismatched, otherwise 4 network, 3 invalid, 1 other error, and 0 when every contract passed or was skipped. A single contract that can't be checked prints the usual error document, as send does.
  • --json prints {"results": [{"path", "method", "result", "code", "elapsed_ms", "differences", "reason", "error"}], "passed", "mismatched", "skipped", "failed"}.

validate and check now share target resolution through query_targets. The output of validate is unchanged: I checked an empty folder, a missing folder, a folder with failures and a whole-project run against main.

Tests

  • 10 unit tests for the comparator and candidate matching.
  • 7 CLI tests: pass, type mismatch exit 5, undocumented status, --status, folder run with and without --unsafe, network exit 4, and the text summary.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test all pass.

Known limitation

A HEAD contract whose response has a body example always mismatches, because HEAD replies carry no body.

Docs: COMMAND.md. The apic-web mirror is a separate PR.

@rizukirr
rizukirr merged commit f2d5c55 into main Nov 14, 2026
5 checks passed
@rizukirr
rizukirr deleted the feat/apic-check branch November 17, 2026 04:07
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