okami.mom/strata

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

Niko1221rc1 merge ds-coder (d6a5a7837)4fb068a8c

main
5.3 KiB74 linesraw
1/** Models > This computer: free graphics memory and RAM first, the SSD only when the model does not fit, and a loaded model changes the card. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { build } from 'esbuild';
5import { mkdtempSync, writeFileSync, rmSync, readFileSync } from 'node:fs';
6import { tmpdir } from 'node:os';
7import { join } from 'node:path';
8import { fileURLToPath, pathToFileURL } from 'node:url';
9
10const stdin = { contents: "import { createElement } from 'react'; import { renderToStaticMarkup } from 'react-dom/server'; import { PcFitCard } from './src/components/PcFitCard'; export { setTranslationLanguage } from './src/lib/i18n'; export const render = props => renderToStaticMarkup(createElement(PcFitCard, props));", resolveDir: fileURLToPath(new URL('..', import.meta.url)), loader: 'ts' };
11const built = await build({ stdin, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json', '.tsx': 'tsx' }, jsx: 'automatic', logLevel: 'silent', banner: { js: "import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);" } });
12const dir = mkdtempSync(join(tmpdir(), 'strata-pc-test-'));
13writeFileSync(join(dir, 'card.mjs'), built.outputFiles[0].text);
14const { render, setTranslationLanguage } = await import(pathToFileURL(join(dir, 'card.mjs')).href);
15rmSync(dir, { recursive: true, force: true });
16const fit = (spillGb, vramUseGb = 12, ramUseGb = 44) => ({ memoryGb: vramUseGb + ramUseGb + spillGb, vramUseGb, ramUseGb, spillGb, known: true });
17const card = props => render({ gpuName: 'RTX 5070', ramGb: 64, vramGb: 12, ...props });
18const live = { vramTotalGb: 12, freeVramGb: 10.3, freeRamGb: 49.8, diskReadGbs: null };
19
20test('free graphics memory and free RAM come first, as real readings', () => {
21  setTranslationLanguage('en');
22  const html = card({ fit: fit(0), live });
23  assert.match(html, /Free right now/);
24  assert.match(html, /Graphics memory<\/span><b>10\.3 GB free<\/b>/);
25  assert.match(html, /RAM<\/span><b>49\.8 GB free<\/b>/);
26  assert.match(html, /of 12 GB/);
27  assert.doesNotMatch(card({ fit: fit(0), live: null }), /Free right now/, 'no readings: no invented numbers');
28});
29
30test('the card does not repeat the SSD warning the version picker already gives; a version that fits says nothing either', () => {
31  setTranslationLanguage('en');
32  assert.doesNotMatch(card({ fit: fit(0), live }), /SSD/);
33  assert.doesNotMatch(card({ fit: fit(0), live }), /Fits fully in memory/, 'no "Fits" words (owner, 11-01)');
34  assert.doesNotMatch(card({ fit: fit(30), live }), /read from the SSD/, 'said once, under the picker');
35  assert.match(card({ fit: fit(30), live }), /This version would take about 12 GB of graphics memory and 44 GB of RAM\./);
36});
37
38test('a loaded model leaves the free memory and nothing else: no hardware line, no name, no Loaded, no "It takes about", no numbers, no SSD line', () => {
39  setTranslationLanguage('en');
40  const fits = card({ fit: fit(0), live, loaded: [{ id: 'iq3_s', label: 'Qwen3.8-Flash-Next · IQ3_S', fit: fit(0) }], selectedLoaded: true });
41  assert.match(fits, /This computer/);
42  assert.match(fits, /Free right now/);
43  assert.match(fits, /Graphics memory<\/span><b>10\.3 GB free<\/b>/);
44  for (const gone of [/RTX 5070/, /graphics memory · /, /Qwen3\.8-Flash-Next/, /Loaded/, /It takes about/, /<dl/, /<dt>/, /SSD/, /pc-loaded/]) assert.doesNotMatch(fits, gone, String(gone));
45  // A loaded model that really streams from the SSD keeps how fast it reads right now; nothing else comes back.
46  const spills = card({ fit: fit(18), live: { ...live, diskReadGbs: 1.2 }, loaded: [{ id: 'q', label: 'Qwen3.8-Flash-Next · UD-Q4_K_XL', fit: fit(18, 12, 53) }], selectedLoaded: true });
47  assert.doesNotMatch(spills, /About 18 GB will be read/);
48  assert.match(spills, /Reading from your SSD now: 1\.2 GB\/s/);
49  for (const gone of [/<dl/, /<dt>/, /Loaded/, /It takes about/, /RTX 5070/]) assert.doesNotMatch(spills, gone, String(gone));
50  assert.doesNotMatch(spills, /This version would take/);
51});
52
53test('before anything is loaded the card says what the chosen version would take', () => {
54  setTranslationLanguage('en');
55  assert.match(card({ fit: fit(0), live }), /This version would take about 12 GB of graphics memory and 44 GB of RAM\./);
56});
57
58test('the numbers come from the host\'s readings, polled while the page is open and read without redrawing the Models page', () => {
59  const wrapper = readFileSync(fileURLToPath(new URL('../src/components/PcComputer.tsx', import.meta.url)), 'utf8');
60  assert.match(wrapper, /api\.get\('\/api\/monitor'\)/);
61  assert.match(wrapper, /useStore\(s => tenth\(s\.monitor\?\.hardware\?\.vramUsedGb\)\)/);
62  assert.match(wrapper, /useStore\(s => tenth\(s\.monitor\?\.hardware\?\.ramUsedGb\)\)/);
63});
64
65test('the new words are in all nine languages', () => {
66  const en = JSON.parse(readFileSync(fileURLToPath(new URL('../src/locales/pick-en.json', import.meta.url)), 'utf8'));
67  for (const lang of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) {
68    const cat = JSON.parse(readFileSync(fileURLToPath(new URL(`../src/locales/pick-${lang}.json`, import.meta.url)), 'utf8'));
69    for (const id of Object.keys(en)) {
70      assert.ok(cat[id], `${lang} ${id}`);
71      assert.deepEqual((cat[id].match(/\{\d+\}/g) ?? []).sort(), (en[id].match(/\{\d+\}/g) ?? []).sort(), `${lang} ${id} slots`);
72    }
73  }
74});