fix(dev): clean up web backend lifecycle

This commit is contained in:
digua committed 2026-06-05 11:12:42 +08:00
1 parent 296573ed5c
commit 953471a514
6 files changed
+124 -106

No files matched your search

+25 -1
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { createChatlabStartCommand } from './dev-server-command.mjs'
import { createChatlabStartCommand, terminateChatlabStartProcess } from './dev-server-command.mjs'
test('web dev backend runs through the current Node executable with the tsx loader', () => {
const command = createChatlabStartCommand({
@@ -25,4 +25,28 @@ test('web dev backend runs through the current Node executable with the tsx load
'--port',
'3110',
])
assert.equal(command.options.detached, true)
})
test('web dev backend cleanup terminates the whole POSIX process group', () => {
const killed = []
const proc = {
pid: 12345,
exitCode: null,
signalCode: null,
kill(signal) {
killed.push(['child', signal])
return true
},
}
terminateChatlabStartProcess(proc, {
platform: 'darwin',
killProcess: (pid, signal) => {
killed.push(['process', pid, signal])
return true
},
})
assert.deepEqual(killed, [['process', -12345, 'SIGTERM']])
})