// ⛔ static/ must reach the page from INSIDE A BUNDLE.
//
// The router filled /static/ by reading this directory at boot. favela-surface-android runs the
// surface from a bare-pack bundle, which packs only what the module graph imports — so on the phone the
// directory read failed, the catch made it an empty list, and every /static/*.js was a 404. composer.js
// never ran, photos went up with no level pyramid, and bsky got the post without its image.
//
// So the files are IMPORTED (as text), and this checks both halves: nothing reads the directory at
// runtime, and the imported set is exactly what is in static/ — the drift the directory read existed to
// prevent (a file added here and never named is a page that silently does nothing).
import test from 'brittle'
import fs from '#node:fs'
import { join } from '#node:path'
const ROOT = new URL('..', import.meta.url).pathname
test('★ the router does not read static/ from disk at runtime', (t) => {
const src = fs.readFileSync(join(ROOT, 'lib/router.js'), 'utf8')
t.absent(/readdirSync/.test(src), 'no directory read')
t.absent(/STATIC_DIR/.test(src), 'no path into static/ built at runtime')
})
test('★ every static/*.js is served, byte for byte, and nothing else', async (t) => {
const { STATIC } = await import('../lib/static-files.js')
const onDisk = fs.readdirSync(join(ROOT, 'static')).filter((f) => f.endsWith('.js')).sort()
t.ok(onDisk.length > 0, 'static/ has files')
t.alike([...STATIC.keys()].sort(), onDisk.map((f) => '/static/' + f), 'the served set IS the directory')
for (const f of onDisk) {
t.is(STATIC.get('/static/' + f), fs.readFileSync(join(ROOT, 'static', f), 'utf8'), f + ' is the file')
}
})