From 5c6834db05b2cd8a2f07383ed1350875eab4b4eb Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:36:20 +0000 Subject: [PATCH] Resolve relative cwd args against parser launch directory Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 13 +++++++++---- apps/t3/src/cli.ts | 10 +++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index 792e8d1046..5420fed132 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -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", () => { diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index cda9b36acc..9afb52bb8d 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -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; }