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

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