Skip to content

Write HTML. Render video. Built for agents.

fix(catalog): registry set-delta check accepts intentional additions (#4287)

Miguel Ángel2c71a3a112a7
diff --git a/package.json b/package.json
index a281205b0f..8743467b56 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,7 @@
"player:perf": "bun run --filter @hyperframes/player perf",
"format:check": "oxfmt --check .",
"knip": "knip",
- "test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/publish-workflow.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/lint-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts",
+ "test:scripts": "node --import tsx --test scripts/animejs-v4-guidance.test.mjs scripts/check-tracked-artifacts.test.mjs scripts/check-registry-set-delta.test.mjs scripts/check-no-main-deletions.test.mjs scripts/check-pr-captures.test.mjs scripts/check-docs-snippet-motion.test.mjs scripts/registry-target-paths.test.mjs scripts/check-workspace-contracts.test.mjs scripts/check-media-use-copy-parity.test.mjs scripts/check-package-cycles.test.mjs scripts/check-cli-process-ownership.test.mjs scripts/check-large-files.test.mjs scripts/package-subpaths.test.mjs scripts/validate-release-channel.test.mjs scripts/publish-workflow.test.mjs scripts/install-workspace-dependencies.test.mjs scripts/draft-changelog.test.ts scripts/set-version.test.ts scripts/release-prepare.test.ts scripts/cli-options.test.ts scripts/changelog-weekly.test.ts scripts/claude-plugin-compression.test.ts scripts/catalog-payload-assets.test.ts scripts/host-registry-assets.test.ts scripts/catalog-preview-temp.test.ts scripts/catalog-hosted-files.test.ts scripts/player-cdn-pin.test.ts scripts/studio-runtime-smoke.test.mjs scripts/verify-packed-manifests.test.mjs scripts/lint-skills.test.mjs scripts/creator-editing-recipes.test.mjs packages/gcp-cloud-run/check-dockerfile-workspaces.test.mjs packages/core/scripts/writeGeneratedFile.test.ts scripts/catalog-drift.test.ts scripts/catalog-fetch-mirror.test.ts scripts/catalog-script-inlining.test.ts scripts/catalog-detail.test.ts scripts/generate-catalog-pages.test.ts scripts/verify-catalog-payloads.test.ts scripts/registry-skill-files.test.ts scripts/creator-editing-capabilities.test.mjs scripts/generate-catalog-previews.test.ts scripts/registry-primitive-payloads.test.ts registry/components/pan-stations/pan-stations.test.mjs && vitest run scripts/catalog/ scripts/contrastRatchet.test.ts scripts/generate-catalog-payloads.test.ts",
"typecheck:scripts": "tsc --noEmit -p scripts/tsconfig.json",
"test:skills": "node --test 'skills/**/*.test.mjs' 'packages/cli/src/media-use/**/*.test.mjs'",
"generate:previews": "tsx scripts/generate-template-previews.ts",
diff --git a/scripts/check-registry-set-delta.mjs b/scripts/check-registry-set-delta.mjs
index 52e4c71066..3977f4eb4c 100644
--- a/scripts/check-registry-set-delta.mjs
+++ b/scripts/check-registry-set-delta.mjs
@@ -1,27 +1,84 @@
#!/usr/bin/env node
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";
-const base = process.argv[2] ?? "origin/main";
-const run = (args) => execFileSync("git", args, { encoding: "utf8" }).trim();
-const baseManifest = JSON.parse(run(["show", base + ":registry/registry.json"]));
-const headManifest = JSON.parse(readFileSync("registry/registry.json", "utf8"));
-const deletedPaths = run(["diff", "--name-only", "--diff-filter=D", base + "...HEAD"])
- .split("\n")
- .filter((path) =>
- /^registry\/(?:blocks|components|examples)\/[^/]+\/registry-item\.json$/.test(path),
- );
-const removed = new Set(deletedPaths.map((path) => path.split("/")[2]));
-const baseNames = new Set(baseManifest.items.map(({ name }) => name));
-const headNames = new Set(headManifest.items.map(({ name }) => name));
-const expected = new Set([...baseNames].filter((name) => !removed.has(name)));
-const missing = [...expected].filter((name) => !headNames.has(name)).sort();
-const unexpected = [...headNames].filter((name) => !expected.has(name)).sort();
-if (missing.length || unexpected.length) {
- console.error("Registry item-set delta mismatch against " + base + ":");
- if (missing.length) console.error(" missing from registry.json: " + missing.join(", "));
- if (unexpected.length) console.error(" unexpected in registry.json: " + unexpected.join(", "));
- process.exit(1);
+import { resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const REGISTRY_ITEM_PATH =
+ /^registry\/(?:blocks|components|examples)\/([^/]+)\/registry-item\.json$/;
+
+export function registryItemNamesFromPaths(paths) {
+ const names = new Set();
+ for (const path of paths) {
+ const match = path.match(REGISTRY_ITEM_PATH);
+ if (match) names.add(match[1]);
+ }
+ return names;
}
-console.log(
- "Registry item-set delta matches " + removed.size + " intentional removals against " + base + ".",
-);
+
+// A name only counts as an intentional removal or addition when its own
+// registry-item.json file was deleted or added in the same diff — a bare
+// registry.json edit with no matching file change is never expected.
+export function computeRegistrySetDelta({ baseNames, headNames, removed, added }) {
+ const expected = new Set([...baseNames].filter((name) => !removed.has(name)));
+ for (const name of added) expected.add(name);
+ const missing = [...expected].filter((name) => !headNames.has(name)).sort();
+ const unexpected = [...headNames].filter((name) => !expected.has(name)).sort();
+ return { missing, unexpected };
+}
+
+function diffPaths(run, base, filter) {
+ return run(["diff", "--name-only", `--diff-filter=${filter}`, base + "...HEAD"])
+ .split("\n")
+ .filter(Boolean);
+}
+
+// IO is injected so the git/fs boundary can be swapped for a fake in tests;
+// the actual delta logic lives in computeRegistrySetDelta above.
+export function runRegistrySetDeltaCheck(base, { run, readRegistryJson }) {
+ const baseManifest = JSON.parse(run(["show", base + ":registry/registry.json"]));
+ const headManifest = JSON.parse(readRegistryJson());
+ const removed = registryItemNamesFromPaths(diffPaths(run, base, "D"));
+ const added = registryItemNamesFromPaths(diffPaths(run, base, "A"));
+ const baseNames = new Set(baseManifest.items.map(({ name }) => name));
+ const headNames = new Set(headManifest.items.map(({ name }) => name));
+ const { missing, unexpected } = computeRegistrySetDelta({ baseNames, headNames, removed, added });
+ return { missing, unexpected, removedCount: removed.size, addedCount: added.size };
+}
+
+export function formatRegistrySetDeltaResult({
+ base,
+ missing,
+ unexpected,
+ removedCount,
+ addedCount,
+}) {
+ const sections = [
+ ["missing from registry.json", missing],
+ ["unexpected in registry.json", unexpected],
+ ].filter(([, names]) => names.length > 0);
+ if (sections.length === 0) {
+ return {
+ ok: true,
+ text: `Registry item-set delta matches ${removedCount} removal(s) and ${addedCount} addition(s) against ${base}.`,
+ };
+ }
+ const lines = sections.map(([label, names]) => ` ${label}: ${names.join(", ")}`);
+ return {
+ ok: false,
+ text: ["Registry item-set delta mismatch against " + base + ":", ...lines].join("\n"),
+ };
+}
+
+function main() {
+ const base = process.argv[2] ?? "origin/main";
+ const run = (args) => execFileSync("git", args, { encoding: "utf8" }).trim();
+ const readRegistryJson = () => readFileSync("registry/registry.json", "utf8");
+ const delta = runRegistrySetDeltaCheck(base, { run, readRegistryJson });
+ const result = formatRegistrySetDeltaResult({ base, ...delta });
+ if (!result.ok) process.exitCode = 1;
+ console[result.ok ? "log" : "error"](result.text);
+}
+
+const entryPath = process.argv[1] ? resolve(process.argv[1]) : null;
+if (entryPath === fileURLToPath(import.meta.url)) main();
diff --git a/scripts/check-registry-set-delta.test.mjs b/scripts/check-registry-set-delta.test.mjs
new file mode 100644
index 0000000000..e38243668c
--- /dev/null
+++ b/scripts/check-registry-set-delta.test.mjs
@@ -0,0 +1,138 @@
+import assert from "node:assert/strict";
+import { describe, it } from "node:test";
+import {
+ computeRegistrySetDelta,
+ formatRegistrySetDeltaResult,
+ registryItemNamesFromPaths,
+ runRegistrySetDeltaCheck,
+} from "./check-registry-set-delta.mjs";
+
+describe("registryItemNamesFromPaths", () => {
+ it("extracts the item name from a registry-item.json path", () => {
+ assert.deepEqual(
+ registryItemNamesFromPaths([
+ "registry/components/text-match-cut/registry-item.json",
+ "registry/blocks/week-in-merges/registry-item.json",
+ ]),
+ new Set(["text-match-cut", "week-in-merges"]),
+ );
+ });
+
+ it("ignores paths that are not a top-level registry-item.json", () => {
+ assert.deepEqual(
+ registryItemNamesFromPaths([
+ "registry/components/text-match-cut/text-match-cut.html",
+ "registry/registry.json",
+ "docs/catalog/components/text-match-cut.mdx",
+ ]),
+ new Set(),
+ );
+ });
+});
+
+describe("computeRegistrySetDelta", () => {
+ it("passes a real addition backed by a new registry-item.json", () => {
+ const { missing, unexpected } = computeRegistrySetDelta({
+ baseNames: new Set(["existing"]),
+ headNames: new Set(["existing", "text-match-cut"]),
+ removed: new Set(),
+ added: new Set(["text-match-cut"]),
+ });
+ assert.deepEqual(missing, []);
+ assert.deepEqual(unexpected, []);
+ });
+
+ it("passes a real removal backed by a deleted registry-item.json", () => {
+ const { missing, unexpected } = computeRegistrySetDelta({
+ baseNames: new Set(["existing", "old-item"]),
+ headNames: new Set(["existing"]),
+ removed: new Set(["old-item"]),
+ added: new Set(),
+ });
+ assert.deepEqual(missing, []);
+ assert.deepEqual(unexpected, []);
+ });
+
+ it("fails a registry.json entry added with no matching registry-item.json file", () => {
+ const { missing, unexpected } = computeRegistrySetDelta({
+ baseNames: new Set(["existing"]),
+ headNames: new Set(["existing", "fake-item"]),
+ removed: new Set(),
+ added: new Set(),
+ });
+ assert.deepEqual(missing, []);
+ assert.deepEqual(unexpected, ["fake-item"]);
+ });
+
+ it("fails a registry.json entry deleted with no matching file deletion", () => {
+ const { missing, unexpected } = computeRegistrySetDelta({
+ baseNames: new Set(["existing", "still-on-disk"]),
+ headNames: new Set(["existing"]),
+ removed: new Set(),
+ added: new Set(),
+ });
+ assert.deepEqual(missing, ["still-on-disk"]);
+ assert.deepEqual(unexpected, []);
+ });
+});
+
+describe("runRegistrySetDeltaCheck", () => {
+ it("wires a fake git/fs boundary through to a clean addition result", () => {
+ const run = (args) => {
+ if (args[0] === "show") {
+ return JSON.stringify({ items: [{ name: "existing" }] });
+ }
+ // diff --name-only --diff-filter=A|D base...HEAD
+ const filter = args[2];
+ if (filter === "--diff-filter=A") {
+ return "registry/components/text-match-cut/registry-item.json\n";
+ }
+ return "";
+ };
+ const readRegistryJson = () =>
+ JSON.stringify({ items: [{ name: "existing" }, { name: "text-match-cut" }] });
+ const result = runRegistrySetDeltaCheck("origin/main", { run, readRegistryJson });
+ assert.deepEqual(result, {
+ missing: [],
+ unexpected: [],
+ removedCount: 0,
+ addedCount: 1,
+ });
+ });
+});
+
+describe("formatRegistrySetDeltaResult", () => {
+ it("reports ok with the removal/addition counts when the delta is clean", () => {
+ const result = formatRegistrySetDeltaResult({
+ base: "origin/main",
+ missing: [],
+ unexpected: [],
+ removedCount: 0,
+ addedCount: 1,
+ });
+ assert.equal(result.ok, true);
+ assert.equal(
+ result.text,
+ "Registry item-set delta matches 0 removal(s) and 1 addition(s) against origin/main.",
+ );
+ });
+
+ it("reports both missing and unexpected names on a mismatch", () => {
+ const result = formatRegistrySetDeltaResult({
+ base: "origin/main",
+ missing: ["still-on-disk"],
+ unexpected: ["fake-item"],
+ removedCount: 0,
+ addedCount: 0,
+ });
+ assert.equal(result.ok, false);
+ assert.equal(
+ result.text,
+ [
+ "Registry item-set delta mismatch against origin/main:",
+ " missing from registry.json: still-on-disk",
+ " unexpected in registry.json: fake-item",
+ ].join("\n"),
+ );
+ });
+});