@@ -4,24 +4,12 @@ import { tmpdir } from "node:os";
44import path from "node:path" ;
55import { afterEach , describe , expect , it } from "vitest" ;
66import type { OpenClawConfig } from "../config/types.openclaw.js" ;
7+ import { withEnvAsync } from "../test-utils/env.js" ;
78import { clearRuntimeAuthProfileStoreSnapshots } from "./auth-profiles.js" ;
89import { clearCurrentProviderAuthState } from "./model-provider-auth.js" ;
910import { runProviderAuthWarmWorkerInput } from "./model-provider-auth.worker.js" ;
1011
1112const tempDirs : string [ ] = [ ] ;
12- const envKeys = [ "OPENCLAW_DISABLE_PERSISTED_PLUGIN_REGISTRY" , "OPENCLAW_STATE_DIR" ] as const ;
13-
14- function restoreEnv ( previous : Record < ( typeof envKeys ) [ number ] , string | undefined > ) : void {
15- // Worker tests mutate process env to isolate state/plugin registry paths;
16- // restore exact previous values after each case.
17- for ( const key of envKeys ) {
18- if ( previous [ key ] === undefined ) {
19- delete process . env [ key ] ;
20- continue ;
21- }
22- process . env [ key ] = previous [ key ] ;
23- }
24- }
2513
2614describe ( "provider auth warm worker" , ( ) => {
2715 afterEach ( ( ) => {
@@ -37,52 +25,50 @@ describe("provider auth warm worker", () => {
3725 // carry them explicitly or warming loses provider availability.
3826 const root = mkdtempSync ( path . join ( tmpdir ( ) , "openclaw-provider-auth-worker-" ) ) ;
3927 tempDirs . push ( root ) ;
40- const previousEnv = Object . fromEntries ( envKeys . map ( ( key ) => [ key , process . env [ key ] ] ) ) as Record <
41- ( typeof envKeys ) [ number ] ,
42- string | undefined
43- > ;
44- process . env . OPENCLAW_DISABLE_PERSISTED_PLUGIN_REGISTRY = "1" ;
45- process . env . OPENCLAW_STATE_DIR = path . join ( root , "state" ) ;
4628
47- try {
48- const agentDir = path . join ( root , "agent" ) ;
49- const cfg = {
50- agents : { list : [ { id : "main" , agentDir } ] } ,
51- models : {
52- providers : {
53- "runtime-only" : {
54- baseUrl : "https://example.com/v1" ,
55- api : "openai" ,
56- models : [ { id : "runtime-model" , name : "Runtime Model" } ] ,
29+ await withEnvAsync (
30+ {
31+ OPENCLAW_DISABLE_PERSISTED_PLUGIN_REGISTRY : "1" ,
32+ OPENCLAW_STATE_DIR : path . join ( root , "state" ) ,
33+ } ,
34+ async ( ) => {
35+ const agentDir = path . join ( root , "agent" ) ;
36+ const cfg = {
37+ agents : { list : [ { id : "main" , agentDir } ] } ,
38+ models : {
39+ providers : {
40+ "runtime-only" : {
41+ baseUrl : "https://example.com/v1" ,
42+ api : "openai" ,
43+ models : [ { id : "runtime-model" , name : "Runtime Model" } ] ,
44+ } ,
5745 } ,
5846 } ,
59- } ,
60- } as unknown as OpenClawConfig ;
61- const result = await runProviderAuthWarmWorkerInput ( {
62- cfg ,
63- runtimeAuthStores : [
64- {
65- agentDir ,
66- store : {
67- version : 1 ,
68- profiles : {
69- "runtime-only:default" : {
70- type : "api_key " ,
71- provider : "runtime-only" ,
47+ } as unknown as OpenClawConfig ;
48+ const result = await runProviderAuthWarmWorkerInput ( {
49+ cfg ,
50+ runtimeAuthStores : [
51+ {
52+ agentDir ,
53+ store : {
54+ version : 1 ,
55+ profiles : {
56+ "runtime-only:default" : {
57+ type : "api_key" ,
58+ provider : "runtime-only " ,
59+ } ,
7260 } ,
7361 } ,
7462 } ,
75- } ,
76- ] ,
77- } ) ;
63+ ] ,
64+ } ) ;
7865
79- expect ( result . status ) . toBe ( "ok" ) ;
80- if ( result . status !== "ok" ) {
81- return ;
82- }
83- expect ( result . snapshot . agents [ 0 ] ?. providers ) . toContainEqual ( [ "runtime-only" , true ] ) ;
84- } finally {
85- restoreEnv ( previousEnv ) ;
86- }
66+ expect ( result . status ) . toBe ( "ok" ) ;
67+ if ( result . status !== "ok" ) {
68+ return ;
69+ }
70+ expect ( result . snapshot . agents [ 0 ] ?. providers ) . toContainEqual ( [ "runtime-only" , true ] ) ;
71+ } ,
72+ ) ;
8773 } , 30_000 ) ;
8874} ) ;
0 commit comments