okami.mom/strata

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

Niko1221Merge f-split-int (a3024ed10) into f-split-qa1: qa2's s3237-s3238 kept, my 21 strings renumbered s3260-s32808667a3dbf

main
5.4 KiB75 linesraw
1// QA report F05: a number typed into Response settings is checked against the field's own range.
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFile } from 'node:fs/promises';
5import { transform } from 'esbuild';
6async function loadTs(path) {
7  const { code } = await transform(await readFile(new URL(path, import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });
8  return import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
9}
10const { checkWholeNumber, numberProblem } = await loadTs('../src/lib/number-field.ts');
11
12test('Max output tokens: -1 and other numbers outside 0 to 1048576 are refused, whole numbers inside are taken', () => {
13  assert.deepEqual(checkWholeNumber('-1', 0, 1048576), { ok: false, problem: 'range' });
14  assert.deepEqual(checkWholeNumber('1048577', 0, 1048576), { ok: false, problem: 'range' });
15  assert.deepEqual(checkWholeNumber('0', 0, 1048576), { ok: true, value: 0 });
16  assert.deepEqual(checkWholeNumber(' 4096 ', 0, 1048576), { ok: true, value: 4096 });
17  assert.deepEqual(checkWholeNumber('1048576', 0, 1048576), { ok: true, value: 1048576 });
18});
19
20test('Seed accepts -1 (random) and refuses what is not a whole number', () => {
21  assert.deepEqual(checkWholeNumber('-1', -1, 2147483647), { ok: true, value: -1 });
22  assert.equal(checkWholeNumber('-2', -1, 2147483647).ok, false);
23  for (const bad of ['', '  ', '-', '1.5', '1e3', 'abc', '12abc', '99999999999999999999']) assert.equal(checkWholeNumber(bad, -1, 2147483647).ok, false, JSON.stringify(bad));
24  assert.deepEqual(checkWholeNumber('', 0, 5), { ok: false, problem: 'empty' });
25});
26
27test('the sentence says what is wrong in plain words, with the range written the reader\'s way', () => {
28  const fmt = n => n.toLocaleString('en');
29  assert.equal(numberProblem(checkWholeNumber('7', 0, 10), 0, 10, fmt), null);
30  assert.deepEqual(numberProblem(checkWholeNumber('', 0, 10), 0, 10, fmt), { text: 'Enter a number.', args: [] });
31  assert.deepEqual(numberProblem(checkWholeNumber('-1', 0, 1048576), 0, 1048576, fmt), { text: 'Enter a whole number from {0} to {1}.', args: ['0', '1,048,576'] });
32});
33
34test('the Response settings dialog uses it: wrong numbers show the sentence and the save stays off', async () => {
35  const source = (await readFile(new URL('../src/app/SamplingDrawer.tsx', import.meta.url), 'utf8')).replace(/\r\n/g, '\n');
36  assert.match(source, /checkWholeNumber\(text, field\.min, field\.max\)/);
37  assert.match(source, /disabled=\{pending \|\| !dirty \|\| invalid\}/);
38  assert.match(source, /if \(!dirty \|\| pending \|\| invalid\)/);
39  assert.match(source, /aria-invalid=\{problem \? true : undefined\}/);
40});
41
42test('F07: a page opened from another computer says why Add skill cannot work instead of waiting', async () => {
43  const pick = await loadTs('../src/lib/folder-pick.ts').catch(() => null);
44  const source = (await readFile(new URL('../src/lib/folder-pick.ts', import.meta.url), 'utf8'));
45  const fn = new Function(`${source.slice(source.indexOf('export function pageIsOnThisComputer')).replace('export function', 'function')}; return pageIsOnThisComputer;`.replace(/: string|: boolean/g, ''))();
46  for (const yes of ['localhost', '127.0.0.1', '127.1.2.3', '[::1]', '::1']) assert.equal(fn(yes), true, yes);
47  for (const no of ['192.168.1.5', 'strata.example.com', 'my-pc.trycloudflare.com']) assert.equal(fn(no), false, no);
48  const skills = (await readFile(new URL('../src/screens/Skills.tsx', import.meta.url), 'utf8'));
49  assert.match(skills, /pageIsOnThisComputer\(window\.location\.hostname\)/);
50  void pick;
51});
52
53test('F08: the message box stops at 30% of the window height (44 to 180 px) and scrolls inside', async () => {
54  const source = await readFile(new URL('../src/lib/responsive.ts', import.meta.url), 'utf8');
55  const composerCap = new Function(`${source.slice(source.indexOf('export function composerCap')).replace('export function', 'function').replace(/: number/g, '')}; return composerCap;`)();
56  assert.equal(composerCap(400), 120); assert.equal(composerCap(500), 150); assert.equal(composerCap(720), 180); assert.equal(composerCap(2000), 180); assert.equal(composerCap(100), 44);
57  const css = await readFile(new URL('../src/styles/annotation-fixes.css', import.meta.url), 'utf8');
58  assert.match(css, /\.composer \.st-composer textarea \{ max-height: clamp\(44px, 30dvh, 180px\); overflow-y: auto; \}/);
59  assert.match(await readFile(new URL('../src/screens/Chat.tsx', import.meta.url), 'utf8'), /composerCap\(window\.innerHeight\)/);
60});
61
62test('O02: the screenshot Download button saves the picture and then says so', async () => {
63  const source = (await readFile(new URL('../src/components/SnapshotDialog.tsx', import.meta.url), 'utf8')).replace(/\r\n/g, '\n');
64  assert.match(source, /onClick=\{\(\) => saveSnapshotWithNotice\(data\)\}>\{tr\("Download"\)\}/);
65  assert.match(source, /downloadSnapshot\(data\);\n\s+pushToast\('success'/);
66  assert.match(source, /pushToast\('error', tr\('The screenshot was not saved'\)/);
67});
68
69test('item 1: the desktop window leaves file drops to the page, and the drop box is animated', async () => {
70  const rust = await readFile(new URL('../../desktop/src-tauri/src/main.rs', import.meta.url), 'utf8');
71  assert.match(rust, /#\[cfg\(windows\)\]\s+let builder = builder\.disable_drag_drop_handler\(\);/);
72  const css = await readFile(new URL('../src/styles/app.css', import.meta.url), 'utf8');
73  assert.match(css, /\.dropzone \{ animation: dropzone-in/);
74  assert.match(css, /prefers-reduced-motion: reduce\) \{ \.dropzone/);
75});