okami.mom/strata

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

Niko1221Merge f-dl99-fixes: the Qwen3.6 first-run download (no engine-race stop, no cancelled engine download, progress to 100%, the picture reader's real figure, the engine-not-ready sentence)361c8d94a

main
6.8 KiB90 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { build } from 'esbuild';
4import { createEngineStep } from '../server/engine-step.mjs';
5
6/* DL99 (a Qwen3.6 UD-Q4_K_XL download that "stays at 99%"): what the setup wizard says and counts after the last byte. Replayed
7   from the install job's own progress as the app host saw it on a real run (Boston 2026-11-15, phaseA-tests/dl99/out1). */
8const compiled = await build({
9  stdin: { contents: "export * from './src/lib/download-eta'; export * from './src/lib/onboarding-download'; export * from './src/lib/i18n';", resolveDir: process.cwd() },
10  bundle: true, write: false, platform: 'node', format: 'esm',
11});
12const lib = await import(`data:text/javascript;base64,${Buffer.from(compiled.outputFiles[0].text).toString('base64')}`);
13lib.setTranslationLanguage('en');
14
15const engineDone = { kind: 'engine', name: 'Engine', state: 'done', done_gb: 0.67, total_gb: 0.67 };
16const model = (state, done) => ({ kind: 'model', name: 'Model files', state, done_gb: done, total_gb: 22.854, files_done: state === 'done' ? 1 : 0, files_total: 1 });
17const reader = (state, done) => ({ kind: 'vision', name: 'Picture reader', state, done_gb: done, total_gb: 0.899, files_done: state === 'done' ? 1 : 0, files_total: 1 });
18
19test('DL99: the wizard says what setup is doing (its own sentence), not "Downloading the picture reader" while the model file is checked', () => {
20  const checking = { running: true, step: '5/7: downloading Qwen3.6-35B-A3B UD-Q4_K_XL', phase: 'verify',
21    label: 'Checking that the model files are complete (a few minutes for a big model; nothing is downloaded)',
22    download: { file: 'checking files', done_gb: 4.13, total_gb: 22.85, remaining_gb: 18.72, percent: 18 },
23    parts: [model('done', 22.854), reader('waiting', 0), engineDone] };
24  const progress = lib.installProgress(checking);
25  assert.equal(lib.guidedStatusText(checking, progress), 'Checking that the model files are complete (a few minutes for a big model; nothing is downloaded)');
26  const tokenizer = { running: true, step: '6/7: preparing the model for Strata', phase: 'tokenizer', label: 'Preparing the tokenizer', parts: [engineDone] };
27  assert.equal(lib.guidedStatusText(tokenizer, lib.installProgress(tokenizer)), 'Preparing the tokenizer');
28  // no sentence from setup yet: the part being fetched, as before
29  const early = { running: true, parts: [model('downloading', 3.1), reader('waiting', 0)] };
30  assert.equal(lib.guidedStatusText(early, lib.installProgress(early)), 'Downloading model files…');
31  assert.equal(lib.guidedStatusText({ running: true }, undefined), 'Preparing your model…');
32  // a server that has not answered yet keeps its own waiting line first
33  const waiting = { running: true, phase: 'waiting', label: 'Waiting for huggingface.co to answer (25 s so far)', parts: [model('downloading', 0)] };
34  assert.equal(lib.guidedStatusText(waiting, lib.installProgress(waiting)), 'Waiting for huggingface.co to answer (25 s so far)');
35});
36
37test('DL99: the model check shows its own figure, not a frozen 96%; the counter does not call it "left to download"', () => {
38  const step = createEngineStep({ control: null });
39  const checking = { running: true, step: '5/7: downloading', label: 'Checking…',
40    download: { file: 'checking files', done_gb: 4.13, total_gb: 22.85, remaining_gb: 18.72, percent: 18 },
41    parts: [model('done', 22.854), reader('waiting', 0)] };
42  const p = lib.installProgress(step.merge(checking));
43  assert.equal(p.percent, 18);
44  assert.ok(Math.abs(p.done_gb - 4.13) < 0.01 && Math.abs(p.total_gb - 22.85) < 0.01, JSON.stringify(p));
45  const counter = lib.downloadCounter(23.8, p, true);
46  assert.notEqual(counter.label, 'GB left to download');
47});
48
49test('DL99: once every file is in, the bar says 100%, not 99% (and never 0.7 / 0.7 GB of the engine alone)', () => {
50  const done = { running: true, step: '6/7: preparing the model for Strata', label: 'Preparing the tokenizer',
51    parts: [model('done', 22.854), reader('done', 0.899), engineDone] };
52  const p = lib.installProgress(done);
53  assert.equal(p.percent, 100);
54  assert.ok(p.total_gb > 24, JSON.stringify(p));
55  const still = lib.installProgress({ parts: [model('done', 22.854), reader('downloading', 0.6), engineDone] });
56  assert.ok(still.percent < 100 && still.percent >= 96, JSON.stringify(still));
57  const almost = lib.installProgress({ parts: [model('downloading', 22.85), reader('done', 0.899)] });
58  assert.equal(almost.percent, 99, 'a part still downloading stays below 100');
59});
60
61const NOT_READY = "Your model is downloaded, but the engine for this PC isn't ready yet. Open Settings > About to install it.";
62
63test('DL99: an install that ended with every file in, for a model the missing engine keeps from being ready, says so on the wizard page', async () => {
64  const { readFileSync } = await import('node:fs');
65  // when: the job is done, the model is not ready, the engine for this PC is missing or can't be used
66  assert.equal(lib.engineNotReadyAfterInstall('done', false, false), true);
67  assert.equal(lib.engineNotReadyAfterInstall('done', undefined, false), true, 'a model the list does not show as ready yet');
68  assert.equal(lib.engineNotReadyAfterInstall('done', true, false), false, 'a ready model moves on to the next step');
69  assert.equal(lib.engineNotReadyAfterInstall('done', false, true), false, 'a usable engine: not this case');
70  assert.equal(lib.engineNotReadyAfterInstall('done', false, undefined), false, 'nothing known about the engine yet');
71  assert.equal(lib.engineNotReadyAfterInstall('running', false, false), false, 'not while the job runs');
72  assert.equal(lib.engineNotReadyAfterInstall('error', false, false), false, 'a failed job shows its own error');
73  // the wizard shows the owner's sentence (11-15) for that case, through the translation catalog
74  const page = readFileSync(new URL('../src/components/GuidedSetup.tsx', import.meta.url), 'utf8');
75  assert.ok(page.includes(`engineNotReadyAfterInstall(installJob?.state, installed?.ready, native?.engine?.usable) ? `), 'hooked to the install job, the model and the engine');
76  assert.ok(page.includes(`tr("${NOT_READY}")`));
77  assert.equal(lib.tr(NOT_READY), NOT_READY);
78  // all nine languages have it (scripts/make-engine-locales.py)
79  const en = JSON.parse(readFileSync(new URL('../src/locales/engine-en.json', import.meta.url), 'utf8'));
80  const key = Object.keys(en).find(k => en[k] === NOT_READY);
81  assert.ok(key, 'in the English catalog');
82  for (const l of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) {
83    const t = JSON.parse(readFileSync(new URL(`../src/locales/engine-${l}.json`, import.meta.url), 'utf8'))[key];
84    assert.ok(t && t !== NOT_READY && t.includes('>'), `${l}: ${t}`);
85  }
86  await lib.loadCatalog('de');
87  lib.setTranslationLanguage('de');
88  assert.match(lib.tr(NOT_READY), /^Dein Modell ist heruntergeladen/);
89  lib.setTranslationLanguage('en');
90});