okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1// Settings > Engine with the engine of a Qwen4 model shape (APP-WIN item 6): Control lists it as its own family ("shape:<shape>", title null); the page titles 2// the group with the model's catalog title (the shape's name when the catalog has none), never the family id; switch and delete pass the family through; 3// an install with no shape engine renders exactly as before (the page source still titles Control's groups with Control's title). 4import test from 'node:test' ; 5import assert from 'node:assert/strict' ; 6import { readFileSync as read } from 'node:fs' ; 7import { build } from 'esbuild' ; 8import { changeEngine } from '../server/engine-library.mjs' ; 9 10const built = await build ({ stdin :{ contents :"export * from './src/lib/engine-list';" , resolveDir :process . cwd () }, bundle :true , write :false , format :'esm' , platform :'node' , loader :{ '.json' :'json' } }); 11const { engineGroupTitle} = await import ( `data:text/javascript;base64, ${ Buffer . from ( built . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 12 13const catalog = [{ family :'qwen' , title :'Qwen3.8-Flash-Next' }, { family :'qwen4exp_q4_lite' , title :'Qwen4 Lite' }]; 14 15test ( 'the group heading: Control\'s title for Qwen, the model\'s catalog title for a shape, the shape\'s name without one; never the family id' , () => { 16assert . equal ( engineGroupTitle ({ family :'qwen' , title :'Qwen and other models' , engines :[] }, catalog ), 'Qwen and other models' ); 17assert . equal ( engineGroupTitle ({ family :'shape:q4_lite' , shape :'q4_lite' , title :null , engines :[] }, catalog ), 'Qwen4 Lite' ); 18assert . equal ( engineGroupTitle ({ family :'shape:q4_mid' , shape :'q4_mid' , title :null , engines :[] }, catalog ), 'q4_mid' ); 19assert . equal ( engineGroupTitle ({ family :'shape:q4_mid' , title :null , engines :[] }, null ), 'q4_mid' , 'no shape field: from the family, no catalog' ); 20for ( const g of [{ family :'shape:q4_lite' , shape :'q4_lite' , title :null , engines :[] }, { family :'shape:q4_mid' , title :null , engines :[] }]) 21assert . doesNotMatch ( engineGroupTitle ( g , catalog ), / shape: / ); 22}); 23 24test ( 'switch and delete take a shape family and pass it to Control; anything else is still refused' , async () => { 25const calls = []; 26const control = { useEngine :async a => { calls . push ([ 'use' , a ]); return { status :'switched' }; }, removeEngine :async a => { calls . push ([ 'remove' , a ]); return { status :'deleted' }; } }; 27assert . equal (( await changeEngine ( control , 'use' , { family :'shape:q4_lite' , folder :'0.1.59-windows-x86_64-cuda-cuda13' })). status , 200 ); 28assert . equal (( await changeEngine ( control , 'remove' , { family :'shape:q4_lite' , folder :'0.1.58-windows-x86_64-cuda-cuda13' })). status , 200 ); 29assert . deepEqual ( calls . map ( c => c [ 1 ]. family ), [ 'shape:q4_lite' , 'shape:q4_lite' ]); 30for ( const family of [ 'shape:' , 'shape:Q4' , 'shape:../x' , 'shapes:q4_lite' , 'q4_lite' , 'strata-q4-lite' ]) 31assert . equal (( await changeEngine ( control , 'use' , { family, folder :'a' })). status , 400 , family ); 32assert . equal ( calls . length , 2 ); 33}); 34 35test ( 'the page: Control\'s title when it has one (no change for an install without shape engines), the catalog-derived one otherwise' , () => { 36const page = read ( new URL ( '../src/components/SettingsEngine.tsx' , import . meta. url ), 'utf8' ); 37assert . match ( page , / \{groups\.length > 1 \? <h3 className="engine-group__title">\{group\.title \? tr\(group\.title\) : engineGroupTitle\(group, native\?\.catalog\?\.families\)\}<\/h3> : null\} / ); 38}); 39 40test ( 'the Use dialog (owner 11-09): a shape group says "{model} runs on engine {version} from its next start." with the group title; Strata keeps its sentence' , () => { 41const page = read ( new URL ( '../src/components/SettingsEngine.tsx' , import . meta. url ), 'utf8' ); 42assert . match ( page , / const useGroup = use \? groups\.find\(g => g\.family === use\.family\) : undefined; / ); 43assert . match ( page , / useGroup\?\.family\.startsWith\('shape:'\) \? tr\("\{0\} runs on engine \{1\} from its next start\. Your models and settings stay as they are\. You can switch back at any time\.", \[engineGroupTitle\(useGroup, native\?\.catalog\?\.families\), use\?\.version \?\? ''\]\) : tr\("Models you start from now on run on engine \{0\}\. Your models and settings stay as they are\. You can switch back at any time\." / ); 44// the words as the person reads them, with the owner's example 45const en = JSON . parse ( read ( new URL ( '../src/locales/engine-en.json' , import . meta. url ), 'utf8' )); 46const key = Object . keys ( en ). find ( k => en [ k ] === '{0} runs on engine {1} from its next start. Your models and settings stay as they are. You can switch back at any time.' ); 47assert . ok ( key , 'in the English catalog' ); 48const title = engineGroupTitle ({ family :'shape:q4_lite' , shape :'q4_lite' , title :null , engines :[] }, [{ family :'qwen4exp_q4_lite' , title :'Qwen4' }]); 49assert . equal ( en [ key ]. replace ( '{0}' , title ). replace ( '{1}' , '0.1.60' ), 'Qwen4 runs on engine 0.1.60 from its next start. Your models and settings stay as they are. You can switch back at any time.' ); 50for ( const lang of [ 'zh' , 'ja' , 'de' , 'es' , 'ru' , 'pt' , 'ko' , 'fr' ]) { 51const t = JSON . parse ( read ( new URL ( `../src/locales/engine- ${ lang } .json` , import . meta. url ), 'utf8' ))[ key ]; 52assert . ok ( t && t . includes ( '{0}' ) && t . includes ( '{1}' ), lang ); 53// only the first sentence is new: the reassurance is the existing translation of the Strata engine's sentence, word for word 54const use = JSON . parse ( read ( new URL ( `../src/locales/engine- ${ lang } .json` , import . meta. url ), 'utf8' )). et15 ; 55const rest = use . slice ( use . search ( / [ 。. ] \s */ ) + use . match ( / [ 。. ] \s */ )[ 0 ]. length ); 56assert . ok ( rest . length > 5 && t . endsWith ( rest ), lang + ': ' + t ); 57} 58assert . ok ( Object . values ( en ). includes ( 'Models you start from now on run on engine {0}. Your models and settings stay as they are. You can switch back at any time.' ), 'the Strata sentence is unchanged' ); 59});