Skip to content

Commit 18d4686

Browse files
committed
fix: keep response-file temp file for downstream steps
The temporary file created for response-file was being cleaned up before downstream steps could access it. Now using keep: true to ensure the file persists until the job completes. Also added script/ to eslint ignores for the mock server.
1 parent fd73d02 commit 18d4686

5 files changed

Lines changed: 16 additions & 62 deletions

File tree

__tests__/main.test.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,13 @@ vi.mock('fs', () => ({
7575
writeFileSync: mockWriteFileSync,
7676
}))
7777

78-
// Mocks for tmp module to control temporary file creation and cleanup
79-
const mockRemoveCallback = vi.fn()
78+
// Mocks for tmp module to control temporary file creation
8079
const mockFileSync = vi.fn().mockReturnValue({
8180
name: '/secure/temp/dir/modelResponse-abc123.txt',
82-
removeCallback: mockRemoveCallback,
8381
})
84-
const mockSetGracefulCleanup = vi.fn()
8582

8683
vi.mock('tmp', () => ({
8784
fileSync: mockFileSync,
88-
setGracefulCleanup: mockSetGracefulCleanup,
8985
}))
9086

9187
// Mock MCP and inference modules
@@ -283,42 +279,24 @@ describe('main.ts', () => {
283279
expect(mockProcessExit).toHaveBeenCalledWith(1)
284280
})
285281

286-
it('creates secure temporary files with proper cleanup', async () => {
282+
it('creates temporary files that persist for downstream steps', async () => {
287283
mockInputs({
288284
prompt: 'Test prompt',
289285
'system-prompt': 'You are a test assistant.',
290286
})
291287

292288
await run()
293289

294-
expect(mockSetGracefulCleanup).toHaveBeenCalledOnce()
295-
290+
// Verify temp file is created with keep: true so it persists
296291
expect(mockFileSync).toHaveBeenCalledWith({
297292
prefix: 'modelResponse-',
298293
postfix: '.txt',
294+
keep: true,
299295
})
300296

301297
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'response-file', '/secure/temp/dir/modelResponse-abc123.txt')
302298
expect(mockWriteFileSync).toHaveBeenCalledWith('/secure/temp/dir/modelResponse-abc123.txt', 'Hello, user!', 'utf-8')
303-
expect(mockRemoveCallback).toHaveBeenCalledOnce()
304-
305-
expect(mockProcessExit).toHaveBeenCalledWith(0)
306-
})
307-
308-
it('handles cleanup errors gracefully', async () => {
309-
mockRemoveCallback.mockImplementationOnce(() => {
310-
throw new Error('Cleanup failed')
311-
})
312-
313-
mockInputs({
314-
prompt: 'Test prompt',
315-
'system-prompt': 'You are a test assistant.',
316-
})
317-
318-
await run()
319299

320-
expect(mockRemoveCallback).toHaveBeenCalledOnce()
321-
expect(core.warning).toHaveBeenCalledWith('Failed to cleanup temporary file: Error: Cleanup failed')
322300
expect(mockProcessExit).toHaveBeenCalledWith(0)
323301
})
324302
})

dist/index.js

Lines changed: 5 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const compat = new FlatCompat({
1919

2020
export default [
2121
{
22-
ignores: ['**/coverage', '**/dist', '**/linter', '**/node_modules'],
22+
ignores: ['**/coverage', '**/dist', '**/linter', '**/node_modules', 'script/**'],
2323
},
2424
...compat.extends(
2525
'eslint:recommended',

src/main.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import {
1818
* @returns Resolves when the action is complete.
1919
*/
2020
export async function run(): Promise<void> {
21-
let responseFile: tmp.FileResult | null = null
22-
23-
// Set up graceful cleanup for temporary files on process exit
24-
tmp.setGracefulCleanup()
25-
2621
try {
2722
const promptFilePath = core.getInput('prompt-file')
2823
const inputVariables = core.getInput('input')
@@ -101,10 +96,13 @@ export async function run(): Promise<void> {
10196

10297
core.setOutput('response', modelResponse || '')
10398

104-
// Create a secure temporary file instead of using the temp directory directly
105-
responseFile = tmp.fileSync({
99+
// Create a temporary file for the response that persists for downstream steps.
100+
// We use keep: true to prevent automatic cleanup - the file will be cleaned up
101+
// by the runner when the job completes.
102+
const responseFile = tmp.fileSync({
106103
prefix: 'modelResponse-',
107104
postfix: '.txt',
105+
keep: true,
108106
})
109107

110108
core.setOutput('response-file', responseFile.name)
@@ -120,16 +118,6 @@ export async function run(): Promise<void> {
120118
}
121119
// Force exit to prevent hanging on open connections
122120
process.exit(1)
123-
} finally {
124-
// Explicit cleanup of temporary file if it was created
125-
if (responseFile) {
126-
try {
127-
responseFile.removeCallback()
128-
} catch (cleanupError) {
129-
// Log cleanup errors but don't fail the action
130-
core.warning(`Failed to cleanup temporary file: ${cleanupError}`)
131-
}
132-
}
133121
}
134122

135123
// Force exit to prevent hanging on open connections

0 commit comments

Comments
 (0)