harness.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Context } from 'cordis'
  2. import type { Agent } from '@deepseek-ai/dsh-agent'
  3. import AgentLoop from '@deepseek-ai/dsh-agent-loop'
  4. import { mountAgentLoopTestDependencies } from '@deepseek-ai/dsh-agent-loop-testkit'
  5. import { LocalBashExecutor } from '@deepseek-ai/dsh-bash-local'
  6. import * as ToolBash from '@deepseek-ai/dsh-tool-bash'
  7. import * as LlmDeepSeek from '@deepseek-ai/dsh-llm-deepseek'
  8. import SubagentService from '@deepseek-ai/dsh-subagent'
  9. import * as Spawn from '../src/index.ts'
  10. import * as ToolSubagent from '@deepseek-ai/dsh-tool-subagent'
  11. /**
  12. * Shared harness for the spawn-backend e2e: the full real stack (DeepSeek
  13. * adapter + real bash tool + the subagent tool bound to the spawn backend), so
  14. * a real parent agent can delegate to a real in-process child that does real
  15. * work (writes a file). Lives outside the *.e2e.ts pattern so importing it never
  16. * re-registers another file's tests.
  17. */
  18. export async function spawnHarness(workdir: string): Promise<Context> {
  19. const ctx = new Context()
  20. // This harness installs only the global default persona, so both parent and
  21. // spawned children render it. It stays neutral for both roles; the
  22. // delegation nudge lives in the e2e's user prompt and the subagent tool's
  23. // own description.
  24. await mountAgentLoopTestDependencies(ctx, {
  25. systemPrompt: { persona: 'You are a coding agent. Report only when the requested work is done.' },
  26. })
  27. await ctx.plugin(AgentLoop, { agents: [] })
  28. await ctx.plugin(LlmDeepSeek)
  29. await ctx.plugin(LocalBashExecutor, { cwd: workdir, timeoutMs: 30_000 })
  30. await ctx.plugin(ToolBash)
  31. await ctx.plugin(SubagentService)
  32. await ctx.plugin(Spawn, { providerName: 'spawn' })
  33. // The model-facing subagent tool, bound to the spawn backend.
  34. await ctx.plugin(ToolSubagent, { provider: 'spawn' })
  35. return ctx
  36. }
  37. export function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
  38. return new Promise((resolve) => {
  39. const dispose = ctx.on('agent/status', (subject, status) => {
  40. if (subject === agent && status === 'idle') {
  41. dispose()
  42. resolve()
  43. }
  44. })
  45. })
  46. }