mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(hub): archive active sessions with stale metadata (#1170)
This commit is contained in:
@@ -1167,6 +1167,28 @@ describe('sessions routes', () => {
|
||||
expect(calls).toEqual(['session-1'])
|
||||
})
|
||||
|
||||
it('archives an active session with stale archived lifecycle metadata', async () => {
|
||||
const calls: string[] = []
|
||||
const session = createSession({
|
||||
active: true,
|
||||
metadata: {
|
||||
path: '/tmp/project',
|
||||
host: 'localhost',
|
||||
flavor: 'codex',
|
||||
lifecycleState: 'archived'
|
||||
}
|
||||
})
|
||||
const { app } = createApp(session, {
|
||||
archiveSession: async (sessionId: string) => { calls.push(sessionId) }
|
||||
})
|
||||
|
||||
const response = await app.request('/api/sessions/session-1/archive', { method: 'POST' })
|
||||
|
||||
expect(response.status).toBe(200)
|
||||
expect(calls).toEqual(['session-1'])
|
||||
expect(await response.json()).toEqual({ ok: true })
|
||||
})
|
||||
|
||||
it('returns 2xx and skips archiveSession when the row is already archived (idempotent)', async () => {
|
||||
let called = false
|
||||
const session = createSession({
|
||||
|
||||
@@ -339,7 +339,7 @@ export function createSessionsRoutes(getSyncEngine: () => SyncEngine | null): Ho
|
||||
}
|
||||
|
||||
const lifecycleState = sessionResult.session.metadata?.lifecycleState
|
||||
if (lifecycleState === 'archived') {
|
||||
if (!sessionResult.session.active && lifecycleState === 'archived') {
|
||||
return c.json({ ok: true, alreadyArchived: true })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user