fix(workflow): distinguish watch completion from timeout and cancellation

This commit is contained in:
gitea committed 2026-10-20 18:06:53 +08:00
1 parent fac81b08e8
commit 98ceb85a5c
9 files changed
+187 -124

No files matched your search

@@ -0,0 +1,15 @@
import { expect, spyOn, test } from "bun:test";
import { parseArgs } from "../../parser.js";
import * as shared from "./shared.js";
import { handleWorkflowTailCommand } from "./tail.js";
test("CLI tail exits nonzero and emits timeout for a job still running at the deadline", async () => {
const client = { get: async (path: string) => Response.json({ data: path.includes("/execution") ? [] : { id: "job", pipelineId: "wf", status: "RUNNING" } }) };
const spy = spyOn(shared, "createWorkflowDetailClient").mockResolvedValue({ client } as any);
try {
const result = await handleWorkflowTailCommand(parseArgs(["workflow", "tail", "wf", "--job", "job", "--timeout", "0.005"]), { jsonMode: true } as any);
expect(result.exitCode).toBe(1);
const events = result.stdout.trim().split("\n").map(line => JSON.parse(line));
expect(events.some(e => e.type === "timeout")).toBe(true);
expect(events.some(e => e.type === "job_completed")).toBe(false);
} finally { spy.mockRestore(); }
});
+3 -3
View File
@@ -94,19 +94,19 @@ export async function handleWorkflowTailCommand(
return {
stdout: printJson(report, runtime.outputOptions),
stderr: "",
exitCode: report.hasFailures ? 1 : 0,
exitCode: report.hasFailures || report.timedOut || report.cancelled ? 1 : 0,
};
}
return {
stdout: runtime.writeStdout ? "" : outputChunks.join(""),
stderr: "",
exitCode: report.hasFailures ? 1 : 0,
exitCode: report.hasFailures || report.timedOut || report.cancelled ? 1 : 0,
};
}
return {
stdout: runtime.writeStdout ? "" : outputChunks.join(""),
stderr: "",
exitCode: report.hasFailures ? 1 : 0,
exitCode: report.hasFailures || report.timedOut || report.cancelled ? 1 : 0,
};
}