test(reply): cover native slash fast path

This commit is contained in:
Ayaan Zaidi
2026-05-08 17:08:51 +05:30
parent ba91d477a2
commit 013e1ac72f

View File

@@ -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({