fix: normalize account config keys for case-insensitive matching

This commit is contained in:
Monty Taylor
2026-02-09 08:07:57 -07:00
committed by Peter Steinberger
parent c89b8d99fc
commit a6dd50fede
2 changed files with 26 additions and 4 deletions

View File

@@ -18,7 +18,10 @@ function listConfiguredAccountIds(cfg: CoreConfig): string[] {
if (!accounts || typeof accounts !== "object") {
return [];
}
return Object.keys(accounts).filter(Boolean);
// Normalize keys so listing and resolution use the same semantics
return Object.keys(accounts)
.filter(Boolean)
.map((id) => normalizeAccountId(id));
}
export function listMatrixAccountIds(cfg: CoreConfig): string[] {
@@ -43,7 +46,18 @@ function resolveAccountConfig(cfg: CoreConfig, accountId: string): MatrixConfig
if (!accounts || typeof accounts !== "object") {
return undefined;
}
return accounts[accountId] as MatrixConfig | undefined;
// Direct lookup first (fast path for already-normalized keys)
if (accounts[accountId]) {
return accounts[accountId] as MatrixConfig;
}
// Fall back to case-insensitive match (user may have mixed-case keys in config)
const normalized = normalizeAccountId(accountId);
for (const key of Object.keys(accounts)) {
if (normalizeAccountId(key) === normalized) {
return accounts[key] as MatrixConfig;
}
}
return undefined;
}
export function resolveMatrixAccount(params: {

View File

@@ -22,8 +22,16 @@ export function resolveMatrixConfigForAccount(
const normalizedAccountId = normalizeAccountId(accountId);
const matrixBase = cfg.channels?.matrix ?? {};
// Try to get account-specific config first
const accountConfig = matrixBase.accounts?.[normalizedAccountId];
// Try to get account-specific config first (direct lookup, then case-insensitive fallback)
let accountConfig = matrixBase.accounts?.[normalizedAccountId];
if (!accountConfig && matrixBase.accounts) {
for (const key of Object.keys(matrixBase.accounts)) {
if (normalizeAccountId(key) === normalizedAccountId) {
accountConfig = matrixBase.accounts[key];
break;
}
}
}
// Merge: account-specific values override top-level values
// For DEFAULT_ACCOUNT_ID with no accounts, use top-level directly