full-loop.e2e.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(), { persona: SYSTEM_PROMPT })
  20. const agent = ctx.agentLoop.create(AgentId('e2e-loop'), { model: 'deepseek-v4-flash' })
  21. agent.send([{ type: 'text', text: 'Run `echo e2e-ok` with the bash tool and tell me its exact output.' }])
  22. await waitForIdle(ctx, agent)
  23. const events = [...agent.session.events]
  24. const calls = events.filter(event => event.type === 'tool/call')
  25. expect(calls.length).toBeGreaterThan(0)
  26. expect(calls.some(event => event.data.name === 'bash')).toBe(true)
  27. const results = events.filter(event => event.type === 'tool/result')
  28. const resultTexts = results.flatMap(event =>
  29. event.data.content.filter(block => block.type === 'text').map(block => block.text))
  30. expect(resultTexts.some(text => text.includes('e2e-ok'))).toBe(true)
  31. expect(finalText(events)).toContain('e2e-ok')
  32. }, 120_000)
  33. })