todo-write.e2e.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { createUserMessage } from '@deepseek-ai/dsh-llm'
  2. import { mkdtemp, rm } from 'node:fs/promises'
  3. import { tmpdir } from 'node:os'
  4. import { join } from 'node:path'
  5. import { afterEach, describe, expect, it } from 'vitest'
  6. import type { Context } from 'cordis'
  7. import { codingHarness, TODO_SYSTEM_PROMPT, waitForIdle } from './harness.ts'
  8. import { SessionId } from '@deepseek-ai/dsh-session'
  9. /**
  10. * A REAL model drives the REAL todo_write tool: verify the WORLD (the session
  11. * log gains a todo/write event whose snapshot the model actually produced), not
  12. * the agent's self-report. Key-gated (see vitest.e2e.config.ts).
  13. */
  14. let ctx: Context | undefined
  15. let workdir: string | undefined
  16. afterEach(async () => {
  17. await ctx?.fiber.dispose()
  18. ctx = undefined
  19. if (workdir !== undefined) await rm(workdir, { recursive: true, force: true })
  20. workdir = undefined
  21. })
  22. describe.skipIf(!process.env.DEEPSEEK_API_KEY)('todo_write: real model records a plan', () => {
  23. it('appends a todo/write event with the model-produced task list', async () => {
  24. workdir = await mkdtemp(join(tmpdir(), 'dsh-todo-write-e2e-'))
  25. ctx = await codingHarness(workdir, { persona: TODO_SYSTEM_PROMPT })
  26. const agent = ctx.agentLoop.create(SessionId('e2e-todo'), { provider: 'deepseek', model: 'deepseek-v4-flash' })
  27. agent.followup(createUserMessage({
  28. content: [{ type: 'text', text:
  29. 'Use the todo_write tool to record a plan of exactly two steps: first '
  30. + '"inspect the failing test" (in_progress), then "apply the fix" (pending). '
  31. + 'Send both in one todo_write call, then reply with the single word DONE.' }], source: { kind: 'user' } }))
  32. await waitForIdle(ctx, agent)
  33. const events = [...agent.session.events]
  34. // The model actually called the tool.
  35. const calls = events.filter(event => event.type === 'tool/call')
  36. expect(calls.some(event => event.data.name === 'todo_write')).toBe(true)
  37. // And the tool wrote a todo/write event to the log — verify the WORLD.
  38. const todoEvents = events.filter(event => event.type === 'todo/write')
  39. expect(todoEvents.length).toBeGreaterThan(0)
  40. const todos = (todoEvents.at(-1)!).data.todos
  41. expect(todos).toEqual([
  42. { content: 'inspect the failing test', status: 'in_progress' },
  43. { content: 'apply the fix', status: 'pending' },
  44. ])
  45. }, 120_000)
  46. })