fix: pass agentDir to /compact command for agent-specific auth (#24133)

Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4bb10ca78c
Co-authored-by: Glucksberg <80581902+Glucksberg@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Glucksberg
2026-02-23 03:33:35 -04:00
committed by GitHub
parent 9ea740afb6
commit 36400df086
6 changed files with 85 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
import { describe, expect, it, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { TemplateContext } from "../templating.js";
import { clearInlineDirectives } from "./get-reply-directives-utils.js";
import { buildTestCtx } from "./test-ctx.js";
@@ -16,6 +16,10 @@ vi.mock("./commands.js", () => ({
const { handleInlineActions } = await import("./get-reply-inline-actions.js");
describe("handleInlineActions", () => {
beforeEach(() => {
handleCommandsMock.mockReset();
});
it("skips whatsapp replies when config is empty and From !== To", async () => {
const typing: TypingController = {
onReplyStart: async () => {},
@@ -81,4 +85,77 @@ describe("handleInlineActions", () => {
expect(typing.cleanup).toHaveBeenCalled();
expect(handleCommandsMock).not.toHaveBeenCalled();
});
it("forwards agentDir into handleCommands", async () => {
const typing: TypingController = {
onReplyStart: async () => {},
startTypingLoop: async () => {},
startTypingOnText: async () => {},
refreshTypingTtl: () => {},
isActive: () => false,
markRunComplete: () => {},
markDispatchIdle: () => {},
cleanup: vi.fn(),
};
handleCommandsMock.mockResolvedValue({ shouldContinue: false, reply: { text: "done" } });
const ctx = buildTestCtx({
Body: "/status",
CommandBody: "/status",
});
const agentDir = "/tmp/inline-agent";
const result = await handleInlineActions({
ctx,
sessionCtx: ctx as unknown as TemplateContext,
cfg: { commands: { text: true } },
agentId: "main",
agentDir,
sessionKey: "s:main",
workspaceDir: "/tmp",
isGroup: false,
typing,
allowTextCommands: false,
inlineStatusRequested: false,
command: {
surface: "whatsapp",
channel: "whatsapp",
channelId: "whatsapp",
ownerList: [],
senderIsOwner: false,
isAuthorizedSender: true,
senderId: "sender-1",
abortKey: "sender-1",
rawBodyNormalized: "/status",
commandBodyNormalized: "/status",
from: "whatsapp:+999",
to: "whatsapp:+999",
},
directives: clearInlineDirectives("/status"),
cleanedBody: "/status",
elevatedEnabled: false,
elevatedAllowed: false,
elevatedFailures: [],
defaultActivation: () => "always",
resolvedThinkLevel: undefined,
resolvedVerboseLevel: undefined,
resolvedReasoningLevel: "off",
resolvedElevatedLevel: "off",
resolveDefaultThinkingLevel: async () => "off",
provider: "openai",
model: "gpt-4o-mini",
contextTokens: 0,
abortedLastRun: false,
sessionScope: "per-sender",
});
expect(result).toEqual({ kind: "reply", reply: { text: "done" } });
expect(handleCommandsMock).toHaveBeenCalledTimes(1);
expect(handleCommandsMock).toHaveBeenCalledWith(
expect.objectContaining({
agentDir,
}),
);
});
});