From 2ddcae012dedcfcc991027a9f0f538ec270d89f4 Mon Sep 17 00:00:00 2001 From: jdalton Date: Wed, 25 Nov 2026 16:57:14 -0500 Subject: [PATCH] fix(test): verify native launcher signal delivery directly --- test/native-launcher.test.mts | 50 ++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/test/native-launcher.test.mts b/test/native-launcher.test.mts index 0b6bca0b6..877598009 100644 --- a/test/native-launcher.test.mts +++ b/test/native-launcher.test.mts @@ -79,30 +79,48 @@ describe('installed native launcher', () => { it.skipIf(process.platform === 'win32').each(['host', 'without execve'])( 'passes a targeted termination signal to the running executable (%s)', + { timeout: 15_000 }, async mode => { // A service supervisor signals the launcher PID directly (no terminal group). - const options = [] - if (mode === 'without execve') { - const preload = path.join(root, 'old-node.cjs') - await writeFile(preload, 'process.execve = undefined') - options.push('--require', preload) - } + const options = + mode === 'without execve' + ? ['--import', 'data:text/javascript,process.execve=undefined'] + : [] + const fixture = ` + process.once('SIGTERM', () => { + process.stdout.write(' SIGTERM', () => process.kill(process.pid, 'SIGTERM')) + }) + setTimeout(() => process.exit(1), 10_000) + process.stdout.write('ready') + ` const child = spawn( process.execPath, - [...options, launcher, '-c', 'printf "%s\\n" "$$"; exec sleep 20'], + [ + ...options, + launcher, + '-c', + 'exec "$@"', + 'fixture', + process.execPath, + '-e', + fixture, + ], { stdio: ['ignore', 'pipe', 'pipe'] }, ) - const exited = once(child, 'exit') - const [output] = await once(child.stdout, 'data') - const nativePid = Number(String(output).trim()) + let output = '' + child.stdout.setEncoding('utf8').on('data', chunk => { + output += chunk + }) + const closed = once(child, 'close') try { - child.kill('SIGTERM') - await expect(exited).resolves.toEqual([null, 'SIGTERM']) - expect(() => process.kill(nativePid, 0)).toThrow() + await Promise.race([once(child.stdout, 'data'), closed]) + expect(child.kill('SIGTERM')).toBe(true) + await expect(closed).resolves.toEqual([null, 'SIGTERM']) + expect(output).toBe('ready SIGTERM') } finally { - try { - process.kill(nativePid, 'SIGKILL') - } catch {} + if (child.exitCode === null && child.signalCode === null) { + child.kill('SIGKILL') + } } }, )