@warlock.js/grimoire 5.57.0 → 5.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/esm/apps/check-apps.mjs +11 -5
  3. package/esm/apps/check-apps.mjs.map +1 -1
  4. package/esm/book/build.d.mts.map +1 -1
  5. package/esm/book/build.mjs +2 -1
  6. package/esm/book/build.mjs.map +1 -1
  7. package/esm/book/render.mjs +10 -0
  8. package/esm/book/render.mjs.map +1 -1
  9. package/esm/bookmap/build.d.mts.map +1 -1
  10. package/esm/bookmap/build.mjs +7 -5
  11. package/esm/bookmap/build.mjs.map +1 -1
  12. package/esm/bookmap/steps.mjs +85 -39
  13. package/esm/bookmap/steps.mjs.map +1 -1
  14. package/esm/check/check-grimoire.d.mts.map +1 -1
  15. package/esm/check/check-grimoire.mjs +4 -1
  16. package/esm/check/check-grimoire.mjs.map +1 -1
  17. package/esm/check/rules/criteria.mjs +21 -2
  18. package/esm/check/rules/criteria.mjs.map +1 -1
  19. package/esm/check/rules/screenshots.mjs +57 -0
  20. package/esm/check/rules/screenshots.mjs.map +1 -0
  21. package/esm/codes/codes.d.mts +12 -0
  22. package/esm/codes/codes.d.mts.map +1 -1
  23. package/esm/codes/codes.mjs +6 -0
  24. package/esm/codes/codes.mjs.map +1 -1
  25. package/esm/contracts/adapter.d.mts +28 -1
  26. package/esm/contracts/adapter.d.mts.map +1 -1
  27. package/esm/contracts/book.d.mts +2 -0
  28. package/esm/contracts/book.d.mts.map +1 -1
  29. package/esm/contracts/book.mjs.map +1 -1
  30. package/esm/contracts/bookmap.d.mts +19 -1
  31. package/esm/contracts/bookmap.d.mts.map +1 -1
  32. package/esm/contracts/scry.d.mts +26 -6
  33. package/esm/contracts/scry.d.mts.map +1 -1
  34. package/esm/contracts/snapshot.d.mts +14 -1
  35. package/esm/contracts/snapshot.d.mts.map +1 -1
  36. package/esm/contracts/test-results.d.mts +34 -0
  37. package/esm/contracts/test-results.d.mts.map +1 -1
  38. package/esm/contracts/written.d.mts +44 -0
  39. package/esm/contracts/written.d.mts.map +1 -1
  40. package/esm/contracts/written.mjs.map +1 -1
  41. package/esm/devtools/data.mjs +116 -5
  42. package/esm/devtools/data.mjs.map +1 -1
  43. package/esm/devtools/feature-map.mjs +149 -0
  44. package/esm/devtools/feature-map.mjs.map +1 -0
  45. package/esm/devtools/index.d.mts +28 -2
  46. package/esm/devtools/index.d.mts.map +1 -1
  47. package/esm/devtools/index.mjs +111 -7
  48. package/esm/devtools/index.mjs.map +1 -1
  49. package/esm/devtools/product-map.d.mts +14 -0
  50. package/esm/devtools/product-map.d.mts.map +1 -0
  51. package/esm/devtools/product-map.mjs +460 -0
  52. package/esm/devtools/product-map.mjs.map +1 -0
  53. package/esm/devtools/site.d.mts +43 -1
  54. package/esm/devtools/site.d.mts.map +1 -1
  55. package/esm/devtools/site.mjs +190 -22
  56. package/esm/devtools/site.mjs.map +1 -1
  57. package/esm/devtools/snapshot-source.mjs +24 -7
  58. package/esm/devtools/snapshot-source.mjs.map +1 -1
  59. package/esm/graph/index.d.mts +10 -1
  60. package/esm/graph/index.d.mts.map +1 -1
  61. package/esm/graph/index.mjs +3 -2
  62. package/esm/graph/index.mjs.map +1 -1
  63. package/esm/index.d.mts +5 -5
  64. package/esm/ownership/index.d.mts.map +1 -1
  65. package/esm/ownership/index.mjs +60 -1
  66. package/esm/ownership/index.mjs.map +1 -1
  67. package/esm/paths/index.d.mts +2 -0
  68. package/esm/paths/index.d.mts.map +1 -1
  69. package/esm/paths/index.mjs +3 -1
  70. package/esm/paths/index.mjs.map +1 -1
  71. package/esm/scry/compact.mjs +170 -0
  72. package/esm/scry/compact.mjs.map +1 -0
  73. package/esm/scry/format.d.mts.map +1 -1
  74. package/esm/scry/format.mjs +19 -2
  75. package/esm/scry/format.mjs.map +1 -1
  76. package/esm/scry/query.d.mts.map +1 -1
  77. package/esm/scry/query.mjs +159 -24
  78. package/esm/scry/query.mjs.map +1 -1
  79. package/esm/test-results/index.d.mts +7 -2
  80. package/esm/test-results/index.d.mts.map +1 -1
  81. package/esm/test-results/index.mjs +79 -12
  82. package/esm/test-results/index.mjs.map +1 -1
  83. package/esm/vitest/index.d.mts +6 -0
  84. package/esm/vitest/index.d.mts.map +1 -1
  85. package/esm/vitest/index.mjs +22 -6
  86. package/esm/vitest/index.mjs.map +1 -1
  87. package/esm/warlock/actions.mjs +15 -7
  88. package/esm/warlock/actions.mjs.map +1 -1
  89. package/esm/warlock/adapter.d.mts.map +1 -1
  90. package/esm/warlock/adapter.mjs +42 -4
  91. package/esm/warlock/adapter.mjs.map +1 -1
  92. package/esm/warlock/commands.mjs +7 -2
  93. package/esm/warlock/commands.mjs.map +1 -1
  94. package/esm/warlock/logo.mjs +12 -0
  95. package/esm/warlock/logo.mjs.map +1 -0
  96. package/esm/warlock/mcp-tools.mjs +51 -15
  97. package/esm/warlock/mcp-tools.mjs.map +1 -1
  98. package/esm/workspace/cache.mjs +194 -0
  99. package/esm/workspace/cache.mjs.map +1 -0
  100. package/esm/workspace/index.d.mts.map +1 -1
  101. package/esm/workspace/index.mjs +7 -3
  102. package/esm/workspace/index.mjs.map +1 -1
  103. package/esm/written/apps.mjs +4 -2
  104. package/esm/written/apps.mjs.map +1 -1
  105. package/esm/written/features.mjs +119 -6
  106. package/esm/written/features.mjs.map +1 -1
  107. package/esm/written/markdown.mjs +66 -1
  108. package/esm/written/markdown.mjs.map +1 -1
  109. package/esm/written/parse-grimoire.d.mts.map +1 -1
  110. package/esm/written/parse-grimoire.mjs +1 -1
  111. package/esm/written/parse-grimoire.mjs.map +1 -1
  112. package/llms-full.txt +108 -12
  113. package/package.json +3 -3
  114. package/skills/backfill-a-grimoire/SKILL.md +5 -0
  115. package/skills/describe-an-app/SKILL.md +12 -0
  116. package/skills/record-a-change/SKILL.md +10 -0
  117. package/skills/use-the-grimoire/SKILL.md +44 -10
  118. package/skills/write-a-feature/SKILL.md +37 -2
  119. package/ui/grimoire-static.js +61 -6
  120. package/ui/grimoire-view.js +2133 -316
  121. package/ui/grimoire.css +1030 -24
  122. package/ui/product-map.css +785 -0
  123. package/ui/product-map.js +1265 -0
