okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
a3a10b90a
main
1/** 2* 0.2.10.1: the desktop app's Auto load uses the all-cards split engine wherever the Terminal does. The decision is Control's (strata_control/split_engine.py, `strata drafting plan`, 3* `strata split-engine apply`; tests/terminal/test_split_parallel.py); this file drives the host's load with a fake Control and checks what the host asks and starts: 4* no --no-split on the plan or the fetch, the MTP draft layer fetched through the existing installer step (gguf_dir, so the model is not fetched again), the split engine's 5* run config saved as the profile, a person's DFlash2 kept, a failed layer fetch ending in a working layer split with one plain note. Nothing here starts an engine. 6*/ 7import './helpers/isolate-profile.mjs' ; // a test run never writes the owner's real Strata profile 8import test from 'node:test' ; 9import assert from 'node:assert/strict' ; 10import { EventEmitter } from 'node:events' ; 11import { mkdtempSync , mkdirSync , readFileSync , rmSync , writeFileSync } from 'node:fs' ; 12import { join , dirname } from 'node:path' ; 13import { tmpdir } from 'node:os' ; 14import { createNativeControl } from '../server/native-control.mjs' ; 15import { createControl } from '../server/control-runtime.mjs' ; 16import { resolveDrafter as hostResolve } from '../server/native-settings.mjs' ; 17 18const SPLIT_PLAN = { ok :true , split :true , choice :'mtp' , drafter :'mtp' , needed :false , gb :0 , line :'Drafting: MTP (the all-cards split engine uses the MTP draft layer, 5.2 GB)' , serves :true }; 19const DFLASH2_PLAN = { ok :true , split :false , choice :'dflash2' , drafter :'dflash2' , needed :true , gb :1.2 , mtp_needed :false , mtp_gb :0 , line :'Drafting: DFlash2' , serves :true }; 20 21/** 22* A packaged install on two 48 GB cards. `plan(options, state)` answers `drafting plan` (state.installs says how many layer installs ran), `split(options, files)` answers `split-engine apply` 23* (it may write options.outPath), `installFails` makes the installer's MCP tool fail, `startFails` fails the first N engine starts. 24*/ 25function fixture ({ plan, split= null , installFails= false , startFails= 0 , metrics= {}, config= {} } = {}) { 26const root = mkdtempSync ( join ( tmpdir (), 'strata-splitapp-test-' )); 27const install = join ( root , 'install' ), data = join ( root , 'host-data' ), home = join ( root , 'home' ), modelsDir = join ( home , 'models' ); 28for ( const d of [ install , data , modelsDir ]) mkdirSync ( d , { recursive :true }); 29const earlier = process . env . STRATA_INSTALL_DIR ; 30process . env . STRATA_INSTALL_DIR = install ; 31const dataFolder = join ( root , 'Strata-data' ), modelFolder = join ( dataFolder , 'models' , 'UD-Q4_K_XL' ); 32const gguf = join ( modelFolder , 'Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00002.gguf' ); 33mkdirSync ( modelFolder , { recursive :true }); 34writeFileSync ( gguf , 'GGUF' ); writeFileSync ( gguf . replace ( '00001' , '00002' ), 'GGUF' ); 35const pack = join ( dataFolder , 'packs' , 'ud_q4_k_xl' ), mtp = join ( dataFolder , 'mtp' , 'rt' ); 36mkdirSync ( join ( pack , 'tokenizer' ), { recursive :true }); 37writeFileSync ( join ( pack , 'native_experts.txt' ), 'x' ); 38const configPath = join ( install , 'strata-ud_q4_k_xl.json' ); 39const args = [ '--pack' , pack , '--native' , gguf , '--ple-gguf' , gguf . replace ( '00001' , '00002' ), '--mtp' , mtp , '--max-context' , '131072' , '--kv' , 'int8' ]; 40writeFileSync ( configPath , JSON . stringify ({ exe :'component:strata-engine' , tokenizer :join ( pack , 'tokenizer' ), args, model_name :'qwen3.8-flash-next-ud_q4_k_xl' , port :8080 , gpu :[ 0 , 1 ], ...config })); 41writeFileSync ( process . env . STRATA_SETTINGS_FILE , JSON . stringify ({ data_dir :join ( root , 'host-owned' , 'Strata-data' ), data_dir_at :1700000000 })); 42const state = { installs :0 , planCalls :[], fetchCalls :[], splitCalls :[], saved :[], starts :0 , rpc :[] }; 43const control = { 44control :{ dir :join ( root , 'control' ), python :join ( root , 'control' , 'python' , 'python' ) }, version :'0.2.10' , 45async installedModels () { 46return { install_dir :install , models :[{ id :'ud_q4_k_xl' , name :'qwen3.8-flash-next-ud_q4_k_xl' , source_config :configPath , context_tokens :131072 , backend :'cuda' , component_status :'present' , missing :[], issue_codes :[] }] }; 47}, 48async engine () { return { usable :true , backend :'cuda' , components_dir :join ( root , 'c' ), engine :{ version :'0.1.56' , platform :'linux-x86_64' , backend :'cuda' , exe :join ( root , 'engine' , 'strata' ), root :join ( root , 'engine' ) } }; }, 49async draftingPlan ( options ) { state . planCalls . push ( options ); return typeof plan === 'function' ?plan ( options , state ) :plan ; }, 50async draftingFetch ( options ) { state . fetchCalls . push ( options ); return { ok :true , event :'result' , pack :null , skipped :false }; }, 51async splitEngine ( options ) { 52state . splitCalls . push ({ ...options , input :JSON . parse ( readFileSync ( options . configPath , 'utf8' )) }); 53if ( ! split ) return { ok :true , split :false , line :'' , warn :false , reasons :[], written :null }; 54return split ( options , state ); 55}, 56async saveProfile ( name , path ) { state . saved . push ( JSON . parse ( readFileSync ( path , 'utf8' ))); return {}; }, 57async start () { state . starts += 1 ; if ( state . starts <= startFails ) throw new Error ( 'The engine stopped: out of memory' ); return { ok :true , state :'ready' }; }, 58async stop () { return { ok :true }; }, 59}; 60const catalog = { families :[{ family :'qwen' , title :'Qwen3.8-Flash-Next' , about :'x' , images :false , experimental :false , sizes :[ 61{ id :'ud_q4_k_xl' , model :'UD-Q4_K_XL' , download_gb :22 , ram_needed_gb :60 , about :'x' , on_this_pc :'fits' , installed :true , images :false , experimental :false }] }], 62contexts :[ 32768 , 131072 ], recommendation :{ family :'qwen' , model :'UD-Q4_K_XL' , context :131072 }, context_note :'' }; 63const hardware = { ram_gb :256 , cpu :{ name :'cpu' , cores :32 }, engine_vendor :'nvidia' , gpus :[ 0 , 1 ]. map ( index => ({ index, name :'NVIDIA RTX A6000' , vendor :'nvidia' , vram_gb :48 , arch :86 , usable :true })) }; 64const spawnProcess = ( command , argv ) => { 65if ( ! String ( argv [ 0 ]). endsWith ( 'strata_mcp.py' )) throw new Error ( 'no process but the installer may be started in packaged mode: ' + command + ' ' + argv . join ( ' ' )); 66const child = new EventEmitter (); child . stdout = new EventEmitter (); child . stderr = new EventEmitter (); child . exitCode = null ; 67child . kill = () => { child . exitCode = 0 ; queueMicrotask (() => child . emit ( 'exit' , 0 )); return true ; }; 68child . stdin = { write ( line ) { 69const message = JSON . parse ( line ); if ( ! message . id ) return ; 70if ( message . method === 'tools/call' ) state . rpc . push ( message . params ); 71let result ; 72if ( message . method === 'initialize' ) result = { protocolVersion :'2024-11-05' }; 73else if ( message . method === 'tools/list' ) result = { tools :[ 'strata_models' , 'strata_status' , 'strata_install' , 'strata_remove' ]. map ( name => ({ name})) }; 74else if ( message . params . name === 'strata_models' ) result = { structuredContent :catalog }; 75else if ( message . params . name === 'strata_status' ) result = { structuredContent :{ hardware, recommendation :catalog . recommendation , install :null , running :[], summary :'x' } }; 76else if ( Object . keys ( message . params . arguments ?? {}). length === 0 ) result = { structuredContent :{ summary :'Install finished' , install :{ running :false , exit_code :0 } } }; 77else if ( message . params . arguments ?. confirm ) { 78if ( installFails ) result = { isError :true , structuredContent :{ error :'The download did not finish.' } }; 79else { state . installs += 1 ; mkdirSync ( mtp , { recursive :true }); writeFileSync ( join ( mtp , 'dense.bin' ), 'x' ); result = { structuredContent :{ summary :'Install started' , plan :{}, install :{ running :true , step :'1/7' } } }; } 80} else result = { structuredContent :{ summary :'Plan' , plan :{ title :'Qwen3.8-Flash-Next UD-Q4_K_XL' , download_gb :5.2 , disk_short :null } } }; 81queueMicrotask (() => child . stdout . emit ( 'data' , Buffer . from ( JSON . stringify ({ jsonrpc :'2.0' , id :message . id , result}) + String . fromCharCode ( 10 )))); 82} }; 83return child ; 84}; 85const fetcher = async url => String ( url ). endsWith ( '/metrics' ) ?Response . json ({ engine :metrics }) :Response . json ({ status :'ok' }); 86const native = createNativeControl ({ control, directory :data , spawnProcess, fetcher, requests :() => [], modelsDirectory :() => modelsDir , hardwareProbe :() => [ 0 , 1 ]. map ( index => ({ index, vram_gb :48 })) }); 87return { native, state, root, gguf, modelFolder, mtp, configPath, args, 88cleanup :() => { if ( earlier === undefined ) delete process . env . STRATA_INSTALL_DIR ; else process . env . STRATA_INSTALL_DIR = earlier ; rmSync ( root , { recursive :true , force :true }); } }; 89} 90const finish = async ( native , id ) => { for ( let i = 0 ; i < 1500 ; i ++ ) { const job = native . state (). jobs . find ( j => j . id === id ); if ( job . state !== 'running' ) return job ; await new Promise ( r => setTimeout ( r , 10 )); } throw new Error ( 'job did not finish' ); }; 91const load = ( f , args = {}) => f . native . operation ( 'load' , { model :'ud_q4_k_xl' , ...args }); 92 93/** The split engine's answer: the layer config with the split's engine and a lane count (Control's split_config, in miniature), written where the host asked. */ 94const splitAnswer = ( options ) => { 95const cfg = JSON . parse ( readFileSync ( options . configPath , 'utf8' )); 96const lanes = Math . min ( 8 , cfg . parallel ?? 6 ); 97writeFileSync ( options . outPath , JSON . stringify ({ ...cfg , exe :'/e/strata-split-2-sm86' , args :[ '--native' , cfg . args [ cfg . args . indexOf ( '--native' ) + 1 ], '--batch' , String ( lanes )], drafting :'mtp' , split_fallback :{ exe :cfg . exe , args :cfg . args , parallel :cfg . parallel }, split_engine_note :'Using the all-cards split engine on 2 cards.' })); 98return { ok :true , split :true , line :'Using the all-cards split engine on 2 cards.' , warn :false , reasons :[], cards :2 , written :options . outPath }; 99}; 100/** Before the layer is fetched Control says split + mtp_needed; after it, split with the layer here. */ 101const splitPlan = ( _options , state ) => state . installs === 0 ?{ ...SPLIT_PLAN , mtp_needed :true , mtp_gb :5.2 } :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 }; 102 103test ( 'no drafting call of the host carries --no-split by itself, and the flag is there for the failed layer fetch' , async () => { 104const calls = []; 105const control = createControl ({ control :{ dir :'C:/c' , python :'py' , cli :'strata.py' }, run :async args => { calls . push ( args ); return { code :0 , json :{ ok :true , event :'result' , serves :true , split :false }, text :'' , stderr :'' }; } }); 106await control . draftingPlan ({ mode :'auto' }); 107await control . draftingPlan ({ configPath :'C:/w/cfg.json' , mode :'auto' , family :'unsloth' , dataDir :'C:/d' }); 108await control . draftingFetch ({ configPath :'C:/w/cfg.json' , mode :'auto' }); 109assert . equal ( calls . length , 3 ); 110for ( const args of calls ) assert . ok ( ! args . includes ( '--no-split' ), args . join ( ' ' )); 111assert . deepEqual ( calls [ 2 ], [ 'drafting' , 'fetch' , '--config' , 'C:/w/cfg.json' , '--mode' , 'auto' , '--if-needed' , '--output' , 'jsonl' ]); 112await control . draftingPlan ({ configPath :'C:/w/cfg.json' , mode :'auto' , noSplit :true }); 113await control . draftingFetch ({ configPath :'C:/w/cfg.json' , mode :'auto' , noSplit :true }); 114assert . ok ( calls [ 3 ]. includes ( '--no-split' ) && calls [ 4 ]. includes ( '--no-split' )); 115await control . splitEngine ({ configPath :'C:/w/layer.json' , outPath :'C:/w/split.json' }); 116assert . deepEqual ( calls [ 5 ], [ 'split-engine' , 'apply' , '--config' , 'C:/w/layer.json' , '--out' , 'C:/w/split.json' , '--output' , 'json' ]); 117}); 118 119test ( '--engines-unloading is on the plan and the fetch only when the host asks for it' , async () => { 120const calls = []; 121const control = createControl ({ control :{ dir :'C:/c' , python :'py' , cli :'strata.py' }, run :async args => { calls . push ( args ); return { code :0 , json :{ ok :true , event :'result' , serves :true , split :false }, text :'' , stderr :'' }; } }); 122await control . draftingPlan ({ configPath :'C:/w/cfg.json' , mode :'auto' }); 123await control . draftingPlan ({ configPath :'C:/w/cfg.json' , mode :'auto' , unloading :true }); 124await control . draftingFetch ({ configPath :'C:/w/cfg.json' , mode :'auto' , unloading :true }); 125assert . ok ( ! calls [ 0 ]. includes ( '--engines-unloading' )); 126assert . ok ( calls [ 1 ]. includes ( '--engines-unloading' ) && calls [ 2 ]. includes ( '--engines-unloading' ), calls . map ( c => c . join ( ' ' )). join ( ' | ' )); 127}); 128 129/** Control as it answers on two cards that the app's own running engine holds: DFlash2 (and its fetch) unless the host says that engine is about to be unloaded. */ 130const busyWhileRunning = ( get ) => ( options ) => get (). native . state (). instances . length > 0 && options . unloading !== true ?DFLASH2_PLAN :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 }; 131 132test ( 'a model switch on two cards: the plan and the fetch say the running engine is about to be unloaded, so its memory is not busy and the split stays' , async () => { 133let f ; 134f = fixture ({ plan :busyWhileRunning (() => f ), split :splitAnswer }); 135try { 136await f . native . refresh ( true ); 137const first = await finish ( f . native , load ( f ). id ); 138assert . equal ( first . state , 'done' , first . error ); 139assert . equal ( f . state . planCalls . length > 0 && f . state . planCalls . every ( c => c . unloading !== true ), true , 'nothing is running at the first load: nothing to unload' ); 140const before = f . state . planCalls . length ; 141const second = await finish ( f . native , load ( f , { values :{ drafting :'mtp' } }). id ); // a different choice: a different engine, the first one is unloaded 142assert . equal ( second . state , 'done' , second . error ); 143const calls = f . state . planCalls . slice ( before ); 144assert . ok ( calls . length >= 1 && calls . every ( c => c . unloading === true ), JSON . stringify ( calls )); 145assert . equal ( f . state . fetchCalls . length , 0 , 'no DFlash2 drafter is fetched because of the old engine memory' ); 146assert . equal ( f . state . splitCalls . length , 2 , 'the split engine was asked at both loads' ); 147assert . equal ( f . native . state (). instances . length , 1 ); 148} finally { await f . native . close (); f . cleanup (); } 149}); 150 151test ( 'a model added beside the running one keeps the memory of the running one busy: the plan is not told to ignore it' , async () => { 152let f ; 153f = fixture ({ plan :busyWhileRunning (() => f ), split :splitAnswer }); 154try { 155await f . native . refresh ( true ); 156const first = await finish ( f . native , load ( f ). id ); 157assert . equal ( first . state , 'done' , first . error ); 158const before = f . state . planCalls . length ; 159await finish ( f . native , load ( f , { multiple :true , gpus :[ 0 ], values :{ drafting :'mtp' } }). id ); 160const calls = f . state . planCalls . slice ( before ); 161assert . ok ( calls . length >= 1 && calls . every ( c => c . unloading !== true ), JSON . stringify ( calls )); 162} finally { await f . native . close (); f . cleanup (); } 163}); 164 165test ( 'Auto on two cards: the MTP draft layer is fetched through the installer with the model\'s own folder, then the split engine\'s run config is what starts' , async () => { 166const f = fixture ({ plan :splitPlan , split :splitAnswer }); 167try { 168await f . native . refresh ( true ); 169const job = await finish ( f . native , load ( f ). id ); 170assert . equal ( job . state , 'done' , job . error ); 171// the plan: no --no-split, so Control's answer is the Terminal's 172assert . ok ( f . state . planCalls . length >= 2 ); 173assert . ok ( f . state . planCalls . every ( c => c . noSplit !== true ), 'the host never asks without the split here' ); 174// the layer: one installer call with drafter mtp, the model folder, and nothing that names a download of the model itself 175const real = f . state . rpc . filter ( p => p . name === 'strata_install' && p . arguments ?. confirm === true ); 176assert . equal ( real . length , 1 ); 177assert . equal ( real [ 0 ]. arguments . drafter , 'mtp' ); 178assert . equal ( real [ 0 ]. arguments . gguf_dir , dirname ( f . gguf ), 'the model\'s files folder, so the model is never fetched again' ); 179assert . equal ( f . state . installs , 1 ); 180assert . equal ( f . state . fetchCalls . length , 0 , 'no DFlash2 drafter is fetched for the split' ); 181// the start: Control was asked once, with the layer split config the app built (4 slots, the app\'s own keys), and the profile holds the split engine\'s config 182assert . equal ( f . state . splitCalls . length , 1 ); 183assert . equal ( f . state . splitCalls [ 0 ]. input . parallel , 4 , 'the app\'s default of 4 slots reaches the split as 4 lanes' ); 184assert . equal ( f . state . splitCalls [ 0 ]. input . host , '127.0.0.1' ); 185assert . ok ( f . state . splitCalls [ 0 ]. input . api_key ); 186assert . equal ( f . state . saved . length , 1 ); 187assert . equal ( f . state . saved [ 0 ]. exe , '/e/strata-split-2-sm86' ); 188assert . equal ( f . state . saved [ 0 ]. args [ f . state . saved [ 0 ]. args . indexOf ( '--batch' ) + 1 ], '4' ); 189assert . equal ( f . state . saved [ 0 ]. drafting , 'mtp' ); 190assert . equal ( f . state . saved [ 0 ]. split_fallback . parallel , 4 , 'the server\'s fallback keeps the app\'s slots' ); 191const instance = f . native . state (). instances [ 0 ]; 192assert . equal ( instance . status , 'ready' ); 193assert . equal ( instance . splitNote , 'Using the all-cards split engine on 2 cards.' ); 194assert . match ( f . native . state (). jobs . at ( - 1 ). details ?? '' , / Using the all-cards split engine on 2 cards\. / , 'the load says what runs' ); 195} finally { await f . native . close (); f . cleanup (); } 196}); 197 198test ( 'the layer is already on disk: no installer call, still the split' , async () => { 199const f = fixture ({ plan :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 }, split :splitAnswer }); 200try { 201await f . native . refresh ( true ); 202const job = await finish ( f . native , load ( f ). id ); 203assert . equal ( job . state , 'done' , job . error ); 204assert . equal ( f . state . rpc . filter ( p => p . name === 'strata_install' ). length , 0 ); 205assert . equal ( f . state . splitCalls . length , 1 ); 206assert . equal ( f . state . saved [ 0 ]. exe , '/e/strata-split-2-sm86' ); 207} finally { await f . native . close (); f . cleanup (); } 208}); 209 210test ( 'a person\'s DFlash2: the plan says layer split, DFlash2 is fetched as before, the split engine is never asked and the app keeps one request at a time' , async () => { 211const f = fixture ({ plan :DFLASH2_PLAN , split :splitAnswer }); 212try { 213await f . native . refresh ( true ); 214const job = await finish ( f . native , load ( f , { values :{ drafting :'dflash2' } }). id ); 215assert . equal ( job . state , 'done' , job . error ); 216assert . equal ( f . state . splitCalls . length , 0 ); 217assert . equal ( f . state . rpc . filter ( p => p . name === 'strata_install' ). length , 0 , 'no draft layer download' ); 218assert . equal ( f . state . fetchCalls . length , 1 ); 219assert . equal ( f . state . fetchCalls [ 0 ]. mode , 'dflash2' ); 220assert . ok ( f . state . fetchCalls [ 0 ]. noSplit !== true ); 221assert . equal ( f . state . saved [ 0 ]. exe , 'component:strata-engine' ); 222assert . equal ( f . state . saved [ 0 ]. parallel , undefined , 'DFlash2 answers one request at a time' ); 223} finally { await f . native . close (); f . cleanup (); } 224}); 225 226test ( 'Off keeps the layer split and the split engine is not asked' , async () => { 227const f = fixture ({ plan :{ ...DFLASH2_PLAN , choice :'off' , drafter :'off' , needed :false , gb :0 }, split :splitAnswer }); 228try { 229await f . native . refresh ( true ); 230const job = await finish ( f . native , load ( f , { values :{ drafting :'off' } }). id ); 231assert . equal ( job . state , 'done' , job . error ); 232assert . equal ( f . state . splitCalls . length , 0 ); 233assert . ok ( ! f . state . saved [ 0 ]. args . includes ( '--mtp' )); 234assert . equal ( f . state . saved [ 0 ]. exe , 'component:strata-engine' ); 235} finally { await f . native . close (); f . cleanup (); } 236}); 237 238test ( 'the draft layer for the split cannot be downloaded: one plain note, the plan is DFlash2\'s again (asked with --no-split), the split is not tried and the model loads on the layer split' , async () => { 239const f = fixture ({ 240installFails :true , split :splitAnswer , 241plan :( options ) => options . noSplit === true ?DFLASH2_PLAN :{ ...SPLIT_PLAN , mtp_needed :true , mtp_gb :5.2 }, 242}); 243try { 244await f . native . refresh ( true ); 245const job = await finish ( f . native , load ( f , { values :{ drafting :null } }). id ); // the Models screen's Load with Auto 246assert . equal ( job . state , 'done' , job . error ); 247assert . equal ( job . drafterNote , 'The MTP drafter could not be downloaded.' ); 248assert . match ( job . details ?? '' , / The MTP drafter could not be downloaded\. / ); 249assert . equal ( f . state . splitCalls . length , 0 , 'no layer, no split' ); 250assert . ok ( f . state . planCalls . some ( c => c . noSplit === true ), 'the plan is asked again as the app asked it in 0.2.10' ); 251assert . equal ( f . state . fetchCalls . length , 1 , 'the DFlash2 drafter is the fallback fetch' ); 252assert . equal ( f . state . fetchCalls [ 0 ]. noSplit , true , 'and Control is told, so it does not plan the split\'s layer again' ); 253assert . equal ( f . state . saved . length , 1 ); 254assert . equal ( f . state . saved [ 0 ]. exe , 'component:strata-engine' ); 255assert . equal ( f . native . state (). instances [ 0 ]. status , 'ready' ); 256} finally { await f . native . close (); f . cleanup (); } 257}); 258 259test ( 'a plain Auto restart with no draft layer on disk does not download it and does not stop: the load goes on, the split engine says no on its own' , async () => { 260// no values: a restart or a tuning run carries no choice, and a saved explicit MTP is not Auto 261const f = fixture ({ plan :{ ...SPLIT_PLAN , mtp_needed :true , mtp_gb :5.2 }, config :{ drafting :'mtp' } }); 262try { 263await f . native . refresh ( true ); 264const job = await finish ( f . native , load ( f ). id ); 265assert . equal ( job . state , 'done' , job . error ); 266assert . equal ( f . state . rpc . filter ( p => p . name === 'strata_install' ). length , 0 , 'a restart never downloads' ); 267assert . equal ( f . state . saved . length , 1 ); 268} finally { await f . native . close (); f . cleanup (); } 269}); 270 271test ( 'the split engine says no (a rule Control knows: engine package, RAM, context): the layer split config starts, nothing else changes' , async () => { 272const f = fixture ({ plan :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 } }); // splitEngine answers split:false 273try { 274await f . native . refresh ( true ); 275const job = await finish ( f . native , load ( f ). id ); 276assert . equal ( job . state , 'done' , job . error ); 277assert . equal ( f . state . splitCalls . length , 1 ); 278assert . equal ( f . state . saved [ 0 ]. exe , 'component:strata-engine' ); 279assert . equal ( f . state . saved [ 0 ]. parallel , 4 ); 280assert . equal ( f . native . state (). instances [ 0 ]. splitNote , undefined ); 281} finally { await f . native . close (); f . cleanup (); } 282}); 283 284test ( 'Control cannot be asked about the split: the layer split starts as it was' , async () => { 285const f = fixture ({ plan :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 }, split :async () => { throw new Error ( 'Control is busy' ); } }); 286try { 287await f . native . refresh ( true ); 288const job = await finish ( f . native , load ( f ). id ); 289assert . equal ( job . state , 'done' , job . error ); 290assert . equal ( f . state . saved [ 0 ]. exe , 'component:strata-engine' ); 291} finally { await f . native . close (); f . cleanup (); } 292}); 293 294test ( 'the server started the layer split because the split engine would not come up: the load says so in one line' , async () => { 295const f = fixture ({ plan :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 }, split :splitAnswer , metrics :{ split_fallback :true } }); 296try { 297await f . native . refresh ( true ); 298const job = await finish ( f . native , load ( f ). id ); 299assert . equal ( job . state , 'done' , job . error ); 300const lines = ( job . details ?? '' ). split ( '\n' ); 301assert . ok ( lines . includes ( 'The all-cards split engine could not start, so the normal layer split runs.' ), job . details ); 302assert . ok ( ! lines . some ( l => / ^Using the all-cards split engine / . test ( l )), 'not the line that said the split would run' ); 303} finally { await f . native . close (); f . cleanup (); } 304}); 305 306test ( 'the second try after a failed start is never the split: one request at a time on the layer split' , async () => { 307const f = fixture ({ plan :{ ...SPLIT_PLAN , mtp_needed :false , mtp_gb :0 }, split :splitAnswer , startFails :1 }); 308try { 309await f . native . refresh ( true ); 310const job = await finish ( f . native , load ( f ). id ); 311assert . equal ( job . state , 'done' , job . error ); 312assert . equal ( f . state . saved . length , 2 ); 313assert . equal ( f . state . saved [ 0 ]. exe , '/e/strata-split-2-sm86' ); 314assert . equal ( f . state . saved [ 1 ]. exe , 'component:strata-engine' ); 315assert . equal ( f . state . saved [ 1 ]. parallel , undefined ); 316assert . equal ( f . state . splitCalls . length , 1 , 'Control was asked once' ); 317assert . equal ( f . native . state (). instances [ 0 ]. splitNote , undefined , 'the line that said the split would run is gone' ); 318} finally { await f . native . close (); f . cleanup (); } 319}); 320 321test ( 'the word "split" reaches the Models screen: Auto is the MTP where Control says split, DFlash2 where it does not, and a person\'s DFlash2 stays' , () => { 322for ( const [ choice , split , want ] of [[ 'auto' , true , 'mtp' ], [ 'auto' , false , 'dflash2' ], [ 'dflash2' , true , 'dflash2' ], [ 'mtp' , true , 'mtp' ], [ 'off' , true , 'off' ]]) { 323assert . equal ( hostResolve ( choice , 'unsloth' , true , split ), want , ` ${ choice } split= ${ split } ` ); 324} 325}); 326 327test ( 'the hint of the Drafting setting and the Models screen say what Auto is on the split, with no new element' , () => { 328const read = rel => readFileSync ( new URL ( rel , import . meta. url ), 'utf8' ). replace ( / \r\n / g , '\n' ); 329assert . match ( read ( '../server/native-settings.mjs' ), / on two or more identical graphics cards that the all-cards split engine takes, it is that engine with the MTP draft layer / ); 330const screen = read ( '../src/components/NativeModels.tsx' ); 331assert . match ( screen , / const splitCards = native\?\.capabilities\?\.dflash2Split === true && cardsGpus\.length !== 1; / , 'one card chosen in the roles is not the split' ); 332assert . ok ( screen . indexOf ( 'const splitCards =' ) > 0 && screen . indexOf ( 'const splitCards =' ) < screen . indexOf ( 'const nowDrafter =' ), 'splitCards is declared before it is used' ); 333assert . match ( screen , / splitCards && drafting === 'auto' \? "Auto uses the all-cards split engine with the MTP draft layer: about \{0\} GB to download, once\." / ); 334const en = JSON . parse ( read ( '../src/locales/df2-en.json' )); 335const ids = Object . entries ( en ). filter (([, v ]) => / all-cards split engine / . test ( v )). map (([ k ]) => k ); 336assert . equal ( ids . length , 2 ); 337for ( const lang of [ 'zh' , 'ja' , 'de' , 'es' , 'ru' , 'pt' , 'ko' , 'fr' ]) { 338const cat = JSON . parse ( read ( `../src/locales/df2- ${ lang } .json` )); 339for ( const id of ids ) assert . ok ( cat [ id ] && cat [ id ] !== en [ id ], ` ${ id } in ${ lang } ` ); 340assert . equal (( cat [ ids [ 0 ]]. match ( / \{0\} / g ) ?? []). length , 1 , `the size slot in ${ lang } ` ); 341} 342});