okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
361c8d94a
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { build } from 'esbuild' ; 4import { createEngineStep } from '../server/engine-step.mjs' ; 5 6/* DL99 (a Qwen3.6 UD-Q4_K_XL download that "stays at 99%"): what the setup wizard says and counts after the last byte. Replayed 7from the install job's own progress as the app host saw it on a real run (Boston 2026-11-15, phaseA-tests/dl99/out1). */ 8const compiled = await build ({ 9stdin :{ contents :"export * from './src/lib/download-eta'; export * from './src/lib/onboarding-download'; export * from './src/lib/i18n';" , resolveDir :process . cwd () }, 10bundle :true , write :false , platform :'node' , format :'esm' , 11}); 12const lib = await import ( `data:text/javascript;base64, ${ Buffer . from ( compiled . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 13lib . setTranslationLanguage ( 'en' ); 14 15const engineDone = { kind :'engine' , name :'Engine' , state :'done' , done_gb :0.67 , total_gb :0.67 }; 16const model = ( state , done ) => ({ kind :'model' , name :'Model files' , state, done_gb :done , total_gb :22.854 , files_done :state === 'done' ?1 :0 , files_total :1 }); 17const reader = ( state , done ) => ({ kind :'vision' , name :'Picture reader' , state, done_gb :done , total_gb :0.899 , files_done :state === 'done' ?1 :0 , files_total :1 }); 18 19test ( 'DL99: the wizard says what setup is doing (its own sentence), not "Downloading the picture reader" while the model file is checked' , () => { 20const checking = { running :true , step :'5/7: downloading Qwen3.6-35B-A3B UD-Q4_K_XL' , phase :'verify' , 21label :'Checking that the model files are complete (a few minutes for a big model; nothing is downloaded)' , 22download :{ file :'checking files' , done_gb :4.13 , total_gb :22.85 , remaining_gb :18.72 , percent :18 }, 23parts :[ model ( 'done' , 22.854 ), reader ( 'waiting' , 0 ), engineDone ] }; 24const progress = lib . installProgress ( checking ); 25assert . equal ( lib . guidedStatusText ( checking , progress ), 'Checking that the model files are complete (a few minutes for a big model; nothing is downloaded)' ); 26const tokenizer = { running :true , step :'6/7: preparing the model for Strata' , phase :'tokenizer' , label :'Preparing the tokenizer' , parts :[ engineDone ] }; 27assert . equal ( lib . guidedStatusText ( tokenizer , lib . installProgress ( tokenizer )), 'Preparing the tokenizer' ); 28// no sentence from setup yet: the part being fetched, as before 29const early = { running :true , parts :[ model ( 'downloading' , 3.1 ), reader ( 'waiting' , 0 )] }; 30assert . equal ( lib . guidedStatusText ( early , lib . installProgress ( early )), 'Downloading model files…' ); 31assert . equal ( lib . guidedStatusText ({ running :true }, undefined ), 'Preparing your model…' ); 32// a server that has not answered yet keeps its own waiting line first 33const waiting = { running :true , phase :'waiting' , label :'Waiting for huggingface.co to answer (25 s so far)' , parts :[ model ( 'downloading' , 0 )] }; 34assert . equal ( lib . guidedStatusText ( waiting , lib . installProgress ( waiting )), 'Waiting for huggingface.co to answer (25 s so far)' ); 35}); 36 37test ( 'DL99: the model check shows its own figure, not a frozen 96%; the counter does not call it "left to download"' , () => { 38const step = createEngineStep ({ control :null }); 39const checking = { running :true , step :'5/7: downloading' , label :'Checking…' , 40download :{ file :'checking files' , done_gb :4.13 , total_gb :22.85 , remaining_gb :18.72 , percent :18 }, 41parts :[ model ( 'done' , 22.854 ), reader ( 'waiting' , 0 )] }; 42const p = lib . installProgress ( step . merge ( checking )); 43assert . equal ( p . percent , 18 ); 44assert . ok ( Math . abs ( p . done_gb - 4.13 ) < 0.01 && Math . abs ( p . total_gb - 22.85 ) < 0.01 , JSON . stringify ( p )); 45const counter = lib . downloadCounter ( 23.8 , p , true ); 46assert . notEqual ( counter . label , 'GB left to download' ); 47}); 48 49test ( 'DL99: once every file is in, the bar says 100%, not 99% (and never 0.7 / 0.7 GB of the engine alone)' , () => { 50const done = { running :true , step :'6/7: preparing the model for Strata' , label :'Preparing the tokenizer' , 51parts :[ model ( 'done' , 22.854 ), reader ( 'done' , 0.899 ), engineDone ] }; 52const p = lib . installProgress ( done ); 53assert . equal ( p . percent , 100 ); 54assert . ok ( p . total_gb > 24 , JSON . stringify ( p )); 55const still = lib . installProgress ({ parts :[ model ( 'done' , 22.854 ), reader ( 'downloading' , 0.6 ), engineDone ] }); 56assert . ok ( still . percent < 100 && still . percent >= 96 , JSON . stringify ( still )); 57const almost = lib . installProgress ({ parts :[ model ( 'downloading' , 22.85 ), reader ( 'done' , 0.899 )] }); 58assert . equal ( almost . percent , 99 , 'a part still downloading stays below 100' ); 59}); 60 61const NOT_READY = "Your model is downloaded, but the engine for this PC isn't ready yet. Open Settings > About to install it." ; 62 63test ( 'DL99: an install that ended with every file in, for a model the missing engine keeps from being ready, says so on the wizard page' , async () => { 64const { readFileSync} = await import ( 'node:fs' ); 65// when: the job is done, the model is not ready, the engine for this PC is missing or can't be used 66assert . equal ( lib . engineNotReadyAfterInstall ( 'done' , false , false ), true ); 67assert . equal ( lib . engineNotReadyAfterInstall ( 'done' , undefined , false ), true , 'a model the list does not show as ready yet' ); 68assert . equal ( lib . engineNotReadyAfterInstall ( 'done' , true , false ), false , 'a ready model moves on to the next step' ); 69assert . equal ( lib . engineNotReadyAfterInstall ( 'done' , false , true ), false , 'a usable engine: not this case' ); 70assert . equal ( lib . engineNotReadyAfterInstall ( 'done' , false , undefined ), false , 'nothing known about the engine yet' ); 71assert . equal ( lib . engineNotReadyAfterInstall ( 'running' , false , false ), false , 'not while the job runs' ); 72assert . equal ( lib . engineNotReadyAfterInstall ( 'error' , false , false ), false , 'a failed job shows its own error' ); 73// the wizard shows the owner's sentence (11-15) for that case, through the translation catalog 74const page = readFileSync ( new URL ( '../src/components/GuidedSetup.tsx' , import . meta. url ), 'utf8' ); 75assert . ok ( page . includes ( `engineNotReadyAfterInstall(installJob?.state, installed?.ready, native?.engine?.usable) ? ` ), 'hooked to the install job, the model and the engine' ); 76assert . ok ( page . includes ( `tr(" ${ NOT_READY } ")` )); 77assert . equal ( lib . tr ( NOT_READY ), NOT_READY ); 78// all nine languages have it (scripts/make-engine-locales.py) 79const en = JSON . parse ( readFileSync ( new URL ( '../src/locales/engine-en.json' , import . meta. url ), 'utf8' )); 80const key = Object . keys ( en ). find ( k => en [ k ] === NOT_READY ); 81assert . ok ( key , 'in the English catalog' ); 82for ( const l of [ 'zh' , 'ja' , 'de' , 'es' , 'ru' , 'pt' , 'ko' , 'fr' ]) { 83const t = JSON . parse ( readFileSync ( new URL ( `../src/locales/engine- ${ l } .json` , import . meta. url ), 'utf8' ))[ key ]; 84assert . ok ( t && t !== NOT_READY && t . includes ( '>' ), ` ${ l } : ${ t } ` ); 85} 86await lib . loadCatalog ( 'de' ); 87lib . setTranslationLanguage ( 'de' ); 88assert . match ( lib . tr ( NOT_READY ), / ^Dein Modell ist heruntergeladen / ); 89lib . setTranslationLanguage ( 'en' ); 90});