Skip to content

feat(frontmatter-validator): [#2280] generate v1 schema and verify drift - #2325

Merged
josecelano merged 48 commits into
torrust:developfrom
josecelano:2280-frontmatter-schema-drift
Sep 24, 2026
Merged

josecelano merged 48 commits into
torrust:developfrom
josecelano:2280-frontmatter-schema-drift

Conversation

@josecelano

@josecelano josecelano commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Closes #2280. Parent EPIC: #2264.

Summary

Generates a JSON Schema Draft 2020-12 projection of the canonical strict v1 frontmatter model (issue and EPIC profiles) directly from the frontmatter-validator Rust types with schemars, tracks the artifact at docs/schemas/frontmatter-v1.schema.json, and adds a frontmatter-schema binary with deterministic offline generate and check (drift) commands. The schema is a derived compatibility artifact; the Rust validator remains the source of truth and its remaining Rust-only invariants are documented in docs/schemas/README.md.

After the core delivery, three maintainer-approved post-implementation refactor plans were executed in this branch, each item as its own signed commit (history intentionally not squashed):

  • Schema command plan (13 items): TempDir-owned tests, exit code 2 for usage errors per the CLI output ADR, pure Command::parse, library-owned artifact encoding, typed Error, atomic same-directory artifact replacement with an explicit symlink policy, closed ArtifactOrigin, shell-safe regeneration hints, writer-injected process reporting.
  • Profile validation plan (10 items): module-owned tests, closed StrictProfileKind, one shared validation sequence with explicit diagnostic precedence, aggregate-owned invariants, definition-owned structural checks, unified Diagnostic::new, shared schema regex constants.
  • Crate layout plan (6 items): crate-owned test fixtures (moved out of the archived Inventory and Resolve Markdown Frontmatter Contracts #2265 folder), diagnostic.rs, Frontmatter::has_double_quoted_scalar replacing a raw-YAML seam, syntax.rs pairing each schema regex with its authoritative predicate, single typed reference-validation path, top-down ordering of profile.rs.

Two pre-PR review findings were fixed in-branch: reference-syntax diagnostics again name the failing semantic-links.<field> (required by the #2266 diagnostic contract for #2281), and the schema's required arrays now include the contract's nullable-but-required fields (epic, github-issue, related-pr, epic-owner), generated from the validator's own field list via a schemars transform so presence has one source and nullability is preserved. The AC5 options considered and the reason #[schemars(required)] was rejected are recorded in the spec.

Files and packages touched

  • contrib/dev-tools/checks/frontmatter-validator/ — src/lib.rs, src/diagnostic.rs, src/syntax.rs, src/profile.rs, src/bin/frontmatter-schema.rs, Cargo.toml, fixtures/ (7 Markdown fixtures + manifest, moved from docs/issues/closed/2265-.../frontmatter-fixtures/)
  • docs/schemas/frontmatter-v1.schema.json (generated), docs/schemas/README.md
  • docs/index.md (schema guide row)
  • docs/issues/open/2280-2264-generate-v1-schema-and-verify-drift/ — spec, three refactor plans with test-design reviews, manual evidence, review reports
  • docs/issues/closed/2265-2264-inventory-markdown-frontmatter-contracts/ISSUE.md (fixture relocation note)
  • Cargo.lock (schemars = "=1.2.1"; pinned because registry 1.2.2 requires an unpublished schemars_derive)

Validation

  • cargo test --package frontmatter-validator: 45 library + 24 binary tests.
  • cargo run --offline --package frontmatter-validator --bin frontmatter-schema -- check: tracked artifact byte-identical to generator output; two independent regenerations produce the same SHA-256.
  • cargo clippy --package frontmatter-validator --all-targets -- -D warnings, cargo +nightly fmt --all -- --check, cargo machete --with-metadata, linter all, repository pre-commit and pre-push gates: all pass on every commit.
  • Every refactor item and correction has a prose-first Arrange-Act-Assert record and a mutation proof in the issue-local test-design reviews; the generated schema stayed byte-identical through all 29 refactor-plan items and changed only in the AC5 fix.
  • Manual scenarios M1-M3 plus an invalid-action case re-run against the final branch (V3 in manual-verification-evidence.md): regeneration idempotent, drift exits 1, unknown action exits 2, stdout empty throughout.
  • Two independent Task Reviewer passes on 2026-09-23 are recorded in agent-review-reports.md; all blockers resolved.
  • No temporary local-only patches were used for verification.

Out of scope (owned by follow-ups)

CLI file discovery, --staged/whole-tree modes, NDJSON diagnostics, structured field_path, and pre-commit integration remain #2281. Excluding the crate's fixtures/ directory from future whole-tree validation and migrating the five specs that use status: open are noted for #2281. Expressing "present but non-null" semantic-link sequences in the schema would require a public model change and is left to #2264.

Copilot AI lite review requested due to automatic review settings September 23, 2026 17:29
@josecelano josecelano self-assigned this Sep 23, 2026

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review effort: Lite
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds a generated JSON Schema (Draft 2020-12) for the strict v1 frontmatter model and introduces a deterministic, offline CLI to generate and drift-check the tracked schema artifact.

Changes:

  • Track the generated v1 schema artifact at docs/schemas/frontmatter-v1.schema.json and document regeneration + schema/Rust boundary.
  • Implement frontmatter-schema binary with generate and check actions, deterministic encoding, drift detection, and CLI-exit-code mapping.
  • Refactor frontmatter-validator crate layout (diagnostics/syntax/profile separation), relocate fixtures into the crate, and add/adjust tests and issue evidence docs.
File Description
docs/​schemas/​frontmatter-v1.schema.json Adds the tracked generated Draft 2020-12 schema artifact for strict v1 profiles.
docs/​schemas/​README.md Documents schema regeneration/check commands and Rust-only invariants not expressed in JSON Schema.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​test-design-review.md Records AAA test design and mutation evidence for schema generation/drift behaviors.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​schema-command-refactor-plan.md Captures the refactor plan and rationale for the schema CLI command implementation/testing.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​profile-test-design-review.md Records test design for strict profile validation refactors and invariants.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​profile-refactor-plan.md Documents refactor sequencing for profile validation ownership/structure.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​manual-verification-evidence.md Provides manual offline regeneration and drift verification evidence.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​crate-layout-test-design-review.md Records test design for crate layout changes (fixtures/diagnostics/syntax seams).
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​crate-layout-refactor-plan.md Documents the crate layout plan and rationale (module boundaries and ownership).
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​agent-review-reports.md Stores independent review reports and acceptance-criteria verification notes.
docs/​issues/​open/​2280-2264-generate-v1-schema-and-verify-drift/​ISSUE.md Updates the #2280 issue spec/status + AC5 decision notes and progress log.
docs/​issues/​closed/​2265-2264-inventory-markdown-frontmatter-contracts/​frontmatter-fixtures/​manifest.md Updates fixture manifest text to reflect relocation rationale/exclusion policy.
docs/​issues/​closed/​2265-2264-inventory-markdown-frontmatter-contracts/​ISSUE.md Notes fixture relocation under #2280 to avoid archived-doc dependency for tests.
docs/​index.md Adds a docs index row pointing to the schemas guide.
contrib/​dev-tools/​checks/​frontmatter-validator/​src/​syntax.rs Introduces frozen v1 syntax predicates + paired schema regex constants and tests.
contrib/​dev-tools/​checks/​frontmatter-validator/​src/​profile.rs Adds schema generation/encoding, strict profile validation refactors, required-field transform, and tests.
contrib/​dev-tools/​checks/​frontmatter-validator/​src/​lib.rs Splits modules, re-exports diagnostics/schema APIs, adds scalar-style query, updates extraction errors.
contrib/​dev-tools/​checks/​frontmatter-validator/​src/​diagnostic.rs Moves diagnostic vocabulary into a dedicated module with unified constructor.
contrib/​dev-tools/​checks/​frontmatter-validator/​src/​bin/​frontmatter-schema.rs Implements the deterministic schema artifact generator/drift checker CLI with tests.
contrib/​dev-tools/​checks/​frontmatter-validator/​Cargo.toml Adds/pins schema + CLI dependencies (schemars, serde_json, tempfile, thiserror).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@josecelano

Copy link
Copy Markdown
Member Author

ACK 6011a86

@josecelano
josecelano merged commit 9c621af into torrust:develop Sep 24, 2026
20 checks passed

This branch was previously deployed

1 inactive deployment
coverage — 6011a86f Deployed Sep 24, 2026 by josecelano via Generate Coverage Report #2300
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.

feat(frontmatter): generate v1 schema and verify drift

2 participants