






















@@ -12,7 +12,7 @@ const mocks = vi.hoisted(() => {
1212defaultRuntime.log(value.endsWith("\n") ? value.slice(0, -1) : value);
1313}),
1414writeJson: vi.fn((value: unknown, space = 2) => {
15-defaultRuntime.log(JSON.stringify(value, null, space > 0 ? space : undefined));
15+defaultRuntime.writeStdout(JSON.stringify(value, null, space > 0 ? space : undefined));
1616}),
1717exit: vi.fn((code: number) => {
1818throw new Error(`__exit__:${code}`);
@@ -548,6 +548,110 @@ describe("cron cli", () => {
548548const addCall = callGatewayFromCli.mock.calls.find((call) => call[0] === "cron.add");
549549const params = addCall?.[2] as { agentId?: string };
550550expect(params?.agentId).toBe("ops");
551+expect(defaultRuntime.error).not.toHaveBeenCalledWith(
552+expect.stringContaining("No --agent specified"),
553+);
554+});
555+556+it("warns when --agent is not specified on cron add with --message", async () => {
557+await runCronCommand([
558+"cron",
559+"add",
560+"--name",
561+"No agent",
562+"--cron",
563+"* * * * *",
564+"--message",
565+"hello",
566+]);
567+568+expect(defaultRuntime.error).toHaveBeenCalledWith(
569+expect.stringContaining("No --agent specified"),
570+);
571+expect(defaultRuntime.error).toHaveBeenCalledWith(
572+expect.stringContaining("default agent (main)"),
573+);
574+});
575+576+it("keeps the missing --agent warning off cron add JSON stdout", async () => {
577+await runCronCommand([
578+"cron",
579+"add",
580+"--name",
581+"No agent JSON",
582+"--cron",
583+"* * * * *",
584+"--message",
585+"hello",
586+"--json",
587+]);
588+589+expect(defaultRuntime.error).toHaveBeenCalledWith(
590+expect.stringContaining("No --agent specified"),
591+);
592+const stdout = defaultRuntime.writeStdout.mock.calls.map(([value]) => value).join("\n");
593+expect(stdout).not.toContain("No --agent specified");
594+expect(JSON.parse(stdout)).toMatchObject({
595+ok: true,
596+params: {
597+name: "No agent JSON",
598+payload: { kind: "agentTurn", message: "hello" },
599+},
600+});
601+});
602+603+it("warns when --agent is blank on cron add with --message", async () => {
604+const params = await runCronAddAndGetParams([
605+"--name",
606+"Blank agent",
607+"--cron",
608+"* * * * *",
609+"--message",
610+"hello",
611+"--agent",
612+" ",
613+]);
614+615+expect(params?.agentId).toBeUndefined();
616+expect(defaultRuntime.error).toHaveBeenCalledWith(
617+expect.stringContaining("No --agent specified"),
618+);
619+});
620+621+it("does not warn when --system-event is used (no agent needed)", async () => {
622+await runCronCommand([
623+"cron",
624+"add",
625+"--name",
626+"System event",
627+"--cron",
628+"* * * * *",
629+"--system-event",
630+"tick",
631+]);
632+633+expect(defaultRuntime.error).not.toHaveBeenCalledWith(
634+expect.stringContaining("No --agent specified"),
635+);
636+});
637+638+it("warns even when --session-key is provided (user should still specify agent explicitly)", async () => {
639+await runCronCommand([
640+"cron",
641+"add",
642+"--name",
643+"With session key",
644+"--cron",
645+"* * * * *",
646+"--message",
647+"hello",
648+"--session-key",
649+"agent:my-agent:my-session",
650+]);
651+652+expect(defaultRuntime.error).toHaveBeenCalledWith(
653+expect.stringContaining("No --agent specified"),
654+);
551655});
552656553657it("sets lightContext on cron add when --light-context is passed", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。