mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 15:21:06 +00:00
fix: honor feishu tool account context
This commit is contained in:
44
extensions/feishu/src/tool-account.test.ts
Normal file
44
extensions/feishu/src/tool-account.test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveFeishuToolAccount } from "./tool-account.js";
|
||||
|
||||
describe("resolveFeishuToolAccount", () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
feishu: {
|
||||
enabled: true,
|
||||
defaultAccount: "ops",
|
||||
appId: "base-app-id",
|
||||
appSecret: "base-app-secret", // pragma: allowlist secret
|
||||
accounts: {
|
||||
ops: {
|
||||
enabled: true,
|
||||
appId: "ops-app-id",
|
||||
appSecret: "ops-app-secret", // pragma: allowlist secret
|
||||
},
|
||||
work: {
|
||||
enabled: true,
|
||||
appId: "work-app-id",
|
||||
appSecret: "work-app-secret", // pragma: allowlist secret
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
it("prefers the active contextual account over configured defaultAccount", () => {
|
||||
const resolved = resolveFeishuToolAccount({
|
||||
api: { config: cfg },
|
||||
defaultAccountId: "work",
|
||||
});
|
||||
|
||||
expect(resolved.accountId).toBe("work");
|
||||
});
|
||||
|
||||
it("falls back to configured defaultAccount when there is no contextual account", () => {
|
||||
const resolved = resolveFeishuToolAccount({
|
||||
api: { config: cfg },
|
||||
});
|
||||
|
||||
expect(resolved.accountId).toBe("ops");
|
||||
});
|
||||
});
|
||||
@@ -35,25 +35,23 @@ function resolveImplicitToolAccountId(params: {
|
||||
return explicitAccountId;
|
||||
}
|
||||
|
||||
const contextualAccountId = normalizeOptionalAccountId(params.defaultAccountId);
|
||||
if (contextualAccountId && listFeishuAccountIds(params.api.config).includes(contextualAccountId)) {
|
||||
const contextualAccount = resolveFeishuAccount({
|
||||
cfg: params.api.config,
|
||||
accountId: contextualAccountId,
|
||||
});
|
||||
if (contextualAccount.enabled) {
|
||||
return contextualAccountId;
|
||||
}
|
||||
}
|
||||
|
||||
const configuredDefaultAccountId = readConfiguredDefaultAccountId(params.api.config);
|
||||
if (configuredDefaultAccountId) {
|
||||
return configuredDefaultAccountId;
|
||||
}
|
||||
|
||||
const contextualAccountId = normalizeOptionalAccountId(params.defaultAccountId);
|
||||
if (!contextualAccountId) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!listFeishuAccountIds(params.api.config).includes(contextualAccountId)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const contextualAccount = resolveFeishuAccount({
|
||||
cfg: params.api.config,
|
||||
accountId: contextualAccountId,
|
||||
});
|
||||
return contextualAccount.enabled ? contextualAccountId : undefined;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function resolveFeishuToolAccount(params: {
|
||||
|
||||
Reference in New Issue
Block a user