























@@ -4,7 +4,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
44import {
55isXaiToolEnabled,
66resolveFallbackXaiAuth,
7-resolveXaiToolApiKey,
87resolveXaiToolApiKeyWithAuth,
98} from "./tool-auth-shared.js";
109@@ -81,11 +80,11 @@ describe("xai tool auth helpers", () => {
8180});
8281});
838284-it("falls back to runtime, then source config, then env for tool auth", () => {
83+it("falls back to runtime, then source config, then env for tool auth", async () => {
8584vi.stubEnv("XAI_API_KEY", "env-key");
868587-expect(
88-resolveXaiToolApiKey({
86+await expect(
87+resolveXaiToolApiKeyWithAuth({
8988runtimeConfig: {
9089plugins: {
9190entries: {
@@ -113,10 +112,10 @@ describe("xai tool auth helpers", () => {
113112},
114113},
115114}),
116-).toBe("runtime-key");
115+).resolves.toBe("runtime-key");
117116118-expect(
119-resolveXaiToolApiKey({
117+await expect(
118+resolveXaiToolApiKeyWithAuth({
120119sourceConfig: {
121120plugins: {
122121entries: {
@@ -131,9 +130,9 @@ describe("xai tool auth helpers", () => {
131130},
132131},
133132}),
134-).toBe("source-key");
133+).resolves.toBe("source-key");
135134136-expect(resolveXaiToolApiKey({})).toBe("env-key");
135+await expect(resolveXaiToolApiKeyWithAuth({})).resolves.toBe("env-key");
137136});
138137139138it("honors explicit disabled flags before auth fallback", () => {
@@ -153,11 +152,11 @@ describe("xai tool auth helpers", () => {
153152await expect(resolveXaiToolApiKeyWithAuth({ auth })).resolves.toBe("profile-key");
154153});
155154156-it("does not use env fallback when a non-env SecretRef is configured but unavailable", () => {
155+it("does not use env fallback when a non-env SecretRef is configured but unavailable", async () => {
157156vi.stubEnv("XAI_API_KEY", "env-key");
158157159-expect(
160-resolveXaiToolApiKey({
158+await expect(
159+resolveXaiToolApiKeyWithAuth({
161160sourceConfig: {
162161plugins: {
163162entries: {
@@ -176,7 +175,7 @@ describe("xai tool auth helpers", () => {
176175},
177176},
178177}),
179-).toBeUndefined();
178+).resolves.toBeUndefined();
180179});
181180182181it("does not bypass blocked explicit tool config with auth profiles", async () => {
@@ -207,11 +206,11 @@ describe("xai tool auth helpers", () => {
207206await expect(resolveXaiToolApiKeyWithAuth({ sourceConfig, auth })).resolves.toBeUndefined();
208207});
209208210-it("resolves env SecretRefs from source config when runtime snapshot is unavailable", () => {
209+it("resolves env SecretRefs from source config when runtime snapshot is unavailable", async () => {
211210vi.stubEnv("XAI_API_KEY", "xai-secretref-key");
212211213-expect(
214-resolveXaiToolApiKey({
212+await expect(
213+resolveXaiToolApiKeyWithAuth({
215214sourceConfig: {
216215plugins: {
217216entries: {
@@ -230,14 +229,14 @@ describe("xai tool auth helpers", () => {
230229},
231230},
232231}),
233-).toBe("xai-secretref-key");
232+).resolves.toBe("xai-secretref-key");
234233});
235234236-it("does not read arbitrary env SecretRef ids for xAI tool auth", () => {
235+it("does not read arbitrary env SecretRef ids for xAI tool auth", async () => {
237236vi.stubEnv("UNRELATED_SECRET", "should-not-be-read");
238237239-expect(
240-resolveXaiToolApiKey({
238+await expect(
239+resolveXaiToolApiKeyWithAuth({
241240sourceConfig: {
242241plugins: {
243242entries: {
@@ -256,14 +255,14 @@ describe("xai tool auth helpers", () => {
256255},
257256},
258257}),
259-).toBeUndefined();
258+).resolves.toBeUndefined();
260259});
261260262-it("does not resolve env SecretRefs when provider allowlist excludes XAI_API_KEY", () => {
261+it("does not resolve env SecretRefs when provider allowlist excludes XAI_API_KEY", async () => {
263262vi.stubEnv("XAI_API_KEY", "xai-secretref-key");
264263265-expect(
266-resolveXaiToolApiKey({
264+await expect(
265+resolveXaiToolApiKeyWithAuth({
267266sourceConfig: {
268267secrets: {
269268providers: {
@@ -290,14 +289,14 @@ describe("xai tool auth helpers", () => {
290289},
291290},
292291}),
293-).toBeUndefined();
292+).resolves.toBeUndefined();
294293});
295294296-it("does not resolve env SecretRefs when provider source is not env", () => {
295+it("does not resolve env SecretRefs when provider source is not env", async () => {
297296vi.stubEnv("XAI_API_KEY", "xai-secretref-key");
298297299-expect(
300-resolveXaiToolApiKey({
298+await expect(
299+resolveXaiToolApiKeyWithAuth({
301300sourceConfig: {
302301secrets: {
303302providers: {
@@ -324,6 +323,6 @@ describe("xai tool auth helpers", () => {
324323},
325324},
326325}),
327-).toBeUndefined();
326+).resolves.toBeUndefined();
328327});
329328});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。