okami.mom/strata

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

Niko1221owner decisions: plan cards keep the screens' count and add "(--gpu N)"; refusal says "free"; app tells the plan which engine it will unloada3a10b90a

main
25.4 KiB342 linesraw
1/**
2 * 0.2.10.1: the desktop app's Auto load uses the all-cards split engine wherever the Terminal does. The decision is Control's (strata_control/split_engine.py, `strata drafting plan`,
3 * `strata split-engine apply`; tests/terminal/test_split_parallel.py); this file drives the host's load with a fake Control and checks what the host asks and starts:
4 * no --no-split on the plan or the fetch, the MTP draft layer fetched through the existing installer step (gguf_dir, so the model is not fetched again), the split engine's
5 * run config saved as the profile, a person's DFlash2 kept, a failed layer fetch ending in a working layer split with one plain note. Nothing here starts an engine.
6 */
7import './helpers/isolate-profile.mjs';   // a test run never writes the owner's real Strata profile
8import test from 'node:test';
9import assert from 'node:assert/strict';
10import { EventEmitter } from 'node:events';
11import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
12import { join, dirname } from 'node:path';
13import { tmpdir } from 'node:os';
14import { createNativeControl } from '../server/native-control.mjs';
15import { createControl } from '../server/control-runtime.mjs';
16import { resolveDrafter as hostResolve } from '../server/native-settings.mjs';
17
18const SPLIT_PLAN = { ok: true, split: true, choice: 'mtp', drafter: 'mtp', needed: false, gb: 0, line: 'Drafting: MTP (the all-cards split engine uses the MTP draft layer, 5.2 GB)', serves: true };
19const DFLASH2_PLAN = { ok: true, split: false, choice: 'dflash2', drafter: 'dflash2', needed: true, gb: 1.2, mtp_needed: false, mtp_gb: 0, line: 'Drafting: DFlash2', serves: true };
20
21/**
22 * A packaged install on two 48 GB cards. `plan(options, state)` answers `drafting plan` (state.installs says how many layer installs ran), `split(options, files)` answers `split-engine apply`
23 * (it may write options.outPath), `installFails` makes the installer's MCP tool fail, `startFails` fails the first N engine starts.
24 */
25function fixture({ plan, split = null, installFails = false, startFails = 0, metrics = {}, config = {} } = {}) {
26  const root = mkdtempSync(join(tmpdir(), 'strata-splitapp-test-'));
27  const install = join(root, 'install'), data = join(root, 'host-data'), home = join(root, 'home'), modelsDir = join(home, 'models');
28  for (const d of [install, data, modelsDir]) mkdirSync(d, { recursive: true });
29  const earlier = process.env.STRATA_INSTALL_DIR;
30  process.env.STRATA_INSTALL_DIR = install;
31  const dataFolder = join(root, 'Strata-data'), modelFolder = join(dataFolder, 'models', 'UD-Q4_K_XL');
32  const gguf = join(modelFolder, 'Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00002.gguf');
33  mkdirSync(modelFolder, { recursive: true });
34  writeFileSync(gguf, 'GGUF'); writeFileSync(gguf.replace('00001', '00002'), 'GGUF');
35  const pack = join(dataFolder, 'packs', 'ud_q4_k_xl'), mtp = join(dataFolder, 'mtp', 'rt');
36  mkdirSync(join(pack, 'tokenizer'), { recursive: true });
37  writeFileSync(join(pack, 'native_experts.txt'), 'x');
38  const configPath = join(install, 'strata-ud_q4_k_xl.json');
39  const args = ['--pack', pack, '--native', gguf, '--ple-gguf', gguf.replace('00001', '00002'), '--mtp', mtp, '--max-context', '131072', '--kv', 'int8'];
40  writeFileSync(configPath, JSON.stringify({ exe: 'component:strata-engine', tokenizer: join(pack, 'tokenizer'), args, model_name: 'qwen3.8-flash-next-ud_q4_k_xl', port: 8080, gpu: [0, 1], ...config }));
41  writeFileSync(process.env.STRATA_SETTINGS_FILE, JSON.stringify({ data_dir: join(root, 'host-owned', 'Strata-data'), data_dir_at: 1700000000 }));
42  const state = { installs: 0, planCalls: [], fetchCalls: [], splitCalls: [], saved: [], starts: 0, rpc: [] };
43  const control = {
44    control: { dir: join(root, 'control'), python: join(root, 'control', 'python', 'python') }, version: '0.2.10',
45    async installedModels() {
46      return { install_dir: install, models: [{ id: 'ud_q4_k_xl', name: 'qwen3.8-flash-next-ud_q4_k_xl', source_config: configPath, context_tokens: 131072, backend: 'cuda', component_status: 'present', missing: [], issue_codes: [] }] };
47    },
48    async engine() { return { usable: true, backend: 'cuda', components_dir: join(root, 'c'), engine: { version: '0.1.56', platform: 'linux-x86_64', backend: 'cuda', exe: join(root, 'engine', 'strata'), root: join(root, 'engine') } }; },
49    async draftingPlan(options) { state.planCalls.push(options); return typeof plan === 'function' ? plan(options, state) : plan; },
50    async draftingFetch(options) { state.fetchCalls.push(options); return { ok: true, event: 'result', pack: null, skipped: false }; },
51    async splitEngine(options) {
52      state.splitCalls.push({ ...options, input: JSON.parse(readFileSync(options.configPath, 'utf8')) });
53      if (!split) return { ok: true, split: false, line: '', warn: false, reasons: [], written: null };
54      return split(options, state);
55    },
56    async saveProfile(name, path) { state.saved.push(JSON.parse(readFileSync(path, 'utf8'))); return {}; },
57    async start() { state.starts += 1; if (state.starts <= startFails) throw new Error('The engine stopped: out of memory'); return { ok: true, state: 'ready' }; },
58    async stop() { return { ok: true }; },
59  };
60  const catalog = { families: [{ family: 'qwen', title: 'Qwen3.8-Flash-Next', about: 'x', images: false, experimental: false, sizes: [
61    { id: 'ud_q4_k_xl', model: 'UD-Q4_K_XL', download_gb: 22, ram_needed_gb: 60, about: 'x', on_this_pc: 'fits', installed: true, images: false, experimental: false }] }],
62    contexts: [32768, 131072], recommendation: { family: 'qwen', model: 'UD-Q4_K_XL', context: 131072 }, context_note: '' };
63  const hardware = { ram_gb: 256, cpu: { name: 'cpu', cores: 32 }, engine_vendor: 'nvidia', gpus: [0, 1].map(index => ({ index, name: 'NVIDIA RTX A6000', vendor: 'nvidia', vram_gb: 48, arch: 86, usable: true })) };
64  const spawnProcess = (command, argv) => {
65    if (!String(argv[0]).endsWith('strata_mcp.py')) throw new Error('no process but the installer may be started in packaged mode: ' + command + ' ' + argv.join(' '));
66    const child = new EventEmitter(); child.stdout = new EventEmitter(); child.stderr = new EventEmitter(); child.exitCode = null;
67    child.kill = () => { child.exitCode = 0; queueMicrotask(() => child.emit('exit', 0)); return true; };
68    child.stdin = { write(line) {
69      const message = JSON.parse(line); if (!message.id) return;
70      if (message.method === 'tools/call') state.rpc.push(message.params);
71      let result;
72      if (message.method === 'initialize') result = { protocolVersion: '2024-11-05' };
73      else if (message.method === 'tools/list') result = { tools: ['strata_models', 'strata_status', 'strata_install', 'strata_remove'].map(name => ({ name })) };
74      else if (message.params.name === 'strata_models') result = { structuredContent: catalog };
75      else if (message.params.name === 'strata_status') result = { structuredContent: { hardware, recommendation: catalog.recommendation, install: null, running: [], summary: 'x' } };
76      else if (Object.keys(message.params.arguments ?? {}).length === 0) result = { structuredContent: { summary: 'Install finished', install: { running: false, exit_code: 0 } } };
77      else if (message.params.arguments?.confirm) {
78        if (installFails) result = { isError: true, structuredContent: { error: 'The download did not finish.' } };
79        else { state.installs += 1; mkdirSync(mtp, { recursive: true }); writeFileSync(join(mtp, 'dense.bin'), 'x'); result = { structuredContent: { summary: 'Install started', plan: {}, install: { running: true, step: '1/7' } } }; }
80      } else result = { structuredContent: { summary: 'Plan', plan: { title: 'Qwen3.8-Flash-Next UD-Q4_K_XL', download_gb: 5.2, disk_short: null } } };
81      queueMicrotask(() => child.stdout.emit('data', Buffer.from(JSON.stringify({ jsonrpc: '2.0', id: message.id, result }) + String.fromCharCode(10))));
82    } };
83    return child;
84  };
85  const fetcher = async url => String(url).endsWith('/metrics') ? Response.json({ engine: metrics }) : Response.json({ status: 'ok' });
86  const native = createNativeControl({ control, directory: data, spawnProcess, fetcher, requests: () => [], modelsDirectory: () => modelsDir, hardwareProbe: () => [0, 1].map(index => ({ index, vram_gb: 48 })) });
87  return { native, state, root, gguf, modelFolder, mtp, configPath, args,
88    cleanup: () => { if (earlier === undefined) delete process.env.STRATA_INSTALL_DIR; else process.env.STRATA_INSTALL_DIR = earlier; rmSync(root, { recursive: true, force: true }); } };
89}
90const finish = async (native, id) => { for (let i = 0; i < 1500; 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'); };
91const load = (f, args = {}) => f.native.operation('load', { model: 'ud_q4_k_xl', ...args });
92
93/** The split engine's answer: the layer config with the split's engine and a lane count (Control's split_config, in miniature), written where the host asked. */
94const splitAnswer = (options) => {
95  const cfg = JSON.parse(readFileSync(options.configPath, 'utf8'));
96  const lanes = Math.min(8, cfg.parallel ?? 6);
97  writeFileSync(options.outPath, JSON.stringify({ ...cfg, exe: '/e/strata-split-2-sm86', args: ['--native', cfg.args[cfg.args.indexOf('--native') + 1], '--batch', String(lanes)], drafting: 'mtp', split_fallback: { exe: cfg.exe, args: cfg.args, parallel: cfg.parallel }, split_engine_note: 'Using the all-cards split engine on 2 cards.' }));
98  return { ok: true, split: true, line: 'Using the all-cards split engine on 2 cards.', warn: false, reasons: [], cards: 2, written: options.outPath };
99};
100/** Before the layer is fetched Control says split + mtp_needed; after it, split with the layer here. */
101const splitPlan = (_options, state) => state.installs === 0 ? { ...SPLIT_PLAN, mtp_needed: true, mtp_gb: 5.2 } : { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 };
102
103test('no drafting call of the host carries --no-split by itself, and the flag is there for the failed layer fetch', async () => {
104  const calls = [];
105  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, split: false }, text: '', stderr: '' }; } });
106  await control.draftingPlan({ mode: 'auto' });
107  await control.draftingPlan({ configPath: 'C:/w/cfg.json', mode: 'auto', family: 'unsloth', dataDir: 'C:/d' });
108  await control.draftingFetch({ configPath: 'C:/w/cfg.json', mode: 'auto' });
109  assert.equal(calls.length, 3);
110  for (const args of calls) assert.ok(!args.includes('--no-split'), args.join(' '));
111  assert.deepEqual(calls[2], ['drafting', 'fetch', '--config', 'C:/w/cfg.json', '--mode', 'auto', '--if-needed', '--output', 'jsonl']);
112  await control.draftingPlan({ configPath: 'C:/w/cfg.json', mode: 'auto', noSplit: true });
113  await control.draftingFetch({ configPath: 'C:/w/cfg.json', mode: 'auto', noSplit: true });
114  assert.ok(calls[3].includes('--no-split') && calls[4].includes('--no-split'));
115  await control.splitEngine({ configPath: 'C:/w/layer.json', outPath: 'C:/w/split.json' });
116  assert.deepEqual(calls[5], ['split-engine', 'apply', '--config', 'C:/w/layer.json', '--out', 'C:/w/split.json', '--output', 'json']);
117});
118
119test('--engines-unloading is on the plan and the fetch only when the host asks for it', async () => {
120  const calls = [];
121  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, split: false }, text: '', stderr: '' }; } });
122  await control.draftingPlan({ configPath: 'C:/w/cfg.json', mode: 'auto' });
123  await control.draftingPlan({ configPath: 'C:/w/cfg.json', mode: 'auto', unloading: true });
124  await control.draftingFetch({ configPath: 'C:/w/cfg.json', mode: 'auto', unloading: true });
125  assert.ok(!calls[0].includes('--engines-unloading'));
126  assert.ok(calls[1].includes('--engines-unloading') && calls[2].includes('--engines-unloading'), calls.map(c => c.join(' ')).join(' | '));
127});
128
129/** Control as it answers on two cards that the app's own running engine holds: DFlash2 (and its fetch) unless the host says that engine is about to be unloaded. */
130const busyWhileRunning = (get) => (options) => get().native.state().instances.length > 0 && options.unloading !== true ? DFLASH2_PLAN : { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 };
131
132test('a model switch on two cards: the plan and the fetch say the running engine is about to be unloaded, so its memory is not busy and the split stays', async () => {
133  let f;
134  f = fixture({ plan: busyWhileRunning(() => f), split: splitAnswer });
135  try {
136    await f.native.refresh(true);
137    const first = await finish(f.native, load(f).id);
138    assert.equal(first.state, 'done', first.error);
139    assert.equal(f.state.planCalls.length > 0 && f.state.planCalls.every(c => c.unloading !== true), true, 'nothing is running at the first load: nothing to unload');
140    const before = f.state.planCalls.length;
141    const second = await finish(f.native, load(f, { values: { drafting: 'mtp' } }).id);   // a different choice: a different engine, the first one is unloaded
142    assert.equal(second.state, 'done', second.error);
143    const calls = f.state.planCalls.slice(before);
144    assert.ok(calls.length >= 1 && calls.every(c => c.unloading === true), JSON.stringify(calls));
145    assert.equal(f.state.fetchCalls.length, 0, 'no DFlash2 drafter is fetched because of the old engine memory');
146    assert.equal(f.state.splitCalls.length, 2, 'the split engine was asked at both loads');
147    assert.equal(f.native.state().instances.length, 1);
148  } finally { await f.native.close(); f.cleanup(); }
149});
150
151test('a model added beside the running one keeps the memory of the running one busy: the plan is not told to ignore it', async () => {
152  let f;
153  f = fixture({ plan: busyWhileRunning(() => f), split: splitAnswer });
154  try {
155    await f.native.refresh(true);
156    const first = await finish(f.native, load(f).id);
157    assert.equal(first.state, 'done', first.error);
158    const before = f.state.planCalls.length;
159    await finish(f.native, load(f, { multiple: true, gpus: [0], values: { drafting: 'mtp' } }).id);
160    const calls = f.state.planCalls.slice(before);
161    assert.ok(calls.length >= 1 && calls.every(c => c.unloading !== true), JSON.stringify(calls));
162  } finally { await f.native.close(); f.cleanup(); }
163});
164
165test('Auto on two cards: the MTP draft layer is fetched through the installer with the model\'s own folder, then the split engine\'s run config is what starts', async () => {
166  const f = fixture({ plan: splitPlan, split: splitAnswer });
167  try {
168    await f.native.refresh(true);
169    const job = await finish(f.native, load(f).id);
170    assert.equal(job.state, 'done', job.error);
171    // the plan: no --no-split, so Control's answer is the Terminal's
172    assert.ok(f.state.planCalls.length >= 2);
173    assert.ok(f.state.planCalls.every(c => c.noSplit !== true), 'the host never asks without the split here');
174    // the layer: one installer call with drafter mtp, the model folder, and nothing that names a download of the model itself
175    const real = f.state.rpc.filter(p => p.name === 'strata_install' && p.arguments?.confirm === true);
176    assert.equal(real.length, 1);
177    assert.equal(real[0].arguments.drafter, 'mtp');
178    assert.equal(real[0].arguments.gguf_dir, dirname(f.gguf), 'the model\'s files folder, so the model is never fetched again');
179    assert.equal(f.state.installs, 1);
180    assert.equal(f.state.fetchCalls.length, 0, 'no DFlash2 drafter is fetched for the split');
181    // the start: Control was asked once, with the layer split config the app built (4 slots, the app\'s own keys), and the profile holds the split engine\'s config
182    assert.equal(f.state.splitCalls.length, 1);
183    assert.equal(f.state.splitCalls[0].input.parallel, 4, 'the app\'s default of 4 slots reaches the split as 4 lanes');
184    assert.equal(f.state.splitCalls[0].input.host, '127.0.0.1');
185    assert.ok(f.state.splitCalls[0].input.api_key);
186    assert.equal(f.state.saved.length, 1);
187    assert.equal(f.state.saved[0].exe, '/e/strata-split-2-sm86');
188    assert.equal(f.state.saved[0].args[f.state.saved[0].args.indexOf('--batch') + 1], '4');
189    assert.equal(f.state.saved[0].drafting, 'mtp');
190    assert.equal(f.state.saved[0].split_fallback.parallel, 4, 'the server\'s fallback keeps the app\'s slots');
191    const instance = f.native.state().instances[0];
192    assert.equal(instance.status, 'ready');
193    assert.equal(instance.splitNote, 'Using the all-cards split engine on 2 cards.');
194    assert.match(f.native.state().jobs.at(-1).details ?? '', /Using the all-cards split engine on 2 cards\./, 'the load says what runs');
195  } finally { await f.native.close(); f.cleanup(); }
196});
197
198test('the layer is already on disk: no installer call, still the split', async () => {
199  const f = fixture({ plan: { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 }, split: splitAnswer });
200  try {
201    await f.native.refresh(true);
202    const job = await finish(f.native, load(f).id);
203    assert.equal(job.state, 'done', job.error);
204    assert.equal(f.state.rpc.filter(p => p.name === 'strata_install').length, 0);
205    assert.equal(f.state.splitCalls.length, 1);
206    assert.equal(f.state.saved[0].exe, '/e/strata-split-2-sm86');
207  } finally { await f.native.close(); f.cleanup(); }
208});
209
210test('a person\'s DFlash2: the plan says layer split, DFlash2 is fetched as before, the split engine is never asked and the app keeps one request at a time', async () => {
211  const f = fixture({ plan: DFLASH2_PLAN, split: splitAnswer });
212  try {
213    await f.native.refresh(true);
214    const job = await finish(f.native, load(f, { values: { drafting: 'dflash2' } }).id);
215    assert.equal(job.state, 'done', job.error);
216    assert.equal(f.state.splitCalls.length, 0);
217    assert.equal(f.state.rpc.filter(p => p.name === 'strata_install').length, 0, 'no draft layer download');
218    assert.equal(f.state.fetchCalls.length, 1);
219    assert.equal(f.state.fetchCalls[0].mode, 'dflash2');
220    assert.ok(f.state.fetchCalls[0].noSplit !== true);
221    assert.equal(f.state.saved[0].exe, 'component:strata-engine');
222    assert.equal(f.state.saved[0].parallel, undefined, 'DFlash2 answers one request at a time');
223  } finally { await f.native.close(); f.cleanup(); }
224});
225
226test('Off keeps the layer split and the split engine is not asked', async () => {
227  const f = fixture({ plan: { ...DFLASH2_PLAN, choice: 'off', drafter: 'off', needed: false, gb: 0 }, split: splitAnswer });
228  try {
229    await f.native.refresh(true);
230    const job = await finish(f.native, load(f, { values: { drafting: 'off' } }).id);
231    assert.equal(job.state, 'done', job.error);
232    assert.equal(f.state.splitCalls.length, 0);
233    assert.ok(!f.state.saved[0].args.includes('--mtp'));
234    assert.equal(f.state.saved[0].exe, 'component:strata-engine');
235  } finally { await f.native.close(); f.cleanup(); }
236});
237
238test('the draft layer for the split cannot be downloaded: one plain note, the plan is DFlash2\'s again (asked with --no-split), the split is not tried and the model loads on the layer split', async () => {
239  const f = fixture({
240    installFails: true, split: splitAnswer,
241    plan: (options) => options.noSplit === true ? DFLASH2_PLAN : { ...SPLIT_PLAN, mtp_needed: true, mtp_gb: 5.2 },
242  });
243  try {
244    await f.native.refresh(true);
245    const job = await finish(f.native, load(f, { values: { drafting: null } }).id);   // the Models screen's Load with Auto
246    assert.equal(job.state, 'done', job.error);
247    assert.equal(job.drafterNote, 'The MTP drafter could not be downloaded.');
248    assert.match(job.details ?? '', /The MTP drafter could not be downloaded\./);
249    assert.equal(f.state.splitCalls.length, 0, 'no layer, no split');
250    assert.ok(f.state.planCalls.some(c => c.noSplit === true), 'the plan is asked again as the app asked it in 0.2.10');
251    assert.equal(f.state.fetchCalls.length, 1, 'the DFlash2 drafter is the fallback fetch');
252    assert.equal(f.state.fetchCalls[0].noSplit, true, 'and Control is told, so it does not plan the split\'s layer again');
253    assert.equal(f.state.saved.length, 1);
254    assert.equal(f.state.saved[0].exe, 'component:strata-engine');
255    assert.equal(f.native.state().instances[0].status, 'ready');
256  } finally { await f.native.close(); f.cleanup(); }
257});
258
259test('a plain Auto restart with no draft layer on disk does not download it and does not stop: the load goes on, the split engine says no on its own', async () => {
260  // no values: a restart or a tuning run carries no choice, and a saved explicit MTP is not Auto
261  const f = fixture({ plan: { ...SPLIT_PLAN, mtp_needed: true, mtp_gb: 5.2 }, config: { drafting: 'mtp' } });
262  try {
263    await f.native.refresh(true);
264    const job = await finish(f.native, load(f).id);
265    assert.equal(job.state, 'done', job.error);
266    assert.equal(f.state.rpc.filter(p => p.name === 'strata_install').length, 0, 'a restart never downloads');
267    assert.equal(f.state.saved.length, 1);
268  } finally { await f.native.close(); f.cleanup(); }
269});
270
271test('the split engine says no (a rule Control knows: engine package, RAM, context): the layer split config starts, nothing else changes', async () => {
272  const f = fixture({ plan: { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 } });   // splitEngine answers split:false
273  try {
274    await f.native.refresh(true);
275    const job = await finish(f.native, load(f).id);
276    assert.equal(job.state, 'done', job.error);
277    assert.equal(f.state.splitCalls.length, 1);
278    assert.equal(f.state.saved[0].exe, 'component:strata-engine');
279    assert.equal(f.state.saved[0].parallel, 4);
280    assert.equal(f.native.state().instances[0].splitNote, undefined);
281  } finally { await f.native.close(); f.cleanup(); }
282});
283
284test('Control cannot be asked about the split: the layer split starts as it was', async () => {
285  const f = fixture({ plan: { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 }, split: async () => { throw new Error('Control is busy'); } });
286  try {
287    await f.native.refresh(true);
288    const job = await finish(f.native, load(f).id);
289    assert.equal(job.state, 'done', job.error);
290    assert.equal(f.state.saved[0].exe, 'component:strata-engine');
291  } finally { await f.native.close(); f.cleanup(); }
292});
293
294test('the server started the layer split because the split engine would not come up: the load says so in one line', async () => {
295  const f = fixture({ plan: { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 }, split: splitAnswer, metrics: { split_fallback: true } });
296  try {
297    await f.native.refresh(true);
298    const job = await finish(f.native, load(f).id);
299    assert.equal(job.state, 'done', job.error);
300    const lines = (job.details ?? '').split('\n');
301    assert.ok(lines.includes('The all-cards split engine could not start, so the normal layer split runs.'), job.details);
302    assert.ok(!lines.some(l => /^Using the all-cards split engine/.test(l)), 'not the line that said the split would run');
303  } finally { await f.native.close(); f.cleanup(); }
304});
305
306test('the second try after a failed start is never the split: one request at a time on the layer split', async () => {
307  const f = fixture({ plan: { ...SPLIT_PLAN, mtp_needed: false, mtp_gb: 0 }, split: splitAnswer, startFails: 1 });
308  try {
309    await f.native.refresh(true);
310    const job = await finish(f.native, load(f).id);
311    assert.equal(job.state, 'done', job.error);
312    assert.equal(f.state.saved.length, 2);
313    assert.equal(f.state.saved[0].exe, '/e/strata-split-2-sm86');
314    assert.equal(f.state.saved[1].exe, 'component:strata-engine');
315    assert.equal(f.state.saved[1].parallel, undefined);
316    assert.equal(f.state.splitCalls.length, 1, 'Control was asked once');
317    assert.equal(f.native.state().instances[0].splitNote, undefined, 'the line that said the split would run is gone');
318  } finally { await f.native.close(); f.cleanup(); }
319});
320
321test('the word "split" reaches the Models screen: Auto is the MTP where Control says split, DFlash2 where it does not, and a person\'s DFlash2 stays', () => {
322  for (const [choice, split, want] of [['auto', true, 'mtp'], ['auto', false, 'dflash2'], ['dflash2', true, 'dflash2'], ['mtp', true, 'mtp'], ['off', true, 'off']]) {
323    assert.equal(hostResolve(choice, 'unsloth', true, split), want, `${choice} split=${split}`);
324  }
325});
326
327test('the hint of the Drafting setting and the Models screen say what Auto is on the split, with no new element', () => {
328  const read = rel => readFileSync(new URL(rel, import.meta.url), 'utf8').replace(/\r\n/g, '\n');
329  assert.match(read('../server/native-settings.mjs'), /on two or more identical graphics cards that the all-cards split engine takes, it is that engine with the MTP draft layer/);
330  const screen = read('../src/components/NativeModels.tsx');
331  assert.match(screen, /const splitCards = native\?\.capabilities\?\.dflash2Split === true && cardsGpus\.length !== 1;/, 'one card chosen in the roles is not the split');
332  assert.ok(screen.indexOf('const splitCards =') > 0 && screen.indexOf('const splitCards =') < screen.indexOf('const nowDrafter ='), 'splitCards is declared before it is used');
333  assert.match(screen, /splitCards && drafting === 'auto' \? "Auto uses the all-cards split engine with the MTP draft layer: about \{0\} GB to download, once\."/);
334  const en = JSON.parse(read('../src/locales/df2-en.json'));
335  const ids = Object.entries(en).filter(([, v]) => /all-cards split engine/.test(v)).map(([k]) => k);
336  assert.equal(ids.length, 2);
337  for (const lang of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) {
338    const cat = JSON.parse(read(`../src/locales/df2-${lang}.json`));
339    for (const id of ids) assert.ok(cat[id] && cat[id] !== en[id], `${id} in ${lang}`);
340    assert.equal((cat[ids[0]].match(/\{0\}/g) ?? []).length, 1, `the size slot in ${lang}`);
341  }
342});