From 4edf6a2c7dc8e9e6bd752aafe56d1c4bb4870307 Mon Sep 17 00:00:00 2001 From: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> Date: Fri, 3 Apr 2026 12:41:20 -0500 Subject: [PATCH] fix: honor line default account setup policy --- extensions/line/src/setup-surface.test.ts | 31 +++++++++++++++++++++++ extensions/line/src/setup-surface.ts | 20 +++++++++------ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/extensions/line/src/setup-surface.test.ts b/extensions/line/src/setup-surface.test.ts index e0b4b655d04..0e2aee1522f 100644 --- a/extensions/line/src/setup-surface.test.ts +++ b/extensions/line/src/setup-surface.test.ts @@ -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"); diff --git a/extensions/line/src/setup-surface.ts b/extensions/line/src/setup-surface.ts index 5b185929cbb..ced954f251d 100644 --- a/extensions/line/src/setup-surface.ts +++ b/extensions/line/src/setup-surface.ts @@ -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, ["*"], ), }