diff --git a/apps/server/src/provider/AntigravityInstallation.test.ts b/apps/server/src/provider/AntigravityInstallation.test.ts index 8de41a4b3b364..41b3675ff9364 100644 --- a/apps/server/src/provider/AntigravityInstallation.test.ts +++ b/apps/server/src/provider/AntigravityInstallation.test.ts @@ -1066,8 +1066,11 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst const baseDir = yield* fs .makeTempDirectoryScoped({ prefix: "t3-agy-cli-test-" }) .pipe(Effect.flatMap((directory) => fs.realPath(directory))); - const cliDirectory = path.join(baseDir, "cli"); + const cliDirectory = path.join(baseDir, 'cli" '); yield* fs.makeDirectory(cliDirectory); + const siblingDirectory = path.join(baseDir, 'cli"'); + yield* fs.makeDirectory(siblingDirectory); + yield* fs.writeFileString(path.join(siblingDirectory, "agy"), "other cli", { mode: 0o755 }); const cli = path.join(cliDirectory, "antigravity"); const alias = path.join(cliDirectory, "agy"); const other = path.join(cliDirectory, "custom-acp"); @@ -1115,7 +1118,7 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst const windowsDirectory = path.join(baseDir, `windows-${name}`); yield* fs.makeDirectory(windowsDirectory); yield* fs.writeFileString(path.join(windowsDirectory, name), "cli"); - const selected = yield* windows.resolve("agy", { PATH: windowsDirectory }); + const selected = yield* windows.resolve("agy", { PATH: `"${windowsDirectory}"` }); expect(selected.harnessPath).toBeNull(); expect((yield* fs.realPath(selected.executablePath)).toLowerCase()).toBe( (yield* fs.realPath(path.join(windowsDirectory, name))).toLowerCase(), diff --git a/apps/server/src/provider/AntigravityInstallation.ts b/apps/server/src/provider/AntigravityInstallation.ts index f16849e2f56ea..b7c61d7a0bcfa 100644 --- a/apps/server/src/provider/AntigravityInstallation.ts +++ b/apps/server/src/provider/AntigravityInstallation.ts @@ -367,8 +367,7 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma ? Object.entries(processEnvironment).findLast(([key]) => key.toUpperCase() === "PATH")?.[1] : processEnvironment.PATH; const candidates: string[] = []; - for (const directory of (pathValue ?? "").split(platform === "win32" ? ";" : ":")) { - const entry = directory.trim().replace(/^"|"$/gu, ""); + for (const entry of (pathValue ?? "").split(platform === "win32" ? ";" : ":")) { if (entry.length === 0) continue; const resolved = yield* commandPath(command, { ...processEnvironment, PATH: entry }); if (resolved !== null) candidates.push(resolved); diff --git a/packages/shared/src/shell.test.ts b/packages/shared/src/shell.test.ts index ac5c59c752379..ac587dd1b5cda 100644 --- a/packages/shared/src/shell.test.ts +++ b/packages/shared/src/shell.test.ts @@ -530,31 +530,35 @@ describe("mergePathValues", () => { expect(mergePathValues("/opt/bin :/opt/bin", "/opt/bin :/usr/bin", "linux")).toBe( "/opt/bin :/opt/bin:/usr/bin", ); + expect(mergePathValues('/opt/bin"', "/opt/bin", "linux")).toBe('/opt/bin":/opt/bin'); }); }); effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => { - it.effect("finds executables in a POSIX PATH directory ending in whitespace", () => - Effect.gen(function* () { - const fs = yield* FileSystem.FileSystem; - const path = yield* Path.Path; - const cwd = yield* fs.makeTempDirectoryScoped({ directory: ".", prefix: "t3-path-" }); - const directory = `${cwd}/bin \u00a0`; - yield* fs.makeDirectory(directory); - const executable = `${directory}/audit-command`; - yield* fs.writeFileString(executable, "#!/bin/sh\n"); - yield* fs.chmod(executable, 0o755); - const env = { PATH: directory }; + // Windows rejects `"` in file names. + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( + "finds executables in a POSIX PATH directory ending in whitespace and quotes", + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const cwd = yield* fs.makeTempDirectoryScoped({ directory: ".", prefix: "t3-path-" }); + const directory = `${cwd}/bin \u00a0"`; + yield* fs.makeDirectory(directory); + const executable = `${directory}/audit-command`; + yield* fs.writeFileString(executable, "#!/bin/sh\n"); + yield* fs.chmod(executable, 0o755); + const env = { PATH: directory }; - expect( - yield* resolveCommandPath("audit-command", { env }).pipe( - Effect.provideService(HostProcess.Platform, "linux"), - Effect.provideService(CommandResolutionCache, new Map()), - ), - ).toBe(path.join(directory, "audit-command")); - const resolveExecutable = yield* SpawnExecutableResolution; - expect(resolveExecutable("audit-command", "linux", env)).toBe(executable); - }), + expect( + yield* resolveCommandPath("audit-command", { env }).pipe( + Effect.provideService(HostProcess.Platform, "linux"), + Effect.provideService(CommandResolutionCache, new Map()), + ), + ).toBe(path.join(directory, "audit-command")); + const resolveExecutable = yield* SpawnExecutableResolution; + expect(resolveExecutable("audit-command", "linux", env)).toBe(executable); + }), ); const recordProbes = (env: NodeJS.ProcessEnv) => diff --git a/packages/shared/src/shell.ts b/packages/shared/src/shell.ts index fd881c5fcd830..d9343fce09fef 100644 --- a/packages/shared/src/shell.ts +++ b/packages/shared/src/shell.ts @@ -106,7 +106,7 @@ function resolveSpawnExecutableWithNode( } for (const pathEntry of (readEnvPath(env) ?? "").split(pathDelimiterForPlatform(platform))) { - const normalizedPathEntry = stripWrappingQuotes(trimPathEntry(pathEntry, platform)); + const normalizedPathEntry = normalizePathEntry(pathEntry, platform); if (normalizedPathEntry.length === 0) continue; for (const candidate of candidates) { const candidatePath = path.join(normalizedPathEntry, candidate); @@ -453,20 +453,21 @@ export const readEnvironmentFromWindowsShell = Effect.fn("shell.readEnvironmentF }, ); -function stripWrappingQuotes(value: string): string { - return value.replace(/^"+|"+$/g, ""); -} - function trimPathEntry(entry: string, platform: NodeJS.Platform): string { return platform === "win32" ? entry.trim() : entry; } +// POSIX PATH entries are literal: whitespace and quotes are part of the directory name. +function normalizePathEntry(entry: string, platform: NodeJS.Platform): string { + return platform === "win32" ? entry.trim().replace(/^"+|"+$/g, "") : entry; +} + function pathDelimiterForPlatform(platform: NodeJS.Platform): string { return platform === "win32" ? WINDOWS_PATH_DELIMITER : POSIX_PATH_DELIMITER; } function normalizePathEntryForComparison(entry: string, platform: NodeJS.Platform): string { - const normalized = stripWrappingQuotes(trimPathEntry(entry, platform)); + const normalized = normalizePathEntry(entry, platform); return platform === "win32" ? normalized.toLowerCase() : normalized; } @@ -675,7 +676,7 @@ const findOnPath = Effect.fnUntraced(function* ( const pathEntries: string[] = []; const seenPathEntries = new Set(); for (const entry of pathValue.split(pathDelimiterForPlatform(platform))) { - const pathEntry = stripWrappingQuotes(trimPathEntry(entry, platform)); + const pathEntry = normalizePathEntry(entry, platform); if (pathEntry.length === 0 || seenPathEntries.has(pathEntry)) continue; seenPathEntries.add(pathEntry);