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
7 changes: 5 additions & 2 deletions apps/server/src/provider/AntigravityInstallation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions apps/server/src/provider/AntigravityInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 24 additions & 20 deletions packages/shared/src/shell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
15 changes: 8 additions & 7 deletions packages/shared/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -675,7 +676,7 @@ const findOnPath = Effect.fnUntraced(function* (
const pathEntries: string[] = [];
const seenPathEntries = new Set<string>();
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);
Expand Down
Loading