

























@@ -14,6 +14,20 @@ const loadCronStore: AsyncUnknownMock = vi.fn();
1414const resolveCronStorePath: UnknownMock = vi.fn();
1515const saveCronStore: AsyncUnknownMock = vi.fn();
161617+type TelegramConfigWrite = {
18+channels?: {
19+telegram?: {
20+defaultTo?: string;
21+accounts?: Record<string, { defaultTo?: string }>;
22+};
23+};
24+};
25+26+type CronStoreWrite = {
27+version: number;
28+jobs: Array<{ id: string; delivery: { channel: string; to: string } }>;
29+};
30+1731vi.mock("openclaw/plugin-sdk/config-mutation", async () => {
1832const actual = await vi.importActual<typeof import("openclaw/plugin-sdk/config-mutation")>(
1933"openclaw/plugin-sdk/config-mutation",
@@ -44,6 +58,24 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
4458describe("maybePersistResolvedTelegramTarget", () => {
4559let maybePersistResolvedTelegramTarget: typeof import("./target-writeback.js").maybePersistResolvedTelegramTarget;
466061+function requireWriteConfigCall(index = 0): [TelegramConfigWrite, Record<string, unknown>] {
62+const call = writeConfigFile.mock.calls[index] as
63+| [TelegramConfigWrite, Record<string, unknown>]
64+| undefined;
65+if (!call) {
66+throw new Error(`expected writeConfigFile call #${index + 1}`);
67+}
68+return call;
69+}
70+71+function requireSaveCronStoreCall(index = 0): [string, CronStoreWrite] {
72+const call = saveCronStore.mock.calls[index] as [string, CronStoreWrite] | undefined;
73+if (!call) {
74+throw new Error(`expected saveCronStore call #${index + 1}`);
75+}
76+return call;
77+}
78+4779beforeAll(async () => {
4880({ maybePersistResolvedTelegramTarget } = await import("./target-writeback.js"));
4981});
@@ -138,31 +170,17 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
138170});
139171140172expect(writeConfigFile).toHaveBeenCalledTimes(1);
141-expect(writeConfigFile).toHaveBeenCalledWith(
142-expect.objectContaining({
143-channels: {
144-telegram: {
145-defaultTo: "-100123",
146-accounts: {
147-alerts: {
148-defaultTo: "-100123",
149-},
150-},
151-},
152-},
153-}),
154-expect.objectContaining({ expectedConfigPath: "/tmp/openclaw.json" }),
155-);
173+const [writtenConfig, writeOptions] = requireWriteConfigCall();
174+expect(writtenConfig.channels?.telegram?.defaultTo).toBe("-100123");
175+expect(writtenConfig.channels?.telegram?.accounts?.alerts?.defaultTo).toBe("-100123");
176+expect(writeOptions.expectedConfigPath).toBe("/tmp/openclaw.json");
156177expect(saveCronStore).toHaveBeenCalledTimes(1);
157-expect(saveCronStore).toHaveBeenCalledWith(
158-"/tmp/cron/jobs.json",
159-expect.objectContaining({
160-jobs: [
161-{ id: "a", delivery: { channel: "telegram", to: "-100123" } },
162-{ id: "b", delivery: { channel: "slack", to: "C123" } },
163-],
164-}),
165-);
178+const [cronPath, cronStore] = requireSaveCronStoreCall();
179+expect(cronPath).toBe("/tmp/cron/jobs.json");
180+expect(cronStore.jobs).toEqual([
181+{ id: "a", delivery: { channel: "telegram", to: "-100123" } },
182+{ id: "b", delivery: { channel: "slack", to: "C123" } },
183+]);
166184});
167185168186it("preserves topic suffix style in writeback target", async () => {
@@ -186,16 +204,10 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
186204resolvedChatId: "-100123",
187205});
188206189-expect(writeConfigFile).toHaveBeenCalledWith(
190-expect.objectContaining({
191-channels: {
192-telegram: {
193-defaultTo: "-100123:topic:9",
194-},
195-},
196-}),
197-expect.any(Object),
198-);
207+expect(writeConfigFile).toHaveBeenCalledTimes(1);
208+const [writtenConfig, writeOptions] = requireWriteConfigCall();
209+expect(writtenConfig.channels?.telegram?.defaultTo).toBe("-100123:topic:9");
210+expect(writeOptions).toEqual({});
199211});
200212201213it("matches username targets case-insensitively", async () => {
@@ -222,22 +234,16 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
222234resolvedChatId: "-100123",
223235});
224236225-expect(writeConfigFile).toHaveBeenCalledWith(
226-expect.objectContaining({
227-channels: {
228-telegram: {
229-defaultTo: "-100123",
230-},
231-},
232-}),
233-expect.any(Object),
234-);
235-expect(saveCronStore).toHaveBeenCalledWith(
236-"/tmp/cron/jobs.json",
237-expect.objectContaining({
238-jobs: [{ id: "a", delivery: { channel: "telegram", to: "-100123" } }],
239-}),
240-);
237+expect(writeConfigFile).toHaveBeenCalledTimes(1);
238+const [writtenConfig, writeOptions] = requireWriteConfigCall();
239+expect(writtenConfig.channels?.telegram?.defaultTo).toBe("-100123");
240+expect(writeOptions).toEqual({});
241+expect(saveCronStore).toHaveBeenCalledTimes(1);
242+const [cronPath, cronStore] = requireSaveCronStoreCall();
243+expect(cronPath).toBe("/tmp/cron/jobs.json");
244+expect(cronStore.jobs).toEqual([
245+{ id: "a", delivery: { channel: "telegram", to: "-100123" } },
246+]);
241247});
242248});
243249}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。