Skip to content

Commit c413503

Browse files
LZY3538claude
andcommitted
test(tavily): add SecretRef resolution regression tests
Cover the three classified outcomes of the guarded SecretRef resolver: - Plain string apiKey resolved directly - Missing config falls back to process.env - Env-source unresolvable SecretRef allowed to fall back - File-source SecretRef blocks env fallback (explicit config boundary) - Exec-source SecretRef blocks env fallback - No config and no env returns undefined 6 tests pass. This protects against the regression where a non-env SecretRef is silently replaced by ambient process.env, per ClawSweeper rank-up recommendation. Co-Authored-By: Claude <[email protected]>
1 parent 3da4ef2 commit c413503

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Tavily config tests cover SecretRef resolution and env fallback behavior.
2+
import { afterEach, describe, expect, it } from "vitest";
3+
import { resolveTavilyApiKey } from "./config.js";
4+
5+
describe("resolveTavilyApiKey", () => {
6+
const originalEnv = process.env.TAVILY_API_KEY;
7+
8+
afterEach(() => {
9+
if (originalEnv === undefined) {
10+
delete process.env.TAVILY_API_KEY;
11+
} else {
12+
process.env.TAVILY_API_KEY = originalEnv;
13+
}
14+
});
15+
16+
it("returns a plain string apiKey as-is", () => {
17+
expect(
18+
resolveTavilyApiKey({
19+
plugins: {
20+
entries: {
21+
tavily: { config: { webSearch: { apiKey: "tvly-abc123" } } },
22+
},
23+
},
24+
} as never),
25+
).toBe("tvly-abc123");
26+
});
27+
28+
it("falls back to process.env when no apiKey is configured", () => {
29+
process.env.TAVILY_API_KEY = "env-fallback-key";
30+
expect(resolveTavilyApiKey({} as never)).toBe("env-fallback-key");
31+
});
32+
33+
it("returns undefined when no apiKey and no env var", () => {
34+
delete process.env.TAVILY_API_KEY;
35+
expect(resolveTavilyApiKey({} as never)).toBeUndefined();
36+
});
37+
38+
it("allows env fallback when an env-source SecretRef is unresolvable", () => {
39+
process.env.TAVILY_API_KEY = "runtime-env-key";
40+
expect(
41+
resolveTavilyApiKey({
42+
plugins: {
43+
entries: {
44+
tavily: {
45+
config: {
46+
webSearch: {
47+
apiKey: {
48+
source: "env",
49+
provider: "default",
50+
id: "TAVILY_API_KEY",
51+
},
52+
},
53+
},
54+
},
55+
},
56+
},
57+
} as never),
58+
).toBe("runtime-env-key");
59+
});
60+
61+
it("blocks env fallback when a file-source SecretRef is configured", () => {
62+
process.env.TAVILY_API_KEY = "ambient-key";
63+
expect(
64+
resolveTavilyApiKey({
65+
plugins: {
66+
entries: {
67+
tavily: {
68+
config: {
69+
webSearch: {
70+
apiKey: {
71+
source: "file",
72+
provider: "default",
73+
id: "/etc/secrets/tavily",
74+
},
75+
},
76+
},
77+
},
78+
},
79+
},
80+
} as never),
81+
).toBeUndefined();
82+
});
83+
84+
it("blocks env fallback when an exec-source SecretRef is configured", () => {
85+
process.env.TAVILY_API_KEY = "ambient-key";
86+
expect(
87+
resolveTavilyApiKey({
88+
plugins: {
89+
entries: {
90+
tavily: {
91+
config: {
92+
webSearch: {
93+
apiKey: {
94+
source: "exec",
95+
provider: "default",
96+
id: "get-tavily-key",
97+
},
98+
},
99+
},
100+
},
101+
},
102+
},
103+
} as never),
104+
).toBeUndefined();
105+
});
106+
});

0 commit comments

Comments
 (0)