spawn-in-process.e2e.ts 2.0 KB

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