@@ -6,6 +6,7 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
66import type { ProviderAuthMethod , ProviderPlugin } from "../plugins/types.js" ;
77import type { RuntimeEnv } from "../runtime.js" ;
88import { resolveUserPath } from "../utils.js" ;
9+ import * as nonInteractiveApiKeys from "./onboard-non-interactive/api-keys.js" ;
910import { setupWizardCommand } from "./onboard.js" ;
1011
1112type ConfigSnapshotStub = {
@@ -261,12 +262,7 @@ describe("setupWizardCommand", () => {
261262 it ( "defaults --reset to config+creds+sessions scope" , async ( ) => {
262263 const runtime = makeRuntime ( ) ;
263264
264- await setupWizardCommand (
265- {
266- reset : true ,
267- } ,
268- runtime ,
269- ) ;
265+ await setupWizardCommand ( { reset : true } , runtime ) ;
270266
271267 expectResetCall ( { scope : "config+creds+sessions" , runtime } ) ;
272268 } ) ;
@@ -324,12 +320,7 @@ describe("setupWizardCommand", () => {
324320 } ,
325321 } ) ;
326322
327- await setupWizardCommand (
328- {
329- reset : true ,
330- } ,
331- runtime ,
332- ) ;
323+ await setupWizardCommand ( { reset : true } , runtime ) ;
333324
334325 expect ( mocks . handleReset ) . toHaveBeenCalledWith (
335326 "config+creds+sessions" ,
@@ -353,13 +344,7 @@ describe("setupWizardCommand", () => {
353344 } ,
354345 } ) ;
355346
356- await setupWizardCommand (
357- {
358- reset : true ,
359- resetScope : "full" ,
360- } ,
361- runtime ,
362- ) ;
347+ await setupWizardCommand ( { reset : true , resetScope : "full" } , runtime ) ;
363348
364349 expect ( mocks . handleReset ) . toHaveBeenCalledWith (
365350 "full" ,
@@ -388,13 +373,7 @@ describe("setupWizardCommand", () => {
388373 } as unknown as OpenClawConfig ,
389374 } ) ;
390375
391- await setupWizardCommand (
392- {
393- reset : true ,
394- resetScope : "full" ,
395- } ,
396- runtime ,
397- ) ;
376+ await setupWizardCommand ( { reset : true , resetScope : "full" } , runtime ) ;
398377
399378 expect ( runtime . error ) . toHaveBeenCalledWith (
400379 "Configured workspace is invalid. Pass --workspace with the workspace to remove, or use a narrower --reset-scope." ,
@@ -414,13 +393,7 @@ describe("setupWizardCommand", () => {
414393 readError : { code : "EACCES" } ,
415394 } ) ;
416395
417- await setupWizardCommand (
418- {
419- reset : true ,
420- resetScope : "full" ,
421- } ,
422- runtime ,
423- ) ;
396+ await setupWizardCommand ( { reset : true , resetScope : "full" } , runtime ) ;
424397
425398 expect ( runtime . error ) . toHaveBeenCalledWith (
426399 "Cannot determine the configured workspace from an unreadable config. Pass --workspace with the workspace to remove, or use a narrower --reset-scope." ,
@@ -437,13 +410,7 @@ describe("setupWizardCommand", () => {
437410 sourceConfig : { gateway : { port : 1 } } ,
438411 } ) ;
439412
440- await setupWizardCommand (
441- {
442- reset : true ,
443- resetScope : "full" ,
444- } ,
445- runtime ,
446- ) ;
413+ await setupWizardCommand ( { reset : true , resetScope : "full" } , runtime ) ;
447414
448415 expect ( mocks . handleReset ) . toHaveBeenCalledWith (
449416 "full" ,
@@ -455,13 +422,7 @@ describe("setupWizardCommand", () => {
455422 it ( "accepts explicit --reset-scope full" , async ( ) => {
456423 const runtime = makeRuntime ( ) ;
457424
458- await setupWizardCommand (
459- {
460- reset : true ,
461- resetScope : "full" ,
462- } ,
463- runtime ,
464- ) ;
425+ await setupWizardCommand ( { reset : true , resetScope : "full" } , runtime ) ;
465426
466427 expectResetCall ( { scope : "full" , runtime } ) ;
467428 } ) ;
@@ -490,12 +451,7 @@ describe("setupWizardCommand", () => {
490451 it ( "rejects --reset-scope without --reset" , async ( ) => {
491452 const runtime = makeRuntime ( ) ;
492453
493- await setupWizardCommand (
494- {
495- resetScope : "full" ,
496- } ,
497- runtime ,
498- ) ;
454+ await setupWizardCommand ( { resetScope : "full" } , runtime ) ;
499455
500456 expect ( runtime . error ) . toHaveBeenCalledWith (
501457 "--reset-scope requires --reset. Re-run with openclaw onboard --reset --reset-scope full." ,
@@ -876,6 +832,56 @@ describe("setupWizardCommand", () => {
876832 expect ( mocks . runNonInteractiveSetup ) . not . toHaveBeenCalled ( ) ;
877833 } ) ;
878834
835+ it . each ( [
836+ { agentName : "robby" , agentId : "robby" , scope : "config" , reuseProfile : true } ,
837+ { agentName : "Robby!" , agentId : "robby" , scope : "config" , reuseProfile : true } ,
838+ { agentName : undefined , agentId : "main" , scope : "config" , reuseProfile : true } ,
839+ { agentName : "robby" , agentId : "robby" , scope : "config+creds+sessions" , reuseProfile : false } ,
840+ { agentName : "robby" , agentId : "robby" , scope : "full" , reuseProfile : false } ,
841+ ] as const ) (
842+ "preflights $agentId provider profiles against reset scope $scope" ,
843+ async ( { agentName, agentId, scope, reuseProfile } ) => {
844+ const runtime = makeRuntime ( ) ;
845+ const workspaceDir = "/tmp/openclaw-reset-agent-workspace" ;
846+ const agentDirSuffix = path . join ( "agents" , agentId , "agent" ) ;
847+ const resolveApiKey = vi
848+ . spyOn ( nonInteractiveApiKeys , "resolveNonInteractiveApiKey" )
849+ . mockImplementation ( async ( input ) =>
850+ input . allowProfile && input . agentDir ?. endsWith ( agentDirSuffix )
851+ ? { key : "fixture-agent-profile-key" , source : "profile" }
852+ : null ,
853+ ) ;
854+
855+ try {
856+ await setupWizardCommand (
857+ {
858+ reset : true ,
859+ resetScope : scope ,
860+ nonInteractive : true ,
861+ acceptRisk : true ,
862+ agentName,
863+ workspace : workspaceDir ,
864+ authChoice : "apiKey" ,
865+ tokenProvider : "anthropic" ,
866+ } ,
867+ runtime ,
868+ ) ;
869+
870+ expect ( resolveApiKey ) . toHaveBeenCalledWith (
871+ expect . objectContaining ( {
872+ agentDir : expect . stringContaining ( agentDirSuffix ) ,
873+ workspaceDir,
874+ allowProfile : reuseProfile ,
875+ } ) ,
876+ ) ;
877+ expect ( mocks . handleReset ) . toHaveBeenCalledTimes ( reuseProfile ? 1 : 0 ) ;
878+ expect ( mocks . runNonInteractiveSetup ) . toHaveBeenCalledTimes ( reuseProfile ? 1 : 0 ) ;
879+ } finally {
880+ resolveApiKey . mockRestore ( ) ;
881+ }
882+ } ,
883+ ) ;
884+
879885 it . each ( localResetProviderCases ) (
880886 "validates $providerId exactly once before reset and non-interactive setup" ,
881887 async ( { providerId, methodId } ) => {
@@ -1115,28 +1121,21 @@ describe("setupWizardCommand", () => {
11151121 expect ( mocks . runInteractiveSetup ) . not . toHaveBeenCalled ( ) ;
11161122 } ) ;
11171123
1118- it ( "rejects conflicting classic and non-interactive modes" , async ( ) => {
1119- const runtime = makeRuntime ( ) ;
1120-
1121- await setupWizardCommand ( { classic : true , nonInteractive : true , acceptRisk : true } , runtime ) ;
1122-
1123- expect ( runtime . error ) . toHaveBeenCalledWith (
1124- "--classic cannot be combined with --non-interactive. Remove --non-interactive to open the classic wizard, or remove --classic for automated setup." ,
1125- ) ;
1126- expect ( runtime . exit ) . toHaveBeenCalledWith ( 1 ) ;
1127- expect ( mocks . runNonInteractiveSetup ) . not . toHaveBeenCalled ( ) ;
1128- expect ( mocks . runInteractiveSetup ) . not . toHaveBeenCalled ( ) ;
1129- expect ( mocks . runGuidedOnboarding ) . not . toHaveBeenCalled ( ) ;
1130- } ) ;
1131-
1132- it ( "rejects conflicting TUI and non-interactive modes" , async ( ) => {
1124+ it . each ( [
1125+ {
1126+ opts : { classic : true } ,
1127+ error :
1128+ "--classic cannot be combined with --non-interactive. Remove --non-interactive to open the classic wizard, or remove --classic for automated setup." ,
1129+ } ,
1130+ {
1131+ opts : { tui : true } ,
1132+ error :
1133+ "--tui cannot be combined with --non-interactive. Remove --tui for automation, or remove --non-interactive to open the terminal hatch." ,
1134+ } ,
1135+ ] ) ( "rejects conflicting $opts and non-interactive modes" , async ( { opts, error } ) => {
11331136 const runtime = makeRuntime ( ) ;
1134-
1135- await setupWizardCommand ( { tui : true , nonInteractive : true , acceptRisk : true } , runtime ) ;
1136-
1137- expect ( runtime . error ) . toHaveBeenCalledWith (
1138- "--tui cannot be combined with --non-interactive. Remove --tui for automation, or remove --non-interactive to open the terminal hatch." ,
1139- ) ;
1137+ await setupWizardCommand ( { ...opts , nonInteractive : true , acceptRisk : true } , runtime ) ;
1138+ expect ( runtime . error ) . toHaveBeenCalledWith ( error ) ;
11401139 expect ( runtime . exit ) . toHaveBeenCalledWith ( 1 ) ;
11411140 expect ( mocks . runNonInteractiveSetup ) . not . toHaveBeenCalled ( ) ;
11421141 expect ( mocks . runInteractiveSetup ) . not . toHaveBeenCalled ( ) ;
0 commit comments