From a5b9eb61c9b43c065c718b95ccb67309d4f7e4f9 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:52:40 +0000 Subject: [PATCH] Validate launch directory before starting runtime Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 20 ++++++++++++++++++++ apps/t3/src/cli.ts | 19 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index a202c2ff6e..d5d8735d99 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -9,6 +9,7 @@ import { readCliVersion, resolveStaticAssetReadTarget, resolveStaticAssetPath, + validateLaunchDirectory, } from "./cli"; describe("parseCliOptions", () => { @@ -325,6 +326,25 @@ describe("formatStartupError", () => { }); }); +describe("validateLaunchDirectory", () => { + it("returns resolved path for existing directories", () => { + const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3-launch-dir-")); + expect(validateLaunchDirectory(tempDir)).toBe(path.resolve(tempDir)); + }); + + it("throws for missing launch directories", () => { + const missing = path.join(os.tmpdir(), `t3-missing-dir-${Date.now()}`); + expect(() => validateLaunchDirectory(missing)).toThrow("Launch directory does not exist"); + }); + + it("throws when launch path points to a file", () => { + const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3-launch-file-")); + const filePath = path.join(tempDir, "not-a-dir.txt"); + writeFileSync(filePath, "content", "utf8"); + expect(() => validateLaunchDirectory(filePath)).toThrow("Launch path is not a directory"); + }); +}); + describe("resolveStaticAssetPath", () => { const distRoot = "/workspace/apps/renderer/dist"; diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index e0b4d99ad6..86d4b2ca89 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -280,11 +280,28 @@ export function readCliVersion( return DEFAULT_CLI_VERSION; } +export function validateLaunchDirectory(launchCwd: string): string { + const resolved = path.resolve(launchCwd); + let stats: fs.Stats; + try { + stats = fs.statSync(resolved); + } catch { + throw new Error(`Launch directory does not exist: ${resolved}`); + } + + if (!stats.isDirectory()) { + throw new Error(`Launch path is not a directory: ${resolved}`); + } + + return resolved; +} + async function runCli(options: CliOptions): Promise { + const launchCwd = validateLaunchDirectory(options.launchCwd); const authToken = randomUUID(); const runtimeServer = await startRuntimeApiServer({ port: options.backendPort, - launchCwd: options.launchCwd, + launchCwd, authToken, });