Skip to content
Open
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
36 changes: 36 additions & 0 deletions apps/pi-extension/server/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,42 @@ describe("pi browser no-op sentinels", () => {
});
});

describe("pi PLANNOTATOR_BROWSER script path", () => {
// #1391: on darwin, `open -a <script>` fails with LaunchServices -10811,
// so a slash-containing non-.app value must be executed directly.
test.if(process.platform !== "win32")(
"executes a script path directly with the URL as argument",
async () => {
clearEnv();
const { mkdtempSync, writeFileSync, readFileSync, existsSync, rmSync } =
await import("node:fs");
const { join } = await import("node:path");
const { tmpdir } = await import("node:os");
const dir = mkdtempSync(join(tmpdir(), "pn-browser-"));
try {
const marker = join(dir, "opened.txt");
const script = join(dir, "handler.sh");
writeFileSync(script, `#!/bin/sh\nprintf '%s' \"$1\" > \"${marker}\"\n`, {
mode: 0o755,
});
process.env.PLANNOTATOR_BROWSER = script;

const result = await openBrowser("http://127.0.0.1:19432");
expect(result.opened).toBe(true);

// spawn is detached; poll briefly for the marker
const deadline = Date.now() + 2000;
while (!existsSync(marker) && Date.now() < deadline) {
await new Promise((r) => setTimeout(r, 25));
}
expect(readFileSync(marker, "utf-8")).toBe("http://127.0.0.1:19432");
} finally {
rmSync(dir, { recursive: true, force: true });
}
},
);
});

describe("pi buildAdvertisedUrl", () => {
test("defaults to localhost", () => {
clearEnv();
Expand Down
13 changes: 11 additions & 2 deletions apps/pi-extension/server/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,17 @@ export async function openBrowser(url: string): Promise<{

if (browser) {
if (plannotatorBrowser && platform === "darwin") {
cmd = "open";
args = ["-a", plannotatorBrowser, url];
if (
plannotatorBrowser.includes("/") &&
!plannotatorBrowser.endsWith(".app")
) {
// Script/executable path — run directly (open -a fails with -10811)
cmd = plannotatorBrowser;
args = [url];
} else {
cmd = "open";
args = ["-a", plannotatorBrowser, url];
}
} else if ((platform === "win32" || wsl) && plannotatorBrowser) {
cmd = "cmd.exe";
args = ["/c", "start", "", plannotatorBrowser, url];
Expand Down