Files
hyperframes/skills/media-use/scripts/lib/registry.test.mjs
T
WaterrrForever 4d3cdc3e4b feat(media-use): resolve official brand logos via a four-tier cascade (#2061)
* feat(media-use): resolve official brand logos via a four-tier cascade

Third-party brand logos (the meeting's 'credibility signals lost' gap)
had no acquisition path: capture only grabs the product's own site
assets, and HeyGen asset search returns generic look-alike icons for
brand queries (0/3 in testing — an X-in-a-circle for LinkedIn). Workers
could only fake a mark or drop it.

New resolve type 'logo', four tiers verified by a 54-brand stress test
(100% cascade hit across dev tools / big tech / non-tech / CN brands):

- svgl — official full-color vector SVGs + wordmark variants (40/54
  first-hits); search is substring-based, so entities pass through
  alias normalization (nextjs → 'next.js', aws → 'amazon web services')
- simple-icons (pinned CDN build) — official monochrome glyphs; catches
  the long tail (nike, visa, toyota, wechat, bytedance)
- github org avatar — known-org map only; a brand name is not a GitHub
  login, guessing risks same-named personal accounts
- domain favicon (DuckDuckGo ip3) — small-raster last resort; sub-500B
  responses are DDG's placeholder and rejected; frozen with a low_res
  provenance flag (chip-size use only)

logo joins the icon/image equivalence group (typesMatch) and the
images/ subdir, so entity cache hits interop with figma-imported marks.
A total miss falls through resolve's normal failure path — no special
casing. HeyGen search stays the icon provider; it is deliberately
absent from the logo cascade.

Docs: media-use gap/types/providers tables + example; the five
workflow banners now cover logos (catalog claim kept for media, 'from
their official sources' added for logos); product-launch story-design
and motion-graphics logo-reveal point at the new type; catalog
surfaces (CLAUDE.md / README / docs) updated in lockstep.

Verified: 19 unit tests + coverage row green; live smoke across all
four tiers (linkedin→svgl, nike→simple-icons, heygen→github.avatar,
amazon→favicon) plus a fabricated brand exiting 1 on the default miss
path. oxlint + oxfmt clean.

* test(media-use): sanction the four logo providers in the registry allowlist

svgl / simple-icons / github.avatar / favicon.ddg join the sanctioned
list — the logo cascade added in the previous commit. Full lib suite
95/95 green.

* test(media-use): gate the logo cascade behavior in CI + single-fetch favicon tier

Review follow-ups (miga-heygen, jrusso1020 on #2061):

- Eight mocked-network tests pin what the manual 54-brand stress test
  only asserted: descriptor shape, alias retry (svgl non-array payload
  → next query, simple-icons 404 → next slug), network-error → null
  fallthrough, the sub-500B placeholder rejection, github's
  no-guessing (zero fetches for unmapped entities), and the real
  cascade order landing tier by tier under a mocked network.
- faviconSearch now hands its verified bytes over as a local file, so
  the freeze step copies instead of re-downloading — one round-trip,
  and the size check is authoritative over what gets frozen.
- The header's hit counts are labeled as a stress-test snapshot, not a
  live invariant.

Full lib suite 103/103; live smoke re-verified (amazon → favicon.ddg,
frozen .ico).
2026-07-08 23:58:41 +08:00

167 lines
6.3 KiB
JavaScript

import { strict as assert } from "node:assert";
import { test } from "node:test";
import { getProviders, getProvider, listTypes, runProviders, runCapability } from "./registry.mjs";
// --- registry shape -------------------------------------------------------
test("listTypes exposes the v2 media types", () => {
const types = listTypes();
for (const t of ["bgm", "sfx", "image", "icon", "voice", "brand"]) {
assert.ok(types.includes(t), `missing type: ${t}`);
}
});
test("heygen provider is first for every type it serves", () => {
for (const t of ["bgm", "sfx", "image", "icon"]) {
const first = getProviders(t)[0];
assert.ok(first, `no enabled provider for ${t}`);
assert.match(first.name, /^heygen/, `${t} first provider is ${first.name}`);
}
});
test("sanctioned providers only: heygen, local mflux/kokoro, codex, design spec, logo tiers", () => {
const allowed =
/^heygen|^mflux\.local$|^kokoro\.local$|^codex\.image_gen$|^design_spec$|^svgl$|^simple-icons$|^github\.avatar$|^favicon\.ddg$/;
for (const t of listTypes()) {
for (const p of getProviders(t)) {
assert.ok(allowed.test(p.name), `${t} lists unsanctioned provider: ${p.name}`);
}
}
});
test("image cascade: heygen catalog, then local mflux, then the codex upsell", () => {
const ps = getProviders("image");
assert.match(ps[0].name, /^heygen/, "heygen catalog first");
const names = ps.map((p) => p.name);
const mflux = ps.find((p) => p.name === "mflux.local");
const codex = ps.find((p) => p.name === "codex.image_gen");
assert.ok(mflux && typeof mflux.generate === "function", "local mflux registered");
assert.ok(codex && typeof codex.generate === "function", "codex upsell registered");
assert.ok(names.indexOf("mflux.local") < names.indexOf("codex.image_gen"), "local before codex");
assert.ok(!mflux.network, "local mflux is kept under --local-only");
assert.ok(codex.network, "codex is network (skipped under --local-only)");
});
test("voice cascade: local Kokoro first (free), HeyGen TTS as the paid upsell", () => {
const ps = getProviders("voice");
assert.equal(ps[0].name, "kokoro.local", "local Kokoro comes first now (HeyGen TTS is paid)");
assert.ok(!ps[0].network, "local Kokoro kept under --local-only");
assert.ok(!ps[0].paid, "local Kokoro is free");
const heygen = ps.find((p) => p.name === "heygen.tts");
assert.ok(heygen && heygen.paid, "HeyGen TTS is the paid upsell");
assert.ok(heygen.network, "HeyGen TTS is network (skipped under --local-only)");
});
test("ctx.provider forces one generator (e.g. 'make an image WITH codex')", async () => {
const providers = [
{ name: "heygen.asset.search", network: true, search: async () => null },
{ name: "mflux.local", generate: async () => ({ hit: "local" }) },
{ name: "codex.image_gen", network: true, generate: async () => ({ hit: "codex" }) },
];
// no override: local wins (first generate to return non-null)
assert.deepEqual(await runProviders(providers, "generate", "x", {}), { hit: "local" });
// override to codex: skip local, use codex even though local would have worked
assert.deepEqual(await runProviders(providers, "generate", "x", { provider: "codex" }), {
hit: "codex",
});
// override matches the full name too
assert.deepEqual(
await runProviders(providers, "generate", "x", { provider: "codex.image_gen" }),
{ hit: "codex" },
);
// --local-only wins even over a forced network provider: no network call,
// clean miss (the caller surfaces the conflict). A forced LOCAL provider under
// --local-only still runs.
assert.equal(
await runProviders(providers, "generate", "x", { provider: "codex", localOnly: true }),
null,
);
assert.deepEqual(
await runProviders(providers, "generate", "x", { provider: "mflux", localOnly: true }),
{ hit: "local" },
);
});
test("getProvider returns the first provider with its type, throws for unknown", () => {
const p = getProvider("bgm");
assert.equal(p.type, "bgm");
assert.equal(typeof p.search, "function");
assert.throws(() => getProvider("unknown_type"), /unknown media type/);
});
test("getProviders throws for unknown type", () => {
assert.throws(() => getProviders("nope"), /unknown media type/);
});
// --- deterministic capability execution (runProviders core) ---------------
test("runProviders calls providers in order and returns the first non-null", async () => {
const calls = [];
const providers = [
{
name: "a",
enabled: true,
search: async () => {
calls.push("a");
return null;
},
},
{
name: "b",
enabled: true,
search: async () => {
calls.push("b");
return { hit: "b" };
},
},
{
name: "c",
enabled: true,
search: async () => {
calls.push("c");
return { hit: "c" };
},
},
];
const res = await runProviders(providers, "search", "x", {});
assert.deepEqual(res, { hit: "b" });
assert.deepEqual(calls, ["a", "b"], "must stop at first non-null, never call c");
});
test("runProviders skips providers missing the requested capability", async () => {
const providers = [
{ name: "a", enabled: true /* no search */ },
{ name: "b", enabled: true, search: async () => ({ hit: "b" }) },
];
const res = await runProviders(providers, "search", "x", {});
assert.deepEqual(res, { hit: "b" });
});
test("runProviders returns null when no provider yields a result", async () => {
const providers = [{ name: "a", enabled: true, search: async () => null }];
assert.equal(await runProviders(providers, "search", "x", {}), null);
});
test("runCapability('bgm','process') is null — process slot is graceful when unfilled", async () => {
assert.equal(await runCapability("bgm", "process", "x", {}), null);
});
test("--local-only skips every network provider (even free remote ones)", async () => {
let remoteRan = false;
const providers = [
{
name: "heygen",
network: true,
search: async () => {
remoteRan = true;
return { hit: "net" };
},
},
{ name: "local", search: async () => ({ hit: "local" }) },
];
assert.deepEqual(await runProviders(providers, "search", "x", { localOnly: true }), {
hit: "local",
});
assert.equal(remoteRan, false, "the remote provider must not be called offline");
});