app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit f20f1581d3e7edb532739d9b3881290dd675dded
parent b7e482fa2813e688dce88296e200a1cc9fa3260c
Author: triesap <tyson@radroots.org>
Date:   Sun, 11 Oct 2026 15:59:55 +0000

test: verify conformance fixture authenticity and separation (HCP-133)

- Freeze source and output hashes with exact producer selections.
- Refuse changed fixture bytes and false qualification claims.
- Isolate package-script fixtures and verify pinned Rust oracle parity.
- Preserve independent-client and deployed-host qualification gates.

Diffstat:
Aweb/tests/conformance/provenance.test.ts | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aweb/tests/conformance/provenance.ts | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aweb/tests/fixtures/provenance/qualified-inputs.v1.json | 194+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mweb/tests/provenance/source-boundaries.test.mjs | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aweb/tools/generate-qualified-fixture-manifest.mjs | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 558 insertions(+), 0 deletions(-)

diff --git a/web/tests/conformance/provenance.test.ts b/web/tests/conformance/provenance.test.ts @@ -0,0 +1,103 @@ +import assert from 'node:assert/strict'; +import { lstat, readFile } from 'node:fs/promises'; +import test from 'node:test'; +import { + provenanceInputPaths, + validateFixtureProvenance, + fixtureQualification +} from './provenance.ts'; +const root = new URL('../../../', import.meta.url); +const inputs = new Map<string, Uint8Array>(); +for (const path of provenanceInputPaths) { + const file = new URL(path, root); + const info = await lstat(file); + assert.ok( + info.isFile() && + !info.isSymbolicLink() && + info.nlink === 1 && + info.size > 0 && + info.size <= 1024 * 1024 + ); + const bytes = new Uint8Array(await readFile(file)); + assert.equal(bytes.byteLength, info.size); + inputs.set(path, bytes); +} +const manifest = JSON.parse( + await readFile( + new URL('../fixtures/provenance/qualified-inputs.v1.json', import.meta.url), + 'utf8' + ) +) as { + inputs: { path: string; bytes: number; sha256: string }[]; + producer: { + node: string; + rust_selection: string; + applesauce: Record<string, string>; + }; + qualification: Record<string, string>; +}; +void test('frozen public and qualified fixture inputs and outputs bind exact producer selection without claiming execution or independent interoperability', () => { + validateFixtureProvenance(manifest, inputs); + assert.equal(manifest.inputs.length, provenanceInputPaths.length); + assert.equal(manifest.producer.rust_selection, '1.99.0'); + assert.deepEqual(manifest.qualification, fixtureQualification); + for (const name of [ + 'food-qualified-writer-rust.v1.json', + 'message-qualified-writer-rust.v1.json' + ]) + assert.ok(manifest.inputs.some((row) => row.path.endsWith(name))); +}); +void test('every changed raw fixture or producer input byte fails against the frozen manifest even when JSON meaning is unchanged', () => { + for (const path of provenanceInputPaths) { + const changed = new Map(inputs); + const value = inputs.get(path)!; + const altered = new Uint8Array(value.byteLength + 1); + altered.set(value); + altered[value.byteLength] = 32; + changed.set(path, altered); + assert.throws(() => validateFixtureProvenance(manifest, changed), path); + } +}); +void test('missing, extra, empty and oversized source inputs fail before fixture qualification', () => { + for (const mutation of ['missing', 'extra', 'empty', 'oversized']) { + const changed = new Map(inputs); + if (mutation === 'missing') changed.delete(provenanceInputPaths[0]); + else if (mutation === 'extra') + changed.set('../outside.json', new Uint8Array([1])); + else + changed.set( + provenanceInputPaths[0], + new Uint8Array(mutation === 'empty' ? 0 : 1024 * 1024 + 1) + ); + assert.throws(() => validateFixtureProvenance(manifest, changed), mutation); + } +}); +void test('fixture descriptor, producer-version and false deployment or independent-client claims are refused', () => { + for (const mutation of [ + 'hash', + 'size', + 'path', + 'node', + 'rust', + 'sdk', + 'deployment', + 'client', + 'roundtrip' + ]) { + const changed = structuredClone(manifest); + if (mutation === 'hash') changed.inputs[0].sha256 = '0'.repeat(64); + else if (mutation === 'size') changed.inputs[0].bytes++; + else if (mutation === 'path') + changed.inputs[0].path = 'web/static/fixture.json'; + else if (mutation === 'node') changed.producer.node = '26.0.0'; + else if (mutation === 'rust') changed.producer.rust_selection = '1.97.1'; + else if (mutation === 'sdk') + changed.producer.applesauce['applesauce-core'] = '0.0.0'; + else if (mutation === 'deployment') + changed.qualification.deployment = 'PASS'; + else if (mutation === 'client') + changed.qualification.independent_client_receive_reply = 'PASS'; + else changed.qualification.sdk_roundtrips = 'FULL_INTEROP_PASS'; + assert.throws(() => validateFixtureProvenance(changed, inputs), mutation); + } +}); diff --git a/web/tests/conformance/provenance.ts b/web/tests/conformance/provenance.ts @@ -0,0 +1,133 @@ +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import { interopInputPaths } from './interop-manifest.ts'; + +export const provenanceInputPaths = [ + ...interopInputPaths, + 'contracts/interop/manifest.json', + 'contracts/interop/food_availability/oracle/Cargo.lock', + ...[ + 'corpus.v1.json', + 'source_profile.v1.json', + 'provenance.v1.json', + 'oracle/Cargo.toml', + 'oracle/Cargo.lock', + 'oracle/src/main.rs' + ].map((name) => 'contracts/interop/message/' + name), + ...[ + 'food-qualified-matrix.ts', + 'food-qualified-writer-rust.v1.json', + 'message-cases.ts', + 'message-qualified-matrix.ts', + 'message-qualified-writer-rust.v1.json', + 'provenance.ts' + ].map((name) => 'web/tests/conformance/' + name), + 'web/tests/fixtures/independent-nip17/public-outer-wires.v1.json', + 'web/tools/check-food-interop.mjs', + 'web/tools/check-message-interop.mjs', + 'web/tools/generate-qualified-fixture-manifest.mjs', + 'web/package.json', + 'web/pnpm-lock.yaml', + 'core/rust-toolchain.toml' +] as const; +export const fixtureQualification = { + frozen_fixtures: 'HASHED_SOURCE_AND_OUTPUT_BYTES', + rust_replays: 'CHECKED_VECTORS_NOT_FRESH_NATIVE_EXECUTION', + sdk_roundtrips: 'SAME_LIBRARY_NOT_INDEPENDENT_CLIENT', + published_nip17: 'PUBLIC_OUTER_SIGNATURES_ONLY_NO_DECRYPTION_CUSTODY', + deployment: 'NOT_QUALIFIED', + independent_client_receive_reply: 'NOT_QUALIFIED_HCM027_REQUIRED', + signing: 'NO_FIXTURE_KEYS_OR_OPERATOR_AUTHORIZATION' +} as const; +export function buildFixtureProvenance( + inputs: ReadonlyMap<string, Uint8Array> +) { + assert.deepEqual([...inputs.keys()].sort(), [...provenanceInputPaths].sort()); + assert.equal(new Set(provenanceInputPaths).size, provenanceInputPaths.length); + const bytes = (path: string) => { + const value = inputs.get(path); + assert.ok(value && value.byteLength > 0 && value.byteLength <= 1024 * 1024); + return value; + }; + const text = (path: string) => + new TextDecoder('utf-8', { fatal: true }).decode(bytes(path)); + const json = (path: string): unknown => JSON.parse(text(path)); + const pkg = json('web/package.json') as { + name: string; + version: string; + engines: { node: string; pnpm: string }; + packageManager: string; + dependencies: Record<string, string>; + devDependencies: Record<string, string>; + }; + assert.equal(pkg.name, 'harvestcircle_web'); + assert.equal(pkg.engines.node, '24.21.0'); + assert.equal(pkg.engines.pnpm, '12.9.1'); + assert.equal(pkg.packageManager, 'pnpm@12.9.1'); + assert.equal(pkg.devDependencies.prettier, '3.9.9'); + const channel = [ + ...text('core/rust-toolchain.toml').matchAll(/^channel = "([^"]+)"$/gmu) + ].map((match) => match[1]); + assert.deepEqual(channel, ['1.99.0']); + const revision = '189c49b74b4bafc142b00b76b296477931139e72'; + assert.deepEqual( + [ + ...text('radroots.lib.source-lock.v1.toml').matchAll( + /^revision = "([0-9a-f]{40})"$/gmu + ) + ].map((match) => match[1]), + [revision] + ); + for (const family of ['food_availability', 'message']) { + assert.ok( + text(`contracts/interop/${family}/oracle/Cargo.toml`).includes( + `rev = "${revision}"` + ) + ); + const corpus = json(`contracts/interop/${family}/corpus.v1.json`) as { + revision: string; + }; + assert.equal(corpus.revision, revision); + } + const publicOuter = json( + 'web/tests/fixtures/independent-nip17/public-outer-wires.v1.json' + ) as { source: { revision: string; scope: string }; cases: unknown[] }; + assert.equal( + publicOuter.source.revision, + '0046368a747c5c25ae2bec28bae0e537744c8f10' + ); + assert.match(publicOuter.source.scope, /outer ciphertext only/); + assert.equal(publicOuter.cases.length, 2); + return { + schema_version: 1, + producer: { + module: 'web/tests/conformance/provenance.ts', + generator: 'web/tools/generate-qualified-fixture-manifest.mjs', + node: pkg.engines.node, + pnpm: pkg.engines.pnpm, + package: pkg.name, + package_version: pkg.version, + rust_selection: channel[0], + rust_version_meaning: 'CHECKED_IN_SELECTION_NOT_AN_EXECUTION_RECEIPT', + applesauce: Object.fromEntries( + ['applesauce-core', 'applesauce-relay', 'applesauce-signers'].map( + (name) => [name, pkg.dependencies[name]] + ) + ), + formatter: pkg.devDependencies.prettier + }, + oracle: { repository: 'https://github.com/radrootslabs/lib', revision }, + qualification: fixtureQualification, + inputs: provenanceInputPaths.map((path) => ({ + path, + bytes: bytes(path).byteLength, + sha256: createHash('sha256').update(bytes(path)).digest('hex') + })) + }; +} +export function validateFixtureProvenance( + manifest: unknown, + inputs: ReadonlyMap<string, Uint8Array> +) { + assert.deepEqual(manifest, buildFixtureProvenance(inputs)); +} diff --git a/web/tests/fixtures/provenance/qualified-inputs.v1.json b/web/tests/fixtures/provenance/qualified-inputs.v1.json @@ -0,0 +1,194 @@ +{ + "schema_version": 1, + "producer": { + "module": "web/tests/conformance/provenance.ts", + "generator": "web/tools/generate-qualified-fixture-manifest.mjs", + "node": "24.21.0", + "pnpm": "12.9.1", + "package": "harvestcircle_web", + "package_version": "0.1.0", + "rust_selection": "1.99.0", + "rust_version_meaning": "CHECKED_IN_SELECTION_NOT_AN_EXECUTION_RECEIPT", + "applesauce": { + "applesauce-core": "6.2.0", + "applesauce-relay": "6.2.1", + "applesauce-signers": "6.2.3" + }, + "formatter": "3.9.9" + }, + "oracle": { + "repository": "https://github.com/radrootslabs/lib", + "revision": "189c49b74b4bafc142b00b76b296477931139e72" + }, + "qualification": { + "frozen_fixtures": "HASHED_SOURCE_AND_OUTPUT_BYTES", + "rust_replays": "CHECKED_VECTORS_NOT_FRESH_NATIVE_EXECUTION", + "sdk_roundtrips": "SAME_LIBRARY_NOT_INDEPENDENT_CLIENT", + "published_nip17": "PUBLIC_OUTER_SIGNATURES_ONLY_NO_DECRYPTION_CUSTODY", + "deployment": "NOT_QUALIFIED", + "independent_client_receive_reply": "NOT_QUALIFIED_HCM027_REQUIRED", + "signing": "NO_FIXTURE_KEYS_OR_OPERATOR_AUTHORIZATION" + }, + "inputs": [ + { + "path": "contracts/interop/food_availability/corpus.v1.json", + "bytes": 265507, + "sha256": "a8d23bf128facbb0752c8b78c826ff765ac033d66ab9d29609aba9940ad7b682" + }, + { + "path": "contracts/interop/food_availability/source_profile.v1.json", + "bytes": 90099, + "sha256": "dede1eb1f682ecd548e8cd3ccb251d298762e504e2588a73528e5f7a5b9eff21" + }, + { + "path": "contracts/interop/food_availability/provenance.v1.json", + "bytes": 6753, + "sha256": "ae0ee1ff898a6cc9da3a89fd56d2340bff54297995e5c6add2b9e0f5d20e3f0d" + }, + { + "path": "contracts/interop/food_availability/oracle/src/main.rs", + "bytes": 21448, + "sha256": "fd2ea8f79c72c17a682e9f27fe020e91933475c2a7218937da60fbb2d42e2432" + }, + { + "path": "contracts/interop/food_availability/oracle/Cargo.toml", + "bytes": 693, + "sha256": "09c93aea3f1714e9a44a1acbb7afad9300b4c9e5d54ed2ef90637bb39331cdc8" + }, + { + "path": "radroots.lib.source-lock.v1.toml", + "bytes": 511, + "sha256": "27de73ec96a4764c493afc1f03c15ad9d89cf0dc8ddd07680af24a66487eaffc" + }, + { + "path": "web/tests/conformance/food-writer-rust.v1.json", + "bytes": 29382, + "sha256": "a7920bfe0e1677c215b6f089e5fcf66dd3ce7e57842f0342164ab847c933f859" + }, + { + "path": "contracts/interop/food_availability/web_templates.v1.json", + "bytes": 33805, + "sha256": "afa91541c4a66b715d2c5eeb54a7cacd6e562024c56efc19464a2a11323721c0" + }, + { + "path": "contracts/interop/food_availability/numeric_boundaries.v1.json", + "bytes": 4741, + "sha256": "9789690d06e0453c6f5e85e5f9df57f01fb95cb4872f9dd420081cbeb313a105" + }, + { + "path": "contracts/interop/food_availability/oracle/tests/native_manifest.rs", + "bytes": 15785, + "sha256": "61b8ad6ee64bedd2f72705f7050e244abf744453bfb4305aa2032781baf85d5d" + }, + { + "path": "contracts/interop/food_availability/oracle/tests/support/mod.rs", + "bytes": 17427, + "sha256": "3ae2b0cebc224e5094c3c6a64a4941d88540f8a9a867c18dcdd62b279dc49262" + }, + { + "path": "contracts/interop/manifest.json", + "bytes": 112732, + "sha256": "c0b677114474290181efdbbf1fe92fb50a20dacbc562ae643f198d1c63e61bd6" + }, + { + "path": "contracts/interop/food_availability/oracle/Cargo.lock", + "bytes": 21648, + "sha256": "a0a888bea579a00cbfb85592104381ddd4995352b00742cd788f2436edd859cd" + }, + { + "path": "contracts/interop/message/corpus.v1.json", + "bytes": 134644, + "sha256": "27fb61b7d06133f6cf42456c0582d1246222755da80e034fa1a4f0c9e1669e19" + }, + { + "path": "contracts/interop/message/source_profile.v1.json", + "bytes": 18884, + "sha256": "bff36b4941decca5471389e0155fb6b4027dac485c3e547be05743a936b5bc5f" + }, + { + "path": "contracts/interop/message/provenance.v1.json", + "bytes": 1243, + "sha256": "ec18e9d72bc534af5d9547614169a9964f24f385f662721e3ba25a04b3160999" + }, + { + "path": "contracts/interop/message/oracle/Cargo.toml", + "bytes": 696, + "sha256": "11b7723cf9c13136a6eaecfdab1e0a4325ed1adfc2c27e7371e8f9b772992c1a" + }, + { + "path": "contracts/interop/message/oracle/Cargo.lock", + "bytes": 21651, + "sha256": "5c81a47d5b34ac7f16d2e118c8614f3e89b47abccec9818fceb9491132e2adc3" + }, + { + "path": "contracts/interop/message/oracle/src/main.rs", + "bytes": 6349, + "sha256": "290247c9151fb2490dc108a974eae7fe8633d085ee2d22c6aecbfb15306cd611" + }, + { + "path": "web/tests/conformance/food-qualified-matrix.ts", + "bytes": 2656, + "sha256": "8adfe9a6242fc64f4349480b97f683fb28634006ed3aa495c928ae62948817ea" + }, + { + "path": "web/tests/conformance/food-qualified-writer-rust.v1.json", + "bytes": 29075, + "sha256": "24188e22fe141eb811c87e94ab7d7f1b31b2cf0d6cddd7ded253fcc87f203f32" + }, + { + "path": "web/tests/conformance/message-cases.ts", + "bytes": 1665, + "sha256": "05266fd83dd3d9c4917e39485d0fb8558ba1d23ac77450765b91414807c358a2" + }, + { + "path": "web/tests/conformance/message-qualified-matrix.ts", + "bytes": 2559, + "sha256": "1691845f50734191904b25f36fd54a54ddb146550d317b8563ce49a36202f807" + }, + { + "path": "web/tests/conformance/message-qualified-writer-rust.v1.json", + "bytes": 12239, + "sha256": "60ea810651ae8f44ea217140f70a22711e6fe6edfc3956dd2b405b9ab78ee7aa" + }, + { + "path": "web/tests/conformance/provenance.ts", + "bytes": 4859, + "sha256": "868ddb89ca5301541eb7e08e7274bc3f70cc21ca27c8f5bfba9b437ba003e73a" + }, + { + "path": "web/tests/fixtures/independent-nip17/public-outer-wires.v1.json", + "bytes": 4339, + "sha256": "05158c7e03369bd3b7e589dd797adbec05010578756ddc34a9e40c2cc9e2c424" + }, + { + "path": "web/tools/check-food-interop.mjs", + "bytes": 11254, + "sha256": "8e8fa1419e6d38fc2aa6ce89d7de569ada6bce2186439c53d30a900dd9ade420" + }, + { + "path": "web/tools/check-message-interop.mjs", + "bytes": 10520, + "sha256": "d04f032aeaaffe29c8a522ad287c5e9d4534b949ef5f10500bbf729dd3bd2659" + }, + { + "path": "web/tools/generate-qualified-fixture-manifest.mjs", + "bytes": 1972, + "sha256": "e8caed8677ad86d9b1f82547d77ca411152ec9879f1386bbaf71451205bb45f3" + }, + { + "path": "web/package.json", + "bytes": 2209, + "sha256": "0728b95c9c1411daff56569eb1e80e1e4edf6803c8b3a7b94a811d9c06f4ee9a" + }, + { + "path": "web/pnpm-lock.yaml", + "bytes": 84588, + "sha256": "4212d73467bace66510af351f6f955421794b2cb6dfd1c988d927e68bc76a5fe" + }, + { + "path": "core/rust-toolchain.toml", + "bytes": 86, + "sha256": "065388cb682c606d7f02487e70f150afccd2326949c4c6247a9fc59f2334fe05" + } + ] +} diff --git a/web/tests/provenance/source-boundaries.test.mjs b/web/tests/provenance/source-boundaries.test.mjs @@ -2,6 +2,8 @@ import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; import { copyFile, + cp, + lstat, link, mkdir, mkdtemp, @@ -196,6 +198,24 @@ async function fixture(run) { await rm(directory, { recursive: true, force: true }); } } +/** Package runners regenerate launchers; give them an independent dependency tree. + * @param {string} directory + */ +async function isolateScriptDependencies(directory) { + const target = path.join(directory, 'node_modules'); + assert.equal((await lstat(target)).isSymbolicLink(), true); + assert.equal( + await realpath(target), + await realpath(path.join(root, 'node_modules')) + ); + await rm(target); + await cp(path.join(root, 'node_modules'), target, { + recursive: true, + verbatimSymlinks: true + }); + assert.equal((await lstat(target)).isDirectory(), true); +} + /** @param {string} directory */ async function confineSvelte(directory) { await rm(path.join(directory, 'node_modules')); @@ -635,6 +655,7 @@ for (const script of ['check', 'lint', 'build', 'test:unit', 'dev']) test(`actual ${script} stops on unsafe production edge`, async () => { await fixture(async ({ directory, put }) => { await put('src/routes/+page.ts', "void import('nostr-tools');"); + await isolateScriptDependencies(directory); const result = spawnSync('corepack', ['pnpm', 'run', script], { cwd: directory, encoding: 'utf8', @@ -873,6 +894,7 @@ for (const script of ['check', 'lint', 'build', 'test:unit', 'dev']) 'src/routes/+page.svelte', '<svelte:head><script src="/tests/provider.js"></script></svelte:head>' ); + await isolateScriptDependencies(directory); const result = spawnSync('corepack', ['pnpm', 'run', script], { cwd: directory, encoding: 'utf8', @@ -1628,6 +1650,7 @@ for (const command of ['check', 'lint', 'build', 'test:unit', 'dev']) 'src/routes/+page.svelte', "<a href={'java'+'script:import(\"nostr-tools\")'}>bad</a>" ); + await isolateScriptDependencies(directory); const result = spawnSync('corepack', ['pnpm', 'run', command], { cwd: directory, encoding: 'utf8', @@ -1926,6 +1949,7 @@ for (const command of ['check', 'lint', 'build', 'test:unit', 'dev']) test(`D07 actual ${command} stops before framework dispatch on SVG URL mutation`, async () => fixture(async ({ put, directory }) => { await put('src/routes/+page.svelte', smilMutation); + await isolateScriptDependencies(directory); const result = spawnSync('corepack', ['pnpm', 'run', command], { cwd: directory, encoding: 'utf8', @@ -2237,3 +2261,43 @@ test( }); } ); + +test('package-script fixtures preserve the primary generated dependency launcher', async () => { + await fixture(async ({ directory, put }) => { + const relative = 'node_modules/applesauce-signers/node_modules/.bin/nanoid'; + const primary = path.join(root, relative); + const before = await readFile(primary); + const primaryStat = await lstat(primary); + assert.equal(primaryStat.isFile(), true); + assert.equal(primaryStat.nlink, 1); + await isolateScriptDependencies(directory); + const isolated = path.join(directory, relative); + const isolatedStat = await lstat(isolated); + assert.equal(isolatedStat.isFile(), true); + assert.equal(isolatedStat.nlink, 1); + assert.notEqual( + `${isolatedStat.dev}:${isolatedStat.ino}`, + `${primaryStat.dev}:${primaryStat.ino}` + ); + assert.deepEqual(await readFile(isolated), before); + await writeFile( + isolated, + Buffer.concat([before, Buffer.from('\n# fixture-only mutation\n')]) + ); + assert.deepEqual(await readFile(primary), before); + await put('src/routes/+page.ts', "void import('nostr-tools');"); + const result = spawnSync('corepack', ['pnpm', 'run', 'check'], { + cwd: directory, + encoding: 'utf8', + timeout: 1800000 + }); + assert.equal(result.error, undefined); + assert.equal(result.status, 1, result.stdout + result.stderr); + assert.match(result.stderr, /forbidden production import nostr-tools/); + assert.doesNotMatch( + result.stdout, + /svelte-check found|vite v.*building|RUN\s+v/ + ); + assert.deepEqual(await readFile(primary), before); + }); +}); diff --git a/web/tools/generate-qualified-fixture-manifest.mjs b/web/tools/generate-qualified-fixture-manifest.mjs @@ -0,0 +1,64 @@ +// Explicit test-fixture generation only; ordinary conformance checks never write. +import assert from 'node:assert/strict'; +import { lstat, readFile, writeFile } from 'node:fs/promises'; +import { format } from 'prettier'; +import { + buildFixtureProvenance, + provenanceInputPaths, + validateFixtureProvenance +} from '../tests/conformance/provenance.ts'; +assert.equal(process.version, 'v24.21.0'); +const args = process.argv.slice(2); +assert.ok(args.length === 0 || (args.length === 1 && args[0] === '--write')); +const root = new URL('../../', import.meta.url); +const inputs = new Map(); +for (const path of provenanceInputPaths) { + const file = new URL(path, root); + const info = await lstat(file); + assert.ok( + info.isFile() && + !info.isSymbolicLink() && + info.nlink === 1 && + info.size > 0 && + info.size <= 1024 * 1024 + ); + const raw = new Uint8Array(await readFile(file)); + assert.equal(raw.byteLength, info.size); + inputs.set(path, raw); +} +const manifest = buildFixtureProvenance(inputs); +const output = new URL( + 'web/tests/fixtures/provenance/qualified-inputs.v1.json', + root +); +if (args[0] === '--write') { + try { + const info = await lstat(output); + assert.ok(info.isFile() && !info.isSymbolicLink() && info.nlink === 1); + } catch (error) { + if (error.code !== 'ENOENT') throw error; + } + await writeFile( + output, + await format(JSON.stringify(manifest), { parser: 'json', tabWidth: 2 }) + ); +} else { + const info = await lstat(output); + assert.ok( + info.isFile() && + !info.isSymbolicLink() && + info.nlink === 1 && + info.size > 0 && + info.size <= 1024 * 1024 + ); + validateFixtureProvenance(JSON.parse(await readFile(output, 'utf8')), inputs); +} +console.log( + JSON.stringify({ + result: 'PASS', + action: args[0] === '--write' ? 'EXPLICIT_GENERATION' : 'CHECK_ONLY', + inputs: manifest.inputs.length, + producer: manifest.producer, + qualification: manifest.qualification + }) +);