feat(contract): add API schema drift detection#401
feat(contract): add API schema drift detection#401sorlen008 wants to merge 2 commits intojackwener:mainfrom
Conversation
UAT Results (Windows 11)
All 5 tests pass. No bugs found — clean implementation. |
|
Good callout @Astro-Han — just looked at #338. The two approaches are complementary:
They solve different sides of the same problem. #338 is the alarm bell, #401 is the diagnostic tool. Happy to defer to the maintainer on which to land first, or both if they see value in the combo. |
c0fe73b to
0619fc5
Compare
0619fc5 to
e7cb24f
Compare
Add contract testing module that captures JSON response schemas, compares them against saved baselines, and reports structural drift (fields added, removed, or type-changed). New CLI subcommands: - `opencli contract snapshot <site> <command>` — save baseline schema - `opencli contract check <site> <command>` — diff against baseline - `opencli contract list` — list saved contracts Schema storage at ~/.opencli/contracts/<site>/<command>.json. Includes 25 unit tests covering schema capture, diffing, formatting, and end-to-end drift detection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e7cb24f to
29b070a
Compare
|
One functional gap I noticed in the CLI wiring: A lot of commands in this repo rely on positional args and valueless booleans from That means |
Closes #50
What this adds
A
contractsubcommand that detects when upstream APIs change their response shape — the #1 cause of silent adapter breakage.Commands
opencli contract snapshot <site> <command> [args...]— run a command and save its response schema as a baselineopencli contract check <site> <command> [args...]— run the command again and diff against the baselineopencli contract list— list all saved baselinesHow it works
+), removed (-), type changed (~). Recurses into nested objects and array items. Paths use dot notation (data.items[].slug).~/.opencli/contracts/<site>/<command>.jsoncheckexits with code 1 if drift is detected, making it CI-friendly.Example
Files
src/contract.ts(new) — schema capture, diff engine, storage, formattingsrc/contract.test.ts(new) — 25 unit tests covering all core functionssrc/cli.ts— wired upcontractsubcommand groupTesting
npx tsc --noEmit— zero type errorsnpm test— all 25 new tests pass. 3 pre-existing failures unrelated.