fixtures.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /** Session/workspace fixture shapes and snapshot defaults for the test runtime. */
  2. import type {
  3. ConversationSnapshot, ISession, SessionId, SessionSummary, WorkspaceListState,
  4. } from '@deepseek-ai/dsh-client-runtime/client'
  5. /**
  6. * Fixture overrides for the session behavior face: any subset of the
  7. * production ISession verbs (typed against it, so a face change surfaces
  8. * here at compile time), plus extra members feature-specific casts consume.
  9. * The open Record tail means a misnamed EXTRA member is not caught by the
  10. * compiler (it grafts as dead weight); the ISession verbs stay safe — a
  11. * misnamed verb leaves the fail-loud stub in place, which names itself at
  12. * the first call.
  13. */
  14. export type SessionBehaviorOverrides = Partial<ISession> & Record<string, unknown>
  15. /**
  16. * act-wrapped mutation runner shared by every runtime object: public mutators
  17. * funnel through it so tests never handle SlotCore microtask batching or
  18. * React act themselves.
  19. */
  20. export type Stabilizer = (fn: () => void | Promise<void>) => Promise<void>
  21. /**
  22. * Session fixture accepted by {@link TestSessions.add}: identity plus optional
  23. * snapshot/list-row overrides and the session behavior face the feature under
  24. * test actually calls (kept open — the runtime never fakes methods a test did
  25. * not supply, so an unstubbed call fails loud at the call site).
  26. */
  27. export interface SessionFixture {
  28. id: string
  29. /** Overrides merged over {@link conversationSnapshot} (sessionId comes from `id`). */
  30. snapshot?: Partial<Omit<ConversationSnapshot, 'sessionId'>>
  31. /** List-row overrides merged over the defaults derived from `id`. */
  32. summary?: Partial<Omit<SessionSummary, 'id'>>
  33. /** Session behavior face: exactly the methods the feature under test calls (ISession subset + extras). */
  34. session?: SessionBehaviorOverrides
  35. }
  36. /**
  37. * A complete quiescent conversation snapshot (open window, no traffic).
  38. * @param sessionId - owning session id.
  39. * @returns the snapshot; spread fixture overrides on top.
  40. */
  41. export function conversationSnapshot(sessionId: SessionId): ConversationSnapshot {
  42. return {
  43. sessionId,
  44. nodes: [],
  45. partial: null,
  46. runningCalls: [],
  47. codeDispatches: new Map(),
  48. pending: [],
  49. queue: [],
  50. running: false,
  51. subagent: null,
  52. composerPhase: 'active',
  53. removed: false,
  54. openState: 'open',
  55. openError: null,
  56. hasMore: false,
  57. loadingOlder: false,
  58. promptError: null,
  59. blank: false,
  60. lastAgentError: null,
  61. }
  62. }
  63. /**
  64. * A ready workspace list with no workspaces (the shape WorkspacesService
  65. * projects after both baselines land).
  66. * @returns the initial state of the test workspaces store.
  67. */
  68. export function workspaceListState(): WorkspaceListState {
  69. return {
  70. items: [],
  71. archivedSessionIds: [],
  72. state: 'idle',
  73. phase: 'ready',
  74. error: null,
  75. baselinesReady: true,
  76. recentWorkspaceId: undefined,
  77. }
  78. }