mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(registry): glass-shard-title renders when mounted, and 4 skipped blocks install again * fix(registry): glass-shard-title loads in Studio and ?play, and its docs payload fails loudly * test(scripts): pin the glass payload's hdr guard for any quote style
62 lines
2.5 KiB
TypeScript
62 lines
2.5 KiB
TypeScript
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { validRegistryName, validRegistryManifest, validRegistryItem } from "./validation.js";
|
|
|
|
const item = {
|
|
name: "demo",
|
|
type: "hyperframes:component",
|
|
title: "Demo",
|
|
description: "Example",
|
|
files: [{ path: "demo.html", target: "components/demo.html", type: "hyperframes:snippet" }],
|
|
};
|
|
|
|
describe("registry manifest boundary", () => {
|
|
it("rejects cache-key traversal and marker breakouts", () => {
|
|
for (const name of ["x/../../../.config/tool", "demo -->", "a".repeat(129)])
|
|
expect(validRegistryName(name)).toBe(false);
|
|
expect(validRegistryName("demo-2")).toBe(true);
|
|
});
|
|
it("validates the published item schema and requested identity", () => {
|
|
expect(validRegistryItem(item, "demo", "hyperframes:component")).toBe(true);
|
|
expect(validRegistryItem(item, "other", "hyperframes:component")).toBe(false);
|
|
expect(validRegistryItem(item, "demo", "hyperframes:block")).toBe(false);
|
|
expect(
|
|
validRegistryItem(
|
|
{ ...item, files: [{ ...item.files[0], target: "../outside" }] },
|
|
"demo",
|
|
"hyperframes:component",
|
|
),
|
|
).toBe(false);
|
|
});
|
|
it("validates cached and remote top-level manifest shape and cardinality", () => {
|
|
const manifest = {
|
|
name: "registry",
|
|
homepage: "https://registry.example",
|
|
items: [{ name: "demo", type: "hyperframes:component" }],
|
|
};
|
|
expect(validRegistryManifest(manifest)).toBe(true);
|
|
expect(validRegistryManifest({ ...manifest, items: [{ name: "../outside" }] })).toBe(false);
|
|
expect(
|
|
validRegistryManifest({ ...manifest, items: Array(10_001).fill(manifest.items[0]) }),
|
|
).toBe(false);
|
|
});
|
|
it("accepts every registry-item.json the repo publishes", () => {
|
|
const registry = join(import.meta.dirname, "../../../../registry");
|
|
const rejected = readdirSync(registry, { withFileTypes: true })
|
|
.filter((dir) => dir.isDirectory())
|
|
.flatMap((dir) =>
|
|
readdirSync(join(registry, dir.name)).map((name) => ({ dir: dir.name, name })),
|
|
)
|
|
.filter(({ dir, name }) => existsSync(join(registry, dir, name, "registry-item.json")))
|
|
.filter(({ dir, name }) => {
|
|
const item = JSON.parse(
|
|
readFileSync(join(registry, dir, name, "registry-item.json"), "utf8"),
|
|
);
|
|
return !validRegistryItem(item, name, item.type);
|
|
})
|
|
.map(({ dir, name }) => `${dir}/${name}`);
|
|
expect(rejected).toEqual([]);
|
|
});
|
|
});
|