echo.e2e.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { fileURLToPath } from 'node:url'
  2. import { describe, expect, it } from 'vitest'
  3. import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
  4. import type { SessionEvent } from '@deepseek-ai/dsh-session'
  5. const binScript = fileURLToPath(new URL('../../../packages/examples/cli-demo/src/bin.ts', import.meta.url))
  6. const configPath = fileURLToPath(new URL('../cordis.yml', import.meta.url))
  7. const tsconfigPath = fileURLToPath(new URL('../../../tsconfig.json', import.meta.url))
  8. async function runEcho(task: string, outputFormat: 'text' | 'stream-json' = 'text'): Promise<string> {
  9. const { stdout } = await runLoaderSmoke({
  10. label: 'echo-agent',
  11. tempDirPrefix: 'echo-smoke-',
  12. binScript,
  13. configPath,
  14. binArgs: ['--config', configPath, '--output-format', outputFormat, task],
  15. tsconfigPath,
  16. })
  17. return stdout
  18. }
  19. describe('echo-agent keyless smoke (Headless through the real Loader tree)', () => {
  20. it('runs the echo tool round-trip and exposes both events in stream-json', async () => {
  21. const lines = (await runEcho('echo hello world', 'stream-json'))
  22. .trimEnd().split('\n').map(line => JSON.parse(line) as Record<string, unknown>)
  23. const events = lines.slice(0, -1).map(line => line['event'] as SessionEvent)
  24. expect(events.some(event => event.type === 'tool/call' && event.data.name === 'echo')).toBe(true)
  25. expect(JSON.stringify(events.find(event => event.type === 'tool/result'))).toContain('ECHO: HELLO WORLD')
  26. expect(lines.at(-1)).toMatchObject({ type: 'result', success: true })
  27. }, LOADER_SMOKE_TEST_TIMEOUT_MS)
  28. it('prints the final canned reply for a direct one-shot task', async () => {
  29. const stdout = await runEcho('just chatting')
  30. expect(stdout).toContain('You said: "just chatting"')
  31. expect(stdout).not.toContain('tool/call')
  32. }, LOADER_SMOKE_TEST_TIMEOUT_MS)
  33. })