fix(routing): make bindings dynamic by calling loadConfig() per-message (#11372)

This commit is contained in:
juanpablodlc
2026-02-08 22:34:55 -08:00
committed by GitHub
parent 0cf93b8fa7
commit 8d96955e19
6 changed files with 22 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ const updateLastRouteMock = vi.fn();
const dispatchMock = vi.fn();
const readAllowFromStoreMock = vi.fn();
const upsertPairingRequestMock = vi.fn();
const loadConfigMock = vi.fn();
vi.mock("./send.js", () => ({
sendMessageDiscord: (...args: unknown[]) => sendMock(...args),
@@ -30,6 +31,13 @@ vi.mock("../pairing/pairing-store.js", () => ({
readChannelAllowFromStore: (...args: unknown[]) => readAllowFromStoreMock(...args),
upsertChannelPairingRequest: (...args: unknown[]) => upsertPairingRequestMock(...args),
}));
vi.mock("../config/config.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../config/config.js")>();
return {
...actual,
loadConfig: (...args: unknown[]) => loadConfigMock(...args),
};
});
vi.mock("../config/sessions.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("../config/sessions.js")>();
return {
@@ -50,6 +58,7 @@ beforeEach(() => {
});
readAllowFromStoreMock.mockReset().mockResolvedValue([]);
upsertPairingRequestMock.mockReset().mockResolvedValue({ code: "PAIRCODE", created: true });
loadConfigMock.mockReset().mockReturnValue({});
__resetDiscordChannelInfoCacheForTest();
});
@@ -685,6 +694,7 @@ describe("discord tool result dispatch", () => {
},
bindings: [{ agentId: "support", match: { channel: "discord", guildId: "g1" } }],
} as ReturnType<typeof import("../config/config.js").loadConfig>;
loadConfigMock.mockReturnValue(cfg);
const handler = createDiscordMessageHandler({
cfg,

View File

@@ -17,6 +17,7 @@ import { formatAllowlistMatchMeta } from "../../channels/allowlist-match.js";
import { resolveControlCommandGate } from "../../channels/command-gating.js";
import { logInboundDrop } from "../../channels/logging.js";
import { resolveMentionGatingWithBypass } from "../../channels/mention-gating.js";
import { loadConfig } from "../../config/config.js";
import { logVerbose, shouldLogVerbose } from "../../globals.js";
import { recordChannelActivity } from "../../infra/channel-activity.js";
import { enqueueSystemEvent } from "../../infra/system-events.js";
@@ -218,8 +219,9 @@ export async function preflightDiscordMessage(
earlyThreadParentType = parentInfo.type;
}
// Fresh config for bindings lookup; other routing inputs are payload-derived.
const route = resolveAgentRoute({
cfg: params.cfg,
cfg: loadConfig(),
channel: "discord",
accountId: params.accountId,
guildId: params.data.guild_id ?? undefined,