|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | +import type { OpenClawConfig } from "../config/types.openclaw.js"; |
| 3 | + |
| 4 | +const storeMocks = vi.hoisted(() => ({ |
| 5 | + ensureAuthProfileStore: vi.fn(() => ({ version: 1, profiles: {} })), |
| 6 | + loadAuthProfileStoreForRuntime: vi.fn(() => ({ version: 1, profiles: {} })), |
| 7 | + loadAuthProfileStoreForSecretsRuntime: vi.fn(() => ({ version: 1, profiles: {} })), |
| 8 | +})); |
| 9 | + |
| 10 | +const credentialMocks = vi.hoisted(() => ({ |
| 11 | + resolvePiCredentialMapFromStore: vi.fn(() => ({})), |
| 12 | +})); |
| 13 | + |
| 14 | +const discoveryCoreMocks = vi.hoisted(() => ({ |
| 15 | + addEnvBackedPiCredentials: vi.fn((credentials: unknown) => credentials), |
| 16 | + scrubLegacyStaticAuthJsonEntriesForDiscovery: vi.fn(), |
| 17 | +})); |
| 18 | + |
| 19 | +vi.mock("./auth-profiles/store.js", () => storeMocks); |
| 20 | + |
| 21 | +vi.mock("./pi-auth-credentials.js", () => credentialMocks); |
| 22 | + |
| 23 | +vi.mock("./pi-auth-discovery-core.js", () => discoveryCoreMocks); |
| 24 | + |
| 25 | +vi.mock("./synthetic-auth.runtime.js", () => ({ |
| 26 | + resolveRuntimeSyntheticAuthProviderRefs: () => [], |
| 27 | +})); |
| 28 | + |
| 29 | +vi.mock("../plugins/provider-runtime.js", () => ({ |
| 30 | + resolveProviderSyntheticAuthWithPlugin: vi.fn(), |
| 31 | +})); |
| 32 | + |
| 33 | +import { externalCliDiscoveryForProviders } from "./auth-profiles/external-cli-discovery.js"; |
| 34 | +import { resolvePiCredentialsForDiscovery } from "./pi-auth-discovery.js"; |
| 35 | + |
| 36 | +describe("resolvePiCredentialsForDiscovery external CLI scoping", () => { |
| 37 | + it("threads scoped external CLI discovery into writable auth store loading", () => { |
| 38 | + const cfg = {} as OpenClawConfig; |
| 39 | + const externalCli = externalCliDiscoveryForProviders({ |
| 40 | + cfg, |
| 41 | + providers: ["fireworks"], |
| 42 | + }); |
| 43 | + |
| 44 | + resolvePiCredentialsForDiscovery("/tmp/openclaw-agent", { |
| 45 | + config: cfg, |
| 46 | + env: {}, |
| 47 | + externalCli, |
| 48 | + }); |
| 49 | + |
| 50 | + expect(storeMocks.ensureAuthProfileStore).toHaveBeenCalledWith("/tmp/openclaw-agent", { |
| 51 | + allowKeychainPrompt: false, |
| 52 | + config: cfg, |
| 53 | + externalCli, |
| 54 | + }); |
| 55 | + expect(storeMocks.loadAuthProfileStoreForRuntime).not.toHaveBeenCalled(); |
| 56 | + }); |
| 57 | + |
| 58 | + it("preserves scoped external CLI discovery for read-only auth store loading", () => { |
| 59 | + const cfg = {} as OpenClawConfig; |
| 60 | + const externalCli = externalCliDiscoveryForProviders({ |
| 61 | + cfg, |
| 62 | + providers: ["fireworks"], |
| 63 | + }); |
| 64 | + |
| 65 | + resolvePiCredentialsForDiscovery("/tmp/openclaw-agent", { |
| 66 | + config: cfg, |
| 67 | + env: {}, |
| 68 | + externalCli, |
| 69 | + readOnly: true, |
| 70 | + }); |
| 71 | + |
| 72 | + expect(storeMocks.loadAuthProfileStoreForRuntime).toHaveBeenCalledWith("/tmp/openclaw-agent", { |
| 73 | + allowKeychainPrompt: false, |
| 74 | + config: cfg, |
| 75 | + externalCli, |
| 76 | + readOnly: true, |
| 77 | + }); |
| 78 | + }); |
| 79 | +}); |
0 commit comments