cli-keyless-smoke.e2e.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { readdir } from 'node:fs/promises'
  2. import { fileURLToPath } from 'node:url'
  3. import { describe, expect, it } from 'vitest'
  4. import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
  5. import type { SessionEvent } from '@deepseek-ai/dsh-session'
  6. const binScript = fileURLToPath(new URL('../../../packages/examples/cli-demo/src/bin.ts', import.meta.url))
  7. const configPath = fileURLToPath(new URL('./fixtures/cli.cordis.yml', import.meta.url))
  8. const tsconfigPath = fileURLToPath(new URL('../../../tsconfig.json', import.meta.url))
  9. describe('coding-agent one-shot CLI keyless smoke', () => {
  10. it('boots the real Loader tree, runs a real bash tool round trip, and persists the turn', async () => {
  11. let persisted = false
  12. const { stdout, stderr } = await runLoaderSmoke({
  13. label: 'coding-agent CLI',
  14. tempDirPrefix: 'coding-cli-smoke-',
  15. binScript,
  16. configPath,
  17. binArgs: ['--config', configPath, '--output-format', 'stream-json', 'prove the tool path'],
  18. tsconfigPath,
  19. inspect: async (cwd) => {
  20. const files = await readdir(cwd, { recursive: true })
  21. persisted = files.some(file => file.endsWith('.jsonl'))
  22. },
  23. })
  24. const lines = stdout.trimEnd().split('\n').map(line => JSON.parse(line) as Record<string, unknown>)
  25. const events = lines.slice(0, -1).map(line => line['event'] as SessionEvent)
  26. const result = lines.at(-1)
  27. expect(stderr).toBe('')
  28. expect(events.some(event => event.type === 'tool/call' && event.data.name === 'bash')).toBe(true)
  29. const toolResult = events.find(event => event.type === 'tool/result')
  30. expect(JSON.stringify(toolResult)).toContain('CLI_TOOL_ROUND_TRIP')
  31. expect(result).toMatchObject({
  32. type: 'result',
  33. success: true,
  34. turn: 1,
  35. reason: { kind: 'completed' },
  36. usage: { inputTokens: 18, outputTokens: 8, cacheReadTokens: 2, reasoningTokens: 1 },
  37. })
  38. expect(String(result?.['result'])).toContain('CLI_TOOL_ROUND_TRIP')
  39. expect(persisted).toBe(true)
  40. }, LOADER_SMOKE_TEST_TIMEOUT_MS)
  41. })