okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b2d08647c
main
1// The Drafting choice in the app (MTP / DFlash2 / Off / Auto): the Models screen row, the setting the host saves, what the host asks Control before 2// a load, the download plan line, and the words in all nine languages. The table of which card gets which drafter lives in Python 3// (strata_control/drafting.py, tests/terminal/test_drafting.py); the app never reads it. 4import test from 'node:test' ; 5import assert from 'node:assert/strict' ; 6import { readFileSync } from 'node:fs' ; 7import { fileURLToPath } from 'node:url' ; 8import { NATIVE_FIELDS , APP_OWNED_FIELDS , validateNativeSettings , withoutDraftLayer } from '../server/native-settings.mjs' ; 9import { createControl } from '../server/control-runtime.mjs' ; 10 11const read = rel => readFileSync ( fileURLToPath ( new URL ( rel , import . meta. url )), 'utf8' ). replace ( / \r\n / g , '\n' ); 12 13test ( 'Drafting is a setting of the model with four choices, saved by the app itself' , () => { 14const field = NATIVE_FIELDS . find ( f => f . id === 'drafting' ); 15assert . ok ( field ); 16assert . deepEqual ( field . choices , [ 'auto' , 'mtp' , 'dflash2' , 'off' ]); 17assert . equal ( field . type , 'enum' ); 18assert . match ( field . hint , / Auto \(recommended\) / ); 19assert . match ( field . hint , / Qwen3\.8-Flash-Next / ); 20assert . match ( field . hint , / one at a time / ); 21assert . ok ( APP_OWNED_FIELDS . includes ( 'drafting' ), 'the engine\'s own source never lists it: the app applies it' ); 22for ( const ok of [ 'auto' , 'mtp' , 'dflash2' , 'off' ]) assert . deepEqual ( validateNativeSettings ({ drafting :ok }), { drafting :ok }); 23assert . deepEqual ( validateNativeSettings ({ drafting :null }), { drafting :null }, 'cleared = Auto' ); 24assert . throws (() => validateNativeSettings ({ drafting :'fastest' }), / Drafting: choose a supported option / ); 25}); 26 27test ( 'Off leaves the draft layer out of every start, the same as "Draft layer (MTP)" off' , () => { 28assert . deepEqual ( withoutDraftLayer ([ '--pack' , 'p' , '--mtp' , '/m' , '--spec' , '4' , '--spec-min-p' , '0.5' , '--batch-mtp' ]), [ '--pack' , 'p' , '--spec' , '4' ]); 29const source = read ( '../server/native-control.mjs' ); 30assert . match ( source , / \(cfg\.mtp===false\|\|cfg\.drafting==='off'\)&&Array\.isArray\(cfg\.args\)\)cfg\.args=withoutDraftLayer\(cfg\.args\) / ); 31}); 32 33test ( 'the Models screen offers the choice next to context, DFlash2 only for Qwen3.8-Flash-Next, and carries it to the plan and the load' , () => { 34const screen = read ( '../src/components/NativeModels.tsx' ); 35assert . match ( screen , / draftingOptions\(selectedSize\.sourceFamily \?\? selectedFamily\?\.family, native\?\.capabilities\?\.dflash2\) / ); 36assert . match ( screen , / draftingWords: Record<string, string> = \{ auto: 'Auto \(recommended\)', mtp: 'MTP', dflash2: 'DFlash2', off: 'Off' \} / ); 37const row = screen . slice ( screen . indexOf ( '<div className="native-choice__row">' ), screen . indexOf ( '{roleCards.length > 1 ? <GpuRoles' )); 38assert . ok ( row . indexOf ( 'Conversation context' ) < row . indexOf ( 'tr("Drafting")' ) && row . indexOf ( 'tr("Drafting")' ) < row . indexOf ( 'Computer use' ), 'in the same row, between context and computer use' ); 39assert . match ( row , / <Select ariaLabel=\{tr\("Drafting"\)\} / , 'the existing Select, no new component' ); 40assert . match ( screen , / setDrafting\(installed\.drafting \?\? 'auto'\) / , 'a model shows what it was saved with' ); 41assert . match ( screen , / const downloadValues = \{ \.\.\.values, \.\.\.\(draftingChoices \? \{ drafting \} : \{\}\) / ); 42assert . match ( screen , / \.\.\.\(draftingChoices \? \{ values: \{ drafting \} \} : \{\}\) / ); 43assert . match ( screen , / Choosing MTP downloads its drafter: about \{0\} GB, once\. / ); 44assert . match ( screen , / Choosing DFlash2 downloads its drafter: about \{0\} GB, once\. / ); 45assert . match ( screen , / resolveDrafter\(drafting, selectedSize\?\.sourceFamily \?\? selectedFamily\?\.family, native\?\.capabilities\?\.dflash2, splitCards\) / , 'the fit uses the drafter that is chosen, and the split word counts only with two or more cards' ); 46assert . match ( screen , / loadedSelected\?\.metrics\?\.engine\?\.drafting_note / , 'what the engine said is shown' ); 47}); 48 49test ( 'the host asks Control before a load, and Control decides (the app never reads the table)' , async () => { 50const calls = []; 51const control = createControl ({ control :{ dir :'C:/c' , python :'py' , cli :'strata.py' }, run :async ( args , options ) => { 52calls . push ({ args, options}); 53return args [ 1 ] === 'plan' 54 ?{ code :0 , json :{ ok :true , needed :true , gb :1.2 , line :'Drafting: DFlash2' }, text :'' , stderr :'' } 55 :{ code :0 , json :{ ok :true , event :'result' , pack :'C:/d/dflash2/x.pack' }, text :'' , stderr :'' }; 56} }); 57const plan = await control . draftingPlan ({ mode :'dflash2' , family :'gyro' , dataDir :'C:/d' }); 58assert . deepEqual ( calls [ 0 ]. args , [ 'drafting' , 'plan' , '--mode' , 'dflash2' , '--family' , 'gyro' , '--data-dir' , 'C:/d' , '--output' , 'json' ]); 59assert . equal ( plan . needed , true ); 60const events = []; 61await control . draftingFetch ({ configPath :'C:/w/cfg.json' , mode :'dflash2' , onEvent :e => events . push ( e ) }); 62assert . deepEqual ( calls [ 1 ]. args , [ 'drafting' , 'fetch' , '--config' , 'C:/w/cfg.json' , '--mode' , 'dflash2' , '--if-needed' , '--output' , 'jsonl' ]); 63assert . equal ( calls [ 1 ]. options . acquire , true , 'only this explicit step may reach the network' ); 64assert . equal ( calls [ 0 ]. options . acquire , undefined , 'planning never does' ); 65const failing = createControl ({ control :{ dir :'C:/c' , python :'py' , cli :'strata.py' }, run :async () => ({ code :5 , json :{ ok :false , error :{ code :'drafting_failed' , message :'The DFlash2 download did not finish.' } }, text :'' , stderr :'' }) }); 66await assert . rejects ( failing . draftingFetch ({ configPath :'x' }), / DFlash2 download did not finish / ); 67}); 68 69test ( 'a load fetches the drafter first, never stops for it, and says what ran' , () => { 70const source = read ( '../server/native-control.mjs' ); 71const prepare = source . slice ( source . indexOf ( 'async function prepareDrafter' ), source . indexOf ( 'function rememberSetting' )); 72assert . match ( prepare , / rememberSetting\(configFile,'drafting',asked===null\|\|asked==='auto'\?null:asked\) / , 'the choice is kept for the next load' ); 73assert . match ( prepare , / drafts\?\.needed!==true\)return / , 'only what Control says is needed is downloaded: DFlash2 for Auto and DFlash2, nothing for MTP and Off' ); 74assert . match ( prepare , / control\.draftingFetch\( / ); 75assert . match ( prepare , / catch\(error\)\{if\(job\.state==='running'\)\{job\.drafterNote=error\.message; / , 'a failed download leaves the MTP and the job says so' ); 76assert . match ( source , / await prepareDrafter\(job,args,cfg,configFile,drafts,\{noSplit\}\) / ); 77assert . match ( source , / drafts\?\.mtp_needed===true&&\(args\.values\?\.drafting!==undefined\|\|\(drafts\.split===true\|\|args\.firstLoad===true\)&& [ \s\S ] * ?\{ [ \s\S ] * ?await installMtpLayer / , 'a switch to the MTP fetches its layer once, from the Models screen own Load (and a plain Auto load when the plan says split, or the first load after a setup)' ); 78assert . match ( source , / async function noteDrafting\(job,instance,key\) / ); 79assert . match ( source , / instance\.status='ready';instance\.phase='idle';await noteDrafting\(job,instance,key\) / ); 80assert . match ( source , / typeof choice==='string'&&typeof control\.draftingPlan==='function' / , 'the plan lists the drafter Control says is needed' ); 81assert . match ( source , / drafting:cfg\.drafting\?\?'auto' / , 'the installed model reports its saved choice' ); 82}); 83 84test ( 'every sentence of the Drafting choice is in the catalog in all nine languages, with the same slots' , () => { 85const langs = [ 'en' , 'zh' , 'ja' , 'de' , 'es' , 'ru' , 'pt' , 'ko' , 'fr' ]; 86const catalogs = Object . fromEntries ( langs . map ( l => [ l , { ...JSON . parse ( read ( `../src/locales/ ${ l } .json` )), ...JSON . parse ( read ( `../src/locales/df2- ${ l } .json` )) }])); 87const idOf = text => Object . entries ( catalogs . en ). find (([, v ]) => v === text )?.[ 0 ]; 88const sentences = [ 'Drafting' , 'Auto (recommended)' , 'MTP' , 'DFlash2' , 89"Drafting: MTP (DFlash2 didn't fit)" , "Drafting: MTP (DFlash2 isn't available in this mode)" , 'Drafting: none in parallel slots (one token per request and step); a single request still drafts' , 'Drafting: MTP (DFlash2 is for Qwen3.8-Flash-Next only)' , 90"Drafting: MTP (the DFlash2 drafter isn't downloaded yet)" , 91'Choosing DFlash2 downloads its drafter: about {0} GB, once.' , 'Choosing MTP downloads its drafter: about {0} GB, once.' , 'Drafting: off (no drafter is downloaded yet)' , "Drafting: DFlash2 (the MTP drafter isn't downloaded yet)" , 92'The DFlash2 drafter could not be downloaded, so the model starts without a drafter. Loading the model…' , 'Downloading the MTP drafter…' , 'The MTP drafter could not be downloaded.' , 93'Downloading the DFlash2 drafter…' , 'Packing the DFlash2 drafter for the engine…' , 'The DFlash2 drafter is ready.' , 94'The DFlash2 drafter could not be downloaded, so the model starts with the MTP. Loading the model…' , 'Loading the model…' , 95// the DFlash2 option (df2-<lang>.json): the paragraph under the dropdown, the lines about the card, the two new notes 96"Drafting: MTP (DFlash2 isn't available on this graphics card)" , "There is no internet connection, so the DFlash2 drafter can't be downloaded now." , 97'On graphics cards like yours, DFlash2 was faster than MTP on some kinds of text and slower on others in our tests.' , 98'On graphics cards like yours, DFlash2 was slower than MTP in our tests.' , 'DFlash2 has not been tested on your graphics card yet.' , 'On your Mac, DFlash2 was faster than MTP on this model in our tests.' , 'DFlash2 is off by default on this graphics card for now; choose it in Drafting to use it.' , 'SSD: not needed' ]; 99const slots = t => ( t . match ( / \{\d + \} / g ) ?? []). sort (). join (); 100for ( const text of sentences ) { 101const id = idOf ( text ); 102assert . ok ( id , `" ${ text . slice ( 0 , 60 )} " is in the English catalog` ); 103for ( const l of langs ) { 104const t = catalogs [ l ][ id ]; 105assert . ok ( typeof t === 'string' && t . trim (), ` ${ id } in ${ l } ` ); 106assert . equal ( slots ( t ), slots ( text ), ` ${ id } in ${ l } has the same slots` ); 107if ( l !== 'en' && text . length > 25 ) assert . notEqual ( t , text , ` ${ id } is translated in ${ l } ` ); 108} 109} 110}); 111 112test ( 'the Drafting dropdown exists only where there is something to choose: Qwen3.8-Flash-Next (qwen, gyro, unsloth) on a computer whose engine can run DFlash2' , async () => { 113const { transform} = await import ( 'esbuild' ); 114const code = ( await transform ( read ( '../src/lib/drafting.ts' ), { loader :'ts' , format :'esm' })). code ; 115const { draftingChoices} = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 116const all = [ 'auto' , 'mtp' , 'dflash2' , 'off' ]; 117// the engine here cannot run it (Metal, Intel, no card), or Control has not answered yet: no dropdown for anyone 118for ( const family of [ 'qwen' , 'gyro' , 'unsloth' , 'coder' , 'swift' , undefined ]) { 119assert . equal ( draftingChoices ( family , false ), null , ` ${ family } , not served` ); 120assert . equal ( draftingChoices ( family , undefined ), null , ` ${ family } , Control has not answered` ); 121assert . equal ( draftingChoices ( family , null ), null ); 122} 123// it can: only the models it is for; the other families have the MTP and nothing to pick against it. 124assert . deepEqual ( draftingChoices ( 'qwen' , true ), all ); 125assert . deepEqual ( draftingChoices ( 'gyro' , true ), all ); 126assert . deepEqual ( draftingChoices ( 'unsloth' , true ), all , "Unsloth's quantizations are the same weights (DFlash2 measured on UD-Q4_K_XL)" ); 127for ( const family of [ 'coder' , 'swift' , 'nvfp4' , 'qwen36' , undefined ]) assert . equal ( draftingChoices ( family , true ), null , ` ${ family } , served` ); 128// the app learns it from Control, once, and false until Control answers 129const host = read ( '../server/native-control.mjs' ); 130assert . match ( host , / dflash2:dflash2Served===true,dflash2Support,dflash2Selq4,dflash2Split\} / ); 131assert . match ( host , / dflash2Served=p\.serves===true / ); 132assert . match ( host , / function probeDrafting\(\)\{if\(!packaged\|\|dflash2Served!==null / ); 133const screen = read ( '../src/components/NativeModels.tsx' ); 134assert . match ( screen , / \{tr\(draftingChoices \? <div className="native-choice__col"> / , 'no choices: no column' ); 135}); 136 137test ( 'Settings > Native engine settings hides the Drafting row where it has no choice; no row is kept for one model only' , () => { 138for ( const f of NATIVE_FIELDS ) assert . ok ( ! ( 'notForModel' in f ) && ! ( 'forModel' in f ), f . id ); 139assert . ok ( ! NATIVE_FIELDS . some ( f => f . id === 'ds_experts' ), 'the DeepSeek Speed row is gone' ); 140const settings = read ( '../src/components/NativeSettings.tsx' ); 141assert . match ( settings , / \(native\?\.fields \?\? \[\]\)\.filter\(f => \(f\.id !== 'drafting' \|\| draftingOffered\) / ); 142}); 143 144test ( 'the DFlash2 drafter is fetched only by the Models screen own Load: a restart, a tuning run or any other load never downloads' , () => { 145const source = read ( '../server/native-control.mjs' ); 146const prepare = source . slice ( source . indexOf ( 'async function prepareDrafter' ), source . indexOf ( 'function rememberSetting' )); 147assert . match ( prepare , / asked===undefined\|\|drafts\?\.needed!==true / , 'no explicit choice in this job: return before any fetch' ); 148const loadScreen = read ( '../src/components/NativeModels.tsx' ); 149assert . match ( loadScreen , / \.\.\.\(draftingChoices \? \{ values: \{ drafting \} \} : \{\}\) / , 'the screen passes the choice only when it showed the dropdown' ); 150const tune = source . slice ( source . indexOf ( "const loaded=await loadEngine(job,{model:args.model,multiple:false" ), source . indexOf ( "const loaded=await loadEngine(job,{model:args.model,multiple:false" ) + 140 ); 151assert . doesNotMatch ( tune , / values: / , 'the tuning run loads without a choice' ); 152}); 153 154test ( 'the paragraph under the dropdown is gone (owner, 11-01: people who care know what to do); the catalog words carry no verdict' , () => { 155const screen = read ( '../src/components/NativeModels.tsx' ); 156for ( const part of [ '7.8% faster than MTP on 19 short prompts' , '1.1% faster on long thinking' , 'faster on 21 of 23 prompts' , 'the answers were identical' ]) assert . ok ( ! screen . includes ( part ), part ); 157const en = JSON . parse ( read ( '../src/locales/df2-en.json' )); 158for ( const text of Object . values ( en )) for ( const word of [ 'recommend' , 'best ' , 'better' , 'should' ]) assert . ok ( ! text . toLowerCase (). includes ( word ), ` ${ word } in " ${ text . slice ( 0 , 50 )} "` ); 159}); 160 161test ( 'one drafter per run: Auto is DFlash2 where the engine has it, the same word in Python and in the app' , async () => { 162const { transform} = await import ( 'esbuild' ); 163const code = ( await transform ( read ( '../src/lib/drafting.ts' ), { loader :'ts' , format :'esm' })). code ; 164const ts = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 165const host = await import ( '../server/native-settings.mjs' ); 166for ( const [ choice , family , served ] of [[ 'auto' , 'qwen' , true ], [ undefined , 'gyro' , true ], [ 'auto' , 'unsloth' , true ], [ 'auto' , 'swift' , true ], [ 'auto' , 'nvfp4' , true ], [ 'auto' , 'qwen' , false ], [ 'auto' , 'coder' , true ], [ 'mtp' , 'qwen' , true ], [ 'dflash2' , 'qwen' , true ], [ 'off' , 'qwen' , true ], [ 'dflash2' , 'coder' , true ]]) { 167assert . equal ( ts . resolveDrafter ( choice , family , served ), host . resolveDrafter ( choice , family , served ), ` ${ choice } ${ family } ${ served } ` ); 168} 169assert . equal ( ts . resolveDrafter ( 'auto' , 'qwen' , true ), 'dflash2' ); 170assert . equal ( ts . resolveDrafter ( 'auto' , 'qwen' , null ), 'mtp' , 'Control has not answered: the MTP' ); 171assert . equal ( host . resolveDrafter ( 'auto' , 'Qwen3.8-Flash-Next-iq3_s' , true ), 'dflash2' , 'a run config model name works too' ); 172// the names setup.py writes (f"{family name}-{model.lower()}"): Unsloth's quantizations are DFlash2's; Swift, Coder and NVFP4 are not 173for ( const name of [ 'qwen3.8-flash-next-unsloth-ud-q4_k_xl' , 'qwen3.8-flash-next-unsloth-ud-iq4_xs' , 'qwen3.8-flash-next-unsloth-q8_0' , 'qwen3.8-flash-next-gyro-gyro-s' ]) assert . equal ( host . resolveDrafter ( 'auto' , name , true ), 'dflash2' , name ); 174for ( const name of [ 'qwen3.8-flash-next-coder-iq1_m' , 'qwen3.8-flash-next-nvfp4-nvfp4' , 'swift-1.5-iq2_xs' , 'qwen3.8-flash-next-unsloth' , 'qwen3.6-35b-a3b-ud-q4_k_xl' ]) assert . equal ( host . resolveDrafter ( 'auto' , name , true ), 'mtp' , name ); 175assert . equal ( ts . resolveDrafter ( 'auto' , 'unsloth' , true ), 'dflash2' ); 176assert . equal ( host . resolveDrafter ( 'auto' , 'unsloth' , true ), 'dflash2' ); 177}); 178 179test ( 'a new install fetches only the drafter it will use; the fit and the slot estimates use the drafter chosen' , async () => { 180const source = read ( '../server/native-control.mjs' ); 181assert . match ( source , / 'gguf_dir','drafter','mtp'\] / ); 182assert . match ( source , / resolveDrafter\(args\.drafting,args\.family,dflash2Served,dflash2Split\);if\(d==='dflash2'\)args=\{\.\.\.args,drafter:'dflash2'\} / , 'DFlash2: the installer leaves the MTP layer out' ); 183const { chooseParallel, MTP_VRAM_GB , DFLASH2_VRAM_GB } = await import ( '../server/native-parallel.mjs' ); 184assert . deepEqual ([ MTP_VRAM_GB , DFLASH2_VRAM_GB ], [ 1.08 , 0.89 ]); 185const config = { args :[ '--mtp' , '/m' , '--max-context' , '32768' ], model_name :'qwen3.8-flash-next-iq3_s' }; 186const hardware = { gpus :[{ index :0 , vram_gb :24 }] }; 187const solo = chooseParallel ({ config, hardware, drafter :'dflash2' }); 188assert . equal ( solo . slots , 1 ); 189assert . match ( solo . note , / one request at a time / ); 190assert . notEqual ( chooseParallel ({ config, hardware, drafter :'mtp' }). slots , 1 , 'the MTP keeps the slots Strata fills in' ); 191assert . equal ( chooseParallel ({ config, hardware, drafter :'dflash2' , values :{ parallel :4 } }). slots , 4 , 'a number the person chose stays (the start then loads the MTP and says so)' ); 192const two = { config :{ ...config , gpu :[ 0 , 1 ] }, hardware :{ gpus :[{ index :0 , vram_gb :24 }, { index :1 , vram_gb :24 }] } }; 193const split = chooseParallel ({ ...two , drafter :'dflash2' }); 194assert . equal ( split . slots , 1 , 'a layer split runs DFlash2 alone, one request at a time (owner 11-02)' ); 195assert . match ( split . note , / one request at a time / ); 196assert . ok ( chooseParallel ({ ...two , drafter :'mtp' }). slots > 1 , 'the MTP on a layer split keeps the slots Strata fills in' ); 197const fit = read ( '../src/lib/native-fit.ts' ); 198assert . match ( fit , / DRAFTER_VRAM_GB: Record<string, number> = \{ mtp: MTP_VRAM_GB, dflash2: DFLASH2_VRAM_GB, dflash2_selq4: DFLASH2_SELQ4_VRAM_GB, off: 0 \} / ); 199}); 200 201test ( 'a failed MTP download says one short line, not the installer text, and the Load goes on' , () => { 202const source = read ( '../server/native-control.mjs' ); 203const fn = source . slice ( source . indexOf ( 'async function installMtpLayer' ), source . indexOf ( 'async function prepareDrafter' )); 204assert . match ( fn , / job\.drafterNote='The MTP drafter could not be downloaded\.' / ); 205assert . doesNotMatch ( fn , / error\.message / ); 206}); 207 208test ( 'the drafter memory figures in the app are the ones strata_control/drafting.py holds (DRAFTER_MIB), and the page uses the true one' , async () => { 209const py = read ( '../../../strata_control/drafting.py' ); 210const table = JSON . parse ( py . match ( / ^DRAFTER_MIB = ( \{ [ ^ } ] * \} ) / m )[ 1 ]); 211const gb = mib => Math . floor ( mib / 10 + 0.5 ) / 100 ; // the same rounding as DRAFTER_GB (half up to 10 MiB) 212assert . deepEqual ( Object . keys ( table ). sort (), [ 'dflash2' , 'dflash2_selq4' , 'mtp' , 'off' ]); 213const parallel = await import ( '../server/native-parallel.mjs' ); 214assert . equal ( parallel . MTP_VRAM_GB , gb ( table . mtp )); 215assert . equal ( parallel . DFLASH2_VRAM_GB , gb ( table . dflash2 )); 216assert . equal ( parallel . DFLASH2_SELQ4_VRAM_GB , gb ( table . dflash2_selq4 )); 217assert . deepEqual ([ table . dflash2 , table . dflash2_selq4 , table . mtp ], [ 890 , 715 , 1082 ]); 218const fit = read ( '../src/lib/native-fit.ts' ); 219const num = name => Number ( fit . match ( new RegExp ( `export const ${ name } = ([0-9.]+);` ))[ 1 ]); 220assert . equal ( num ( 'MTP_VRAM_GB' ), gb ( table . mtp )); 221assert . equal ( num ( 'DFLASH2_VRAM_GB' ), gb ( table . dflash2 )); 222assert . equal ( num ( 'DFLASH2_SELQ4_VRAM_GB' ), gb ( table . dflash2_selq4 )); 223assert . match ( fit , / DRAFTER_VRAM_GB: Record<string, number> = \{ mtp: MTP_VRAM_GB, dflash2: DFLASH2_VRAM_GB, dflash2_selq4: DFLASH2_SELQ4_VRAM_GB, off: 0 \} / ); 224// Control's word reaches the page, and the page hands the fit the drafter it really loads 225const control = read ( '../server/native-control.mjs' ); 226assert . match ( control , / dflash2Selq4=p\.serves===true&&p\.selq4===true / ); 227assert . match ( control , / dflash2Support,dflash2Selq4,dflash2Split\} / ); 228assert . match ( read ( '../src/lib/native.ts' ), / dflash2Selq4\?:boolean / ); 229const page = read ( '../src/components/NativeModels.tsx' ); 230assert . match ( page , / const fitDrafter = nowDrafter === 'dflash2' && native\?\.capabilities\?\.dflash2Selq4 === true \? 'dflash2_selq4' : nowDrafter; / ); 231assert . match ( page , / drafter: fitDrafter / ); 232assert . doesNotMatch ( page , / drafter: nowDrafter / ); 233}); 234 235test ( 'where the all-cards split engine takes the start, Auto is the MTP in the label, the fit, the install and a plain Auto load (Control plan says so)' , async () => { 236const { transform} = await import ( 'esbuild' ); 237const code = ( await transform ( read ( '../src/lib/drafting.ts' ), { loader :'ts' , format :'esm' })). code ; 238const ts = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 239const host = await import ( '../server/native-settings.mjs' ); 240for ( const [ choice , family , served , split , want ] of [ 241[ 'auto' , 'qwen' , true , true , 'mtp' ], [ undefined , 'unsloth' , true , true , 'mtp' ], [ 'auto' , 'gyro' , true , true , 'mtp' ], 242[ 'auto' , 'qwen' , true , false , 'dflash2' ], [ 'auto' , 'qwen' , true , undefined , 'dflash2' ], [ 'auto' , 'qwen' , true , null , 'dflash2' ], 243[ 'dflash2' , 'qwen' , true , true , 'dflash2' ], [ 'mtp' , 'qwen' , true , true , 'mtp' ], [ 'off' , 'qwen' , true , true , 'off' ], 244[ 'auto' , 'qwen' , false , true , 'mtp' ], [ 'auto' , 'swift' , true , true , 'mtp' ], 245]) { 246assert . equal ( ts . resolveDrafter ( choice , family , served , split ), want , `ts ${ choice } ${ family } ${ served } ${ split } ` ); 247assert . equal ( host . resolveDrafter ( choice , family , served , split ), want , `host ${ choice } ${ family } ${ served } ${ split } ` ); 248} 249const source = read ( '../server/native-control.mjs' ); 250assert . match ( source , / dflash2Split=p\.split===true / , 'the probe reads the plan word' ); 251assert . match ( source , / drafts\?\.mtp_needed===true&&\(args\.values\?\.drafting!==undefined\|\|\(drafts\.split===true\|\|args\.firstLoad===true\)&&\(config\.drafting==null\|\|String\(config\.drafting\)\.toLowerCase\(\)==='auto'\)\) / , 252'a plain Auto load fetches the draft layer when the plan says split (or it is the first load after a setup); a saved explicit choice is left alone' ); 253assert . match ( read ( '../src/lib/native.ts' ), / dflash2Split\?:boolean / ); 254}); 255 256test ( 'the MTP fetch the app makes names the folder of the model own files, so the installer never downloads the model again' , () => { 257const source = read ( '../server/native-control.mjs' ); 258assert . match ( source , / async function installMtpLayer\(job,args,config\)\{ [ \s\S ] * ?const native=\(\(\)=>\{const a=\(config\.args\?\?\[\]\)\.map\(String\),i=a\.indexOf\('--native'\) [ \s\S ] * ?install\(job,\{family:fam\.family,model:size\.model,drafter:'mtp',vision:args\.vision\?\?\(config\.vision\?'yes':'no'\),\.\.\.\(native\?\{gguf_dir:dirname\(native\)\}:\{\}\)\}\) / ); 259}); 260 261test ( '0.2.10.1: the app plans and fetches like the Terminal (no --no-split), and Auto on a computer where Control says split is the MTP in the label and the fit' , async () => { 262const calls = []; 263const 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 }, text :'' , stderr :'' }; } }); 264await control . draftingPlan ({ mode :'auto' }); 265await control . draftingPlan ({ configPath :'C:/w/cfg.json' , mode :'auto' , family :'unsloth' , dataDir :'C:/d' }); 266await control . draftingFetch ({ configPath :'C:/w/cfg.json' , mode :'auto' }); 267assert . equal ( calls . length , 3 ); 268for ( const c of calls ) assert . ok ( ! c . args . includes ( '--no-split' ), c . args . join ( ' ' )); 269const { transform} = await import ( 'esbuild' ); 270const code = ( await transform ( read ( '../src/lib/drafting.ts' ), { loader :'ts' , format :'esm' })). code ; 271const ts = await import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 272const host = await import ( '../server/native-settings.mjs' ); 273for ( const split of [ false , undefined , null ]) { 274assert . equal ( ts . resolveDrafter ( 'auto' , 'unsloth' , true , split ), 'dflash2' ); 275assert . equal ( host . resolveDrafter ( 'auto' , 'unsloth' , true , split ), 'dflash2' ); 276} 277// Control's word split:true (capabilities.dflash2Split, read from `drafting plan` at start-up) makes Auto the MTP; a person's own DFlash2 stays 278assert . equal ( ts . resolveDrafter ( 'auto' , 'unsloth' , true , true ), 'mtp' ); 279assert . equal ( host . resolveDrafter ( 'auto' , 'unsloth' , true , true ), 'mtp' ); 280assert . equal ( ts . resolveDrafter ( 'dflash2' , 'unsloth' , true , true ), 'dflash2' ); 281assert . equal ( host . resolveDrafter ( 'dflash2' , 'unsloth' , true , true ), 'dflash2' ); 282assert . equal ( ts . resolveDrafter ( 'off' , 'unsloth' , true , true ), 'off' ); 283assert . match ( read ( '../server/native-control.mjs' ), / dflash2Split=p\.split===true / , 'the probe reads the split word of Control' ); 284assert . doesNotMatch ( read ( '../server/control-runtime.mjs' ), / '--no-split', '--output', 'json'\] | '--no-split', '--if-needed' / ); 285});