fix(web): preserve session not-found and member history behavior

This commit is contained in:
digua authored and digua committed 2026-05-22 10:20:39 +08:00
1 parent 5f76e65359
commit 1e7325197c
5 files changed
+135 -6

No files matched your search

@@ -0,0 +1,34 @@
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import Fastify from 'fastify'
import type { SessionRuntimeAdapter } from '@openchatlab/node-runtime'
import { registerSessionRoutes } from './sessions'
function createMissingSessionAdapter(): SessionRuntimeAdapter {
return {
listSessionIds: () => [],
openReadonly: () => null,
openWritable: () => null,
closeSession: () => {},
getDbPath: (sessionId) => `/tmp/${sessionId}.db`,
deleteSessionFile: () => false,
ensureReadonly: () => {
throw Object.assign(new Error('Session not found'), { statusCode: 404 })
},
ensureWritable: () => {
throw Object.assign(new Error('Session not found'), { statusCode: 404 })
},
}
}
describe('CLI Web session routes', () => {
it('returns 404 when requesting a missing session by id', async () => {
const app = Fastify()
registerSessionRoutes(app, createMissingSessionAdapter())
const response = await app.inject({ method: 'GET', url: '/_web/sessions/missing' })
await app.close()
assert.equal(response.statusCode, 404)
})
})
+5 -1
View File
@@ -7,7 +7,11 @@ export function registerSessionRoutes(server: FastifyInstance, adapter: SessionR
})
server.get<{ Params: { id: string } }>('/_web/sessions/:id', async (request) => {
return sessionService.getAnalysisSession(adapter, request.params.id)
const session = sessionService.getAnalysisSession(adapter, request.params.id)
if (!session) {
throw Object.assign(new Error(`Session not found: ${request.params.id}`), { statusCode: 404 })
}
return session
})
server.delete<{ Params: { id: string } }>('/_web/sessions/:id', async (request, reply) => {