diff --git a/packages/hub/src/node/__tests__/host-terminals.test.ts b/packages/hub/src/node/__tests__/host-terminals.test.ts index 834601b1..d8f1b8ca 100644 --- a/packages/hub/src/node/__tests__/host-terminals.test.ts +++ b/packages/hub/src/node/__tests__/host-terminals.test.ts @@ -333,6 +333,40 @@ describe('devframeTerminalHost child-process status lifecycle', () => { }) describe('devframeTerminalHost interactive PTY sessions', () => { + itPty('inherits the parent process environment', async () => { + expect.assertions(1) + + const environmentVariable = 'DEVFRAME_PTY_INHERITED_ENV' + const previousValue = process.env[environmentVariable] + process.env[environmentVariable] = 'inherited' + + let session: Awaited> | undefined + try { + const { host, sinks } = createTerminalHost() + session = await host.startPtySession({ + command: NODE, + args: ['-e', `process.stdout.write(process.env.${environmentVariable} ?? "missing")`], + }, { + id: 'pty-environment', + title: 'PTY environment', + }) + + await waitUntil(() => { + if (!sinks.get('pty-environment')?.closed) + throw new Error('PTY stream is still open') + }) + + expect(session.buffer?.join('')).toContain('inherited') + } + finally { + await session?.terminate() + if (previousValue === undefined) + delete process.env[environmentVariable] + else + process.env[environmentVariable] = previousValue + } + }) + itPosixPty('spawns an interactive PTY that accepts input and is marked interactive', async () => { const { host, sinks } = createTerminalHost() diff --git a/packages/hub/src/node/host-terminals.ts b/packages/hub/src/node/host-terminals.ts index 4857a01f..ef92d8f8 100644 --- a/packages/hub/src/node/host-terminals.ts +++ b/packages/hub/src/node/host-terminals.ts @@ -410,6 +410,7 @@ export class DevframeTerminalsHost implements DevframeTerminalsHostType { rows, cwd: executeOptions.cwd ?? process.cwd(), env: { + ...process.env, TERM: PTY_TERM_NAME, COLORTERM: 'truecolor', FORCE_COLOR: '1',