Skip to content

Commit 9c03504

Browse files
committed
fix(agent): merge env for background exec
1 parent d63f593 commit 9c03504

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

src/main/lib/agentRuntime/backgroundExecSessionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class BackgroundExecSessionManager {
133133

134134
const child = spawn(shell, [...args, command], {
135135
cwd,
136-
env: options?.env ? { ...options.env } : { ...process.env },
136+
env: { ...process.env, ...(options?.env ?? {}) },
137137
detached: process.platform !== 'win32',
138138
stdio: ['pipe', 'pipe', 'pipe']
139139
})

test/main/lib/agentRuntime/backgroundExecSessionManager.test.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -234,32 +234,38 @@ describe('BackgroundExecSessionManager', () => {
234234
expect(log.output).toBe('timeout tail')
235235
})
236236

237-
it('passes the prepared env through start without re-merging PATH', async () => {
237+
it('merges the prepared env on top of process env when starting a session', async () => {
238238
const child = new MockChildProcess()
239239
vi.mocked(spawn).mockReturnValue(child as never)
240+
process.env.BASELINE_FLAG = 'baseline'
240241

241-
const result = await manager.start('conv-1', 'echo test', '/workspace', {
242-
timeout: 0,
243-
env: {
244-
PATH: '/prepared/bin:/usr/local/bin',
245-
CUSTOM_FLAG: '1'
246-
}
247-
})
248-
249-
expect(result).toEqual({
250-
sessionId: expect.stringMatching(/^bg_/),
251-
status: 'running'
252-
})
253-
expect(spawn).toHaveBeenCalledWith(
254-
expect.any(String),
255-
expect.any(Array),
256-
expect.objectContaining({
257-
cwd: '/workspace',
242+
try {
243+
const result = await manager.start('conv-1', 'echo test', '/workspace', {
244+
timeout: 0,
258245
env: {
259246
PATH: '/prepared/bin:/usr/local/bin',
260247
CUSTOM_FLAG: '1'
261248
}
262249
})
263-
)
250+
251+
expect(result).toEqual({
252+
sessionId: expect.stringMatching(/^bg_/),
253+
status: 'running'
254+
})
255+
expect(spawn).toHaveBeenCalledWith(
256+
expect.any(String),
257+
expect.any(Array),
258+
expect.objectContaining({
259+
cwd: '/workspace',
260+
env: expect.objectContaining({
261+
BASELINE_FLAG: 'baseline',
262+
PATH: '/prepared/bin:/usr/local/bin',
263+
CUSTOM_FLAG: '1'
264+
})
265+
})
266+
)
267+
} finally {
268+
delete process.env.BASELINE_FLAG
269+
}
264270
})
265271
})

0 commit comments

Comments
 (0)