feat(M3): Async CLI Integration

This commit is contained in:
2026-05-19 22:22:54 -05:00
parent a2c2b8bf6d
commit 591829369c
5 changed files with 440 additions and 271 deletions
+28 -47
View File
@@ -2,7 +2,16 @@ import { describe, it } from "node:test";
import assert from "node:assert";
import { main } from "../src/cli.js";
import { ClientNotFoundError } from "../src/types.js";
import type { ClientInfo, ExecResult, ClientName } from "../src/types.js";
import type { ClientInfo, ExecResult, ClientName, Job, JobStatus, DebugInfo } from "../src/types.js";
function mockJob(overrides: Partial<Job> & { id: string; status: JobStatus }): Job {
return {
client: "codex",
prompt: "hello",
startedAt: "2024-01-01T00:00:00Z",
...overrides,
} as Job;
}
function captureOutput() {
const logs: string[] = [];
@@ -426,7 +435,8 @@ describe("main", () => {
durationMs: 42,
stderrLength: 0,
stdoutLength: 6,
} as any);
noisySuccess: false,
} satisfies DebugInfo);
return {
stdout: "output",
stderr: "",
@@ -516,7 +526,8 @@ describe("main", () => {
durationMs: 42,
stderrLength: 0,
stdoutLength: 6,
} as any);
noisySuccess: false,
} satisfies DebugInfo);
return {
stdout: "output",
stderr: "",
@@ -705,7 +716,8 @@ describe("main", () => {
durationMs: 42,
stderrLength: 0,
stdoutLength: 6,
} as any);
noisySuccess: false,
} satisfies DebugInfo);
return { id: "job-def", client: "codex", prompt: "hello", status: "running", startedAt: new Date().toISOString() };
},
stderrWrite: (chunk) => stderrChunks.push(chunk),
@@ -871,7 +883,8 @@ describe("main", () => {
durationMs: 42,
stderrLength: 0,
stdoutLength: 6,
} as any);
noisySuccess: false,
} satisfies DebugInfo);
return { id: "job-ghi", client: "codex", prompt: "do something", status: "running", startedAt: new Date().toISOString() };
},
resolveClient: () => "codex",
@@ -953,13 +966,7 @@ describe("main", () => {
["node", "cli.ts", "status", "job-123"],
{
detectClients: () => mockClients,
getJob: (jobId) => ({
id: jobId,
client: "codex",
prompt: "hello",
status: "running",
startedAt: "2024-01-01T00:00:00Z",
} as any),
getJob: (jobId) => mockJob({ id: jobId, status: "running" }),
}
);
assert.strictEqual(code, 0);
@@ -979,15 +986,14 @@ describe("main", () => {
["node", "cli.ts", "status", "job-456"],
{
detectClients: () => mockClients,
getJob: (jobId) => ({
getJob: (jobId) => mockJob({
id: jobId,
client: "claude",
prompt: "write tests",
status: "completed",
startedAt: "2024-01-01T00:00:00Z",
completedAt: "2024-01-01T00:01:00Z",
result: { stdout: "ok", stderr: "", exitCode: 0, client: "claude", durationMs: 100 },
} as any),
}),
}
);
assert.strictEqual(code, 0);
@@ -1040,13 +1046,7 @@ describe("main", () => {
["node", "cli.ts", "status", "job-123", "--text"],
{
detectClients: () => mockClients,
getJob: (jobId) => ({
id: jobId,
client: "codex",
prompt: "hello",
status: "running",
startedAt: "2024-01-01T00:00:00Z",
} as any),
getJob: (jobId) => mockJob({ id: jobId, status: "running" }),
}
);
assert.strictEqual(code, 0);
@@ -1169,13 +1169,7 @@ describe("main", () => {
["node", "cli.ts", "cancel", "job-abc"],
{
detectClients: () => mockClients,
getJob: (jobId) => ({
id: jobId,
client: "codex",
prompt: "hello",
status: "running",
startedAt: "2024-01-01T00:00:00Z",
} as any),
getJob: (jobId) => mockJob({ id: jobId, status: "running" }),
cancelJob: (jobId) => {
cancelledJobId = jobId;
},
@@ -1198,14 +1192,7 @@ describe("main", () => {
["node", "cli.ts", "cancel", "job-done"],
{
detectClients: () => mockClients,
getJob: (jobId) => ({
id: jobId,
client: "codex",
prompt: "hello",
status: "completed",
startedAt: "2024-01-01T00:00:00Z",
completedAt: "2024-01-01T00:01:00Z",
} as any),
getJob: (jobId) => mockJob({ id: jobId, status: "completed", completedAt: "2024-01-01T00:01:00Z" }),
}
);
assert.strictEqual(code, 1);
@@ -1257,13 +1244,7 @@ describe("main", () => {
["node", "cli.ts", "cancel", "job-abc", "--text"],
{
detectClients: () => mockClients,
getJob: (jobId) => ({
id: jobId,
client: "codex",
prompt: "hello",
status: "running",
startedAt: "2024-01-01T00:00:00Z",
} as any),
getJob: (jobId) => mockJob({ id: jobId, status: "running" }),
cancelJob: () => {},
}
);
@@ -1285,7 +1266,7 @@ describe("main", () => {
listJobs: () => [
{ id: "job-1", client: "codex", prompt: "p1", status: "running", startedAt: "2024-01-01T00:00:00Z" },
{ id: "job-2", client: "claude", prompt: "p2", status: "completed", startedAt: "2024-01-01T00:01:00Z" },
] as any[],
],
}
);
assert.strictEqual(code, 0);
@@ -1310,7 +1291,7 @@ describe("main", () => {
receivedFilter = options?.filter;
return [
{ id: "job-1", client: "codex", prompt: "p1", status: "running", startedAt: "2024-01-01T00:00:00Z" },
] as any[];
];
},
}
);
@@ -1333,7 +1314,7 @@ describe("main", () => {
detectClients: () => mockClients,
listJobs: () => [
{ id: "job-1", client: "codex", prompt: "p1", status: "running", startedAt: "2024-01-01T00:00:00Z" },
] as any[],
],
}
);
assert.strictEqual(code, 0);