




















@@ -78,6 +78,23 @@ vi.mock("../plugins/provider-runtime.js", () => ({
7878 resolveProviderSyntheticAuthWithPlugin,
7979}));
808081+function expectAuthResult(
82+value: ReturnType<ReturnType<typeof createProviderAuthResolver>>,
83+expected: {
84+apiKey?: string;
85+mode: string;
86+source: string;
87+profileId?: string;
88+},
89+) {
90+expect(value.apiKey).toBe(expected.apiKey);
91+expect(value.mode).toBe(expected.mode);
92+expect(value.source).toBe(expected.source);
93+if ("profileId" in expected) {
94+expect(value.profileId).toBe(expected.profileId);
95+}
96+}
97+8198describe("provider auth aliases", () => {
8299beforeEach(async () => {
83100vi.resetModules();
@@ -95,12 +112,12 @@ describe("provider auth aliases", () => {
95112{ version: 1, profiles: {} },
96113);
9711498-expect(resolveAuth("fixture-provider")).toMatchObject({
115+expectAuthResult(resolveAuth("fixture-provider"), {
99116apiKey: "FIXTURE_PROVIDER_API_KEY",
100117mode: "api_key",
101118source: "env",
102119});
103-expect(resolveAuth("fixture-provider-plan")).toMatchObject({
120+expectAuthResult(resolveAuth("fixture-provider-plan"), {
104121apiKey: "FIXTURE_PROVIDER_API_KEY",
105122mode: "api_key",
106123source: "env",
@@ -119,13 +136,13 @@ describe("provider auth aliases", () => {
119136},
120137});
121138122-expect(resolveAuth("fixture-provider")).toMatchObject({
139+expectAuthResult(resolveAuth("fixture-provider"), {
123140apiKey: "FIXTURE_PROVIDER_API_KEY",
124141mode: "api_key",
125142source: "profile",
126143profileId: "fixture-provider:default",
127144});
128-expect(resolveAuth("fixture-provider-plan")).toMatchObject({
145+expectAuthResult(resolveAuth("fixture-provider-plan"), {
129146apiKey: "FIXTURE_PROVIDER_API_KEY",
130147mode: "api_key",
131148source: "profile",
@@ -169,12 +186,12 @@ describe("provider auth aliases", () => {
169186{},
170187);
171188172-expect(resolveAuth("openai")).toMatchObject({
189+expectAuthResult(resolveAuth("openai"), {
173190apiKey: "OPENAI_API_KEY",
174191mode: "api_key",
175192source: "env",
176193});
177-expect(resolveAuth("evil-openai")).toMatchObject({
194+expectAuthResult(resolveAuth("evil-openai"), {
178195apiKey: undefined,
179196mode: "none",
180197source: "none",
@@ -225,7 +242,7 @@ describe("provider auth aliases", () => {
225242},
226243);
227244228-expect(resolveAuth("openai-compatible")).toMatchObject({
245+expectAuthResult(resolveAuth("openai-compatible"), {
229246apiKey: "OPENAI_API_KEY",
230247mode: "api_key",
231248source: "env",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。