Skip to content

Commit 637b9bc

Browse files
igorcostaAutohand Evolve
andcommitted
Make foreground command cancellation testing event-driven
Replace filesystem PID polling, Vitest's one-second wait loop, and the competing command timeout with a stdout readiness promise. The child now stays alive until the test aborts it, so the assertion still proves captured output is preserved without racing process startup under full-suite load. Validated with 25 repeated focused runs, all 38 command tests, the 6,788-test repository suite, lint, typecheck, production ESM/CJS/declaration builds, and all 23 built-CLI Tuistory scenarios. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent f0ba4b7 commit 637b9bc

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

‎tests/command.spec.ts‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,33 +171,35 @@ describe('runCommand', () => {
171171
});
172172

173173
it('aborts a foreground command and preserves output captured before termination', async () => {
174-
const markerPath = join(testDir, 'foreground-abort-pid');
175174
const controller = new AbortController();
176175
let streamedOutput = '';
176+
let resolveStarted!: () => void;
177+
const started = new Promise<void>((resolve) => {
178+
resolveStarted = resolve;
179+
});
177180
const commandPromise = runCommand(
178181
process.execPath,
179182
['-e', [
180-
`require('node:fs').writeFileSync(${JSON.stringify(markerPath)}, String(process.pid))`,
181183
`process.stdout.write('started\\n')`,
182-
'setTimeout(() => process.exit(0), 500)',
184+
'setInterval(() => {}, 1000)',
183185
].join(';')],
184186
testDir,
185187
{
186188
signal: controller.signal,
187-
timeout: 750,
188189
onStdout: (chunk) => {
189190
streamedOutput += chunk;
191+
if (streamedOutput.includes('started\n')) {
192+
resolveStarted();
193+
}
190194
},
191195
}
192196
);
193-
const pid = await waitForProcessId(markerPath);
194-
await vi.waitFor(() => expect(streamedOutput).toContain('started'));
197+
await started;
195198

196199
controller.abort();
197200
const error = await commandPromise.catch((caught: unknown) => caught);
198201

199202
expect(error).toMatchObject({ name: 'AbortError', stdout: 'started\n' });
200-
await waitForProcessExit(pid);
201203
});
202204

203205
it('forces a foreground command to exit when it ignores SIGTERM', async () => {

0 commit comments

Comments
 (0)