import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { createHash } from 'node:crypto'; import { test } from 'node:test'; const read = path => readFile(new URL('../' + path, import.meta.url)); test('opt-in model is the unchanged licensed 4.57 MB foreground model', async () => { const bytes = await read('public/models/u2netp/model.onnx'); const manifest = JSON.parse(await read('public/models/u2netp/manifest.json')); assert.equal(bytes.length, 4574861); assert.equal(bytes.length, manifest.bytes); assert.equal(createHash('sha256').update(bytes).digest('hex'), manifest.sha256); assert.equal(manifest.sha256, '309c8469258dda742793dce0ebea8e6dd393174f89934733ecc8b14c76f4ddd8'); assert.match((await read('public/models/u2netp/LICENSES.txt')).toString(), /Apache|MIT/); }); test('worker uses local pixels, same-origin model and installed external WASM runtime', async () => { const source = (await read('src/cutout/cutout.worker.ts')).toString(); const runtime = JSON.parse(await read('node_modules/onnxruntime-web/package.json')); assert.match(source, /new OffscreenCanvas\(320,320\)/); assert.match(source, /context.drawImage\(image/); assert.match(source, /const MODEL='\/models\/u2netp\/model.onnx'/); assert.ok(source.includes(`const RUNTIME='${runtime.version}'`)); assert.match(source, /crypto.subtle.digest\('SHA-256',bytes\)/); assert.match(source, /ort.env.wasm.numThreads=1/); assert.equal([...source.matchAll(/\bfetch\(/g)].length, 1); assert.doesNotMatch(source, /FormData|XMLHttpRequest|sendBeacon|method:\s*['"]POST/); });