Skip to content

Add JSON contract and snapshot matching#278

Merged
JE-Chen merged 2 commits into
devfrom
feat/json-contract
Jun 21, 2026
Merged

Add JSON contract and snapshot matching#278
JE-Chen merged 2 commits into
devfrom
feat/json-contract

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

json_schema validates a value against an authored schema and jsonpath extracts values, but nothing matched two JSON payloads with relaxed rules or diffed them path-by-path for contract / snapshot tests. This adds that layer (composes with json_schema + json_patch).

  • match_json(actual, expected, *, ignore, match_type, partial)MatchReport(ok, mismatches); each mismatch is {path, kind} (missing/extra/changed). partial = subset match, match_type = Pact-style like (types must match), ignore = skip volatile paths.
  • diff_json(actual, expected) — raw path-tagged diff.
  • normalize_json(value, *, drop) — canonical copy (sorted keys, dropped keys).
  • snapshot(actual, path) — golden-master (write-if-absent, else compare).

true stays distinct from 1. Pure stdlib (json), deterministic.

Five-layer wiring

  • Headless core: je_auto_control/utils/json_contract/
  • Facade: re-exported from __init__.py + __all__
  • Executor: AC_match_json, AC_diff_json
  • MCP: ac_match_json, ac_diff_json
  • Script Builder: "JSON Contract: Match" / "JSON Contract: Diff" under Data

Tests & docs

  • test/unit_test/headless/test_json_contract_batch.py (14 tests: changed/missing/extra, partial, match_type, ignore, nested path, snapshot)
  • v70 feature docs (EN + Zh) + toctree
  • What's-new in all three READMEs

Lint clean: ruff / pylint / bandit / radon.

json_schema validates against an authored schema and jsonpath extracts,
but nothing matched two JSON payloads with relaxed rules or diffed them
path-by-path for contract/snapshot tests. Add match_json (partial,
match_type, ignore), diff_json (path-tagged missing/extra/changed),
normalize_json and golden-master snapshot. Composes with json_schema and
json_patch. Wired through the facade, AC_match_json/AC_diff_json executor
commands, MCP tools and the Script Builder.
@codacy-production

codacy-production Bot commented Jun 21, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 57 complexity · 0 duplication

Metric Results
Complexity 57
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit 96364bd into dev Jun 21, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/json-contract branch June 21, 2026 01:42
@sonarqubecloud

Copy link
Copy Markdown

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