test(apiproxy): register question callers

This commit is contained in:
Tianyi Cui
2026-08-08 15:48:22 +08:00
parent f6449c838c
commit b837e30a80
1 file changed
+9 -5
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { Context } from 'cordis'
import type { Agent } from '@deepseek-ai/dsh-agent'
import AgentRegistry, { type Agent } from '@deepseek-ai/dsh-agent'
import SessionStore from '@deepseek-ai/dsh-session'
import UserInteractionService from '@deepseek-ai/dsh-user-interaction'
import type { ApiProxy, MuxFrame, RpcRequest } from '@deepseek-ai/dsh-host-apiproxy/api'
@@ -10,6 +10,7 @@ import { createApiProxy } from '../src/api-proxy.ts'
async function harness(): Promise<{ ctx: Context; api: ApiProxy }> {
const ctx = new Context()
await ctx.plugin(SessionStore)
await ctx.plugin(AgentRegistry)
await ctx.plugin(UserInteractionService)
return {
ctx,
@@ -17,8 +18,11 @@ async function harness(): Promise<{ ctx: Context; api: ApiProxy }> {
}
}
function agent(id: string): Agent {
return { id } as unknown as Agent
function agent(ctx: Context): Agent {
const session = ctx.sessions.create()
const value = { id: session.id, session, status: 'idle', ctx } as Agent
ctx.agents.register(value)
return value
}
function openMux(api: ApiProxy, abort: AbortController): {
@@ -71,7 +75,7 @@ describe('question response validation', () => {
const abort = new AbortController()
const mux = openMux(api, abort)
const asked = ctx.userInteraction.ask({
agent: agent('session-multi'),
agent: agent(ctx),
questions: [{
id: 'targets',
question: 'Choose targets and add another',
@@ -95,7 +99,7 @@ describe('question response validation', () => {
const abort = new AbortController()
const mux = openMux(api, abort)
const asked = ctx.userInteraction.ask({
agent: agent('session-single'),
agent: agent(ctx),
questions: [{
id: 'target',
question: 'Choose one target',