harness.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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 LocalFileSystem from '@deepseek-ai/dsh-fs-local'
  6. import * as FsPolicy from '@deepseek-ai/dsh-fs-policy'
  7. import * as ToolFs from '@deepseek-ai/dsh-tool-fs'
  8. import * as LlmDeepSeek from '@deepseek-ai/dsh-llm-deepseek'
  9. /**
  10. * Build the real fs-tool stack for with-key e2e tests. Agents have no session
  11. * cwd, so `fsCwd` is their workspace; `persona` configures the deployment prompt.
  12. * This helper lives outside the e2e glob so imports do not register tests.
  13. */
  14. export async function fsHarness(fsCwd: string, persona = ''): Promise<Context> {
  15. const ctx = new Context()
  16. await mountAgentLoopTestDependencies(ctx, { systemPrompt: { persona } })
  17. await ctx.plugin(AgentLoop, { agents: [] })
  18. await ctx.plugin(LlmDeepSeek)
  19. await ctx.plugin(LocalFileSystem, { cwd: fsCwd })
  20. await ctx.plugin(FsPolicy)
  21. await ctx.plugin(ToolFs)
  22. return ctx
  23. }
  24. export function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
  25. return new Promise((resolve) => {
  26. const dispose = ctx.on('agent/status', ({ agent: subject, status }) => {
  27. if (subject === agent && status === 'idle') {
  28. dispose()
  29. resolve()
  30. }
  31. })
  32. })
  33. }