feat(S-103): Test-drive and implement --debug diagnostic mode
This commit is contained in:
@@ -406,4 +406,91 @@ describe("main", () => {
|
||||
out.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("run prints debug diagnostic JSON to stderr with --debug", async () => {
|
||||
const out = captureOutput();
|
||||
const stderrChunks: string[] = [];
|
||||
try {
|
||||
const code = await main(
|
||||
["node", "cli.ts", "run", "--client", "codex", "--prompt", "hello", "--debug"],
|
||||
{
|
||||
detectClients: () => mockClients,
|
||||
executePrompt: async (_client, _prompt, options?) => {
|
||||
options?.onDebug?.({
|
||||
command: "codex",
|
||||
args: ["exec", "--yolo", "hello"],
|
||||
pid: 12345,
|
||||
exitCode: 0,
|
||||
exitSignal: null,
|
||||
durationMs: 42,
|
||||
stderrLength: 0,
|
||||
stdoutLength: 6,
|
||||
} as any);
|
||||
return {
|
||||
stdout: "output",
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
client: "codex",
|
||||
durationMs: 42,
|
||||
};
|
||||
},
|
||||
stderrWrite: (chunk) => stderrChunks.push(chunk),
|
||||
}
|
||||
);
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(stderrChunks.length, 1);
|
||||
const diag = JSON.parse(stderrChunks[0]);
|
||||
assert.strictEqual(diag.command, "codex");
|
||||
assert.deepStrictEqual(diag.args, ["exec", "--yolo", "hello"]);
|
||||
assert.strictEqual(diag.pid, 12345);
|
||||
assert.strictEqual(diag.exitCode, 0);
|
||||
assert.strictEqual(diag.exitSignal, null);
|
||||
assert.strictEqual(diag.durationMs, 42);
|
||||
assert.strictEqual(diag.stderrLength, 0);
|
||||
} finally {
|
||||
out.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("dispatch prints debug diagnostic JSON to stderr with --debug", async () => {
|
||||
const out = captureOutput();
|
||||
const stderrChunks: string[] = [];
|
||||
try {
|
||||
const code = await main(
|
||||
["node", "cli.ts", "dispatch", "do something", "--debug"],
|
||||
{
|
||||
detectClients: () => mockClients,
|
||||
executePrompt: async (_client, _prompt, options?) => {
|
||||
options?.onDebug?.({
|
||||
command: "codex",
|
||||
args: ["exec", "--yolo", "do something"],
|
||||
pid: 12345,
|
||||
exitCode: 0,
|
||||
exitSignal: null,
|
||||
durationMs: 42,
|
||||
stderrLength: 0,
|
||||
stdoutLength: 6,
|
||||
} as any);
|
||||
return {
|
||||
stdout: "output",
|
||||
stderr: "",
|
||||
exitCode: 0,
|
||||
client: "codex",
|
||||
durationMs: 42,
|
||||
};
|
||||
},
|
||||
resolveClient: () => "codex",
|
||||
resolveConfig: () => ({ paths: {}, timeout: 600_000 }),
|
||||
stderrWrite: (chunk) => stderrChunks.push(chunk),
|
||||
}
|
||||
);
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(stderrChunks.length, 1);
|
||||
const diag = JSON.parse(stderrChunks[0]);
|
||||
assert.strictEqual(diag.command, "codex");
|
||||
assert.strictEqual(diag.durationMs, 42);
|
||||
} finally {
|
||||
out.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user