1
0

todo-write.e2e.ts 2.2 KB

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