Skip to content

Commit 08e4e88

Browse files
committed
fix(gateway): preserve auto-enabled message action fallback
1 parent d346f20 commit 08e4e88

2 files changed

Lines changed: 31 additions & 23 deletions

File tree

src/gateway/server-methods/send.test.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ describe("gateway send mirroring", () => {
469469
expect(response?.[0]).toBe(true);
470470
});
471471

472-
it("keeps the request context config for message.action when the active snapshot source does not match", async () => {
473-
const contextConfig = {
472+
it("keeps the post-auto-enable request config for message.action when the active snapshot source does not match", async () => {
473+
const sourceConfig = {
474474
channels: {
475475
discord: {
476476
accounts: {
@@ -485,11 +485,28 @@ describe("gateway send mirroring", () => {
485485
},
486486
},
487487
};
488-
mocks.applyPluginAutoEnable.mockImplementation(() => ({
489-
config: contextConfig,
490-
changes: [],
488+
const autoEnabledRequestConfig = {
489+
channels: {
490+
discord: {
491+
enabled: true,
492+
accounts: {
493+
drclaw: {
494+
token: {
495+
source: "env",
496+
provider: "default",
497+
id: "DISCORD_BOT_TOKEN_DRCLAW",
498+
},
499+
},
500+
},
501+
},
502+
},
503+
plugins: { allow: ["discord"] },
504+
};
505+
mocks.applyPluginAutoEnable.mockReturnValue({
506+
config: autoEnabledRequestConfig,
507+
changes: [{ path: "channels.discord.enabled", value: true }],
491508
autoEnabledReasons: {},
492-
}));
509+
});
493510
mocks.getActiveSecretsRuntimeConfigSnapshot.mockReturnValue({
494511
config: {
495512
channels: {
@@ -513,7 +530,7 @@ describe("gateway send mirroring", () => {
513530

514531
const context = {
515532
...makeContext(),
516-
getRuntimeConfig: () => contextConfig,
533+
getRuntimeConfig: () => sourceConfig,
517534
} as unknown as GatewayRequestContext;
518535
await sendHandlers["message.action"]({
519536
params: {
@@ -529,7 +546,7 @@ describe("gateway send mirroring", () => {
529546
isWebchatConnect: () => false,
530547
});
531548

532-
expect(lastDispatchChannelMessageActionCall()?.cfg).toBe(contextConfig);
549+
expect(lastDispatchChannelMessageActionCall()?.cfg).toBe(autoEnabledRequestConfig);
533550
});
534551

535552
it("does not read the active secrets runtime config snapshot for send requests", async () => {

src/gateway/server-methods/send.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,18 @@ function resolveMessageActionRuntimeConfig(params: {
188188
if (!activeRuntime) {
189189
return params.cfg;
190190
}
191-
const selected =
192-
selectApplicableRuntimeConfig({
193-
inputConfig: params.sourceCfg,
194-
runtimeConfig: activeRuntime.config,
195-
runtimeSourceConfig: activeRuntime.sourceConfig,
196-
}) ??
197-
selectApplicableRuntimeConfig({
198-
inputConfig: params.cfg,
199-
runtimeConfig: activeRuntime.config,
200-
runtimeSourceConfig: activeRuntime.sourceConfig,
201-
});
202-
if (!selected) {
203-
return params.cfg;
204-
}
191+
const selected = selectApplicableRuntimeConfig({
192+
inputConfig: params.sourceCfg,
193+
runtimeConfig: activeRuntime.config,
194+
runtimeSourceConfig: activeRuntime.sourceConfig,
195+
});
205196
if (selected === activeRuntime.config && selected !== params.cfg) {
206197
return applyPluginAutoEnable({
207198
config: selected,
208199
env: process.env,
209200
}).config;
210201
}
211-
return selected;
202+
return params.cfg;
212203
}
213204

214205
function buildGatewayDeliveryPayload(params: {

0 commit comments

Comments
 (0)