import { describe, expect, it } from "vitest"; import { classifyPage } from "./PageClassifier.ts"; import type { DomSnapshot } from "./dom/PageSummarizer.ts"; import { youtubeAdapter, redditAdapter } from "@src/connectors"; const base = (url: string, extra: Partial = {}): DomSnapshot => ({ url, title: "t", landmarks: ["main", "navigation"], candidates: [], video_elements: [], text_excerpt: "", scroll: { y: 0, height: 5000, viewport: 900 }, has_login_form: false, dialog_open: false, ...extra }); describe("classifyPage", () => { it("uses adapter url hints", () => { expect(classifyPage(base("https://www.youtube.com/results?search_query=ai"), youtubeAdapter.pageTypeHints).page_type).toBe("SEARCH_RESULTS"); expect(classifyPage(base("https://www.youtube.com/watch?v=dQw4w9WgXcQ"), youtubeAdapter.pageTypeHints).page_type).toBe("VIDEO_DETAIL"); expect(classifyPage(base("https://www.youtube.com/@someone/videos"), youtubeAdapter.pageTypeHints).page_type).toBe("CHANNEL"); expect(classifyPage(base("https://www.reddit.com/r/quebec/comments/abc123/titre/"), redditAdapter.pageTypeHints).page_type).toBe("POST_DETAIL"); expect(classifyPage(base("https://www.reddit.com/r/quebec/"), redditAdapter.pageTypeHints).page_type).toBe("GROUP"); }); it("flags login pages and unknown pages without throwing", () => { expect(classifyPage(base("https://example.com/x", { has_login_form: true })).page_type).toBe("LOGIN"); const u = classifyPage(base("https://example.com/whatever")); expect(u.page_type).toBe("UNKNOWN"); expect(u.confidence).toBeLessThan(0.5); }); });