okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3d9c21509
main
1/** Round 8: deliverable cards, grouped activity and the pieces of a reply in order (contract: notes-split-agent8.md, item 12). */ 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { build } from 'esbuild' ; 5import { fileURLToPath } from 'node:url' ; 6 7const src = f => fileURLToPath ( new URL ( `../src/ ${ f } ` , import . meta. url )); 8const stub = fileURLToPath ( new URL ( './helpers/react-stub.mjs' , import . meta. url )); 9const result = await build ({ entryPoints :[ src ( 'lib/deliverables.ts' )], bundle :true , format :'esm' , platform :'node' , write :false , alias :{ react :stub }, logLevel :'silent' }); 10const D = await import ( `data:text/javascript;base64, ${ Buffer . from ( result . outputFiles [ 0 ]. text ). toString ( 'base64' )} ` ); 11 12test ( 'a deliverable frame is read; unknown kinds become "other"; no path means no card' , () => { 13const d = D . readDeliverable ({ path :'a/pagoda.html' , abs :'C:/a/pagoda.html' , kind :'html' , status :'created' , size :7270 , lines :225 , added :225 , removed :0 }); 14assert . equal ( d . name , 'pagoda.html' ); assert . equal ( D . fileTypeLabel ( d ), 'HTML' ); 15assert . equal ( D . readDeliverable ({ path :'x.bin' , kind :'weird' }). kind , 'other' ); 16assert . equal ( D . readDeliverable ({ kind :'html' }), null ); 17assert . equal ( D . fileTypeLabel ({ kind :'markdown' , name :'README.md' }), 'MD' ); 18assert . equal ( D . fileSize ( 7270 ), '7.1 KB' ); assert . equal ( D . fileSize ( 512 ), '512 B' ); 19}); 20 21test ( 'text between activities stays in order: text, group, text; a group frame re-sent replaces its line' , () => { 22let b = D . appendText ( undefined , 'Building. ' ); 23b = D . appendText ( b , 'Now.' ); 24b = D . upsertGroup ( b , D . readGroup ({ id :'g1' , closed :false , line :'Ran a command' , files :[] })); 25b = D . appendText ( b , 'Next.' ); 26b = D . upsertGroup ( b , D . readGroup ({ id :'g1' , closed :true , line :'Ran 2 commands' , files :[] })); 27assert . deepEqual ( b . map ( x => x . kind ), [ 'text' , 'group' , 'text' ]); 28assert . equal ( b [ 0 ]. text , 'Building. Now.' ); assert . equal ( b [ 1 ]. line , 'Ran 2 commands' ); assert . equal ( b [ 1 ]. closed , true ); 29}); 30 31test ( 'one card per path; created stays created and the line counts add up' , () => { 32const a = D . readDeliverable ({ path :'p.html' , kind :'html' , status :'created' , size :10 , lines :5 , added :5 , removed :0 }); 33const b = D . readDeliverable ({ path :'p.html' , kind :'html' , status :'changed' , size :14 , lines :7 , added :3 , removed :1 }); 34const list = D . mergeDeliverable ( D . mergeDeliverable ( undefined , a ), b ); 35assert . equal ( list . length , 1 ); assert . equal ( list [ 0 ]. status , 'created' ); assert . equal ( list [ 0 ]. added , 8 ); assert . equal ( list [ 0 ]. removed , 1 ); assert . equal ( list [ 0 ]. size , 14 ); 36}); 37 38test ( 'a finished run opens one main result in the sidebar: the file the answer names, else the one written last, only kinds the sidebar shows' , () => { 39const f = ( path , kind ) => D . readDeliverable ({ path, kind, status :'created' , size :10 , lines :5 , added :5 , removed :0 }); 40const add = ( list , file ) => D . mergeDeliverable ( list , file ); 41let list = add ( add ( add ( undefined , f ( 'notes.md' , 'markdown' )), f ( 'pagoda.html' , 'html' )), f ( 'build.py' , 'code' )); 42assert . equal ( D . mainResult ( list , 'All done.' ). name , 'pagoda.html' , 'the last written one the sidebar can show (a script is not shown)' ); 43assert . equal ( D . mainResult ( list , 'The notes are in notes.md.' ). name , 'notes.md' , 'the file the answer names wins' ); 44assert . equal ( D . mainResult ( list , 'Open Pagoda.HTML and read notes.md for details; the page is pagoda.html' ). name , 'pagoda.html' , 'the last one it names' ); 45list = add ( list , f ( 'notes.md' , 'markdown' )); 46assert . equal ( D . mainResult ( list , '' ). name , 'notes.md' , 'a file written again counts as written last' ); 47assert . equal ( list . length , 3 , 'still one card per path' ); 48assert . equal ( D . mainResult ( add ( undefined , f ( 'run.py' , 'code' )), 'Made run.py' ), null , 'code is not opened by itself' ); 49assert . equal ( D . mainResult ( undefined , '' ), null ); 50for ( const kind of [ 'html' , 'markdown' , 'pdf' , 'image' , 'csv' , 'text' ]) assert . ok ( D . SIDEBAR_KINDS . includes ( kind ), kind ); 51}); 52 53test ( 'the file card: Open uses the system, the menu has Open in sidebar, and a run opens its result by itself' , async () => { 54const { readFile} = await import ( 'node:fs/promises' ); 55const card = await readFile ( new URL ( '../src/components/Deliverables.tsx' , import . meta. url ), 'utf8' ); 56assert . match ( card , / fileAction\.open\(sessionId, file\.path, 'app'\) [ ^ ] * ?\{tr\("Open"\)\} / , 'Open hands the file to its own app or the browser' ); 57assert . match ( card , / showOf\(file, sessionId, onPreview, file\.kind\); \}\}><Icon name="panel"\/>\{tr\("Open in sidebar"\)\} / , 'the menu opens the sidebar preview' ); 58const chat = await readFile ( new URL ( '../src/screens/Chat.tsx' , import . meta. url ), 'utf8' ); 59assert . match ( chat , / mainResult\(lastReply\.deliverables, lastReply\.content\) / ); 60assert . match ( chat , / before !== true \|\| lastReply\.streaming \|\| lastReply\.error / , 'only a run seen finishing, and not a failed one' ); 61});