fix: honor feishu tool account context

This commit is contained in:
Tak Hoffman 2026-04-03 14:18:50 -05:00
parent f5ec0e429f
commit a18167a2cb
No known key found for this signature in database
2 changed files with 56 additions and 14 deletions

View 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");
});
});

View File

@ -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: {