feat(contract): add API schema drift detection#401
Open
sorlen008 wants to merge 1 commit intojackwener:mainfrom
Open
feat(contract): add API schema drift detection#401sorlen008 wants to merge 1 commit intojackwener:mainfrom
sorlen008 wants to merge 1 commit intojackwener:mainfrom
Conversation
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>
Contributor
Author
UAT Results (Windows 11)
All 5 tests pass. No bugs found — clean implementation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.