spawn-runner-built.e2e.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { spawnSync } from 'node:child_process'
  2. import { existsSync } from 'node:fs'
  3. import { fileURLToPath } from 'node:url'
  4. import { describe, expect, it } from 'vitest'
  5. import { cleanupRunnerFiles, createRunnerFiles, readRunnerEvents } from '../src/runner-protocol.ts'
  6. const builtEntry = fileURLToPath(import.meta.resolve('@deepseek-ai/dsh-subprocess-local/spawn-runner'))
  7. const required = process.env.DSH_REQUIRE_BUILT_SUBPROCESS_RUNNER === '1'
  8. describe.skipIf(!existsSync(builtEntry) && !required)('built subprocess runner entry', () => {
  9. it('reports the direct target outcome through the published entry', () => {
  10. if (!existsSync(builtEntry)) throw new Error(`required built subprocess runner is missing: ${builtEntry}`)
  11. const files = createRunnerFiles({
  12. argv: [process.execPath, '-e', 'process.exit(11)'],
  13. cwd: process.cwd(),
  14. env: {},
  15. })
  16. try {
  17. const result = spawnSync(process.execPath, [
  18. builtEntry,
  19. '--mode',
  20. 'node',
  21. '--request',
  22. files.requestPath,
  23. '--events',
  24. files.eventsPath,
  25. ], { encoding: 'utf8', timeout: 10_000 })
  26. expect(result.error).toBeUndefined()
  27. const events = readRunnerEvents(files.eventsPath)
  28. expect(events).toHaveLength(2)
  29. expect(events[0]?.type).toBe('started')
  30. if (events[0]?.type !== 'started') throw new Error('expected started event')
  31. expect(events[0].pid).toBeGreaterThan(0)
  32. expect(events[1]).toEqual({ type: 'exit', exitCode: 11, signal: null })
  33. } finally {
  34. cleanupRunnerFiles(files)
  35. }
  36. })
  37. })