



















@@ -127,20 +127,17 @@ describe("agents delete command", () => {
127127128128await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
129129130-expect(gatewayMocks.callGateway).toHaveBeenCalledWith(
131-expect.objectContaining({
132-method: "agents.delete",
133-params: { agentId: "ops", deleteFiles: true },
134-requiredMethods: ["agents.delete"],
135-}),
136-);
130+expect(gatewayMocks.callGateway).toHaveBeenCalledOnce();
131+const gatewayCall = gatewayMocks.callGateway.mock.calls[0]?.[0];
132+expect(gatewayCall?.method).toBe("agents.delete");
133+expect(gatewayCall?.params).toEqual({ agentId: "ops", deleteFiles: true });
134+expect(gatewayCall?.requiredMethods).toEqual(["agents.delete"]);
137135expect(configMocks.replaceConfigFile).not.toHaveBeenCalled();
138136expectSessionStore(storePath, sessions);
139-expect(readJsonLogs()[0]).toMatchObject({
140-agentId: "ops",
141-removedBindings: 0,
142-transport: "gateway",
143-});
137+const output = readJsonLogs()[0];
138+expect(output?.agentId).toBe("ops");
139+expect(output?.removedBindings).toBe(0);
140+expect(output?.transport).toBe("gateway");
144141});
145142});
146143@@ -168,13 +165,13 @@ describe("agents delete command", () => {
168165await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
169166170167expect(runtime.exit).not.toHaveBeenCalled();
171-expect(configMocks.replaceConfigFile).toHaveBeenCalledWith(
172- expect.objectContaining({
173- nextConfig: {
174- agents: { list: [{ id: "main", workspace: path.join(stateDir, "workspace-main") }] },
175- },
176-}),
177-);
168+expect(configMocks.replaceConfigFile).toHaveBeenCalledOnce();
169+const replaceConfigFileCalls = configMocks.replaceConfigFile.mock.calls as unknown as Array<
170+[{ nextConfig: OpenClawConfig }]
171+>;
172+expect(replaceConfigFileCalls[0]?.[0].nextConfig).toEqual({
173+agents: { list: [{ id: "main", workspace: path.join(stateDir, "workspace-main") }] },
174+});
178175expectSessionStore(storePath, {
179176"agent:main:main": { sessionId: "sess-main", updatedAt: now + 3 },
180177});
@@ -282,11 +279,9 @@ describe("agents delete command", () => {
282279// The JSON output should report why the workspace was retained.
283280const jsonOutput = readJsonLogs();
284281expect(jsonOutput).toHaveLength(1);
285-expect(jsonOutput[0]).toMatchObject({
286-workspaceRetained: true,
287-workspaceRetainedReason: "shared",
288-workspaceSharedWith: ["main"],
289-});
282+expect(jsonOutput[0]?.workspaceRetained).toBe(true);
283+expect(jsonOutput[0]?.workspaceRetainedReason).toBe("shared");
284+expect(jsonOutput[0]?.workspaceSharedWith).toEqual(["main"]);
290285expect(processMocks.runCommandWithTimeout).not.toHaveBeenCalledWith(
291286["trash", sharedWorkspace],
292287{ timeoutMs: 5000 },
@@ -321,10 +316,9 @@ describe("agents delete command", () => {
321316322317await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
323318324-expect(readJsonLogs()[0]).toMatchObject({
325-workspaceRetained: true,
326-workspaceSharedWith: ["main"],
327-});
319+const output = readJsonLogs()[0];
320+expect(output?.workspaceRetained).toBe(true);
321+expect(output?.workspaceSharedWith).toEqual(["main"]);
328322expect(processMocks.runCommandWithTimeout).not.toHaveBeenCalledWith(
329323["trash", childWorkspace],
330324{ timeoutMs: 5000 },
@@ -359,10 +353,9 @@ describe("agents delete command", () => {
359353360354await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
361355362-expect(readJsonLogs()[0]).toMatchObject({
363-workspaceRetained: true,
364-workspaceSharedWith: ["main"],
365-});
356+const output = readJsonLogs()[0];
357+expect(output?.workspaceRetained).toBe(true);
358+expect(output?.workspaceSharedWith).toEqual(["main"]);
366359expect(processMocks.runCommandWithTimeout).not.toHaveBeenCalledWith(
367360["trash", sharedWorkspace],
368361{ timeoutMs: 5000 },
@@ -400,10 +393,9 @@ describe("agents delete command", () => {
400393401394await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
402395403-expect(readJsonLogs()[0]).toMatchObject({
404-workspaceRetained: true,
405-workspaceSharedWith: ["main"],
406-});
396+const output = readJsonLogs()[0];
397+expect(output?.workspaceRetained).toBe(true);
398+expect(output?.workspaceSharedWith).toEqual(["main"]);
407399expect(processMocks.runCommandWithTimeout).not.toHaveBeenCalledWith(
408400["trash", aliasWorkspace],
409401{ timeoutMs: 5000 },
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。