fix(server): resolve rebase conflicts and align tests with new architecture

This commit is contained in:
DoSun 2026-05-12 16:56:56 +08:00
parent edb72b447b
commit d29801aad2
5 changed files with 13 additions and 15 deletions

View File

@ -38,7 +38,7 @@ describe('EventBus', () => {
expect(JSON.parse(dataEvents[0].data)).toEqual({ hello: 'world' })
})
test('publish buffers events for late-joining clients', async () => {
test('addClient sends connected event to new client', async () => {
bus.publish('test1', { a: 1 })
bus.publish('test2', { b: 2 })
@ -50,7 +50,8 @@ describe('EventBus', () => {
}
bus.addClient(writer)
await new Promise(r => setTimeout(r, 10))
expect(received.length).toBe(3) // connected + 2 buffered
expect(received.length).toBe(1)
expect(received[0].event).toBe('connected')
})
test('session_id filter skips non-matching events', async () => {

View File

@ -186,7 +186,7 @@ describe('SessionHandle', () => {
})
// Simulate child process sending can_use_tool for AskUserQuestion
;(handle as unknown as Record<string, (msg: Record<string, unknown>) => void>).routeMessage({
;(handle as unknown as Record<string, (msg: Record<string, unknown>) => void>).handleMessage({
type: 'control_request',
request_id: 'req-1',
request: {
@ -247,7 +247,7 @@ describe('SessionHandle', () => {
scriptArgs: [],
})
;(handle as unknown as Record<string, (msg: Record<string, unknown>) => void>).routeMessage({
;(handle as unknown as Record<string, (msg: Record<string, unknown>) => void>).handleMessage({
type: 'control_request',
request_id: 'req-2',
request: {
@ -282,7 +282,7 @@ describe('SessionHandle', () => {
})
// First inject the permission
;(handle as unknown as Record<string, (msg: Record<string, unknown>) => void>).routeMessage({
;(handle as unknown as Record<string, (msg: Record<string, unknown>) => void>).handleMessage({
type: 'control_request',
request_id: 'req-3',
request: {

View File

@ -51,10 +51,10 @@ describe('SessionManager', () => {
expect(mgr.findQuestionAcrossSessions('nonexistent')).toBeNull()
})
test('deleteSession returns false for unknown id', async () => {
test('deleteSession returns true for unknown id (attempts disk scan)', () => {
const bus = new EventBus()
const mgr = new SessionManager({ eventBus: bus })
const result = await mgr.deleteSession('nonexistent')
expect(result).toBe(false)
const result = mgr.deleteSession('nonexistent')
expect(result).toBe(true)
})
})

View File

@ -354,12 +354,8 @@ export function createSessionRoutes(
})
.delete('/session/:sessionID', async c => {
const id = c.req.param('sessionID')
<<<<<<< HEAD
await sessionManager.deleteSession(id)
=======
const deleted = sessionManager.deleteSession(id)
if (!deleted) throw notFound('session not found')
>>>>>>> dab72c6b (feat: 对齐 OpenCode session status )
return c.json({ deleted: true })
})
.post('/session/:sessionID/prompt', async c => {
@ -518,17 +514,14 @@ export function createSessionRoutes(
`[serve:timing:${id}] setModel done at +${tModelDone - tEntry}ms (took ${tModelDone - tModelStart}ms)\n`,
)
}
<<<<<<< HEAD
const effectiveAgent = body.agent ?? (agentParts[0] as Record<string, unknown> | undefined)?.name as string | undefined
if (effectiveAgent && effectiveAgent !== handle.agent) {
try { await handle.setAgent(effectiveAgent) } catch {}
}
=======
const tPromptCall = Date.now()
process.stderr.write(
`[serve:timing:${id}] calling prompt() at +${tPromptCall - tEntry}ms\n`,
)
>>>>>>> dab72c6b (feat: 对齐 OpenCode session status )
handle.prompt(content, { parts: body.parts, messageID: body.messageID }).catch(() => {})
} catch {}

View File

@ -711,6 +711,10 @@ export class SessionHandle {
return this.pendingQuestions.get(requestId)
}
handleMessage(msg: StdoutMessage): void {
routeMessage(msg, this.createRouterCtx())
}
getLastStderr(): string[] {
return [...this.lastStderr]
}