| 1 | import test from 'node:test' ; |
| 2 | import assert from 'node:assert/strict' ; |
| 3 | import {createHash} from 'node:crypto' ; |
| 4 | import {readFileSync} from 'node:fs' ; |
| 5 | import {avatar, recipe, createRng} from '../src/index.js' ; |
| 6 | // Observed v1 baselines. Do not regenerate silently after a visual change. |
| 7 | const fixtures = [ |
| 8 | ['fixture-6' , 'masks' , 'eec76b565ecb257360802cd4d5eb30913fffe97c06ba6b09a315db886c7603d0' ], |
| 9 | ['fixture-0' , 'creatures' , '31a91272a95cfd0a50fff7c6bd572ee84fa1af2b1c61392e9333214c10ae5783' ], |
| 10 | ['fixture-25' , 'botanical' , '10480b88ef9b36468996bd50bb88551b315eff332974b239de93db32f6fd6b0f' ], |
| 11 | ['fixture-1' , 'orbital' , '7f7a558f2d1ea95b4f4e0a5701c40ce2cbbe1b98e5bb6ff6a71fc57b340434ad' ], |
| 12 | ['fixture-11' , 'landscapes' , 'd773085a08b6cabc8924f3b2c0244d399f6f643e482e4403f747efddb41de59c' ], |
| 13 | ['fixture-2' , 'glyphs' , '8dfbbd3b67d1c29f0a4971a837a107d5e13c7a499a8433b7be7a45bc196385be' ], |
| 14 | ['fixture-4' , 'woven' , 'd1d0eecf83c96e3e573f9170f5bb950f27bdf5b32d334add4b2b0149a633e94c' ], |
| 15 | ['fixture-3' , 'machines' , '824c60f3de59713b1911793f299f585f85cf1ee190c03e13173f06f21309c719' ] |
| 16 | ]; |
| 17 | test('version 1 SVG bytes stay fixed for every family' , () => { |
| 18 | for (const [seed, family, digest] of fixtures) { |
| 19 | assert.equal(recipe(seed).family, family); |
| 20 | assert.equal(createHash('sha256' ).update(avatar(seed)).digest('hex' ), digest); |
| 21 | } |
| 22 | }); |
| 23 | test('version 1 PRNG and complete recipe stay fixed' , () => { |
| 24 | const rng = createRng('seedmark fixture' , 'layout' ); |
| 25 | assert.deepEqual(Array.from({length: 8}, () => rng.next()), [0.9326388167683035, 0.5709015629254282, 0.6208453709259629, 0.3309869400691241, 0.9687688224948943, 0.5534903716761619, 0.6713465694338083, 0.20093300566077232]); |
| 26 | assert.deepEqual(recipe('fixture-6' ), { |
| 27 | version: 1, family: 'masks' , palette: ['#422d26' , '#f8e8c8' , '#e8a04d' , '#72afa0' ], |
| 28 | layout: {variant: 0, flip: 1, tilt: -12}, silhouette: {variant: 3, width: 26, height: 39}, |
| 29 | features: {variant: 3, count: 5, accent: 0}, texture: {variant: 1, marks: 3} |
| 30 | }); |
| 31 | }); |
| 32 | test('public source stays portable and has no ambient entropy or external assets' , () => { |
| 33 | for (const name of ['index.js' , 'render.js' ]) { |
| 34 | const source = readFileSync(new URL(`../src/${name}` , import.meta.url), 'utf8' ); |
| 35 | assert(!/Math\.random|\bDate\b|\bperformance\b|\bprocess\b|\bdocument\b|\bwindow\b|node:|foreignObject|<script|<image|<text|\bid=/.test(source)); |
| 36 | } |
| 37 | }); |