50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { strict as assert } from "node:assert";
|
|
import { runCommandObserved, type CommandProgress } from "./src/command";
|
|
import { repoRoot } from "./src/config";
|
|
|
|
const progressEvents: CommandProgress[] = [];
|
|
const startedAt = Date.now();
|
|
const result = await runCommandObserved(
|
|
[
|
|
"bun",
|
|
"--eval",
|
|
"setTimeout(() => {}, 10_000)",
|
|
],
|
|
repoRoot,
|
|
{
|
|
timeoutMs: 250,
|
|
heartbeatMs: 50,
|
|
killAfterMs: 100,
|
|
onProgress: (progress) => progressEvents.push(progress),
|
|
},
|
|
);
|
|
|
|
assert.equal(result.timedOut, true);
|
|
assert.notEqual(result.signal, null);
|
|
assert.ok(result.durationMs !== undefined && result.durationMs < 2_000, `expected bounded duration, got ${result.durationMs}`);
|
|
assert.ok(Date.now() - startedAt < 2_000, "silent child should not block beyond timeout");
|
|
assert.ok(progressEvents.length > 0, "silent child must still emit heartbeat progress");
|
|
assert.ok(progressEvents.some((event) => event.elapsedMs > 0 && event.timeoutMs === 250), "heartbeat must expose elapsed and timeout");
|
|
assert.equal(result.stdoutBytes, 0);
|
|
assert.equal(result.stderrBytes, 0);
|
|
assert.equal(result.stdoutTruncated, false);
|
|
assert.equal(result.stderrTruncated, false);
|
|
|
|
const noisy = await runCommandObserved(
|
|
[
|
|
"bun",
|
|
"--eval",
|
|
"console.log('x'.repeat(2048)); console.error('y'.repeat(2048));",
|
|
],
|
|
repoRoot,
|
|
{ timeoutMs: 5_000, maxCaptureChars: 128 },
|
|
);
|
|
|
|
assert.equal(noisy.exitCode, 0);
|
|
assert.ok(noisy.stdout.length <= 128);
|
|
assert.ok(noisy.stderr.length <= 128);
|
|
assert.equal(noisy.stdoutTruncated, true);
|
|
assert.equal(noisy.stderrTruncated, true);
|
|
|
|
console.log("check command progress contract ok");
|