Build Hermes Canopy 0.1.0 single-gateway preview
This commit is contained in:
commit
2b57fd62eb
5 files changed
+502
No files matched your search
@@ -0,0 +1,84 @@
|
||||
import {test} from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {registerHooks} from 'node:module'
|
||||
const hooks = registerHooks({resolve(specifier, context, next) {
|
||||
if (specifier === '@hermes/plugin-sdk') return {url: 'data:text/javascript,export const host={},useValue=()=>{},useQuery=()=>{},useQueryClient=()=>{}', shortCircuit:true}
|
||||
if (specifier === 'react') return {url: 'data:text/javascript,export const useEffect=()=>{},useState=()=>{},useId=()=>{}', shortCircuit:true}
|
||||
if (specifier === 'react/jsx-runtime') return {url: 'data:text/javascript,export const jsx=(type,props)=>({type,props})', shortCircuit:true}
|
||||
return next(specifier, context)
|
||||
}})
|
||||
const {default: plugin, routesFor, loadBot, openExisting, avatarSource} = await import('../plugin.js')
|
||||
hooks.deregister()
|
||||
const route = {connectionId:'g', profile:'work',targetProfile:'work',mode:'remote'}
|
||||
const state = name => ({get:()=>name})
|
||||
const row = (id, extra={}) => ({id,session_id:id,source:'local',title:id, ...extra})
|
||||
const page = (sessions, next_cursor=null) => ({scope:'stored',sessions,next_cursor})
|
||||
const live = sessions => ({scope:'live',sessions})
|
||||
|
||||
test('registers opt-in Overview in the Sessions group', () => {
|
||||
const registrations=[]
|
||||
plugin.register({register: v=>registrations.push(v)})
|
||||
assert.equal(plugin.defaultEnabled,false)
|
||||
assert.equal(registrations[0].title,'Übersicht')
|
||||
assert.deepEqual(registrations[0].data.dock,{pane:'sessions',pos:'center'})
|
||||
})
|
||||
test('route inventory only includes the current gateway, no name-only routing', async () => {
|
||||
const host={profileRoutes: async()=>[route, {...route, connectionId:'other'},route]}
|
||||
assert.deepEqual(await routesFor(host,'g'),[route])
|
||||
await assert.rejects(routesFor(host,'missing'))
|
||||
})
|
||||
test('pages completely, merges live and stored aliases, filters internal and archive metadata', async () => {
|
||||
const calls=[]
|
||||
const result=await loadBot({requestProfile: async (owner,method,p)=>{
|
||||
assert.equal(owner,route)
|
||||
assert.equal(method,'session.list')
|
||||
assert.equal(p.include_hidden,false)
|
||||
assert.ok(!('title' in p))
|
||||
calls.push(p)
|
||||
if (p.scope==='live') return live([row('a',{last_active_at:10}),row('room',{source:'bot_room'})])
|
||||
if (!p.cursor) return page([row('root',{resolved_id:'a',session_id:'a'}),row('job',{source:'kanban'}),row('old',{archived:true})],'next')
|
||||
return page([row('b'),row('b'),row('helper',{source:'tool'}),row('hidden',{hidden:true})])
|
||||
}},route)
|
||||
assert.deepEqual(result.sessions.map(r=>r.id),['a','b'])
|
||||
assert.deepEqual(result.sessions[0].aliases,['a','root'])
|
||||
assert.equal(calls.filter(c=>c.cursor==='next').length,1)
|
||||
})
|
||||
test('empty lists are supported; legacy responses and repeating cursors fail closed', async () => {
|
||||
assert.deepEqual(await loadBot({requestProfile:async (_,__,p)=>p.scope==='live'?live([]):page([])},route),{sessions:[],liveAtLimit:false})
|
||||
await assert.rejects(loadBot({requestProfile:async()=>({sessions:[]})},route), /Pagination|Vertrag/)
|
||||
await assert.rejects(loadBot({requestProfile:async()=>page([], 'loop')},route),/Cursor/)
|
||||
})
|
||||
test('request error is not an empty bot', async () => {
|
||||
await assert.rejects(loadBot({requestProfile: async()=>{throw Error('offline')}},route),/offline/)
|
||||
})
|
||||
test('a full live window is flagged, not presented as complete', async () => {
|
||||
const res=await loadBot({requestProfile:async (_,__,p)=>p.scope==='live'
|
||||
?live(Array.from({length:200},(_,n)=>row(String(n)))):page([])},route)
|
||||
assert.equal(res.sessions.length,200)
|
||||
assert.equal(res.liveAtLimit,true)
|
||||
})
|
||||
test('a cancelled page scan does not ask the host for more pages', async () => {
|
||||
const controller=new AbortController()
|
||||
let calls=0
|
||||
await assert.rejects(loadBot({requestProfile:async()=>{
|
||||
calls++
|
||||
controller.abort()
|
||||
return page([], 'next')
|
||||
}},route,controller.signal),{name:'AbortError'})
|
||||
assert.equal(calls,1)
|
||||
})
|
||||
test('opens only on the scoped route, refuses missing inventory and cross-profile aliases', async () => {
|
||||
const calls=[]
|
||||
const host={state:{connectionId:state('g'),gateway:state('open')},profileRoutes:async()=>[route],openSession:async (...args)=>calls.push(args)}
|
||||
const session={id:'a',aliases:['a','root']}
|
||||
await openExisting(host,'g',route,session,[{route,sessions:[session]}])
|
||||
assert.equal(calls[0][0],'a'); assert.equal(calls[0][1].route,route)
|
||||
await assert.rejects(openExisting(host,'g',route,session,[{route,sessions:[]}]),/verfügbar/)
|
||||
await assert.rejects(openExisting(host,'g',route,session,[{route,sessions:[session]},{route:{...route,profile:'b'},sessions:[{id:'root',aliases:['root']}]}]),/eindeutig/)
|
||||
assert.equal(calls.length,1)
|
||||
})
|
||||
test('avatar only accepts raster data or falls back to initials', ()=>{
|
||||
assert.equal(avatarSource({found:true,data:'data:image/png;base64,aGk='}),'data:image/png;base64,aGk=')
|
||||
assert.equal(avatarSource({found:true,data:'data:image/svg+xml;base64,aGk='}),null)
|
||||
assert.equal(avatarSource({found:false}),null)
|
||||
})
|
||||
Reference in new issue
Block a user