Handle older session-list contracts in Canopy

This commit is contained in:
michael committed 2026-11-19 14:35:43 +01:00
1 parent b24611adb7
commit a8b2459dbc
4 files changed
+86 -16

No files matched your search

+22
View File
@@ -51,6 +51,28 @@ test('empty lists are supported; legacy responses and repeating cursors fail clo
test('request error is not an empty bot', async () => {
await assert.rejects(loadBot({requestProfile: async()=>{throw Error('offline')}},route),/offline/)
})
test('a legacy session.list response uses only the scoped SDK metadata fallback and flags its cap', async () => {
const res=await loadBot({requestProfile:async()=>({sessions:[]}),listPersistedSessions:async(owner, options)=>{
assert.equal(owner,route)
assert.deepEqual(options,{profile:'work',limit:500})
return {sessions:[{id:'kept',source:'gui',profile:'work',last_active:123},
{id:'group',source:'bot_room',profile:'work'},{id:'old',source:'gui',profile:'work',archived:true}],
total:580,limit:500,offset:0,errors:[],storage:{}}
}},route)
assert.deepEqual(res.sessions.map(r=>[r.id,r.lastActive]),[['kept',123]])
assert.equal(res.storedAtLimit,true)
})
test('unsupported query arguments can fall back but permission and storage errors may not look empty', async () => {
const unsupported=async()=>{throw {code:4001,data:{reason:'invalid_params'}}}
const empty=async()=>({sessions:[],total:0,limit:500,offset:0,errors:[]})
assert.equal((await loadBot({requestProfile:unsupported,listPersistedSessions:empty},route)).sessions.length,0)
await assert.rejects(loadBot({requestProfile:async()=>{throw Error('permission_denied')},
listPersistedSessions:async()=>assert.fail('must not fall back')},route),/permission_denied/)
await assert.rejects(loadBot({requestProfile:unsupported,listPersistedSessions:async()=>({
...(await empty()),errors:[{profile:'work',error:'locked'}]})},route),/Profilspeicher/)
await assert.rejects(loadBot({requestProfile:unsupported,listPersistedSessions:async()=>({
...(await empty()),sessions:[{id:'wrong',profile:'other',source:'gui'}]})},route),/Profil/)
})
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)