1- import { describe , expect , it , vi } from "vitest" ;
1+ import { beforeEach , describe , expect , it , vi } from "vitest" ;
22import type { OpenClawConfig } from "../config/types.openclaw.js" ;
33
44const 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+
1926vi . mock ( "./auth-profiles/store.js" , ( ) => storeMocks ) ;
2027
2128vi . mock ( "./pi-auth-credentials.js" , ( ) => credentialMocks ) ;
2229
2330vi . mock ( "./pi-auth-discovery-core.js" , ( ) => discoveryCoreMocks ) ;
2431
2532vi . mock ( "./synthetic-auth.runtime.js" , ( ) => ( {
26- resolveRuntimeSyntheticAuthProviderRefs : ( ) => [ ] ,
33+ resolveRuntimeSyntheticAuthProviderRefs :
34+ syntheticAuthMocks . resolveRuntimeSyntheticAuthProviderRefs ,
2735} ) ) ;
2836
2937vi . mock ( "../plugins/provider-runtime.js" , ( ) => ( {
30- resolveProviderSyntheticAuthWithPlugin : vi . fn ( ) ,
38+ resolveProviderSyntheticAuthWithPlugin : syntheticAuthMocks . resolveProviderSyntheticAuthWithPlugin ,
3139} ) ) ;
3240
3341import { externalCliDiscoveryForProviders } from "./auth-profiles/external-cli-discovery.js" ;
3442import { resolvePiCredentialsForDiscovery } from "./pi-auth-discovery.js" ;
3543
3644describe ( "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} ) ;
0 commit comments