Validate launch directory before starting runtime
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
a9bb1d6b19
commit
a5b9eb61c9
2 files changed
+38
-1
No files matched your search
@@ -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";
|
||||
|
||||
|
||||
+18
-1
@@ -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<void> {
|
||||
const launchCwd = validateLaunchDirectory(options.launchCwd);
|
||||
const authToken = randomUUID();
|
||||
const runtimeServer = await startRuntimeApiServer({
|
||||
port: options.backendPort,
|
||||
launchCwd: options.launchCwd,
|
||||
launchCwd,
|
||||
authToken,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user