@@ -741,6 +741,67 @@ describe("loadConfig", () => {
741741 }
742742 } ) ;
743743
744+ test ( "--help after flags throws CliHelpError" , async ( ) => {
745+ await expect (
746+ loadConfig ( [ "--force" , "--help" ] , { globalSettingsPath : NO_SETTINGS } ) ,
747+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
748+ await expect (
749+ loadConfig ( [ "--force" , "-h" ] , { globalSettingsPath : NO_SETTINGS } ) ,
750+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
751+ } ) ;
752+
753+ test ( "--help after a positional throws CliHelpError" , async ( ) => {
754+ await expect (
755+ loadConfig ( [ "ship it" , "--help" ] , { globalSettingsPath : NO_SETTINGS } ) ,
756+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
757+ } ) ;
758+
759+ test ( "resume -h / --help throws CliHelpError instead of treating it as a session id" , async ( ) => {
760+ await expect (
761+ loadConfig ( [ "resume" , "-h" ] , { globalSettingsPath : NO_SETTINGS } ) ,
762+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
763+ await expect (
764+ loadConfig ( [ "resume" , "--help" ] , { globalSettingsPath : NO_SETTINGS } ) ,
765+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
766+ await expect (
767+ loadConfig ( [ "continue" , "-h" ] , { globalSettingsPath : NO_SETTINGS } ) ,
768+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
769+ } ) ;
770+
771+ test ( "value flags do not swallow --help / -h as their value" , async ( ) => {
772+ for ( const flag of [ "--provider" , "--model" , "--cwd" , "--config" , "--profile" ] as const ) {
773+ await expect (
774+ loadConfig ( [ flag , "--help" ] , { globalSettingsPath : NO_SETTINGS } ) ,
775+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
776+ await expect (
777+ loadConfig ( [ flag , "-h" ] , { globalSettingsPath : NO_SETTINGS } ) ,
778+ ) . rejects . toBeInstanceOf ( CliHelpError ) ;
779+ }
780+ } ) ;
781+
782+ test ( "value flags reject other flag-shaped tokens as values" , async ( ) => {
783+ await expect (
784+ loadConfig ( [ "--provider" , "--force" ] , { globalSettingsPath : NO_SETTINGS } ) ,
785+ ) . rejects . toThrow ( "--provider requires a value" ) ;
786+ await expect (
787+ loadConfig ( [ "--model" , "--cwd" ] , { globalSettingsPath : NO_SETTINGS } ) ,
788+ ) . rejects . toThrow ( "--model requires a value" ) ;
789+ await expect (
790+ loadConfig ( [ "exec" , "--director" , "--force" , "ship it" ] , {
791+ globalSettingsPath : NO_SETTINGS ,
792+ } ) ,
793+ ) . rejects . toThrow ( "--director requires a value" ) ;
794+ } ) ;
795+
796+ test ( "value flags still error clearly when the value is omitted" , async ( ) => {
797+ await expect ( loadConfig ( [ "--provider" ] , { globalSettingsPath : NO_SETTINGS } ) ) . rejects . toThrow (
798+ "--provider requires a value" ,
799+ ) ;
800+ await expect ( loadConfig ( [ "--model" ] , { globalSettingsPath : NO_SETTINGS } ) ) . rejects . toThrow (
801+ "--model requires a value" ,
802+ ) ;
803+ } ) ;
804+
744805 test ( "rejects unknown flags" , async ( ) => {
745806 await expect ( loadConfig ( [ "--unknown" ] , { globalSettingsPath : NO_SETTINGS } ) ) . rejects . toThrow (
746807 / u n r e c o g n i z e d f l a g / ,
0 commit comments