okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1/** 2* The model's own choices outlive setup: "Draft layer (MTP)" off, picture reading off, a context size set by hand. 3* Setup writes --mtp, --spec-min-p and --vision into the arguments every time it runs; the host applies the saved choices on every 4* load. Nothing here starts an engine; Control is a fake that records what the host saved and asked it to start. 5*/ 6import './helpers/isolate-profile.mjs' ; // a test run never writes the owner's real Strata profile 7import test from 'node:test' ; 8import assert from 'node:assert/strict' ; 9import { mkdtempSync , mkdirSync , readFileSync , rmSync , writeFileSync } from 'node:fs' ; 10import { join } from 'node:path' ; 11import { tmpdir } from 'node:os' ; 12import { createNativeControl } from '../server/native-control.mjs' ; 13import { withoutDraftLayer , NATIVE_FIELDS , APP_OWNED_FIELDS , validateNativeSettings } from '../server/native-settings.mjs' ; 14import { checkRunConfig } from '../server/run-config-check.mjs' ; 15 16const ARGS = [ '--pack' , '/p' , '--expert-cache' , 'auto' , '--spec' , '4' , '--spec-min-p' , '0.5' , '--mtp' , '/m/rt' , '--max-context' , '40000' , '--kv' , 'int8' , '--vision' ]; 17 18function fixture ( config = {}, { gpuGb= 12 } = {}) { 19const root = mkdtempSync ( join ( tmpdir (), 'strata-draft-test-' )); 20const install = join ( root , 'install' ), data = join ( root , 'data' ); 21mkdirSync ( install , { recursive :true }); 22process . env . STRATA_INSTALL_DIR = install ; 23const path = join ( install , 'strata-q2_0.json' ); 24writeFileSync ( path , JSON . stringify ({ exe :'component:strata-engine' , tokenizer :join ( install , 'tok' ), args :ARGS , model_name :'Qwen q2_0' , port :8080 , ...config })); 25const saved = []; 26const control = { 27control :{ dir :join ( root , 'control' ) }, version :'0.2.0' , 28async installedModels () { return { install_dir :install , models :[{ id :'q2_0' , name :'Qwen q2_0' , source_config :path , component_status :'present' , context_tokens :40000 }] }; }, 29async engine () { return { usable :true , backend :'cuda' , components_dir :'E:\\c' , engine :{ version :'0.2.0' , platform :'windows-x86_64' , backend :'cuda' , exe :'E:\\e\\strata.exe' , root :'E:\\e' } }; }, 30async saveProfile ( name , file ) { saved . push ( JSON . parse ( readFileSync ( file , 'utf8' ))); return {}; }, 31async start () { return { ok :true , state :'ready' }; }, 32async stop () { return { ok :true }; }, 33}; 34const native = createNativeControl ({ control, hardwareProbe :() => [{ index :0 , vram_gb :gpuGb }], directory :data , spawnProcess :() => { throw new Error ( 'no process' ); }, fetcher :async () => Response . json ({ status :'ok' }), requests :() => [] }); 35return { native, saved, path, cleanup :() => rmSync ( root , { recursive :true , force :true }) }; 36} 37const finish = async ( native , id ) => { for ( let i = 0 ; i < 500 ; 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' ); }; 38const visionSection = { exe :'E:\\e\\strata-vision.exe' , mmproj :'E:\\mm.gguf' , model :'E:\\m.gguf' , gpu :false , max_tokens :300 }; 39 40test ( 'withoutDraftLayer takes out --mtp, --spec-min-p and --batch-mtp and keeps --spec' , () => { 41assert . deepEqual ( withoutDraftLayer ( ARGS ), [ '--pack' , '/p' , '--expert-cache' , 'auto' , '--spec' , '4' , '--max-context' , '40000' , '--kv' , 'int8' , '--vision' ]); 42assert . deepEqual ( withoutDraftLayer ([ '--mtp' , '2' , '--spec' , '2' , '--batch-mtp' ]), [ '--spec' , '2' ], 'Qwen3.6: a draft count' ); 43assert . deepEqual ( withoutDraftLayer ([ '--spec' , '4' , '--mtp' ]), [ '--spec' , '4' ], 'a flag with no value at the end' ); 44assert . deepEqual ( withoutDraftLayer ([ '--mtp' , '--spec' , '4' ]), [ '--spec' , '4' ], 'a flag whose next word is another flag' ); 45}); 46 47test ( '"Draft layer (MTP)" is a setting of the app, not frozen, and "MTP per request" is not frozen either' , async () => { 48assert . ok ( NATIVE_FIELDS . some ( f => f . id === 'mtp' && f . type === 'boolean' )); 49assert . deepEqual ( APP_OWNED_FIELDS . sort (), [ 'batchMtp' , 'drafting' , 'mtp' ]); 50const f = fixture (); 51try { 52await f . native . refresh ( true ); 53for ( const id of [ 'mtp' , 'batchMtp' , 'drafting' ]) assert . equal ( f . native . state (). fields . find ( x => x . id === id ). supported , true , ` ${ id } must not be disabled` ); 54assert . deepEqual ( validateNativeSettings ({ mtp :false }), { mtp :false }); 55assert . equal ( checkRunConfig ( JSON . stringify ({ exe :'e' , tokenizer :'t' , args :[], mtp :false })). issues . length , 0 , 'the file check knows the key' ); 56} finally { await f . native . close (); f . cleanup (); } 57}); 58 59test ( 'saving "Draft layer" off keeps it in the model file, and every load starts without --mtp' , async () => { 60const f = fixture (); 61try { 62await f . native . refresh ( true ); 63f . native . save ( 'q2_0' , { values :{ mtp :false } }); 64assert . equal ( JSON . parse ( readFileSync ( f . path , 'utf8' )). mtp , false ); 65// a setup run rewrites the arguments (here: the same text with --mtp back) and keeps the key; the load applies it 66const job = await finish ( f . native , f . native . operation ( 'load' , { model :'q2_0' , vision :'no' }). id ); 67assert . equal ( job . state , 'done' , job . error ); 68const args = f . saved [ 0 ]. args ; 69assert . ok ( ! args . includes ( '--mtp' ) && ! args . includes ( '--spec-min-p' ) && ! args . includes ( '--batch-mtp' ), args . join ( ' ' )); 70assert . equal ( args [ args . indexOf ( '--spec' ) + 1 ], '4' , '--spec stays: prompt lookup still uses its windows' ); 71assert . equal ( args [ args . indexOf ( '--max-context' ) + 1 ], '40000' , 'a context set by hand is not touched' ); 72// and back to the default: the key goes, the draft layer is in again 73f . native . save ( 'q2_0' , { values :{ mtp :null } }); 74assert . equal ( 'mtp' in JSON . parse ( readFileSync ( f . path , 'utf8' )), false ); 75} finally { await f . native . close (); f . cleanup (); } 76}); 77 78test ( 'the load with the draft layer off in its own values, and a retry, both keep it off' , async () => { 79const f = fixture (); 80try { 81await f . native . refresh ( true ); 82const job = await finish ( f . native , f . native . operation ( 'load' , { model :'q2_0' , vision :'no' , values :{ mtp :false } }). id ); 83assert . equal ( job . state , 'done' , job . error ); 84assert . ok ( ! f . saved [ 0 ]. args . includes ( '--mtp' )); 85assert . ok ( ! f . saved [ 0 ]. args . includes ( '--batch-mtp' ), 'no draft layer, so no draft layer per request either, even on a big card' ); 86} finally { await f . native . close (); f . cleanup (); } 87}); 88 89test ( 'picture reading off sticks: no vision section and no --vision on the engine, whatever setup wrote' , async () => { 90const f = fixture ({ vision :visionSection , ui_vision_enabled :false , ui_vision_device :'yes' }); 91try { 92await f . native . refresh ( true ); 93const job = await finish ( f . native , f . native . operation ( 'load' , { model :'q2_0' }). id ); // the screen sends nothing: the saved choice decides 94assert . equal ( job . state , 'done' , job . error ); 95assert . equal ( f . saved [ 0 ]. vision , undefined ); 96assert . ok ( ! f . saved [ 0 ]. args . includes ( '--vision' )); 97assert . equal ( JSON . parse ( readFileSync ( f . path , 'utf8' )). ui_vision_enabled , false , 'the choice stays saved' ); 98} finally { await f . native . close (); f . cleanup (); } 99}); 100 101test ( 'picture reading on keeps --vision; the Models screen sees the prepared pictures instead of "off"' , async () => { 102const f = fixture ({ vision :visionSection }); 103try { 104await f . native . refresh ( true ); 105assert . equal ( f . native . state (). installed . models [ 0 ]. images , 'yes' , 'prepared: the screen loads straight away, no setup run' ); 106const job = await finish ( f . native , f . native . operation ( 'load' , { model :'q2_0' }). id ); 107assert . equal ( job . state , 'done' , job . error ); 108assert . ok ( f . saved [ 0 ]. args . includes ( '--vision' )); 109assert . ok ( f . saved [ 0 ]. vision ); 110} finally { await f . native . close (); f . cleanup (); } 111const g = fixture (); 112try { await g . native . refresh ( true ); assert . equal ( g . native . state (). installed . models [ 0 ]. images , 'off' , 'no vision section: not prepared' ); } finally { await g . native . close (); g . cleanup (); } 113});