You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(citations): unit tests for classifyDomain and hostname helpers #198
Add unit tests for the citation source-category classifier in web/src/lib/citations/classify.ts.
It's pure, deterministic logic with clear ordered rules — a great test target.
⚠️Blocked by #195 — this needs the Vitest setup from #195 to be merged
first. Please don't start until the test runner exists.
What to do
Add web/src/lib/citations/classify.test.ts covering the exported functions.
classifyDomain(domain, ctx)
The rules are ordered — first match wins. Cover:
Precedence:you and competitor win over everything else. A domain that
is both in ctx.competitorDomains and would otherwise be a forum/social
must classify as competitor. Same for you over competitor.
Brand / competitor matching via ctx.brandDomains / ctx.competitorDomains,
including subdomains (suffix match, e.g. blog.mybrand.com → you).
forum / social / review / institutional list matches (use a known entry
from each list, plus a subdomain variant like old.reddit.com → forum).
Institutional TLD patterns:.edu, .gov, .mil, and the generic .ac.uk / .edu.tr / .gov.xx forms → institutional.
editorial list match.
Fallthrough to other for an unknown domain.
Empty context lists don't crash and don't false-match.
extractHostname(rawUrl)
Strips www. and lowercases (https://www.FOO.com/bar → foo.com).
Recovers a hostname from bare / stripped inputs (no scheme).
Returns null for empty / unparseable input.
normalizeDomain(raw)
Normalizes https://www.Foo.com/x and foo.COM/ → foo.com.
Returns '' for null / undefined.
Acceptance
cd web && yarn test runs the new suite and it passes.
The ordered-precedence behavior is explicitly covered.
No changes to classify.ts itself (test-only). If a genuine bug surfaces,
open a separate issue rather than changing behavior here.
Activity
gkhngyk commentedon Jun 8, 2026
Part of the test-infrastructure epic #125 (item 4). Blocked by #195.