





























@@ -7,8 +7,23 @@ type RunMessageActionParams = {
77cfg?: unknown;
88action: string;
99params: Record<string, unknown>;
10+agentId?: string;
11+senderIsOwner?: boolean;
12+gateway?: {
13+clientName?: string;
14+mode?: string;
15+};
1016};
111718+function readOnlyMessageActionCall(): RunMessageActionParams {
19+expect(runMessageActionMock).toHaveBeenCalledOnce();
20+const call = runMessageActionMock.mock.calls[0]?.[0];
21+if (!call) {
22+throw new Error("Expected message action call");
23+}
24+return call;
25+}
26+1227let testConfig: Record<string, unknown> = {};
1328const applyPluginAutoEnable = vi.hoisted(() => vi.fn(({ config }) => ({ config, changes: [] })));
1429vi.mock("../config/config.js", () => ({
@@ -182,41 +197,34 @@ describe("messageCommand", () => {
182197183198await runMessageCommand();
184199185-expect(runMessageActionMock).toHaveBeenCalledWith(
186-expect.objectContaining({
187-cfg: resolvedConfig,
188-action: "send",
189-params: expect.objectContaining({
190-channel: "telegram",
191-target: "123456",
192-message: "hi",
193-}),
194-agentId: "main",
195-senderIsOwner: true,
196-gateway: expect.objectContaining({
197-clientName: "cli",
198-mode: "cli",
199-}),
200-}),
201-);
202-expect(runMessageActionMock.mock.calls[0]?.[0]?.cfg).not.toBe(rawConfig);
203-expect(resolveCommandConfigWithSecrets).toHaveBeenCalledWith(
204-expect.objectContaining({
205-config: rawConfig,
206-commandName: "message",
207-}),
208-);
200+const actionCall = readOnlyMessageActionCall();
201+expect(actionCall.cfg).toBe(resolvedConfig);
202+expect(actionCall.action).toBe("send");
203+expect(actionCall.params.channel).toBe("telegram");
204+expect(actionCall.params.target).toBe("123456");
205+expect(actionCall.params.message).toBe("hi");
206+expect(actionCall.agentId).toBe("main");
207+expect(actionCall.senderIsOwner).toBe(true);
208+expect(actionCall.gateway?.clientName).toBe("cli");
209+expect(actionCall.gateway?.mode).toBe("cli");
210+expect(actionCall.cfg).not.toBe(rawConfig);
211+const configResolutionCall = resolveCommandConfigWithSecrets.mock.calls[0]?.[0] as {
212+commandName?: string;
213+config?: unknown;
214+targetIds?: Set<string>;
215+};
216+expect(configResolutionCall.config).toBe(rawConfig);
217+expect(configResolutionCall.commandName).toBe("message");
209218expect(getScopedChannelsCommandSecretTargets).toHaveBeenCalledWith({
210219config: rawConfig,
211220channel: "telegram",
212221accountId: undefined,
213222});
214-const call = resolveCommandConfigWithSecrets.mock.calls[0]?.[0] as {
215-targetIds?: Set<string>;
216-};
217-expect(call.targetIds).toBeInstanceOf(Set);
223+expect(configResolutionCall.targetIds).toBeInstanceOf(Set);
218224expect(
219-[...(call.targetIds ?? [])].filter((id) => !id.startsWith("channels.telegram.")),
225+[...(configResolutionCall.targetIds ?? [])].filter(
226+(id) => !id.startsWith("channels.telegram."),
227+),
220228).toStrictEqual([]);
221229});
222230@@ -237,15 +245,16 @@ describe("messageCommand", () => {
237245238246await runMessageCommand();
239247240-expect(runMessageActionMock).toHaveBeenCalledWith(
241-expect.objectContaining({
242-cfg: locallyResolvedConfig,
243-}),
244-);
245-expect(runMessageActionMock.mock.calls[0]?.[0]?.cfg).not.toBe(rawConfig);
246-expect(runtime.log).toHaveBeenCalledWith(
247-expect.stringContaining("[secrets] gateway secrets.resolve unavailable"),
248-);
248+const actionCall = readOnlyMessageActionCall();
249+expect(actionCall.cfg).toBe(locallyResolvedConfig);
250+expect(actionCall.cfg).not.toBe(rawConfig);
251+expect(
252+vi
253+.mocked(runtime.log)
254+.mock.calls.some(([message]) =>
255+String(message).includes("[secrets] gateway secrets.resolve unavailable"),
256+),
257+).toBe(true);
249258});
250259251260it("uses auto-enabled effective config for message actions", async () => {
@@ -268,12 +277,9 @@ describe("messageCommand", () => {
268277config: resolvedConfig,
269278env: process.env,
270279});
271-expect(runMessageActionMock).toHaveBeenCalledWith(
272-expect.objectContaining({
273-cfg: autoEnabledConfig,
274-params: expect.objectContaining({ target: "123456" }),
275-}),
276-);
280+const actionCall = readOnlyMessageActionCall();
281+expect(actionCall.cfg).toBe(autoEnabledConfig);
282+expect(actionCall.params.target).toBe("123456");
277283});
278284279285it("normalizes poll actions and sender ownership before dispatch", async () => {
@@ -286,17 +292,12 @@ describe("messageCommand", () => {
286292senderIsOwner: false,
287293});
288294289-expect(runMessageActionMock).toHaveBeenCalledWith(
290-expect.objectContaining({
291-action: "poll",
292-senderIsOwner: false,
293-params: expect.objectContaining({
294-channel: "telegram",
295-target: "123456789",
296-pollQuestion: "Ship it?",
297-}),
298-}),
299-);
295+const actionCall = readOnlyMessageActionCall();
296+expect(actionCall.action).toBe("poll");
297+expect(actionCall.senderIsOwner).toBe(false);
298+expect(actionCall.params.channel).toBe("telegram");
299+expect(actionCall.params.target).toBe("123456789");
300+expect(actionCall.params.pollQuestion).toBe("Ship it?");
300301});
301302302303it("rejects unknown message actions before dispatch", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。