diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index f0f75d62e5..7f03e4377f 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -86,6 +86,12 @@ describe("parseCliOptions", () => { ); }); + it("throws for empty cwd flag values", () => { + expect(() => parseCliOptions(["--cwd="], {}, "/workspace")).toThrow( + "Invalid value for --cwd", + ); + }); + it("throws for unknown arguments", () => { expect(() => parseCliOptions(["--wat"], {}, "/workspace")).toThrow( "Unknown argument: --wat", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index ad7e718ef3..340a59b310 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -36,6 +36,15 @@ function parseEnvPort( }; } +function parseExplicitPath(value: string, key: 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); +} + interface CliOptions { backendPort: number; webPort: number; @@ -152,12 +161,12 @@ export function parseCliOptions( } if (arg.startsWith("--cwd=")) { - launchCwd = path.resolve(arg.split("=")[1] ?? cwd); + launchCwd = parseExplicitPath(arg.split("=")[1] ?? "", "--cwd"); continue; } if (arg === "--cwd") { - launchCwd = path.resolve(readArgValue(argv, index, "--cwd")); + launchCwd = parseExplicitPath(readArgValue(argv, index, "--cwd"), "--cwd"); index += 1; continue; }