test: tighten provider usage auth assertions

This commit is contained in:
Peter Steinberger
2026-05-11 03:49:18 +01:00
parent 9334947acb
commit 520e704bfd

View File

@@ -47,6 +47,14 @@ async function withTempHome<T>(fn: (homeDir: string) => Promise<T>): Promise<T>
}
}
function providerCalls(mockFn: { mock: { calls: unknown[][] } }): unknown[] {
return mockFn.mock.calls.map(([params]) =>
params && typeof params === "object" && "provider" in params
? (params as { provider?: unknown }).provider
: undefined,
);
}
describe("resolveProviderAuths plugin boundary", () => {
beforeAll(async () => {
({ resolveProviderAuths } = await import("./provider-usage.auth.js"));
@@ -126,11 +134,7 @@ describe("resolveProviderAuths plugin boundary", () => {
]);
});
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "zai",
}),
);
expect(providerCalls(resolveProviderUsageAuthWithPluginMock)).toEqual(["zai"]);
expect(ensureAuthProfileStoreMock).not.toHaveBeenCalled();
});
@@ -160,11 +164,7 @@ describe("resolveProviderAuths plugin boundary", () => {
});
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledTimes(1);
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "zai",
}),
);
expect(providerCalls(resolveProviderUsageAuthWithPluginMock)).toEqual(["zai"]);
});
it("keeps auth-profile credential sources provider-specific", async () => {
@@ -205,11 +205,7 @@ describe("resolveProviderAuths plugin boundary", () => {
});
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledTimes(1);
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "anthropic",
}),
);
expect(providerCalls(resolveProviderUsageAuthWithPluginMock)).toEqual(["anthropic"]);
expect(ensureAuthProfileStoreMock).not.toHaveBeenCalled();
});
@@ -250,16 +246,8 @@ describe("resolveProviderAuths plugin boundary", () => {
]);
});
expect(resolveAuthProfileOrderMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "minimax-portal",
}),
);
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "minimax",
}),
);
expect(providerCalls(resolveAuthProfileOrderMock)).toEqual(["minimax", "minimax-portal"]);
expect(providerCalls(resolveProviderUsageAuthWithPluginMock)).toEqual(["minimax"]);
expect(ensureAuthProfileStoreMock).not.toHaveBeenCalled();
});
@@ -286,11 +274,7 @@ describe("resolveProviderAuths plugin boundary", () => {
]);
});
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "minimax",
}),
);
expect(providerCalls(resolveProviderUsageAuthWithPluginMock)).toEqual(["minimax"]);
expect(ensureAuthProfileStoreMock).not.toHaveBeenCalled();
});
@@ -332,10 +316,6 @@ describe("resolveProviderAuths plugin boundary", () => {
});
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledTimes(1);
expect(resolveProviderUsageAuthWithPluginMock).toHaveBeenCalledWith(
expect.objectContaining({
provider: "anthropic",
}),
);
expect(providerCalls(resolveProviderUsageAuthWithPluginMock)).toEqual(["anthropic"]);
});
});