From 429a6a8cc9527f976faa032f8ca317384f60ca23 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 11 May 2026 03:36:18 +0100 Subject: [PATCH] test: tighten slash command steer assertions --- .../chat/slash-command-executor.node.test.ts | 91 +++++++++---------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/ui/src/ui/chat/slash-command-executor.node.test.ts b/ui/src/ui/chat/slash-command-executor.node.test.ts index c1e002df3a4..8ce9efa44a5 100644 --- a/ui/src/ui/chat/slash-command-executor.node.test.ts +++ b/ui/src/ui/chat/slash-command-executor.node.test.ts @@ -20,6 +20,21 @@ function row(key: string, overrides?: Partial): GatewaySessio }; } +function requireRequestCall( + request: ReturnType, + method: string, +): { method: string; payload: Record } { + const call = request.mock.calls.find(([calledMethod]) => calledMethod === method); + if (!call) { + throw new Error(`expected ${method} request`); + } + return { method: call[0] as string, payload: call[1] as Record }; +} + +function expectNoRequestCall(request: ReturnType, method: string) { + expect(request.mock.calls.some(([calledMethod]) => calledMethod === method)).toBe(false); +} + describe("executeSlashCommand /kill", () => { it("aborts every sub-agent session for /kill all", async () => { const request = vi.fn(async (method: string, _payload?: unknown) => { @@ -970,14 +985,10 @@ describe("executeSlashCommand /steer (soft inject)", () => { ); expect(result.content).toBe("Steered."); - expect(request).toHaveBeenCalledWith( - "chat.send", - expect.objectContaining({ - sessionKey: "agent:main:main", - message: "try a different approach", - deliver: false, - }), - ); + const chatSend = requireRequestCall(request, "chat.send"); + expect(chatSend.payload.sessionKey).toBe("agent:main:main"); + expect(chatSend.payload.message).toBe("try a different approach"); + expect(chatSend.payload.deliver).toBe(false); }); it("injects into a matching subagent when the first word resolves to one", async () => { @@ -1007,14 +1018,10 @@ describe("executeSlashCommand /steer (soft inject)", () => { ); expect(result.content).toBe("Steered `researcher`."); - expect(request).toHaveBeenCalledWith( - "chat.send", - expect.objectContaining({ - sessionKey: "agent:main:subagent:researcher", - message: "try a different approach", - deliver: false, - }), - ); + const chatSend = requireRequestCall(request, "chat.send"); + expect(chatSend.payload.sessionKey).toBe("agent:main:subagent:researcher"); + expect(chatSend.payload.message).toBe("try a different approach"); + expect(chatSend.payload.deliver).toBe(false); }); it("uses cached sessions to avoid an extra sessions.list round trip", async () => { @@ -1045,14 +1052,10 @@ describe("executeSlashCommand /steer (soft inject)", () => { expect(result.content).toBe("Steered `researcher`."); expect(request).toHaveBeenCalledTimes(1); - expect(request).toHaveBeenCalledWith( - "chat.send", - expect.objectContaining({ - sessionKey: "agent:main:subagent:researcher", - message: "try a different approach", - deliver: false, - }), - ); + const chatSend = requireRequestCall(request, "chat.send"); + expect(chatSend.payload.sessionKey).toBe("agent:main:subagent:researcher"); + expect(chatSend.payload.message).toBe("try a different approach"); + expect(chatSend.payload.deliver).toBe(false); }); it("matches an explicit full subagent session key", async () => { @@ -1082,14 +1085,10 @@ describe("executeSlashCommand /steer (soft inject)", () => { ); expect(result.content).toBe("Steered `agent:main:subagent:researcher`."); - expect(request).toHaveBeenCalledWith( - "chat.send", - expect.objectContaining({ - sessionKey: "agent:main:subagent:researcher", - message: "try a different approach", - deliver: false, - }), - ); + const chatSend = requireRequestCall(request, "chat.send"); + expect(chatSend.payload.sessionKey).toBe("agent:main:subagent:researcher"); + expect(chatSend.payload.message).toBe("try a different approach"); + expect(chatSend.payload.deliver).toBe(false); }); it("does not treat 'all' as a subagent wildcard", async () => { @@ -1111,14 +1110,10 @@ describe("executeSlashCommand /steer (soft inject)", () => { ); expect(result.content).toBe("Steered."); - expect(request).toHaveBeenCalledWith( - "chat.send", - expect.objectContaining({ - sessionKey: "agent:main:main", - message: "all good now", - deliver: false, - }), - ); + const chatSend = requireRequestCall(request, "chat.send"); + expect(chatSend.payload.sessionKey).toBe("agent:main:main"); + expect(chatSend.payload.message).toBe("all good now"); + expect(chatSend.payload.deliver).toBe(false); }); it("does not match agent id as target — treats 'main' as message text", async () => { @@ -1145,14 +1140,10 @@ describe("executeSlashCommand /steer (soft inject)", () => { ); expect(result.content).toBe("Steered."); - expect(request).toHaveBeenCalledWith( - "chat.send", - expect.objectContaining({ - sessionKey: "agent:main:main", - message: "main refine the plan", - deliver: false, - }), - ); + const chatSend = requireRequestCall(request, "chat.send"); + expect(chatSend.payload.sessionKey).toBe("agent:main:main"); + expect(chatSend.payload.message).toBe("main refine the plan"); + expect(chatSend.payload.deliver).toBe(false); }); it("keeps ended subagent targets so steer does not fall back to the current session", async () => { @@ -1183,7 +1174,7 @@ describe("executeSlashCommand /steer (soft inject)", () => { expect(result.content).toBe("No active run matched `researcher`. Use `/redirect` instead."); expect(request).toHaveBeenCalledWith("sessions.list", {}); - expect(request).not.toHaveBeenCalledWith("chat.send", expect.anything()); + expectNoRequestCall(request, "chat.send"); }); it("returns a no-op summary when the current session has no active run", async () => { @@ -1203,7 +1194,7 @@ describe("executeSlashCommand /steer (soft inject)", () => { expect(result.content).toBe("No active run. Use the chat input or `/redirect` instead."); expect(request).toHaveBeenCalledWith("sessions.list", {}); - expect(request).not.toHaveBeenCalledWith("chat.send", expect.anything()); + expectNoRequestCall(request, "chat.send"); }); it("returns steer usage when no message is provided", async () => {