// payload-trees.test.mjs — the materialized trees are byte-identical to the // fixtures that used to sit on disk (sha256 measured before deletion, S1). import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync, readdirSync } from 'node:fs'; import { join, relative } from 'node:path'; import { createHash } from 'node:crypto'; import { PAYLOAD_TREES, materializeTree } from './payload-trees.mjs'; function walk(dir) { return readdirSync(dir, { withFileTypes: true, recursive: true }) .filter(e => e.isFile()) .map(e => join(e.parentPath, e.name)); } describe('payload-trees: materialized bytes match the retired on-disk fixtures', () => { for (const name of Object.keys(PAYLOAD_TREES)) { it(name, () => { const { dir, cleanup } = materializeTree(name); try { const written = walk(dir).map(f => relative(dir, f)).sort(); assert.deepEqual(written, Object.keys(PAYLOAD_TREES[name]).sort(), 'file set changed'); for (const [rel, { sha256 }] of Object.entries(PAYLOAD_TREES[name])) { const got = createHash('sha256').update(readFileSync(join(dir, rel))).digest('hex'); assert.equal(got, sha256, `${name}/${rel} differs from the retired fixture`); } } finally { cleanup(); } }); } });