api-proxy-blank.spec.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * The summary blank bit means "conversation not started" (no turn has run),
  3. * not "log empty": standalone plugin events — command lifecycle records,
  4. * plan/mode, session titles — never flip it, so running /plan or /goal on a
  5. * fresh session keeps it list-hidden and reusable, while the first accepted
  6. * prompt's turn/start clears it. The host/session-added frame shares the
  7. * same predicate function (covered by the workspace spec's frame assertion).
  8. */
  9. import { describe, expect, it } from 'vitest'
  10. import { Context } from 'cordis'
  11. import AgentRegistry from '@deepseek-ai/dsh-agent'
  12. import type { Agent } from '@deepseek-ai/dsh-agent'
  13. import SessionStore from '@deepseek-ai/dsh-session'
  14. import type { Session } from '@deepseek-ai/dsh-session'
  15. import UserInteractionService from '@deepseek-ai/dsh-user-interaction'
  16. import { CommandId } from '@deepseek-ai/dsh-commands/brand'
  17. import type { ApiProxy, RpcRequest } from '@deepseek-ai/dsh-host-apiproxy/api'
  18. import { RpcId } from '@deepseek-ai/dsh-host-apiproxy/api/rpc'
  19. import { createApiProxy } from '@deepseek-ai/dsh-host-apiproxy'
  20. let nextRpc = 1
  21. function request<P>(payload: P): RpcRequest<P> {
  22. return { rpcId: RpcId(`blank-${String(nextRpc++)}`), payload }
  23. }
  24. async function harness(): Promise<{ ctx: Context; api: ApiProxy; attach: (session: Session) => void }> {
  25. const ctx = new Context()
  26. await ctx.plugin(SessionStore)
  27. await ctx.plugin(UserInteractionService)
  28. await ctx.plugin(AgentRegistry)
  29. return {
  30. ctx,
  31. api: createApiProxy(ctx, { provider: 'p', model: 'm', cwd: '/tmp', workspaceRoot: '/tmp' }),
  32. attach: (session) => {
  33. ctx.agents.register({ id: session.id, session, status: 'idle', ctx } as Agent)
  34. },
  35. }
  36. }
  37. /** Append the standalone (non-conversation) event family a fresh session can accumulate. */
  38. function appendStandalone(session: Session): void {
  39. session.append('command/run', {
  40. commandId: CommandId('blank-cmd-1'), name: 'plan', args: '', source: { kind: 'user' },
  41. })
  42. session.append('plan/mode', { active: true })
  43. session.append('command/done', { commandId: CommandId('blank-cmd-1'), kind: 'success', text: 'Plan mode on.' })
  44. session.append('session/title', {
  45. title: 'standalone title', messageSeqs: [], source: { kind: 'fallback' },
  46. })
  47. }
  48. async function listBlank(api: ApiProxy, id: string): Promise<boolean | undefined> {
  49. const response = await api.sessions.list(request({}))
  50. if (!response.result.ok) throw new Error('list failed')
  51. return response.result.value.items.find(item => item.sessionId === id)?.blank
  52. }
  53. describe('summary blank = conversation not started', () => {
  54. it('standalone events (command lifecycle, plan/mode, title) keep the session blank', async () => {
  55. const { ctx, api, attach } = await harness()
  56. const session = ctx.sessions.create()
  57. attach(session)
  58. expect(await listBlank(api, session.id)).toBe(true)
  59. appendStandalone(session)
  60. expect(await listBlank(api, session.id)).toBe(true)
  61. })
  62. it('the first turn clears blank', async () => {
  63. const { ctx, api, attach } = await harness()
  64. const session = ctx.sessions.create()
  65. attach(session)
  66. appendStandalone(session)
  67. session.append('turn/start', { turn: 0, trigger: { kind: 'message', source: { kind: 'user' } } })
  68. expect(await listBlank(api, session.id)).toBe(false)
  69. })
  70. })