spawn-runner-built.e2e.ts 1.6 KB

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