


























@@ -46,6 +46,27 @@ const flowsCancelCommand = mocks.flowsCancelCommand;
4646const setVerbose = mocks.setVerbose;
4747const runtime = mocks.runtime;
484849+type MockCalls = {
50+mock: { calls: unknown[][] };
51+};
52+53+function requireRecord(value: unknown, label: string): Record<string, unknown> {
54+expect(typeof value, label).toBe("object");
55+expect(value, label).not.toBeNull();
56+return value as Record<string, unknown>;
57+}
58+59+function expectCommandOptions(command: MockCalls, expected: Record<string, unknown>) {
60+expect(command.mock.calls).toHaveLength(1);
61+const [options, actualRuntime] = command.mock.calls[0] ?? [];
62+expect(actualRuntime).toBe(runtime);
63+const optionsRecord = requireRecord(options, "command options");
64+for (const [key, value] of Object.entries(expected)) {
65+expect(optionsRecord[key], key).toEqual(value);
66+}
67+return optionsRecord;
68+}
69+4970vi.mock("../../commands/status.js", () => ({
5071statusCommand: mocks.statusCommand,
5172}));
@@ -135,17 +156,14 @@ describe("registerStatusHealthSessionsCommands", () => {
135156]);
136157137158expect(setVerbose).toHaveBeenCalledWith(true);
138-expect(statusCommand).toHaveBeenCalledWith(
139-expect.objectContaining({
140-json: true,
141-all: true,
142-deep: true,
143-usage: true,
144-timeoutMs: 5000,
145-verbose: true,
146-}),
147-runtime,
148-);
159+expectCommandOptions(statusCommand, {
160+json: true,
161+all: true,
162+deep: true,
163+usage: true,
164+timeoutMs: 5000,
165+verbose: true,
166+});
149167});
150168151169it("rejects invalid status timeout without calling status command", async () => {
@@ -162,14 +180,11 @@ describe("registerStatusHealthSessionsCommands", () => {
162180await runCli(["health", "--json", "--timeout", "2500", "--verbose"]);
163181164182expect(setVerbose).toHaveBeenCalledWith(true);
165-expect(healthCommand).toHaveBeenCalledWith(
166-expect.objectContaining({
167-json: true,
168-timeoutMs: 2500,
169-verbose: true,
170-}),
171-runtime,
172-);
183+expectCommandOptions(healthCommand, {
184+json: true,
185+timeoutMs: 2500,
186+verbose: true,
187+});
173188});
174189175190it("rejects invalid health timeout without calling health command", async () => {
@@ -196,38 +211,29 @@ describe("registerStatusHealthSessionsCommands", () => {
196211]);
197212198213expect(setVerbose).toHaveBeenCalledWith(true);
199-expect(sessionsCommand).toHaveBeenCalledWith(
200-expect.objectContaining({
201-json: true,
202-store: "/tmp/sessions.json",
203-active: "120",
204-limit: "25",
205-}),
206-runtime,
207-);
214+expectCommandOptions(sessionsCommand, {
215+json: true,
216+store: "/tmp/sessions.json",
217+active: "120",
218+limit: "25",
219+});
208220});
209221210222it("runs sessions command with --agent forwarding", async () => {
211223await runCli(["sessions", "--agent", "work"]);
212224213-expect(sessionsCommand).toHaveBeenCalledWith(
214-expect.objectContaining({
215-agent: "work",
216-allAgents: false,
217-}),
218-runtime,
219-);
225+expectCommandOptions(sessionsCommand, {
226+agent: "work",
227+allAgents: false,
228+});
220229});
221230222231it("runs sessions command with --all-agents forwarding", async () => {
223232await runCli(["sessions", "--all-agents"]);
224233225-expect(sessionsCommand).toHaveBeenCalledWith(
226-expect.objectContaining({
227-allAgents: true,
228-}),
229-runtime,
230-);
234+expectCommandOptions(sessionsCommand, {
235+allAgents: true,
236+});
231237});
232238233239it("runs sessions cleanup subcommand with forwarded options", async () => {
@@ -245,31 +251,25 @@ describe("registerStatusHealthSessionsCommands", () => {
245251"--json",
246252]);
247253248-expect(sessionsCleanupCommand).toHaveBeenCalledWith(
249-expect.objectContaining({
250-store: "/tmp/sessions.json",
251-agent: undefined,
252-allAgents: false,
253-dryRun: true,
254-enforce: true,
255-fixMissing: true,
256-fixDmScope: true,
257-activeKey: "agent:main:main",
258-json: true,
259-}),
260-runtime,
261-);
254+expectCommandOptions(sessionsCleanupCommand, {
255+store: "/tmp/sessions.json",
256+agent: undefined,
257+allAgents: false,
258+dryRun: true,
259+enforce: true,
260+fixMissing: true,
261+fixDmScope: true,
262+activeKey: "agent:main:main",
263+json: true,
264+});
262265});
263266264267it("forwards parent-level all-agents to cleanup subcommand", async () => {
265268await runCli(["sessions", "--all-agents", "cleanup", "--dry-run"]);
266269267-expect(sessionsCleanupCommand).toHaveBeenCalledWith(
268-expect.objectContaining({
269-allAgents: true,
270-}),
271-runtime,
272-);
270+expectCommandOptions(sessionsCleanupCommand, {
271+allAgents: true,
272+});
273273});
274274275275it("runs sessions export-trajectory with owner-routable export options", async () => {
@@ -287,16 +287,13 @@ describe("registerStatusHealthSessionsCommands", () => {
287287"--json",
288288]);
289289290-expect(exportTrajectoryCommand).toHaveBeenCalledWith(
291-expect.objectContaining({
292-sessionKey: "agent:main:telegram:direct:owner",
293-output: "bug-123",
294-workspace: "/workspace",
295-store: "/tmp/sessions.json",
296-json: true,
297-}),
298-runtime,
299-);
290+expectCommandOptions(exportTrajectoryCommand, {
291+sessionKey: "agent:main:telegram:direct:owner",
292+output: "bug-123",
293+workspace: "/workspace",
294+store: "/tmp/sessions.json",
295+json: true,
296+});
300297});
301298302299it("forwards encoded sessions export-trajectory requests", async () => {
@@ -308,50 +305,38 @@ describe("registerStatusHealthSessionsCommands", () => {
308305"--json",
309306]);
310307311-expect(exportTrajectoryCommand).toHaveBeenCalledWith(
312-expect.objectContaining({
313-requestJsonBase64: "eyJzZXNzaW9uS2V5IjoiYWdlbnQ6bWFpbjp0ZWxlZ3JhbTpkaXJlY3Q6b3duZXIifQ",
314-json: true,
315-}),
316-runtime,
317-);
308+expectCommandOptions(exportTrajectoryCommand, {
309+requestJsonBase64: "eyJzZXNzaW9uS2V5IjoiYWdlbnQ6bWFpbjp0ZWxlZ3JhbTpkaXJlY3Q6b3duZXIifQ",
310+json: true,
311+});
318312});
319313320314it("runs tasks list from the parent command", async () => {
321315await runCli(["tasks", "--json", "--runtime", "acp", "--status", "running"]);
322316323-expect(tasksListCommand).toHaveBeenCalledWith(
324-expect.objectContaining({
325-json: true,
326-runtime: "acp",
327-status: "running",
328-}),
329-runtime,
330-);
317+expectCommandOptions(tasksListCommand, {
318+json: true,
319+runtime: "acp",
320+status: "running",
321+});
331322});
332323333324it("runs tasks show subcommand with lookup forwarding", async () => {
334325await runCli(["tasks", "show", "run-123", "--json"]);
335326336-expect(tasksShowCommand).toHaveBeenCalledWith(
337-expect.objectContaining({
338-lookup: "run-123",
339-json: true,
340-}),
341-runtime,
342-);
327+expectCommandOptions(tasksShowCommand, {
328+lookup: "run-123",
329+json: true,
330+});
343331});
344332345333it("runs tasks maintenance subcommand with apply forwarding", async () => {
346334await runCli(["tasks", "--json", "maintenance", "--apply"]);
347335348-expect(tasksMaintenanceCommand).toHaveBeenCalledWith(
349-expect.objectContaining({
350-json: true,
351-apply: true,
352-}),
353-runtime,
354-);
336+expectCommandOptions(tasksMaintenanceCommand, {
337+json: true,
338+apply: true,
339+});
355340});
356341357342it("runs tasks audit subcommand with filters", async () => {
@@ -367,84 +352,63 @@ describe("registerStatusHealthSessionsCommands", () => {
367352"5",
368353]);
369354370-expect(tasksAuditCommand).toHaveBeenCalledWith(
371-expect.objectContaining({
372-json: true,
373-severity: "error",
374-code: "stale_running",
375-limit: 5,
376-}),
377-runtime,
378-);
355+expectCommandOptions(tasksAuditCommand, {
356+json: true,
357+severity: "error",
358+code: "stale_running",
359+limit: 5,
360+});
379361});
380362381363it("routes tasks flow commands through the TaskFlow handlers", async () => {
382364await runCli(["tasks", "flow", "list", "--json", "--status", "blocked"]);
383-expect(flowsListCommand).toHaveBeenCalledWith(expect.any(Object), runtime);
365+expectCommandOptions(flowsListCommand, {});
384366385367await runCli(["tasks", "flow", "show", "flow-123", "--json"]);
386-expect(flowsShowCommand).toHaveBeenCalledWith(
387-expect.objectContaining({
388-lookup: "flow-123",
389-}),
390-runtime,
391-);
368+expectCommandOptions(flowsShowCommand, {
369+lookup: "flow-123",
370+});
392371393372await runCli(["tasks", "flow", "cancel", "flow-123"]);
394-expect(flowsCancelCommand).toHaveBeenCalledWith(
395-expect.objectContaining({
396-lookup: "flow-123",
397-}),
398-runtime,
399-);
373+expectCommandOptions(flowsCancelCommand, {
374+lookup: "flow-123",
375+});
400376});
401377402378it("runs tasks notify subcommand with lookup and policy forwarding", async () => {
403379await runCli(["tasks", "notify", "run-123", "state_changes"]);
404380405-expect(tasksNotifyCommand).toHaveBeenCalledWith(
406-expect.objectContaining({
407-lookup: "run-123",
408-notify: "state_changes",
409-}),
410-runtime,
411-);
381+expectCommandOptions(tasksNotifyCommand, {
382+lookup: "run-123",
383+notify: "state_changes",
384+});
412385});
413386414387it("runs tasks cancel subcommand with lookup forwarding", async () => {
415388await runCli(["tasks", "cancel", "run-123"]);
416389417-expect(tasksCancelCommand).toHaveBeenCalledWith(
418-expect.objectContaining({
419-lookup: "run-123",
420-}),
421-runtime,
422-);
390+expectCommandOptions(tasksCancelCommand, {
391+lookup: "run-123",
392+});
423393});
424394425395it("runs commitments list with filters", async () => {
426396await runCli(["commitments", "--json", "--agent", "work", "--status", "snoozed"]);
427397428-expect(commitmentsListCommand).toHaveBeenCalledWith(
429-expect.objectContaining({
430-json: true,
431-agent: "work",
432-status: "snoozed",
433-all: false,
434-}),
435-runtime,
436-);
398+expectCommandOptions(commitmentsListCommand, {
399+json: true,
400+agent: "work",
401+status: "snoozed",
402+all: false,
403+});
437404});
438405439406it("runs commitments dismiss with id forwarding", async () => {
440407await runCli(["commitments", "dismiss", "cm_1", "cm_2"]);
441408442-expect(commitmentsDismissCommand).toHaveBeenCalledWith(
443-expect.objectContaining({
444-ids: ["cm_1", "cm_2"],
445-}),
446-runtime,
447-);
409+expectCommandOptions(commitmentsDismissCommand, {
410+ids: ["cm_1", "cm_2"],
411+});
448412});
449413450414it("does not register the legacy top-level flows command", () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。