@@ -34,79 +34,79 @@ const mockCore = {
3434 describe ( "check_command_position.cjs" , ( ) => {
3535 let checkCommandPositionScript , originalEnv ;
3636 ( beforeEach ( ( ) => {
37- ( vi . clearAllMocks ( ) , ( originalEnv = { GH_AW_COMMAND : process . env . GH_AW_COMMAND } ) ) ;
37+ ( vi . clearAllMocks ( ) , ( originalEnv = { GH_AW_COMMANDS : process . env . GH_AW_COMMANDS } ) ) ;
3838 const scriptPath = path . join ( __dirname , "check_command_position.cjs" ) ;
3939 ( ( checkCommandPositionScript = fs . readFileSync ( scriptPath , "utf8" ) ) , ( mockContext . eventName = "issues" ) , ( mockContext . payload = { } ) ) ;
4040 } ) ,
4141 afterEach ( ( ) => {
42- void 0 !== originalEnv . GH_AW_COMMAND ? ( process . env . GH_AW_COMMAND = originalEnv . GH_AW_COMMAND ) : delete process . env . GH_AW_COMMAND ;
42+ void 0 !== originalEnv . GH_AW_COMMANDS ? ( process . env . GH_AW_COMMANDS = originalEnv . GH_AW_COMMANDS ) : delete process . env . GH_AW_COMMANDS ;
4343 } ) ,
44- it ( "should fail when GH_AW_COMMAND is not set" , async ( ) => {
45- ( delete process . env . GH_AW_COMMAND , await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) , expect ( mockCore . setFailed ) . toHaveBeenCalledWith ( "Configuration error: GH_AW_COMMAND not specified." ) ) ;
44+ it ( "should fail when GH_AW_COMMANDS is not set" , async ( ) => {
45+ ( delete process . env . GH_AW_COMMANDS , await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) , expect ( mockCore . setFailed ) . toHaveBeenCalledWith ( "Configuration error: GH_AW_COMMANDS not specified." ) ) ;
4646 } ) ,
4747 it ( "should pass when command is the first word in issue body" , async ( ) => {
48- ( ( process . env . GH_AW_COMMAND = "test-bot" ) ,
48+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "test-bot" ] ) ) ,
4949 ( mockContext . eventName = "issues" ) ,
5050 ( mockContext . payload = { issue : { body : "/test-bot please help with this issue" } } ) ,
5151 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
5252 expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true" ) ,
53- expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "Command '/test-bot' is at the start" ) ) ) ;
53+ expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "matched at the start" ) ) ) ;
5454 } ) ,
5555 it ( "should fail when command is not the first word in issue body" , async ( ) => {
56- ( ( process . env . GH_AW_COMMAND = "test-bot" ) ,
56+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "test-bot" ] ) ) ,
5757 ( mockContext . eventName = "issues" ) ,
5858 ( mockContext . payload = { issue : { body : "Please help with /test-bot this issue" } } ) ,
5959 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
6060 expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "false" ) ,
61- expect ( mockCore . warning ) . toHaveBeenCalledWith ( expect . stringContaining ( "Command '/test-bot' is not the first word " ) ) ) ;
61+ expect ( mockCore . warning ) . toHaveBeenCalledWith ( expect . stringContaining ( "None of the commands " ) ) ) ;
6262 } ) ,
6363 it ( "should pass when command is first word after whitespace" , async ( ) => {
64- ( ( process . env . GH_AW_COMMAND = "helper" ) ,
64+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "helper" ] ) ) ,
6565 ( mockContext . eventName = "issue_comment" ) ,
6666 ( mockContext . payload = { comment : { body : " \n /helper analyze this code" } } ) ,
6767 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
6868 expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true" ) ) ;
6969 } ) ,
7070 it ( "should pass for non-comment events" , async ( ) => {
71- ( ( process . env . GH_AW_COMMAND = "test-bot" ) ,
71+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "test-bot" ] ) ) ,
7272 ( mockContext . eventName = "workflow_dispatch" ) ,
7373 ( mockContext . payload = { } ) ,
7474 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
7575 expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true" ) ,
7676 expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "does not require command position check" ) ) ) ;
7777 } ) ,
7878 it ( "should handle pull_request event with command at start" , async ( ) => {
79- ( ( process . env . GH_AW_COMMAND = "review-bot" ) ,
79+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "review-bot" ] ) ) ,
8080 ( mockContext . eventName = "pull_request" ) ,
8181 ( mockContext . payload = { pull_request : { body : "/review-bot please review my changes" } } ) ,
8282 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
8383 expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true" ) ) ;
8484 } ) ,
8585 it ( "should pass when text is empty" , async ( ) => {
86- ( ( process . env . GH_AW_COMMAND = "test-bot" ) ,
86+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "test-bot" ] ) ) ,
8787 ( mockContext . eventName = "issues" ) ,
8888 ( mockContext . payload = { issue : { body : "" } } ) ,
8989 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
90- expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true " ) ,
91- expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "No command " ) ) ) ;
90+ expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "false " ) ,
91+ expect ( mockCore . warning ) . toHaveBeenCalledWith ( expect . stringContaining ( "None of the commands " ) ) ) ;
9292 } ) ,
9393 it ( "should pass when text does not contain the command" , async ( ) => {
94- ( ( process . env . GH_AW_COMMAND = "test-bot" ) ,
94+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "test-bot" ] ) ) ,
9595 ( mockContext . eventName = "issues" ) ,
9696 ( mockContext . payload = { issue : { body : "This is a regular issue without any command" } } ) ,
9797 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
98- expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true " ) ,
99- expect ( mockCore . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "No command " ) ) ) ;
98+ expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "false " ) ,
99+ expect ( mockCore . warning ) . toHaveBeenCalledWith ( expect . stringContaining ( "None of the commands " ) ) ) ;
100100 } ) ,
101101 it ( "should handle discussion events" , async ( ) => {
102- ( ( process . env . GH_AW_COMMAND = "discuss-bot" ) ,
102+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "discuss-bot" ] ) ) ,
103103 ( mockContext . eventName = "discussion" ) ,
104104 ( mockContext . payload = { discussion : { body : "/discuss-bot help needed here" } } ) ,
105105 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
106106 expect ( mockCore . setOutput ) . toHaveBeenCalledWith ( "command_position_ok" , "true" ) ) ;
107107 } ) ,
108108 it ( "should handle discussion_comment events" , async ( ) => {
109- ( ( process . env . GH_AW_COMMAND = "discuss-bot" ) ,
109+ ( ( process . env . GH_AW_COMMANDS = JSON . stringify ( [ "discuss-bot" ] ) ) ,
110110 ( mockContext . eventName = "discussion_comment" ) ,
111111 ( mockContext . payload = { comment : { body : "/discuss-bot analyze this" } } ) ,
112112 await eval ( `(async () => { ${ checkCommandPositionScript } ; await main(); })()` ) ,
0 commit comments