@@ -96,7 +96,8 @@ vi.mock('@actions/core', () => core)
9696
9797// Mock process.exit to prevent it from actually exiting during tests
9898const mockProcessExit = vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => {
99- throw new Error ( 'process.exit called' )
99+ // Prevent actual exit, but don't throw - just return
100+ return undefined as never
100101} )
101102
102103// The module being tested should be imported dynamically. This ensures that the
@@ -127,6 +128,7 @@ describe('main.ts', () => {
127128
128129 expect ( core . setOutput ) . toHaveBeenCalled ( )
129130 verifyStandardResponse ( )
131+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
130132 } )
131133
132134 it ( 'Sets a failed status when no prompt is set' , async ( ) => {
@@ -135,8 +137,7 @@ describe('main.ts', () => {
135137 'prompt-file' : '' ,
136138 } )
137139
138- // Expect the run function to throw due to process.exit being mocked
139- await expect ( run ( ) ) . rejects . toThrow ( 'process.exit called' )
140+ await run ( )
140141
141142 expect ( core . setFailed ) . toHaveBeenCalledWith ( 'Neither prompt-file nor prompt was set' )
142143 expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
@@ -165,6 +166,7 @@ describe('main.ts', () => {
165166 expect ( mockConnectToGitHubMCP ) . not . toHaveBeenCalled ( )
166167 expect ( mockMcpInference ) . not . toHaveBeenCalled ( )
167168 verifyStandardResponse ( )
169+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
168170 } )
169171
170172 it ( 'uses MCP inference when enabled and connection succeeds' , async ( ) => {
@@ -197,6 +199,7 @@ describe('main.ts', () => {
197199 )
198200 expect ( mockSimpleInference ) . not . toHaveBeenCalled ( )
199201 verifyStandardResponse ( )
202+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
200203 } )
201204
202205 it ( 'falls back to simple inference when MCP connection fails' , async ( ) => {
@@ -215,6 +218,7 @@ describe('main.ts', () => {
215218 expect ( mockMcpInference ) . not . toHaveBeenCalled ( )
216219 expect ( core . warning ) . toHaveBeenCalledWith ( 'MCP connection failed, falling back to simple inference' )
217220 verifyStandardResponse ( )
221+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
218222 } )
219223
220224 it ( 'properly integrates with loadContentFromFileOrInput' , async ( ) => {
@@ -248,6 +252,7 @@ describe('main.ts', () => {
248252 responseFormat : undefined ,
249253 } )
250254 verifyStandardResponse ( )
255+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
251256 } )
252257
253258 it ( 'handles non-existent prompt-file with an error' , async ( ) => {
@@ -259,8 +264,7 @@ describe('main.ts', () => {
259264 'prompt-file' : promptFile ,
260265 } )
261266
262- // Expect the run function to throw due to process.exit being mocked
263- await expect ( run ( ) ) . rejects . toThrow ( 'process.exit called' )
267+ await run ( )
264268
265269 expect ( core . setFailed ) . toHaveBeenCalledWith ( `File for prompt-file was not found: ${ promptFile } ` )
266270 expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
0 commit comments