|
1 | 1 | import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 2 |
|
3 | 3 | const mocks = vi.hoisted(() => ({ |
| 4 | + loadAuthProfileStoreForSecretsRuntime: vi.fn(), |
4 | 5 | resolvePreferredNodePath: vi.fn(), |
5 | 6 | resolveGatewayProgramArguments: vi.fn(), |
6 | 7 | resolveSystemNodeInfo: vi.fn(), |
7 | 8 | renderSystemNodeWarning: vi.fn(), |
8 | 9 | buildServiceEnvironment: vi.fn(), |
9 | 10 | })); |
10 | 11 |
|
| 12 | +vi.mock("../agents/auth-profiles.js", () => ({ |
| 13 | + loadAuthProfileStoreForSecretsRuntime: mocks.loadAuthProfileStoreForSecretsRuntime, |
| 14 | +})); |
| 15 | + |
11 | 16 | vi.mock("../daemon/runtime-paths.js", () => ({ |
12 | 17 | resolvePreferredNodePath: mocks.resolvePreferredNodePath, |
13 | 18 | resolveSystemNodeInfo: mocks.resolveSystemNodeInfo, |
@@ -63,6 +68,10 @@ function mockNodeGatewayPlanFixture( |
63 | 68 | programArguments: ["node", "gateway"], |
64 | 69 | workingDirectory, |
65 | 70 | }); |
| 71 | + mocks.loadAuthProfileStoreForSecretsRuntime.mockReturnValue({ |
| 72 | + version: 1, |
| 73 | + profiles: {}, |
| 74 | + }); |
66 | 75 | mocks.resolveSystemNodeInfo.mockResolvedValue({ |
67 | 76 | path: "/opt/node", |
68 | 77 | version, |
@@ -232,6 +241,67 @@ describe("buildGatewayInstallPlan", () => { |
232 | 241 | expect(plan.environment.HOME).toBe("/Users/service"); |
233 | 242 | expect(plan.environment.OPENCLAW_PORT).toBe("3000"); |
234 | 243 | }); |
| 244 | + |
| 245 | + it("merges env-backed auth-profile refs into the service environment", async () => { |
| 246 | + mockNodeGatewayPlanFixture({ |
| 247 | + serviceEnvironment: { |
| 248 | + OPENCLAW_PORT: "3000", |
| 249 | + }, |
| 250 | + }); |
| 251 | + mocks.loadAuthProfileStoreForSecretsRuntime.mockReturnValue({ |
| 252 | + version: 1, |
| 253 | + profiles: { |
| 254 | + "openai:default": { |
| 255 | + type: "api_key", |
| 256 | + provider: "openai", |
| 257 | + keyRef: { source: "env", provider: "default", id: "OPENAI_API_KEY" }, |
| 258 | + }, |
| 259 | + "anthropic:default": { |
| 260 | + type: "token", |
| 261 | + provider: "anthropic", |
| 262 | + tokenRef: { source: "env", provider: "default", id: "ANTHROPIC_TOKEN" }, |
| 263 | + }, |
| 264 | + }, |
| 265 | + }); |
| 266 | + |
| 267 | + const plan = await buildGatewayInstallPlan({ |
| 268 | + env: { |
| 269 | + OPENAI_API_KEY: "sk-openai-test", // pragma: allowlist secret |
| 270 | + ANTHROPIC_TOKEN: "ant-test-token", |
| 271 | + }, |
| 272 | + port: 3000, |
| 273 | + runtime: "node", |
| 274 | + }); |
| 275 | + |
| 276 | + expect(plan.environment.OPENAI_API_KEY).toBe("sk-openai-test"); |
| 277 | + expect(plan.environment.ANTHROPIC_TOKEN).toBe("ant-test-token"); |
| 278 | + }); |
| 279 | + |
| 280 | + it("skips unresolved auth-profile env refs", async () => { |
| 281 | + mockNodeGatewayPlanFixture({ |
| 282 | + serviceEnvironment: { |
| 283 | + OPENCLAW_PORT: "3000", |
| 284 | + }, |
| 285 | + }); |
| 286 | + mocks.loadAuthProfileStoreForSecretsRuntime.mockReturnValue({ |
| 287 | + version: 1, |
| 288 | + profiles: { |
| 289 | + "openai:default": { |
| 290 | + type: "api_key", |
| 291 | + provider: "openai", |
| 292 | + keyRef: { source: "env", provider: "default", id: "OPENAI_API_KEY" }, |
| 293 | + }, |
| 294 | + }, |
| 295 | + }); |
| 296 | + |
| 297 | + const plan = await buildGatewayInstallPlan({ |
| 298 | + env: {}, |
| 299 | + port: 3000, |
| 300 | + runtime: "node", |
| 301 | + }); |
| 302 | + |
| 303 | + expect(plan.environment.OPENAI_API_KEY).toBeUndefined(); |
| 304 | + }); |
235 | 305 | }); |
236 | 306 |
|
237 | 307 | describe("gatewayInstallErrorHint", () => { |
|
0 commit comments