

























@@ -7,6 +7,8 @@ const modelsListCommandMock = vi.hoisted(() => vi.fn(async () => {}));
77const modelsStatusCommandMock = vi.hoisted(() => vi.fn(async () => {}));
88const runDaemonStatusMock = vi.hoisted(() => vi.fn(async () => {}));
99const statusJsonCommandMock = vi.hoisted(() => vi.fn(async () => {}));
10+const tasksListJsonCommandMock = vi.hoisted(() => vi.fn(async () => {}));
11+const tasksAuditJsonCommandMock = vi.hoisted(() => vi.fn(async () => {}));
1012const channelsListCommandMock = vi.hoisted(() => vi.fn(async () => {}));
1113const channelsStatusCommandMock = vi.hoisted(() => vi.fn(async () => {}));
1214@@ -38,6 +40,15 @@ vi.mock("../../commands/status-json.js", () => ({
3840statusJsonCommand: statusJsonCommandMock,
3941}));
404243+vi.mock("../../commands/tasks-json.js", () => ({
44+tasksListJsonCommand: tasksListJsonCommandMock,
45+tasksAuditJsonCommand: tasksAuditJsonCommandMock,
46+}));
47+48+vi.mock("../../commands/tasks.js", () => {
49+throw new Error("routed task JSON commands must not import the full tasks command module");
50+});
51+4152vi.mock("../../commands/channels/list.js", () => ({
4253channelsListCommand: channelsListCommandMock,
4354}));
@@ -376,4 +387,117 @@ describe("program routes", () => {
376387expect.any(Object),
377388);
378389});
390+391+it("routes tasks list JSON through the lean task JSON command", async () => {
392+const rootRoute = expectRoute(["tasks"]);
393+expect(rootRoute?.loadPlugins).toBeUndefined();
394+expect(rootRoute?.canRun?.(["node", "openclaw", "tasks"])).toBe(false);
395+await expect(
396+rootRoute?.run([
397+"node",
398+"openclaw",
399+"tasks",
400+"--json",
401+"--runtime",
402+"cli",
403+"--status=running",
404+]),
405+).resolves.toBe(true);
406+expect(tasksListJsonCommandMock).toHaveBeenCalledWith(
407+{ json: true, runtime: "cli", status: "running" },
408+expect.any(Object),
409+);
410+411+const listRoute = expectRoute(["tasks", "list"]);
412+expect(listRoute?.loadPlugins).toBeUndefined();
413+await expect(
414+listRoute?.run(["node", "openclaw", "tasks", "list", "--json", "--runtime=cron"]),
415+).resolves.toBe(true);
416+expect(tasksListJsonCommandMock).toHaveBeenLastCalledWith(
417+{ json: true, runtime: "cron", status: undefined },
418+expect.any(Object),
419+);
420+});
421+422+it("routes parent task filter values that command-path discovery sees as positionals", async () => {
423+const separateValueArgv = [
424+"node",
425+"openclaw",
426+"tasks",
427+"--json",
428+"--runtime",
429+"cli",
430+"--status",
431+"running",
432+];
433+const separateValueRoute = findRoutedCommand(["tasks", "cli"], separateValueArgv);
434+expect(separateValueRoute).not.toBeNull();
435+await expect(separateValueRoute?.run(separateValueArgv)).resolves.toBe(true);
436+expect(tasksListJsonCommandMock).toHaveBeenCalledWith(
437+{ json: true, runtime: "cli", status: "running" },
438+expect.any(Object),
439+);
440+441+const parentOptionBeforeSubcommandArgv = [
442+"node",
443+"openclaw",
444+"tasks",
445+"--runtime",
446+"cli",
447+"list",
448+"--json",
449+];
450+const parentOptionBeforeSubcommandRoute = findRoutedCommand(
451+["tasks", "cli"],
452+parentOptionBeforeSubcommandArgv,
453+);
454+expect(parentOptionBeforeSubcommandRoute).not.toBeNull();
455+await expect(
456+parentOptionBeforeSubcommandRoute?.run(parentOptionBeforeSubcommandArgv),
457+).resolves.toBe(true);
458+expect(tasksListJsonCommandMock).toHaveBeenLastCalledWith(
459+{ json: true, runtime: "cli", status: undefined },
460+expect.any(Object),
461+);
462+});
463+464+it("routes tasks audit JSON through the lean task JSON command", async () => {
465+const route = expectRoute(["tasks", "audit"]);
466+expect(route?.loadPlugins).toBeUndefined();
467+expect(route?.canRun?.(["node", "openclaw", "tasks", "audit"])).toBe(false);
468+await expect(
469+route?.run([
470+"node",
471+"openclaw",
472+"tasks",
473+"audit",
474+"--json",
475+"--severity",
476+"error",
477+"--code=stale_running",
478+"--limit",
479+"5",
480+]),
481+).resolves.toBe(true);
482+expect(tasksAuditJsonCommandMock).toHaveBeenCalledWith(
483+{ json: true, severity: "error", code: "stale_running", limit: 5 },
484+expect.any(Object),
485+);
486+});
487+488+it("returns false for task JSON routes when option values are missing or unknown", async () => {
489+await expectRunFalse(["tasks"], ["node", "openclaw", "tasks", "--json", "--runtime"]);
490+await expectRunFalse(["tasks", "list"], ["node", "openclaw", "tasks", "list"]);
491+await expectRunFalse(
492+["tasks", "audit"],
493+["node", "openclaw", "tasks", "audit", "--json", "--limit"],
494+);
495+await expectRunFalse(
496+["tasks", "audit"],
497+["node", "openclaw", "tasks", "audit", "--json", "--unknown"],
498+);
499+expect(
500+findRoutedCommand(["tasks", "cli"], ["node", "openclaw", "tasks", "--runtime", "cli"]),
501+).toBeNull();
502+});
379503});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。