okami.mom/strata

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

Niko1221rc1 merge ds-coder (d6a5a7837)4fb068a8c

main
4.4 KiB65 linesraw
1/** Second batch of the owner's chat feedback: reasoning that opens smoothly, code blocks, the preview icon button, the sidebar preview's motion. */
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { readFile } from 'node:fs/promises';
5import { transform } from 'esbuild';
6
7const read = p => readFile(new URL(`../${p}`, import.meta.url), 'utf8');
8const { code } = await transform((await read('src/lib/code-preview.ts')).replace("import { useSyncExternalStore } from 'react';", 'const useSyncExternalStore = () => null;').replace("import type { PreviewArtifact } from './artifacts';", ''), { loader: 'ts', format: 'esm' });
9const lib = await import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);
10const liquid = await read('src/styles/liquid.css');
11
12test('only HTML and Markdown blocks have a preview; each block has its own stable id', () => {
13  assert.equal(lib.codePreviewKind('html'), 'website');
14  assert.equal(lib.codePreviewKind('HTML'), 'website');
15  assert.equal(lib.codePreviewKind('md'), 'markdown');
16  assert.equal(lib.codePreviewKind('markdown'), 'markdown');
17  assert.equal(lib.codePreviewKind('bash'), null);
18  const a = lib.codePreview('m1', 'html', '<p>a</p>'), b = lib.codePreview('m1', 'html', '<p>b</p>');
19  assert.notEqual(a.id, b.id, 'two blocks in one answer are two previews');
20  assert.equal(a.id, lib.codePreview('m1', 'html', '<p>a</p>').id, 'the same block keeps its id');
21  assert.equal(lib.codePreview('m1', 'bash', 'ls'), null);
22});
23
24test('a finished answer with exactly one whole HTML page goes to the sidebar by itself; snippets and several blocks do not', () => {
25  const page = '<!doctype html>\n<html><body>hi</body></html>';
26  assert.equal(lib.mainCodePreview('m', `Here:\n\n\`\`\`html\n${page}\n\`\`\`\n`)?.kind, 'website');
27  assert.equal(lib.mainCodePreview('m', 'A snippet:\n\n```html\n<b>x</b>\n```\n'), null);
28  assert.equal(lib.mainCodePreview('m', `\`\`\`html\n${page}\n\`\`\`\n\n\`\`\`html\n${page}\n\`\`\`\n`), null);
29  assert.equal(lib.mainCodePreview('m', 'Notes:\n\n```markdown\n# a\n```\n'), null, 'Markdown blocks keep the button only');
30});
31
32test('the code block has an icon preview button left of Copy, with an open state, and no text button', async () => {
33  const md = await read('src/components/Markdown.tsx'), btn = await read('src/components/CodePreviewBtn.tsx');
34  assert.ok(!/<Btn[^>]*>\{tr\("Open preview"\)/.test(md), 'no text button');
35  assert.ok(md.indexOf('<CodePreviewBtn') < md.indexOf('<CopyBtn'), 'preview first, copy after it');
36  assert.match(btn, /aria-pressed=\{open\}/);
37  assert.match(btn, /tr\(open \? 'Close preview' : 'Open preview'\)/);
38  assert.match(liquid, /\.st-code \.st-btn--icon\[data-open\]/);
39});
40
41test('reasoning opens by growing and fading, the line above never moves, and it has hover and press feedback', () => {
42  assert.match(liquid, /\.rz::details-content \{[^}]*block-size: 0;[^}]*opacity: 0;/);
43  assert.match(liquid, /\.rz\[open\]::details-content \{[^}]*block-size: auto;[^}]*opacity: 1;/);
44  assert.match(liquid, /\.rz > summary:hover \{[^}]*--st-fill-hover/);
45  assert.match(liquid, /\.rz > summary:active \{[^}]*--st-fill-press/);
46  assert.match(liquid, /\.rz__body \{[^}]*border-left: 2px solid/);
47});
48
49test('code blocks have room after them and are lighter than the text; the 12px floor of pass 37 is untouched', async () => {
50  assert.match(liquid, /\.st-bubble \.st-code \{\s*margin: 16px 0 20px;/);
51  assert.match(liquid, /\.st-code__head \{\s*min-height: 34px;/);
52  const app = await read('src/styles/app.css');
53  assert.match(app, /--st-fs-read-sm: max\(12px, calc\(var\(--st-content-fs, 12px\) \* \.8125\)\);/);
54});
55
56test('the sidebar preview comes in and goes out with motion, from the one motion scale, and the reduced-motion gate zeroes the distance', () => {
57  assert.match(liquid, /\.chatsplit \.artifact-panel \{\s*animation: st-panel-in var\(--st-t-choreo\) var\(--st-ease-enter\) both;/);
58  assert.match(liquid, /\[data-leaving\] \{[^}]*animation: st-panel-out var\(--st-t-choreo\) var\(--st-ease-exit\) both;/);
59  assert.match(liquid, /@media \(prefers-reduced-motion: reduce\) \{\s*:root \{ --st-press-scale: 1; --st-panel-shift: 0px; \}/);
60});
61
62test('only the layer-safe properties move: no transition on width, height or margin in the motion section', () => {
63  const section = liquid.slice(liquid.indexOf('17. the motion system'));
64  assert.ok(!/transition:[^;]*\b(width|height|margin|top|left)\b/.test(section));
65});