Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions packages/extension/src/embedded/stdio-process.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as childProcess from 'node:child_process'
import * as os from 'node:os'
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'

import {
Expand Down Expand Up @@ -353,12 +351,9 @@ function ensureBundledBridgeDeps(projectCwd: string, bridgeCwd: string): string
}

function mixChildEnv(projectCwd: string): NodeJS.ProcessEnv {
const mixHome = path.join(os.homedir(), '.mix')
return {
...process.env,
MIX_ENV: process.env.PI_ELIXIR_BRIDGE_MIX_ENV || 'dev',
MIX_HOME: mixHome,
MIX_ARCHIVES: path.join(mixHome, 'archives'),
PI_ELIXIR_PROJECT_CWD: projectCwd
}
}
Expand Down
22 changes: 20 additions & 2 deletions packages/extension/test/beam-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ describe('resolveUrl', () => {

afterEach(() => {
resetModuleState()
vi.unstubAllEnvs()
vi.restoreAllMocks()
vi.useRealTimers()
})
Expand Down Expand Up @@ -299,7 +300,12 @@ describe('resolveUrl', () => {
expect(fetch).toHaveBeenCalled()
})

it('returns null and starts embedded when no external MCP server found', async () => {
it('preserves caller Mix paths when starting embedded', async () => {
const mixHome = '/mise/elixir/1.20.1-otp-28/.mix'
const mixArchives = `${mixHome}/archives`
vi.stubEnv('MIX_HOME', mixHome)
vi.stubEnv('MIX_ARCHIVES', mixArchives)
vi.stubEnv('PI_ELIXIR_BRIDGE_MIX_ENV', 'test')
vi.mocked(fetch).mockRejectedValue(new Error('connection refused'))
vi.mocked(fs.readFileSync).mockImplementation(() => {
throw new Error('ENOENT')
Expand All @@ -313,13 +319,25 @@ describe('resolveUrl', () => {
vi.mocked(childProcess.spawn).mockReturnValue(fakeProc)

const result = await resolveUrl('/embedded-project')
const expectedMixEnv = {
MIX_ARCHIVES: mixArchives,
MIX_ENV: 'test',
MIX_HOME: mixHome,
PI_ELIXIR_PROJECT_CWD: '/embedded-project'
}

expect(result).toBeNull()
expect(childProcess.execFileSync).toHaveBeenCalledWith(
'mix',
['deps.get'],
expect.objectContaining({ env: expect.objectContaining(expectedMixEnv) })
)
expect(childProcess.spawn).toHaveBeenCalledWith(
'mix',
['run', '-e', 'Pi.Transport.Stdio.start()'],
expect.objectContaining({
cwd: expect.stringContaining('packages/bridge'),
env: expect.objectContaining({ PI_ELIXIR_PROJECT_CWD: '/embedded-project' })
env: expect.objectContaining(expectedMixEnv)
})
)
})
Expand Down
Loading