mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(cli): browser ensure fails when the unzip leaves no Chrome executable (#5329)
* fix(cli): browser ensure fails when the unzip leaves no Chrome executable * refactor(cli): keep install debug output and report only the last unzip attempt * fix(cli): browser ensure exits after a failure or a --force download * fix(cli): browser checks name why Chrome could not be installed * fix(cli): render shows why its setup step failed instead of a crash dump * refactor(cli): build the browser download label and staged test path once * refactor(cli): one owner for the render setup result line * fix(cli): render setup failures report through one error line * refactor(cli): one reader and writer for both render setup lines
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runCancellableProcess } from "./cancellableProcess.js";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { runCancellableProcess, runRenderSetupWorker } from "./cancellableProcess.js";
|
||||
import { testProcessIsAlive, waitForTestCondition } from "./processTestUtils.js";
|
||||
|
||||
const IS_POSIX = process.platform !== "win32";
|
||||
@@ -79,3 +79,16 @@ describe.skipIf(!IS_POSIX)("cancellable process tree teardown", () => {
|
||||
}
|
||||
}, 5_000);
|
||||
});
|
||||
|
||||
describe("render setup worker failure", () => {
|
||||
it("rejects with only the worker's reason, not its crash output", async () => {
|
||||
const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
||||
try {
|
||||
const failure = runRenderSetupWorker("bogus" as "lint", {}, {});
|
||||
|
||||
await expect(failure).rejects.toThrow(/^Unknown render setup mode: bogus$/);
|
||||
} finally {
|
||||
stderr.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { spawn, type ChildProcess, type SpawnOptions } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { terminateProcessTree } from "./processTree.js";
|
||||
import { renderSetupFailureFrom, renderSetupResultFrom } from "../renderSetupWorkerLifecycle.js";
|
||||
|
||||
export interface CancellableProcessResult {
|
||||
stdout: string;
|
||||
@@ -187,7 +188,13 @@ export function runCancellableProcess(
|
||||
});
|
||||
}
|
||||
|
||||
const SETUP_RESULT_PREFIX = "HYPERFRAMES_RENDER_SETUP_RESULT:";
|
||||
function renderSetupError(error: unknown): unknown {
|
||||
if (!(error instanceof CancellableProcessError)) return error;
|
||||
const failure = renderSetupFailureFrom(error.stderr);
|
||||
if (failure?.earlierOutput.trim()) process.stderr.write(`${failure.earlierOutput.trimEnd()}\n`);
|
||||
const reason = failure?.reason ?? error.stderr.trim();
|
||||
return reason ? new Error(reason, { cause: error }) : error;
|
||||
}
|
||||
|
||||
export async function runRenderSetupWorker<T>(
|
||||
mode: "browser" | "lint" | "orphan-cleanup",
|
||||
@@ -216,16 +223,10 @@ export async function runRenderSetupWorker<T>(
|
||||
);
|
||||
} catch (error) {
|
||||
if (options.signal?.aborted) options.signal.throwIfAborted();
|
||||
if (error instanceof CancellableProcessError && error.stderr.trim()) {
|
||||
throw new Error(error.stderr.trim(), { cause: error });
|
||||
}
|
||||
throw error;
|
||||
throw renderSetupError(error);
|
||||
}
|
||||
if (result.stderr) process.stderr.write(result.stderr);
|
||||
const encoded = result.stdout
|
||||
.split(/\r?\n/)
|
||||
.find((line) => line.startsWith(SETUP_RESULT_PREFIX))
|
||||
?.slice(SETUP_RESULT_PREFIX.length);
|
||||
if (!encoded) throw new Error(`${mode} setup process exited without a result`);
|
||||
return JSON.parse(encoded) as T;
|
||||
const value = renderSetupResultFrom(result.stdout);
|
||||
if (value === undefined) throw new Error(`${mode} setup process exited without a result`);
|
||||
return value as T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user