okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Drafting Off in the app: a model saved with Off loads after a restart, and the Models screen shows the saved choice (0.2.15 release test)c77572806

main
2.8 KiB36 linesraw
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', () => {
12  const load = source.slice(source.indexOf('async function loadEngine'), source.indexOf('const fingerprint=createHash'));
13  assert.match(load, /await prepareDrafter\(job,args,cfg,configFile,drafts,\{noSplit\}\)/);
14  const prepare = source.slice(source.indexOf('async function prepareDrafter'), source.indexOf('function rememberSetting'));
15  assert.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', () => {
19  const at = source.indexOf("instance.status='ready';instance.phase='idle';await noteDrafting(job,instance,key);");
20  assert.ok(at > 0, 'the ready branch of loadEngine');
21  const ready = source.slice(at, source.indexOf('emit();ensurePoll();', at));
22  assert.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)');
24  assert.doesNotMatch(ready, /writeModelConfig\(record\(args\.model\)\.path,\{\.\.\.config,/, 'not the copy read before the choice was saved');
25  const helper = source.slice(source.indexOf('function savedNow('), source.indexOf('function writeModelConfig('));
26  assert.match(helper, /checkedSettingsConfig\(readFileSync\(path,'utf8'\)\)/);
27  assert.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', () => {
31  const screen = readFileSync(fileURLToPath(new URL('../src/components/NativeModels.tsx', import.meta.url)), 'utf8').replace(/\r\n/g, '\n');
32  const at = screen.indexOf("setDrafting(installed.drafting ?? 'auto');");
33  assert.ok(at > 0, 'the page opens a model with its saved choice');
34  const deps = screen.slice(screen.indexOf('}, [', at), screen.indexOf(']);', at));
35  assert.match(deps, /installed\?\.drafting/, 'a saved choice that arrives after the page opened is shown (otherwise the next Load sends Auto)');
36});