From 013e1ac72f1bd3b20d596da464ca116f05c7b3f3 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Fri, 8 May 2026 17:08:51 +0530 Subject: [PATCH] test(reply): cover native slash fast path --- .../reply/get-reply.fast-path.test.ts | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/auto-reply/reply/get-reply.fast-path.test.ts b/src/auto-reply/reply/get-reply.fast-path.test.ts index 069961e2687..dce4d111db6 100644 --- a/src/auto-reply/reply/get-reply.fast-path.test.ts +++ b/src/auto-reply/reply/get-reply.fast-path.test.ts @@ -130,6 +130,86 @@ describe("getReplyFromConfig fast test bootstrap", () => { expect(vi.mocked(runPreparedReplyMock)).toHaveBeenCalledOnce(); }); + it("handles native /status before workspace bootstrap", async () => { + const home = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-native-status-fast-")); + const targetSessionKey = "agent:main:telegram:123"; + const cfg = markCompleteReplyConfig({ + agents: { + defaults: { + model: "openai/gpt-5.5", + workspace: path.join(home, "workspace"), + }, + }, + session: { store: path.join(home, "sessions.json") }, + } as OpenClawConfig); + + const reply = await getReplyFromConfig( + buildGetReplyCtx({ + Body: "/status", + BodyForAgent: "/status", + RawBody: "/status", + CommandBody: "/status", + CommandSource: "native", + CommandAuthorized: true, + SessionKey: "telegram:slash:123", + CommandTargetSessionKey: targetSessionKey, + }), + undefined, + cfg, + ); + + expect(reply).toEqual(expect.objectContaining({ text: expect.stringContaining("OpenClaw") })); + expect(mocks.ensureAgentWorkspace).not.toHaveBeenCalled(); + expect(mocks.initSessionState).not.toHaveBeenCalled(); + expect(mocks.resolveReplyDirectives).not.toHaveBeenCalled(); + expect(vi.mocked(runPreparedReplyMock)).not.toHaveBeenCalled(); + }); + + it("handles native slash directives before workspace bootstrap", async () => { + const home = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-native-slash-fast-")); + const targetSessionKey = "agent:main:telegram:123"; + const cfg = markCompleteReplyConfig({ + agents: { + defaults: { + model: "anthropic/claude-opus-4-6", + workspace: path.join(home, "workspace"), + }, + }, + session: { store: path.join(home, "sessions.json") }, + } as OpenClawConfig); + mocks.resolveReplyDirectives.mockResolvedValueOnce({ + kind: "reply", + reply: { text: "model status" }, + }); + + await expect( + getReplyFromConfig( + buildGetReplyCtx({ + Body: "/model status", + BodyForAgent: "/model status", + RawBody: "/model status", + CommandBody: "/model status", + CommandSource: "native", + CommandAuthorized: true, + SessionKey: "telegram:slash:123", + CommandTargetSessionKey: targetSessionKey, + }), + undefined, + cfg, + ), + ).resolves.toEqual({ text: "model status" }); + + expect(mocks.ensureAgentWorkspace).not.toHaveBeenCalled(); + expect(mocks.initSessionState).not.toHaveBeenCalled(); + expect(vi.mocked(runPreparedReplyMock)).not.toHaveBeenCalled(); + expect(mocks.resolveReplyDirectives).toHaveBeenCalledWith( + expect.objectContaining({ + sessionKey: targetSessionKey, + workspaceDir: expect.any(String), + }), + ); + }); + it("uses native command target session keys during fast bootstrap", () => { const result = initFastReplySessionState({ ctx: buildGetReplyCtx({