Files
strata/apps/host/tests/language-preferences.test.mjs
T
Niko1221 0b3299a019 apps/host: the owner's UI and the Node App Host
The UI source from the 14 October handoff (src/, public/, index.html, vite and
tsconfig, tests, audit-fixes, design docs) and the App Host (server/*.mjs): model
import and monitor routes, API-provider catalog and streaming (OpenAI chat, OpenAI Responses,
the Messages API), serving, tunnel, tasks, plus the host routes for Time-skip
(server/timeskip.mjs) and the tuning plan/reports. src/lib/time-skip.ts renders a real
job's own record.

The UI design is unchanged. The rebuild routed #/tuning to a new TunePanel; that is
reverted: src/screens/ModelRun.tsx and src/main.tsx are the handoff's again (#/tuning
goes where the handoff sends it), and src/components/TunePanel.tsx and
src/styles/tuning.css, which only that route used, are not carried over. Left out of
git on purpose: dist/ (build output), node_modules, and docs/evidence + docs/checkpoints
(170 MB of screenshots, kept in StrataSplit\evidence-archive).

From the owner's rebuild branch strata/rebuild-2026-10.
2026-10-15 10:24:09 +02:00

24 lines
2.0 KiB
JavaScript

import {test} from 'node:test';
import assert from 'node:assert/strict';
import {build} from 'esbuild';
import {createRequire} from 'node:module';
const bundle=await build({stdin:{contents:"export {getState,setLanguage,setFontFamily,resetAppearance} from './src/lib/store'; export {tr,currentLanguage} from './src/lib/i18n';",resolveDir:process.cwd()},bundle:true,write:false,platform:'node',format:'cjs'});
function open(saved){
const data=new Map(Object.entries(saved)),css=new Map(),root={dataset:{},style:{setProperty:(key,value)=>css.set(key,value),removeProperty:key=>css.delete(key)}};
const storage={getItem:key=>data.get(key)??null,setItem:(key,value)=>data.set(key,value),removeItem:key=>data.delete(key)};
const mod={exports:{}};
new Function('require','module','exports','localStorage','sessionStorage','matchMedia','document',bundle.outputFiles[0].text)(createRequire(import.meta.url),mod,mod.exports,storage,storage,()=>({matches:false,addEventListener(){}}),{documentElement:root,querySelector:()=>null});
return{...mod.exports,data,css,root};
}
test('saved language applies on the first render; language and installed font persist together',()=>{
const first=open({'strata.prefs.v2':JSON.stringify({language:'ko',fontFamily:''})});
assert.equal(first.currentLanguage(),'ko');assert.notEqual(first.tr('Settings'),'Settings');
first.setLanguage('pt');first.setFontFamily('Arial');
assert.equal(first.root.lang,'pt');assert.match(first.css.get('--st-font'),/^"Arial",system-ui/);
const second=open(Object.fromEntries(first.data));assert.equal(second.currentLanguage(),'pt');assert.equal(second.getState().fontFamily,'Arial');
second.setFontFamily('');assert.equal(second.css.has('--st-font'),false);assert.equal(second.getState().language,'pt');
});
test('invalid saved language falls back to English and font names reject control characters',()=>{
const app=open({'strata.prefs.v2':JSON.stringify({language:'unknown',fontFamily:'Arial\u0000'})});assert.equal(app.currentLanguage(),'en');assert.equal(app.getState().fontFamily,'Arial');
});