|
| 1 | +/** |
| 2 | + * Manifest gates for the e2e suite. |
| 3 | + * |
| 4 | + * The linkage is inverted: test files cite the requirement id(s) they prove via |
| 5 | + * `verifies(...)` (helpers/verifies.ts) and requirements.ts is pure data. These |
| 6 | + * tests statically scan test/e2e/scenarios/*.test.ts for the cited ids and check them |
| 7 | + * against the manifest, plus the manifest's own internal consistency rules. |
| 8 | + */ |
| 9 | + |
| 10 | +import { readdirSync, readFileSync } from 'node:fs'; |
| 11 | +import path from 'node:path'; |
| 12 | +import { fileURLToPath } from 'node:url'; |
| 13 | + |
| 14 | +import { expect, test } from 'vitest'; |
| 15 | + |
| 16 | +import { REQUIREMENTS } from './requirements.js'; |
| 17 | + |
| 18 | +const E2E_DIR = path.dirname(fileURLToPath(import.meta.url)); |
| 19 | + |
| 20 | +interface VerifiesCall { |
| 21 | + file: string; |
| 22 | + /** Explicit `{ title: '...' }` passed to verifies(), if any (undefined for an untitled body). */ |
| 23 | + title: string | undefined; |
| 24 | + ids: string[]; |
| 25 | +} |
| 26 | + |
| 27 | +/** Statically scan test/e2e/scenarios/*.test.ts for `verifies(<ids>, ...)` calls. */ |
| 28 | +function scanVerifiesCalls(): VerifiesCall[] { |
| 29 | + const calls: VerifiesCall[] = []; |
| 30 | + const scenariosDir = path.join(E2E_DIR, 'scenarios'); |
| 31 | + const files = readdirSync(scenariosDir) |
| 32 | + .filter(f => f.endsWith('.test.ts')) |
| 33 | + .toSorted(); |
| 34 | + for (const file of files) { |
| 35 | + const text = readFileSync(path.join(scenariosDir, file), 'utf8'); |
| 36 | + // Each call spans from its header to the first column-0 close (`});` for an |
| 37 | + // untitled hugged call, `);` for a call expanded by an opts third argument). |
| 38 | + for (const m of text.matchAll(/verifies\(\s*('[^']*'|\[[^\]]*\])\s*,\s*async\s*\([\s\S]*?\n(?:\}\);|\);)/g)) { |
| 39 | + const ids = [...(m[1] ?? '').matchAll(/'([^']*)'/g)].map(x => x[1]).filter(id => id !== undefined); |
| 40 | + const title = m[0].match(/\{\s*title:\s*'([^']*)'\s*\}\s*\n?\);$/)?.[1]; |
| 41 | + calls.push({ file, title, ids }); |
| 42 | + } |
| 43 | + } |
| 44 | + return calls; |
| 45 | +} |
| 46 | + |
| 47 | +const CALLS = scanVerifiesCalls(); |
| 48 | +const CITED = new Set(CALLS.flatMap(c => c.ids)); |
| 49 | + |
| 50 | +test('every non-deferred requirement id is cited by at least one verifies() call', () => { |
| 51 | + const missing = Object.entries(REQUIREMENTS) |
| 52 | + .filter(([id, r]) => !r.deferred && !CITED.has(id)) |
| 53 | + .map(([id]) => id); |
| 54 | + expect(missing).toEqual([]); |
| 55 | +}); |
| 56 | + |
| 57 | +test('every cited requirement id exists in the manifest and is not deferred', () => { |
| 58 | + const bad: string[] = []; |
| 59 | + for (const c of CALLS) { |
| 60 | + for (const id of c.ids) { |
| 61 | + const req = REQUIREMENTS[id]; |
| 62 | + if (!req) bad.push(`${c.file}: a verifies() call cites unknown requirement '${id}'`); |
| 63 | + else if (req.deferred) bad.push(`${c.file}: a verifies() call cites deferred requirement '${id}'`); |
| 64 | + } |
| 65 | + } |
| 66 | + expect(bad).toEqual([]); |
| 67 | +}); |
| 68 | + |
| 69 | +test('every knownFailure with a test string names an explicit verifies() title that cites the requirement', () => { |
| 70 | + const bad: string[] = []; |
| 71 | + for (const [id, r] of Object.entries(REQUIREMENTS)) { |
| 72 | + for (const kf of r.knownFailures ?? []) { |
| 73 | + if (kf.test === undefined) continue; |
| 74 | + const cited = CALLS.some(c => c.title === kf.test && c.ids.includes(id)); |
| 75 | + if (!cited) |
| 76 | + bad.push( |
| 77 | + `${id}: knownFailure references title '${kf.test}', which is not an explicit verifies() title citing this requirement` |
| 78 | + ); |
| 79 | + } |
| 80 | + } |
| 81 | + expect(bad).toEqual([]); |
| 82 | +}); |
| 83 | + |
| 84 | +test('every transport-restricted requirement explains why in note', () => { |
| 85 | + const missing = Object.entries(REQUIREMENTS) |
| 86 | + .filter(([, r]) => r.transports !== undefined && !r.note) |
| 87 | + .map(([id]) => id); |
| 88 | + expect(missing).toEqual([]); |
| 89 | +}); |
| 90 | + |
| 91 | +test('every supersedes reference points at an existing requirement id', () => { |
| 92 | + for (const [id, req] of Object.entries(REQUIREMENTS)) { |
| 93 | + if (req.supersedes !== undefined) { |
| 94 | + expect(REQUIREMENTS[req.supersedes], `${id} supersedes unknown id '${req.supersedes}'`).toBeDefined(); |
| 95 | + } |
| 96 | + } |
| 97 | +}); |
0 commit comments