Skip to content

Commit 9ee8c8c

Browse files
mweinbachclaude
andcommitted
fix(shared): resolve spawn commands against the env the child inherits
resolveSpawnCommand goes back to a plain spread for extendEnv. The spawner merges the same way, so collapsing PATH spellings during resolution could pick an executable from a PATH the child never sees. Path/PATH deduplication stays in the Windows environment probe merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5dd6f0a commit 9ee8c8c

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎packages/shared/src/shell.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,26 +648,32 @@ effectIt.layer(NodeServices.layer)("resolveSpawnCommand", (it) => {
648648
}),
649649
);
650650

651-
it.effect("collapses PATH spellings to the preferred patch value when extending host env", () =>
651+
it.effect("resolves with the same PATH spellings the spawned child inherits", () =>
652652
Effect.gen(function* () {
653653
let resolvedEnvironment: NodeJS.ProcessEnv | undefined;
654654
yield* resolveSpawnCommand("codex", [], {
655-
env: { PATH: "C:\\explicit", Path: "C:\\other" },
655+
env: { Path: "C:\\custom" },
656656
extendEnv: true,
657657
}).pipe(
658658
Effect.provideService(HostProcess.Platform, "win32"),
659659
Effect.provideService(CommandResolutionCache, new Map()),
660660
Effect.provideService(HostProcess.Environment, {
661-
Path: "C:\\host",
661+
PATH: "C:\\host",
662662
PATHEXT: ".EXE",
663663
}),
664664
Effect.provideService(SpawnExecutableResolution, (_command, _platform, env) => {
665665
resolvedEnvironment = env;
666-
return "C:\\explicit\\codex.exe";
666+
return "C:\\host\\codex.exe";
667667
}),
668668
);
669669

670-
expect(resolvedEnvironment).toEqual({ PATH: "C:\\explicit", PATHEXT: ".EXE" });
670+
// The child process spawner merges with a plain spread, so resolution must
671+
// not collapse PATH spellings the child will still see.
672+
expect(resolvedEnvironment).toEqual({
673+
PATH: "C:\\host",
674+
PATHEXT: ".EXE",
675+
Path: "C:\\custom",
676+
});
671677
}),
672678
);
673679

‎packages/shared/src/shell.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,13 @@ export const resolveSpawnCommand = Effect.fnUntraced(function* (
746746
}
747747

748748
const hostEnvironment = yield* HostProcess.Environment;
749+
// extendEnv mirrors the spawner's plain spread so resolution sees the PATH the
750+
// child process actually inherits.
749751
const env =
750752
options.env === undefined
751753
? hostEnvironment
752754
: options.extendEnv
753-
? mergeWindowsEnv(hostEnvironment, options.env)
755+
? { ...hostEnvironment, ...options.env }
754756
: options.env;
755757
const resolveExecutable = yield* SpawnExecutableResolution;
756758
// The scan is synchronous and runs before every child process, so it shares

0 commit comments

Comments
 (0)