fix: add async CaseRun CLI controls
This commit is contained in:
@@ -113,6 +113,68 @@ test("case run exposes Keil hex and axf artifacts in evidence summary", () => {
|
||||
assert.deepEqual(artifactsFromKeilStatusForTest({ result: { hex_file: "F:\\out.hex", axf_file: "F:\\out.axf" } }), ["F:\\out.hex", "F:\\out.axf"]);
|
||||
});
|
||||
|
||||
test("case run start returns immediately and status/result/logs are short polling commands", async () => {
|
||||
const root = await mkdtempCaseRoot();
|
||||
const caseRepo = path.join(root, "hwlab-case-registry");
|
||||
const cwd = path.join(root, "hwlab");
|
||||
const caseId = "d601-f103-v2-compile";
|
||||
try {
|
||||
await createCaseRepo(caseRepo, caseId);
|
||||
await mkdir(cwd, { recursive: true });
|
||||
const started = await runHwlabCli([
|
||||
"case",
|
||||
"run",
|
||||
"start",
|
||||
caseId,
|
||||
"--case-repo",
|
||||
caseRepo,
|
||||
"--run-id",
|
||||
"run-async"
|
||||
], {
|
||||
cwd,
|
||||
now: () => "2026-06-05T00:00:00.000Z",
|
||||
startProcess: async (input) => {
|
||||
await writeFile(input.stdoutPath, "worker accepted\n", "utf8");
|
||||
await writeFile(input.stderrPath, "", "utf8");
|
||||
return { pid: 4242 };
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal(started.exitCode, 0);
|
||||
assert.equal(started.payload.action, "case.run.start");
|
||||
assert.equal(started.payload.status, "submitted");
|
||||
assert.equal(started.payload.startReturned, true);
|
||||
assert.equal(started.payload.pid, 4242);
|
||||
assert.match(started.payload.statusCommand, /case run status run-async/u);
|
||||
assert.match(started.payload.resultCommand, /case run result run-async/u);
|
||||
assert.match(started.payload.logsCommand, /case run logs run-async/u);
|
||||
|
||||
const status = await runHwlabCli(["case", "run", "status", "run-async"], { cwd, now: () => "2026-06-05T00:00:01.000Z" });
|
||||
assert.equal(status.exitCode, 0);
|
||||
assert.equal(status.payload.action, "case.run.status");
|
||||
assert.equal(status.payload.status, "running");
|
||||
assert.equal(status.payload.stage, "started");
|
||||
assert.equal(status.payload.pid, 4242);
|
||||
assert.equal(status.payload.stdoutBytes, Buffer.byteLength("worker accepted\n"));
|
||||
assert.equal(status.payload.stderrBytes, 0);
|
||||
assert.match(status.payload.nextPollCommand, /case run status run-async/u);
|
||||
|
||||
const result = await runHwlabCli(["case", "run", "result", "run-async"], { cwd, now: () => "2026-06-05T00:00:02.000Z" });
|
||||
assert.equal(result.exitCode, 0);
|
||||
assert.equal(result.payload.action, "case.run.result");
|
||||
assert.equal(result.payload.ready, false);
|
||||
assert.equal(result.payload.status, "running");
|
||||
assert.match(result.payload.nextPollCommand, /case run status run-async/u);
|
||||
|
||||
const logs = await runHwlabCli(["case", "run", "logs", "run-async", "--tail", "200"], { cwd, now: () => "2026-06-05T00:00:03.000Z" });
|
||||
assert.equal(logs.exitCode, 0);
|
||||
assert.equal(logs.payload.action, "case.run.logs");
|
||||
assert.equal(logs.payload.stdout, "worker accepted\n");
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("case run orchestrates agent prompt, diff capture, and compile evidence without auto evaluation", async () => {
|
||||
const root = await mkdtempCaseRoot();
|
||||
const caseRepo = path.join(root, "hwlab-case-registry");
|
||||
@@ -134,6 +196,7 @@ test("case run orchestrates agent prompt, diff capture, and compile evidence wit
|
||||
await writeFile(path.join(caseDir, "hwpod-spec.yaml"), hwpodSpecText(), "utf8");
|
||||
|
||||
const requests: any[] = [];
|
||||
let sawAgentRunningState = false;
|
||||
const result = await runHwlabCli([
|
||||
"case",
|
||||
"run",
|
||||
@@ -149,7 +212,17 @@ test("case run orchestrates agent prompt, diff capture, and compile evidence wit
|
||||
], {
|
||||
cwd,
|
||||
now: () => "2026-06-05T00:00:00.000Z",
|
||||
sleep: async () => undefined,
|
||||
sleep: async () => {
|
||||
const runState = JSON.parse(await readFile(path.join(cwd, ".state", "hwlab-cli", "caserun", "run-agent-flow", "run.json"), "utf8"));
|
||||
assert.equal(runState.stage, "agent-running");
|
||||
assert.equal(runState.agent.stageStatus, "running");
|
||||
assert.equal(runState.agent.sessionId, "ses_case_run");
|
||||
assert.equal(runState.agent.conversationId, "cnv_case_d601-f103-v2-compile_run-agent-flow");
|
||||
assert.equal(runState.agent.threadId, "thread-case");
|
||||
assert.match(runState.agent.traceId, /^trc_case_/u);
|
||||
assert.match(runState.agent.nextPollCommand, /client agent result trc_case_/u);
|
||||
sawAgentRunningState = true;
|
||||
},
|
||||
env: { HWLAB_API_KEY: "hwl_live_test_case_agent_key" },
|
||||
runProcess: async () => ({ command: [], exitCode: 0, stdout: JSON.stringify({ body: { results: [{ output: { stdout: JSON.stringify({ job_id: "job-compile-1" }) } }] } }), stderr: "" }),
|
||||
fetchImpl: caseRunFlowFetch(requests)
|
||||
@@ -168,6 +241,7 @@ test("case run orchestrates agent prompt, diff capture, and compile evidence wit
|
||||
assert.equal(result.payload.build.hwpodExitCode, 0);
|
||||
assert.equal(result.payload.build.keilStatus, "completed");
|
||||
assert.equal(result.payload.collect.autoEvaluation, false);
|
||||
assert.equal(sawAgentRunningState, true);
|
||||
|
||||
const prompt = await readFile(path.join(cwd, ".state", "hwlab-cli", "caserun", "run-agent-flow", "agent-prompt.md"), "utf8");
|
||||
assert.match(prompt, /without auto-grading/u);
|
||||
|
||||
Reference in New Issue
Block a user