// @requirements REQ-PRODUCT-STORAGE-LOCALIZATION REQ-PRODUCT-LOCALIZATION REQ-PRODUCT-STORAGE-EXCEPTIONS REQ-PRODUCT-CF-HOST import {test} from 'node:test'; import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import {JSDOM} from 'jsdom'; import {IDBFactory} from 'fake-indexeddb'; import {createStorageExceptions,createIndexedDBStorageExceptionJournal} from '@notabenda/core/storage-exceptions'; import {mountStorageExceptionControls} from '@notabenda/core/storage-exceptions/ui'; import {validateSiteConfig} from '@notabenda/core'; import {createAccessibilityAudit} from '../../scripts/accessibility-audit.mjs'; import {memoryJournal} from '../../packages/notabenda/test/storage-exception-helpers.mjs'; import {serveHost} from '../host.mjs'; const root=new URL('../dist/public/',import.meta.url),file=path=>readFile(new URL(path,root),'utf8'); test('Portuguese storage settings publish local assets and script-free legal pages without backend allocation',async()=>{ const html=await file('localization/storage/index.html'),d=new JSDOM(html).window.document,c=JSON.parse(await file('localization/storage/site.json'));assert.equal(d.documentElement.lang,'pt-BR');assert.equal(d.documentElement.dir,'ltr');assert.equal(validateSiteConfig(c,{mode:'preview'}).valid,true);assert.equal(validateSiteConfig(c,{mode:'production'}).valid,false);assert.equal(d.querySelectorAll('script[type=module]').length,1);assert.ok(d.querySelector('.demo-corner'));assert.equal(c.site.id,'juniper-storage-pt');assert.equal(c.consent,undefined);assert.equal(c.storage.some(s=>s.id==='consent-memory'||s.id==='recommendations-storage'),false);assert.deepEqual(c.jurisdictions,['GB']);assert.ok(c.storage.filter(s=>s.classification==='exception').every(s=>s.name.startsWith('juniper-storage-pt:')));assert.ok(d.getElementById('change-layout').disabled);assert.ok(d.getElementById('sample-interaction').disabled); const forbidden=()=>{throw Error('No backend allocation');},env={ASSETS:{fetch:async()=>new Response(html,{headers:{'Content-Type':'text/html'}})},WORKSPACE:{get:forbidden},DEMO_WORKSPACES:{get:forbidden}};const response=await serveHost(new Request('https://example.test/localization/storage/'),env);assert.equal(response.status,200);assert.equal(response.headers.get('Set-Cookie'),null);assert.match(response.headers.get('Content-Security-Policy'),/script-src 'self'; connect-src 'self'/); for(const node of d.querySelectorAll('script[src],link[rel=stylesheet]')){const path=node.getAttribute('src')??node.getAttribute('href');assert.ok(path.startsWith('/assets/'));assert.ok((await file(path.slice(1))).length);} for(const kind of ['privacy','cookies','terms']){const policy=await file('localization/storage/'+kind+'/index.html');assert.doesNotMatch(policy,/