TypeScript
refactor(shared): test favicon selection through public API (#10005)
Julius Marminge3e544f8cda37
diff --git a/packages/shared/src/favicon.test.ts b/packages/shared/src/favicon.test.tsindex ce80a079b3f..676f7811011 100644--- a/packages/shared/src/favicon.test.ts+++ b/packages/shared/src/favicon.test.ts@@ -1,11 +1,6 @@import { describe, expect, it } from "@effect/vitest";-import {- explicitFaviconUrl,- faviconUrlForOrigin,- faviconUrlForPage,- toolActivityFaviconUrl,-} from "./favicon.ts";+import { faviconUrlForOrigin, toolActivityFaviconUrl } from "./favicon.ts";describe("faviconUrlForOrigin", () => {it.each([@@ -46,12 +41,12 @@ describe("faviconUrlForOrigin", () => {);});-describe("faviconUrlForPage", () => {+describe("toolActivityFaviconUrl", () => {it("uses the page origin instead of a third-party favicon service", () => {- expect(faviconUrlForPage("https://example.com/docs/page?q=1")).toBe(+ expect(toolActivityFaviconUrl({ pageUrl: "https://example.com/docs/page?q=1" }, "light")).toBe("https://example.com/favicon.ico",);- expect(faviconUrlForPage("http://localhost:5173/app")).toBe(+ expect(toolActivityFaviconUrl({ pageUrl: "http://localhost:5173/app" }, "light")).toBe("http://localhost:5173/favicon.ico",);});@@ -86,7 +81,17 @@ describe("faviconUrlForPage", () => {});it("accepts provider-supplied image URLs but rejects extension URLs", () => {- expect(explicitFaviconUrl("https://example.com/icon.png")).toBe("https://example.com/icon.png");- expect(explicitFaviconUrl("chrome-extension://example/_favicon/")).toBeNull();+ expect(+ toolActivityFaviconUrl(+ { pageUrl: "https://example.com/docs", faviconUrl: "https://example.com/icon.png" },+ "light",+ ),+ ).toBe("https://example.com/icon.png");+ expect(+ toolActivityFaviconUrl(+ { pageUrl: "https://example.com/docs", faviconUrl: "chrome-extension://example/_favicon/" },+ "light",+ ),+ ).toBe("https://example.com/favicon.ico");});});diff --git a/packages/shared/src/favicon.ts b/packages/shared/src/favicon.tsindex a3286b28e99..2c4847115b9 100644--- a/packages/shared/src/favicon.ts+++ b/packages/shared/src/favicon.ts@@ -5,7 +5,7 @@ import { isPublicFaviconHost } from "./hostClassification.ts";* conventional favicon and let the image element fall back to a browser glyph.* Chrome-backed tools can pass their tab's explicit favicon URL separately.*/-export function faviconUrlForPage(rawUrl: string | null | undefined, _size = 32): string | null {+function faviconUrlForPage(rawUrl: string | null | undefined, _size = 32): string | null {if (!rawUrl || rawUrl.length > 4096) return null;try {const pageUrl = new URL(rawUrl);@@ -40,7 +40,7 @@ function themedFaviconUrlForPage(}/** Accepts image URLs supplied by a trusted provider event. */-export function explicitFaviconUrl(rawUrl: string | null | undefined): string | null {+function explicitFaviconUrl(rawUrl: string | null | undefined): string | null {if (!rawUrl || rawUrl.length > 4096) return null;try {const url = new URL(rawUrl);