spawn.e2e.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { mkdtemp, readFile, 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 { spawnHarness, waitForIdle } from './harness.ts'
  7. import { SessionId } from '@deepseek-ai/dsh-session'
  8. /** Key-gated smoke for a real parent delegating filesystem work to a real child. */
  9. let ctx: Context | undefined
  10. let workdir: string | undefined
  11. afterEach(async () => {
  12. await ctx?.fiber.dispose()
  13. ctx = undefined
  14. if (workdir !== undefined) await rm(workdir, { recursive: true, force: true })
  15. workdir = undefined
  16. })
  17. describe.skipIf(!process.env.DEEPSEEK_API_KEY)('spawn backend with-key smoke', () => {
  18. it('a parent delegates to a child that writes a file on disk', async () => {
  19. workdir = await mkdtemp(join(tmpdir(), 'dsh-subagent-spawn-e2e-'))
  20. ctx = await spawnHarness(workdir)
  21. const parent = ctx.agentLoop.create(SessionId('e2e-parent'), { provider: 'deepseek', model: 'deepseek-v4-flash' })
  22. parent.followup({ content: [{ type: 'text', text:
  23. 'Use the subagent tool to delegate this exact task: "Use the bash tool to write the text '
  24. + 'SUBAGENT_WAS_HERE into a file named proof.txt in the current directory." '
  25. + 'After the subagent finishes, tell me it is done.' }], source: { kind: 'user' } })
  26. await waitForIdle(ctx, parent)
  27. // Assert the filesystem effect independently of the model response.
  28. const proof = await readFile(join(workdir, 'proof.txt'), 'utf8')
  29. expect(proof).toContain('SUBAGENT_WAS_HERE')
  30. // The parent's log records the subagent tool/call + its result (not the
  31. // child's internal steps).
  32. const events = [...parent.session.events]
  33. const subagentCalls = events.filter(e => e.type === 'tool/call' && e.data.name === 'subagent')
  34. expect(subagentCalls.length).toBeGreaterThan(0)
  35. }, 180_000)
  36. })