REAL-WORLD-SCHEMAS-12: First cross-document check: dangling depends_on
What it demonstrates
Section titled “What it demonstrates”A docRule that flags a task whose depends_on names an id no task defines.
Builds on: REAL-WORLD-SCHEMAS-10: Corpus config: route two types, first match wins
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, docRule, runCorpus } from "markdown-contract";const task = contract({ frontmatter: z.object({ id: z.string(), depends_on: z.array(z.string()).default([]) }).strict(), body: sections({ allowUnknown: true }, [section("Goal")]), rules: [ docRule("task/depends-resolve", (doc, ctx) => doc.frontmatter.depends_on.filter(d => !KNOWN_IDS.has(d)).map(d => ctx.finding({ id: "task/depends-resolve", level: "error", message: `unknown dependency ${d}` }))) ],});await runCorpus({ rules: [{ include: ["docs/planning/tasks/**/*.md"], contract: task }] }, { cwd: "." });Surfaces exercised
Section titled “Surfaces exercised”contract({ rules }); docRule(id, (doc, ctx)) reading typed doc.frontmatterrunCorpus aggregating findings + exitCode (aggregation not yet fully tested — T-DRAG)