Fix: Make cleanup strategy dynamic to support testing mocks

This commit is contained in:
xuewenjie
2025-12-12 17:47:03 +08:00
parent 574d89da14
commit b272ac0119

View File

@@ -137,7 +137,7 @@ const posixStrategy: ProcessCleanupStrategy = {
}, },
}; };
const cleanupStrategy = const getCleanupStrategy = () =>
os.platform() === 'win32' ? windowsStrategy : posixStrategy; os.platform() === 'win32' ? windowsStrategy : posixStrategy;
/** /**
@@ -151,17 +151,18 @@ export class ShellExecutionService {
private static activeChildProcesses = new Set<number>(); private static activeChildProcesses = new Set<number>();
static cleanup() { static cleanup() {
const strategy = getCleanupStrategy();
// Cleanup PTYs // Cleanup PTYs
for (const [pid, pty] of this.activePtys) { for (const [pid, pty] of this.activePtys) {
try { try {
cleanupStrategy.killPty(pid, pty); strategy.killPty(pid, pty);
} catch { } catch {
// ignore // ignore
} }
} }
// Cleanup child processes // Cleanup child processes
cleanupStrategy.killChildProcesses(this.activeChildProcesses); strategy.killChildProcesses(this.activeChildProcesses);
} }
static { static {