okami.mom/strata

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

Niko1221app: Drafting Off fetches no draft layer; the offline note only when no drafter runsb2d08647c

main
24.5 KiB285 linesraw
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', () => {
14  const field = NATIVE_FIELDS.find(f => f.id === 'drafting');
15  assert.ok(field);
16  assert.deepEqual(field.choices, ['auto', 'mtp', 'dflash2', 'off']);
17  assert.equal(field.type, 'enum');
18  assert.match(field.hint, /Auto \(recommended\)/);
19  assert.match(field.hint, /Qwen3\.8-Flash-Next/);
20  assert.match(field.hint, /one at a time/);
21  assert.ok(APP_OWNED_FIELDS.includes('drafting'), 'the engine\'s own source never lists it: the app applies it');
22  for (const ok of ['auto', 'mtp', 'dflash2', 'off']) assert.deepEqual(validateNativeSettings({ drafting: ok }), { drafting: ok });
23  assert.deepEqual(validateNativeSettings({ drafting: null }), { drafting: null }, 'cleared = Auto');
24  assert.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', () => {
28  assert.deepEqual(withoutDraftLayer(['--pack', 'p', '--mtp', '/m', '--spec', '4', '--spec-min-p', '0.5', '--batch-mtp']), ['--pack', 'p', '--spec', '4']);
29  const source = read('../server/native-control.mjs');
30  assert.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', () => {
34  const screen = read('../src/components/NativeModels.tsx');
35  assert.match(screen, /draftingOptions\(selectedSize\.sourceFamily \?\? selectedFamily\?\.family, native\?\.capabilities\?\.dflash2\)/);
36  assert.match(screen, /draftingWords: Record<string, string> = \{ auto: 'Auto \(recommended\)', mtp: 'MTP', dflash2: 'DFlash2', off: 'Off' \}/);
37  const row = screen.slice(screen.indexOf('<div className="native-choice__row">'), screen.indexOf('{roleCards.length > 1 ? <GpuRoles'));
38  assert.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');
39  assert.match(row, /<Select ariaLabel=\{tr\("Drafting"\)\}/, 'the existing Select, no new component');
40  assert.match(screen, /setDrafting\(installed\.drafting \?\? 'auto'\)/, 'a model shows what it was saved with');
41  assert.match(screen, /const downloadValues = \{ \.\.\.values, \.\.\.\(draftingChoices \? \{ drafting \} : \{\}\)/);
42  assert.match(screen, /\.\.\.\(draftingChoices \? \{ values: \{ drafting \} \} : \{\}\)/);
43  assert.match(screen, /Choosing MTP downloads its drafter: about \{0\} GB, once\./);
44  assert.match(screen, /Choosing DFlash2 downloads its drafter: about \{0\} GB, once\./);
45  assert.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');
46  assert.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 () => {
50  const calls = [];
51  const control = createControl({ control: { dir: 'C:/c', python: 'py', cli: 'strata.py' }, run: async (args, options) => {
52    calls.push({ args, options });
53    return 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  } });
57  const plan = await control.draftingPlan({ mode: 'dflash2', family: 'gyro', dataDir: 'C:/d' });
58  assert.deepEqual(calls[0].args, ['drafting', 'plan', '--mode', 'dflash2', '--family', 'gyro', '--data-dir', 'C:/d', '--output', 'json']);
59  assert.equal(plan.needed, true);
60  const events = [];
61  await control.draftingFetch({ configPath: 'C:/w/cfg.json', mode: 'dflash2', onEvent: e => events.push(e) });
62  assert.deepEqual(calls[1].args, ['drafting', 'fetch', '--config', 'C:/w/cfg.json', '--mode', 'dflash2', '--if-needed', '--output', 'jsonl']);
63  assert.equal(calls[1].options.acquire, true, 'only this explicit step may reach the network');
64  assert.equal(calls[0].options.acquire, undefined, 'planning never does');
65  const 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: '' }) });
66  await 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', () => {
70  const source = read('../server/native-control.mjs');
71  const prepare = source.slice(source.indexOf('async function prepareDrafter'), source.indexOf('function rememberSetting'));
72  assert.match(prepare, /rememberSetting\(configFile,'drafting',asked===null\|\|asked==='auto'\?null:asked\)/, 'the choice is kept for the next load');
73  assert.match(prepare, /drafts\?\.needed!==true\)return/, 'only what Control says is needed is downloaded: DFlash2 for Auto and DFlash2, nothing for MTP and Off');
74  assert.match(prepare, /control\.draftingFetch\(/);
75  assert.match(prepare, /catch\(error\)\{if\(job\.state==='running'\)\{job\.drafterNote=error\.message;/, 'a failed download leaves the MTP and the job says so');
76  assert.match(source, /await prepareDrafter\(job,args,cfg,configFile,drafts,\{noSplit\}\)/);
77  assert.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)');
78  assert.match(source, /async function noteDrafting\(job,instance,key\)/);
79  assert.match(source, /instance\.status='ready';instance\.phase='idle';await noteDrafting\(job,instance,key\)/);
80  assert.match(source, /typeof choice==='string'&&typeof control\.draftingPlan==='function'/, 'the plan lists the drafter Control says is needed');
81  assert.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', () => {
85  const langs = ['en', 'zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr'];
86  const catalogs = Object.fromEntries(langs.map(l => [l, { ...JSON.parse(read(`../src/locales/${l}.json`)), ...JSON.parse(read(`../src/locales/df2-${l}.json`)) }]));
87  const idOf = text => Object.entries(catalogs.en).find(([, v]) => v === text)?.[0];
88  const 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'];
99  const slots = t => (t.match(/\{\d+\}/g) ?? []).sort().join();
100  for (const text of sentences) {
101    const id = idOf(text);
102    assert.ok(id, `"${text.slice(0, 60)}" is in the English catalog`);
103    for (const l of langs) {
104      const t = catalogs[l][id];
105      assert.ok(typeof t === 'string' && t.trim(), `${id} in ${l}`);
106      assert.equal(slots(t), slots(text), `${id} in ${l} has the same slots`);
107      if (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 () => {
113  const { transform } = await import('esbuild');
114  const code = (await transform(read('../src/lib/drafting.ts'), { loader: 'ts', format: 'esm' })).code;
115  const { draftingChoices } = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
116  const 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
118  for (const family of ['qwen', 'gyro', 'unsloth', 'coder', 'swift', undefined]) {
119    assert.equal(draftingChoices(family, false), null, `${family}, not served`);
120    assert.equal(draftingChoices(family, undefined), null, `${family}, Control has not answered`);
121    assert.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.
124  assert.deepEqual(draftingChoices('qwen', true), all);
125  assert.deepEqual(draftingChoices('gyro', true), all);
126  assert.deepEqual(draftingChoices('unsloth', true), all, "Unsloth's quantizations are the same weights (DFlash2 measured on UD-Q4_K_XL)");
127  for (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
129  const host = read('../server/native-control.mjs');
130  assert.match(host, /dflash2:dflash2Served===true,dflash2Support,dflash2Selq4,dflash2Split\}/);
131  assert.match(host, /dflash2Served=p\.serves===true/);
132  assert.match(host, /function probeDrafting\(\)\{if\(!packaged\|\|dflash2Served!==null/);
133  const screen = read('../src/components/NativeModels.tsx');
134  assert.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', () => {
138  for (const f of NATIVE_FIELDS) assert.ok(!('notForModel' in f) && !('forModel' in f), f.id);
139  assert.ok(!NATIVE_FIELDS.some(f => f.id === 'ds_experts'), 'the DeepSeek Speed row is gone');
140  const settings = read('../src/components/NativeSettings.tsx');
141  assert.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', () => {
145  const source = read('../server/native-control.mjs');
146  const prepare = source.slice(source.indexOf('async function prepareDrafter'), source.indexOf('function rememberSetting'));
147  assert.match(prepare, /asked===undefined\|\|drafts\?\.needed!==true/, 'no explicit choice in this job: return before any fetch');
148  const loadScreen = read('../src/components/NativeModels.tsx');
149  assert.match(loadScreen, /\.\.\.\(draftingChoices \? \{ values: \{ drafting \} \} : \{\}\)/, 'the screen passes the choice only when it showed the dropdown');
150  const 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);
151  assert.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', () => {
155  const screen = read('../src/components/NativeModels.tsx');
156  for (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);
157  const en = JSON.parse(read('../src/locales/df2-en.json'));
158  for (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 () => {
162  const { transform } = await import('esbuild');
163  const code = (await transform(read('../src/lib/drafting.ts'), { loader: 'ts', format: 'esm' })).code;
164  const ts = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
165  const host = await import('../server/native-settings.mjs');
166  for (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]]) {
167    assert.equal(ts.resolveDrafter(choice, family, served), host.resolveDrafter(choice, family, served), `${choice} ${family} ${served}`);
168  }
169  assert.equal(ts.resolveDrafter('auto', 'qwen', true), 'dflash2');
170  assert.equal(ts.resolveDrafter('auto', 'qwen', null), 'mtp', 'Control has not answered: the MTP');
171  assert.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
173  for (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);
174  for (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);
175  assert.equal(ts.resolveDrafter('auto', 'unsloth', true), 'dflash2');
176  assert.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 () => {
180  const source = read('../server/native-control.mjs');
181  assert.match(source, /'gguf_dir','drafter','mtp'\]/);
182  assert.match(source, /resolveDrafter\(args\.drafting,args\.family,dflash2Served,dflash2Split\);if\(d==='dflash2'\)args=\{\.\.\.args,drafter:'dflash2'\}/, 'DFlash2: the installer leaves the MTP layer out');
183  const { chooseParallel, MTP_VRAM_GB, DFLASH2_VRAM_GB } = await import('../server/native-parallel.mjs');
184  assert.deepEqual([MTP_VRAM_GB, DFLASH2_VRAM_GB], [1.08, 0.89]);
185  const config = { args: ['--mtp', '/m', '--max-context', '32768'], model_name: 'qwen3.8-flash-next-iq3_s' };
186  const hardware = { gpus: [{ index: 0, vram_gb: 24 }] };
187  const solo = chooseParallel({ config, hardware, drafter: 'dflash2' });
188  assert.equal(solo.slots, 1);
189  assert.match(solo.note, /one request at a time/);
190  assert.notEqual(chooseParallel({ config, hardware, drafter: 'mtp' }).slots, 1, 'the MTP keeps the slots Strata fills in');
191  assert.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)');
192  const two = { config: { ...config, gpu: [0, 1] }, hardware: { gpus: [{ index: 0, vram_gb: 24 }, { index: 1, vram_gb: 24 }] } };
193  const split = chooseParallel({ ...two, drafter: 'dflash2' });
194  assert.equal(split.slots, 1, 'a layer split runs DFlash2 alone, one request at a time (owner 11-02)');
195  assert.match(split.note, /one request at a time/);
196  assert.ok(chooseParallel({ ...two, drafter: 'mtp' }).slots > 1, 'the MTP on a layer split keeps the slots Strata fills in');
197  const fit = read('../src/lib/native-fit.ts');
198  assert.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', () => {
202  const source = read('../server/native-control.mjs');
203  const fn = source.slice(source.indexOf('async function installMtpLayer'), source.indexOf('async function prepareDrafter'));
204  assert.match(fn, /job\.drafterNote='The MTP drafter could not be downloaded\.'/);
205  assert.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 () => {
209  const py = read('../../../strata_control/drafting.py');
210  const table = JSON.parse(py.match(/^DRAFTER_MIB = (\{[^}]*\})/m)[1]);
211  const gb = mib => Math.floor(mib / 10 + 0.5) / 100;          // the same rounding as DRAFTER_GB (half up to 10 MiB)
212  assert.deepEqual(Object.keys(table).sort(), ['dflash2', 'dflash2_selq4', 'mtp', 'off']);
213  const parallel = await import('../server/native-parallel.mjs');
214  assert.equal(parallel.MTP_VRAM_GB, gb(table.mtp));
215  assert.equal(parallel.DFLASH2_VRAM_GB, gb(table.dflash2));
216  assert.equal(parallel.DFLASH2_SELQ4_VRAM_GB, gb(table.dflash2_selq4));
217  assert.deepEqual([table.dflash2, table.dflash2_selq4, table.mtp], [890, 715, 1082]);
218  const fit = read('../src/lib/native-fit.ts');
219  const num = name => Number(fit.match(new RegExp(`export const ${name} = ([0-9.]+);`))[1]);
220  assert.equal(num('MTP_VRAM_GB'), gb(table.mtp));
221  assert.equal(num('DFLASH2_VRAM_GB'), gb(table.dflash2));
222  assert.equal(num('DFLASH2_SELQ4_VRAM_GB'), gb(table.dflash2_selq4));
223  assert.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
225  const control = read('../server/native-control.mjs');
226  assert.match(control, /dflash2Selq4=p\.serves===true&&p\.selq4===true/);
227  assert.match(control, /dflash2Support,dflash2Selq4,dflash2Split\}/);
228  assert.match(read('../src/lib/native.ts'), /dflash2Selq4\?:boolean/);
229  const page = read('../src/components/NativeModels.tsx');
230  assert.match(page, /const fitDrafter = nowDrafter === 'dflash2' && native\?\.capabilities\?\.dflash2Selq4 === true \? 'dflash2_selq4' : nowDrafter;/);
231  assert.match(page, /drafter: fitDrafter/);
232  assert.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 () => {
236  const { transform } = await import('esbuild');
237  const code = (await transform(read('../src/lib/drafting.ts'), { loader: 'ts', format: 'esm' })).code;
238  const ts = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
239  const host = await import('../server/native-settings.mjs');
240  for (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  ]) {
246    assert.equal(ts.resolveDrafter(choice, family, served, split), want, `ts ${choice} ${family} ${served} ${split}`);
247    assert.equal(host.resolveDrafter(choice, family, served, split), want, `host ${choice} ${family} ${served} ${split}`);
248  }
249  const source = read('../server/native-control.mjs');
250  assert.match(source, /dflash2Split=p\.split===true/, 'the probe reads the plan word');
251  assert.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');
253  assert.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', () => {
257  const source = read('../server/native-control.mjs');
258  assert.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 () => {
262  const calls = [];
263  const 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: '' }; } });
264  await control.draftingPlan({ mode: 'auto' });
265  await control.draftingPlan({ configPath: 'C:/w/cfg.json', mode: 'auto', family: 'unsloth', dataDir: 'C:/d' });
266  await control.draftingFetch({ configPath: 'C:/w/cfg.json', mode: 'auto' });
267  assert.equal(calls.length, 3);
268  for (const c of calls) assert.ok(!c.args.includes('--no-split'), c.args.join(' '));
269  const { transform } = await import('esbuild');
270  const code = (await transform(read('../src/lib/drafting.ts'), { loader: 'ts', format: 'esm' })).code;
271  const ts = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
272  const host = await import('../server/native-settings.mjs');
273  for (const split of [false, undefined, null]) {
274    assert.equal(ts.resolveDrafter('auto', 'unsloth', true, split), 'dflash2');
275    assert.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
278  assert.equal(ts.resolveDrafter('auto', 'unsloth', true, true), 'mtp');
279  assert.equal(host.resolveDrafter('auto', 'unsloth', true, true), 'mtp');
280  assert.equal(ts.resolveDrafter('dflash2', 'unsloth', true, true), 'dflash2');
281  assert.equal(host.resolveDrafter('dflash2', 'unsloth', true, true), 'dflash2');
282  assert.equal(ts.resolveDrafter('off', 'unsloth', true, true), 'off');
283  assert.match(read('../server/native-control.mjs'), /dflash2Split=p\.split===true/, 'the probe reads the split word of Control');
284  assert.doesNotMatch(read('../server/control-runtime.mjs'), /'--no-split', '--output', 'json'\]|'--no-split', '--if-needed'/);
285});