mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* fix(cli): render --json gives each missing tool, a held slot and an old Node its own code Every failed `render --json` answered with `error.code: "runtime_error"`, so a script could only tell a missing FFmpeg from a busy render slot by matching the human message. A CliRuntimeError now carries a code, as CliUsageError does, and the envelope reports it: chrome_not_found, ffmpeg_not_found, ffprobe_not_found, render_locked. A Node older than 22 prints the envelope too (node_version_unsupported) when the run asked for --json. Other failures keep runtime_error. Refs #7408 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * test(cli): give the bin entry test's runtimeVersion stub the new JSON export bin/hyperframes.mjs now imports runtimeVersionJson, so the stub dist file binEntry.test.ts writes must export it too, or the bin fails to load. --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
86 lines
2.9 KiB
TypeScript
86 lines
2.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { CliRuntimeError, CliUsageError } from "./commandResult.js";
|
|
import { failureMessage, jsonErrorBody, jsonFailure, recordFailure } from "./jsonError.js";
|
|
|
|
const runtime = { exitCode: 1, kind: "runtime_error" } as const;
|
|
|
|
describe("jsonFailure", () => {
|
|
it("builds the shared envelope, with a hint only when there is one", () => {
|
|
expect(jsonFailure("refused", "no")).toEqual({
|
|
ok: false,
|
|
error: { code: "refused", message: "no" },
|
|
});
|
|
expect(jsonFailure("refused", "no", "try")).toEqual({
|
|
ok: false,
|
|
error: { code: "refused", message: "no", hint: "try" },
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("failureMessage", () => {
|
|
it("unwraps a presented failure to its cause", () => {
|
|
const failed = new CliRuntimeError("Command failed", {
|
|
presented: true,
|
|
cause: new Error("No composition found in /x"),
|
|
});
|
|
expect(failureMessage(failed)).toBe("No composition found in /x");
|
|
});
|
|
|
|
it("falls back to what the command reported", () => {
|
|
recordFailure("Could not fetch render", "No credentials");
|
|
expect(failureMessage(new CliRuntimeError("Command failed", { presented: true }))).toBe(
|
|
"Could not fetch render",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("jsonErrorBody", () => {
|
|
it("keeps a usage error's own code, message and hint", () => {
|
|
const error = new CliUsageError("Unknown flag: --out", {
|
|
code: "unknown_flag",
|
|
hint: "Did you mean --output?",
|
|
});
|
|
expect(jsonErrorBody(error, { exitCode: 2, kind: "usage_error" }, "noise")).toEqual({
|
|
code: "unknown_flag",
|
|
message: "Unknown flag: --out",
|
|
hint: "Did you mean --output?",
|
|
});
|
|
});
|
|
|
|
it("uses the reported failure, with its hint, for a generic presented error", () => {
|
|
recordFailure("No composition found", "Run npx hyperframes init");
|
|
expect(
|
|
jsonErrorBody(new CliRuntimeError("Command failed", { presented: true }), runtime, "x"),
|
|
).toEqual({
|
|
code: "runtime_error",
|
|
message: "No composition found",
|
|
hint: "Run npx hyperframes init",
|
|
});
|
|
});
|
|
|
|
it("keeps a runtime error's own code next to the failure the command reported", () => {
|
|
recordFailure("FFmpeg not found", "Configured path does not exist");
|
|
const error = new CliRuntimeError("Command failed", {
|
|
presented: true,
|
|
code: "ffmpeg_not_found",
|
|
});
|
|
expect(jsonErrorBody(error, runtime, "x")).toEqual({
|
|
code: "ffmpeg_not_found",
|
|
message: "FFmpeg not found",
|
|
hint: "Configured path does not exist",
|
|
});
|
|
});
|
|
|
|
it("keeps a runtime error's own code when the message comes from its cause", () => {
|
|
const error = new CliRuntimeError("Command failed", {
|
|
presented: true,
|
|
cause: new Error("Another render is running (pid 7)"),
|
|
code: "render_locked",
|
|
});
|
|
expect(jsonErrorBody(error, runtime, "x")).toEqual({
|
|
code: "render_locked",
|
|
message: "Another render is running (pid 7)",
|
|
});
|
|
});
|
|
});
|