@@ -20,22 +20,52 @@ export function withModelsTempHome<T>(fn: (home: string) => Promise<T>): Promise
2020 } ) ;
2121}
2222
23- export function installModelsConfigTestHooks ( opts ?: { restoreFetch ?: boolean } ) {
23+ export function installModelsConfigTestHooks ( opts ?: {
24+ restoreFetch ?: boolean ;
25+ resetPluginLoaderState ?: boolean ;
26+ resetProviderRuntimeHookCache ?: boolean ;
27+ } ) {
2428 let previousHome : string | undefined ;
29+ let previousOpenClawAgentDir : string | undefined ;
30+ let previousPiCodingAgentDir : string | undefined ;
2531 const originalFetch = globalThis . fetch ;
32+ const shouldResetPluginLoaderState = opts ?. resetPluginLoaderState !== false ;
33+ const shouldResetProviderRuntimeHookCache = opts ?. resetProviderRuntimeHookCache !== false ;
2634
2735 beforeEach ( ( ) => {
2836 previousHome = process . env . HOME ;
29- resetPluginLoaderTestStateForTest ( ) ;
37+ previousOpenClawAgentDir = process . env . OPENCLAW_AGENT_DIR ;
38+ previousPiCodingAgentDir = process . env . PI_CODING_AGENT_DIR ;
39+ delete process . env . OPENCLAW_AGENT_DIR ;
40+ delete process . env . PI_CODING_AGENT_DIR ;
41+ if ( shouldResetPluginLoaderState ) {
42+ resetPluginLoaderTestStateForTest ( ) ;
43+ }
3044 resetModelsJsonReadyCacheForTest ( ) ;
31- resetProviderRuntimeHookCacheForTest ( ) ;
45+ if ( shouldResetProviderRuntimeHookCache ) {
46+ resetProviderRuntimeHookCacheForTest ( ) ;
47+ }
3248 } ) ;
3349
3450 afterEach ( ( ) => {
3551 process . env . HOME = previousHome ;
36- resetPluginLoaderTestStateForTest ( ) ;
52+ if ( previousOpenClawAgentDir === undefined ) {
53+ delete process . env . OPENCLAW_AGENT_DIR ;
54+ } else {
55+ process . env . OPENCLAW_AGENT_DIR = previousOpenClawAgentDir ;
56+ }
57+ if ( previousPiCodingAgentDir === undefined ) {
58+ delete process . env . PI_CODING_AGENT_DIR ;
59+ } else {
60+ process . env . PI_CODING_AGENT_DIR = previousPiCodingAgentDir ;
61+ }
62+ if ( shouldResetPluginLoaderState ) {
63+ resetPluginLoaderTestStateForTest ( ) ;
64+ }
3765 resetModelsJsonReadyCacheForTest ( ) ;
38- resetProviderRuntimeHookCacheForTest ( ) ;
66+ if ( shouldResetProviderRuntimeHookCache ) {
67+ resetProviderRuntimeHookCacheForTest ( ) ;
68+ }
3969 if ( opts ?. restoreFetch && originalFetch ) {
4070 globalThis . fetch = originalFetch ;
4171 }
0 commit comments