import test from 'node:test'; import assert from 'node:assert/strict'; import {startRuntime} from '../src/startup.js'; import {validateSettings} from '../src/core.js'; test('older separate KV preferences become one precision',()=>{ const s=validateSettings({cacheK:'q8_0',cacheV:'f32'}); assert.equal(s.cacheK,'q8_0');assert.equal(s.cacheV,'q8_0'); }); test('cancel stops GPU startup even when the runtime never resolves',async()=>{ const controller=new AbortController();let stopped=0; const pending=startRuntime(()=>new Promise(()=>{}),{signal:controller.signal,stop:()=>stopped++}); controller.abort();await assert.rejects(pending,{name:'AbortError'});assert.equal(stopped,1); }); test('a runtime worker error rejects loading and stops its worker',async()=>{ let fail,stopped=0; const pending=startRuntime(()=>new Promise(()=>{}),{stop:()=>stopped++,onFailure:f=>{fail=f;}}); fail(new Error('Worker failed to initialize')); await assert.rejects(pending,/Worker failed/);assert.equal(stopped,1);assert.equal(fail,null); }); test('stalled startup times out without leaving the UI waiting',async()=>{ let stopped=0; await assert.rejects(startRuntime(()=>new Promise(()=>{}),{stop:()=>stopped++,timeoutMs:10}),/GPU setup did not finish/); assert.equal(stopped,1); }); test('successful startup removes cancellation and timeout handlers',async()=>{ let stopped=0;const controller=new AbortController(); assert.equal(await startRuntime(()=>42,{signal:controller.signal,stop:()=>stopped++,timeoutMs:10}),42); controller.abort();assert.equal(stopped,0); });