Skip to content

feat: validate reports against their schema before rendering - #42

Merged
katodea merged 4 commits into
trunkfrom
add/ajv
Sep 23, 2026
Merged

katodea merged 4 commits into
trunkfrom
add/ajv

Conversation

@katodea

@katodea katodea commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

what

  • package.json, package-lock.json — new root manifest; ajv is the only dependency
  • scripts/validate-report.js
    • validate() checks a report against schemas/qa-report-<type>-schema.json in ajv strict mode, but only when that file declares $schema: shop and aeo today. functional, performance and accessibility are still example documents and pass through with a note
    • typesFor() is the flagged types plus whatever the content shows (mode: "aeo", a shop block), so a missing or wrong flag can't skip the check
    • checkReport() prints one line per mismatch, then Fix these fields in <file>, then re-run. and Nothing was rendered.
  • scripts/generate-report.js
    • validates before rendering; a refusal sets process.exitCode and returns
    • --skip-validation renders without the check, for archived reports whose shape predates their schema
    • the "missing mode" error no longer says "pass --aeo to force", which hit the same error
  • scripts/run-qa-report.sh
    • no longer validates on its own; the renderer does
    • step 2 reads websiteName and timestamp with JSON.parse instead of splitting raw text, so a missing field or compact JSON no longer crashes it
    • with no flag, mode: "aeo" resolves to --aeo, so the stamp and the filename label get it too
  • schemas/qa-report-aeo-schema.json — "type": "object" on the eight criterionSignalPairing branches so the schema compiles in strict mode. no change to what it accepts
  • tests/validate-report.test.js, tests/generate-report.test.js — strict-mode compile of each schema, format edge cases, refuse and pass through both the wrapper and the renderer, the no-ajv and broken-schema paths, shop and aeo detected from content, the 64 KB cut-off, the --aeo message
  • .github/workflows/ci.yml — npm ci before node --test
  • docs updated to reflect these changes

why

the skills lean on long "did I…?" checklists to get the report JSON right, and nothing enforces them. the files in schemas/ described the shape, but nothing ever read them: shop and aeo were real JSON Schema that no run had ever been checked against, and an opus 5 performance run invented a top-level summary key that the renderer silently ignored.

now a report has to match its schema to render. when it doesn't, the model gets the exact field:

/issues/low/0/category must be equal to one of the allowed values: Catalog, Product, Cart, Checkout, Store

and fixes the JSON. that's the feedback loop the checklists were pretending to be, and it's the first step of the skills refactor: once the schema is the gate, the rewrites can drop the checklists.

the check lives in the renderer, not the wrapper, because every render goes through generate-report.js: run-qa-report.sh, the merge, and a direct call. the first version only validated in run-qa-report.sh, while CLAUDE.md (loaded in every kosh session) documents the renderer-only command, so a refused model had a documented way around it. skipping the check is now an explicit, named flag.

npm ci rather than npm install, because npm install can rewrite the committed lockfile (under a different npm version, say), and a modified package-lock.json blocks the user's next git pull.

notes

  • run-qa-report.sh and merge-qa-reports.sh still paste file paths into single-quoted JS strings (18 places, 17 of them pre-existing), so a path containing ' fails. it fails on trunk too, as a misleading "Invalid JSON". a follow-up fixes all of them together with the merge script's matching split() parsing

co-authored by claude opus 5.5 🛂

@katodea katodea self-assigned this Sep 23, 2026
@t51eng-poseidon

Copy link
Copy Markdown

🔱 Poseidon started reviewing this PR — central run.

@t51eng-poseidon t51eng-poseidon Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔱 Poseidon Review

Summary — Adds ajv schema validation to the report renderer (gated on schemas that declare $schema, i.e. shop and aeo) so a non-matching report is refused on every render path; low risk, and the change is unusually well covered by tests. No issues found on this pass.

I verified the parts most likely to break: the date-time validator correctly rejects Feb 30, non-leap Feb 29, and hour 24 while accepting leap-year and offset forms; the uri validator rejects surrounding whitespace and relative paths; the top-level return (rather than process.exit) on validation failure lets a long refusal drain to a pipe; provenance is modeled in the shop schema so stamping-before-validation doesn't itself fail the check; and the set -e wrapper exits on a refused report with the ajv errors already flushed to stderr.


ℹ️ Review info
  • Commit: 88d6dc7
  • Files reviewed: .github/workflows/ci.yml, CLAUDE.md, README.md, docs/getting-started.md, hooks/hooks.json, schemas/qa-report-aeo-schema.json, scripts/generate-report.js, scripts/run-qa-report.sh, scripts/validate-report.js, tests/generate-report.test.js, tests/validate-report.test.js
  • Files skipped: package.json, package-lock.json (dependency manifest / lockfile — ajv ^8.20.0 only)
  • Model: claude-opus-4-8

@katodea
katodea merged commit 97b950d into trunk Sep 23, 2026
3 checks passed
@katodea
katodea deleted the add/ajv branch September 23, 2026 18:21
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