Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2
3import { faviconUrlForOrigin, toolActivityFaviconUrl } from "./favicon.ts";
4
5describe("faviconUrlForOrigin", () => {
6 it.each([
7 "http://192.168.1.10:8080",
8 "http://localhost:3000",
9 "http://home.arpa",
10 "https://printer.local.",
11 "https://api.internal",
12 "https://box.tailnet.ts.net",
13 "http://127.1",
14 "http://0x7f000001",
15 "http://[::]",
16 "http://[::1]",
17 "http://[::ffff:192.168.1.10]",
18 "http://[fd00::1]",
19 "http://[fe80::1]",
20 "http://100.64.0.1",
21 "http://198.51.100.1",
22 "http://[2001:db8::1]",
23 "http://service.test",
24 "http://private.onion",
25 "http://127.1..",
26 ])("does not disclose %s to the favicon provider", (origin) => {
27 expect(faviconUrlForOrigin(origin)).toBeNull();
28 });
29
30 it("keeps the public origin, port and requested size", () => {
31 expect(faviconUrlForOrigin("https://github.com:8443/pingdotgg/t3code?private=query", 64)).toBe(
32 "https://www.google.com/s2/favicons?domain=github.com%3A8443&sz=64",
33 );
34 });
35
36 it.each([null, undefined, "", "invalid URL", "file:///tmp/private", "data:text/plain,private"])(
37 "rejects an invalid or unsupported origin %s",
38 (origin) => {
39 expect(faviconUrlForOrigin(origin)).toBeNull();
40 },
41 );
42});
43
44describe("toolActivityFaviconUrl", () => {
45 it("uses the page origin instead of a third-party favicon service", () => {
46 expect(toolActivityFaviconUrl({ pageUrl: "https://example.com/docs/page?q=1" }, "light")).toBe(
47 "https://example.com/favicon.ico",
48 );
49 expect(toolActivityFaviconUrl({ pageUrl: "http://localhost:5173/app" }, "light")).toBe(
50 "http://localhost:5173/favicon.ico",
51 );
52 });
53
54 it("selects site-owned light and dark variants without filtering full-color icons", () => {
55 expect(toolActivityFaviconUrl({ pageUrl: "https://github.com/openai/codex" }, "light")).toBe(
56 "https://github.githubassets.com/favicons/favicon.svg",
57 );
58 expect(toolActivityFaviconUrl({ pageUrl: "https://github.com/openai/codex" }, "dark")).toBe(
59 "https://github.githubassets.com/favicons/favicon-dark.svg",
60 );
61
62 const fullColorIcon = {
63 pageUrl: "https://example.com/docs",
64 faviconUrl: "https://cdn.example.com/full-color.png",
65 };
66 expect(toolActivityFaviconUrl(fullColorIcon, "light")).toBe(fullColorIcon.faviconUrl);
67 expect(toolActivityFaviconUrl(fullColorIcon, "dark")).toBe(fullColorIcon.faviconUrl);
68 });
69
70 it("prefers a provider-supplied dark favicon", () => {
71 expect(
72 toolActivityFaviconUrl(
73 {
74 pageUrl: "https://example.com/docs",
75 faviconUrl: "https://example.com/light.svg",
76 faviconUrlDark: "https://example.com/dark.svg",
77 },
78 "dark",
79 ),
80 ).toBe("https://example.com/dark.svg");
81 });
82
83 it("accepts provider-supplied image URLs but rejects extension URLs", () => {
84 expect(
85 toolActivityFaviconUrl(
86 { pageUrl: "https://example.com/docs", faviconUrl: "https://example.com/icon.png" },
87 "light",
88 ),
89 ).toBe("https://example.com/icon.png");
90 expect(
91 toolActivityFaviconUrl(
92 { pageUrl: "https://example.com/docs", faviconUrl: "chrome-extension://example/_favicon/" },
93 "light",
94 ),
95 ).toBe("https://example.com/favicon.ico");
96 });
97});