static.test.ts (2309B)
1 import { test } from 'node:test'; 2 import assert from 'node:assert/strict'; 3 import { readdir, readFile } from 'node:fs/promises'; 4 5 // Bootstrap output conformance only; Food/Message oracle parity is not qualified. 6 await test('actual static shell is prerendered and excludes controlled harness code', async () => { 7 const root = new URL('../../build/', import.meta.url); 8 const files = await readdir(root, { recursive: true, withFileTypes: true }); 9 assert.ok( 10 files.some((entry) => entry.isFile() && entry.name === 'index.html') 11 ); 12 const html = await readFile(new URL('index.html', root), 'utf8'); 13 assert.match(html, /<a[^>]*href="\/"[^>]*>HarvestCircle<\/a>/); 14 assert.match(html, /<title>HarvestCircle<\/title>/); 15 const fallback = await readFile(new URL('200.html', root), 'utf8'); 16 assert.notEqual(fallback, html); 17 assert.doesNotMatch(fallback, /<a[^>]*href="\/"[^>]*>HarvestCircle<\/a>/); 18 assert.match(fallback, /<script[\s\S]*_app\/immutable/); 19 // Admit the exact public SSR notice, while retaining the original scan 20 // against private state, runtime effects and fixture markers elsewhere. 21 const identityNotice = 22 '<p id="identity-navbar-status" role="status" tabindex="-1">Use your Nostr extension to choose your identity.</p>'; 23 assert.equal(html.split(identityNotice).length, 2); 24 assert.ok(!fallback.includes(identityNotice)); 25 for (const document of [html, fallback]) { 26 assert.doesNotMatch( 27 document.replace(identityNotice, ''), 28 /HC_TEST_ONLY_|nostr|private|draft|conversation|signEvent|indexedDB|WebSocket/i 29 ); 30 } 31 const metadata = await readFile(new URL('build-info.json', root), 'utf8'); 32 assert.equal( 33 metadata, 34 await readFile( 35 new URL('../../static/build-info.json', import.meta.url), 36 'utf8' 37 ) 38 ); 39 const provenance: unknown = JSON.parse(metadata); 40 assert.ok(provenance && typeof provenance === 'object'); 41 assert.deepEqual(Object.keys(provenance), [ 42 'web_source', 43 'radroots_oracle', 44 'dependency_locks' 45 ]); 46 for (const entry of files) { 47 if (!entry.isFile()) continue; 48 const content = await readFile(`${entry.parentPath}/${entry.name}`, 'utf8'); 49 assert.doesNotMatch( 50 content, 51 /HC_TEST_ONLY_|createRelayHarness|createStaticHarness|installControlledProvider/ 52 ); 53 } 54 });