From d0a43cf8c0842b930d5c40ba4a809ccc5c014629 Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Fri, 3 Apr 2026 12:38:12 -0500 Subject: [PATCH] fix: honor googlechat default account setup policy --- extensions/googlechat/src/setup-surface.ts | 12 ++++----- extensions/googlechat/src/setup.test.ts | 31 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/extensions/googlechat/src/setup-surface.ts b/extensions/googlechat/src/setup-surface.ts index 1106a48781c..0d54f53f537 100644 --- a/extensions/googlechat/src/setup-surface.ts +++ b/extensions/googlechat/src/setup-surface.ts @@ -42,11 +42,11 @@ const googlechatDmPolicy: ChannelSetupDmPolicy = { channel, policyKey: "channels.googlechat.dm.policy", allowFromKey: "channels.googlechat.dm.allowFrom", - resolveConfigKeys: (_cfg, accountId) => - accountId && accountId !== DEFAULT_ACCOUNT_ID + resolveConfigKeys: (cfg, accountId) => + (accountId ?? resolveDefaultGoogleChatAccountId(cfg)) !== DEFAULT_ACCOUNT_ID ? { - policyKey: `channels.googlechat.accounts.${accountId}.dm.policy`, - allowFromKey: `channels.googlechat.accounts.${accountId}.dm.allowFrom`, + policyKey: `channels.googlechat.accounts.${accountId ?? resolveDefaultGoogleChatAccountId(cfg)}.dm.policy`, + allowFromKey: `channels.googlechat.accounts.${accountId ?? resolveDefaultGoogleChatAccountId(cfg)}.dm.allowFrom`, } : { policyKey: "channels.googlechat.dm.policy", @@ -55,10 +55,10 @@ const googlechatDmPolicy: ChannelSetupDmPolicy = { getCurrent: (cfg, accountId) => resolveGoogleChatAccount({ cfg, - accountId: accountId ?? DEFAULT_ACCOUNT_ID, + accountId: accountId ?? resolveDefaultGoogleChatAccountId(cfg), }).config.dm?.policy ?? "pairing", setPolicy: (cfg, policy, accountId) => { - const resolvedAccountId = accountId ?? DEFAULT_ACCOUNT_ID; + const resolvedAccountId = accountId ?? resolveDefaultGoogleChatAccountId(cfg); const currentDm = resolveGoogleChatAccount({ cfg, accountId: resolvedAccountId, diff --git a/extensions/googlechat/src/setup.test.ts b/extensions/googlechat/src/setup.test.ts index d8bc4b4156a..bbd65123bef 100644 --- a/extensions/googlechat/src/setup.test.ts +++ b/extensions/googlechat/src/setup.test.ts @@ -218,6 +218,37 @@ describe("googlechat setup", () => { }); }); + it("uses configured defaultAccount for omitted DM policy account context", () => { + const cfg = { + channels: { + googlechat: { + defaultAccount: "alerts", + dm: { + policy: "disabled", + }, + accounts: { + alerts: { + serviceAccount: { client_email: "bot@example.com" }, + dm: { + policy: "allowlist", + }, + }, + }, + }, + }, + } as OpenClawConfig; + + expect(googlechatPlugin.setupWizard?.dmPolicy?.getCurrent(cfg)).toBe("allowlist"); + expect(googlechatPlugin.setupWizard?.dmPolicy?.resolveConfigKeys?.(cfg)).toEqual({ + policyKey: "channels.googlechat.accounts.alerts.dm.policy", + allowFromKey: "channels.googlechat.accounts.alerts.dm.allowFrom", + }); + + const next = googlechatPlugin.setupWizard?.dmPolicy?.setPolicy(cfg, "open"); + expect(next?.channels?.googlechat?.dm?.policy).toBe("disabled"); + expect(next?.channels?.googlechat?.accounts?.alerts?.dm?.policy).toBe("open"); + }); + it('writes open DM policy to the named account and preserves inherited allowFrom with "*"', () => { const next = googlechatPlugin.setupWizard?.dmPolicy?.setPolicy( {