From b0d168b6aef23c766d4e3a70dacfa3374fa4cc43 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 01:04:52 +0000 Subject: [PATCH] Validate runtime launchCwd before server startup Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 22 ++++++++++++++++++++++ apps/t3/src/runtimeApiServer.ts | 9 +++++++++ 2 files changed, 31 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 9d6fc541f4..c224f3b4fd 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -181,6 +181,28 @@ describe("runtimeApiServer", () => { ]); }); + it("rejects startup when launchCwd does not exist", async () => { + const missingPath = path.join(process.cwd(), `missing-launch-cwd-${Date.now()}`); + await expect( + startRuntimeApiServer({ + port: 0, + launchCwd: missingPath, + }), + ).rejects.toThrow("Invalid launchCwd: directory does not exist"); + }); + + it("rejects startup when launchCwd is not a directory", async () => { + const tempDir = mkdtempSync(path.join(os.tmpdir(), "t3-launch-cwd-file-")); + const filePath = path.join(tempDir, "launch.txt"); + writeFileSync(filePath, "not-a-directory", "utf8"); + await expect( + startRuntimeApiServer({ + port: 0, + launchCwd: filePath, + }), + ).rejects.toThrow("Invalid launchCwd: expected directory path"); + }); + it("rejects empty auth token configuration", async () => { await expect( startRuntimeApiServer({ diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 46222298d7..a0b6002540 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -333,6 +333,15 @@ export async function startRuntimeApiServer( options: RuntimeApiServerOptions, ): Promise { const launchCwd = path.resolve(options.launchCwd); + let launchCwdStats: fs.Stats; + try { + launchCwdStats = fs.statSync(launchCwd); + } catch { + throw new Error(`Invalid launchCwd: directory does not exist: ${launchCwd}`); + } + if (!launchCwdStats.isDirectory()) { + throw new Error(`Invalid launchCwd: expected directory path: ${launchCwd}`); + } const authToken = options.authToken?.trim(); if (options.authToken !== undefined && !authToken) { throw new Error("Invalid runtime auth token: expected non-empty string.");