okami.mom/strata

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

Niko1221Merge f-split-int (c157ea373) into f-split-qa1: my new strings renumbered after s3236 (s3237-s3255)e5476b0e1

main
4.4 KiB62 linesraw
1// QA report F04: a skill created with "Skill enabled" off stays off, and it keeps its trigger phrases.
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { spawn } from 'node:child_process';
5import { mkdtemp, rm } from 'node:fs/promises';
6import { createServer } from 'node:net';
7import { tmpdir } from 'node:os';
8import { join, resolve } from 'node:path';
9
10const root = resolve(import.meta.dirname, '..');
11
12async function startHost(home) {
13  const socket = createServer(); await new Promise(r => socket.listen(0, '127.0.0.1', r));
14  const port = socket.address().port; await new Promise(r => socket.close(r));
15  const child = spawn(process.execPath, ['server/index.mjs'], { cwd: root, env: { ...process.env, STRATA_HOME: home, STRATA_MODELS_DIR: join(home, 'models'), STRATA_PORT: String(port), STRATA_REAL_ENGINE: '0', STRATA_WORKSPACE: join(home, 'work') }, stdio: 'ignore', windowsHide: true });
16  const base = `http://127.0.0.1:${port}`;
17  const call = async (path, method = 'GET', body) => {
18    const response = await fetch(base + path, { method, headers: body ? { 'Content-Type': 'application/json' } : undefined, body: body ? JSON.stringify(body) : undefined });
19    return { status: response.status, data: await response.json() };
20  };
21  for (let i = 0; i < 100; i++) { try { if ((await call('/api/skills')).status === 200) break; } catch { /* not up yet */ } await new Promise(r => setTimeout(r, 100)); }
22  const stopped = new Promise(r => child.once('exit', r));
23  return { call, stop: async () => { child.kill(); await stopped; } };
24}
25
26test('a skill created with Skill enabled off is saved off, kept after a restart, and an enabled one stays on', { timeout: 60000 }, async () => {
27  const home = await mkdtemp(join(tmpdir(), 'strata-qa2-skill-'));
28  let host = await startHost(home);
29  try {
30    const off = await host.call('/api/skills', 'POST', { name: 'QA disabled creation check', description: 'a', body: 'Harmless test instructions.', enabled: false, triggers: ['qa check', ' ', 'qa check', 'disabled'] });
31    assert.equal(off.status, 201);
32    const row = off.data.skills.find(s => s.id === off.data.id);
33    assert.equal(row.enabled, false, 'the answer to the save already says off');
34    assert.deepEqual(row.triggers, ['qa check', 'disabled']);
35    const on = await host.call('/api/skills', 'POST', { name: 'QA enabled one', description: '', body: 'More instructions.', enabled: true });
36    assert.equal(on.data.skills.find(s => s.id === on.data.id).enabled, true);
37    const plain = await host.call('/api/skills', 'POST', { name: 'QA no flag', body: 'Older callers send no flag.' });
38    assert.equal(plain.data.skills.find(s => s.id === plain.data.id).enabled, true, 'no flag keeps the old behaviour: on');
39    assert.equal((await host.call('/api/skills', 'POST', { name: 'Bad', body: 'x', triggers: 'not a list' })).status, 400);
40    await host.stop();
41    host = await startHost(home);
42    const again = (await host.call('/api/skills')).data;
43    assert.equal(again.find(s => s.id === off.data.id).enabled, false, 'still off after a restart');
44    assert.deepEqual(again.find(s => s.id === off.data.id).triggers, ['qa check', 'disabled']);
45    assert.equal(again.find(s => s.id === on.data.id).enabled, true);
46  } finally { await host.stop(); await rm(home, { recursive: true, force: true, maxRetries: 3 }).catch(() => {}); }
47});
48
49test('F05: the host refuses an output limit below 0 or above its maximum, and keeps the saved one', { timeout: 60000 }, async () => {
50  const home = await mkdtemp(join(tmpdir(), 'strata-qa2-tokens-'));
51  const host = await startHost(home);
52  try {
53    const value = async () => (await host.call('/api/engine')).data.expert.find(p => p.id === 'sample.maxTokens').value;
54    assert.equal(await value(), 0);
55    assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: -1 }] })).status, 400);
56    assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: 1048577 }] })).status, 400);
57    assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: 2.5 }] })).status, 400);
58    assert.equal(await value(), 0, 'nothing was saved');
59    assert.equal((await host.call('/api/engine', 'PATCH', { expert: [{ id: 'sample.maxTokens', value: 4096 }] })).status, 200);
60    assert.equal(await value(), 4096);
61  } finally { await host.stop(); await rm(home, { recursive: true, force: true, maxRetries: 3 }).catch(() => {}); }
62});