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(); } });