full-loop.e2e.ts 1.7 KB

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