Validate runtime launchCwd before server startup

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 01:04:52 +00:00
1 parent 053488cd66
commit b0d168b6ae
2 files changed
+31

No files matched your search

+22
View File
@@ -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({
+9
View File
@@ -333,6 +333,15 @@ export async function startRuntimeApiServer(
options: RuntimeApiServerOptions,
): Promise<RuntimeApiServer> {
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.");