okami.mom/strata

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

Niko1221Merge f-ds-out ac306afb2 into f-own-intaff3a132f

main
5.7 KiB59 linesraw
1// Settings > Engine with the engine of a Qwen4 model shape (APP-WIN item 6): Control lists it as its own family ("shape:<shape>", title null); the page titles
2// the group with the model's catalog title (the shape's name when the catalog has none), never the family id; switch and delete pass the family through;
3// an install with no shape engine renders exactly as before (the page source still titles Control's groups with Control's title).
4import test from 'node:test';
5import assert from 'node:assert/strict';
6import { readFileSync as read } from 'node:fs';
7import { build } from 'esbuild';
8import { changeEngine } from '../server/engine-library.mjs';
9
10const built = await build({ stdin: { contents: "export * from './src/lib/engine-list';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
11const { engineGroupTitle } = await import(`data:text/javascript;base64,${Buffer.from(built.outputFiles[0].text).toString('base64')}`);
12
13const catalog = [{ family: 'qwen', title: 'Qwen3.8-Flash-Next' }, { family: 'qwen4exp_q4_lite', title: 'Qwen4 Lite' }];
14
15test('the group heading: Control\'s title for Qwen, the model\'s catalog title for a shape, the shape\'s name without one; never the family id', () => {
16  assert.equal(engineGroupTitle({ family: 'qwen', title: 'Qwen and other models', engines: [] }, catalog), 'Qwen and other models');
17  assert.equal(engineGroupTitle({ family: 'shape:q4_lite', shape: 'q4_lite', title: null, engines: [] }, catalog), 'Qwen4 Lite');
18  assert.equal(engineGroupTitle({ family: 'shape:q4_mid', shape: 'q4_mid', title: null, engines: [] }, catalog), 'q4_mid');
19  assert.equal(engineGroupTitle({ family: 'shape:q4_mid', title: null, engines: [] }, null), 'q4_mid', 'no shape field: from the family, no catalog');
20  for (const g of [{ family: 'shape:q4_lite', shape: 'q4_lite', title: null, engines: [] }, { family: 'shape:q4_mid', title: null, engines: [] }])
21    assert.doesNotMatch(engineGroupTitle(g, catalog), /shape:/);
22});
23
24test('switch and delete take a shape family and pass it to Control; anything else is still refused', async () => {
25  const calls = [];
26  const control = { useEngine: async a => { calls.push(['use', a]); return { status: 'switched' }; }, removeEngine: async a => { calls.push(['remove', a]); return { status: 'deleted' }; } };
27  assert.equal((await changeEngine(control, 'use', { family: 'shape:q4_lite', folder: '0.1.59-windows-x86_64-cuda-cuda13' })).status, 200);
28  assert.equal((await changeEngine(control, 'remove', { family: 'shape:q4_lite', folder: '0.1.58-windows-x86_64-cuda-cuda13' })).status, 200);
29  assert.deepEqual(calls.map(c => c[1].family), ['shape:q4_lite', 'shape:q4_lite']);
30  for (const family of ['shape:', 'shape:Q4', 'shape:../x', 'shapes:q4_lite', 'q4_lite', 'strata-q4-lite'])
31    assert.equal((await changeEngine(control, 'use', { family, folder: 'a' })).status, 400, family);
32  assert.equal(calls.length, 2);
33});
34
35test('the page: Control\'s title when it has one (no change for an install without shape engines), the catalog-derived one otherwise', () => {
36  const page = read(new URL('../src/components/SettingsEngine.tsx', import.meta.url), 'utf8');
37  assert.match(page, /\{groups\.length > 1 \? <h3 className="engine-group__title">\{group\.title \? tr\(group\.title\) : engineGroupTitle\(group, native\?\.catalog\?\.families\)\}<\/h3> : null\}/);
38});
39
40test('the Use dialog (owner 11-09): a shape group says "{model} runs on engine {version} from its next start." with the group title; Strata keeps its sentence', () => {
41  const page = read(new URL('../src/components/SettingsEngine.tsx', import.meta.url), 'utf8');
42  assert.match(page, /const useGroup = use \? groups\.find\(g => g\.family === use\.family\) : undefined;/);
43  assert.match(page, /useGroup\?\.family\.startsWith\('shape:'\) \? tr\("\{0\} runs on engine \{1\} from its next start\. Your models and settings stay as they are\. You can switch back at any time\.", \[engineGroupTitle\(useGroup, native\?\.catalog\?\.families\), use\?\.version \?\? ''\]\) : tr\("Models you start from now on run on engine \{0\}\. Your models and settings stay as they are\. You can switch back at any time\."/);
44  // the words as the person reads them, with the owner's example
45  const en = JSON.parse(read(new URL('../src/locales/engine-en.json', import.meta.url), 'utf8'));
46  const key = Object.keys(en).find(k => en[k] === '{0} runs on engine {1} from its next start. Your models and settings stay as they are. You can switch back at any time.');
47  assert.ok(key, 'in the English catalog');
48  const title = engineGroupTitle({ family: 'shape:q4_lite', shape: 'q4_lite', title: null, engines: [] }, [{ family: 'qwen4exp_q4_lite', title: 'Qwen4' }]);
49  assert.equal(en[key].replace('{0}', title).replace('{1}', '0.1.60'), 'Qwen4 runs on engine 0.1.60 from its next start. Your models and settings stay as they are. You can switch back at any time.');
50  for (const lang of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) {
51    const t = JSON.parse(read(new URL(`../src/locales/engine-${lang}.json`, import.meta.url), 'utf8'))[key];
52    assert.ok(t && t.includes('{0}') && t.includes('{1}'), lang);
53    // only the first sentence is new: the reassurance is the existing translation of the Strata engine's sentence, word for word
54    const use = JSON.parse(read(new URL(`../src/locales/engine-${lang}.json`, import.meta.url), 'utf8')).et15;
55    const rest = use.slice(use.search(/[。.]\s*/) + use.match(/[。.]\s*/)[0].length);
56    assert.ok(rest.length > 5 && t.endsWith(rest), lang + ': ' + t);
57  }
58  assert.ok(Object.values(en).includes('Models you start from now on run on engine {0}. Your models and settings stay as they are. You can switch back at any time.'), 'the Strata sentence is unchanged');
59});