Files
heygen-com--hyperframes/packages/engine/src/services/frameCapture.test.ts
T
wehub-resource-sync 85453da49f
regression / regression-shards (style-16-prod style-9-prod style-17-prod iframe-render-compat variables-prod mp4-h265-sdr, shard-4) (push) Has been cancelled
regression / regression-shards (style-4-prod style-11-prod style-2-prod animejs-adapter typegpu-adapter parallel-capture-regression, shard-5) (push) Has been cancelled
regression / regression-shards (style-7-prod style-8-prod style-10-prod css-spinner-render-compat webm-transparency mp4-h264-sdr webm-vp9, shard-3) (push) Has been cancelled
regression / regression-shards (sub-composition-video style-18-prod raf-ball-render-compat font-variant-numeric sub-comp-t0 sub-comp-id-selector, shard-7) (push) Has been cancelled
Windows render verification / Detect changes (push) Has been cancelled
Windows render verification / Preflight (lint + format) (push) Has been cancelled
Windows render verification / Render on windows-latest (push) Has been cancelled
Windows render verification / Tests on windows-latest (push) Has been cancelled
CI / Detect changes (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Fallow audit (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Producer: integration tests (push) Has been cancelled
CI / Producer: unit tests (push) Has been cancelled
CI / File size check (push) Has been cancelled
CI / Test: skills (push) Has been cancelled
CI / Skills: manifest in sync (push) Has been cancelled
CI / CLI: npx shim (macos-latest) (push) Has been cancelled
CI / CLI: npx shim (ubuntu-latest) (push) Has been cancelled
CI / CLI: npx shim (windows-latest) (push) Has been cancelled
CI / SDK: unit + contract + smoke (push) Has been cancelled
CI / Test: runtime contract (push) Has been cancelled
CI / Studio: load smoke (push) Has been cancelled
CI / Smoke: global install (push) Has been cancelled
CI / CLI smoke (required) (push) Has been cancelled
CI / Semantic PR title (push) Has been cancelled
Player perf / Detect changes (push) Has been cancelled
Player perf / Preflight (lint + format) (push) Has been cancelled
Player perf / player-perf (push) Has been cancelled
Player perf / Perf: drift (push) Has been cancelled
Player perf / Perf: fps (push) Has been cancelled
Player perf / Perf: parity (push) Has been cancelled
Player perf / Perf: scrub (push) Has been cancelled
Player perf / Perf: load (push) Has been cancelled
preview-regression / Detect changes (push) Has been cancelled
preview-regression / Preflight (lint + format) (push) Has been cancelled
preview-regression / Preview parity (push) Has been cancelled
preview-regression / preview-regression (push) Has been cancelled
regression / regression (push) Has been cancelled
regression / Detect changes (push) Has been cancelled
regression / Preflight (lint + format) (push) Has been cancelled
regression / regression-shards (hdr-regression style-5-prod style-3-prod mov-prores, shard-1) (push) Has been cancelled
regression / regression-shards (overlay-montage-prod style-12-prod chat missing-host-comp-id png-sequence portrait-edge-bleed, shard-6) (push) Has been cancelled
regression / regression-shards (style-13-prod style-6-prod vignelli-stacking gsap-letters-render-compat audio-mux-parity, shard-8) (push) Has been cancelled
regression / regression-shards (style-15-prod hdr-hlg-regression style-1-prod many-cuts vfr-screen-recording render-symlinked-assets, shard-2) (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Docs / Validate docs (push) Has been cancelled
Sync skills to ClawHub / Publish changed skills (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:58:35 +08:00

225 lines
7.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import {
formatHttpErrorDiagnostic,
formatConsoleDiagnostic,
formatNavigationFailureDiagnostic,
formatNavigationStartDiagnostic,
formatRequestFailureDiagnostic,
isFontResourceError,
sanitizeDiagnosticUrl,
} from "./frameCapture.js";
describe("isFontResourceError", () => {
it("matches Google Fonts CSS load failures via location.url", () => {
expect(
isFontResourceError(
"error",
"Failed to load resource: net::ERR_FAILED",
"https://fonts.googleapis.com/css2?family=Inter",
),
).toBe(true);
});
it("matches gstatic font binaries via location.url", () => {
expect(
isFontResourceError(
"error",
"Failed to load resource: the server responded with a status of 404 (Not Found)",
"https://fonts.gstatic.com/s/inter/v12/foo.woff2",
),
).toBe(true);
});
it("matches self-hosted woff2 failures", () => {
expect(
isFontResourceError(
"error",
"Failed to load resource: net::ERR_CONNECTION_REFUSED",
"http://localhost:9999/font.woff2",
),
).toBe(true);
});
it("matches .ttf and .otf URLs", () => {
expect(
isFontResourceError("error", "Failed to load resource: 404", "http://example.com/a.ttf"),
).toBe(true);
expect(
isFontResourceError("error", "Failed to load resource: 404", "http://example.com/b.otf"),
).toBe(true);
});
it("does NOT match non-font resources (images, scripts, videos)", () => {
expect(
isFontResourceError("error", "Failed to load resource: 404", "https://example.com/img.png"),
).toBe(false);
expect(
isFontResourceError(
"error",
"Failed to load resource: 404",
"https://cdn.example.com/bundle.js",
),
).toBe(false);
expect(
isFontResourceError("error", "Failed to load resource: 404", "https://example.com/video.mp4"),
).toBe(false);
});
it("does NOT match when location.url is missing and text has no URL (safe default)", () => {
expect(isFontResourceError("error", "Failed to load resource: 404", "")).toBe(false);
});
it("still matches when URL appears in text (older Chrome formats)", () => {
expect(
isFontResourceError(
"error",
"Failed to load resource: https://fonts.googleapis.com/... 404",
"",
),
).toBe(true);
});
it("does NOT match non-error console messages", () => {
expect(
isFontResourceError(
"warn",
"Failed to load resource: 404",
"https://fonts.googleapis.com/css2",
),
).toBe(false);
expect(
isFontResourceError(
"info",
"Failed to load resource: 404",
"https://fonts.googleapis.com/css2",
),
).toBe(false);
});
it("does NOT match unrelated error messages", () => {
expect(isFontResourceError("error", "Uncaught ReferenceError: x is not defined", "")).toBe(
false,
);
expect(
isFontResourceError("error", "Some other error", "https://fonts.googleapis.com/css2"),
).toBe(false);
});
it("is case-insensitive for URL matching", () => {
expect(
isFontResourceError(
"error",
"Failed to load resource: 404",
"https://FONTS.GOOGLEAPIS.COM/css2",
),
).toBe(true);
expect(
isFontResourceError("error", "Failed to load resource: 404", "http://example.com/FONT.WOFF2"),
).toBe(true);
});
});
describe("formatConsoleDiagnostic", () => {
it("surfaces HyperFrames page logs with a dedicated host prefix", () => {
expect(
formatConsoleDiagnostic("info", "[hyperframes] render runtime fps JSHandle@object", ""),
).toEqual({
text: "[HyperFrames] render runtime fps JSHandle@object",
suppressHostLog: false,
});
});
it("keeps font load errors in diagnostics but suppresses host log noise", () => {
expect(
formatConsoleDiagnostic(
"error",
"Failed to load resource: net::ERR_FAILED",
"https://fonts.googleapis.com/css2?family=Inter",
),
).toEqual({
text: "[Browser] Failed to load resource: net::ERR_FAILED",
suppressHostLog: true,
});
});
it("preserves existing browser prefixes for generic logs", () => {
expect(formatConsoleDiagnostic("warn", "careful", "")).toEqual({
text: "[Browser:WARN] careful",
suppressHostLog: false,
});
});
});
describe("navigation diagnostics", () => {
it("redacts credentials, query strings, and fragments from diagnostic URLs", () => {
expect(
sanitizeDiagnosticUrl("https://user:pass@example.com/assets/video.mp4?token=secret#frag"),
).toBe("https://example.com/assets/video.mp4");
});
it("redacts data and blob URLs", () => {
expect(sanitizeDiagnosticUrl("data:image/png;base64,abc123")).toBe("data:<redacted>");
expect(sanitizeDiagnosticUrl("blob:https://example.com/abc123")).toBe("blob:<redacted>");
});
it("redacts query strings from relative URLs", () => {
expect(sanitizeDiagnosticUrl("/relative/path.png?token=secret#frag")).toBe(
"/relative/path.png",
);
});
it("formats page.goto failures with mode, timeout, elapsed time, and sanitized URL", () => {
const diagnostic = formatNavigationFailureDiagnostic({
captureMode: "screenshot",
url: "http://127.0.0.1:4173/index.html?claim_token=secret",
timeoutMs: 60_000,
elapsedMs: 60_123,
error: new Error("Navigation timeout of 60000 ms exceeded"),
});
expect(diagnostic).toContain("[FrameCapture:ERROR] page.goto failed");
expect(diagnostic).toContain("mode=screenshot");
expect(diagnostic).toContain("timeoutMs=60000");
expect(diagnostic).toContain("elapsedMs=60123");
expect(diagnostic).toContain("url=http://127.0.0.1:4173/index.html");
expect(diagnostic).not.toContain("claim_token");
});
it("formats page.goto starts with mode, timeout, and sanitized URL", () => {
const diagnostic = formatNavigationStartDiagnostic({
captureMode: "screenshot",
url: "http://127.0.0.1:4173/index.html?claim_token=secret",
timeoutMs: 60_000,
});
expect(diagnostic).toContain("[FrameCapture:NAV] page.goto start");
expect(diagnostic).toContain("mode=screenshot");
expect(diagnostic).toContain("timeoutMs=60000");
expect(diagnostic).toContain("url=http://127.0.0.1:4173/index.html");
expect(diagnostic).not.toContain("claim_token");
});
it("formats request and HTTP failures with sanitized URLs", () => {
expect(
formatRequestFailureDiagnostic({
method: "GET",
resourceType: "media",
url: "https://cdn.example.com/video.mp4?token=secret",
failureText: "net::ERR_FAILED",
}),
).toBe(
"[Browser:REQUESTFAILED] GET https://cdn.example.com/video.mp4 resource=media error=net::ERR_FAILED",
);
expect(
formatHttpErrorDiagnostic({
method: "GET",
resourceType: "image",
url: "https://cdn.example.com/frame.png?token=secret",
status: 403,
statusText: "Forbidden",
}),
).toBe("[Browser:HTTP403] GET https://cdn.example.com/frame.png resource=image Forbidden");
});
});