mirror of https://github.com/openclaw/openclaw.git
fix(regression): align sdk config write account lookup
This commit is contained in:
parent
d27b99c6af
commit
12923eb612
|
|
@ -3,6 +3,7 @@ import { formatPairingApproveHint } from "../channels/plugins/helpers.js";
|
|||
import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js";
|
||||
import {
|
||||
adaptScopedAccountAccessor,
|
||||
authorizeConfigWrite,
|
||||
createScopedAccountConfigAccessors,
|
||||
createScopedChannelConfigAdapter,
|
||||
createScopedChannelConfigBase,
|
||||
|
|
@ -12,6 +13,7 @@ import {
|
|||
createTopLevelChannelConfigBase,
|
||||
createHybridChannelConfigBase,
|
||||
mapAllowFromEntries,
|
||||
resolveChannelConfigWrites,
|
||||
resolveIMessageConfigAllowFrom,
|
||||
resolveIMessageConfigDefaultTo,
|
||||
resolveOptionalConfigString,
|
||||
|
|
@ -113,6 +115,55 @@ describe("provider config readers", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("config write helpers", () => {
|
||||
it("matches account ids case-insensitively", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
configWrites: true,
|
||||
accounts: {
|
||||
Work: { configWrites: false },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(resolveChannelConfigWrites({ cfg, channelId: "telegram", accountId: "work" })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
it("blocks account-scoped writes when the configured account key differs only by case", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: {
|
||||
configWrites: true,
|
||||
accounts: {
|
||||
Work: { configWrites: false },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
authorizeConfigWrite({
|
||||
cfg,
|
||||
target: {
|
||||
kind: "account",
|
||||
scope: { channelId: "telegram", accountId: "work" },
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
allowed: false,
|
||||
reason: "target-disabled",
|
||||
blockedScope: {
|
||||
kind: "target",
|
||||
scope: { channelId: "telegram", accountId: "work" },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("adaptScopedAccountAccessor", () => {
|
||||
it("binds positional callback args into the shared account context object", () => {
|
||||
const accessor = adaptScopedAccountAccessor(({ cfg, accountId }) => ({
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {
|
|||
import type { ChannelConfigAdapter } from "../channels/plugins/types.adapters.js";
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveAccountEntry } from "../routing/account-lookup.js";
|
||||
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../routing/session-key.js";
|
||||
import { normalizeStringEntries } from "../shared/string-normalization.js";
|
||||
|
||||
|
|
@ -173,8 +174,7 @@ function resolveChannelAccountConfig(
|
|||
channelConfig: ChannelConfigWithAccounts,
|
||||
accountId?: string | null,
|
||||
): AccountConfigWithWrites | undefined {
|
||||
const normalized = normalizeAccountId(accountId);
|
||||
return normalized ? channelConfig.accounts?.[normalized] : undefined;
|
||||
return resolveAccountEntry(channelConfig.accounts, normalizeAccountId(accountId));
|
||||
}
|
||||
|
||||
function listConfigWriteTargetScopes(target?: ConfigWriteTarget): ConfigWriteScope[] {
|
||||
|
|
|
|||
Loading…
Reference in New Issue