okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
4fb068a8c
main
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' , () => { 13assert . equal ( lib . codePreviewKind ( 'html' ), 'website' ); 14assert . equal ( lib . codePreviewKind ( 'HTML' ), 'website' ); 15assert . equal ( lib . codePreviewKind ( 'md' ), 'markdown' ); 16assert . equal ( lib . codePreviewKind ( 'markdown' ), 'markdown' ); 17assert . equal ( lib . codePreviewKind ( 'bash' ), null ); 18const a = lib . codePreview ( 'm1' , 'html' , '<p>a</p>' ), b = lib . codePreview ( 'm1' , 'html' , '<p>b</p>' ); 19assert . notEqual ( a . id , b . id , 'two blocks in one answer are two previews' ); 20assert . equal ( a . id , lib . codePreview ( 'm1' , 'html' , '<p>a</p>' ). id , 'the same block keeps its id' ); 21assert . 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' , () => { 25const page = '<!doctype html>\n<html><body>hi</body></html>' ; 26assert . equal ( lib . mainCodePreview ( 'm' , `Here:\n\n\`\`\`html\n ${ page } \n\`\`\`\n` )?. kind , 'website' ); 27assert . equal ( lib . mainCodePreview ( 'm' , 'A snippet:\n\n```html\n<b>x</b>\n```\n' ), null ); 28assert . equal ( lib . mainCodePreview ( 'm' , `\`\`\`html\n ${ page } \n\`\`\`\n\n\`\`\`html\n ${ page } \n\`\`\`\n` ), null ); 29assert . 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 () => { 33const md = await read ( 'src/components/Markdown.tsx' ), btn = await read ( 'src/components/CodePreviewBtn.tsx' ); 34assert . ok ( ! /<Btn [ ^ > ] * >\{tr\("Open preview"\) / . test ( md ), 'no text button' ); 35assert . ok ( md . indexOf ( '<CodePreviewBtn' ) < md . indexOf ( '<CopyBtn' ), 'preview first, copy after it' ); 36assert . match ( btn , / aria-pressed=\{open\} / ); 37assert . match ( btn , / tr\(open \? 'Close preview' : 'Open preview'\) / ); 38assert . 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' , () => { 42assert . match ( liquid , / \.rz::details-content \{ [ ^ } ] * block-size: 0; [ ^ } ] * opacity: 0; / ); 43assert . match ( liquid , / \.rz\[open\]::details-content \{ [ ^ } ] * block-size: auto; [ ^ } ] * opacity: 1; / ); 44assert . match ( liquid , / \.rz > summary:hover \{ [ ^ } ] * --st-fill-hover / ); 45assert . match ( liquid , / \.rz > summary:active \{ [ ^ } ] * --st-fill-press / ); 46assert . 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 () => { 50assert . match ( liquid , / \.st-bubble \.st-code \{\s * margin: 16px 0 20px; / ); 51assert . match ( liquid , / \.st-code__head \{\s * min-height: 34px; / ); 52const app = await read ( 'src/styles/app.css' ); 53assert . 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' , () => { 57assert . match ( liquid , / \.chatsplit \.artifact-panel \{\s * animation: st-panel-in var\(--st-t-choreo\) var\(--st-ease-enter\) both; / ); 58assert . match ( liquid , / \[data-leaving\] \{ [ ^ } ] * animation: st-panel-out var\(--st-t-choreo\) var\(--st-ease-exit\) both; / ); 59assert . 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' , () => { 63const section = liquid . slice ( liquid . indexOf ( '17. the motion system' )); 64assert . ok ( ! /transition: [ ^ ; ] * \b ( width | height | margin | top | left ) \b / . test ( section )); 65});