provenance.test.ts (3920B)
1 import assert from 'node:assert/strict'; 2 import { lstat, readFile } from 'node:fs/promises'; 3 import test from 'node:test'; 4 import { 5 provenanceInputPaths, 6 validateFixtureProvenance, 7 fixtureQualification 8 } from './provenance.ts'; 9 const root = new URL('../../../', import.meta.url); 10 const inputs = new Map<string, Uint8Array>(); 11 for (const path of provenanceInputPaths) { 12 const file = new URL(path, root); 13 const info = await lstat(file); 14 assert.ok( 15 info.isFile() && 16 !info.isSymbolicLink() && 17 info.nlink === 1 && 18 info.size > 0 && 19 info.size <= 1024 * 1024 20 ); 21 const bytes = new Uint8Array(await readFile(file)); 22 assert.equal(bytes.byteLength, info.size); 23 inputs.set(path, bytes); 24 } 25 const manifest = JSON.parse( 26 await readFile( 27 new URL('../fixtures/provenance/qualified-inputs.v1.json', import.meta.url), 28 'utf8' 29 ) 30 ) as { 31 inputs: { path: string; bytes: number; sha256: string }[]; 32 producer: { 33 node: string; 34 rust_selection: string; 35 applesauce: Record<string, string>; 36 }; 37 qualification: Record<string, string>; 38 }; 39 void test('frozen public and qualified fixture inputs and outputs bind exact producer selection without claiming execution or independent interoperability', () => { 40 validateFixtureProvenance(manifest, inputs); 41 assert.equal(manifest.inputs.length, provenanceInputPaths.length); 42 assert.equal(manifest.producer.rust_selection, '1.99.0'); 43 assert.deepEqual(manifest.qualification, fixtureQualification); 44 for (const name of [ 45 'food-qualified-writer-rust.v1.json', 46 'message-qualified-writer-rust.v1.json' 47 ]) 48 assert.ok(manifest.inputs.some((row) => row.path.endsWith(name))); 49 }); 50 void test('every changed raw fixture or producer input byte fails against the frozen manifest even when JSON meaning is unchanged', () => { 51 for (const path of provenanceInputPaths) { 52 const changed = new Map(inputs); 53 const value = inputs.get(path)!; 54 const altered = new Uint8Array(value.byteLength + 1); 55 altered.set(value); 56 altered[value.byteLength] = 32; 57 changed.set(path, altered); 58 assert.throws(() => validateFixtureProvenance(manifest, changed), path); 59 } 60 }); 61 void test('missing, extra, empty and oversized source inputs fail before fixture qualification', () => { 62 for (const mutation of ['missing', 'extra', 'empty', 'oversized']) { 63 const changed = new Map(inputs); 64 if (mutation === 'missing') changed.delete(provenanceInputPaths[0]); 65 else if (mutation === 'extra') 66 changed.set('../outside.json', new Uint8Array([1])); 67 else 68 changed.set( 69 provenanceInputPaths[0], 70 new Uint8Array(mutation === 'empty' ? 0 : 1024 * 1024 + 1) 71 ); 72 assert.throws(() => validateFixtureProvenance(manifest, changed), mutation); 73 } 74 }); 75 void test('fixture descriptor, producer-version and false deployment or independent-client claims are refused', () => { 76 for (const mutation of [ 77 'hash', 78 'size', 79 'path', 80 'node', 81 'rust', 82 'sdk', 83 'deployment', 84 'client', 85 'roundtrip' 86 ]) { 87 const changed = structuredClone(manifest); 88 if (mutation === 'hash') changed.inputs[0].sha256 = '0'.repeat(64); 89 else if (mutation === 'size') changed.inputs[0].bytes++; 90 else if (mutation === 'path') 91 changed.inputs[0].path = 'web/static/fixture.json'; 92 else if (mutation === 'node') changed.producer.node = '26.0.0'; 93 else if (mutation === 'rust') changed.producer.rust_selection = '1.97.1'; 94 else if (mutation === 'sdk') 95 changed.producer.applesauce['applesauce-core'] = '0.0.0'; 96 else if (mutation === 'deployment') 97 changed.qualification.deployment = 'PASS'; 98 else if (mutation === 'client') 99 changed.qualification.independent_client_receive_reply = 'PASS'; 100 else changed.qualification.sdk_roundtrips = 'FULL_INTEROP_PASS'; 101 assert.throws(() => validateFixtureProvenance(changed, inputs), mutation); 102 } 103 });