|
| 1 | +import { Command } from "commander"; |
| 2 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | + |
| 4 | +const callGatewayFromCli = vi.fn(); |
| 5 | + |
| 6 | +vi.mock("../gateway-rpc.js", async () => { |
| 7 | +const actual = await vi.importActual<typeof import("../gateway-rpc.js")>("../gateway-rpc.js"); |
| 8 | +return { |
| 9 | + ...actual, |
| 10 | +callGatewayFromCli: (...args: Parameters<typeof actual.callGatewayFromCli>) => |
| 11 | +callGatewayFromCli(...args), |
| 12 | +}; |
| 13 | +}); |
| 14 | + |
| 15 | +const { registerCronEditCommand } = await import("./register.cron-edit.js"); |
| 16 | + |
| 17 | +function createCronProgram(): Command { |
| 18 | +const program = new Command(); |
| 19 | +program.exitOverride(); |
| 20 | +registerCronEditCommand(program); |
| 21 | +return program; |
| 22 | +} |
| 23 | + |
| 24 | +describe("cron edit command", () => { |
| 25 | +beforeEach(() => { |
| 26 | +callGatewayFromCli.mockReset(); |
| 27 | +callGatewayFromCli.mockResolvedValue({ ok: true }); |
| 28 | +}); |
| 29 | + |
| 30 | +it("documents that --best-effort-deliver implies announce mode when used alone (#83908)", () => { |
| 31 | +const editCommand = createCronProgram().commands.find((command) => command.name() === "edit"); |
| 32 | +const help = editCommand?.helpInformation() ?? ""; |
| 33 | + |
| 34 | +expect(help).toContain("--best-effort-deliver"); |
| 35 | +expect(help).toMatch(/also\s+implies --announce when used alone/); |
| 36 | +}); |
| 37 | + |
| 38 | +it("keeps the documented --best-effort-deliver-only patch behavior (#83908)", async () => { |
| 39 | +const program = createCronProgram(); |
| 40 | + |
| 41 | +await program.parseAsync(["edit", "job-1", "--best-effort-deliver"], { from: "user" }); |
| 42 | + |
| 43 | +expect(callGatewayFromCli).toHaveBeenCalledWith( |
| 44 | +"cron.update", |
| 45 | +expect.objectContaining({ bestEffortDeliver: true }), |
| 46 | +{ |
| 47 | +id: "job-1", |
| 48 | +patch: { |
| 49 | +payload: { kind: "agentTurn" }, |
| 50 | +delivery: { |
| 51 | +mode: "announce", |
| 52 | +bestEffort: true, |
| 53 | +}, |
| 54 | +}, |
| 55 | +}, |
| 56 | +); |
| 57 | +}); |
| 58 | +}); |