fix(acp): guard missing delivery channel config

This commit is contained in:
Peter Steinberger
2026-04-05 14:23:47 +01:00
parent 2780980a28
commit d842251ef8
2 changed files with 29 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import { createAcpDispatchDeliveryCoordinator } from "./dispatch-acp-delivery.js";
import type { ReplyDispatcher } from "./reply-dispatcher.js";
import { buildTestCtx } from "./test-ctx.js";
@@ -273,4 +274,30 @@ describe("createAcpDispatchDeliveryCoordinator", () => {
}),
);
});
it("routes ACP replies when cfg.channels is missing", async () => {
const coordinator = createAcpDispatchDeliveryCoordinator({
cfg: {} as OpenClawConfig,
ctx: buildTestCtx({
Provider: "discord",
Surface: "discord",
SessionKey: "agent:codex-acp:session-1",
}),
dispatcher: createDispatcher(),
inboundAudio: false,
shouldRouteToOriginating: true,
originatingChannel: "discord",
originatingTo: "channel:thread-1",
});
await coordinator.deliver("block", { text: "hello" }, { skipTts: true });
expect(deliveryMocks.routeReply).toHaveBeenCalledWith(
expect.objectContaining({
channel: "discord",
to: "channel:thread-1",
accountId: undefined,
}),
);
});
});

View File

@@ -43,8 +43,8 @@ function resolveDeliveryAccountId(params: {
return undefined;
}
const channelCfg = (
params.cfg.channels as Record<string, { defaultAccount?: unknown } | undefined>
)[channelId];
params.cfg.channels as Record<string, { defaultAccount?: unknown } | undefined> | undefined
)?.[channelId];
const configuredDefault = channelCfg?.defaultAccount;
return typeof configuredDefault === "string" && configuredDefault.trim()
? configuredDefault.trim()