interop-manifest.test.ts (3223B)
1 import assert from 'node:assert/strict'; 2 import { lstat, readFile } from 'node:fs/promises'; 3 import test from 'node:test'; 4 import { 5 interopInputPaths, 6 validateInteropManifest 7 } from './interop-manifest.ts'; 8 import { webTemplates } from './food-writer-cases.ts'; 9 const root = new URL('../../../', import.meta.url); 10 const inputs = new Map<string, Uint8Array>(); 11 for (const path of interopInputPaths) { 12 const file = new URL(path, root); 13 const info = await lstat(file); 14 assert.ok( 15 info.isFile() && 16 !info.isSymbolicLink() && 17 info.size > 0 && 18 info.size <= 1024 * 1024 19 ); 20 inputs.set(path, new Uint8Array(await readFile(file))); 21 } 22 const manifest = JSON.parse( 23 await readFile(new URL('contracts/interop/manifest.json', root), 'utf8') 24 ) as { 25 oracle: { revision: string }; 26 cases: { 27 id: string; 28 fixture: { path: string; sha256: string }; 29 expected: unknown; 30 participation: { 31 native_consumer: string; 32 typescript: string; 33 unsupported_reason: string | null; 34 }; 35 }[]; 36 }; 37 void test('one manifest binds forty public cases, sixteen website outputs and ten native boundaries to the pinned oracle', () => { 38 validateInteropManifest(manifest, inputs, webTemplates); 39 assert.equal(manifest.cases.length, 66); 40 assert.equal( 41 manifest.cases.filter( 42 (row) => row.participation.typescript === 'food_reader' 43 ).length, 44 18 45 ); 46 }); 47 for (const mutation of [ 48 'duplicate', 49 'missing', 50 'hash', 51 'revision', 52 'unsafe_path', 53 'expected', 54 'unqualified_native', 55 'unsupported' 56 ] as const) 57 void test(`shared manifest rejects ${mutation} without normalizing the difference`, () => { 58 const changed = structuredClone(manifest); 59 if (mutation === 'duplicate') changed.cases[1].id = changed.cases[0].id; 60 else if (mutation === 'missing') changed.cases.pop(); 61 else if (mutation === 'hash') 62 changed.cases[0].fixture.sha256 = '0'.repeat(64); 63 else if (mutation === 'revision') changed.oracle.revision = '0'.repeat(40); 64 else if (mutation === 'unsafe_path') 65 changed.cases[0].fixture.path = 'web/static/private.json'; 66 else if (mutation === 'expected') 67 changed.cases[13].expected = { outcome: 'excluded' }; 68 else if (mutation === 'unqualified_native') 69 changed.cases[0].participation.native_consumer = 'PASS'; 70 else changed.cases[0].participation.unsupported_reason = null; 71 assert.throws(() => validateInteropManifest(changed, inputs, webTemplates)); 72 }); 73 void test('changed raw bytes, missing input, wrong source pin and stale actual website output all fail', () => { 74 for (const mutation of ['bytes', 'missing', 'pin', 'builder'] as const) { 75 const changed = new Map(inputs); 76 let templates = webTemplates; 77 if (mutation === 'missing') changed.delete(interopInputPaths[0]); 78 else if (mutation === 'builder') templates = webTemplates.slice(1); 79 else if (mutation === 'pin') 80 changed.set( 81 'radroots.lib.source-lock.v1.toml', 82 new TextEncoder().encode('revision = "' + '0'.repeat(40) + '"\n') 83 ); 84 else changed.set(interopInputPaths[0], new TextEncoder().encode('{}')); 85 assert.throws(() => validateInteropManifest(manifest, changed, templates)); 86 } 87 });