Skip to content

rules(links): anchor mismatch — inbound anchor text vs the target's title/H1/slug #110

Closed

Description

@nc9

Part of #103 (V-05).

links/anchor-text is page-scope and looks only at a page's outgoing links, asking whether the
text is empty or generic. Nothing asks the question that actually matters for topicality: does the
anchor text pointing at a page have anything to do with that page?

Real remainders found across the audited sites, after the false positives were eliminated:

  • A consultancy site — how I work -> /engage, x12, and it is the only anchor text that page
    ever receives.
  • squirrelscan.com — View all posts -> /blog, x18.
  • An agency site — phrasal anchors like wire that up -> /services/analytics.

Chrome anchors are template text and must be excluded, or every site fails on its own nav.

Must-not-fire — four traps, each of which produced phantom findings

  1. Extract anchor text with a separator between child nodes. Concatenating them yields
    CarpentryStructural & finish carpentrySee details, which matches nothing — 171 phantom
    mismatches on one site
    from this alone.
  2. Plurals must match. Fridges -> /repairs/fridge is a match. Compare with a stem or prefix
    rule, not set intersection.
  3. Two-character brand tokens are real tokens. LG -> /brands/lg must match; a length > 2
    token filter drops the only word in the anchor.
  4. Utility pages are never mismatch targets. /privacy, /terms, /contact are linked with
    boilerplate text by design.

And the counting rule, which is the subject of V-06 (#104): judge per (source page, target) pair,
not per link.

Depends on #109
Depends on #104

Acceptance Criteria

  • New site-scope rule links/anchor-mismatch, registered in the rules catalog
  • For each (source page, target page) pair joined by at least one contextual link, compares the pair's combined anchor text against the target's title, H1 and slug
  • Warns only when no meaningful token is shared, and reports the anchor text, the target URL and the target's title
  • Chrome links are excluded from the comparison entirely
  • Anchor text extraction inserts a separator between child nodes; fixture: a card whose link wraps a heading and a description resolves to space-separated tokens
  • Fixture: anchor Fridges -> page titled Fridge repairs at /repairs/fridge — no warning
  • Fixture: anchor LG -> /brands/lg — no warning
  • Fixture: /privacy linked as Privacy from every page — no warning
  • Fixture: anchor click here -> a page titled Commercial freezer repairs — warns
  • Escalates in the message when the mismatching anchor is the ONLY contextual anchor text a page receives
  • Byte-identical output across the legacy and siteQuery paths
  • Rule page added to docs/ and make validate passes there
  • packages/audit-engine/tests/streaming-rules-canonical-golden.test.ts updated: bump v1.findings.length and v1.perRuleTally.length by exactly one each, and add a comment line naming this rule as the cause, matching the convention already used for the six rules above it

Activity

  1. added
    enhancement
    P3
    size: M
    rules
    on Aug 19, 2026
  2. added theissue type on Oct 28, 2026
  3. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against main 26432b6 (rule landed as 94bc5ed and 447219c, first released in v0.0.165):

    # Criterion Result Evidence
    1 Site-scope rule links/anchor-mismatch, registered PASS packages/rules/src/links/anchor-mismatch.ts (scope: "site"), loadAllRules() returns it (317 rules, links category 14)
    2 Per (source, target) pair, combined anchor text vs title, H1, slug PASS AnchorGraphBuilder.addPage keys pairs by (target, source); evaluateAnchorGraph compares against title+H1 tokens plus slug tokens. anchor-mismatch.test.ts "the pair's combined anchor text is judged, per pair not per link"
    3 Warns only when no token shared; reports anchor text, target URL, target title PASS "click here -> Commercial freezer repairs warns and names anchor, URL and title" asserts all three in the item label
    4 Chrome links excluded PASS isContextualGraphLink drops isChrome; "chrome links are excluded entirely" (judged stays 1); also in the dual-path fixture
    5 Separator between child nodes; card fixture PASS anchor-text-separator.test.ts "a card wrapping a heading and a description is space separated" (both extractors, exact string); rule test "real HTML through parsePage: a card link separates its words"
    6 Fridges -> Fridge repairs at /repairs/fridge: no warning PASS "Fridges -> Fridge repairs at /repairs/fridge does not warn", plus tokensMatch unit asserts
    7 LG -> /brands/lg: no warning PASS "LG -> /brands/lg does not warn"; the same file asserts meaningfulTokens("LG") is ["lg"]
    8 /privacy linked from every page: no warning PASS "/privacy linked as Privacy from every page does not warn": anchors there are deliberately mismatching ("Legal notes", "Fine print") and judged is 1, so the exclusion is what keeps it quiet
    9 click here -> Commercial freezer repairs warns PASS same test as row 3
    10 Escalates when the only contextual anchor text PASS "escalates when the mismatch is the only contextual anchor text" (positive and a mixed negative control)
    11 Byte-identical across legacy and siteQuery paths PASS site-query-link-rules-golden.test.ts "streaming path is deep-equal to legacy AND flags only the mismatch" (siteQuery run gets empty site.pages) and four more dual-path cases; streaming-rules-canonical-golden.test.ts "v2 streaming snapshot is byte-identical to the v1 baseline" over the 518-page fixture
    12 Rule page in docs/, make validate passes PASS docs/rules/links/anchor-mismatch.mdx read in full, listed in docs/docs.json and the links index; make validate in docs/ passed (tangly check strict, links, glossary, 62 tests). Counts match code: Links 14 in README, docs index, rules index, seo index
    13 Canonical golden bumped by exactly one each, with a comment PASS streaming-rules-canonical-golden.test.ts: findings 103745 -> 103746 and perRuleTally 316 -> 317, each with a comment naming links/anchor-mismatch

    Ran on main, sequentially: anchor-mismatch.test.ts, anchor-text-separator.test.ts and site-query-link-rules-golden.test.ts (80 pass, 0 fail); streaming-rules-canonical-golden.test.ts and page-link-rows-projection.test.ts (5 pass, 0 fail). Local bun was 1.4.3.

    Memory bounds are not an acceptance item but were read: pair, token, character and per-page caps are tested ("any dropped pair turns the only-anchor escalation off", "the token budget truncates too", "an over-long word is dropped"), and the streaming path keeps one page batch resident. No whole-engine memory measurement was run.

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3enhancementrulessize: M

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions