Files
hyperframes/scripts/verify-catalog-payloads.test.ts
T
Michael Wang b7c26ff844 fix(catalog): payload check treats the optional caption-overrides.json as absent, not failed (#7813)
* fix(registry): catalog payload check passes a missing caption-overrides.json

The runtime requests an optional caption-overrides.json on any page with a
.caption-group and reads a 404 as "no overrides". The docs host has no such
file, so every caption payload that uses .caption-group (caption-emoji-pop,
caption-neon-accent, caption-pill-karaoke, caption-weight-shift) failed
verify:catalog-payloads with a 404, its console line, and an aborted request.
The check only ran on those payloads once a change regenerated them.

The verifier now sets that miss aside, as `hyperframes validate` already does
through shouldIgnoreHttpError. A non-404 status, any other failure on that URL,
and an invalid overrides file still fail. To match the console line by URL,
checkPageLoads now appends the resource URL to Chrome's "Failed to load
resource" message, whose text leaves it out.

* style(producer): name the failed resource URL instead of commenting it
2026-11-15 07:22:20 +00:00

142 lines
5.3 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
changedItems,
declaresWebgpu,
itemsFromDiff,
withoutAbortedMedia,
withoutMissingCaptionOverrides,
parsePayload,
remainingFailures,
withoutWebgpuAbsence,
} from "./verify-catalog-payloads.ts";
describe("itemsFromDiff", () => {
it("names the items whose block or component payload changed and ignores everything else", () => {
const diff = [
"docs/public/catalog/blocks/glass-shard-title.json",
"docs/public/catalog/components/liquid-glass-widgets.json",
"docs/public/catalog/items/glass-shard-title/assets/x.png",
"docs/public/catalog/vendor/three.core.json",
"docs/catalog/blocks/glass-shard-title.mdx",
"",
].join("\n");
assert.deepEqual([...itemsFromDiff(diff)].sort(), [
"glass-shard-title",
"liquid-glass-widgets",
]);
});
});
describe("declaresWebgpu", () => {
it("reads the webgpu tag from the item's own manifest", () => {
assert.equal(declaresWebgpu("blocks", "liquid-glass-widgets"), true);
assert.equal(declaresWebgpu("blocks", "glass-shard-title"), false);
assert.equal(declaresWebgpu("blocks", "no-such-item"), false);
});
});
describe("withoutWebgpuAbsence", () => {
const network = "404 GET http://localhost/public/catalog/x.png";
const absent = [
"pageerror: Frost: no WebGPU adapter",
"console.error: LiquidGlass: WebGPU not available",
"console.error: Failed to request adapter",
];
const unrelated = "pageerror: ReferenceError: liquid is not defined";
const otherAdapter = "console.error: Failed to request storage adapter";
it("passes a declared item's WebGPU-absent errors and keeps everything else", () => {
assert.deepEqual(withoutWebgpuAbsence(true, [...absent, unrelated, otherAdapter, network]), [
unrelated,
otherAdapter,
network,
]);
});
it("fails an undeclared item with the same wording", () => {
assert.deepEqual(withoutWebgpuAbsence(false, absent), absent);
});
});
describe("remainingFailures", () => {
const absent = "console.error: LiquidGlass: WebGPU not available";
it("forgives by the item's own manifest tag in the right folder", () => {
assert.deepEqual(remainingFailures("blocks", "liquid-glass-widgets", [absent]), []);
assert.deepEqual(remainingFailures("blocks", "glass-shard-title", [absent]), [absent]);
assert.deepEqual(remainingFailures("components", "liquid-glass-widgets", [absent]), [absent]);
});
});
describe("parsePayload", () => {
it("tells a live payload from a marker", () => {
assert.deepEqual(parsePayload('{"html":"<p></p>"}'), { kind: "live", html: "<p></p>" });
assert.deepEqual(parsePayload('{"unsupported":"canvas-draw-element"}'), {
kind: "marker",
reason: "canvas-draw-element",
});
});
});
describe("withoutAbortedMedia", () => {
it("drops an aborted media request and keeps a 404, an aborted script and any other failure", () => {
const kept = [
"404 GET http://localhost/a.mp4",
"request failed: https://cdn.example/x.js (net::ERR_ABORTED)",
"request failed: https://cdn.example/x.mp4 (net::ERR_NAME_NOT_RESOLVED)",
];
const aborted = "request failed: https://cdn.example/x.mp4 (net::ERR_ABORTED)";
assert.deepEqual(withoutAbortedMedia([aborted, ...kept]), kept);
});
});
describe("withoutMissingCaptionOverrides", () => {
it("drops the runtime's missing caption-overrides.json and keeps every other failure", () => {
const url = "http://localhost:4000/caption-overrides.json";
const miss = [
`404 GET ${url}`,
`console.error: Failed to load resource: the server responded with a status of 404 (Not Found) (${url})`,
`request failed: ${url} (net::ERR_ABORTED)`,
];
const kept = [
`500 GET ${url}`,
`request failed: ${url} (net::ERR_NAME_NOT_RESOLVED)`,
"404 GET http://localhost:4000/public/catalog/caption-overrides.json.png",
"404 GET http://localhost:4000/assets/caption-overrides.json",
"console.error: Failed to load resource: the server responded with a status of 404 (Not Found) (http://localhost:4000/x.png)",
"console.error: [HyperFrames] Invalid caption-overrides.json: expected an array",
];
assert.deepEqual(withoutMissingCaptionOverrides([...miss, ...kept]), kept);
});
});
it("browser selection includes regenerated edits and new untracked payloads", (t) => {
const root = mkdtempSync(join(tmpdir(), "catalog-selection-"));
t.after(() => rmSync(root, { recursive: true, force: true }));
const git = (...args: string[]) => execFileSync("git", args, { cwd: root });
mkdirSync(join(root, "docs/public/catalog/blocks"), { recursive: true });
const old = join(root, "docs/public/catalog/blocks/old.json");
writeFileSync(old, "{}");
git("init", "-q");
git("add", ".");
git(
"-c",
"user.name=Test",
"-c",
"user.email=test@example.invalid",
"-c",
"commit.gpgsign=false",
"commit",
"-qm",
"fixture",
);
writeFileSync(old, '{"html":"updated"}');
writeFileSync(join(root, "docs/public/catalog/blocks/new.json"), "{}");
assert.deepEqual([...changedItems("HEAD", root)].sort(), ["new", "old"]);
});