Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion src/runs/shared/pi-spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ function normalizePath(filePath: string): string {
return path.isAbsolute(filePath) ? filePath : path.resolve(filePath);
}

function isStandalonePiExecutable(execPath: string): boolean {
const executableName = execPath.split(/[\\/]/).pop();
return /^pi(?:\.exe)?$/i.test(executableName ?? "");
}

export function resolvePiCliScript(
deps: PiSpawnDeps = {},
): string | undefined {
Expand Down Expand Up @@ -141,10 +146,15 @@ export function getPiSpawnCommand(
return { command: piBinary, args };
}

const execPath = deps.execPath ?? process.execPath;
if (isStandalonePiExecutable(execPath)) {
return { command: execPath, args };
}

const piCliPath = resolvePiCliScript(deps);
if (piCliPath) {
return {
command: deps.execPath ?? process.execPath,
command: execPath,
args: [piCliPath, ...args],
};
}
Expand Down
26 changes: 26 additions & 0 deletions test/unit/pi-spawn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ describe("getPiSpawnCommand", () => {
assert.deepEqual(result, { command: "pi", args });
});

for (const [platform, execPath] of [
["darwin", "/opt/pi/pi"],
["win32", "C:\\Program Files\\Pi\\pi.exe"],
] as const) {
it(`uses the standalone Pi executable directly on ${platform}`, () => {
const packageJsonPath = "/opt/pi-package/package.json";
const cliPath = path.resolve(
path.dirname(packageJsonPath),
"dist/cli.js",
);
const deps = makeDeps({
platform,
execPath,
argv1: "/missing/host.js",
packageJsonPath,
packageJsonContent: JSON.stringify({ bin: { pi: "dist/cli.js" } }),
existing: [packageJsonPath, cliPath],
});
const args = ["--mode", "json", "-p", "Task: review diff"];
assert.deepEqual(getPiSpawnCommand(args, deps), {
command: execPath,
args,
});
});
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.

for (const platform of ["darwin", "linux", "win32"] as const) {
it(`uses node + argv1 on ${platform} when argv1 belongs to the Pi package`, () => {
const tempDir = fs.mkdtempSync(
Expand Down