test(subprocess): cover runner liveness polling

This commit is contained in:
pku-xht committed 2026-08-20 22:37:52 +08:00
1 parent 0f3db79902
commit b25e790e36
2 files changed
+5

No files matched your search

@@ -68,6 +68,7 @@ interface RunnerHandshake {
function runnerExited(child: ChildProcess): boolean {
if (child.exitCode !== null || child.signalCode !== null) return true
if (child.pid === undefined) return true
/* v8 ignore start -- Linux zombie detection is exercised by the real user-systemd test environment. */
if (process.platform === 'linux') {
try {
const stat = readFileSync(`/proc/${String(child.pid)}/stat`, 'utf8')
@@ -77,10 +78,12 @@ function runnerExited(child: ChildProcess): boolean {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return true
}
}
/* v8 ignore stop */
try {
process.kill(child.pid, 0)
return false
} catch (error) {
/* v8 ignore next -- EPERM means the known process still exists but is not signalable. */
return (error as NodeJS.ErrnoException).code === 'ESRCH'
}
}
@@ -1,6 +1,7 @@
import { spawnSync } from 'node:child_process'
import type { ChildProcess } from 'node:child_process'
import { existsSync, statSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, expect, it, vi } from 'vitest'
import type { SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess'
@@ -131,6 +132,7 @@ describe('spawn runner transport', () => {
const files = createRunnerFiles({ argv: ['node'], cwd: '.', env: {} })
try {
expect(readRunnerEvents(files.eventsPath)).toEqual([])
await expect(readRunnerEventsAsync(join(files.directory, 'missing.ndjson'))).resolves.toEqual([])
appendRunnerEvent(files.eventsPath, { type: 'started', pid: 123 })
appendRunnerEvent(files.eventsPath, {
type: 'runner-error',