@@ -4,11 +4,13 @@ import { join } from "node:path"
44import {
55 AGENTS_TARGET_DIR ,
66 checkVersionCompatibility ,
7+ createLogger ,
78 getAgentsSourceDir ,
89 getErrorMessage ,
910 getPackageRoot ,
1011 isTransientError ,
1112 MIN_CONTENT_LENGTH ,
13+ parseCliFlags ,
1214 parseFrontmatter ,
1315 REQUIRED_FRONTMATTER_FIELDS ,
1416 REQUIRED_KEYWORDS ,
@@ -760,4 +762,123 @@ This is a test agent that handles various tasks.
760762 } )
761763 } )
762764 } )
765+
766+ describe ( "parseCliFlags" , ( ) => {
767+ it ( "should return all false flags for empty argv" , ( ) => {
768+ const result = parseCliFlags ( [ ] )
769+ expect ( result ) . toEqual ( { dryRun : false , verbose : false , help : false } )
770+ } )
771+
772+ it ( "should return all false flags for argv without flags" , ( ) => {
773+ const result = parseCliFlags ( [ "node" , "script.js" ] )
774+ expect ( result ) . toEqual ( { dryRun : false , verbose : false , help : false } )
775+ } )
776+
777+ it ( "should detect --dry-run flag" , ( ) => {
778+ const result = parseCliFlags ( [ "node" , "script.js" , "--dry-run" ] )
779+ expect ( result . dryRun ) . toBe ( true )
780+ expect ( result . verbose ) . toBe ( false )
781+ expect ( result . help ) . toBe ( false )
782+ } )
783+
784+ it ( "should detect --verbose flag" , ( ) => {
785+ const result = parseCliFlags ( [ "node" , "script.js" , "--verbose" ] )
786+ expect ( result . dryRun ) . toBe ( false )
787+ expect ( result . verbose ) . toBe ( true )
788+ expect ( result . help ) . toBe ( false )
789+ } )
790+
791+ it ( "should detect --help flag" , ( ) => {
792+ const result = parseCliFlags ( [ "node" , "script.js" , "--help" ] )
793+ expect ( result . dryRun ) . toBe ( false )
794+ expect ( result . verbose ) . toBe ( false )
795+ expect ( result . help ) . toBe ( true )
796+ } )
797+
798+ it ( "should detect multiple flags" , ( ) => {
799+ const result = parseCliFlags ( [ "node" , "script.js" , "--dry-run" , "--verbose" ] )
800+ expect ( result . dryRun ) . toBe ( true )
801+ expect ( result . verbose ) . toBe ( true )
802+ expect ( result . help ) . toBe ( false )
803+ } )
804+
805+ it ( "should detect all flags" , ( ) => {
806+ const result = parseCliFlags ( [ "node" , "script.js" , "--dry-run" , "--verbose" , "--help" ] )
807+ expect ( result ) . toEqual ( { dryRun : true , verbose : true , help : true } )
808+ } )
809+
810+ it ( "should ignore unknown flags" , ( ) => {
811+ const result = parseCliFlags ( [ "node" , "script.js" , "--unknown" , "--other" ] )
812+ expect ( result ) . toEqual ( { dryRun : false , verbose : false , help : false } )
813+ } )
814+
815+ it ( "should handle flags in any position" , ( ) => {
816+ const result = parseCliFlags ( [ "--verbose" , "node" , "--dry-run" , "script.js" , "--help" ] )
817+ expect ( result ) . toEqual ( { dryRun : true , verbose : true , help : true } )
818+ } )
819+
820+ it ( "should not match partial flag names" , ( ) => {
821+ const result = parseCliFlags ( [ "node" , "script.js" , "--dry-run-test" , "--verbosity" ] )
822+ expect ( result . dryRun ) . toBe ( false )
823+ expect ( result . verbose ) . toBe ( false )
824+ } )
825+ } )
826+
827+ describe ( "createLogger" , ( ) => {
828+ it ( "should return an object with log and verbose methods" , ( ) => {
829+ const logger = createLogger ( false )
830+ expect ( typeof logger . log ) . toBe ( "function" )
831+ expect ( typeof logger . verbose ) . toBe ( "function" )
832+ } )
833+
834+ it ( "should log messages with log() method" , ( ) => {
835+ const originalLog = console . log
836+ const messages : string [ ] = [ ]
837+ console . log = ( msg : string ) => messages . push ( msg )
838+
839+ const logger = createLogger ( false )
840+ logger . log ( "test message" )
841+
842+ console . log = originalLog
843+ expect ( messages ) . toContain ( "test message" )
844+ } )
845+
846+ it ( "should not log verbose messages when verbose is false" , ( ) => {
847+ const originalLog = console . log
848+ const messages : string [ ] = [ ]
849+ console . log = ( msg : string ) => messages . push ( msg )
850+
851+ const logger = createLogger ( false )
852+ logger . verbose ( "verbose message" )
853+
854+ console . log = originalLog
855+ expect ( messages ) . toHaveLength ( 0 )
856+ } )
857+
858+ it ( "should log verbose messages with [VERBOSE] prefix when verbose is true" , ( ) => {
859+ const originalLog = console . log
860+ const messages : string [ ] = [ ]
861+ console . log = ( msg : string ) => messages . push ( msg )
862+
863+ const logger = createLogger ( true )
864+ logger . verbose ( "verbose message" )
865+
866+ console . log = originalLog
867+ expect ( messages ) . toContain ( "[VERBOSE] verbose message" )
868+ } )
869+
870+ it ( "should log both normal and verbose messages when verbose is true" , ( ) => {
871+ const originalLog = console . log
872+ const messages : string [ ] = [ ]
873+ console . log = ( msg : string ) => messages . push ( msg )
874+
875+ const logger = createLogger ( true )
876+ logger . log ( "normal message" )
877+ logger . verbose ( "verbose message" )
878+
879+ console . log = originalLog
880+ expect ( messages ) . toContain ( "normal message" )
881+ expect ( messages ) . toContain ( "[VERBOSE] verbose message" )
882+ } )
883+ } )
763884} )
0 commit comments