keyless-smoke.e2e.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { readFile, readdir } from 'node:fs/promises'
  2. import { zstdDecompress } from 'node:zlib'
  3. import { promisify } from 'node:util'
  4. import { join } from 'node:path'
  5. import { fileURLToPath } from 'node:url'
  6. import { describe, expect, it } from 'vitest'
  7. import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
  8. import type { SessionEvent } from '@deepseek-ai/dsh-session'
  9. const binScript = fileURLToPath(new URL('./fixtures/headless-driver.ts', import.meta.url))
  10. const configPath = fileURLToPath(new URL('./fixtures/cli.cordis.yml', import.meta.url))
  11. const tsconfigPath = fileURLToPath(new URL('../../../tsconfig.json', import.meta.url))
  12. const decompress = promisify(zstdDecompress)
  13. describe('headless-agent keyless smoke', () => {
  14. it('boots the real Loader tree, runs a real bash tool round trip, and persists the turn', async () => {
  15. let persistedHeader: Record<string, unknown> | undefined
  16. const { stdout, stderr } = await runLoaderSmoke({
  17. label: 'headless-agent',
  18. tempDirPrefix: 'headless-agent-smoke-',
  19. binScript,
  20. libBinScript: binScript,
  21. configPath,
  22. binArgs: [configPath, 'prove the tool path'],
  23. tsconfigPath,
  24. inspect: async (cwd) => {
  25. const files = await readdir(cwd, { recursive: true })
  26. const relativePath = files.find(file => file.endsWith('.jsonl.zstd'))
  27. if (relativePath === undefined) return
  28. const compressed = await readFile(join(cwd, relativePath))
  29. expect(compressed.subarray(0, 4).toString('hex')).toBe('28b52ffd')
  30. persistedHeader = JSON.parse((await decompress(compressed)).toString()) as Record<string, unknown>
  31. },
  32. })
  33. const lines = stdout.trimEnd().split('\n').map(line => JSON.parse(line) as Record<string, unknown>)
  34. const events = lines.slice(0, -1).map(line => line['event'] as SessionEvent)
  35. const result = lines.at(-1)
  36. expect(stderr).toBe('')
  37. expect(events.some(event => event.type === 'tool/call' && event.data.name === 'bash')).toBe(true)
  38. const toolResult = events.find(event => event.type === 'tool/result')
  39. expect(JSON.stringify(toolResult)).toContain('CLI_TOOL_ROUND_TRIP')
  40. expect(result).toMatchObject({
  41. type: 'result',
  42. usage: { inputTokens: 18, outputTokens: 8, cacheReadTokens: 2, reasoningTokens: 1 },
  43. })
  44. expect(String(result?.['output'])).toContain('CLI_TOOL_ROUND_TRIP')
  45. expect(persistedHeader).toMatchObject({ type: 'session' })
  46. }, LOADER_SMOKE_TEST_TIMEOUT_MS)
  47. })