

























11// Cron edit register tests cover cron edit command registration and option wiring.
22import { Command } from "commander";
33import { beforeEach, describe, expect, it, vi } from "vitest";
4+import { defaultRuntime } from "../../runtime.js";
4556const callGatewayFromCli = vi.fn();
67@@ -228,4 +229,114 @@ describe("cron edit command", () => {
228229expect(help).toContain("--clear-model");
229230expect(help).toContain("--clear-tools");
230231});
232+233+it("clears the delivery channel with --clear-channel (CLI parity with cron.update channel:null)", async () => {
234+const program = createCronProgram();
235+236+await program.parseAsync(["edit", "job-1", "--clear-channel"], { from: "user" });
237+238+expect(callGatewayFromCli).toHaveBeenCalledWith(
239+"cron.update",
240+expect.objectContaining({ clearChannel: true }),
241+{
242+id: "job-1",
243+patch: { delivery: { channel: null } },
244+},
245+);
246+});
247+248+it("clears the delivery destination with --clear-to", async () => {
249+const program = createCronProgram();
250+251+await program.parseAsync(["edit", "job-1", "--clear-to"], { from: "user" });
252+253+expect(callGatewayFromCli).toHaveBeenCalledWith(
254+"cron.update",
255+expect.objectContaining({ clearTo: true }),
256+{
257+id: "job-1",
258+patch: { delivery: { to: null } },
259+},
260+);
261+});
262+263+it("clears the delivery thread id with --clear-thread-id", async () => {
264+const program = createCronProgram();
265+266+await program.parseAsync(["edit", "job-1", "--clear-thread-id"], { from: "user" });
267+268+expect(callGatewayFromCli).toHaveBeenCalledWith(
269+"cron.update",
270+expect.objectContaining({ clearThreadId: true }),
271+{
272+id: "job-1",
273+patch: { delivery: { threadId: null } },
274+},
275+);
276+});
277+278+it("clears the delivery account override with --clear-account", async () => {
279+const program = createCronProgram();
280+281+await program.parseAsync(["edit", "job-1", "--clear-account"], { from: "user" });
282+283+expect(callGatewayFromCli).toHaveBeenCalledWith(
284+"cron.update",
285+expect.objectContaining({ clearAccount: true }),
286+{
287+id: "job-1",
288+patch: { delivery: { accountId: null } },
289+},
290+);
291+});
292+293+it.each([
294+{ set: "--channel", value: "telegram", clear: "--clear-channel" },
295+{ set: "--to", value: "12345", clear: "--clear-to" },
296+{ set: "--thread-id", value: "42", clear: "--clear-thread-id" },
297+{ set: "--account", value: "writer", clear: "--clear-account" },
298+])("rejects $set combined with $clear", async ({ set, value, clear }) => {
299+const errorSpy = vi.spyOn(defaultRuntime, "error").mockImplementation(() => {});
300+const exitSpy = vi.spyOn(defaultRuntime, "exit").mockImplementation((() => undefined) as never);
301+const program = createCronProgram();
302+303+await program.parseAsync(["edit", "job-1", set, value, clear], { from: "user" });
304+305+expect(errorSpy).toHaveBeenCalledWith(
306+expect.stringContaining(`Use ${set} or ${clear}, not both`),
307+);
308+expect(callGatewayFromCli).not.toHaveBeenCalled();
309+310+errorSpy.mockRestore();
311+exitSpy.mockRestore();
312+});
313+314+it("rejects --webhook combined with a delivery clear flag", async () => {
315+const errorSpy = vi.spyOn(defaultRuntime, "error").mockImplementation(() => {});
316+const exitSpy = vi.spyOn(defaultRuntime, "exit").mockImplementation((() => undefined) as never);
317+const program = createCronProgram();
318+319+await program.parseAsync(
320+["edit", "job-1", "--webhook", "https://example.invalid/hook", "--clear-channel"],
321+{ from: "user" },
322+);
323+324+expect(errorSpy).toHaveBeenCalledWith(
325+expect.stringContaining("--webhook cannot be combined with chat delivery options."),
326+);
327+expect(callGatewayFromCli).not.toHaveBeenCalled();
328+329+errorSpy.mockRestore();
330+exitSpy.mockRestore();
331+});
332+333+it("documents the delivery clear flags alongside the sibling --clear-model", () => {
334+const editCommand = createCronProgram().commands.find((command) => command.name() === "edit");
335+const help = editCommand?.helpInformation() ?? "";
336+337+expect(help).toContain("--clear-channel");
338+expect(help).toContain("--clear-to");
339+expect(help).toContain("--clear-thread-id");
340+expect(help).toContain("--clear-account");
341+});
231342});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。