diff --git a/src/auto-reply/reply/commands-info.test.ts b/src/auto-reply/reply/commands-info.test.ts index 5f64e8682a4..85d3a0dfa23 100644 --- a/src/auto-reply/reply/commands-info.test.ts +++ b/src/auto-reply/reply/commands-info.test.ts @@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../../config/config.js"; import type { MsgContext } from "../templating.js"; import { handleContextCommand } from "./commands-context-command.js"; +import { handleStatusCommand } from "./commands-info.js"; +import { buildStatusReply } from "./commands-status.js"; import type { HandleCommandsParams } from "./commands-types.js"; import { handleWhoamiCommand } from "./commands-whoami.js"; @@ -11,6 +13,10 @@ vi.mock("./commands-context-report.js", () => ({ buildContextReply: buildContextReplyMock, })); +vi.mock("./commands-status.js", () => ({ + buildStatusReply: vi.fn(async () => ({ text: "status reply" })), +})); + function buildInfoParams( commandBodyNormalized: string, cfg: OpenClawConfig, @@ -134,4 +140,32 @@ describe("info command handlers", () => { } } }); + + it("prefers the persisted session parent when routing /status context", async () => { + const params = buildInfoParams( + "/status", + { + commands: { text: true }, + channels: { whatsapp: { allowFrom: ["*"] } }, + } as OpenClawConfig, + { + ParentSessionKey: undefined, + }, + ); + params.sessionEntry = { + sessionId: "session-1", + updatedAt: Date.now(), + parentSessionKey: "discord:group:parent-room", + } as HandleCommandsParams["sessionEntry"]; + + const statusResult = await handleStatusCommand(params, true); + + expect(statusResult?.shouldContinue).toBe(false); + + expect(vi.mocked(buildStatusReply)).toHaveBeenCalledWith( + expect.objectContaining({ + parentSessionKey: "discord:group:parent-room", + }), + ); + }); }); diff --git a/src/auto-reply/reply/commands-info.ts b/src/auto-reply/reply/commands-info.ts index b5d1ecb963f..53ed76708af 100644 --- a/src/auto-reply/reply/commands-info.ts +++ b/src/auto-reply/reply/commands-info.ts @@ -189,7 +189,7 @@ export const handleStatusCommand: CommandHandler = async (params, allowTextComma command: params.command, sessionEntry: params.sessionEntry, sessionKey: params.sessionKey, - parentSessionKey: params.ctx.ParentSessionKey, + parentSessionKey: params.sessionEntry?.parentSessionKey ?? params.ctx.ParentSessionKey, sessionScope: params.sessionScope, provider: params.provider, model: params.model,