diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 253d6fa167..d2bf1c4d07 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -236,6 +236,24 @@ describe("runtimeApiServer", () => { ).rejects.toThrow("Invalid launchCwd does not exist"); }); + it("rejects startup when launchCwd is empty", async () => { + await expect( + startRuntimeApiServer({ + port: 0, + launchCwd: "", + }), + ).rejects.toThrow("Invalid launchCwd must be a non-empty path"); + }); + + it("rejects startup when launchCwd is not a string", async () => { + await expect( + startRuntimeApiServer({ + port: 0, + launchCwd: 123 as unknown as string, + }), + ).rejects.toThrow("Invalid launchCwd must be a non-empty path"); + }); + 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"); diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 3f2629fba4..031f786194 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -284,6 +284,10 @@ async function runTerminalCommand( } function resolveExistingDirectory(targetPath: string, label: string): string { + if (typeof targetPath !== "string" || targetPath.trim().length === 0) { + throw new Error(`${label} must be a non-empty path.`); + } + const candidate = path.resolve(targetPath); let stats: fs.Stats; try {