okami.mom/strata

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

Niko1221Tests that pinned old values follow the merged decisions: native-fit (MTP layer 1.08 GB), tune-outcome (calm running step, GUI feedback 2 item 3), setup tests (128K default context on every card; the picture-file host in strata_control/pictures.py is behind acquisition.require)c0380157d

main
6.1 KiB75 linesraw
1/** Items 11, 13 and 15: one result layout for every outcome, and the tuned values in Expert mode. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFile } from 'node:fs/promises';
5import { build } from 'esbuild';
6import { fileURLToPath } from 'node:url';
7
8const src = f => fileURLToPath(new URL(`../src/${f}`, import.meta.url));
9async function load(file) {
10  const result = await build({ entryPoints: [src(`lib/${file}`)], bundle: true, format: 'esm', platform: 'node', write: false, alias: { react: fileURLToPath(new URL('./helpers/react-stub.mjs', import.meta.url)) }, logLevel: 'silent', loader: { '.json': 'json' } });
11  return import(`data:text/javascript;base64,${Buffer.from(result.outputFiles[0].text).toString('base64')}`);
12}
13globalThis.window ??= globalThis; globalThis.localStorage ??= { getItem: () => null, setItem: () => {} };
14globalThis.navigator ??= { language: 'en' };
15const { readOutcome, tokS, failureDetails } = await load('tune-outcome.ts');
16const { tunedFields, describeChange } = await load('tune-values.ts');
17
18test('every outcome the host reports lands on one card with a tone, an icon and its reason', () => {
19  const o = (result, state = 'done') => readOutcome(result, state);
20  const faster = o({ code: 'faster', values: { gain_pct: 18.4, base_tok_s: 41.2, tuned_tok_s: 48.6, preset_name: 'Fast · 64K' } });
21  assert.deepEqual([faster.code, faster.tone, faster.icon, faster.gainPct, faster.baseTokS, faster.tunedTokS, faster.presetName], ['faster', 'ok', 'check', 18.4, 41.2, 48.6, 'Fast · 64K']);
22  assert.deepEqual([o({ code: 'already_fastest', values: { base_tok_s: 41.2, minutes: 12 } }).tone, o({ code: 'already_fastest' }).icon], ['ok', 'check']);
23  const busy = o({ code: 'busy_pc', reason_code: 'noisy', values: { noise_pct: 14 } });
24  assert.deepEqual([busy.code, busy.tone, busy.icon, busy.reason, busy.noisePct], ['busy_pc', 'warn', 'clock', 'noisy', 14]);
25  assert.equal(o({ code: 'busy_pc', reason_code: 'not_tried' }).reason, 'not_tried');
26  const failed = o({ code: 'failed', reason_code: 'no_memory' });
27  assert.deepEqual([failed.code, failed.tone, failed.icon, failed.reason], ['failed', 'bad', 'x', 'no_memory']);
28  assert.equal(o({ code: 'stopped' }).tone, 'neutral');
29  assert.equal(o(null, 'cancelled').code, 'stopped');
30  assert.equal(o(null, 'error').code, 'failed', 'a job that ended in an error is a failed tune');
31});
32
33test('answers from a check of a saved tuning and from an older Control still get a card', () => {
34  const o = (r, s = 'done') => readOutcome(r, s);
35  assert.equal(o({ verdict: 'keep' }).code, 'still_fast'); assert.equal(o({ verdict: 'retune' }).code, 'slower'); assert.equal(o({ verdict: 'inconclusive' }).code, 'unsure');
36  assert.equal(o({ outcome: 'improved', gain_pct: 12, base: { decode_tok_s: 40 }, chosen: { decode_tok_s: 45 } }).tunedTokS, 45);
37  assert.equal(o({ outcome: 'default_confirmed' }).code, 'already_fastest'); assert.equal(o({ outcome: 'inconclusive' }).code, 'busy_pc'); assert.equal(o({ outcome: 'base_failed' }).code, 'failed');
38  assert.equal(tokS(41.234), '41.2'); assert.equal(tokS(null), '—');
39});
40
41test('the busy-PC card says it in plain words, in the same card as every other result, with Try again', async () => {
42  const card = await readFile(src('components/TuneRunView.tsx'), 'utf8');
43  assert.match(card, /Your PC was busy during the test, so we couldn't measure reliably\. Nothing was changed\. Try again when other programs are closed\./);
44  const dialog = await readFile(src('components/NativeTune.tsx'), 'utf8');
45  assert.match(dialog, /<TuneOutcomeCard outcome=\{outcome\}/); assert.match(dialog, /'Try again'/);
46  assert.ok(!/tune-orbit/.test(dialog), 'no second, different-looking result screen');
47});
48
49test('item 14 (changed by GUI feedback 2, item 3): the running step is calm - no glow, no beep, no spinning ring - and reduced motion is honoured', async () => {
50  const css = await readFile(src('styles/app.css'), 'utf8');
51  assert.ok(!/tune-glow|tune-beep/.test(css), 'the glow and the beep animations are gone from the running step');
52  assert.ok(!/\.tune-step\[data-s="run"\] \.tune-step__badge::before/.test(css), 'the spinning ring is gone');
53  assert.match(css, /prefers-reduced-motion: reduce\) \{[\s\S]*tune-step__state::before/, 'reduced motion switches the pulse off too');
54});
55
56test('item 11: Expert mode shows the values the tuning set', () => {
57  const f = tunedFields([{ flag: '--kv', was: 'int8', now: 'k8v4' }, { flag: '--resident-experts', was: null, now: '' }, { flag: '--vram-reserve-mib', was: '1536', now: '2048' }, { flag: '--spec', was: '4', now: '6' }]);
58  assert.deepEqual(f, { kv: 'k8v4', lowRam: 'resident', vramReserveMib: 2048 });
59  assert.deepEqual(tunedFields([{ flag: '--mmap-experts', was: '', now: null }]), { lowRam: 'auto' });
60  assert.deepEqual(tunedFields(undefined), {});
61  assert.deepEqual(describeChange({ flag: '--pool-workers', was: '6', now: '8' }), { name: 'pool workers', now: '8', was: '6' });
62});
63
64test('#4805: a tuning that did not finish carries the reason the tuner gave and what this PC has in its Details', () => {
65  const hardware = { ram_gb: 32, gpus: [{ name: 'NVIDIA GeForce RTX 4050 Laptop GPU', vram_gb: 6 }] };
66  const text = failureDetails({ message: 'Your current settings could not be measured: the engine stopped: no VRAM is left for the expert cache', notes: ['The model was unloaded for the test.'] }, hardware);
67  assert.match(text, /^Your current settings could not be measured: the engine stopped: no VRAM is left for the expert cache/);
68  assert.match(text, /The model was unloaded for the test\./);
69  assert.match(text, /Memory: 32 GB in this PC/);
70  assert.match(text, /Graphics card: NVIDIA GeForce RTX 4050 Laptop GPU, 6 GB/);
71  assert.equal(failureDetails({ message: 'Not tuned: not enough free memory to start it safely (3.1 GiB free, 9.0 GiB needed)' }, null), 'Not tuned: not enough free memory to start it safely (3.1 GiB free, 9.0 GiB needed)');
72  assert.equal(failureDetails({ summary: 'x' }, hardware), null, 'nothing to say: no empty Details');
73  assert.equal(failureDetails(null, hardware), null);
74  assert.equal(failureDetails({ message: 'a', notes: ['a'] }, null), 'a', 'the same sentence is not repeated');
75});