mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 14:27:26 +00:00
EPIPE (darwin/linux), EOF (win32's UV_EOF for a closed named pipe) and ECONNRESET all mean the process reading our stdin has gone. Bucketed as authoring, telemetry blamed the composition for a host event. Matched on the errno code and on the message, since the code is lost when a worker pool flattens the error to a string. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
105 lines
4.7 KiB
TypeScript
105 lines
4.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { CaptureFailure, classifyCaptureFailure, isFatalCaptureFailure } from "./captureFailure.js";
|
|
|
|
describe("classifyCaptureFailure", () => {
|
|
it.each([
|
|
["Target closed", "transient_browser"],
|
|
["Runtime.callFunctionOn timed out after 30000ms", "protocol_timeout"],
|
|
["Runtime.evaluate timed out", "protocol_timeout"],
|
|
["Network.enable timed out. Increase the protocolTimeout setting.", "protocol_timeout"],
|
|
["[Parallel] Capture failed: Worker 0: Network.enable timed out", "protocol_timeout"],
|
|
[
|
|
"Page.captureScreenshot timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.",
|
|
"protocol_timeout",
|
|
],
|
|
["drawElement worker encode timed out (frame 42)", "protocol_timeout"],
|
|
["Waiting failed: 30000ms exceeded", "protocol_timeout"],
|
|
["JavaScript heap out of memory", "memory_exhaustion"],
|
|
["drawElement self-verify failed", "verification"],
|
|
["Composition has zero duration. Runtime ready: true", "authoring"],
|
|
["Protocol error (Page.captureScreenshot): Unable to capture screenshot", "transient_browser"],
|
|
[
|
|
"[Parallel] Capture failed: Worker 0: Protocol error (Page.captureScreenshot): Unable to capture screenshot",
|
|
"transient_browser",
|
|
],
|
|
// The timed-out variant of the same call stays protocol_timeout (checked first).
|
|
["Protocol error (Page.captureScreenshot): waiting for debugger timed out", "protocol_timeout"],
|
|
] as const)("classifies %s as %s", (message, kind) => {
|
|
expect(classifyCaptureFailure(new Error(message)).kind).toBe(kind);
|
|
});
|
|
|
|
it("lets the composed signal authoritatively classify cancellation", () => {
|
|
const controller = new AbortController();
|
|
controller.abort();
|
|
expect(
|
|
classifyCaptureFailure(new Error("Target closed"), { signal: controller.signal }).kind,
|
|
).toBe("cancelled");
|
|
});
|
|
|
|
it("lets a later cancellation override an already typed transient failure", () => {
|
|
const controller = new AbortController();
|
|
const transient = new CaptureFailure({
|
|
kind: "transient_browser",
|
|
message: "Target closed",
|
|
workerDiagnostics: [
|
|
{ workerId: 1, framesCaptured: 2, startFrame: 0, endFrame: 4, lines: ["Target closed"] },
|
|
],
|
|
});
|
|
controller.abort();
|
|
|
|
const cancelled = classifyCaptureFailure(transient, { signal: controller.signal });
|
|
|
|
expect(cancelled.kind).toBe("cancelled");
|
|
expect(cancelled.cause).toBe(transient);
|
|
expect(cancelled.workerDiagnostics).toEqual(transient.workerDiagnostics);
|
|
});
|
|
|
|
it("preserves cause and immutable worker diagnostics", () => {
|
|
const cause = Object.assign(new Error("write failed"), { code: "ENOSPC" });
|
|
const failure = classifyCaptureFailure(cause, {
|
|
workerDiagnostics: [
|
|
{ workerId: 2, framesCaptured: 3, startFrame: 0, endFrame: 10, lines: ["disk full"] },
|
|
],
|
|
});
|
|
|
|
expect(failure.kind).toBe("io");
|
|
expect(failure.cause).toBe(cause);
|
|
expect(failure.workerDiagnostics[0]?.workerId).toBe(2);
|
|
expect(Object.isFrozen(failure.workerDiagnostics)).toBe(true);
|
|
expect(Object.isFrozen(failure.workerDiagnostics[0]?.lines)).toBe(true);
|
|
});
|
|
|
|
it("classifies a broken encoder pipe as io, not authoring", () => {
|
|
// The streaming encoder's stdin write fails this way when ffmpeg dies
|
|
// first. Bucketed as authoring, PostHog blamed the composition for a host
|
|
// event and the cohort could not be root-caused.
|
|
for (const code of ["EPIPE", "EOF", "ECONNRESET"]) {
|
|
const withCode = Object.assign(new Error(`write ${code}`), { code });
|
|
expect(classifyCaptureFailure(withCode).kind).toBe("io");
|
|
// Flattened through a worker-pool message boundary the code is lost;
|
|
// the message alone must still classify.
|
|
expect(classifyCaptureFailure(new Error(`[Parallel] write ${code}`)).kind).toBe("io");
|
|
}
|
|
expect(classifyCaptureFailure(new Error("write to EPIPEline")).kind).toBe("authoring");
|
|
});
|
|
|
|
it("classifies repeated operation text in linear time", () => {
|
|
const repeatedCopy = "copy".repeat(25_000);
|
|
|
|
expect(classifyCaptureFailure(new Error(repeatedCopy)).kind).toBe("authoring");
|
|
expect(classifyCaptureFailure(new Error(`${repeatedCopy} failed`)).kind).toBe("io");
|
|
expect(classifyCaptureFailure(new Error("copy\nfailed")).kind).toBe("authoring");
|
|
});
|
|
|
|
it("marks structural failures fatal but leaves retryable failures non-fatal", () => {
|
|
expect(
|
|
isFatalCaptureFailure(new CaptureFailure({ kind: "authoring", message: "bad source" })),
|
|
).toBe(true);
|
|
expect(
|
|
isFatalCaptureFailure(
|
|
new CaptureFailure({ kind: "protocol_timeout", message: "protocol timeout" }),
|
|
),
|
|
).toBe(false);
|
|
});
|
|
});
|