Repository navigation
feat(rules): add links/no-contextual-inbound (#109) - #121
Conversation
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]>
f2a4fd9 to
243100b
Compare
|
Rebased onto current Conflicts were all rule-count arithmetic (README, which matches every number in the resolved docs. Separately, this PR was never green. The The rule under test ( CI is now fully green. |
Closes #109
Part of #103 (V-04).
links/orphan-pagesandlinks/weak-internal-linkscount 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.isChromerecords whether the anchor sat inside anav/header/footer/asidelandmark (packages/parser/src/extractors/chrome.ts). Deliberately stricter than the existingdetectLinkPosition, 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'shtml.tsextractor, which is the one the crawler serialises intoparsedDataand which both rule paths re-read.Bounded per-page scalar.
SiteQuery.contextualIncomingLinkCounts()is accumulated in the SAME scan asincomingLinkCounts()— identical keys, order, universe handling and filters — socontextual <= allholds by construction. The legacysite.pagespath rebuilds both counts in one pass.The rule. Warns on
contextual === 0 && raw >= minInboundLinks— exactly the band whereorphan-pagesstays silent, so the two never report the same page. Homepage exempt, same exclude handling asorphan-pages.Backwards compatible:
isChromeis optional;undefinedcounts 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
nav/header/footer/aside)site.pagespath and thesiteQueryaccumulatorsite-query-link-rules-golden.test.ts: an explicit count-level parity assertion plus deep-equal rule output)links/no-contextual-inbound, registered in the rules cataloglinks/orphan-pageslinks/orphan-pageslinks/orphan-pagesandlinks/weak-internal-linksoutput is unchanged (their fixtures and expectations are untouched; the new cases use a separate fixture)docs/, listed indocs/rules/links/index.mdxanddocs/docs.jsonstreaming-rules-canonical-golden.test.ts:findings.length98218 → 98219 andperRuleTally.length276 → 277, each with a comment line naming this ruleTests added
packages/rules/tests/no-contextual-inbound.test.ts— the two named fixtures plus homepage exemption, exclude patterns, threshold handoff withorphan-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 theorphan-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 onisChrome.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/tsgoexecution 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.