Compare commits

...
Author SHA1 Message Date
paseo-bot[bot] e09abaf59d fix(desktop): preserve project launches with display scaling 2026-12-05 21:09:40 +00:00
paseo-bot[bot] 9d08b583d9 fix(desktop): preserve CLI arguments after launch switches 2026-12-05 20:53:53 +00:00
paseo-bot[bot] 86ae1c7a83 fix(desktop): preserve launches with Electron switches 2026-12-05 20:24:58 +00:00
paseo-bot[bot] 4c00134303 fix(desktop): keep daemon home arguments in CLI mode
Desktop startup treated an existing absolute daemon home as a project to open. Classify the invocation from its first argument after removing Electron switches.
2026-12-05 20:23:29 +00:00
5 changed files with 107 additions and 45 deletions
@@ -92,6 +92,21 @@ describe("passthrough CLI", () => {
).toBeNull();
});
it("opens the development app when Electron switches precede its entrypoint", () => {
expect(
parsePassthroughCliArgs({
argv: [
"/usr/bin/electron",
"--no-sandbox",
"--inspect=127.0.0.1:0",
"/checkout/packages/desktop",
],
isDefaultApp: true,
forceCli: false,
}),
).toBeNull();
});
it("preserves CLI flags for direct app invocations", () => {
expect(
parsePassthroughCliArgs({
@@ -102,6 +117,19 @@ describe("passthrough CLI", () => {
).toEqual(["--version"]);
});
it("preserves Electron-like values in a CLI command", () => {
const command = ["terminal", "send-keys", "terminal-id", "--literal", "--"];
const keys = ["--disable-gpu", "--inspect=0", "Enter"];
expect(
parsePassthroughCliArgs({
argv: ["/usr/bin/Paseo", "--no-sandbox", ...command, ...keys],
isDefaultApp: false,
forceCli: false,
}),
).toEqual([...command, ...keys]);
});
it("passes --open-project through as a normal CLI arg", () => {
expect(
parsePassthroughCliArgs({
+2 -10
View File
@@ -1,8 +1,8 @@
import { pathToFileURL } from "node:url";
import { getDesktopLaunchArgs } from "../../desktop-launch-args.js";
import { resolvePassthroughCliEntrypoint } from "./entrypoints.js";
const DESKTOP_CLI_ENV = "PASEO_DESKTOP_CLI";
const IGNORED_ARG_PREFIXES = ["-psn_", "--class=", "--no-sandbox", "--remote-debugging-port="];
export type PassthroughCliRunner = (argv: string[]) => Promise<number>;
@@ -11,15 +11,7 @@ export function parsePassthroughCliArgs(input: {
isDefaultApp: boolean;
forceCli: boolean;
}): string[] | null {
const startIndex = input.isDefaultApp ? 2 : 1;
const effective: string[] = [];
for (const arg of input.argv.slice(startIndex)) {
if (IGNORED_ARG_PREFIXES.some((prefix) => arg.startsWith(prefix))) {
continue;
}
effective.push(arg);
}
const effective = getDesktopLaunchArgs(input);
if (input.forceCli) {
return effective;
@@ -0,0 +1,32 @@
const ELECTRON_ARG_PREFIXES = [
"-psn_",
"--class=",
"--force-device-scale-factor=",
"--inspect=",
"--ozone-platform=",
"--remote-debugging-address=",
"--remote-debugging-port=",
];
const ELECTRON_ARGS = new Set(["--allow-file-access-from-files", "--disable-gpu", "--no-sandbox"]);
function skipElectronSwitches(args: string[], start: number): number {
let index = start;
while (index < args.length) {
const arg = args[index]!;
if (
!ELECTRON_ARGS.has(arg) &&
!ELECTRON_ARG_PREFIXES.some((prefix) => arg.startsWith(prefix))
) {
break;
}
index += 1;
}
return index;
}
export function getDesktopLaunchArgs(input: { argv: string[]; isDefaultApp: boolean }): string[] {
const firstArg = skipElectronSwitches(input.argv, 1);
// Electron retains switches before the development entrypoint. Wrappers can also add them after it.
const start = input.isDefaultApp ? skipElectronSwitches(input.argv, firstArg + 1) : firstArg;
return input.argv.slice(start);
}
@@ -1,4 +1,4 @@
import { mkdtempSync, mkdirSync } from "node:fs";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
@@ -23,6 +23,8 @@ describe("open-project-routing", () => {
parseOpenProjectPathFromArgv({
argv: [
"/Applications/Paseo.app/Contents/MacOS/Paseo",
"--disable-gpu",
"--ozone-platform=x11",
"--allow-file-access-from-files",
"--no-sandbox",
projectPath,
@@ -32,32 +34,57 @@ describe("open-project-routing", () => {
).toBe(projectPath);
});
it("does not treat flags as project paths", () => {
const projectPath = mkdtempSync(path.join(tmpdir(), "paseo-open-project-"));
const flagLikeDirectory = path.join(projectPath, "--version");
mkdirSync(flagLikeDirectory);
it("leaves an existing daemon home directory in the CLI arguments", () => {
const home = mkdtempSync(path.join(tmpdir(), "paseo-daemon-home-"));
try {
expect(
parseOpenProjectPathFromArgv({
argv: ["/usr/bin/Paseo", "--no-sandbox", "daemon", "start", "--home", home],
isDefaultApp: false,
}),
).toBeNull();
} finally {
rmSync(home, { recursive: true, force: true });
}
});
it("leaves a path after a CLI flag in the CLI arguments", () => {
expect(
parseOpenProjectPathFromArgv({
argv: ["/Applications/Paseo.app/Contents/MacOS/Paseo", "--version", flagLikeDirectory],
isDefaultApp: false,
}),
).toBe(flagLikeDirectory);
expect(
parseOpenProjectPathFromArgv({
argv: ["/Applications/Paseo.app/Contents/MacOS/Paseo", "--version"],
argv: ["/usr/bin/Paseo", "--version", tmpdir()],
isDefaultApp: false,
}),
).toBeNull();
});
it.each([{ selector: [] }, { selector: ["--open-project"] }])(
"opens a project after the Electron display scale switch with selector $selector",
({ selector }) => {
const projectPath = mkdtempSync(path.join(tmpdir(), "paseo-open-project-"));
try {
expect(
parseOpenProjectPathFromArgv({
argv: ["/usr/bin/Paseo", "--force-device-scale-factor=1.5", ...selector, projectPath],
isDefaultApp: false,
}),
).toBe(projectPath);
} finally {
rmSync(projectPath, { recursive: true, force: true });
}
},
);
it("returns the path from an explicit --open-project flag for backward compatibility", () => {
const projectPath = mkdtempSync(path.join(tmpdir(), "paseo-open-project-"));
expect(
parseOpenProjectPathFromArgv({
argv: ["/Applications/Paseo.app/Contents/MacOS/Paseo", "--open-project", projectPath],
argv: [
"/Applications/Paseo.app/Contents/MacOS/Paseo",
"--disable-gpu",
"--open-project",
projectPath,
],
isDefaultApp: false,
}),
).toBe(projectPath);
+4 -21
View File
@@ -1,8 +1,8 @@
import { existsSync, statSync } from "node:fs";
import path from "node:path";
import { getDesktopLaunchArgs } from "./desktop-launch-args.js";
const OPEN_PROJECT_FLAG = "--open-project";
const OPEN_PROJECT_IGNORED_ARG_PREFIXES = ["-psn_", "--no-sandbox"];
function isExistingDirectoryAbsolutePath(candidate: string): boolean {
if (!path.isAbsolute(candidate) || !existsSync(candidate)) {
@@ -20,24 +20,7 @@ export function parseOpenProjectPathFromArgv(input: {
argv: string[];
isDefaultApp: boolean;
}): string | null {
const effectiveArgs = input.argv
.slice(input.isDefaultApp ? 2 : 1)
.filter((arg) => !OPEN_PROJECT_IGNORED_ARG_PREFIXES.some((prefix) => arg.startsWith(prefix)));
const positionalProjectPath = effectiveArgs.find(
(arg) => !arg.startsWith("-") && isExistingDirectoryAbsolutePath(arg),
);
if (positionalProjectPath) {
return positionalProjectPath;
}
const openProjectIndex = effectiveArgs.indexOf(OPEN_PROJECT_FLAG);
if (openProjectIndex === -1) {
return null;
}
const flaggedProjectPath = effectiveArgs[openProjectIndex + 1];
return flaggedProjectPath && isExistingDirectoryAbsolutePath(flaggedProjectPath)
? flaggedProjectPath
: null;
const [firstArg, secondArg] = getDesktopLaunchArgs(input);
const projectPath = firstArg === OPEN_PROJECT_FLAG ? secondArg : firstArg;
return projectPath && isExistingDirectoryAbsolutePath(projectPath) ? projectPath : null;
}