@@ -1 +1 @@
1
- {"version":3,"file":"build.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/bookmap/build.ts"],"sourcesContent":["/**\n * Builds the book maps and the collected indexes in memory. Pure: reads only\n * its input.\n */\nimport type { BookFacts, BookFile } from \"../contracts/adapter\";\nimport { BOOK_SCHEMA_VERSION, type BookAnnotations, type BookManifest } from \"../contracts/book\";\nimport type {\n CollectedFiles,\n FeatureBookmap,\n FeaturesIndex,\n FlowBookmap,\n FlowBookmapCriterion,\n Ownership,\n TaskSummary,\n TasksIndex,\n} from \"../contracts/bookmap\";\nimport type { AppMatch } from \"../contracts/snapshot\";\nimport type { ProofLine, ProofResult, TestResultsStore } from \"../contracts/test-results\";\nimport type {\n WrittenFeature,\n WrittenFlow,\n WrittenGrimoire,\n WrittenTask,\n} from \"../contracts/written\";\nimport { fileGraph } from \"../graph\";\nimport { toPosixPath } from \"../paths\";\nimport { criterionStatus } from \"../test-results\";\nimport { resolveStep, type StepContext } from \"./steps\";\n\n/** Everything the book maps are computed from. */\nexport type CollectedInput = {\n written: WrittenGrimoire;\n facts: BookFacts;\n ownership: Ownership;\n apps: Record<string, AppMatch>;\n proofs: ProofLine[];\n results: TestResultsStore | null;\n /** Test file → current sha256 (a result with another hash is stale). */\n testHashes: Record<string, string>;\n};\n\n/** The file name of a flow without `.md`: the name of its book map. */\nexport function flowFileId(flow: WrittenFlow): string {\n const name = toPosixPath(flow.file).split(\"/\").pop() ?? flow.id.value;\n\n return name.endsWith(\".md\") ? name.slice(0, -3) : name;\n}\n\n// ── Flow book maps ─────────────────────────────────────────────────────────\n\n/**\n * The result recorded for the test a proof line points at: same file and\n * line, else (the test moved) same name among the results whose line no\n * proof of that file claims.\n */\nfunction resultFor(\n proof: ProofLine,\n line: number,\n results: readonly ProofResult[],\n claimedLines: ReadonlySet<string>,\n): ProofResult | null {\n const file = toPosixPath(proof.at.file);\n const sameProof = (result: ProofResult): boolean =>\n result.feature === proof.feature &&\n result.flow === proof.flow &&\n result.criterion === proof.criterion;\n const inFile = results.filter((result) => toPosixPath(result.testFile) === file);\n const atLine = inFile.filter((result) => result.line === line);\n const byLine = atLine.find(sameProof) ?? atLine[0];\n\n if (byLine) return byLine;\n\n const name = proof.test?.name ?? null;\n\n if (name === null) return null;\n\n const named = inFile.filter(\n (result) =>\n !claimedLines.has(`${file}:${result.line}`) &&\n (result.testName === name || result.testName.endsWith(` > ${name}`)),\n );\n\n return named.find(sameProof) ?? named[0] ?? null;\n}\n\nfunction flowCriteria(flow: WrittenFlow, input: CollectedInput): FlowBookmapCriterion[] {\n const results = input.results?.results ?? [];\n const claimedLines = new Set(\n input.proofs.flatMap((proof) =>\n proof.test === null ? [] : [`${toPosixPath(proof.at.file)}:${proof.test.line}`],\n ),\n );\n\n return flow.criteria.map((criterion) => {\n const tests = input.proofs\n .filter(\n (proof) =>\n proof.ref === flow.ref && proof.criterion === criterion.id && proof.test !== null,\n )\n .map((proof) => {\n const line = proof.test?.line ?? proof.at.line;\n const file = toPosixPath(proof.at.file);\n const result = resultFor(proof, line, results, claimedLines);\n const currentHash = input.testHashes[file];\n const stale =\n result !== null && currentHash !== undefined && result.testFileHash !== currentHash;\n\n return {\n file,\n line,\n name: proof.test?.name ?? null,\n result: result?.outcome ?? (\"not-run\" as const),\n stale,\n };\n })\n .sort((left, right) => left.file.localeCompare(right.file) || left.line - right.line);\n\n return {\n id: criterion.id,\n app: criterion.app,\n text: criterion.text,\n tests,\n status: criterionStatus(tests),\n };\n });\n}\n\nfunction shownBy(flow: WrittenFlow, written: WrittenGrimoire): FlowBookmap[\"shownBy\"] {\n const shown: FlowBookmap[\"shownBy\"] = [];\n\n for (const app of written.apps) {\n const appId = app.id.value;\n\n for (const layout of app.layouts) {\n for (const row of layout.blocks) {\n if (row.flow === flow.ref) {\n shown.push({\n app: appId,\n type: \"layout\",\n id: layout.id,\n block: row.block,\n file: layout.file,\n });\n }\n }\n }\n\n for (const page of [...app.pages, ...app.screens]) {\n for (const row of page.blocks) {\n if (row.flow === flow.ref) {\n shown.push({\n app: appId,\n type: page.type,\n id: page.id,\n block: row.block,\n file: page.file,\n });\n }\n }\n }\n }\n\n return shown;\n}\n\nfunction flowBookmap(\n feature: WrittenFeature,\n flow: WrittenFlow,\n input: CollectedInput,\n context: StepContext,\n): FlowBookmap {\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n feature: feature.id,\n flow: flowFileId(flow),\n ref: flow.ref,\n steps: flow.steps.map((step) => resolveStep(step, feature, context)),\n criteria: flowCriteria(flow, input),\n shownBy: shownBy(flow, input.written),\n };\n}\n\n// ── Feature book maps ──────────────────────────────────────────────────────\n\nfunction featureBookmap(\n feature: WrittenFeature,\n flows: readonly FlowBookmap[],\n input: CollectedInput,\n byPath: ReadonlyMap<string, BookFile>,\n): FeatureBookmap {\n const { ownership, facts } = input;\n const own = ownership.features[feature.id]?.own ?? [];\n const ownSet = new Set(own);\n\n // Own files importing each file, from one pass over the own files' imports (`own` is sorted, so each list is too).\n const importersOf = new Map<string, string[]>();\n\n for (const ownFile of own) {\n for (const entry of byPath.get(ownFile)?.imports ?? []) {\n if (entry.file === null) continue;\n\n const list = importersOf.get(entry.file) ?? [];\n\n if (list.at(-1) !== ownFile) list.push(ownFile);\n importersOf.set(entry.file, list);\n }\n }\n\n const borrowed: FeatureBookmap[\"borrowed\"] = (ownership.features[feature.id]?.borrowed ?? []).map(\n (file) => ({\n file,\n owner: ownership.files[file]?.owner ?? null,\n by: importersOf.get(file) ?? [],\n }),\n );\n\n const routes: FeatureBookmap[\"routes\"] = [];\n\n for (const route of facts.routes ?? []) {\n if (route.isPage) continue;\n\n const file =\n route.handlerFile !== null && ownSet.has(route.handlerFile)\n ? route.handlerFile\n : route.sourceFile !== null && ownSet.has(route.sourceFile)\n ? route.sourceFile\n : null;\n\n if (file !== null)\n routes.push({ method: route.method, path: route.path, name: route.name, file });\n }\n\n const pages: FeatureBookmap[\"pages\"] = {};\n const add = (app: string, item: FeatureBookmap[\"pages\"][string][number]): void => {\n (pages[app] ??= []).push(item);\n };\n const appOfSite = new Map<string, string>();\n const appOfMobile = new Map<string, string>();\n\n for (const match of Object.values(input.apps)) {\n if (match.site && !appOfSite.has(match.site.id)) appOfSite.set(match.site.id, match.app);\n if (match.mobile && !appOfMobile.has(match.mobile.id))\n appOfMobile.set(match.mobile.id, match.app);\n }\n\n for (const page of facts.pages) {\n const owned = ownSet.has(page.file) || (page.setupFile !== null && ownSet.has(page.setupFile));\n\n if (owned)\n add(appOfSite.get(page.site) ?? page.site, {\n route: page.route,\n file: page.file,\n type: \"page\",\n });\n }\n\n for (const mobile of facts.mobile) {\n for (const screen of mobile.screens) {\n if (ownSet.has(screen.file)) {\n add(appOfMobile.get(mobile.id) ?? mobile.id, {\n route: screen.route,\n file: screen.file,\n type: \"screen\",\n });\n }\n }\n }\n\n const sortedPages: FeatureBookmap[\"pages\"] = {};\n\n for (const app of Object.keys(pages).sort()) {\n sortedPages[app] = (pages[app] ?? []).sort(\n (left, right) => left.route.localeCompare(right.route) || left.file.localeCompare(right.file),\n );\n }\n\n const reached = new Set(flows.flatMap((flow) => flow.steps.flatMap((step) => step.files)));\n\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n feature: feature.id,\n own,\n borrowed,\n routes,\n pages: sortedPages,\n unreached: own.filter((file) => !reached.has(file)),\n };\n}\n\n// ── Indexes ────────────────────────────────────────────────────────────────\n\nfunction compareVersions(left: string, right: string): number {\n const [leftWhole = 0, leftDecimal = 0] = left.split(\".\").map(Number);\n const [rightWhole = 0, rightDecimal = 0] = right.split(\".\").map(Number);\n\n return leftWhole - rightWhole || leftDecimal - rightDecimal;\n}\n\nfunction featuresIndex(written: WrittenGrimoire): FeaturesIndex {\n const features: FeaturesIndex[\"features\"] = [];\n\n for (const feature of [...written.features].sort((left, right) =>\n left.id.localeCompare(right.id),\n )) {\n const readme = feature.readme;\n\n if (readme === null) continue;\n\n const releases = new Map<string, { version: string; release: string; date: string }>();\n\n for (const entry of feature.changelog?.entries ?? []) {\n if (entry.release === null || entry.date === null) continue;\n\n const version = entry.version.value;\n const known = releases.get(version);\n\n if (!known || entry.date > known.date) {\n releases.set(version, { version, release: entry.release, date: entry.date });\n }\n }\n\n features.push({\n id: feature.id,\n title: readme.title.value,\n status: readme.status.value,\n version: readme.version.value,\n updated: readme.updated.value,\n apps: readme.apps.map((app) => app.value),\n origin: readme.origin?.value ?? null,\n flows: feature.flows.map((flow) => ({\n id: flow.id.value,\n status: flow.status.value,\n since: flow.since.value,\n })),\n releases: [...releases.values()].sort(\n (left, right) =>\n right.date.localeCompare(left.date) || compareVersions(right.version, left.version),\n ),\n });\n }\n\n return { schemaVersion: BOOK_SCHEMA_VERSION, features };\n}\n\nfunction taskNumber(id: string): number {\n const match = /^T-(\\d+)$/.exec(id);\n\n return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;\n}\n\nfunction taskSummary(task: WrittenTask): TaskSummary {\n return {\n id: task.id.value,\n title: task.heading?.value ?? task.id.value,\n type: task.type.value,\n status: task.status.value,\n feature: task.feature?.value ?? null,\n flow: task.flow?.value ?? null,\n apps: task.apps.map((app) => app.value),\n file: task.file,\n shipped: task.shipped\n ? { feature: task.shipped.value.feature, version: task.shipped.value.version }\n : null,\n decisionNeeded: task.decisionNeeded,\n };\n}\n\nfunction tasksIndex(written: WrittenGrimoire): TasksIndex {\n const sorted = [...written.tasks].sort(\n (left, right) =>\n taskNumber(left.id.value) - taskNumber(right.id.value) ||\n left.id.value.localeCompare(right.id.value),\n );\n const open = sorted.filter((task) => task.folder === \"open\").map(taskSummary);\n\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n open,\n waiting: open.filter(\n (task) => task.status === \"waiting for approval\" || task.decisionNeeded !== null,\n ),\n done: sorted.filter((task) => task.folder === \"done\").map(taskSummary),\n };\n}\n\n// ── Public ─────────────────────────────────────────────────────────────────\n\n/** Every feature and flow book map, `features/index.json` and `tasks/index.json`. Pure. */\nexport function buildCollectedFiles(input: CollectedInput): CollectedFiles {\n const context: StepContext = {\n written: input.written,\n facts: input.facts,\n apps: input.apps,\n graph: fileGraph(input.facts.files),\n };\n const byPath = new Map(input.facts.files.map((file) => [file.file, file]));\n const features: CollectedFiles[\"features\"] = {};\n const flows: CollectedFiles[\"flows\"] = {};\n\n for (const feature of [...input.written.features].sort((left, right) =>\n left.id.localeCompare(right.id),\n )) {\n const maps = feature.flows.map((flow) => flowBookmap(feature, flow, input, context));\n\n for (const map of maps) flows[map.ref] = map;\n\n features[feature.id] = featureBookmap(feature, maps, input, byPath);\n }\n\n return {\n features,\n flows,\n featuresIndex: featuresIndex(input.written),\n tasksIndex: tasksIndex(input.written),\n };\n}\n\n/** The per-file owner, borrowers and flows the book entries show. Pure. */\nexport function annotationsFrom(\n input: CollectedInput,\n collected: CollectedFiles,\n manifest: Pick<BookManifest, \"tests\">,\n): BookAnnotations {\n const flowsOf = new Map<string, Set<string>>();\n\n for (const map of Object.values(collected.flows)) {\n for (const step of map.steps) {\n for (const file of step.files) {\n const set = flowsOf.get(file) ?? new Set<string>();\n set.add(map.ref);\n flowsOf.set(file, set);\n }\n }\n }\n\n const files: BookAnnotations[\"files\"] = {};\n\n for (const file of input.facts.files) {\n const ownership = input.ownership.files[file.file];\n\n files[file.file] = {\n feature: ownership?.owner ?? null,\n borrowedBy: [...(ownership?.borrowedBy ?? [])],\n flows: [...(flowsOf.get(file.file) ?? [])].sort(),\n };\n }\n\n return { writtenHash: input.written.hash, tests: { ...manifest.tests }, files };\n}\n"],"mappings":";;;;;;;;;AA0CA,SAAgB,WAAW,MAA2B;CACpD,MAAM,OAAO,YAAY,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK,KAAK,GAAG;CAEhE,OAAO,KAAK,SAAS,KAAK,IAAI,KAAK,MAAM,GAAG,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[],"sources":["../../../../../../../../packages/grimoire/src/bookmap/build.ts"],"sourcesContent":["/**\n * Builds the book maps and the collected indexes in memory. Pure: reads only\n * its input.\n */\nimport type { BookFacts, BookFile } from \"../contracts/adapter\";\nimport { BOOK_SCHEMA_VERSION, type BookAnnotations, type BookManifest } from \"../contracts/book\";\nimport type {\n CollectedFiles,\n FeatureBookmap,\n FeaturesIndex,\n FlowBookmap,\n FlowBookmapCriterion,\n Ownership,\n TaskSummary,\n TasksIndex,\n} from \"../contracts/bookmap\";\nimport type { AppMatch } from \"../contracts/snapshot\";\nimport type { ProofLine, ProofResult, TestResultsStore } from \"../contracts/test-results\";\nimport type {\n WrittenFeature,\n WrittenFlow,\n WrittenGrimoire,\n WrittenTask,\n} from \"../contracts/written\";\nimport { fileGraph } from \"../graph\";\nimport { isExemptFromReach, specOnlyFiles } from \"../ownership\";\nimport { toPosixPath } from \"../paths\";\nimport { criterionStatus } from \"../test-results\";\nimport { resolveStep, type StepContext } from \"./steps\";\n\n/** Everything the book maps are computed from. */\nexport type CollectedInput = {\n written: WrittenGrimoire;\n facts: BookFacts;\n ownership: Ownership;\n apps: Record<string, AppMatch>;\n proofs: ProofLine[];\n results: TestResultsStore | null;\n /** Test file → current sha256 (a result with another hash is stale). */\n testHashes: Record<string, string>;\n};\n\n/** The file name of a flow without `.md`: the name of its book map. */\nexport function flowFileId(flow: WrittenFlow): string {\n const name = toPosixPath(flow.file).split(\"/\").pop() ?? flow.id.value;\n\n return name.endsWith(\".md\") ? name.slice(0, -3) : name;\n}\n\n// ── Flow book maps ─────────────────────────────────────────────────────────\n\n/**\n * The result recorded for the test a proof line points at: same file and\n * line, else (the test moved) same name among the results whose line no\n * proof of that file claims.\n */\nfunction resultFor(\n proof: ProofLine,\n line: number,\n results: readonly ProofResult[],\n claimedLines: ReadonlySet<string>,\n): ProofResult | null {\n const file = toPosixPath(proof.at.file);\n const sameProof = (result: ProofResult): boolean =>\n result.feature === proof.feature &&\n result.flow === proof.flow &&\n result.criterion === proof.criterion;\n const inFile = results.filter((result) => toPosixPath(result.testFile) === file);\n const atLine = inFile.filter((result) => result.line === line);\n const byLine = atLine.find(sameProof) ?? atLine[0];\n\n if (byLine) return byLine;\n\n const name = proof.test?.name ?? null;\n\n if (name === null) return null;\n\n const named = inFile.filter(\n (result) =>\n !claimedLines.has(`${file}:${result.line}`) &&\n (result.testName === name || result.testName.endsWith(` > ${name}`)),\n );\n\n return named.find(sameProof) ?? named[0] ?? null;\n}\n\nfunction flowCriteria(flow: WrittenFlow, input: CollectedInput): FlowBookmapCriterion[] {\n const results = input.results?.results ?? [];\n const claimedLines = new Set(\n input.proofs.flatMap((proof) =>\n proof.test === null ? [] : [`${toPosixPath(proof.at.file)}:${proof.test.line}`],\n ),\n );\n\n return flow.criteria.map((criterion) => {\n const tests = input.proofs\n .filter(\n (proof) =>\n proof.ref === flow.ref && proof.criterion === criterion.id && proof.test !== null,\n )\n .map((proof) => {\n const line = proof.test?.line ?? proof.at.line;\n const file = toPosixPath(proof.at.file);\n const result = resultFor(proof, line, results, claimedLines);\n const currentHash = input.testHashes[file];\n const stale =\n result !== null && currentHash !== undefined && result.testFileHash !== currentHash;\n\n return {\n file,\n line,\n name: proof.test?.name ?? null,\n result: result?.outcome ?? (\"not-run\" as const),\n stale,\n };\n })\n .sort((left, right) => left.file.localeCompare(right.file) || left.line - right.line);\n\n return {\n id: criterion.id,\n app: criterion.app,\n text: criterion.text,\n tests,\n status: criterionStatus(tests),\n };\n });\n}\n\nfunction shownBy(flow: WrittenFlow, written: WrittenGrimoire): FlowBookmap[\"shownBy\"] {\n const shown: FlowBookmap[\"shownBy\"] = [];\n\n for (const app of written.apps) {\n const appId = app.id.value;\n\n for (const layout of app.layouts) {\n for (const row of layout.blocks) {\n if (row.flow === flow.ref) {\n shown.push({\n app: appId,\n type: \"layout\",\n id: layout.id,\n block: row.block,\n file: layout.file,\n });\n }\n }\n }\n\n for (const page of [...app.pages, ...app.screens]) {\n for (const row of page.blocks) {\n if (row.flow === flow.ref) {\n shown.push({\n app: appId,\n type: page.type,\n id: page.id,\n block: row.block,\n file: page.file,\n });\n }\n }\n }\n }\n\n return shown;\n}\n\nfunction flowBookmap(\n feature: WrittenFeature,\n flow: WrittenFlow,\n input: CollectedInput,\n context: StepContext,\n): FlowBookmap {\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n feature: feature.id,\n flow: flowFileId(flow),\n ref: flow.ref,\n steps: flow.steps.map((step) => resolveStep(step, feature, context)),\n criteria: flowCriteria(flow, input),\n shownBy: shownBy(flow, input.written),\n };\n}\n\n// ── Feature book maps ──────────────────────────────────────────────────────\n\nfunction featureBookmap(\n feature: WrittenFeature,\n flows: readonly FlowBookmap[],\n input: CollectedInput,\n byPath: ReadonlyMap<string, BookFile>,\n specOnly: ReadonlySet<string>,\n): FeatureBookmap {\n const { ownership, facts } = input;\n const own = ownership.features[feature.id]?.own ?? [];\n const ownSet = new Set(own);\n\n // Own files importing each file, from one pass over the own files' imports (`own` is sorted, so each list is too).\n const importersOf = new Map<string, string[]>();\n\n for (const ownFile of own) {\n for (const entry of byPath.get(ownFile)?.imports ?? []) {\n if (entry.file === null) continue;\n\n const list = importersOf.get(entry.file) ?? [];\n\n if (list.at(-1) !== ownFile) list.push(ownFile);\n importersOf.set(entry.file, list);\n }\n }\n\n const borrowed: FeatureBookmap[\"borrowed\"] = (ownership.features[feature.id]?.borrowed ?? []).map(\n (file) => ({\n file,\n owner: ownership.files[file]?.owner ?? null,\n by: importersOf.get(file) ?? [],\n }),\n );\n\n const routes: FeatureBookmap[\"routes\"] = [];\n\n for (const route of facts.routes ?? []) {\n if (route.isPage) continue;\n\n const file =\n route.handlerFile !== null && ownSet.has(route.handlerFile)\n ? route.handlerFile\n : route.sourceFile !== null && ownSet.has(route.sourceFile)\n ? route.sourceFile\n : null;\n\n if (file !== null)\n routes.push({ method: route.method, path: route.path, name: route.name, file });\n }\n\n const pages: FeatureBookmap[\"pages\"] = {};\n const add = (app: string, item: FeatureBookmap[\"pages\"][string][number]): void => {\n (pages[app] ??= []).push(item);\n };\n const appOfSite = new Map<string, string>();\n const appOfMobile = new Map<string, string>();\n\n for (const match of Object.values(input.apps)) {\n if (match.site && !appOfSite.has(match.site.id)) appOfSite.set(match.site.id, match.app);\n if (match.mobile && !appOfMobile.has(match.mobile.id))\n appOfMobile.set(match.mobile.id, match.app);\n }\n\n for (const page of facts.pages) {\n const owned = ownSet.has(page.file) || (page.setupFile !== null && ownSet.has(page.setupFile));\n\n if (owned)\n add(appOfSite.get(page.site) ?? page.site, {\n route: page.route,\n file: page.file,\n type: \"page\",\n });\n }\n\n for (const mobile of facts.mobile) {\n for (const screen of mobile.screens) {\n if (ownSet.has(screen.file)) {\n add(appOfMobile.get(mobile.id) ?? mobile.id, {\n route: screen.route,\n file: screen.file,\n type: \"screen\",\n });\n }\n }\n }\n\n const sortedPages: FeatureBookmap[\"pages\"] = {};\n\n for (const app of Object.keys(pages).sort()) {\n sortedPages[app] = (pages[app] ?? []).sort(\n (left, right) => left.route.localeCompare(right.route) || left.file.localeCompare(right.file),\n );\n }\n\n // Ownership coverage (GR3006) counts type-only reach too.\n const reached = new Set(\n flows.flatMap((flow) => flow.steps.flatMap((step) => [...step.files, ...step.typeOnlyFiles])),\n );\n\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n feature: feature.id,\n own,\n borrowed,\n routes,\n pages: sortedPages,\n unreached: own.filter(\n (file) =>\n !reached.has(file) &&\n !specOnly.has(file) &&\n !isExemptFromReach(byPath.get(file) ?? { type: \"source\" }),\n ),\n };\n}\n\n// ── Indexes ────────────────────────────────────────────────────────────────\n\nfunction compareVersions(left: string, right: string): number {\n const [leftWhole = 0, leftDecimal = 0] = left.split(\".\").map(Number);\n const [rightWhole = 0, rightDecimal = 0] = right.split(\".\").map(Number);\n\n return leftWhole - rightWhole || leftDecimal - rightDecimal;\n}\n\nfunction featuresIndex(written: WrittenGrimoire): FeaturesIndex {\n const features: FeaturesIndex[\"features\"] = [];\n\n for (const feature of [...written.features].sort((left, right) =>\n left.id.localeCompare(right.id),\n )) {\n const readme = feature.readme;\n\n if (readme === null) continue;\n\n const releases = new Map<string, { version: string; release: string; date: string }>();\n\n for (const entry of feature.changelog?.entries ?? []) {\n if (entry.release === null || entry.date === null) continue;\n\n const version = entry.version.value;\n const known = releases.get(version);\n\n if (!known || entry.date > known.date) {\n releases.set(version, { version, release: entry.release, date: entry.date });\n }\n }\n\n features.push({\n id: feature.id,\n title: readme.title.value,\n status: readme.status.value,\n version: readme.version.value,\n updated: readme.updated.value,\n apps: readme.apps.map((app) => app.value),\n origin: readme.origin?.value ?? null,\n flows: feature.flows.map((flow) => ({\n id: flow.id.value,\n status: flow.status.value,\n since: flow.since.value,\n })),\n releases: [...releases.values()].sort(\n (left, right) =>\n right.date.localeCompare(left.date) || compareVersions(right.version, left.version),\n ),\n });\n }\n\n return { schemaVersion: BOOK_SCHEMA_VERSION, features };\n}\n\nfunction taskNumber(id: string): number {\n const match = /^T-(\\d+)$/.exec(id);\n\n return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;\n}\n\nfunction taskSummary(task: WrittenTask): TaskSummary {\n return {\n id: task.id.value,\n title: task.heading?.value ?? task.id.value,\n type: task.type.value,\n status: task.status.value,\n feature: task.feature?.value ?? null,\n flow: task.flow?.value ?? null,\n apps: task.apps.map((app) => app.value),\n file: task.file,\n shipped: task.shipped\n ? { feature: task.shipped.value.feature, version: task.shipped.value.version }\n : null,\n decisionNeeded: task.decisionNeeded,\n };\n}\n\nfunction tasksIndex(written: WrittenGrimoire): TasksIndex {\n const sorted = [...written.tasks].sort(\n (left, right) =>\n taskNumber(left.id.value) - taskNumber(right.id.value) ||\n left.id.value.localeCompare(right.id.value),\n );\n const open = sorted.filter((task) => task.folder === \"open\").map(taskSummary);\n\n return {\n schemaVersion: BOOK_SCHEMA_VERSION,\n open,\n waiting: open.filter(\n (task) => task.status === \"waiting for approval\" || task.decisionNeeded !== null,\n ),\n done: sorted.filter((task) => task.folder === \"done\").map(taskSummary),\n };\n}\n\n// ── Public ─────────────────────────────────────────────────────────────────\n\n/** Every feature and flow book map, `features/index.json` and `tasks/index.json`. Pure. */\nexport function buildCollectedFiles(input: CollectedInput): CollectedFiles {\n const context: StepContext = {\n written: input.written,\n facts: input.facts,\n apps: input.apps,\n graph: fileGraph(input.facts.files),\n };\n const byPath = new Map(input.facts.files.map((file) => [file.file, file]));\n const specOnly = specOnlyFiles(input.facts.files);\n const features: CollectedFiles[\"features\"] = {};\n const flows: CollectedFiles[\"flows\"] = {};\n\n for (const feature of [...input.written.features].sort((left, right) =>\n left.id.localeCompare(right.id),\n )) {\n const maps = feature.flows.map((flow) => flowBookmap(feature, flow, input, context));\n\n for (const map of maps) flows[map.ref] = map;\n\n features[feature.id] = featureBookmap(feature, maps, input, byPath, specOnly);\n }\n\n return {\n features,\n flows,\n featuresIndex: featuresIndex(input.written),\n tasksIndex: tasksIndex(input.written),\n };\n}\n\n/** The per-file owner, borrowers and flows the book entries show. Pure. */\nexport function annotationsFrom(\n input: CollectedInput,\n collected: CollectedFiles,\n manifest: Pick<BookManifest, \"tests\">,\n): BookAnnotations {\n const flowsOf = new Map<string, Set<string>>();\n\n for (const map of Object.values(collected.flows)) {\n for (const step of map.steps) {\n for (const file of [...step.files, ...step.typeOnlyFiles]) {\n const set = flowsOf.get(file) ?? new Set<string>();\n set.add(map.ref);\n flowsOf.set(file, set);\n }\n }\n }\n\n const files: BookAnnotations[\"files\"] = {};\n\n for (const file of input.facts.files) {\n const ownership = input.ownership.files[file.file];\n\n files[file.file] = {\n feature: ownership?.owner ?? null,\n borrowedBy: [...(ownership?.borrowedBy ?? [])],\n flows: [...(flowsOf.get(file.file) ?? [])].sort(),\n };\n }\n\n return { writtenHash: input.written.hash, tests: { ...manifest.tests }, files };\n}\n"],"mappings":";;;;;;;;;;AA2CA,SAAgB,WAAW,MAA2B;CACpD,MAAM,OAAO,YAAY,KAAK,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,I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AK,QAAQ;GACjB,SAAS,WAAW,SAAS;GAC7B,YAAY,CAAC,GAAI,WAAW,cAAc,CAAC,CAAE;GAC7C,OAAO,CAAC,GAAI,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,CAAE,CAAC,CAAC,KAAK;EAClD;CACF;CAEA,OAAO;EAAE,aAAa,MAAM,QAAQ;EAAM,OAAO,EAAE,GAAG,SAAS,MAAM;EAAG;CAAM;AAChF"}
@@ -29,33 +29,90 @@ function sortedUnique(files) {
29
29
  const NOTHING = {
30
30
  found: false,
31
31
  entry: null,
32
- files: []
32
+ entries: [],
33
+ direct: [],
34
+ files: [],
35
+ typeOnlyFiles: []
33
36
  };
34
- function routeStep(step, facts, graph) {
35
- if (facts.routes === null || step.route === null) return {
36
- found: null,
37
- entry: null,
38
- files: []
37
+ const UNKNOWN = {
38
+ ...NOTHING,
39
+ found: null
40
+ };
41
+ /**
42
+ * Work out a step's files from its entry files. `extra` are files that belong
43
+ * to the step without being imported by an entry (a route's routes file).
44
+ */
45
+ function reach(graph, entries, extra = []) {
46
+ const entryFiles = sortedUnique(entries);
47
+ const known = new Set(entryFiles);
48
+ const direct = /* @__PURE__ */ new Set();
49
+ for (const entry of entryFiles) for (const edge of graph.get(entry)?.imports ?? []) if (edge.file !== null && !known.has(edge.file)) direct.add(edge.file);
50
+ const files = /* @__PURE__ */ new Set([
51
+ ...entryFiles,
52
+ ...extra,
53
+ ...importClosure(graph, entryFiles, { skipTypeOnly: true })
54
+ ]);
55
+ const everything = importClosure(graph, entryFiles);
56
+ return {
57
+ entries: entryFiles,
58
+ direct: sortedUnique(direct),
59
+ files: sortedUnique(files),
60
+ typeOnlyFiles: everything.filter((file) => !files.has(file))
39
61
  };
62
+ }
63
+ /** `auth-only.middleware.ts` → `authOnly` (the camelCase stem without the role suffix). */
64
+ function middlewareNameOf(file) {
65
+ return (file.split("/").pop() ?? file).replace(/\.(?:d\.ts|[cm]?[jt]sx?)$/, "").replace(/\.middleware$/, "").replace(/[-_.]+([a-zA-Z0-9])/g, (_match, letter) => letter.toUpperCase());
66
+ }
67
+ /**
68
+ * The files of the middleware a route names. A name matches a file that exports
69
+ * it, or a `*.middleware.*` file whose stem is the name (`auth-only.middleware.ts` ↔ `authOnly`).
70
+ * When the routes file imports some of the matches, only those count (two
71
+ * modules may name a middleware the same). The routes file's other imports are
72
+ * not followed: it imports every controller of its module.
73
+ */
74
+ function middlewareFiles(names, routesFile, graph) {
75
+ const imported = new Set(routesFile === null ? [] : (graph.get(routesFile)?.imports ?? []).flatMap((edge) => edge.file === null ? [] : [edge.file]));
76
+ const found = [];
77
+ for (const name of names) {
78
+ const matches = [];
79
+ for (const [file, entry] of graph) {
80
+ const exports = entry.exports ?? [];
81
+ const byStem = /\.middleware\.(?:[cm]?[jt]sx?)$/.test(file) && middlewareNameOf(file) === name;
82
+ if (exports.some((item) => item.name === name) || byStem) matches.push(file);
83
+ }
84
+ const near = matches.filter((file) => imported.has(file));
85
+ found.push(...near.length > 0 ? near : matches.length === 1 ? matches : []);
86
+ }
87
+ return found;
88
+ }
89
+ function routeStep(step, facts, graph) {
90
+ if (facts.routes === null || step.route === null) return UNKNOWN;
40
91
  const target = step.route;
41
92
  const routes = facts.routes.filter((route) => routeMatches(route, target.method, target.path));
42
93
  const first = routes[0];
43
94
  if (!first) return NOTHING;
44
- const files = /* @__PURE__ */ new Set();
45
- for (const route of routes) {
46
- if (route.handlerFile !== null) importClosure(graph, [route.handlerFile]).forEach((file) => files.add(file));
47
- if (route.sourceFile !== null) files.add(route.sourceFile);
48
- }
95
+ const handlers = routes.flatMap((route) => route.handlerFile === null ? [] : [route.handlerFile]);
96
+ const sources = routes.flatMap((route) => route.sourceFile === null ? [] : [route.sourceFile]);
97
+ const middleware = routes.flatMap((route) => middlewareFiles(route.middleware, route.sourceFile, graph));
98
+ const handlerReach = reach(graph, [...handlers, ...middleware], sources);
99
+ const entries = sortedUnique([
100
+ ...handlers,
101
+ ...middleware,
102
+ ...sources
103
+ ]);
49
104
  return {
50
105
  found: true,
51
106
  entry: first.handlerFile ?? first.sourceFile,
52
- files: sortedUnique(files)
107
+ ...handlerReach,
108
+ entries,
109
+ direct: handlerReach.direct.filter((file) => !entries.includes(file))
53
110
  };
54
111
  }
55
112
  function pageStep(step, feature, facts, apps, graph) {
56
113
  const wanted = normalizeRoutePath(step.target);
57
- const entries = [];
58
- const files = /* @__PURE__ */ new Set();
114
+ const matched = [];
115
+ const starts = [];
59
116
  const appIds = step.app === null ? feature.readme?.apps.map((app) => app.value) ?? [] : [step.app];
60
117
  for (const appId of appIds) {
61
118
  const match = apps[appId];
@@ -64,51 +121,44 @@ function pageStep(step, feature, facts, apps, graph) {
64
121
  const siteId = match.site.id;
65
122
  for (const page of facts.pages) {
66
123
  if (page.site !== siteId || normalizeRoutePath(page.route) !== wanted) continue;
67
- entries.push(page.file);
68
- const start = page.setupFile === null ? [page.file] : [page.file, page.setupFile];
69
- importClosure(graph, start).forEach((file) => files.add(file));
70
- start.forEach((file) => files.add(file));
124
+ matched.push(page.file);
125
+ starts.push(page.file);
126
+ if (page.setupFile !== null) starts.push(page.setupFile);
71
127
  }
72
128
  }
73
129
  if (match.mobile) for (const screen of match.mobile.screens) {
74
130
  if (normalizeRoutePath(screen.route) !== wanted) continue;
75
- entries.push(screen.file);
76
- importClosure(graph, [screen.file]).forEach((file) => files.add(file));
77
- files.add(screen.file);
131
+ matched.push(screen.file);
132
+ starts.push(screen.file);
78
133
  }
79
134
  }
80
- const entry = entries[0];
135
+ const entry = matched[0];
81
136
  if (entry === void 0) return NOTHING;
82
137
  return {
83
138
  found: true,
84
139
  entry,
85
- files: sortedUnique(files)
140
+ ...reach(graph, starts)
86
141
  };
87
142
  }
88
143
  function namedStep(step, facts, graph) {
89
144
  const named = facts.named.filter((thing) => thing.type === step.type && thing.name === step.target);
90
145
  const first = named[0];
91
- if (!first) return NOTHING;
92
- const files = /* @__PURE__ */ new Set();
93
- for (const thing of named) {
94
- if (thing.file === null) continue;
95
- importClosure(graph, [thing.file]).forEach((file) => files.add(file));
96
- files.add(thing.file);
97
- }
146
+ if (!first) return facts.routes === null ? UNKNOWN : NOTHING;
147
+ const entries = named.flatMap((thing) => thing.file === null ? [] : [thing.file]);
98
148
  return {
99
149
  found: true,
100
150
  entry: first.file,
101
- files: sortedUnique(files)
151
+ ...reach(graph, entries)
102
152
  };
103
153
  }
104
154
  function affectsStep(step, written) {
105
155
  const target = step.affects;
106
156
  if (target === null) return NOTHING;
107
157
  const feature = written.features.find((candidate) => candidate.id === target.feature);
158
+ const found = feature !== void 0 && (target.flow === null || feature.flows.some((flow) => flow.id.value === target.flow));
108
159
  return {
109
- found: feature !== void 0 && (target.flow === null || feature.flows.some((flow) => flow.id.value === target.flow)),
110
- entry: null,
111
- files: []
160
+ ...NOTHING,
161
+ found
112
162
  };
113
163
  }
114
164
  /** One step of a flow of `feature`, with what it matched in the book. */
@@ -118,11 +168,7 @@ function resolveStep(step, feature, context) {
118
168
  else if (step.type === "page") match = pageStep(step, feature, context.facts, context.apps, context.graph);
119
169
  else if (NAMED_TYPES.has(step.type)) match = namedStep(step, context.facts, context.graph);
120
170
  else if (step.type === "affects") match = affectsStep(step, context.written);
121
- else match = {
122
- found: null,
123
- entry: null,
124
- files: []
125
- };
171
+ else match = UNKNOWN;
126
172
  const target = step.app === null ? step.target : `${step.target} [${step.app}]`;
127
173
  return {
128
174
  index: step.index,
@@ -1 +1 @@
1
- {"version":3,"file":"steps.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/bookmap/steps.ts"],"sourcesContent":["/**\n * The files behind each step of a flow: what a route, page, mail, job, event\n * or notification step reaches in the book.\n */\nimport type { BookFacts, BookNamedType } from \"../contracts/adapter\";\nimport type { FlowBookmapStep } from \"../contracts/bookmap\";\nimport type { AppMatch } from \"../contracts/snapshot\";\nimport type { WrittenFeature, WrittenGrimoire, WrittenStep } from \"../contracts/written\";\nimport { importClosure, type FileGraph } from \"../graph\";\n\nconst NAMED_TYPES: ReadonlySet<string> = new Set<BookNamedType>([\n \"mail\",\n \"job\",\n \"event\",\n \"notification\",\n]);\n\n/** A route path with params written one way (`:id` and `[id]` → `:id`) and no trailing `/`. */\nexport function normalizeRoutePath(route: string): string {\n const withParams = route\n .trim()\n .replace(/\\[\\.\\.\\.([^\\]]+)\\]/g, \":$1\")\n .replace(/\\[([^\\]]+)\\]/g, \":$1\");\n const trimmed = withParams.replace(/\\/+$/, \"\");\n\n return trimmed === \"\" ? \"/\" : trimmed;\n}\n\n/**\n * Whether a route answers `METHOD path`: paths compared after\n * `normalizeRoutePath` (`:id` ≡ `[id]`, trailing `/` ignored), methods\n * without regard to case, `ALL` on either side matching any method. The\n * check, the book maps and `scry --route` all match this way.\n */\nexport function routeMatches(\n route: { readonly method: string; readonly path: string },\n method: string,\n path: string,\n): boolean {\n const routeMethod = route.method.toUpperCase();\n const asked = method.toUpperCase();\n const methodMatches = routeMethod === asked || routeMethod === \"ALL\" || asked === \"ALL\";\n\n return methodMatches && normalizeRoutePath(route.path) === normalizeRoutePath(path);\n}\n\nfunction sortedUnique(files: Iterable<string>): string[] {\n return [...new Set(files)].sort();\n}\n\n/** What the step matched: its entry file and the files behind it. */\ntype StepMatch = Pick<FlowBookmapStep, \"found\" | \"entry\" | \"files\">;\n\nconst NOTHING: StepMatch = { found: false, entry: null, files: [] };\n\nfunction routeStep(step: WrittenStep, facts: BookFacts, graph: FileGraph): StepMatch {\n if (facts.routes === null || step.route === null) return { found: null, entry: null, files: [] };\n\n const target = step.route;\n const routes = facts.routes.filter((route) => routeMatches(route, target.method, target.path));\n const first = routes[0];\n\n if (!first) return NOTHING;\n\n const files = new Set<string>();\n\n for (const route of routes) {\n if (route.handlerFile !== null)\n importClosure(graph, [route.handlerFile]).forEach((file) => files.add(file));\n if (route.sourceFile !== null) files.add(route.sourceFile);\n }\n\n return { found: true, entry: first.handlerFile ?? first.sourceFile, files: sortedUnique(files) };\n}\n\nfunction pageStep(\n step: WrittenStep,\n feature: WrittenFeature,\n facts: BookFacts,\n apps: Record<string, AppMatch>,\n graph: FileGraph,\n): StepMatch {\n const wanted = normalizeRoutePath(step.target);\n const entries: string[] = [];\n const files = new Set<string>();\n\n // `page /support [web-admin]` looks in that app only; without a scope, in the feature's apps.\n const appIds =\n step.app === null ? (feature.readme?.apps.map((app) => app.value) ?? []) : [step.app];\n\n for (const appId of appIds) {\n const match = apps[appId];\n\n if (!match) continue;\n\n if (match.site) {\n const siteId = match.site.id;\n\n for (const page of facts.pages) {\n if (page.site !== siteId || normalizeRoutePath(page.route) !== wanted) continue;\n\n entries.push(page.file);\n const start = page.setupFile === null ? [page.file] : [page.file, page.setupFile];\n importClosure(graph, start).forEach((file) => files.add(file));\n start.forEach((file) => files.add(file));\n }\n }\n\n if (match.mobile) {\n for (const screen of match.mobile.screens) {\n if (normalizeRoutePath(screen.route) !== wanted) continue;\n\n entries.push(screen.file);\n importClosure(graph, [screen.file]).forEach((file) => files.add(file));\n files.add(screen.file);\n }\n }\n }\n\n const entry = entries[0];\n\n if (entry === undefined) return NOTHING;\n\n return { found: true, entry, files: sortedUnique(files) };\n}\n\nfunction namedStep(step: WrittenStep, facts: BookFacts, graph: FileGraph): StepMatch {\n const named = facts.named.filter(\n (thing) => thing.type === step.type && thing.name === step.target,\n );\n const first = named[0];\n\n if (!first) return NOTHING;\n\n const files = new Set<string>();\n\n for (const thing of named) {\n if (thing.file === null) continue;\n\n importClosure(graph, [thing.file]).forEach((file) => files.add(file));\n files.add(thing.file);\n }\n\n return { found: true, entry: first.file, files: sortedUnique(files) };\n}\n\nfunction affectsStep(step: WrittenStep, written: WrittenGrimoire): StepMatch {\n const target = step.affects;\n\n if (target === null) return NOTHING;\n\n const feature = written.features.find((candidate) => candidate.id === target.feature);\n const found =\n feature !== undefined &&\n (target.flow === null || feature.flows.some((flow) => flow.id.value === target.flow));\n\n return { found, entry: null, files: [] };\n}\n\n/** Everything the step resolver reads. */\nexport type StepContext = {\n written: WrittenGrimoire;\n facts: BookFacts;\n apps: Record<string, AppMatch>;\n graph: FileGraph;\n};\n\n/** One step of a flow of `feature`, with what it matched in the book. */\nexport function resolveStep(\n step: WrittenStep,\n feature: WrittenFeature,\n context: StepContext,\n): FlowBookmapStep {\n let match: StepMatch;\n\n if (step.type === \"route\") match = routeStep(step, context.facts, context.graph);\n else if (step.type === \"page\")\n match = pageStep(step, feature, context.facts, context.apps, context.graph);\n else if (NAMED_TYPES.has(step.type)) match = namedStep(step, context.facts, context.graph);\n else if (step.type === \"affects\") match = affectsStep(step, context.written);\n else match = { found: null, entry: null, files: [] };\n\n const target = step.app === null ? step.target : `${step.target} [${step.app}]`;\n\n return { index: step.index, type: step.type, target, ...match };\n}\n"],"mappings":";;;AAUA,MAAM,8BAAmC,IAAI,IAAmB;CAC9D;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,mBAAmB,OAAuB;CAKxD,MAAM,UAJa,MAChB,KAAK,CAAC,CACN,QAAQ,uBAAuB,KAAK,CAAC,CACrC,QAAQ,iBAAiB,KACH,CAAC,CAAC,QAAQ,QAAQ,EAAE;CAE7C,OAAO,YAAY,KAAK,MAAM;AAChC;;;;;;;AAQA,SAAgB,aACd,OACA,QACA,MACS;CACT,MAAM,cAAc,MAAM,OAAO,YAAY;CAC7C,MAAM,QAAQ,OAAO,YAAY;CAGjC,QAFsB,gBAAgB,SAAS,gBAAgB,SAAS,UAAU,UAE1D,mBAAmB,MAAM,IAAI,MAAM,mBAAmB,IAAI;AACpF;AAEA,SAAS,aAAa,OAAmC;CACvD,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK;AAClC;AAKA,MAAM,UAAqB;CAAE,OAAO;CAAO,OAAO;CAAM,OAAO,CAAC;AAAE;AAElE,SAAS,UAAU,MAAmB,OAAkB,OAA6B;CACnF,IAAI,MAAM,WAAW,QAAQ,KAAK,UAAU,MAAM,OAAO;EAAE,OAAO;EAAM,OAAO;EAAM,OAAO,CAAC;CAAE;CAE/F,MAAM,SAAS,KAAK;CACpB,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CACjB,IAAI;CAEJ,IAAI,KAAK,SAAS,SAAS,QAAQ,UAAU,MAAM,QAAQ,OAAO,QAAQ,KAAK;MAC1E,IAAI,KAAK,SAAS,QACrB,QAAQ,SAAS,MAAM,SAAS,QAAQ,OAAO,QAAQ,MAAM,QAAQ,KAAK;MACvE,IAAI,YAAY,IAAI,KAAK,IAAI,GAAG,QAAQ,UAAU,MAAM,QAAQ,OAAO,QAAQ,KAAK;MACpF,IAAI,KAAK,SAAS,WAAW,QAAQ,YAAY,MAAM,QAAQ,OAAO;MACtE,QAAQ;EAAE,OAAO;EAAM,OAAO;EAAM,OAAO,CAAC;CAAE;CAEnD,MAAM,SAAS,KAAK,QAAQ,OAAO,KAAK,SAAS,GAAG,KAAK,OAAO,IAAI,KAAK,IAAI;CAE7E,OAAO;EAAE,OAAO,KAAK;EAAO,MAAM,KAAK;EAAM;EAAQ,GAAG;CAAM;AAChE"}
1
+ {"version":3,"file":"steps.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/bookmap/steps.ts"],"sourcesContent":["/**\n * The files behind each step of a flow: what a route, page, mail, job, event\n * or notification step reaches in the book.\n */\nimport type { BookFacts, BookNamedType } from \"../contracts/adapter\";\nimport type { FlowBookmapStep } from \"../contracts/bookmap\";\nimport type { AppMatch } from \"../contracts/snapshot\";\nimport type { WrittenFeature, WrittenGrimoire, WrittenStep } from \"../contracts/written\";\nimport { importClosure, type FileGraph } from \"../graph\";\n\nconst NAMED_TYPES: ReadonlySet<string> = new Set<BookNamedType>([\n \"mail\",\n \"job\",\n \"event\",\n \"notification\",\n]);\n\n/** A route path with params written one way (`:id` and `[id]` → `:id`) and no trailing `/`. */\nexport function normalizeRoutePath(route: string): string {\n const withParams = route\n .trim()\n .replace(/\\[\\.\\.\\.([^\\]]+)\\]/g, \":$1\")\n .replace(/\\[([^\\]]+)\\]/g, \":$1\");\n const trimmed = withParams.replace(/\\/+$/, \"\");\n\n return trimmed === \"\" ? \"/\" : trimmed;\n}\n\n/**\n * Whether a route answers `METHOD path`: paths compared after\n * `normalizeRoutePath` (`:id` ≡ `[id]`, trailing `/` ignored), methods\n * without regard to case, `ALL` on either side matching any method. The\n * check, the book maps and `scry --route` all match this way.\n */\nexport function routeMatches(\n route: { readonly method: string; readonly path: string },\n method: string,\n path: string,\n): boolean {\n const routeMethod = route.method.toUpperCase();\n const asked = method.toUpperCase();\n const methodMatches = routeMethod === asked || routeMethod === \"ALL\" || asked === \"ALL\";\n\n return methodMatches && normalizeRoutePath(route.path) === normalizeRoutePath(path);\n}\n\nfunction sortedUnique(files: Iterable<string>): string[] {\n return [...new Set(files)].sort();\n}\n\n/** What the step matched: its entry files and the files behind them. */\ntype StepMatch = Pick<\n FlowBookmapStep,\n \"found\" | \"entry\" | \"entries\" | \"direct\" | \"files\" | \"typeOnlyFiles\"\n>;\n\nconst NOTHING: StepMatch = {\n found: false,\n entry: null,\n entries: [],\n direct: [],\n files: [],\n typeOnlyFiles: [],\n};\n\nconst UNKNOWN: StepMatch = { ...NOTHING, found: null };\n\n/**\n * Work out a step's files from its entry files. `extra` are files that belong\n * to the step without being imported by an entry (a route's routes file).\n */\nfunction reach(\n graph: FileGraph,\n entries: readonly string[],\n extra: readonly string[] = [],\n): Pick<StepMatch, \"entries\" | \"direct\" | \"files\" | \"typeOnlyFiles\"> {\n const entryFiles = sortedUnique(entries);\n const known = new Set(entryFiles);\n const direct = new Set<string>();\n\n for (const entry of entryFiles) {\n for (const edge of graph.get(entry)?.imports ?? []) {\n if (edge.file !== null && !known.has(edge.file)) direct.add(edge.file);\n }\n }\n\n const files = new Set([\n ...entryFiles,\n ...extra,\n ...importClosure(graph, entryFiles, { skipTypeOnly: true }),\n ]);\n const everything = importClosure(graph, entryFiles);\n\n return {\n entries: entryFiles,\n direct: sortedUnique(direct),\n files: sortedUnique(files),\n typeOnlyFiles: everything.filter((file) => !files.has(file)),\n };\n}\n\n/** `auth-only.middleware.ts` → `authOnly` (the camelCase stem without the role suffix). */\nfunction middlewareNameOf(file: string): string {\n const base = (file.split(\"/\").pop() ?? file).replace(/\\.(?:d\\.ts|[cm]?[jt]sx?)$/, \"\");\n const stem = base.replace(/\\.middleware$/, \"\");\n\n return stem.replace(/[-_.]+([a-zA-Z0-9])/g, (_match, letter: string) => letter.toUpperCase());\n}\n\n/**\n * The files of the middleware a route names. A name matches a file that exports\n * it, or a `*.middleware.*` file whose stem is the name (`auth-only.middleware.ts` ↔ `authOnly`).\n * When the routes file imports some of the matches, only those count (two\n * modules may name a middleware the same). The routes file's other imports are\n * not followed: it imports every controller of its module.\n */\nfunction middlewareFiles(\n names: readonly string[],\n routesFile: string | null,\n graph: FileGraph,\n): string[] {\n const imported = new Set(\n routesFile === null\n ? []\n : (graph.get(routesFile)?.imports ?? []).flatMap((edge) =>\n edge.file === null ? [] : [edge.file],\n ),\n );\n const found: string[] = [];\n\n for (const name of names) {\n const matches: string[] = [];\n\n for (const [file, entry] of graph) {\n const exports = (entry as { exports?: readonly { name: string }[] }).exports ?? [];\n\n const byStem =\n /\\.middleware\\.(?:[cm]?[jt]sx?)$/.test(file) && middlewareNameOf(file) === name;\n\n if (exports.some((item) => item.name === name) || byStem) matches.push(file);\n }\n\n const near = matches.filter((file) => imported.has(file));\n\n found.push(...(near.length > 0 ? near : matches.length === 1 ? matches : []));\n }\n\n return found;\n}\n\nfunction routeStep(step: WrittenStep, facts: BookFacts, graph: FileGraph): StepMatch {\n if (facts.routes === null || step.route === null) return UNKNOWN;\n\n const target = step.route;\n const routes = facts.routes.filter((route) => routeMatches(route, target.method, target.path));\n const first = routes[0];\n\n if (!first) return NOTHING;\n\n const handlers = routes.flatMap((route) =>\n route.handlerFile === null ? [] : [route.handlerFile],\n );\n const sources = routes.flatMap((route) => (route.sourceFile === null ? [] : [route.sourceFile]));\n const middleware = routes.flatMap((route) =>\n middlewareFiles(route.middleware, route.sourceFile, graph),\n );\n const handlerReach = reach(graph, [...handlers, ...middleware], sources);\n // The routes files are entries too, but their own imports are not part of the step.\n const entries = sortedUnique([...handlers, ...middleware, ...sources]);\n\n return {\n found: true,\n entry: first.handlerFile ?? first.sourceFile,\n ...handlerReach,\n entries,\n direct: handlerReach.direct.filter((file) => !entries.includes(file)),\n };\n}\n\nfunction pageStep(\n step: WrittenStep,\n feature: WrittenFeature,\n facts: BookFacts,\n apps: Record<string, AppMatch>,\n graph: FileGraph,\n): StepMatch {\n const wanted = normalizeRoutePath(step.target);\n const matched: string[] = [];\n const starts: string[] = [];\n\n // `page /support [web-admin]` looks in that app only; without a scope, in the feature's apps.\n const appIds =\n step.app === null ? (feature.readme?.apps.map((app) => app.value) ?? []) : [step.app];\n\n for (const appId of appIds) {\n const match = apps[appId];\n\n if (!match) continue;\n\n if (match.site) {\n const siteId = match.site.id;\n\n for (const page of facts.pages) {\n if (page.site !== siteId || normalizeRoutePath(page.route) !== wanted) continue;\n\n matched.push(page.file);\n starts.push(page.file);\n if (page.setupFile !== null) starts.push(page.setupFile);\n }\n }\n\n if (match.mobile) {\n for (const screen of match.mobile.screens) {\n if (normalizeRoutePath(screen.route) !== wanted) continue;\n\n matched.push(screen.file);\n starts.push(screen.file);\n }\n }\n }\n\n const entry = matched[0];\n\n if (entry === undefined) return NOTHING;\n\n return { found: true, entry, ...reach(graph, starts) };\n}\n\nfunction namedStep(step: WrittenStep, facts: BookFacts, graph: FileGraph): StepMatch {\n const named = facts.named.filter(\n (thing) => thing.type === step.type && thing.name === step.target,\n );\n const first = named[0];\n\n // Mails, jobs, events and notifications come from the booted app: without route facts they were not checked.\n if (!first) return facts.routes === null ? UNKNOWN : NOTHING;\n\n const entries = named.flatMap((thing) => (thing.file === null ? [] : [thing.file]));\n\n return { found: true, entry: first.file, ...reach(graph, entries) };\n}\n\nfunction affectsStep(step: WrittenStep, written: WrittenGrimoire): StepMatch {\n const target = step.affects;\n\n if (target === null) return NOTHING;\n\n const feature = written.features.find((candidate) => candidate.id === target.feature);\n const found =\n feature !== undefined &&\n (target.flow === null || feature.flows.some((flow) => flow.id.value === target.flow));\n\n return { ...NOTHING, found };\n}\n\n/** Everything the step resolver reads. */\nexport type StepContext = {\n written: WrittenGrimoire;\n facts: BookFacts;\n apps: Record<string, AppMatch>;\n graph: FileGraph;\n};\n\n/** One step of a flow of `feature`, with what it matched in the book. */\nexport function resolveStep(\n step: WrittenStep,\n feature: WrittenFeature,\n context: StepContext,\n): FlowBookmapStep {\n let match: StepMatch;\n\n if (step.type === \"route\") match = routeStep(step, context.facts, context.graph);\n else if (step.type === \"page\")\n match = pageStep(step, feature, context.facts, context.apps, context.graph);\n else if (NAMED_TYPES.has(step.type)) match = namedStep(step, context.facts, context.graph);\n else if (step.type === \"affects\") match = affectsStep(step, context.written);\n else match = UNKNOWN;\n\n const target = step.app === null ? step.target : `${step.target} [${step.app}]`;\n\n return { index: step.index, type: step.type, target, ...match };\n}\n"],"mappings":";;;AAUA,MAAM,8BAAmC,IAAI,IAAmB;CAC9D;CACA;CACA;CACA;AACF,CAAC;;AAGD,SAAgB,mBAAmB,OAAuB;CAKxD,MAAM,UAJa,MAChB,KAAK,CAAC,CACN,QAAQ,uBAAuB,KAAK,CAAC,CACrC,QAAQ,iBAAiB,KACH,CAAC,CAAC,QAAQ,QAAQ,EAAE;CAE7C,OAAO,YAAY,KAAK,MAAM;AAChC;;;;;;;AAQA,SAAgB,aACd,OACA,QACA,MACS;CACT,MAAM,cAAc,MAAM,OAAO,YAAY;CAC7C,MAAM,QAAQ,OAAO,YAAY;CAGjC,QAFsB,gBAAgB,SAAS,gBAAgB,SAAS,UAAU,UAE1D,mBAAmB,MAAM,IAAI,MAAM,mBAAmB,IAAI;AACpF;AAEA,SAAS,aAAa,OAAmC;CACvD,OAAO,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK;AAClC;AAQA,MAAM,UAAqB;CACzB,OAAO;CACP,OAAO;CACP,SAAS,CAAC;CACV,QAAQ,CAAC;CACT,OAAO,CAAC;CACR,eAAe,CAAC;AAClB;AAEA,MAAM,UAAqB;CAAE,GAAG;C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,MAAM,OAAO,OAAO;CAAE;AACpE;AAEA,SAAS,YAAY,MAAmB,SAAqC;CAC3E,MAAM,SAAS,KAAK;CAEpB,IAAI,WAAW,MAAM,OAAO;CAE5B,MAAM,UAAU,QAAQ,SAAS,MAAM,cAAc,UAAU,OAAO,OAAO,OAAO;CACpF,MAAM,QACJ,YAAY,WACX,OAAO,SAAS,QAAQ,QAAQ,MAAM,MAAM,SAAS,KAAK,GAAG,UAAU,OAAO,IAAI;CAErF,OAAO;EAAE,GAAG;EAAS;CAAM;AAC7B;;AAWA,SAAgB,YACd,MACA,SACA,SACiB;CACjB,IAAI;CAEJ,IAAI,KAAK,SAAS,SAAS,QAAQ,UAAU,MAAM,QAAQ,OAAO,QAAQ,KAAK;MAC1E,IAAI,KAAK,SAAS,QACrB,QAAQ,SAAS,MAAM,SAAS,QAAQ,OAAO,QAAQ,MAAM,QAAQ,KAAK;MACvE,IAAI,YAAY,IAAI,KAAK,IAAI,GAAG,QAAQ,UAAU,MAAM,QAAQ,OAAO,QAAQ,KAAK;MACpF,IAAI,KAAK,SAAS,WAAW,QAAQ,YAAY,MAAM,QAAQ,OAAO;MACtE,QAAQ;CAEb,MAAM,SAAS,KAAK,QAAQ,OAAO,KAAK,SAAS,GAAG,KAAK,OAAO,IAAI,KAAK,IAAI;CAE7E,OAAO;EAAE,OAAO,KAAK;EAAO,MAAM,KAAK;EAAM;EAAQ,GAAG;CAAM;AAChE"}
@@ -1 +1 @@
1
- {"version":3,"file":"check-grimoire.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/check/check-grimoire.ts"],"mappings":";;;;wBA8BgB,cAAc,UAAU,mBAAmB"}
1
+ {"version":3,"file":"check-grimoire.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/check/check-grimoire.ts"],"mappings":";;;;wBAiCgB,cAAc,UAAU,mBAAmB"}
@@ -4,8 +4,9 @@ import { checkTestResults } from "../test-results/index.mjs";
4
4
  import { checkReleases } from "../releases/index.mjs";
5
5
  import { checkTasks } from "../tasks/index.mjs";
6
6
  import { checkBookNotes } from "./rules/book-notes.mjs";
7
- import { checkCriteriaTests, checkProofTargets } from "./rules/criteria.mjs";
7
+ import { checkCaseCriteria, checkCriteriaTests, checkProofTargets } from "./rules/criteria.mjs";
8
8
  import { checkAppNames, checkChangelogLinks, checkRelations, checkSteps } from "./rules/links.mjs";
9
+ import { checkScreenshots } from "./rules/screenshots.mjs";
9
10
  import { checkFolders, checkHeaders, checkOwners, checkUnreached } from "./rules/source-files.mjs";
10
11
  import { checkChangeWords, checkFlowVersions, checkReadmeDates } from "./rules/versions.mjs";
11
12
 
@@ -20,6 +21,8 @@ const CHECK_RULES = [
20
21
  checkOwners,
21
22
  checkFolders,
22
23
  checkUnreached,
24
+ checkCaseCriteria,
25
+ checkScreenshots,
23
26
  checkCriteriaTests,
24
27
  checkProofTargets,
25
28
  checkReadmeDates,
@@ -1 +1 @@
1
- {"version":3,"file":"check-grimoire.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/check/check-grimoire.ts"],"sourcesContent":["import { checkApps } from \"../apps\";\nimport type { GrimoireCheckReport, GrimoireFinding } from \"../contracts/findings\";\nimport type { GrimoireRule, GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { checkReleases } from \"../releases\";\nimport { checkTasks } from \"../tasks\";\nimport { checkTestResults } from \"../test-results\";\nimport { checkBookNotes } from \"./rules/book-notes\";\nimport { checkCriteriaTests, checkProofTargets } from \"./rules/criteria\";\nimport { checkAppNames, checkChangelogLinks, checkRelations, checkSteps } from \"./rules/links\";\nimport { checkFolders, checkHeaders, checkOwners, checkUnreached } from \"./rules/source-files\";\nimport { checkChangeWords, checkFlowVersions, checkReadmeDates } from \"./rules/versions\";\n\n/** The check's own rules, in report order before sorting. */\nexport const CHECK_RULES: readonly GrimoireRule[] = [\n checkSteps,\n checkAppNames,\n checkChangelogLinks,\n checkRelations,\n checkHeaders,\n checkOwners,\n checkFolders,\n checkUnreached,\n checkCriteriaTests,\n checkProofTargets,\n checkReadmeDates,\n checkChangeWords,\n checkFlowVersions,\n];\n\n/** Run every rule over a snapshot. Pure; never writes. */\nexport function checkGrimoire(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n const findings = [\n ...snapshot.structure,\n ...snapshot.proofFindings,\n ...CHECK_RULES.flatMap((rule) => rule(snapshot)),\n ...checkApps(snapshot),\n ...checkReleases(snapshot),\n ...checkTasks(snapshot),\n ...checkTestResults(snapshot),\n ...checkBookNotes(snapshot),\n ];\n\n return finishReport(snapshot, findings);\n}\n\n/**\n * Mark the findings on proposed features and flows as expected, sort them\n * and count them. The findings of the snapshot are copied, never changed.\n */\nexport function finishReport(\n snapshot: GrimoireSnapshot,\n findings: readonly GrimoireFinding[],\n): GrimoireCheckReport {\n const proposed = proposedWork(snapshot);\n const marked = findings\n .map((finding) => ({ ...finding, expected: finding.expected || isProposed(finding, proposed) }))\n .sort(compareFindings);\n const unexpected = marked.filter((finding) => !finding.expected);\n const errors = unexpected.filter((finding) => finding.severity === \"error\").length;\n\n return {\n schemaVersion: 1,\n root: snapshot.root,\n findings: marked,\n counts: {\n errors,\n warnings: unexpected.length - errors,\n expected: marked.length - unexpected.length,\n },\n ok: errors === 0,\n routes: snapshot.routes,\n };\n}\n\n/** Feature ids and `<feature>/<flow>` refs whose status is `proposed`. */\nfunction proposedWork(snapshot: GrimoireSnapshot): Set<string> {\n const proposed = new Set<string>();\n\n for (const feature of snapshot.written.features) {\n if (feature.readme?.status.value === \"proposed\") proposed.add(feature.id);\n\n for (const flow of feature.flows) {\n if (flow.status.value === \"proposed\") proposed.add(flow.ref);\n }\n }\n\n return proposed;\n}\n\nfunction isProposed(finding: GrimoireFinding, proposed: ReadonlySet<string>): boolean {\n const { feature, flow } = finding.subject;\n const flowFeature = flow?.split(\"/\")[0] ?? null;\n\n return [feature, flow, flowFeature].some((id) => id !== null && proposed.has(id));\n}\n\n/** Unexpected findings first, then expected; within each, errors before warnings, then by file, line and code. */\nfunction compareFindings(left: GrimoireFinding, right: GrimoireFinding): number {\n return (\n Number(left.expected) - Number(right.expected) ||\n severityRank(left) - severityRank(right) ||\n compareText(\n left.at?.file ?? left.subject.file ?? \"\",\n right.at?.file ?? right.subject.file ?? \"\",\n ) ||\n (left.at?.line ?? 0) - (right.at?.line ?? 0) ||\n compareText(left.code, right.code) ||\n compareText(left.message, right.message)\n );\n}\n\nfunction severityRank(finding: GrimoireFinding): number {\n return finding.severity === \"error\" ? 0 : 1;\n}\n\n/** Locale-free comparison, so the order is the same on every machine. */\nfunction compareText(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,cAAuC;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAgB,cAAc,UAAiD;CAY7E,OAAO,aAAa,UAAU;EAV5B,GAAG,SAAS;EACZ,GAAG,SAAS;EACZ,GAAG,YAAY,SAAS,SAAS,KAAK,QAAQ,CAAC;EAC/C,GAAG,UAAU,QAAQ;EACrB,GAAG,cAAc,QAAQ;EACzB,GAAG,WAAW,QAAQ;EACtB,GAAG,iBAAiB,QAAQ;EAC5B,GAAG,eAAe,QAAQ;CAGS,CAAC;AACxC;;;;;AAMA,SAAgB,aACd,UACA,UACqB;CACrB,MAAM,WAAW,aAAa,QAAQ;CACtC,MAAM,SAAS,SACZ,KAAK,aAAa;EAAE,GAAG;EAAS,UAAU,QAAQ,YAAY,WAAW,SAAS,QAAQ;CAAE,EAAE,CAAC,CAC/F,KAAK,eAAe;CACvB,MAAM,aAAa,OAAO,QAAQ,YAAY,CAAC,QAAQ,QAAQ;CAC/D,MAAM,SAAS,WAAW,QAAQ,YAAY,QAAQ,aAAa,OAAO,CAAC,CAAC;CAE5E,OAAO;EACL,eAAe;EACf,MAAM,SAAS;EACf,UAAU;EACV,QAAQ;GACN;GACA,UAAU,WAAW,SAAS;GAC9B,UAAU,OAAO,SAAS,WAAW;EACvC;EACA,IAAI,WAAW;EACf,QAAQ,SAAS;CACnB;AACF;;AAGA,SAAS,aAAa,UAAyC;CAC7D,MAAM,2BAAW,IAAI,IAAY;CAEjC,KAAK,MAAM,WAAW,SAAS,QAAQ,UAAU;EAC/C,IAAI,QAAQ,QAAQ,OAAO,UAAU,YAAY,SAAS,IAAI,QAAQ,EAAE;EAExE,KAAK,MAAM,QAAQ,QAAQ,OACzB,IAAI,KAAK,OAAO,UAAU,YAAY,SAAS,IAAI,KAAK,GAAG;CAE/D;CAEA,OAAO;AACT;AAEA,SAAS,WAAW,SAA0B,UAAwC;CACpF,MAAM,EAAE,SAAS,SAAS,QAAQ;CAGlC,OAAO;EAAC;EAAS;EAFG,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM;CAET,CAAC,CAAC,MAAM,OAAO,OAAO,QAAQ,SAAS,IAAI,EAAE,CAAC;AAClF;;AAGA,SAAS,gBAAgB,MAAuB,OAAgC;CAC9E,OACE,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,QAAQ,KAC7C,aAAa,IAAI,IAAI,aAAa,KAAK,KACvC,YACE,KAAK,IAAI,QAAQ,KAAK,QAAQ,QAAQ,IACtC,MAAM,IAAI,QAAQ,MAAM,QAAQ,QAAQ,EAC1C,MACC,KAAK,IAAI,QAAQ,MAAM,MAAM,IAAI,QAAQ,MAC1C,YAAY,KAAK,MAAM,MAAM,IAAI,KACjC,YAAY,KAAK,SAAS,MAAM,OAAO;AAE3C;AAEA,SAAS,aAAa,SAAkC;CACtD,OAAO,QAAQ,aAAa,UAAU,IAAI;AAC5C;;AAGA,SAAS,YAAY,MAAc,OAAuB;CACxD,OAAO,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAChD"}
1
+ {"version":3,"file":"check-grimoire.mjs","names":[],"sources":["../../../../../../../../packages/grimoire/src/check/check-grimoire.ts"],"sourcesContent":["import { checkApps } from \"../apps\";\nimport type { GrimoireCheckReport, GrimoireFinding } from \"../contracts/findings\";\nimport type { GrimoireRule, GrimoireSnapshot } from \"../contracts/snapshot\";\nimport { checkReleases } from \"../releases\";\nimport { checkTasks } from \"../tasks\";\nimport { checkTestResults } from \"../test-results\";\nimport { checkBookNotes } from \"./rules/book-notes\";\nimport { checkCaseCriteria, checkCriteriaTests, checkProofTargets } from \"./rules/criteria\";\nimport { checkAppNames, checkChangelogLinks, checkRelations, checkSteps } from \"./rules/links\";\nimport { checkScreenshots } from \"./rules/screenshots\";\nimport { checkFolders, checkHeaders, checkOwners, checkUnreached } from \"./rules/source-files\";\nimport { checkChangeWords, checkFlowVersions, checkReadmeDates } from \"./rules/versions\";\n\n/** The check's own rules, in report order before sorting. */\nexport const CHECK_RULES: readonly GrimoireRule[] = [\n checkSteps,\n checkAppNames,\n checkChangelogLinks,\n checkRelations,\n checkHeaders,\n checkOwners,\n checkFolders,\n checkUnreached,\n checkCaseCriteria,\n checkScreenshots,\n checkCriteriaTests,\n checkProofTargets,\n checkReadmeDates,\n checkChangeWords,\n checkFlowVersions,\n];\n\n/** Run every rule over a snapshot. Pure; never writes. */\nexport function checkGrimoire(snapshot: GrimoireSnapshot): GrimoireCheckReport {\n const findings = [\n ...snapshot.structure,\n ...snapshot.proofFindings,\n ...CHECK_RULES.flatMap((rule) => rule(snapshot)),\n ...checkApps(snapshot),\n ...checkReleases(snapshot),\n ...checkTasks(snapshot),\n ...checkTestResults(snapshot),\n ...checkBookNotes(snapshot),\n ];\n\n return finishReport(snapshot, findings);\n}\n\n/**\n * Mark the findings on proposed features and flows as expected, sort them\n * and count them. The findings of the snapshot are copied, never changed.\n */\nexport function finishReport(\n snapshot: GrimoireSnapshot,\n findings: readonly GrimoireFinding[],\n): GrimoireCheckReport {\n const proposed = proposedWork(snapshot);\n const marked = findings\n .map((finding) => ({ ...finding, expected: finding.expected || isProposed(finding, proposed) }))\n .sort(compareFindings);\n const unexpected = marked.filter((finding) => !finding.expected);\n const errors = unexpected.filter((finding) => finding.severity === \"error\").length;\n\n return {\n schemaVersion: 1,\n root: snapshot.root,\n findings: marked,\n counts: {\n errors,\n warnings: unexpected.length - errors,\n expected: marked.length - unexpected.length,\n },\n ok: errors === 0,\n routes: snapshot.routes,\n };\n}\n\n/** Feature ids and `<feature>/<flow>` refs whose status is `proposed`. */\nfunction proposedWork(snapshot: GrimoireSnapshot): Set<string> {\n const proposed = new Set<string>();\n\n for (const feature of snapshot.written.features) {\n if (feature.readme?.status.value === \"proposed\") proposed.add(feature.id);\n\n for (const flow of feature.flows) {\n if (flow.status.value === \"proposed\") proposed.add(flow.ref);\n }\n }\n\n return proposed;\n}\n\nfunction isProposed(finding: GrimoireFinding, proposed: ReadonlySet<string>): boolean {\n const { feature, flow } = finding.subject;\n const flowFeature = flow?.split(\"/\")[0] ?? null;\n\n return [feature, flow, flowFeature].some((id) => id !== null && proposed.has(id));\n}\n\n/** Unexpected findings first, then expected; within each, errors before warnings, then by file, line and code. */\nfunction compareFindings(left: GrimoireFinding, right: GrimoireFinding): number {\n return (\n Number(left.expected) - Number(right.expected) ||\n severityRank(left) - severityRank(right) ||\n compareText(\n left.at?.file ?? left.subject.file ?? \"\",\n right.at?.file ?? right.subject.file ?? \"\",\n ) ||\n (left.at?.line ?? 0) - (right.at?.line ?? 0) ||\n compareText(left.code, right.code) ||\n compareText(left.message, right.message)\n );\n}\n\nfunction severityRank(finding: GrimoireFinding): number {\n return finding.severity === \"error\" ? 0 : 1;\n}\n\n/** Locale-free comparison, so the order is the same on every machine. */\nfunction compareText(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAa,cAAuC;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAgB,cAAc,UAAiD;CAY7E,OAAO,aAAa,UAAU;EAV5B,GAAG,SAAS;EACZ,GAAG,SAAS;EACZ,GAAG,YAAY,SAAS,SAAS,KAAK,QAAQ,CAAC;EAC/C,GAAG,UAAU,QA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AAI,IAAI,aAAa,KAAK,KACvC,YACE,KAAK,IAAI,QAAQ,KAAK,QAAQ,QAAQ,IACtC,MAAM,IAAI,QAAQ,MAAM,QAAQ,QAAQ,EAC1C,MACC,KAAK,IAAI,QAAQ,MAAM,MAAM,IAAI,QAAQ,MAC1C,YAAY,KAAK,MAAM,MAAM,IAAI,KACjC,YAAY,KAAK,SAAS,MAAM,OAAO;AAE3C;AAEA,SAAS,aAAa,SAAkC;CACtD,OAAO,QAAQ,aAAa,UAAU,IAAI;AAC5C;;AAGA,SAAS,YAAY,MAAc,OAAuB;CACxD,OAAO,OAAO,QAAQ,KAAK,OAAO,QAAQ,IAAI;AAChD"}
@@ -3,7 +3,8 @@ import { isRetired, writtenLookup } from "./lookup.mjs";
3
3
 
4
4
  //#region ../../packages/grimoire/src/check/rules/criteria.ts
5
5
  /**
6
- * GR4001–GR4002: criteria and the `@proves` lines that name them.
6
+ * GR2013 and GR4001–GR4002: criteria, the cases that name them and the
7
+ * `@proves` lines that name them.
7
8
  */
8
9
  /** GR4001: a criterion of a flow (not retired) that no `@proves` line names. */
9
10
  function checkCriteriaTests(snapshot) {
@@ -42,7 +43,25 @@ function checkProofTargets(snapshot) {
42
43
  }
43
44
  return findings;
44
45
  }
46
+ /** GR2013: a case that ends in `(AC-n)` naming a criterion its flow does not have. */
47
+ function checkCaseCriteria(snapshot) {
48
+ const findings = [];
49
+ for (const feature of snapshot.written.features) for (const flow of feature.flows) {
50
+ const known = new Set(flow.criteria.map((criterion) => criterion.id));
51
+ for (const entry of flow.cases) for (const id of entry.criteria) {
52
+ if (known.has(id)) continue;
53
+ findings.push(createFinding({
54
+ code: "GR2013",
55
+ message: `the case "${entry.question}" in ${flow.ref} names ${id}, which the flow does not have`,
56
+ at: entry.at,
57
+ feature: feature.id,
58
+ flow: flow.ref
59
+ }));
60
+ }
61
+ }
62
+ return findings;
63
+ }
45
64
 
46
65
  //#endregion
47
- export { checkCriteriaTests, checkProofTargets };
66
+ export { checkCaseCriteria, checkCriteriaTests, checkProofTargets };
48
67
  //# sourceMappingURL=criteria.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"criteria.mjs","names":[],"sources":["../../../../../../../../../packages/grimoire/src/check/rules/criteria.ts"],"sourcesContent":["/**\n * GR4001–GR4002: criteria and the `@proves` lines that name them.\n */\nimport { createFinding } from \"../../codes\";\nimport type { GrimoireFinding } from \"../../contracts/findings\";\nimport type { GrimoireSnapshot } from \"../../contracts/snapshot\";\nimport { isRetired, writtenLookup } from \"./lookup\";\n\n/** GR4001: a criterion of a flow (not retired) that no `@proves` line names. */\nexport function checkCriteriaTests(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const proven = new Set(snapshot.proofs.map((proof) => `${proof.ref} ${proof.criterion}`));\n const findings: GrimoireFinding[] = [];\n\n for (const feature of snapshot.written.features) {\n for (const flow of feature.flows) {\n if (isRetired(feature, flow)) continue;\n\n for (const criterion of flow.criteria) {\n if (proven.has(`${flow.ref} ${criterion.id}`)) continue;\n\n findings.push(\n createFinding({\n code: \"GR4001\",\n message: `${flow.ref} ${criterion.id} has no test`,\n at: criterion.at,\n feature: feature.id,\n flow: flow.ref,\n }),\n );\n }\n }\n }\n\n return findings;\n}\n\n/** GR4002: a `@proves` line naming a flow or criterion that does not exist. */\nexport function checkProofTargets(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const { flows } = writtenLookup(snapshot);\n const findings: GrimoireFinding[] = [];\n\n for (const proof of snapshot.proofs) {\n const flow = flows.get(proof.ref);\n const missing = !flow\n ? `no flow ${proof.ref}`\n : flow.criteria.some((criterion) => criterion.id === proof.criterion)\n ? null\n : `no ${proof.criterion} in ${proof.ref}`;\n\n if (missing === null) continue;\n\n findings.push(\n createFinding({\n code: \"GR4002\",\n message: `\"@proves ${proof.ref} ${proof.criterion}\" names ${missing}`,\n at: proof.at,\n feature: proof.feature,\n flow: proof.ref,\n }),\n );\n }\n\n return findings;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,mBAAmB,UAA+C;CAChF,MAAM,SAAS,IAAI,IAAI,SAAS,OAAO,KAAK,UAAU,GAAG,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC;CACxF,MAAM,WAA8B,CAAC;CAErC,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,KAAK,MAAM,QAAQ,QAAQ,OAAO;EAChC,IAAI,UAAU,SAAS,IAAI,GAAG;EAE9B,KAAK,MAAM,aAAa,KAAK,UAAU;GACrC,IAAI,OAAO,IAAI,GAAG,KAAK,IAAI,GAAG,UAAU,IAAI,GAAG;GAE/C,SAAS,KACP,cAAc;IACZ,MAAM;IACN,SAAS,GAAG,KAAK,IAAI,GAAG,UAAU,GAAG;IACrC,IAAI,UAAU;IACd,SAAS,QAAQ;IACjB,MAAM,KAAK;GACb,CAAC,CACH;EACF;CACF;CAGF,OAAO;AACT;;AAGA,SAAgB,kBAAkB,UAA+C;CAC/E,MAAM,EAAE,UAAU,cAAc,QAAQ;CACxC,MAAM,WAA8B,CAAC;CAErC,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,MAAM,OAAO,MAAM,IAAI,MAAM,GAAG;EAChC,MAAM,UAAU,CAAC,OACb,WAAW,MAAM,QACjB,KAAK,SAAS,MAAM,cAAc,UAAU,OAAO,MAAM,SAAS,IAChE,OACA,MAAM,MAAM,UAAU,MAAM,MAAM;EAExC,IAAI,YAAY,MAAM;EAEtB,SAAS,KACP,cAAc;GACZ,MAAM;GACN,SAAS,YAAY,MAAM,IAAI,GAAG,MAAM,UAAU,UAAU;GAC5D,IAAI,MAAM;GACV,SAAS,MAAM;GACf,MAAM,MAAM;EACd,CAAC,CACH;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"criteria.mjs","names":[],"sources":["../../../../../../../../../packages/grimoire/src/check/rules/criteria.ts"],"sourcesContent":["/**\n * GR2013 and GR4001–GR4002: criteria, the cases that name them and the\n * `@proves` lines that name them.\n */\nimport { createFinding } from \"../../codes\";\nimport type { GrimoireFinding } from \"../../contracts/findings\";\nimport type { GrimoireSnapshot } from \"../../contracts/snapshot\";\nimport { isRetired, writtenLookup } from \"./lookup\";\n\n/** GR4001: a criterion of a flow (not retired) that no `@proves` line names. */\nexport function checkCriteriaTests(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const proven = new Set(snapshot.proofs.map((proof) => `${proof.ref} ${proof.criterion}`));\n const findings: GrimoireFinding[] = [];\n\n for (const feature of snapshot.written.features) {\n for (const flow of feature.flows) {\n if (isRetired(feature, flow)) continue;\n\n for (const criterion of flow.criteria) {\n if (proven.has(`${flow.ref} ${criterion.id}`)) continue;\n\n findings.push(\n createFinding({\n code: \"GR4001\",\n message: `${flow.ref} ${criterion.id} has no test`,\n at: criterion.at,\n feature: feature.id,\n flow: flow.ref,\n }),\n );\n }\n }\n }\n\n return findings;\n}\n\n/** GR4002: a `@proves` line naming a flow or criterion that does not exist. */\nexport function checkProofTargets(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const { flows } = writtenLookup(snapshot);\n const findings: GrimoireFinding[] = [];\n\n for (const proof of snapshot.proofs) {\n const flow = flows.get(proof.ref);\n const missing = !flow\n ? `no flow ${proof.ref}`\n : flow.criteria.some((criterion) => criterion.id === proof.criterion)\n ? null\n : `no ${proof.criterion} in ${proof.ref}`;\n\n if (missing === null) continue;\n\n findings.push(\n createFinding({\n code: \"GR4002\",\n message: `\"@proves ${proof.ref} ${proof.criterion}\" names ${missing}`,\n at: proof.at,\n feature: proof.feature,\n flow: proof.ref,\n }),\n );\n }\n\n return findings;\n}\n\n/** GR2013: a case that ends in `(AC-n)` naming a criterion its flow does not have. */\nexport function checkCaseCriteria(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const findings: GrimoireFinding[] = [];\n\n for (const feature of snapshot.written.features) {\n for (const flow of feature.flows) {\n const known = new Set(flow.criteria.map((criterion) => criterion.id));\n\n for (const entry of flow.cases) {\n for (const id of entry.criteria) {\n if (known.has(id)) continue;\n\n findings.push(\n createFinding({\n code: \"GR2013\",\n message: `the case \"${entry.question}\" in ${flow.ref} names ${id}, which the flow does not have`,\n at: entry.at,\n feature: feature.id,\n flow: flow.ref,\n }),\n );\n }\n }\n }\n }\n\n return findings;\n}\n"],"mappings":";;;;;;;;;AAUA,SAAgB,mBAAmB,UAA+C;CAChF,MAAM,SAAS,IAAI,IAAI,SAAS,OAAO,KAAK,UAAU,GAAG,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC;CACxF,MAAM,WAA8B,CAAC;CAErC,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,KAAK,MAAM,QAAQ,QAAQ,OAAO;EAChC,IAAI,UAAU,SAAS,IAAI,GAAG;EAE9B,KAAK,MAAM,aAAa,KAAK,UAAU;GACrC,IAAI,OAAO,IAAI,GAAG,KAAK,IAAI,GAAG,UAAU,IAAI,GAAG;GAE/C,SAAS,KACP,cAAc;IACZ,MAAM;IACN,SAAS,GAAG,KAAK,IAAI,GAAG,UAAU,GAAG;IACrC,IAAI,UAAU;IACd,SAAS,QAAQ;IACjB,MAAM,KAAK;GACb,CAAC,CACH;EACF;CACF;CAGF,OAAO;AACT;;AAGA,SAAgB,kBAAkB,UAA+C;CAC/E,MAAM,EAAE,UAAU,cAAc,QAAQ;CACxC,MAAM,WAA8B,CAAC;CAErC,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,MAAM,OAAO,MAAM,IAAI,MAAM,GAAG;EAChC,MAAM,UAAU,CAAC,OACb,WAAW,MAAM,QACjB,KAAK,SAAS,MAAM,cAAc,UAAU,OAAO,MAAM,SAAS,IAChE,OACA,MAAM,MAAM,UAAU,MAAM,MAAM;EAExC,IAAI,YAAY,MAAM;EAEtB,SAAS,KACP,cAAc;GACZ,MAAM;GACN,SAAS,YAAY,MAAM,IAAI,GAAG,MAAM,UAAU,UAAU;GAC5D,IAAI,MAAM;GACV,SAAS,MAAM;GACf,MAAM,MAAM;EACd,CAAC,CACH;CACF;CAEA,OAAO;AACT;;AAGA,SAAgB,kBAAkB,UAA+C;CAC/E,MAAM,WAA8B,CAAC;CAErC,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,KAAK,MAAM,QAAQ,QAAQ,OAAO;EAChC,MAAM,QAAQ,IAAI,IAAI,KAAK,SAAS,KAAK,cAAc,UAAU,EAAE,CAAC;EAEpE,KAAK,MAAM,SAAS,KAAK,OACvB,KAAK,MAAM,MAAM,MAAM,UAAU;GAC/B,IAAI,MAAM,IAAI,EAAE,GAAG;GAEnB,SAAS,KACP,cAAc;IACZ,MAAM;IACN,SAAS,aAAa,MAAM,SAAS,OAAO,KAAK,IAAI,SAAS,GAAG;IACjE,IAAI,MAAM;IACV,SAAS,QAAQ;IACjB,MAAM,KAAK;GACb,CAAC,CACH;EACF;CAEJ;CAGF,OAAO;AACT"}
@@ -0,0 +1,57 @@
1
+ import { createFinding } from "../../codes/index.mjs";
2
+ import { GRIMOIRE_PATHS } from "../../paths/index.mjs";
3
+ import path from "node:path";
4
+ import { statSync } from "node:fs";
5
+
6
+ //#region ../../packages/grimoire/src/check/rules/screenshots.ts
7
+ /**
8
+ * GR2014: image lines that name a screenshot file that does not exist, or
9
+ * that is not an image type the viewers serve.
10
+ */
11
+ /** Image types a screenshot may have. */
12
+ const SCREENSHOT_EXTENSIONS = [
13
+ ".png",
14
+ ".jpg",
15
+ ".jpeg",
16
+ ".webp",
17
+ ".gif"
18
+ ];
19
+ function isFile(target) {
20
+ try {
21
+ return statSync(target).isFile();
22
+ } catch {
23
+ return false;
24
+ }
25
+ }
26
+ /** GR2014: a screenshot of a story step, page, screen or block that is missing or not an image type. */
27
+ function checkScreenshots(snapshot) {
28
+ const findings = [];
29
+ const folder = path.join(snapshot.root, GRIMOIRE_PATHS.screenshots);
30
+ const check = (screenshots, subject) => {
31
+ for (const screenshot of screenshots) {
32
+ if (screenshot.path === null) continue;
33
+ const extension = path.posix.extname(screenshot.path).toLowerCase();
34
+ const problem = !SCREENSHOT_EXTENSIONS.includes(extension) ? `is not one of ${SCREENSHOT_EXTENSIONS.join(", ")}` : isFile(path.join(folder, ...screenshot.path.split("/"))) ? null : "does not exist";
35
+ if (problem === null) continue;
36
+ findings.push(createFinding({
37
+ code: "GR2014",
38
+ message: `the image ${JSON.stringify(screenshot.written)} ${problem} (grimoire/screenshots/${screenshot.path})`,
39
+ at: screenshot.at,
40
+ ...subject
41
+ }));
42
+ }
43
+ };
44
+ for (const feature of snapshot.written.features) for (const flow of feature.flows) for (const step of flow.story) check(step.screenshots, {
45
+ feature: feature.id,
46
+ flow: flow.ref
47
+ });
48
+ for (const app of snapshot.written.apps) for (const page of [...app.pages, ...app.screens]) {
49
+ check(page.screenshots, { app: app.id.value });
50
+ for (const block of page.blockFiles) check(block.screenshots, { app: app.id.value });
51
+ }
52
+ return findings;
53
+ }
54
+
55
+ //#endregion
56
+ export { SCREENSHOT_EXTENSIONS, checkScreenshots };
57
+ //# sourceMappingURL=screenshots.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"screenshots.mjs","names":[],"sources":["../../../../../../../../../packages/grimoire/src/check/rules/screenshots.ts"],"sourcesContent":["/**\n * GR2014: image lines that name a screenshot file that does not exist, or\n * that is not an image type the viewers serve.\n */\nimport { statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { createFinding } from \"../../codes\";\nimport type { GrimoireFinding } from \"../../contracts/findings\";\nimport type { GrimoireSnapshot } from \"../../contracts/snapshot\";\nimport type { WrittenScreenshot } from \"../../contracts/written\";\nimport { GRIMOIRE_PATHS } from \"../../paths\";\n\n/** Image types a screenshot may have. */\nexport const SCREENSHOT_EXTENSIONS: readonly string[] = [\".png\", \".jpg\", \".jpeg\", \".webp\", \".gif\"];\n\nfunction isFile(target: string): boolean {\n try {\n return statSync(target).isFile();\n } catch {\n return false;\n }\n}\n\n/** GR2014: a screenshot of a story step, page, screen or block that is missing or not an image type. */\nexport function checkScreenshots(snapshot: GrimoireSnapshot): GrimoireFinding[] {\n const findings: GrimoireFinding[] = [];\n const folder = path.join(snapshot.root, GRIMOIRE_PATHS.screenshots);\n\n const check = (\n screenshots: readonly WrittenScreenshot[],\n subject: { feature?: string; flow?: string; app?: string },\n ): void => {\n for (const screenshot of screenshots) {\n // A path outside the folder is GR1029 (the parser); nothing to look up.\n if (screenshot.path === null) continue;\n\n const extension = path.posix.extname(screenshot.path).toLowerCase();\n const problem = !SCREENSHOT_EXTENSIONS.includes(extension)\n ? `is not one of ${SCREENSHOT_EXTENSIONS.join(\", \")}`\n : isFile(path.join(folder, ...screenshot.path.split(\"/\")))\n ? null\n : \"does not exist\";\n\n if (problem === null) continue;\n\n findings.push(\n createFinding({\n code: \"GR2014\",\n message: `the image ${JSON.stringify(screenshot.written)} ${problem} (grimoire/screenshots/${screenshot.path})`,\n at: screenshot.at,\n ...subject,\n }),\n );\n }\n };\n\n for (const feature of snapshot.written.features) {\n for (const flow of feature.flows) {\n for (const step of flow.story) {\n check(step.screenshots, { feature: feature.id, flow: flow.ref });\n }\n }\n }\n\n for (const app of snapshot.written.apps) {\n for (const page of [...app.pages, ...app.screens]) {\n check(page.screenshots, { app: app.id.value });\n\n for (const block of page.blockFiles) check(block.screenshots, { app: app.id.value });\n }\n }\n\n return findings;\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,wBAA2C;CAAC;CAAQ;CAAQ;CAAS;CAAS;AAAM;AAEjG,SAAS,OAAO,QAAyB;CACvC,IAAI;EACF,OAAO,SAAS,MAAM,CAAC,CAAC,OAAO;CACjC,QAAQ;EACN,OAAO;CACT;AACF;;AAGA,SAAgB,iBAAiB,UAA+C;CAC9E,MAAM,WAA8B,CAAC;CACrC,MAAM,SAAS,KAAK,KAAK,SAAS,MAAM,eAAe,WAAW;CAElE,MAAM,SACJ,aACA,YACS;EACT,KAAK,MAAM,cAAc,aAAa;GAEpC,IAAI,WAAW,SAAS,MAAM;GAE9B,MAAM,YAAY,KAAK,MAAM,QAAQ,WAAW,IAAI,CAAC,CAAC,YAAY;GAClE,MAAM,UAAU,CAAC,sBAAsB,SAAS,SAAS,IACrD,iBAAiB,sBAAsB,KAAK,IAAI,MAChD,OAAO,KAAK,KAAK,QAAQ,GAAG,WAAW,KAAK,MAAM,GAAG,CAAC,CAAC,IACrD,OACA;GAEN,IAAI,YAAY,MAAM;GAEtB,SAAS,KACP,cAAc;IACZ,MAAM;IACN,SAAS,aAAa,KAAK,UAAU,WAAW,OAAO,EAAE,GAAG,QAAQ,yBAAyB,WAAW,KAAK;IAC7G,IAAI,WAAW;IACf,GAAG;GACL,CAAC,CACH;EACF;CACF;CAEA,KAAK,MAAM,WAAW,SAAS,QAAQ,UACrC,KAAK,MAAM,QAAQ,QAAQ,OACzB,KAAK,MAAM,QAAQ,KAAK,OACtB,MAAM,KAAK,aAAa;EAAE,SAAS,QAAQ;EAAI,MAAM,KAAK;CAAI,CAAC;CAKrE,KAAK,MAAM,OAAO,SAAS,QAAQ,MACjC,KAAK,MAAM,QAAQ,CAAC,GAAG,IAAI,OAAO,GAAG,IAAI,OAAO,GAAG;EACjD,MAAM,KAAK,aAAa,EAAE,KAAK,IAAI,GAAG,MAAM,CAAC;EAE7C,KAAK,MAAM,SAAS,KAAK,YAAY,MAAM,MAAM,aAAa,EAAE,KAAK,IAAI,GAAG,MAAM,CAAC;CACrF;CAGF,OAAO;AACT"}
@@ -57,6 +57,10 @@ export declare const GRIMOIRE_CODE_LIST: readonly [GrimoireCodeDefinition & {
57
57
  readonly code: "GR1027";
58
58
  }, GrimoireCodeDefinition & {
59
59
  readonly code: "GR1028";
60
+ }, GrimoireCodeDefinition & {
61
+ readonly code: "GR1029";
62
+ }, GrimoireCodeDefinition & {
63
+ readonly code: "GR1030";
60
64
  }, GrimoireCodeDefinition & {
61
65
  readonly code: "GR2001";
62
66
  }, GrimoireCodeDefinition & {
@@ -81,6 +85,10 @@ export declare const GRIMOIRE_CODE_LIST: readonly [GrimoireCodeDefinition & {
81
85
  readonly code: "GR2011";
82
86
  }, GrimoireCodeDefinition & {
83
87
  readonly code: "GR2012";
88
+ }, GrimoireCodeDefinition & {
89
+ readonly code: "GR2013";
90
+ }, GrimoireCodeDefinition & {
91
+ readonly code: "GR2014";
84
92
  }, GrimoireCodeDefinition & {
85
93
  readonly code: "GR3001";
86
94
  }, GrimoireCodeDefinition & {
@@ -109,6 +117,10 @@ export declare const GRIMOIRE_CODE_LIST: readonly [GrimoireCodeDefinition & {
109
117
  readonly code: "GR4007";
110
118
  }, GrimoireCodeDefinition & {
111
119
  readonly code: "GR4008";
120
+ }, GrimoireCodeDefinition & {
121
+ readonly code: "GR4009";
122
+ }, GrimoireCodeDefinition & {
123
+ readonly code: "GR4010";
112
124
  }, GrimoireCodeDefinition & {
113
125
  readonly code: "GR5001";
114
126
  }, GrimoireCodeDefinition & {
@@ -1 +1 @@
1
- {"version":3,"file":"codes.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/codes/codes.ts"],"mappings":";;;qBA0Ca,8BAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqsBnB,uBAAuB;;qBAGtB,gBAAgB,SAAS,OAAO,cAAc"}
1
+ {"version":3,"file":"codes.d.mts","names":[],"sources":["../../../../../../../../packages/grimoire/src/codes/codes.ts"],"mappings":";;;qBA0Ca,8BAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAqvBnB,uBAAuB;;qBAGtB,gBAAgB,SAAS,OAAO,cAAc"}
@@ -44,6 +44,8 @@ const GRIMOIRE_CODE_LIST = [
44
44
  define("GR1026", "structure", "error", "The feature README lists a flow that has no file", "Add `flows/<flow>.md`, or remove the flow from the README's Flows list.", WRITE),
45
45
  define("GR1027", "structure", "warning", "A flow file is not listed in the feature README", "Add the flow to the README's Flows list.", WRITE),
46
46
  define("GR1028", "structure", "error", "A list line has the wrong form", "Write list lines as `- name text`: the name, spaces, then the text.", WRITE),
47
+ define("GR1029", "structure", "warning", "An image line points outside grimoire/screenshots", "Keep screenshots in `grimoire/screenshots/` and write the path relative to the Markdown file, like `![Product page](../../../screenshots/web/product.png)`.", WRITE),
48
+ define("GR1030", "structure", "warning", "A flow has no summary", "Write one or two plain sentences under the flow's `# Title`: who does what, and what they get.", WRITE),
47
49
  define("GR2001", "links", "error", "A route step names a route that does not exist", "Fix the method and path in the flow, or add the route in code.", RECORD),
48
50
  define("GR2002", "links", "error", "A page step names a page that does not exist", "Fix the route path in the flow, or add the page to one of the feature's apps. A step scoped like `page /support [web-admin]` looks only in that app.", RECORD),
49
51
  define("GR2003", "links", "error", "A mail step names a mail that does not exist", "Use the mail's name as code defines it, or add the mail.", RECORD),
@@ -56,6 +58,8 @@ const GRIMOIRE_CODE_LIST = [
56
58
  define("GR2010", "links", "error", "A changelog entry names a flow that does not exist", "Fix the flow id before the `:`, or add the flow.", RECORD),
57
59
  define("GR2011", "links", "error", "A changelog entry names a criterion the flow does not have", "Fix the criterion id, or add the criterion to the flow.", RECORD),
58
60
  define("GR2012", "links", "error", "A README relation names a flow that does not exist", "Fix the `<feature>/<flow>` reference in Affects and affected by.", WRITE),
61
+ define("GR2013", "links", "error", "A case names a criterion the flow does not have", "Fix the `(AC-n)` at the end of the case line, or add the criterion under Acceptance criteria.", WRITE),
62
+ define("GR2014", "links", "warning", "An image line names a screenshot file that does not exist", "Add the image under `grimoire/screenshots/`, or fix the path.", WRITE),
59
63
  define("GR3001", "files", "warning", "A source file has no header sentence", "Start the file with a one-sentence comment saying why it exists.", FILE),
60
64
  define("GR3002", "files", "warning", "A source file belongs to no feature", "Add its folder to a feature's `folders`, or tag it `@feature <id>` in its header.", FILE),
61
65
  define("GR3003", "files", "error", "A source file has two owners", "Keep one owner: remove the duplicate folder from one feature, or keep one `@feature` tag.", FILE),
@@ -70,6 +74,8 @@ const GRIMOIRE_CODE_LIST = [
70
74
  define("GR4006", "tests", "error", "A test proving a criterion failed in its last run", "Fix the code or the test, then run the tests again.", RECORD),
71
75
  define("GR4007", "tests", "warning", "A criterion's test result is older than the test file", "Run the tests again.", RECORD),
72
76
  define("GR4008", "tests", "warning", "A criterion's test did not run in the last run", "Run the tests that prove the criterion.", RECORD),
77
+ define("GR4009", "tests", "warning", "Tests prove criteria but no test results are recorded", "Add `grimoireReporter()` from `@warlock.js/grimoire/vitest` to `test.reporters` in the Vitest config and run the tests; in production, ship the results file with the deploy.", RECORD),
78
+ define("GR4010", "tests", "warning", "The reporter could not match a proving test to its result", "Keep the `it(...)` or `test(...)` call on the line right under the `@proves` comment, with a plain string name.", RECORD),
73
79
  define("GR5001", "apps", "error", "A block points to a flow that does not exist", "Fix the `<feature>/<flow>` in the Flow column or the block file.", APP),
74
80
  define("GR5002", "apps", "error", "A condition is not declared in the app README", "Add the condition under Conditions in the app README, or use a declared one.", APP),
75
81
  define("GR5003", "apps", "error", "A page's route does not exist in its site", "Fix the `route` of the page file, or remove the page file if the page is gone.", APP),