feat(S-103): Test-drive and implement --debug diagnostic mode
This commit is contained in:
@@ -16,6 +16,7 @@ interface MockScenario {
|
||||
|
||||
function createMockChildProcess(scenario: MockScenario): any {
|
||||
const child = new EventEmitter() as any;
|
||||
child.pid = 12345;
|
||||
child.stdout = Readable.from(
|
||||
scenario.stdout !== undefined ? [scenario.stdout] : []
|
||||
);
|
||||
@@ -257,4 +258,66 @@ describe("executePrompt", () => {
|
||||
global.setTimeout = origSetTimeout;
|
||||
}
|
||||
});
|
||||
|
||||
it("emits debug info via onDebug when debug is true for successful execution", async () => {
|
||||
const scenarios = new Map<string, MockScenario>([
|
||||
["codex exec --yolo hello", { stdout: "ok", stderr: "warn", exitCode: 0 }],
|
||||
]);
|
||||
const debugInfos: any[] = [];
|
||||
const result = await executePrompt("codex", "hello", {
|
||||
spawn: mockSpawn(scenarios),
|
||||
existsSync: () => true,
|
||||
debug: true,
|
||||
onDebug: (info) => debugInfos.push(info),
|
||||
});
|
||||
assert.strictEqual(result.exitCode, 0);
|
||||
assert.strictEqual(debugInfos.length, 1);
|
||||
const info = debugInfos[0];
|
||||
assert.strictEqual(info.command, "codex");
|
||||
assert.deepStrictEqual(info.args, ["exec", "--yolo", "hello"]);
|
||||
assert.strictEqual(info.pid, 12345);
|
||||
assert.strictEqual(info.exitCode, 0);
|
||||
assert.strictEqual(info.exitSignal, null);
|
||||
assert.strictEqual(info.stderrLength, 4);
|
||||
assert.strictEqual(info.stdoutLength, 2);
|
||||
assert.strictEqual(typeof info.durationMs, "number");
|
||||
assert.ok(info.durationMs >= 0);
|
||||
});
|
||||
|
||||
it("emits debug info via onDebug when debug is true for failed execution", async () => {
|
||||
const scenarios = new Map<string, MockScenario>([
|
||||
["codex exec --yolo fail", { stdout: "", stderr: "error", exitCode: 1 }],
|
||||
]);
|
||||
const debugInfos: any[] = [];
|
||||
const result = await executePrompt("codex", "fail", {
|
||||
spawn: mockSpawn(scenarios),
|
||||
existsSync: () => true,
|
||||
debug: true,
|
||||
onDebug: (info) => debugInfos.push(info),
|
||||
});
|
||||
assert.strictEqual(result.exitCode, 1);
|
||||
assert.strictEqual(debugInfos.length, 1);
|
||||
assert.strictEqual(debugInfos[0].exitCode, 1);
|
||||
assert.strictEqual(debugInfos[0].stderrLength, 5);
|
||||
assert.strictEqual(debugInfos[0].stdoutLength, 0);
|
||||
});
|
||||
|
||||
it("emits debug info via onDebug for spawn errors", async () => {
|
||||
const scenarios = new Map<string, MockScenario>();
|
||||
const debugInfos: any[] = [];
|
||||
await assert.rejects(
|
||||
executePrompt("codex", "hello", {
|
||||
spawn: mockSpawn(scenarios),
|
||||
existsSync: () => true,
|
||||
debug: true,
|
||||
onDebug: (info) => debugInfos.push(info),
|
||||
}),
|
||||
(err: unknown) => err instanceof ClientNotFoundError
|
||||
);
|
||||
assert.strictEqual(debugInfos.length, 1);
|
||||
assert.strictEqual(debugInfos[0].command, "codex");
|
||||
assert.deepStrictEqual(debugInfos[0].args, ["exec", "--yolo", "hello"]);
|
||||
assert.strictEqual(debugInfos[0].exitCode, null);
|
||||
assert.strictEqual(debugInfos[0].exitSignal, null);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user