okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c77572806
main
1// A Drafting choice made on the Models screen is kept for the next start (0.2.15 release test T6-app, p1004, C2 app): the Load saved 2// "drafting": "off" into the model's run config (prepareDrafter / rememberSetting), and the write at ready then put back the copy of the 3// run config the Load had read before that, so the key was gone: after an app restart the page showed Auto and the next Load ran DFlash2. 4import test from 'node:test' ; 5import assert from 'node:assert/strict' ; 6import { readFileSync } from 'node:fs' ; 7import { fileURLToPath } from 'node:url' ; 8 9const source = readFileSync ( fileURLToPath ( new URL ( '../server/native-control.mjs' , import . meta. url )), 'utf8' ). replace ( / \r\n / g , '\n' ); 10 11test ( 'the Load saves the Drafting choice before the engine starts' , () => { 12const load = source . slice ( source . indexOf ( 'async function loadEngine' ), source . indexOf ( 'const fingerprint=createHash' )); 13assert . match ( load , / await prepareDrafter\(job,args,cfg,configFile,drafts,\{noSplit\}\) / ); 14const prepare = source . slice ( source . indexOf ( 'async function prepareDrafter' ), source . indexOf ( 'function rememberSetting' )); 15assert . match ( prepare , / rememberSetting\(configFile,'drafting',asked===null\|\|asked==='auto'\?null:asked\) / ); 16}); 17 18test ( 'the run-config write at ready starts from the file as it is now, so the saved choice is kept' , () => { 19const at = source . indexOf ( "instance.status='ready';instance.phase='idle';await noteDrafting(job,instance,key);" ); 20assert . ok ( at > 0 , 'the ready branch of loadEngine' ); 21const ready = source . slice ( at , source . indexOf ( 'emit();ensurePoll();' , at )); 22assert . match ( ready , / writeModelConfig\(record\(args\.model\)\.path,\{\.\.\.savedNow\(record\(args\.model\)\.path,config\), / , 23'the write at ready reads the run config again (it holds the Drafting choice the Load saved)' ); 24assert . doesNotMatch ( ready , / writeModelConfig\(record\(args\.model\)\.path,\{\.\.\.config, / , 'not the copy read before the choice was saved' ); 25const helper = source . slice ( source . indexOf ( 'function savedNow(' ), source . indexOf ( 'function writeModelConfig(' )); 26assert . match ( helper , / checkedSettingsConfig\(readFileSync\(path,'utf8'\)\) / ); 27assert . match ( helper , / catch\{return fallback;\} / ); 28}); 29 30test ( 'after an app restart the Models screen shows the saved Drafting choice: the page follows the saved value when it arrives' , () => { 31const screen = readFileSync ( fileURLToPath ( new URL ( '../src/components/NativeModels.tsx' , import . meta. url )), 'utf8' ). replace ( / \r\n / g , '\n' ); 32const at = screen . indexOf ( "setDrafting(installed.drafting ?? 'auto');" ); 33assert . ok ( at > 0 , 'the page opens a model with its saved choice' ); 34const deps = screen . slice ( screen . indexOf ( '}, [' , at ), screen . indexOf ( ']);' , at )); 35assert . match ( deps , / installed\?\.drafting / , 'a saved choice that arrives after the page opened is shown (otherwise the next Load sends Auto)' ); 36});