session-list-blank.host.spec.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, permission knob events, 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 '@deepseek-ai/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 UserQuestionService from '@deepseek-ai/dsh-user-questions'
  16. import { CommandId } from '@deepseek-ai/dsh-commands/brand'
  17. // Side-effect type imports: the knob-event SessionEventMap merges.
  18. import type {} from '@deepseek-ai/dsh-permission-presets'
  19. import type {} from '@deepseek-ai/dsh-sandbox-policy'
  20. import type {} from '@deepseek-ai/dsh-user-approval'
  21. import { createSessionTestRemote, type TestSessionRemote } from './test-remote.ts'
  22. async function harness(): Promise<{ ctx: Context; remote: TestSessionRemote; attach: (session: Session) => void }> {
  23. const ctx = new Context()
  24. await ctx.plugin(SessionStore)
  25. await ctx.plugin(UserQuestionService)
  26. await ctx.plugin(AgentRegistry)
  27. return {
  28. ctx,
  29. remote: createSessionTestRemote(ctx, { defaultModelSelection: () => ({ provider: 'p', model: 'm' }), cwd: '/tmp' }),
  30. attach: (session) => {
  31. ctx.agents.register({ id: session.id, session, status: 'idle', ctx } as Agent)
  32. },
  33. }
  34. }
  35. /** Append the standalone (non-conversation) event family a fresh session can accumulate. */
  36. function appendStandalone(session: Session): void {
  37. session.append('command/run', {
  38. commandId: CommandId('blank-cmd-1'), name: 'plan', args: '', source: { kind: 'user' },
  39. })
  40. session.append('plan/mode', { active: true })
  41. session.append('command/done', { commandId: CommandId('blank-cmd-1'), kind: 'success', text: 'Plan mode on.' })
  42. session.append('session/title', {
  43. title: 'standalone title', messageSeqs: [], source: { kind: 'fallback' },
  44. })
  45. // The three permission knob events (a /permission switch on a fresh session).
  46. session.append('permission/preset', { preset: 'danger-full-access' })
  47. session.append('sandbox/mode', { mode: 'danger-full-access' })
  48. session.append('approval/policy', { policy: 'never' })
  49. }
  50. async function listBlank(remote: TestSessionRemote, id: string): Promise<boolean | undefined> {
  51. const result = await remote.list({})
  52. if (!result.ok) throw new Error('list failed')
  53. return result.value.items.find(item => item.sessionId === id)?.blank
  54. }
  55. describe('summary blank = conversation not started', () => {
  56. it('standalone events (command lifecycle, plan/mode, title) keep the session blank', async () => {
  57. const { ctx, remote, attach } = await harness()
  58. const session = ctx.sessions.create()
  59. attach(session)
  60. expect(await listBlank(remote, session.id)).toBe(true)
  61. appendStandalone(session)
  62. expect(await listBlank(remote, session.id)).toBe(true)
  63. })
  64. it('the first turn clears blank', async () => {
  65. const { ctx, remote, attach } = await harness()
  66. const session = ctx.sessions.create()
  67. attach(session)
  68. appendStandalone(session)
  69. session.append('turn/start', { turn: 0 })
  70. expect(await listBlank(remote, session.id)).toBe(false)
  71. })
  72. })