fix: honor googlechat default account setup policy

This commit is contained in:
Tak Hoffman 2026-04-03 12:38:12 -05:00
parent acfa09679c
commit d0a43cf8c0
No known key found for this signature in database
2 changed files with 37 additions and 6 deletions

View File

@ -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,

View File

@ -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(
{