MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / createChildBackedChannel

Function createChildBackedChannel

packages/kaos/test/ssh-process.test.ts:78–112  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

76}
77
78function createChildBackedChannel(): { channel: unknown } {
79 const child = spawn(process.execPath, [
80 '-e',
81 [
82 "process.on('SIGTERM', () => {",
83 " console.log('cleanup done');",
84 ' process.exit(42);',
85 '});',
86 "console.log('ready');",
87 'setInterval(() => {}, 1000);',
88 ].join('\n'),
89 ]);
90
91 const stdout = new PassThrough();
92 child.stdout.pipe(stdout);
93
94 const channel = Object.assign(stdout, {
95 stderr: child.stderr,
96 signal(name: string): void {
97 child.kill(`SIG${name}` as NodeJS.Signals);
98 },
99 close(): void {
100 child.kill('SIGTERM');
101 },
102 on(event: string, listener: (...args: unknown[]) => void): unknown {
103 if (event === 'exit' || event === 'close') {
104 child.on(event, listener as (...args: [number | null]) => void);
105 return channel;
106 }
107 return PassThrough.prototype.on.call(stdout, event, listener);
108 },
109 });
110
111 return { channel };
112}
113
114describe('SSHProcess.kill()', () => {
115 test('kill("SIGTERM") sends "TERM" to channel.signal (strips SIG prefix)', async () => {

Callers 1

Calls 1

spawnFunction · 0.50

Tested by

no test coverage detected