fix(channels): include default account when base config has tokens
When a channel config has top-level tokens (botToken/appToken/token) AND named accounts in the accounts section, listAccountIds() omitted the default account. This meant only named accounts started, leaving the base-config bot disconnected. Now detects base-level tokens and includes 'default' alongside named accounts so both providers start. Includes 3 test cases: base tokens present, default already in accounts (no duplicate), and no base tokens (unchanged behavior). Co-authored-by: Eddie Abrams <eddie@bighatbio.com>
This commit is contained in:
parent
91d37ccfc3
commit
4e183da984
@ -81,6 +81,35 @@ describe("createAccountListHelpers", () => {
|
||||
it("returns sorted ids", () => {
|
||||
expect(listAccountIds(cfg({ z: {}, a: {}, m: {} }))).toEqual(["a", "m", "z"]);
|
||||
});
|
||||
|
||||
it("includes default when base config has botToken and named accounts exist", () => {
|
||||
const config = {
|
||||
channels: {
|
||||
testchannel: {
|
||||
botToken: "xoxb-base",
|
||||
appToken: "xapp-base",
|
||||
accounts: { tank: {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
expect(listAccountIds(config)).toEqual(["default", "tank"]);
|
||||
});
|
||||
|
||||
it("does not duplicate default when already in accounts", () => {
|
||||
const config = {
|
||||
channels: {
|
||||
testchannel: {
|
||||
botToken: "xoxb-base",
|
||||
accounts: { default: {}, tank: {} },
|
||||
},
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
expect(listAccountIds(config)).toEqual(["default", "tank"]);
|
||||
});
|
||||
|
||||
it("does not include default when base has no tokens", () => {
|
||||
expect(listAccountIds(cfg({ tank: {} }))).toEqual(["tank"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveDefaultAccountId", () => {
|
||||
|
||||
@ -43,6 +43,16 @@ export function createAccountListHelpers(
|
||||
if (ids.length === 0) {
|
||||
return [DEFAULT_ACCOUNT_ID];
|
||||
}
|
||||
// If the base channel config has its own tokens (botToken/appToken/token),
|
||||
// include the default account alongside named accounts so both providers start.
|
||||
if (!ids.includes(DEFAULT_ACCOUNT_ID)) {
|
||||
const channel = cfg.channels?.[channelKey];
|
||||
const base = channel as Record<string, unknown> | undefined;
|
||||
const hasBaseTokens = Boolean(base?.botToken || base?.appToken || base?.token);
|
||||
if (hasBaseTokens) {
|
||||
return [DEFAULT_ACCOUNT_ID, ...ids].toSorted((a, b) => a.localeCompare(b));
|
||||
}
|
||||
}
|
||||
return ids.toSorted((a, b) => a.localeCompare(b));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user