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.
57 lines
3.8 KiB
JavaScript
57 lines
3.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { transform } from 'esbuild';
|
|
import { migrateSetup } from '../server/setup.mjs';
|
|
const { code } = await transform(await readFile(new URL('../src/lib/lifecycle.ts', import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });
|
|
const { lifecyclePolicy } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
|
|
|
|
test('old setup steps map once and preserve selections and completed work', () => {
|
|
const choices = { variantId:'fixture', profile:'performance', contextLength:'8k', batch:1024, batchAuto:false };
|
|
const history = [{step:3, at:'fixture'}];
|
|
for (const [oldStep, expected] of [[1,1],[2,2],[3,2],[4,3],[5,4]]) {
|
|
const original = { step:oldStep, choices, history, dismissed:true, complete:false };
|
|
const migrated = migrateSetup(original);
|
|
assert.equal(migrated.step, expected); assert.equal(migrated.flowVersion, 2);
|
|
assert.deepEqual(migrated.choices, choices); assert.deepEqual(migrated.history, history);
|
|
assert.equal(migrated.dismissed, true); assert.equal(migrated.complete, false);
|
|
assert.deepEqual(migrateSetup(migrated), migrated);
|
|
assert.equal(original.step, oldStep);
|
|
}
|
|
});
|
|
|
|
test('shared lifecycle policy blocks queued, active, disconnected and unknown status', () => {
|
|
const idle = {connected:true, streaming:false, stats:{running:0, waiting:0}, busy:{}};
|
|
assert.equal(lifecyclePolicy(idle).allowed, true);
|
|
for (const patch of [
|
|
{stats:{running:0, waiting:2}}, {stats:{running:1, waiting:0}}, {streaming:true},
|
|
{connected:false}, {stats:null}, {stats:{running:0}}, {stats:{running:0,waiting:NaN}},
|
|
{busy:{restart:true}}, {busy:{unload:true}}, {busy:{'load:fixture':true}},
|
|
]) assert.equal(lifecyclePolicy({...idle, ...patch}).allowed, false, JSON.stringify(patch));
|
|
assert.match(lifecyclePolicy({...idle, stats:{running:0,waiting:2}}).reason, /2 queued/);
|
|
assert.match(lifecyclePolicy({...idle, stats:null}).reason, /unavailable/);
|
|
assert.equal(lifecyclePolicy({...idle, busy:{'install:fixture':true}}).allowed, true);
|
|
});
|
|
|
|
test('blocked lifecycle writes do not change config; save-only still works', async () => {
|
|
const { build } = await import('esbuild');
|
|
const { createRequire } = await import('node:module');
|
|
const { outputFiles } = await build({entryPoints:[new URL('../src/lib/store.ts',import.meta.url).pathname],bundle:true,write:false,platform:'node',format:'cjs'});
|
|
const mod={exports:{}}; new Function('require','module','exports','matchMedia',outputFiles[0].text)(createRequire(import.meta.url),mod,mod.exports,()=>({addEventListener(){},matches:false}));
|
|
const store=mod.exports; const originalFetch=globalThis.fetch; const requests=[];
|
|
globalThis.fetch=async (url, options) => {requests.push([url,options]); return new Response(JSON.stringify({expert:[],beginner:{contextLength:'recommended'},engine:{running:false}}),{status:200});};
|
|
try {
|
|
for (const stats of [null,{running:0,waiting:2}]) {
|
|
Object.assign(store.getState(),{connection:'live',serving:stats ? {stats} : null,library:{mode:'real',variants:[],loaded:'fixture'},busy:{}});
|
|
await assert.rejects(store.saveEngine({expert:[]},true,true),/unavailable|queued/);
|
|
assert.equal(await store.loadVariant('fixture'),false);
|
|
assert.equal(await store.unloadModel(),false);
|
|
assert.equal(await store.restartEngine(),false);
|
|
assert.equal(requests.length,0);
|
|
for(const toast of store.getState().toasts) store.holdToast(toast.id);
|
|
}
|
|
await store.saveEngine({expert:[]},true,false);
|
|
assert.equal(requests.length,1); assert.equal(requests[0][1].method,'PATCH');
|
|
} finally {globalThis.fetch=originalFetch; for(const toast of store.getState().toasts)store.holdToast(toast.id);}
|
|
});
|