todo-write.e2e.ts 1.9 KB

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