@@ -125,12 +125,15 @@ function createSecretsApplyResult(options?: {
125125 } ;
126126}
127127
128- async function withPlanFile ( run : ( planPath : string ) => Promise < void > ) {
128+ async function withPlanFile (
129+ run : ( planPath : string ) => Promise < void > ,
130+ contents = `${ JSON . stringify ( createManualSecretsPlan ( ) ) } \n` ,
131+ ) {
129132 const planPath = path . join (
130133 os . tmpdir ( ) ,
131134 `openclaw-secrets-cli-test-${ Date . now ( ) } -${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } .json` ,
132135 ) ;
133- await fs . writeFile ( planPath , ` ${ JSON . stringify ( createManualSecretsPlan ( ) ) } \n` , "utf8" ) ;
136+ await fs . writeFile ( planPath , contents , "utf8" ) ;
134137 try {
135138 await run ( planPath ) ;
136139 } finally {
@@ -386,19 +389,14 @@ describe("secrets CLI", () => {
386389 } ) ;
387390
388391 it ( "shows a user-friendly error when the secrets plan file is malformed JSON" , async ( ) => {
389- const planPath = path . join (
390- os . tmpdir ( ) ,
391- `openclaw-secrets-cli-test-${ Date . now ( ) } -${ Math . random ( ) . toString ( 16 ) . slice ( 2 ) } .json` ,
392- ) ;
393- await fs . writeFile ( planPath , "{invalid json" , "utf8" ) ;
394- try {
395- await createProgram ( ) . parseAsync ( [ "secrets" , "apply" , "--from" , planPath ] , { from : "user" } ) ;
396- } catch {
397- // exitOverride converts exit(1) to CommanderError
398- }
399- expect ( defaultRuntime . error ) . toHaveBeenCalledWith (
400- expect . stringContaining ( "Malformed JSON in secrets plan file:" ) ,
401- ) ;
392+ await withPlanFile ( async ( planPath ) => {
393+ await expect (
394+ createProgram ( ) . parseAsync ( [ "secrets" , "apply" , "--from" , planPath ] , { from : "user" } ) ,
395+ ) . rejects . toThrow ( "__exit__:1" ) ;
396+
397+ expect ( runtimeErrors . at ( - 1 ) ) . toContain ( `Malformed JSON in secrets plan file: ${ planPath } ` ) ;
398+ expect ( runSecretsApply ) . not . toHaveBeenCalled ( ) ;
399+ } , "{invalid json" ) ;
402400 } ) ;
403401
404402 it ( "does not print skipped-exec note when apply dry-run skippedExecRefs is zero" , async ( ) => {
0 commit comments