|
| 1 | +/** |
| 2 | + * Which provenance kind each corpus area is allowed to use (#1417). |
| 3 | + * |
| 4 | + * The kind decides how strongly an entry is pinned: `mined` bytes are re-derived |
| 5 | + * from git history by `pnpm check:replay-compat`, `derived` bytes are only |
| 6 | + * digest-pinned inside the same editable manifest. Without this rule an entry |
| 7 | + * could be edited, relabelled `derived`, given a matching digest, and quietly |
| 8 | + * escape the historical verifier. So the area — not the manifest line — decides: |
| 9 | + * anything mined out of the replay suites must stay `mined` forever. |
| 10 | + */ |
| 11 | + |
| 12 | +import type { ReplayCompatEntry, ReplayCompatProvenance } from './manifest.ts'; |
| 13 | + |
| 14 | +const CORPUS_AREA_PROVENANCE_KIND: Readonly<Record<string, ReplayCompatProvenance['kind']>> = { |
| 15 | + // Mined from the git history of `test/integration/replays`. |
| 16 | + integration: 'mined', |
| 17 | + // Mined from the git history of `examples/test-app/replays`. |
| 18 | + examples: 'mined', |
| 19 | + // Composed from a release's own grammar/docs: no historical blob exists. |
| 20 | + docs: 'derived', |
| 21 | +}; |
| 22 | + |
| 23 | +function corpusArea(file: string): string { |
| 24 | + const area = file.split('/')[1]; |
| 25 | + if (!area || !file.startsWith('scripts/')) { |
| 26 | + throw new Error(`Corpus file "${file}" must live under scripts/<area>/.`); |
| 27 | + } |
| 28 | + return area; |
| 29 | +} |
| 30 | + |
| 31 | +export function requiredProvenanceKind(file: string): ReplayCompatProvenance['kind'] { |
| 32 | + const area = corpusArea(file); |
| 33 | + const kind = CORPUS_AREA_PROVENANCE_KIND[area]; |
| 34 | + if (!kind) { |
| 35 | + throw new Error( |
| 36 | + `Corpus area "${area}" has no declared provenance kind. Add it to CORPUS_AREA_PROVENANCE_KIND ` + |
| 37 | + `in test/replay-compat/provenance-rules.ts before adding entries under it.`, |
| 38 | + ); |
| 39 | + } |
| 40 | + return kind; |
| 41 | +} |
| 42 | + |
| 43 | +/** Human-readable violations, so the same rule can fail a test or a CI script. */ |
| 44 | +export function findProvenanceKindViolations( |
| 45 | + entries: readonly ReplayCompatEntry[], |
| 46 | +): readonly string[] { |
| 47 | + return entries.flatMap((entry) => { |
| 48 | + const required = requiredProvenanceKind(entry.file); |
| 49 | + if (entry.provenance.kind === required) return []; |
| 50 | + return [ |
| 51 | + `${entry.id}: entries under scripts/${corpusArea(entry.file)}/ must stay "${required}", ` + |
| 52 | + `but this one is "${entry.provenance.kind}". Reclassifying a mined script drops it out of ` + |
| 53 | + `pnpm check:replay-compat; keep the released blob id instead.`, |
| 54 | + ]; |
| 55 | + }); |
| 56 | +} |
0 commit comments