okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
99866a47a
main
1// QA report F01: reasoning wrappers and stray tag fragments never show in an answer or its Markdown export. 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 ) { 7const { code} = await transform ( await readFile ( new URL ( path , import . meta. url ), 'utf8' ), { loader :'ts' , format :'esm' }); 8return import ( `data:text/javascript;base64, ${ Buffer . from ( code ). toString ( 'base64' )} ` ); 9} 10const { tidyAnswer} = await loadTs ( '../src/lib/answer-text.ts' ); 11const { appendText} = await loadTs ( '../src/lib/deliverables.ts' ). catch (() => ({})); 12 13test ( 'a literal <analysis> or <think> wrapper is removed, the words stay' , () => { 14assert . equal ( tidyAnswer ( '<analysis>The answer is 4.' ), 'The answer is 4.' ); 15assert . equal ( tidyAnswer ( 'Sure.\n<think>\nplan\n</think>\nIt is 4.' ), 'Sure.\n\nplan\n\nIt is 4.' ); 16assert . equal ( tidyAnswer ( 'x </ANALYSIS> y <Thinking style="a"> z' ), 'x y z' ); 17}); 18 19test ( 'a tag that lost its "<" at the very start is not shown as a prefix' , () => { 20assert . equal ( tidyAnswer ( 'p> CEDAR-742' ), 'CEDAR-742' ); 21assert . equal ( tidyAnswer ( ' /p> done' ), 'done' ); 22assert . equal ( tidyAnswer ( 'analysis> 4' ), '4' ); 23}); 24 25test ( 'ordinary text, code and comparisons are untouched' , () => { 26for ( const text of [ 'CEDAR-742' , 'if a > b then c' , 'x -> y' , '```html\n<p>hi</p>\n```' , 'The p> in the middle' , '<div>kept</div>' , 'a <b and c> d' , 'Result: 5 > 3' , '' ]) assert . equal ( tidyAnswer ( text ), text ); 27}); 28 29test ( 'streaming: a tag that arrives in pieces is removed once it is complete' , () => { 30let content = '' ; 31for ( const piece of [ '<' , 'ana' , 'lysis' , '>' , 'The code is ' , 'p' , '> no' ]) content = tidyAnswer ( content + piece ); 32assert . equal ( content , 'The code is p> no' ); 33let lead = '' ; 34for ( const piece of [ 'p' , '>' , ' CEDAR' , '-742' ]) lead = tidyAnswer ( lead + piece ); 35assert . equal ( lead , 'CEDAR-742' ); 36}); 37 38test ( 'the store applies it to the answer, the ordered pieces and the Markdown export' , async () => { 39const store = await readFile ( new URL ( '../src/lib/store.ts' , import . meta. url ), 'utf8' ); 40assert . match ( store , / tidyAnswer\(m\.content\+text\) / ); // applyDelta, which the queued pieces go through 41assert . match ( store , / m\.role === 'assistant' \? tidyAnswer\(m\.content\) : m\.content\) / ); 42assert . match ( await readFile ( new URL ( '../src/lib/deliverables.ts' , import . meta. url ), 'utf8' ), / tidyAnswer\(last\.text \+ text\) / ); 43});