VALIDATION-PLANES-02: The smallest contract: one required section
What it demonstrates
Section titled “What it demonstrates”contract({body: sections([section(…)])}).validate(src) emits a single structure-plane Finding for a missing section.
Builds on: VALIDATION-PLANES-01: Parse markdown into a DocTree
How it’s done
Section titled “How it’s done”A TypeScript program against the library API; inline comments show the resulting values and behavior.
import { contract, sections, section } from "markdown-contract";
const c = contract({ body: sections({}, [section("Summary")]) });const { findings } = c.validate("## Overview\n", { path: "doc.md" });// findings[0] = { id: "structure/section-missing", level: "error",// path: "doc.md", message: "required section 'Summary' is missing" }Surfaces exercised
Section titled “Surfaces exercised”contract() / sections() / section() (src/core/grammar.ts)Contract.validate() (src/core/validate.ts)structure/section-missing (src/core/structure.ts)Finding {id, level, path, message} (src/core/finding.ts)