11// Auth choice tests cover auth choice application, provider config, and credential prompts.
2- import fs from "node:fs/promises" ;
32import path from "node:path" ;
43import { afterAll , afterEach , beforeAll , describe , expect , it , vi } from "vitest" ;
4+ import {
5+ createAuthTestLifecycle ,
6+ createExitThrowingRuntime ,
7+ createWizardPrompter ,
8+ setupAuthTestEnv ,
9+ } from "../../test/helpers/auth-wizard.js" ;
510import { resolveAgentDir } from "../agents/agent-scope.js" ;
611import type { OpenClawConfig } from "../config/config.js" ;
712import { resolveAgentModelPrimaryValue } from "../config/model-input.js" ;
@@ -10,12 +15,6 @@ import * as providerAuthChoices from "../plugins/provider-auth-choices.js";
1015import type { ProviderAuthMethod , ProviderAuthResult , ProviderPlugin } from "../plugins/types.js" ;
1116import type { WizardPrompter } from "../wizard/prompts.js" ;
1217import { applyAuthChoice } from "./auth-choice.apply.js" ;
13- import {
14- createAuthTestLifecycle ,
15- createExitThrowingRuntime ,
16- createWizardPrompter ,
17- setupAuthTestEnv ,
18- } from "./test-wizard-helpers.js" ;
1918
2019type DetectZaiEndpoint = ( params : {
2120 apiKey : string ;
@@ -605,6 +604,7 @@ describe("applyAuthChoice", () => {
605604 "SYNTHETIC_API_KEY" ,
606605 ] ) ;
607606 let authTestRoot : string | null = null ;
607+ let authTestCleanup : ( ( ) => Promise < void > ) | null = null ;
608608 let authStateCounter = 0 ;
609609 async function setupTempState ( ) {
610610 if ( ! authTestRoot ) {
@@ -683,15 +683,15 @@ describe("applyAuthChoice", () => {
683683 let defaultProviderPlugins : ProviderPlugin [ ] = [ ] ;
684684
685685 beforeAll ( async ( ) => {
686- authTestRoot = ( await setupAuthTestEnv ( "openclaw-auth-" ) ) . stateDir ;
686+ const authTestEnv = await setupAuthTestEnv ( "openclaw-auth-" ) ;
687+ authTestRoot = authTestEnv . stateDir ;
688+ authTestCleanup = authTestEnv . cleanup ;
687689 defaultProviderPlugins = await createDefaultProviderPlugins ( ) ;
688690 resolvePluginProviders . mockReturnValue ( defaultProviderPlugins ) ;
689691 } ) ;
690692
691693 afterAll ( async ( ) => {
692- if ( authTestRoot ) {
693- await fs . rm ( authTestRoot , { recursive : true , force : true } ) ;
694- }
694+ await authTestCleanup ?.( ) ;
695695 } ) ;
696696
697697 afterEach ( async ( ) => {
0 commit comments