full-loop.e2e.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { afterEach, describe, expect, it } from 'vitest'
  2. import type { Context } from 'cordis'
  3. import { AgentId } from '@deepseek-ai/dsh-agent'
  4. import { codingHarness, finalText, SYSTEM_PROMPT, waitForIdle } from './harness.ts'
  5. /**
  6. * The first place a REAL model meets the REAL bash tool: the cheap canary
  7. * before the coding-task e2e. Key-gated (see vitest.e2e.config.ts).
  8. */
  9. let ctx: Context | undefined
  10. afterEach(async () => {
  11. // Always dispose the harness, even on failure/retry/timeout: agent-loop
  12. // teardown stops the loop and LocalBashExecutor teardown kills any
  13. // process the model left behind.
  14. await ctx?.fiber.dispose()
  15. ctx = undefined
  16. })
  17. describe.skipIf(!process.env.DEEPSEEK_API_KEY)('full loop: real model + real bash tool', () => {
  18. it('runs a bash command on request and reports its output', async () => {
  19. ctx = await codingHarness(process.cwd())
  20. const agent = ctx.agentLoop.create(AgentId('e2e-loop'), {
  21. model: 'deepseek-v4-flash',
  22. systemPrompt: SYSTEM_PROMPT,
  23. })
  24. agent.send([{ type: 'text', text: 'Run `echo e2e-ok` with the bash tool and tell me its exact output.' }])
  25. await waitForIdle(ctx, agent)
  26. const events = [...agent.session.events]
  27. const calls = events.filter(event => event.type === 'tool/call')
  28. expect(calls.length).toBeGreaterThan(0)
  29. expect(calls.some(event => event.data.name === 'bash')).toBe(true)
  30. const results = events.filter(event => event.type === 'tool/result')
  31. const resultTexts = results.flatMap(event =>
  32. event.data.content.filter(block => block.type === 'text').map(block => block.text))
  33. expect(resultTexts.some(text => text.includes('e2e-ok'))).toBe(true)
  34. expect(finalText(events)).toContain('e2e-ok')
  35. }, 120_000)
  36. })