Resolve relative cwd args against parser launch directory

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 00:36:20 +00:00
1 parent e773e60486
commit 5c6834db05
2 files changed
+14 -9

No files matched your search

+9 -4
View File
@@ -108,19 +108,24 @@ describe("parseCliOptions", () => {
expect(options.backendPort).toBe(7001);
expect(options.webPort).toBe(7002);
expect(options.noOpen).toBe(true);
expect(options.launchCwd).toBe(path.resolve("apps/t3"));
expect(options.launchCwd).toBe(path.resolve("/workspace", "apps/t3"));
expect(options.backendPortLocked).toBe(true);
expect(options.webPortLocked).toBe(true);
});
it("accepts a positional cwd argument", () => {
const options = parseCliOptions(["apps/renderer"], {}, "/workspace");
expect(options.launchCwd).toBe(path.resolve("apps/renderer"));
expect(options.launchCwd).toBe(path.resolve("/workspace", "apps/renderer"));
});
it("trims positional cwd arguments before resolving path", () => {
const options = parseCliOptions([" apps/renderer "], {}, "/workspace");
expect(options.launchCwd).toBe(path.resolve("apps/renderer"));
expect(options.launchCwd).toBe(path.resolve("/workspace", "apps/renderer"));
});
it("resolves relative cwd arguments against provided parser cwd", () => {
const options = parseCliOptions(["--cwd", "project"], {}, "/tmp/t3-root");
expect(options.launchCwd).toBe(path.resolve("/tmp/t3-root", "project"));
});
it("rejects whitespace-only positional cwd arguments", () => {
@@ -227,7 +232,7 @@ describe("parseCliOptions", () => {
it("trims cwd flag values before resolving path", () => {
const options = parseCliOptions(["--cwd", " apps/renderer "], {}, "/workspace");
expect(options.launchCwd).toBe(path.resolve("apps/renderer"));
expect(options.launchCwd).toBe(path.resolve("/workspace", "apps/renderer"));
});
it("throws for unknown arguments", () => {
+5 -5
View File
@@ -36,13 +36,13 @@ function parseEnvPort(
};
}
function parseExplicitPath(value: string, key: string): string {
function parseExplicitPath(value: string, key: string, cwd: string): string {
const trimmed = value.trim();
if (trimmed.length === 0) {
throw new Error(`Invalid value for ${key}: expected a non-empty path.`);
}
return path.resolve(trimmed);
return path.resolve(cwd, trimmed);
}
function parseBooleanEnvFlag(value: string | undefined): boolean {
@@ -170,12 +170,12 @@ export function parseCliOptions(
}
if (arg.startsWith("--cwd=")) {
launchCwd = parseExplicitPath(arg.split("=")[1] ?? "", "--cwd");
launchCwd = parseExplicitPath(arg.split("=")[1] ?? "", "--cwd", cwd);
continue;
}
if (arg === "--cwd") {
launchCwd = parseExplicitPath(readArgValue(argv, index, "--cwd"), "--cwd");
launchCwd = parseExplicitPath(readArgValue(argv, index, "--cwd"), "--cwd", cwd);
index += 1;
continue;
}
@@ -184,7 +184,7 @@ export function parseCliOptions(
if (usedPositionalCwd) {
throw new Error(`Unexpected positional argument: ${arg}`);
}
launchCwd = parseExplicitPath(arg, "[path]");
launchCwd = parseExplicitPath(arg, "[path]", cwd);
usedPositionalCwd = true;
continue;
}