Skip to content

Commit e2fc175

Browse files
committed
fix(tests): pass undefined env to avoid multiple process.env spreads
Root cause found: The spawn function from @socketsecurity/lib/spawn ALWAYS spreads process.env first (line 622), then spreads our env: env: { __proto__: null, ...process.env, // spawn's spread ...env, // our env } When we passed env with spread process.env, it caused multiple spreads: ...process.env (spawn's) ...process.env (our first spread) ...process.env (constants.processEnv) Each spread creates a plain object, losing Windows Proxy behavior. Solution: Pass undefined for env when no custom vars needed. Spawn function will use process.env directly (with VITEST=1 already set).
1 parent 0b86233 commit e2fc175

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/cli/test/utils.mts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,17 @@ export async function spawnSocketCli(
266266
const commandArgs = isJsFile ? [entryPath, ...args] : args
267267

268268
try {
269+
// Only pass env if we have custom environment variables.
270+
// The spawn function from @socketsecurity/lib/spawn ALWAYS spreads
271+
// process.env first (line 622), then spreads our env on top.
272+
// If we pass env with spread process.env, it gets spread multiple times
273+
// losing Windows Proxy behavior. By passing undefined, spawn uses
274+
// process.env directly without any spreading.
275+
const env = spawnEnv ? { ...constants.processEnv, ...spawnEnv } : undefined
276+
269277
const output = await spawn(command, commandArgs, {
270278
cwd,
271-
env: {
272-
...process.env,
273-
...constants.processEnv,
274-
...spawnEnv,
275-
},
279+
env,
276280
...restOptions,
277281
// Close stdin to prevent tests from hanging
278282
// when commands wait for input. Must be after restOptions

0 commit comments

Comments
 (0)