// Point the DB at a closed port before the pool is built; the settings read is // monkeypatched in every test that reaches it, so no query runs. process.env.DB_HOST = '127.0.0.1' process.env.DB_PORT = '59999' // A brand URL, so the og:image absolutization of an uploaded path is exercised // rather than being dead code in the test environment. process.env.BRAND_URL = process.env.BRAND_URL || 'https://shard.example' // BRAND_LOGO defaults to empty (no logo image rendered), which would make the // "og:image still comes from env" assertions below pass vacuously. process.env.BRAND_LOGO = process.env.BRAND_LOGO || '/brand/logo.png' const { test, afterEach, after } = require('node:test') const assert = require('node:assert/strict') // The cached, settings-aware HTML shell (docs/website/THEMING_AND_NAV.md §4.3). // Three properties are load-bearing enough to lock here: that an untouched // instance gets byte-for-byte the shell it got before this feature existed, that // a DB fault still serves a page, and that the steady state is one cached string // rather than a settings read per page view. const htmlShell = require('../src/utils/htmlShell') const settings = require('../src/model/settings/settings.model') const brand = require('../src/config/brand') const db = require('../src/utils/db') after(() => db.close()) const originalGetShellBrand = settings.getShellBrand afterEach(() => { settings.getShellBrand = originalGetShellBrand }) // A stand-in for the built client/dist/index.html: the two tags the shell // rewrites plus the stylesheet link the theme block has to follow. const TEMPLATE = ` Vite App
` // The shell app.js served BEFORE this phase, reproduced verbatim. The point of // the test is that this string and the new renderer's output are identical for // an instance with no brand_assets and no theme_visual row (§9), so it is copied // rather than imported. function legacyRenderIndexHtml(html) { const htmlEscape = (s) => String(s).replace( /[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]), ) const title = htmlEscape(brand.name) const desc = htmlEscape(brand.description) const tags = [ ``, ``, '', brand.url ? `` : '', brand.logo ? `` : '', '', ``, ``, brand.favicon ? `` : '', ] .filter(Boolean) .join('\n ') return html .replace(/[\s\S]*?<\/title>/i, `<title>${title}`) .replace(/()/i, `$1${desc}$2`) .replace(/<\/head>/i, ` ${tags}\n `) } // ── The byte-identical guarantee (§9) ───────────────────────────────── test('with no overrides the shell is byte-identical to the pre-feature one', () => { assert.equal(htmlShell.render(TEMPLATE, {}), legacyRenderIndexHtml(TEMPLATE)) }) test('an empty theme and empty assets are the same as no overrides at all', () => { // A row that parsed to nothing usable resolves to null/undefined rather than // to an empty block, or "reset" would leave a `', 'color': 'red' }, }) assert.match(html, /