fix: honor line default account setup policy

This commit is contained in:
Tak Hoffman 2026-04-03 12:41:20 -05:00
parent 4afa720a0c
commit 4edf6a2c7d
No known key found for this signature in database
2 changed files with 43 additions and 8 deletions

View File

@ -208,6 +208,37 @@ describe("line setup wizard", () => {
});
});
it("uses configured defaultAccount for omitted DM policy account context", async () => {
const { lineSetupWizard } = await import("./setup-surface.js");
const cfg = {
channels: {
line: {
defaultAccount: "work",
dmPolicy: "disabled",
allowFrom: ["Uroot"],
accounts: {
work: {
channelAccessToken: "token",
channelSecret: "secret",
dmPolicy: "allowlist",
},
},
},
},
} as OpenClawConfig;
expect(lineSetupWizard.dmPolicy?.getCurrent(cfg)).toBe("allowlist");
expect(lineSetupWizard.dmPolicy?.resolveConfigKeys?.(cfg)).toEqual({
policyKey: "channels.line.accounts.work.dmPolicy",
allowFromKey: "channels.line.accounts.work.allowFrom",
});
const next = lineSetupWizard.dmPolicy?.setPolicy(cfg, "open");
expect(next?.channels?.line?.dmPolicy).toBe("disabled");
expect(next?.channels?.line?.accounts?.work?.dmPolicy).toBe("open");
});
it('writes open policy state to the named account and preserves inherited allowFrom with "*"', async () => {
const { lineSetupWizard } = await import("./setup-surface.js");

View File

@ -3,6 +3,7 @@ import {
createStandardChannelSetupStatus,
mergeAllowFromEntries,
} from "openclaw/plugin-sdk/setup";
import { resolveDefaultLineAccountId } from "./accounts.js";
import {
isLineConfigured,
listLineAccountIds,
@ -44,31 +45,34 @@ const lineDmPolicy: ChannelSetupDmPolicy = {
channel,
policyKey: "channels.line.dmPolicy",
allowFromKey: "channels.line.allowFrom",
resolveConfigKeys: (_cfg, accountId) =>
accountId && accountId !== DEFAULT_ACCOUNT_ID
resolveConfigKeys: (cfg, accountId) =>
(accountId ?? resolveDefaultLineAccountId(cfg)) !== DEFAULT_ACCOUNT_ID
? {
policyKey: `channels.line.accounts.${accountId}.dmPolicy`,
allowFromKey: `channels.line.accounts.${accountId}.allowFrom`,
policyKey: `channels.line.accounts.${accountId ?? resolveDefaultLineAccountId(cfg)}.dmPolicy`,
allowFromKey: `channels.line.accounts.${accountId ?? resolveDefaultLineAccountId(cfg)}.allowFrom`,
}
: {
policyKey: "channels.line.dmPolicy",
allowFromKey: "channels.line.allowFrom",
},
getCurrent: (cfg, accountId) =>
resolveLineAccount({ cfg, accountId: accountId ?? DEFAULT_ACCOUNT_ID }).config.dmPolicy ??
resolveLineAccount({ cfg, accountId: accountId ?? resolveDefaultLineAccountId(cfg) }).config
.dmPolicy ??
"pairing",
setPolicy: (cfg, policy, accountId) =>
patchLineAccountConfig({
cfg,
accountId: accountId ?? DEFAULT_ACCOUNT_ID,
accountId: accountId ?? resolveDefaultLineAccountId(cfg),
enabled: true,
patch:
policy === "open"
? {
dmPolicy: "open",
allowFrom: mergeAllowFromEntries(
resolveLineAccount({ cfg, accountId: accountId ?? DEFAULT_ACCOUNT_ID }).config
.allowFrom,
resolveLineAccount({
cfg,
accountId: accountId ?? resolveDefaultLineAccountId(cfg),
}).config.allowFrom,
["*"],
),
}