

























@@ -95,6 +95,7 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
9595cfg: {} as OpenClawConfig,
9696rawTarget: "-100123",
9797resolvedChatId: "-100123",
98+gatewayClientScopes: ["operator.admin"],
9899});
99100100101expect(readConfigFileSnapshotForWrite).not.toHaveBeenCalled();
@@ -118,6 +119,23 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
118119expect(saveCronStore).not.toHaveBeenCalled();
119120});
120121122+it("does not let internal writeback override non-admin gateway scopes", async () => {
123+await maybePersistResolvedTelegramTarget({
124+cfg: {
125+cron: { store: "/tmp/cron/jobs.json" },
126+} as OpenClawConfig,
127+rawTarget: "t.me/mychannel",
128+resolvedChatId: "-100123",
129+gatewayClientScopes: ["operator.write"],
130+trustedInternalWriteback: true,
131+});
132+133+expect(readConfigFileSnapshotForWrite).not.toHaveBeenCalled();
134+expect(writeConfigFile).not.toHaveBeenCalled();
135+expect(loadCronStore).not.toHaveBeenCalled();
136+expect(saveCronStore).not.toHaveBeenCalled();
137+});
138+121139it("skips config and cron writeback for gateway callers with an empty scope set", async () => {
122140await maybePersistResolvedTelegramTarget({
123141cfg: {
@@ -133,6 +151,53 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
133151expect(loadCronStore).not.toHaveBeenCalled();
134152expect(saveCronStore).not.toHaveBeenCalled();
135153});
154+155+it("skips config and cron writeback when gateway scopes are missing", async () => {
156+await maybePersistResolvedTelegramTarget({
157+cfg: {
158+cron: { store: "/tmp/cron/jobs.json" },
159+} as OpenClawConfig,
160+rawTarget: "t.me/mychannel",
161+resolvedChatId: "-100123",
162+gatewayClientScopes: undefined,
163+});
164+165+expect(readConfigFileSnapshotForWrite).not.toHaveBeenCalled();
166+expect(writeConfigFile).not.toHaveBeenCalled();
167+expect(loadCronStore).not.toHaveBeenCalled();
168+expect(saveCronStore).not.toHaveBeenCalled();
169+});
170+171+it("writes back for gateway callers with operator.admin", async () => {
172+readConfigFileSnapshotForWrite.mockResolvedValue({
173+snapshot: {
174+config: {
175+channels: {
176+telegram: {
177+defaultTo: "t.me/mychannel",
178+},
179+},
180+},
181+},
182+writeOptions: {},
183+});
184+loadCronStore.mockResolvedValue({
185+version: 1,
186+jobs: [{ id: "a", delivery: { channel: "telegram", to: "t.me/mychannel" } }],
187+});
188+189+await maybePersistResolvedTelegramTarget({
190+cfg: {
191+cron: { store: "/tmp/cron/jobs.json" },
192+} as OpenClawConfig,
193+rawTarget: "t.me/mychannel",
194+resolvedChatId: "-100123",
195+gatewayClientScopes: ["operator.admin"],
196+});
197+198+expect(writeConfigFile).toHaveBeenCalledTimes(1);
199+expect(saveCronStore).toHaveBeenCalledTimes(1);
200+});
136201}
137202138203it("writes back matching config and cron targets", async () => {
@@ -167,6 +232,8 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
167232} as OpenClawConfig,
168233rawTarget: "t.me/mychannel",
169234resolvedChatId: "-100123",
235+gatewayClientScopes: undefined,
236+trustedInternalWriteback: true,
170237});
171238172239expect(writeConfigFile).toHaveBeenCalledTimes(1);
@@ -202,6 +269,8 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
202269cfg: {} as OpenClawConfig,
203270rawTarget: "t.me/mychannel:topic:9",
204271resolvedChatId: "-100123",
272+gatewayClientScopes: undefined,
273+trustedInternalWriteback: true,
205274});
206275207276expect(writeConfigFile).toHaveBeenCalledTimes(1);
@@ -232,6 +301,8 @@ export function installMaybePersistResolvedTelegramTargetTests(params?: {
232301cfg: {} as OpenClawConfig,
233302rawTarget: "@MyChannel",
234303resolvedChatId: "-100123",
304+gatewayClientScopes: undefined,
305+trustedInternalWriteback: true,
235306});
236307237308expect(writeConfigFile).toHaveBeenCalledTimes(1);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。