okami.mom/strata

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

Niko1221Merge f-clean-7 (045843071): the app loads screens, languages, Prism and Time-skip on first use; main chunk 3,123,528 -> 755,418 B, start screen 248.5 -> 143.4 ms (p2006 Chrome, median of 10); nothing users see changes (cleanup step 7)1631a9fde

main
4.6 KiB71 linesraw
1import test from 'node:test';
2import assert from 'node:assert/strict';
3import { readFile } from 'node:fs/promises';
4import { build } from 'esbuild';
5
6const bundled = await build({ entryPoints: ['src/lib/loop.ts'], bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
7const { parseLoop, loopEvery, LOOP_MIN_MS } = await import(`data:text/javascript;base64,${Buffer.from(bundled.outputFiles[0].text).toString('base64')}`);
8
9test('/loop reads how often, then what to do', () => {
10  assert.deepEqual(parseLoop('/loop 10m check the build'), { kind: 'start', everyMs: 600000, prompt: 'check the build' });
11  assert.deepEqual(parseLoop('/loop 2h summarise my inbox notes'), { kind: 'start', everyMs: 7200000, prompt: 'summarise my inbox notes' });
12  assert.deepEqual(parseLoop('/loop every 5 minutes say hi'), { kind: 'start', everyMs: 300000, prompt: 'say hi' });
13  assert.equal(parseLoop('hello /loop'), null, 'only a message that starts with /loop is a loop');
14  assert.equal(parseLoop('/looping'), null);
15});
16
17test('/loop with no time, a tiny time or a huge time is explained in plain words, never run', () => {
18  assert.equal(parseLoop('/loop check the build').kind, 'help');
19  assert.match(parseLoop('/loop check the build').problem, /how often/);
20  assert.match(parseLoop('/loop 10s ping').problem, /1 minute/);
21  assert.match(parseLoop('/loop 48h ping').problem, /24 hours/);
22  assert.equal(LOOP_MIN_MS, 60000);
23});
24
25test('/loop, /loop stop and the words for how often', () => {
26  assert.deepEqual(parseLoop('/loop'), { kind: 'status' });
27  assert.deepEqual(parseLoop('/loop stop'), { kind: 'stop' });
28  assert.deepEqual(parseLoop('/loop OFF'), { kind: 'stop' });
29  assert.equal(loopEvery(60000), 'every minute');
30  assert.equal(loopEvery(600000), 'every 10 minutes');
31  assert.equal(loopEvery(3600000), 'every hour');
32  assert.equal(loopEvery(7200000), 'every 2 hours');
33});
34
35test('the slash menu lists /time-skip, /goal and /loop with plain descriptions, and /loop no longer just opens Tasks', async () => {
36  const chat = await readFile('src/screens/Chat.tsx', 'utf8');
37  for (const [label, words] of [['/time-skip', 'Try a change on a copy'], ['/goal', 'keep working until it is done'], ['/loop', 'every few minutes']]) {
38    const line = chat.split('\n').find(l => l.includes(`label: '${label}'`));
39    assert.ok(line, `${label} is in the menu`);
40    assert.ok(line.includes(words), `${label} has a plain description`);
41  }
42  const commands = await readFile('src/lib/commands.ts', 'utf8');
43  assert.ok(!/slash: \['loop'\]/.test(commands), 'the old /loop alias that only opened Tasks is gone');
44});
45
46test('the store sends /loop to the loop and /time-skip to a real job when a local model is ready', async () => {
47  const store = await readFile('src/lib/store.ts', 'utf8');
48  assert.match(store, /parseLoop\(text\.trim\(\)\)/);
49  assert.match(store, /startTimeSkipReal\(demoPrompt\)/);
50  assert.match(store, /nativeState\(\)\?\.instances\.some\(i => i\.status === 'ready'\)/);
51  assert.match(store, /!m\.timeSkipId && !m\.local/, 'notes from the app and trial turns are not sent back to the model');
52});
53
54test('the new slash-command, Time-skip and Tools words are translated in every language, with their slots', async () => {
55  const i18n = await build({ stdin: { contents: "export * from './src/lib/i18n';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
56  const { tr, setTranslationLanguage, loadCatalog } = await import(`data:text/javascript;base64,${Buffer.from(i18n.outputFiles[0].text).toString('base64')}`);
57  for (const l of ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr']) await loadCatalog(l);  // the non-English catalogs load on first use (src/lib/i18n.ts loadCatalog); load them before the first tr()
58  const cases = [
59    ['Keep the update', 'de', 'Aktualisierung behalten'],
60    ['Put the original back', 'ja', '元に戻す'],
61    ['Repeat a message every few minutes while this chat is open', 'es', 'Repite un mensaje cada pocos minutos mientras este chat esté abierto'],
62    ['Search the web', 'zh', '搜索网络'],
63  ];
64  for (const [text, lang, want] of cases) { setTranslationLanguage(lang); assert.equal(tr(text), want, `${lang}: ${text}`); }
65  setTranslationLanguage('de');
66  assert.equal(tr('Revision {0}', [2]), 'Überarbeitung 2');
67  assert.equal(tr('every {0} minutes', [10]), 'alle 10 Minuten');
68  assert.equal(tr('Time-skip stopped. The model rejected the credentials. Your files were not changed.'), 'Time-skip wurde gestoppt. The model rejected the credentials. Deine Dateien wurden nicht geändert.');
69  setTranslationLanguage('en');
70  assert.equal(tr('Keep the update'), 'Keep the update');
71});