okami.mom/strata

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

Niko1221rc1 merge ds-coder (d6a5a7837)4fb068a8c

main
5.1 KiB72 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { readFile } from 'node:fs/promises';
4import { nativeFixture, finishJob } from './helpers/native-fixture.mjs';
5
6test('a second model on a card another model uses still loads (recommend, never force); two cards, two models', async () => {
7  const f = nativeFixture();
8  try {
9    await f.control.refresh(true);
10    const load = async args => { const done = await finishJob(f.control, f.control.operation('load', args).id); assert.equal(done.state, 'done', done.error); return done; };
11    await load({ model: 'iq2_xs', gpus: [0], multiple: true });
12    await load({ model: 'iq3_s', gpus: [1], multiple: true });
13    assert.deepEqual(f.control.state().instances.map(i => [i.model, i.gpus, i.status]), [['iq2_xs', [0], 'ready'], ['iq3_s', [1], 'ready']]);
14    await load({ model: 'iq3_s', gpus: [0], multiple: true });   // the same card as the first model: allowed, and said on the card's row
15    assert.equal(f.control.state().instances.length, 3);
16  } finally { await f.cleanup(); }
17});
18
19test('the screens say which card a loaded model uses, prefer a free card for a second model, and show an unload refusal beside its button', async () => {
20  const models = await readFile(new URL('../src/components/NativeModels.tsx', import.meta.url), 'utf8');
21  assert.match(models, /usedBy=\{i => usedBy\(\[i\]\)\}/);
22  assert.match(models, /const busy = \(i: number\) => expert && multiple && usedBy\(\[i\]\)\.length > 0/);   // a card another loaded model uses starts Off
23  const roles = await readFile(new URL('../src/components/GpuRoles.tsx', import.meta.url), 'utf8');
24  assert.match(roles, /tr\('In use by \{0\}', \[other\.join\(', '\)\]\)/);
25  assert.match(models, /loadedAction\(`instances\/\$\{i\.id\}\/unload`\)/);
26  assert.match(models, /loadedError \? <ErrorNotice message=\{loadedError\}/);
27  const control = await readFile(new URL('../server/native-control.mjs', import.meta.url), 'utf8');
28  assert.match(control, /is already used by \$\{sharedWith\.label\}, so this model did not fit there/);
29});
30
31test('usedBy is declared before the card choice that calls it (a const used earlier broke the Models page when Run multiple models was on)', async () => {
32  const models = await readFile(new URL('../src/components/NativeModels.tsx', import.meta.url), 'utf8');
33  assert.ok(models.indexOf('const usedBy = ') > 0 && models.indexOf('const usedBy = ') < models.indexOf('const recommended = '));
34});
35
36test('a model that failed to start is not offered in the chat model picker', async () => {
37  const picker = await readFile(new URL('../src/components/ChatModelPicker.tsx', import.meta.url), 'utf8');
38  assert.equal((picker.match(/native\?\.instances\.filter\(i => i\.status !== 'error'\)\.map/g) ?? []).length, 2);
39});
40
41import { friendlyModelName } from '../server/model-names.mjs';
42test('a loaded model is named from the catalog (family and version), the file id only as a fallback', async () => {
43  const catalog = { families: [{ title: 'Qwen3.8-Flash-Next', sizes: [{ id: 'q2_0', model: 'Q2_0' }] }, { title: 'Qwen3.8-Flash-Next (Gyro)', sizes: [{ id: 'gyro-gyro-s', model: 'Gyro-S' }] }] };
44  assert.equal(friendlyModelName(catalog, 'q2_0'), 'Qwen3.8-Flash-Next Q2_0');
45  assert.equal(friendlyModelName(catalog, 'gyro-gyro-s'), 'Qwen3.8-Flash-Next Gyro-S');
46  assert.equal(friendlyModelName(catalog, 'nope'), null);
47  assert.equal(friendlyModelName(null, 'q2_0'), null);
48  const f = nativeFixture();
49  try {
50    await f.control.refresh(true);
51    const done = await finishJob(f.control, f.control.operation('load', { model: 'iq2_xs' }).id);
52    assert.equal(done.state, 'done', done.error);
53    assert.equal(f.control.state().instances[0].label, 'Qwen3.8-Flash-Next IQ2_XS');
54  } finally { await f.cleanup(); }
55});
56
57test('card names use the GPU numbering of the other screens, and the fit figures subtract the models that stay loaded', async () => {
58  const models = await readFile(new URL('../src/components/NativeModels.tsx', import.meta.url), 'utf8');
59  const roles = await readFile(new URL('../src/lib/gpu-roles.ts', import.meta.url), 'utf8');
60  assert.ok(roles.includes('`GPU ${c.index + 1}`'));    // GPU 1 is card 0, as on every other screen
61  assert.match(await readFile(new URL('../src/components/GpuRoles.tsx', import.meta.url), 'utf8'), /\{gpuLabel\(c\)\} · \{c\.name\}/);
62  assert.match(models, /const keptModels = expert && multiple/);
63  assert.match(models, /inUse=\{keptModels\.length \?/);
64  const card = await readFile(new URL('../src/components/PcFitCard.tsx', import.meta.url), 'utf8');
65  assert.match(card, /vramGb > 0 \? <FreeMeter label="Graphics memory" total=\{live\.vramTotalGb \?\? vramGb\} free=\{live\.freeVramGb\}/);
66  assert.match(card, /<FreeMeter label="RAM" total=\{ramGb\} free=\{live\.freeRamGb\}/);
67  // the arithmetic itself
68  const text = 'fits: needs 44 GB of the 273 GB available.';
69  const gone = Math.round(14 + 27);
70  assert.equal(text.replace(/of the (\d+) GB available/, (_m, n) => `of the ${Math.max(0, Number(n) - gone)} GB available`), 'fits: needs 44 GB of the 232 GB available.');
71  assert.equal('RX 9070 (card 0) + RAM'.replace(/\(card (\d+)\)/g, (_m, n) => `(GPU ${Number(n) + 1})`), 'RX 9070 (GPU 1) + RAM');
72});