Skip to content

JSON Schemas for every JSON output, checked in the tests and in CI (#467, 1/2) - #528

Open
leftibot wants to merge 4 commits into
cpp-best-practices:mainfrom
leftibot:ui-json-schemas
Open

leftibot wants to merge 4 commits into
cpp-best-practices:mainfrom
leftibot:ui-json-schemas

Conversation

@leftibot

@leftibot leftibot commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #533 — merge after it; until then this diff includes its commits (and those of the PRs below it).

Part of #467: section 4.1 of the interface review, JSON Schemas for the JSON outputs. The accessibility items follow in the PR stacked on this one. Sections 1, 4.2–4.8, 5.2, 5.4 and 6 are still open; they wait for #521 and #523.

What changes

  • Schemas. project_validator/schemas/<format>.schema.json (Draft 2020-12) for each entry of JSON_FORMATS: results, facts, answers, map, checks, support-matrix and project-reports. Each schema is whole in its one file. The statuses, tiers, loss causes and answers are enums, and a test checks those enums against the code's own (Status, score tiers, losses.CAUSES, Answer, project_reports.KINDS/SIZES). The schemas ship in the wheel through package-data.
  • Tests (tests/test_output_schemas.py, part of the existing suite, so it runs in every CI test job):
    • every tests/snapshots/*.json is checked part by part against the definition it holds (answers, about, results, facts, map); registry.json is skipped because it is no output;
    • fresh outputs of five fixtures are checked, plus --list, --support-matrix and a --compare run;
    • a wrong enum value or an unknown field is refused;
    • each schema's SHA-256 is pinned beside its format's version, so a schema can change only with its version.
  • CI (new schemas job in ci.yml):
    • check-jsonschema validates a fresh example of each output;
    • Sentry's json-schema-diff (the Rust crate, cargo install --version 0.1.8 --locked) diffs each schema against the base branch's copy and fails on a breaking change when the format's version did not move.
  • data/latest.json (project reports) is the one output that changes. It is now wrapped in the {format, version, ...} envelope (project-reports, version 1), and its score's version is score_version, apart from the format's version. site.py, its README and the tests that read it are updated. Nothing else in the repository reads it.
  • Docs. README Stability, docs/architecture.md, project_reports/README.md, docs/ecosystems/json_schema.md (Sentry's crate counts as json-schema-diff), and one sentence added to the CHANGELOG's JSON formats bullet.

Self-check

The schema files make this repository a JSON Schema project, so the strict self-check now judges schema-validation, schema-examples and schema-compatibility. All three pass, through the new CI job:

  • check-jsonschema covers validation and the examples;
  • json-schema-diff covers compatibility.

The npm json-schema-diff is no help here. It refuses Draft 2020-12 (no schema with key or ref ".../draft/2020-12/schema"). With $schema removed it reports "No differences found" even when an enum in $defs loses a value. Sentry's crate caught both test cases: an enum losing a value, and a change made only inside $defs. It does not follow allOf refs, so the schemas inline their shared fields rather than compose them with allOf.

The JSON Schema profile now tells the two tools apart, as the maintainer decided:

  • A job that installs it with cargo install, cargo binstall or taiki-e/install-action (tool: json-schema-diff) runs json-schema-diff (Rust).
  • Anything else runs the npm package: npx, npm, package.json, or no install step at all.
  • On a project with a Draft 2019-09 or 2020-12 schema, the npm package's run is inert ("the npm json-schema-diff cannot read Draft 2020-12 or 2019-09 schemas …") and earns no schema-compatibility credit.
  • Tests in tests/test_json_schema.py use real CI lines, this repository's own included.
  • I also excluded 2019-09: the npm package can't read that dialect either.

Decisions and open points

  • Decided by the maintainer: jsonschema (with types-jsonschema) stays a test-only dependency; both CI tools stay; format versions stay at "1" until the stable-IDs PR.
  • Format versions stay at "1" even though the review notes that shapes changed after 1. Bumping them is an output change this PR does not make.
  • A finding the schemas exposed: in --facts, a fact type with its own kind field (TestFile, FuzzTarget, documents, suppressions) overwrites the type name in kind, for example "kind": "test blocks in .zig files". The schema allows any string. Fixing it changes the output, so it belongs with the stable-ID work (4.2).

Existing tests changed

  • tests/test_project_reports.py: three tests that read latest.json now read it inside the envelope (["project-reports"]); the empty case expects the envelope instead of [].
  • tests/checks/test_schema_compatibility.py test_json_schemas_are_diffed_against_the_base: npx json-schema-diff on the layout's Draft 2020-12 schema is no longer credited (the maintainer's decision). The test now expects that WARN with its reason, and a PASS for the Rust crate.
  • The well-configured JSON Schema and Data fixtures (Draft 2020-12 schemas) now cargo install and run the crate. Their snapshots change, plus bare_json_schema.json (its hint lists the crate first) and registry.json (the new tool).

Checks

  • gates2.sh: all steps pass (ruff, ruff format, mypy, lizard, the unittest suite under branch coverage at 99%, jscpd 0 clones, markdownlint, strict self-check)
  • Corpus (cJSON, CycloneDX/specification): the scores are unchanged (CycloneDX has schemas but no compatibility tool).
  • CI: npm audit failed because the branch predates Update cross-spawn to 7.1.2 (GHSA-ghv9-86vm-4v8m) #529, so the lockfile now pins cross-spawn 7.1.2. The macOS jobs were never picked up by a runner ("not acquired … capacity constraints").

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.96907% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.45%. Comparing base (b31abd3) to head (abf689b).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
project_validator/facts/tools.py 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
- Coverage   99.45%   99.45%   -0.01%     
==========================================
  Files         382      383       +1     
  Lines       28683    28766      +83     
  Branches     3666     3680      +14     
==========================================
+ Hits        28528    28610      +82     
- Misses        155      156       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leftibot
leftibot force-pushed the ui-json-schemas branch 2 times, most recently from 72a41b6 to 580fbb6 Compare December 1, 2026 22:23
leftibot and others added 4 commits December 1, 2026 18:20
`cargo clippy -- -D warnings -A warnings` earned warnings-as-errors and
`-W clippy::pedantic -A clippy::pedantic` earned clippy::pedantic,
though clippy reads the last level a lint is given.

- facts.tools.undone: the words of a command that set what a later word
  sets otherwise, and why, by policy/inert_commands.toml's
  `later_flag_wins`: lint levels for clippy (-A/-W/-D, --allow/--warn/
  --deny, also after `--` and as `-Dwarnings`), and dart/flutter
  analyze's --fatal-infos/--no-fatal-infos and --fatal-warnings pairs.
- ci_texts leaves the undone words out; advisory_texts holds the whole
  command, and practices.not_enforced gives why, so the requirement only
  the undone flag meets is "in place but not enforced": "-D warnings runs
  in CI but cannot fail it (-A warnings, later on its line, undoes -D
  warnings)". `dart analyze --no-fatal-infos --fatal-infos` stays fatal.
- Rust's clippy::pedantic requirement no longer matches
  `-A clippy::pedantic`, which allows the lints.
- MSBuild's RunAnalyzers or EnableNETAnalyzers false, or AnalysisMode
  None (inert_commands.toml `msbuild_analyzers_off`), in every C#
  project or a Directory.Build.props above it, make the analyzer runs
  inert by settings: "CI runs Roslynator, but its settings leave it
  nothing to check". NoWarn lists stay per rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
Conditions are kept for the whole process. When the unbounded curl loop
test runs first, as in mutmut's clean run, which orders tests by
duration, the bounded reading builds no new nodes and never reaches the
lowered bound, so mutmut failed on cpp-best-practices#533. The bounded reading now gets
fresh CURL_USE_ names, and the test first reads the plain fixture to
hold that in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…pp-best-practices#467)

A Draft 2020-12 schema per format of JSON_FORMATS in project_validator/schemas, each whole in its file, with enums
for the statuses, tiers, loss causes and answers. tests/test_output_schemas.py validates every snapshot and fresh
outputs against them, checks the enums are the code's own and pins each schema's digest beside its format's version.

The project reports' data/latest.json joins the formats: it is wrapped in the {format, version, ...} envelope
(project-reports, version 1) and its score's version is score_version.

CI's schemas job validates fresh outputs with check-jsonschema and diffs each schema against the base branch's with
Sentry's json-schema-diff, failing a breaking change whose format version did not move. jsonschema is a test
dependency only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…cpp-best-practices#467)

Two tools are called json-schema-diff. A job that installs it with cargo install, cargo binstall or
taiki-e/install-action runs Sentry's crate, json-schema-diff (Rust), which reads Draft 2020-12; anything else (npx,
npm, package.json, or nothing said) runs the npm package. On a project with a Draft 2019-09 or 2020-12 schema the npm
package stops at the dialect, so its run is inert: it earns no schema-compatibility credit.

The well-configured JSON Schema and Data fixtures (Draft 2020-12 schemas) now install and run the crate; their
snapshots, bare_json_schema's hint and registry.json follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

This branch has not been deployed

No deployments
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