Skip to content

Commit 2f4ac99

Browse files
committed
fix(usage): preserve direct auth failures
1 parent 28eef49 commit 2f4ac99

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎src/infra/provider-usage.auth.plugin.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ describe("resolveProviderAuths plugin boundary", () => {
152152
expect(ensureAuthProfileStoreMock).not.toHaveBeenCalled();
153153
});
154154

155+
it("preserves exact plugin auth failures for direct callers", async () => {
156+
const authError = new Error("plugin auth failed");
157+
resolveProviderUsageAuthWithPluginMock.mockRejectedValueOnce(authError);
158+
159+
await expect(
160+
resolveProviderAuthsForTest({
161+
providers: ["anthropic"],
162+
}),
163+
).rejects.toBe(authError);
164+
});
165+
155166
it("resolves SecretRef-backed profiles before provider credential classification", async () => {
156167
const store = {
157168
profiles: {

‎src/infra/provider-usage.auth.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,10 @@ export async function resolveProviderAuths(params: {
579579
auths.push(fallbackAuth);
580580
}
581581
} catch (error) {
582-
params.onError?.(provider, error);
582+
if (!params.onError) {
583+
throw error;
584+
}
585+
params.onError(provider, error);
583586
}
584587
}
585588

‎src/infra/provider-usage.load.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,7 @@ export async function loadProviderUsageSummary(
158158
fetchFn,
159159
}),
160160
timeoutMs + 1000,
161-
{
162-
provider: auth.provider,
163-
displayName:
164-
displayNames.get(auth.provider) ?? providerUsageLabel(auth.provider) ?? auth.provider,
165-
windows: [],
166-
error: "Timeout",
167-
},
161+
failureSnapshot(auth.provider, "Timeout"),
168162
).catch((error: unknown) => {
169163
const message = error instanceof Error ? error.message : String(error);
170164
return failureSnapshot(auth.provider, message.trim() || "Fetch failed");

0 commit comments

Comments
 (0)