okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4fb068a8c
main
1import test from 'node:test' ; 2import assert from 'node:assert/strict' ; 3import { readFile } from 'node:fs/promises' ; 4import { nativeFixture , finishJob } from './helpers/native-fixture.mjs' ; 5 6test ( 'a second model on a card another model uses still loads (recommend, never force); two cards, two models' , async () => { 7const f = nativeFixture (); 8try { 9await f . control . refresh ( true ); 10const load = async args => { const done = await finishJob ( f . control , f . control . operation ( 'load' , args ). id ); assert . equal ( done . state , 'done' , done . error ); return done ; }; 11await load ({ model :'iq2_xs' , gpus :[ 0 ], multiple :true }); 12await load ({ model :'iq3_s' , gpus :[ 1 ], multiple :true }); 13assert . deepEqual ( f . control . state (). instances . map ( i => [ i . model , i . gpus , i . status ]), [[ 'iq2_xs' , [ 0 ], 'ready' ], [ 'iq3_s' , [ 1 ], 'ready' ]]); 14await load ({ model :'iq3_s' , gpus :[ 0 ], multiple :true }); // the same card as the first model: allowed, and said on the card's row 15assert . equal ( f . control . state (). instances . length , 3 ); 16} finally { await f . cleanup (); } 17}); 18 19test ( 'the screens say which card a loaded model uses, prefer a free card for a second model, and show an unload refusal beside its button' , async () => { 20const models = await readFile ( new URL ( '../src/components/NativeModels.tsx' , import . meta. url ), 'utf8' ); 21assert . match ( models , / usedBy=\{i => usedBy\(\[i\]\)\} / ); 22assert . match ( models , / const busy = \(i: number\) => expert && multiple && usedBy\(\[i\]\)\.length > 0 / ); // a card another loaded model uses starts Off 23const roles = await readFile ( new URL ( '../src/components/GpuRoles.tsx' , import . meta. url ), 'utf8' ); 24assert . match ( roles , / tr\('In use by \{0\}', \[other\.join\(', '\)\]\) / ); 25assert . match ( models , / loadedAction\(`instances\/\$\{i\.id\}\/unload`\) / ); 26assert . match ( models , / loadedError \? <ErrorNotice message=\{loadedError\} / ); 27const control = await readFile ( new URL ( '../server/native-control.mjs' , import . meta. url ), 'utf8' ); 28assert . match ( control , / is already used by \$\{sharedWith\.label\}, so this model did not fit there / ); 29}); 30 31test ( 'usedBy is declared before the card choice that calls it (a const used earlier broke the Models page when Run multiple models was on)' , async () => { 32const models = await readFile ( new URL ( '../src/components/NativeModels.tsx' , import . meta. url ), 'utf8' ); 33assert . ok ( models . indexOf ( 'const usedBy = ' ) > 0 && models . indexOf ( 'const usedBy = ' ) < models . indexOf ( 'const recommended = ' )); 34}); 35 36test ( 'a model that failed to start is not offered in the chat model picker' , async () => { 37const picker = await readFile ( new URL ( '../src/components/ChatModelPicker.tsx' , import . meta. url ), 'utf8' ); 38assert . equal (( picker . match ( / native\?\.instances\.filter\(i => i\.status !== 'error'\)\.map / g ) ?? []). length , 2 ); 39}); 40 41import { friendlyModelName } from '../server/model-names.mjs' ; 42test ( 'a loaded model is named from the catalog (family and version), the file id only as a fallback' , async () => { 43const catalog = { families :[{ title :'Qwen3.8-Flash-Next' , sizes :[{ id :'q2_0' , model :'Q2_0' }] }, { title :'Qwen3.8-Flash-Next (Gyro)' , sizes :[{ id :'gyro-gyro-s' , model :'Gyro-S' }] }] }; 44assert . equal ( friendlyModelName ( catalog , 'q2_0' ), 'Qwen3.8-Flash-Next Q2_0' ); 45assert . equal ( friendlyModelName ( catalog , 'gyro-gyro-s' ), 'Qwen3.8-Flash-Next Gyro-S' ); 46assert . equal ( friendlyModelName ( catalog , 'nope' ), null ); 47assert . equal ( friendlyModelName ( null , 'q2_0' ), null ); 48const f = nativeFixture (); 49try { 50await f . control . refresh ( true ); 51const done = await finishJob ( f . control , f . control . operation ( 'load' , { model :'iq2_xs' }). id ); 52assert . equal ( done . state , 'done' , done . error ); 53assert . equal ( f . control . state (). instances [ 0 ]. label , 'Qwen3.8-Flash-Next IQ2_XS' ); 54} finally { await f . cleanup (); } 55}); 56 57test ( 'card names use the GPU numbering of the other screens, and the fit figures subtract the models that stay loaded' , async () => { 58const models = await readFile ( new URL ( '../src/components/NativeModels.tsx' , import . meta. url ), 'utf8' ); 59const roles = await readFile ( new URL ( '../src/lib/gpu-roles.ts' , import . meta. url ), 'utf8' ); 60assert . ok ( roles . includes ( '`GPU ${c.index + 1}`' )); // GPU 1 is card 0, as on every other screen 61assert . match ( await readFile ( new URL ( '../src/components/GpuRoles.tsx' , import . meta. url ), 'utf8' ), / \{gpuLabel\(c\)\} · \{c\.name\} / ); 62assert . match ( models , / const keptModels = expert && multiple / ); 63assert . match ( models , / inUse=\{keptModels\.length \? / ); 64const card = await readFile ( new URL ( '../src/components/PcFitCard.tsx' , import . meta. url ), 'utf8' ); 65assert . match ( card , / vramGb > 0 \? <FreeMeter label="Graphics memory" total=\{live\.vramTotalGb \?\? vramGb\} free=\{live\.freeVramGb\} / ); 66assert . match ( card , / <FreeMeter label="RAM" total=\{ramGb\} free=\{live\.freeRamGb\} / ); 67// the arithmetic itself 68const text = 'fits: needs 44 GB of the 273 GB available.' ; 69const gone = Math . round ( 14 + 27 ); 70assert . equal ( text . replace ( / of the ( \d + ) GB available / , ( _m , n ) => `of the ${ Math . max ( 0 , Number ( n ) - gone )} GB available` ), 'fits: needs 44 GB of the 232 GB available.' ); 71assert . equal ( 'RX 9070 (card 0) + RAM' . replace ( / \(card ( \d + ) \) / g , ( _m , n ) => `(GPU ${ Number ( n ) + 1 } )` ), 'RX 9070 (GPU 1) + RAM' ); 72});