fix(sync): merge auth providers across all candidate files

readStoredAuthProvidersFromDisk() previously returned only the first
successfully-parsed auth file, missing providers that existed only in
fallback locations (e.g. github-copilot in ~/.pi/agent/auth.json when
another provider was in ~/.fusion/agent/auth.json). Now iterates all
candidates and merges entries with first-found-wins priority.
This commit is contained in:
gsxdsm
2026-04-26 11:35:44 -07:00
parent 8ca4e0989c
commit 43523b92bf
2 changed files with 149 additions and 2 deletions

View File

@@ -4,15 +4,19 @@ import { ApiError } from "../api-error.js";
import { getAuthFileCandidates, type StoredAuthProvider } from "../auth-paths.js";
export async function readStoredAuthProvidersFromDisk(): Promise<Record<string, StoredAuthProvider>> {
const merged: Record<string, StoredAuthProvider> = {};
for (const authJsonPath of getAuthFileCandidates()) {
try {
const authContent = await fsReadFile(authJsonPath, "utf-8");
return JSON.parse(authContent) as Record<string, StoredAuthProvider>;
const parsed = JSON.parse(authContent) as Record<string, StoredAuthProvider>;
for (const [provider, credential] of Object.entries(parsed)) {
merged[provider] ??= credential;
}
} catch {
// Try next candidate.
}
}
return {};
return merged;
}
/**