Skip to content

Commit c3a0fb9

Browse files
committed
test(live): bound provider discovery hooks
1 parent 3b1921b commit c3a0fb9

3 files changed

Lines changed: 66 additions & 10 deletions

File tree

src/agents/models.profiles.live.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,18 @@ describeLive("live models (profile keys)", () => {
732732
}
733733

734734
const providers = parseProviderFilter(process.env.OPENCLAW_LIVE_PROVIDERS);
735+
const providerList = providers ? [...providers] : null;
735736
const agentDir = resolveOpenClawAgentDir();
736737
const authStorage = discoverAuthStorage(agentDir, {
737738
config: cfg,
738739
env: process.env,
739-
...(providers ? { externalCli: externalCliDiscoveryForProviders({ cfg, providers }) } : {}),
740+
...(providerList
741+
? {
742+
externalCli: externalCliDiscoveryForProviders({ cfg, providers: providerList }),
743+
skipExternalAuthProfiles: true,
744+
syntheticAuthProviderRefs: providerList,
745+
}
746+
: {}),
740747
});
741748
logProgress("[live-models] loading model registry");
742749
const models = await withLiveStageTimeout(

src/agents/pi-auth-discovery.external-cli.test.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { describe, expect, it, vi } from "vitest";
1+
import { beforeEach, describe, expect, it, vi } from "vitest";
22
import type { OpenClawConfig } from "../config/types.openclaw.js";
33

44
const storeMocks = vi.hoisted(() => ({
55
ensureAuthProfileStore: vi.fn(() => ({ version: 1, profiles: {} })),
6+
ensureAuthProfileStoreWithoutExternalProfiles: vi.fn(() => ({ version: 1, profiles: {} })),
7+
loadAuthProfileStoreWithoutExternalProfiles: vi.fn(() => ({ version: 1, profiles: {} })),
68
loadAuthProfileStoreForRuntime: vi.fn(() => ({ version: 1, profiles: {} })),
79
loadAuthProfileStoreForSecretsRuntime: vi.fn(() => ({ version: 1, profiles: {} })),
810
}));
@@ -16,24 +18,34 @@ const discoveryCoreMocks = vi.hoisted(() => ({
1618
scrubLegacyStaticAuthJsonEntriesForDiscovery: vi.fn(),
1719
}));
1820

21+
const syntheticAuthMocks = vi.hoisted(() => ({
22+
resolveRuntimeSyntheticAuthProviderRefs: vi.fn(() => []),
23+
resolveProviderSyntheticAuthWithPlugin: vi.fn(),
24+
}));
25+
1926
vi.mock("./auth-profiles/store.js", () => storeMocks);
2027

2128
vi.mock("./pi-auth-credentials.js", () => credentialMocks);
2229

2330
vi.mock("./pi-auth-discovery-core.js", () => discoveryCoreMocks);
2431

2532
vi.mock("./synthetic-auth.runtime.js", () => ({
26-
resolveRuntimeSyntheticAuthProviderRefs: () => [],
33+
resolveRuntimeSyntheticAuthProviderRefs:
34+
syntheticAuthMocks.resolveRuntimeSyntheticAuthProviderRefs,
2735
}));
2836

2937
vi.mock("../plugins/provider-runtime.js", () => ({
30-
resolveProviderSyntheticAuthWithPlugin: vi.fn(),
38+
resolveProviderSyntheticAuthWithPlugin: syntheticAuthMocks.resolveProviderSyntheticAuthWithPlugin,
3139
}));
3240

3341
import { externalCliDiscoveryForProviders } from "./auth-profiles/external-cli-discovery.js";
3442
import { resolvePiCredentialsForDiscovery } from "./pi-auth-discovery.js";
3543

3644
describe("resolvePiCredentialsForDiscovery external CLI scoping", () => {
45+
beforeEach(() => {
46+
vi.clearAllMocks();
47+
});
48+
3749
it("threads scoped external CLI discovery into writable auth store loading", () => {
3850
const cfg = {} as OpenClawConfig;
3951
const externalCli = externalCliDiscoveryForProviders({
@@ -76,4 +88,29 @@ describe("resolvePiCredentialsForDiscovery external CLI scoping", () => {
7688
readOnly: true,
7789
});
7890
});
91+
92+
it("can skip runtime external auth overlays and scope synthetic auth discovery", () => {
93+
resolvePiCredentialsForDiscovery("/tmp/openclaw-agent", {
94+
env: {},
95+
skipExternalAuthProfiles: true,
96+
syntheticAuthProviderRefs: ["fireworks"],
97+
});
98+
99+
expect(storeMocks.ensureAuthProfileStoreWithoutExternalProfiles).toHaveBeenCalledWith(
100+
"/tmp/openclaw-agent",
101+
{
102+
allowKeychainPrompt: false,
103+
},
104+
);
105+
expect(storeMocks.ensureAuthProfileStore).not.toHaveBeenCalled();
106+
expect(syntheticAuthMocks.resolveRuntimeSyntheticAuthProviderRefs).not.toHaveBeenCalled();
107+
expect(syntheticAuthMocks.resolveProviderSyntheticAuthWithPlugin).toHaveBeenCalledWith({
108+
provider: "fireworks",
109+
context: {
110+
config: undefined,
111+
provider: "fireworks",
112+
providerConfig: undefined,
113+
},
114+
});
115+
});
79116
});

src/agents/pi-auth-discovery.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { resolveRuntimeSyntheticAuthProviderRefs } from "../plugins/synthetic-au
33
import type { ExternalCliAuthDiscovery } from "./auth-profiles/external-cli-discovery.js";
44
import {
55
ensureAuthProfileStore,
6+
ensureAuthProfileStoreWithoutExternalProfiles,
7+
loadAuthProfileStoreWithoutExternalProfiles,
68
loadAuthProfileStoreForRuntime,
79
loadAuthProfileStoreForSecretsRuntime,
810
} from "./auth-profiles/store.js";
@@ -15,7 +17,9 @@ import {
1517
export type DiscoverAuthStorageOptions = {
1618
externalCli?: ExternalCliAuthDiscovery;
1719
readOnly?: boolean;
20+
skipExternalAuthProfiles?: boolean;
1821
skipCredentials?: boolean;
22+
syntheticAuthProviderRefs?: Iterable<string>;
1923
} & PiDiscoveryAuthLookupOptions;
2024

2125
export function resolvePiCredentialsForDiscovery(
@@ -28,17 +32,25 @@ export function resolvePiCredentialsForDiscovery(
2832
...(options?.externalCli ? { externalCli: options.externalCli } : {}),
2933
};
3034
const store =
31-
options?.readOnly === true
32-
? options.externalCli || options.config
33-
? loadAuthProfileStoreForRuntime(agentDir, { readOnly: true, ...storeOptions })
34-
: loadAuthProfileStoreForSecretsRuntime(agentDir)
35-
: ensureAuthProfileStore(agentDir, storeOptions);
35+
options?.skipExternalAuthProfiles === true
36+
? options.readOnly === true
37+
? loadAuthProfileStoreWithoutExternalProfiles(agentDir)
38+
: ensureAuthProfileStoreWithoutExternalProfiles(agentDir, {
39+
allowKeychainPrompt: false,
40+
})
41+
: options?.readOnly === true
42+
? options.externalCli || options.config
43+
? loadAuthProfileStoreForRuntime(agentDir, { readOnly: true, ...storeOptions })
44+
: loadAuthProfileStoreForSecretsRuntime(agentDir)
45+
: ensureAuthProfileStore(agentDir, storeOptions);
3646
const credentials = addEnvBackedPiCredentials(resolvePiCredentialMapFromStore(store), {
3747
config: options?.config,
3848
workspaceDir: options?.workspaceDir,
3949
env: options?.env,
4050
});
41-
for (const provider of resolveRuntimeSyntheticAuthProviderRefs()) {
51+
const syntheticAuthProviderRefs =
52+
options?.syntheticAuthProviderRefs ?? resolveRuntimeSyntheticAuthProviderRefs();
53+
for (const provider of syntheticAuthProviderRefs) {
4254
if (credentials[provider]) {
4355
continue;
4456
}

0 commit comments

Comments
 (0)