Skip to content

feat(rules): add links/no-contextual-inbound (#109) - #121

Merged
nc9 merged 2 commits into
mainfrom
loop/109-rules-links-pages-with-zero-contextual-i
Aug 24, 2026
Merged

nc9 merged 2 commits into
mainfrom
loop/109-rules-links-pages-with-zero-contextual-i

Conversation

@nc9

@nc9 nc9 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Closes #109

Part of #103 (V-04).

links/orphan-pages and links/weak-internal-links count RAW inbound links, with no container distinction — a link repeated in the sitewide footer of a 200-page site scores the same as a link from body copy. A page reachable only through chrome therefore has a healthy count and passes both while receiving no editorial support.

What changed

Link graph. LinkData.isChrome records whether the anchor sat inside a nav/header/footer/aside landmark (packages/parser/src/extractors/chrome.ts). Deliberately stricter than the existing detectLinkPosition, which also matches class/id substrings — too loose to drive a warning (class="post-nav" would reclassify a post's body links). Set by all three ParsedPage producers, including the parser's html.ts extractor, which is the one the crawler serialises into parsedData and which both rule paths re-read.

Bounded per-page scalar. SiteQuery.contextualIncomingLinkCounts() is accumulated in the SAME scan as incomingLinkCounts() — identical keys, order, universe handling and filters — so contextual <= all holds by construction. The legacy site.pages path rebuilds both counts in one pass.

The rule. Warns on contextual === 0 && raw >= minInboundLinks — exactly the band where orphan-pages stays silent, so the two never report the same page. Homepage exempt, same exclude handling as orphan-pages.

Backwards compatible: isChrome is optional; undefined counts as contextual on both paths, so a crawl DB stored before this change degrades to the pre-change numbers rather than flagging every page.

Acceptance criteria

  • The link graph records, per link, whether it sat inside site chrome (ancestor nav/header/footer/aside)
  • A bounded per-page scalar for contextual (non-chrome) inbound link count is available to rules from both the legacy site.pages path and the siteQuery accumulator
  • Both paths produce identical counts for the same crawl, covered by a test (site-query-link-rules-golden.test.ts: an explicit count-level parity assertion plus deep-equal rule output)
  • New site-scope rule links/no-contextual-inbound, registered in the rules catalog
  • Warns on pages whose contextual inbound count is 0 while their raw inbound count is above the orphan threshold
  • Excludes the homepage and honours the same exclude patterns as links/orphan-pages
  • Fixture: a page linked from the sitewide footer only — warns, and is NOT reported by links/orphan-pages
  • Fixture: a page linked once from body copy — no warning
  • Existing links/orphan-pages and links/weak-internal-links output is unchanged (their fixtures and expectations are untouched; the new cases use a separate fixture)
  • Rule page added to docs/, listed in docs/rules/links/index.mdx and docs/docs.json
  • streaming-rules-canonical-golden.test.ts: findings.length 98218 → 98219 and perRuleTally.length 276 → 277, each with a comment line naming this rule

Tests added

  • packages/rules/tests/no-contextual-inbound.test.ts — the two named fixtures plus homepage exemption, exclude patterns, threshold handoff with orphan-pages, nofollow chrome, pre-change crawls, sample cap.
  • packages/audit-engine/tests/site-query-link-rules-golden.test.ts — count-level parity, dual-path deep-equality, and the orphan-pages-stays-silent assertion on the same crawl.
  • packages/parser/tests/link-chrome.test.ts — landmark detection, nested wrappers, class/id names are not chrome.
  • apps/cli/tests/audit/parsed-page-producer-parity.test.ts — all three producers agree on isChrome.

Also

Docs rule counts were stale (README said 273 in one place and 275 in another; catalog was 276 — content/date-agreement's +1 was missed in #108). All brought to 277.

Not verified locally

Local bun/tsgo execution was blocked by this environment's command policy, so the typecheck and test suite were not run here — CI is the first execution. The golden-pin reasoning is spelled out in the test comment: the rule is site-scoped (one check, always) and passes on the 518-page fixture, whose only chrome link is the header nav's link to /, which is exempt.

nc9 and others added 2 commits August 25, 2026 08:07
Link graph now records per-link `isChrome` — anchor sat inside a
nav/header/footer/aside landmark. Landmark-strict on purpose: the existing
`detectLinkPosition` class/id heuristics are too loose to drive a warning.

Set by all three ParsedPage producers (parser html.ts, which is what the crawler
serialises into parsedData, plus both parseHtmlForRules copies), so both rule
paths see it.

SiteQuery gains `contextualIncomingLinkCounts()`, accumulated in the SAME pass as
`incomingLinkCounts()` — same keys, same order, same filters. Legacy site.pages
path rebuilds both counts identically; parity covered by
site-query-link-rules-golden.

New site-scope rule warns on contextual == 0 while raw >= the orphan threshold,
i.e. exactly where orphan-pages/weak-internal-links stay silent. Homepage and
excludePatterns handled as in orphan-pages. Neither existing rule's output moves.

Golden pins: findings 98218 -> 98219, tally 276 -> 277 (site-scoped, one check;
passes on the fixture — its only chrome link targets the exempt homepage).

Docs rule counts also brought back in step with the catalog (277); content/
date-agreement's +1 was missed in #108.

Signed-off-by: Nik Cubrilovic <[email protected]>
…test

detectLinkPosition resolves on the closest ancestor, so a link inside
<header><nav> is "nav", not "header". The assertion claimed "header"
and had been failing CI since the PR was opened; the rule under test
(isChrome) was always correct. #109

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the loop/109-rules-links-pages-with-zero-contextual-i branch from f2a4fd9 to 243100b Compare August 24, 2026 22:16
@nc9

nc9 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and fixed a pre-existing test failure.

Conflicts were all rule-count arithmetic (README, docs/index.mdx, docs/rules/index.mdx). main had resynced every count to 276 via #119/#122; this PR adds one rule, so they resolve to 277. Verified empirically rather than by arithmetic — loadAllRules() returns:

TOTAL: 277
CATEGORIES: 21
links: 15

which matches every number in the resolved docs.

Separately, this PR was never green. The CLI tests job had been failing since it was opened, on this PR's own new test:

link-chrome.test.ts:83
- expected ["header", "content", "nav"]
- received ["nav",    "content", "nav"]

The rule under test (isChrome) was always correct — all its assertions passed. The wrong assertion was on the unrelated position label, which this PR never touches: detectLinkPosition resolves on the closest ancestor, so a link in <header><nav> is "nav", not "header". That is exactly the "previous behaviour" the test's own comment says it is pinning, so I corrected the expectation and the comment rather than the code.

CI is now fully green.

@nc9
nc9 merged commit a2f3d5f into main Aug 24, 2026
14 checks passed
@nc9
nc9 deleted the loop/109-rules-links-pages-with-zero-contextual-i branch August 24, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rules(links): pages with zero CONTEXTUAL inbound links pass orphan-pages

1 participant