@@ -96,7 +96,8 @@ vi.mock('@actions/core', () => core)
96
96
97
97
// Mock process.exit to prevent it from actually exiting during tests
98
98
const 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
100
101
} )
101
102
102
103
// The module being tested should be imported dynamically. This ensures that the
@@ -127,6 +128,7 @@ describe('main.ts', () => {
127
128
128
129
expect ( core . setOutput ) . toHaveBeenCalled ( )
129
130
verifyStandardResponse ( )
131
+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
130
132
} )
131
133
132
134
it ( 'Sets a failed status when no prompt is set' , async ( ) => {
@@ -135,8 +137,7 @@ describe('main.ts', () => {
135
137
'prompt-file' : '' ,
136
138
} )
137
139
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 ( )
140
141
141
142
expect ( core . setFailed ) . toHaveBeenCalledWith ( 'Neither prompt-file nor prompt was set' )
142
143
expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
@@ -165,6 +166,7 @@ describe('main.ts', () => {
165
166
expect ( mockConnectToGitHubMCP ) . not . toHaveBeenCalled ( )
166
167
expect ( mockMcpInference ) . not . toHaveBeenCalled ( )
167
168
verifyStandardResponse ( )
169
+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
168
170
} )
169
171
170
172
it ( 'uses MCP inference when enabled and connection succeeds' , async ( ) => {
@@ -197,6 +199,7 @@ describe('main.ts', () => {
197
199
)
198
200
expect ( mockSimpleInference ) . not . toHaveBeenCalled ( )
199
201
verifyStandardResponse ( )
202
+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
200
203
} )
201
204
202
205
it ( 'falls back to simple inference when MCP connection fails' , async ( ) => {
@@ -215,6 +218,7 @@ describe('main.ts', () => {
215
218
expect ( mockMcpInference ) . not . toHaveBeenCalled ( )
216
219
expect ( core . warning ) . toHaveBeenCalledWith ( 'MCP connection failed, falling back to simple inference' )
217
220
verifyStandardResponse ( )
221
+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
218
222
} )
219
223
220
224
it ( 'properly integrates with loadContentFromFileOrInput' , async ( ) => {
@@ -248,6 +252,7 @@ describe('main.ts', () => {
248
252
responseFormat : undefined ,
249
253
} )
250
254
verifyStandardResponse ( )
255
+ expect ( mockProcessExit ) . toHaveBeenCalledWith ( 0 )
251
256
} )
252
257
253
258
it ( 'handles non-existent prompt-file with an error' , async ( ) => {
@@ -259,8 +264,7 @@ describe('main.ts', () => {
259
264
'prompt-file' : promptFile ,
260
265
} )
261
266
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 ( )
264
268
265
269
expect ( core . setFailed ) . toHaveBeenCalledWith ( `File for prompt-file was not found: ${ promptFile } ` )
266
270
expect ( mockProcessExit ) . toHaveBeenCalledWith ( 1 )
0 commit comments