todo-write.e2e.ts 2.3 KB

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