mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-04 07:19:52 +00:00
* 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).
138 lines
5.7 KiB
JavaScript
138 lines
5.7 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert";
|
|
import { readFileSync } from "node:fs";
|
|
import {
|
|
entityFrom,
|
|
titleMatches,
|
|
svglQueriesFor,
|
|
simpleIconSlugsFor,
|
|
githubOrgFor,
|
|
faviconDomainFor,
|
|
svglSearch,
|
|
simpleIconsSearch,
|
|
githubAvatarSearch,
|
|
faviconSearch,
|
|
} from "./logo-provider.mjs";
|
|
import { getProviders, runProviders } from "./registry.mjs";
|
|
|
|
test("entityFrom strips filler words from the intent; --entity wins", () => {
|
|
assert.equal(entityFrom("LinkedIn logo"), "linkedin");
|
|
assert.equal(entityFrom("official Slack brand mark"), "slack");
|
|
assert.equal(entityFrom("anything", "Notion"), "notion");
|
|
});
|
|
|
|
test("titleMatches ignores case, spacing, punctuation — and rejects lookalikes", () => {
|
|
assert.ok(titleMatches("Next.js", "nextjs"));
|
|
assert.ok(titleMatches("Coca-Cola", "coca cola"));
|
|
assert.ok(!titleMatches("Slackware", "slack"));
|
|
});
|
|
|
|
test("svgl queries include the alias forms the raw entity can't match", () => {
|
|
assert.ok(svglQueriesFor("nextjs").includes("next.js"));
|
|
assert.ok(svglQueriesFor("aws").includes("amazon web services"));
|
|
assert.deepEqual(svglQueriesFor("figma"), ["figma"]);
|
|
});
|
|
|
|
test("simple-icons slugs cover the renamed entries", () => {
|
|
assert.ok(simpleIconSlugsFor("nextjs").includes("nextdotjs"));
|
|
assert.ok(simpleIconSlugsFor("aws").includes("amazonwebservices"));
|
|
assert.deepEqual(simpleIconSlugsFor("nike"), ["nike"]);
|
|
});
|
|
|
|
test("github avatar tier never guesses an org", () => {
|
|
assert.equal(githubOrgFor("slack"), "slackhq");
|
|
assert.equal(githubOrgFor("heygen"), "heygen-com");
|
|
assert.equal(githubOrgFor("some-random-startup"), null);
|
|
});
|
|
|
|
test("favicon domain defaults to <entity>.com with explicit overrides", () => {
|
|
assert.equal(faviconDomainFor("cocacola"), "coca-cola.com");
|
|
assert.equal(faviconDomainFor("stripe"), "stripe.com");
|
|
});
|
|
|
|
// --- async tiers, network mocked -------------------------------------------
|
|
// The 54-brand stress test is a manual snapshot; these pin the same behavior
|
|
// as CI gates: descriptor shape, alias retry, error→null fallthrough, the
|
|
// placeholder filter, and the real cascade order under a mocked network.
|
|
|
|
const json = (data) => new Response(JSON.stringify(data), { status: 200 });
|
|
const status = (code) => new Response(null, { status: code });
|
|
const bin = (n) => new Response(new Uint8Array(n), { status: 200 });
|
|
|
|
test("svglSearch returns the descriptor shape on an exact title hit", async (t) => {
|
|
t.mock.method(globalThis, "fetch", async () =>
|
|
json([{ title: "Figma", route: "https://svgl.app/library/figma.svg" }]),
|
|
);
|
|
const res = await svglSearch("Figma logo", {});
|
|
assert.equal(res.url, "https://svgl.app/library/figma.svg");
|
|
assert.equal(res.ext, ".svg");
|
|
assert.equal(res.metadata.provider, "svgl");
|
|
});
|
|
|
|
test("svglSearch skips a non-array payload and retries with the alias query", async (t) => {
|
|
const seen = [];
|
|
t.mock.method(globalThis, "fetch", async (url) => {
|
|
seen.push(decodeURIComponent(String(url)));
|
|
return seen.length === 1
|
|
? json({ error: "unexpected shape" })
|
|
: json([{ title: "Next.js", route: "https://svgl.app/library/nextjs.svg" }]);
|
|
});
|
|
const res = await svglSearch("nextjs logo", {});
|
|
assert.equal(res.metadata.provenance.query, "next.js", "hit came from the alias query");
|
|
assert.ok(seen.length >= 2, "raw query then alias");
|
|
});
|
|
|
|
test("svglSearch returns null when the network is down — the cascade falls through", async (t) => {
|
|
t.mock.method(globalThis, "fetch", async () => {
|
|
throw new Error("network down");
|
|
});
|
|
assert.equal(await svglSearch("figma logo", {}), null);
|
|
});
|
|
|
|
test("simpleIconsSearch falls to the next slug on a 404", async (t) => {
|
|
const seen = [];
|
|
t.mock.method(globalThis, "fetch", async (url) => {
|
|
seen.push(String(url));
|
|
return String(url).includes("amazonwebservices") ? status(200) : status(404);
|
|
});
|
|
const res = await simpleIconsSearch("aws logo", {});
|
|
assert.ok(res.url.endsWith("amazonwebservices.svg"));
|
|
assert.equal(seen.length, 2, "plain slug 404s first, alias slug hits");
|
|
});
|
|
|
|
test("faviconSearch rejects DDG's sub-500B placeholder with null", async (t) => {
|
|
t.mock.method(globalThis, "fetch", async () => bin(120));
|
|
assert.equal(await faviconSearch("someco logo", {}), null);
|
|
});
|
|
|
|
test("faviconSearch hands verified bytes over as a local file — one fetch, no re-download", async (t) => {
|
|
const fetchMock = t.mock.method(globalThis, "fetch", async () => bin(600));
|
|
const res = await faviconSearch("someco logo", {});
|
|
assert.ok(res.localPath, "returns a localPath, not a url");
|
|
assert.equal(readFileSync(res.localPath).byteLength, 600, "frozen bytes are the verified bytes");
|
|
assert.equal(fetchMock.mock.callCount(), 1, "single network round-trip");
|
|
assert.equal(res.metadata.provenance.low_res, true);
|
|
});
|
|
|
|
test("githubAvatarSearch never touches the network for an unmapped entity", async (t) => {
|
|
const fetchMock = t.mock.method(globalThis, "fetch", async () => status(200));
|
|
assert.equal(await githubAvatarSearch("some-random-startup logo", {}), null);
|
|
assert.equal(fetchMock.mock.callCount(), 0);
|
|
});
|
|
|
|
test("the real logo cascade falls through tier by tier to the first hit", async (t) => {
|
|
t.mock.method(globalThis, "fetch", async (url) => {
|
|
const u = String(url);
|
|
if (u.includes("api.svgl.app")) return json([]); // tier 1: no hit
|
|
if (u.includes("jsdelivr")) return status(404); // tier 2: no such slug
|
|
// tier 3 (github) is never called: entity is unmapped
|
|
if (u.includes("duckduckgo")) return bin(600); // tier 4: real favicon
|
|
throw new Error(`unexpected fetch: ${u}`);
|
|
});
|
|
const res = await runProviders(getProviders("logo"), "search", "zzzbrand logo", {
|
|
entity: "zzzbrand",
|
|
});
|
|
assert.ok(res, "cascade must land on the favicon tier");
|
|
assert.equal(res.metadata.provider, "favicon.ddg");
|
|
});
|