okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
44d885874
main
1import { fileURLToPath } from 'node:url' ; 2import test from 'node:test' ; 3import assert from 'node:assert/strict' ; 4import { build } from 'esbuild' ; 5import { createRequire } from 'node:module' ; 6const { outputFiles} = await build ({ entryPoints :[ fileURLToPath ( new URL ( '../src/lib/commands.ts' , import . meta. url ))], bundle :true , write :false , platform :'node' , format :'cjs' , plugins :[{ name :'test-store' , setup ( build ) { build . onResolve ({ filter :/ ^\.\/store$ / }, () => ({ path :'store' , namespace :'test-store' })); build . onLoad ({ filter :/ . */ , namespace :'test-store' }, () => ({ contents :` 7export const getState = () => testStore.state; 8export const selectSession = id => { testStore.state.activeSession = id; testStore.calls.push(['select',id]); }; 9export const go = (...args) => testStore.calls.push(['go',...args]); 10export const exportConversation=()=>{},newSession=()=>({id:'new'}),pushToast=()=>{},restartEngine=()=>{},setFocus=()=>{},setNavOpen=()=>{},setPalette=()=>{},setShortcuts=()=>{},setTheme=()=>{},toggleFocus=()=>{},toggleRail=()=>{},unloadModel=()=>{};` , loader :'js' })); } }] }); 11function harness ( overrides = {}) { 12const testStore = { state :{ theme :'light' , sessions :Array . from ({ length :8 },( _ , i ) => ({ id :String ( i ), title :'Chat ' + i , updatedAt :`2026-10- ${ String ( 10 - i ). padStart ( 2 , '0' )} ` })), activeSession :'7' }, calls :[]}; 13const module = { exports :{}}; 14new Function ( 'require' , 'module' , 'exports' , 'testStore' , 'localStorage' , 'navigator' , 'window' , outputFiles [ 0 ]. text )( createRequire ( import . meta. url ), module , module . exports , testStore ,{ getItem :() => JSON . stringify ( overrides )},{ platform :'MacIntel' },{ location :{ hash :'#/chat/7' }}); 15const press = ( key , extra = {}) => { const event = { key, code :'' , metaKey :true , ctrlKey :false , altKey :false , shiftKey :false , target :{ matches :() => false }, preventDefault (){ this . prevented = true ;}, ...extra }; module . exports . handleAppShortcut ( event ); return event ;}; 16return { ...module . exports , testStore, press}; 17} 18test ( 'numbered shortcuts switch to the same current-plus-five slots shown in the sidebar' ,() => { 19const h = harness (); 20assert . equal ( h . press ( '2' ). prevented , true ); 21assert . deepEqual ( h . testStore . calls ,[[ 'select' , '1' ],[ 'go' , 'chat' , '1' ]]); 22h . testStore . calls = []; 23h . press ( '1' ,{ metaKey :false , ctrlKey :true }); 24assert . deepEqual ( h . testStore . calls ,[[ 'select' , '0' ],[ 'go' , 'chat' , '0' ]]); 25}); 26test ( 'Option digit navigation stays distinct from numbered chats on macOS' ,() => { 27const h = harness (); h . press ( '¡' ,{ altKey :true , code :'Digit1' }); 28assert . deepEqual ( h . testStore . calls ,[[ 'go' , 'chat' ]]); 29}); 30test ( 'saved custom shortcuts dispatch after reload and recording suppresses app actions' ,() => { 31const h = harness ({ 'go:chat' :{ key :'c' , mod :true , alt :false , shift :true }}); 32h . press ( 'C' ,{ shiftKey :true }); assert . deepEqual ( h . testStore . calls ,[[ 'go' , 'chat' ]]); 33h . testStore . state . shortcutsOpen = true ; h . testStore . calls = []; h . press ( '1' ); assert . deepEqual ( h . testStore . calls ,[]); 34});