fix: honor bluebubbles default account setup policy

This commit is contained in:
Tak Hoffman 2026-04-03 12:45:42 -05:00
parent 638e831bca
commit f115aba582
No known key found for this signature in database
2 changed files with 44 additions and 6 deletions

View File

@ -185,6 +185,37 @@ describe("bluebubbles setup surface", () => {
});
});
it("uses configured defaultAccount for omitted DM policy account context", async () => {
const { blueBubblesSetupWizard } = await import("./setup-surface.js");
const cfg = {
channels: {
bluebubbles: {
defaultAccount: "work",
dmPolicy: "disabled",
allowFrom: ["user@example.com"],
accounts: {
work: {
serverUrl: "http://localhost:1234",
password: "secret",
dmPolicy: "allowlist",
},
},
},
},
} as OpenClawConfig;
expect(blueBubblesSetupWizard.dmPolicy?.getCurrent(cfg)).toBe("allowlist");
expect(blueBubblesSetupWizard.dmPolicy?.resolveConfigKeys?.(cfg)).toEqual({
policyKey: "channels.bluebubbles.accounts.work.dmPolicy",
allowFromKey: "channels.bluebubbles.accounts.work.allowFrom",
});
const next = blueBubblesSetupWizard.dmPolicy?.setPolicy(cfg, "open");
expect(next?.channels?.bluebubbles?.dmPolicy).toBe("disabled");
expect(next?.channels?.bluebubbles?.accounts?.work?.dmPolicy).toBe("open");
});
it('writes open policy state to the named account and preserves inherited allowFrom with "*"', async () => {
const { blueBubblesSetupWizard } = await import("./setup-surface.js");

View File

@ -135,21 +135,28 @@ const dmPolicy: ChannelSetupDmPolicy = {
channel,
policyKey: "channels.bluebubbles.dmPolicy",
allowFromKey: "channels.bluebubbles.allowFrom",
resolveConfigKeys: (_cfg, accountId) =>
accountId && accountId !== DEFAULT_ACCOUNT_ID
resolveConfigKeys: (cfg, accountId) =>
(accountId ?? resolveDefaultBlueBubblesAccountId(cfg)) !== DEFAULT_ACCOUNT_ID
? {
policyKey: `channels.bluebubbles.accounts.${accountId}.dmPolicy`,
allowFromKey: `channels.bluebubbles.accounts.${accountId}.allowFrom`,
policyKey: `channels.bluebubbles.accounts.${accountId ?? resolveDefaultBlueBubblesAccountId(cfg)}.dmPolicy`,
allowFromKey: `channels.bluebubbles.accounts.${accountId ?? resolveDefaultBlueBubblesAccountId(cfg)}.allowFrom`,
}
: {
policyKey: "channels.bluebubbles.dmPolicy",
allowFromKey: "channels.bluebubbles.allowFrom",
},
getCurrent: (cfg, accountId) =>
resolveBlueBubblesAccount({ cfg, accountId: accountId ?? DEFAULT_ACCOUNT_ID }).config
resolveBlueBubblesAccount({
cfg,
accountId: accountId ?? resolveDefaultBlueBubblesAccountId(cfg),
}).config
.dmPolicy ?? "pairing",
setPolicy: (cfg, policy, accountId) =>
setBlueBubblesDmPolicy(cfg, accountId ?? DEFAULT_ACCOUNT_ID, policy),
setBlueBubblesDmPolicy(
cfg,
accountId ?? resolveDefaultBlueBubblesAccountId(cfg),
policy,
),
promptAllowFrom: promptBlueBubblesAllowFrom,
};