fix(cli): preserve Discord voice outbound helper (#85529) · openclaw/openclaw@82cb02a
giodl73-repo
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -85,6 +85,15 @@ describe("createDefaultDeps", () => {
|
85 | 85 | expectUnusedRuntimeFactoriesNotLoaded("telegram"); |
86 | 86 | }); |
87 | 87 | |
| 88 | +it("does not create channel senders for Discord voice helper keys", async () => { |
| 89 | +const createDefaultDeps = await loadCreateDefaultDeps("discord-voice-helper"); |
| 90 | +const deps = createDefaultDeps(); |
| 91 | + |
| 92 | +expect(deps.discordVoice).toBeUndefined(); |
| 93 | +expect(deps.sendDiscordVoice).toBeUndefined(); |
| 94 | +expect(runtimeFactories.discord).not.toHaveBeenCalled(); |
| 95 | +}); |
| 96 | + |
88 | 97 | it("reuses cached runtime send surfaces after first lazy load", async () => { |
89 | 98 | const createDefaultDeps = await loadCreateDefaultDeps("module-cache"); |
90 | 99 | const deps = createDefaultDeps(); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { normalizeChannelId } from "../channels/registry.js"; |
1 | 2 | import type { OutboundSendDeps } from "../infra/outbound/send-deps.js"; |
2 | 3 | import { createLazyRuntimeSurface } from "../shared/lazy-runtime.js"; |
3 | 4 | import type { CliDeps } from "./deps.types.js"; |
@@ -47,6 +48,10 @@ const NON_CHANNEL_DEP_KEYS = new Set([
|
47 | 48 | "valueOf", |
48 | 49 | ]); |
49 | 50 | |
| 51 | +function resolveKnownChannelId(raw: string): string | undefined { |
| 52 | +return normalizeChannelId(raw) ?? undefined; |
| 53 | +} |
| 54 | + |
50 | 55 | // Per-channel module caches for lazy loading. |
51 | 56 | const senderCache = new Map<string, Promise<RuntimeSend>>(); |
52 | 57 | |
@@ -100,7 +105,11 @@ export function createDefaultDeps(): CliDeps {
|
100 | 105 | if (existing !== undefined || NON_CHANNEL_DEP_KEYS.has(property)) { |
101 | 106 | return existing; |
102 | 107 | } |
103 | | -const sender = resolveSender(property); |
| 108 | +const channelId = resolveKnownChannelId(property); |
| 109 | +if (!channelId) { |
| 110 | +return existing; |
| 111 | +} |
| 112 | +const sender = resolveSender(channelId); |
104 | 113 | Reflect.set(target, property, sender, receiver); |
105 | 114 | return sender; |
106 | 115 | }, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { describe, expect, it, vi } from "vitest"; |
2 | | -import { createOutboundSendDepsFromCliSource } from "./outbound-send-mapping.js"; |
| 2 | +import { |
| 3 | +CLI_OUTBOUND_SEND_FACTORY, |
| 4 | +createOutboundSendDepsFromCliSource, |
| 5 | +} from "./outbound-send-mapping.js"; |
3 | 6 | |
4 | 7 | describe("createOutboundSendDepsFromCliSource", () => { |
5 | 8 | it("adds generic legacy aliases for channel-keyed send deps", () => { |
@@ -29,4 +32,23 @@ describe("createOutboundSendDepsFromCliSource", () => {
|
29 | 32 | sendImessage: deps.imessage, |
30 | 33 | }); |
31 | 34 | }); |
| 35 | + |
| 36 | +it("does not manufacture Discord voice helper deps from the lazy channel factory", () => { |
| 37 | +const sendFactory = vi.fn((channelId: string) => vi.fn().mockName(channelId)); |
| 38 | +const outbound = createOutboundSendDepsFromCliSource({ |
| 39 | +[CLI_OUTBOUND_SEND_FACTORY]: sendFactory, |
| 40 | +}); |
| 41 | + |
| 42 | +expect(outbound.discordVoice).toBeUndefined(); |
| 43 | +expect(outbound.sendDiscordVoice).toBeUndefined(); |
| 44 | +expect(sendFactory).not.toHaveBeenCalled(); |
| 45 | +}); |
| 46 | + |
| 47 | +it("preserves explicitly provided Discord voice helper deps", () => { |
| 48 | +const discordVoice = vi.fn(); |
| 49 | +const outbound = createOutboundSendDepsFromCliSource({ discordVoice }); |
| 50 | + |
| 51 | +expect(outbound.discordVoice).toBe(discordVoice); |
| 52 | +expect(outbound.sendDiscordVoice).toBe(discordVoice); |
| 53 | +}); |
32 | 54 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { normalizeChannelId } from "../channels/registry.js"; |
1 | 2 | import { |
2 | 3 | resolveLegacyOutboundSendDepKeys, |
3 | 4 | type OutboundSendDeps, |
@@ -46,6 +47,10 @@ function resolveChannelIdFromLegacyOutboundKey(key: string): string | undefined
|
46 | 47 | return normalizedStem || undefined; |
47 | 48 | } |
48 | 49 | |
| 50 | +function resolveKnownChannelId(raw: string): string | undefined { |
| 51 | +return normalizeChannelId(raw) ?? undefined; |
| 52 | +} |
| 53 | + |
49 | 54 | /** |
50 | 55 | * Pass CLI send sources through as-is — both CliOutboundSendSource and |
51 | 56 | * OutboundSendDeps are now channel-ID-keyed records. |
@@ -82,8 +87,9 @@ export function createOutboundSendDepsFromCliSource(deps: CliOutboundSendSource)
|
82 | 87 | } |
83 | 88 | |
84 | 89 | const resolveFactoryValue = (key: string): unknown => { |
85 | | -const channelId = |
| 90 | +const candidate = |
86 | 91 | outbound[key] === undefined ? (resolveChannelIdFromLegacyOutboundKey(key) ?? key) : key; |
| 92 | +const channelId = resolveKnownChannelId(candidate); |
87 | 93 | if (!channelId || channelId === "then" || channelId === "toJSON") { |
88 | 94 | return undefined; |
89 | 95 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。