Skip to content

feat(report,cli): count query-string variants with their canonical page #858 - #1348

Closed
nc9 wants to merge 3 commits into
mainfrom
feat/canonical-groups-858
Closed

nc9 wants to merge 3 commits into
mainfrom
feat/canonical-groups-858

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Closes #858

Decision recorded on the issue (maintainer): group in the report by declared canonical, crawler unchanged, scores unchanged.

What changes (fresh crawls; a smart audit's carried union is not folded):

  • canonicalVariantMap (audit-engine): a crawled page whose rel=canonical resolves to a DIFFERENT crawled page of the same site and path (trailing slash and fragment tolerated; chains resolved, loops dropped) is a variant. No canonical, a self canonical, another path/host, or an uncrawled canonical = its own page.
  • foldChecksToCanonical: pageUrl, pages and item sourcePages (and an item that is itself a page) are mapped to the canonical page and deduped, in place, once, in reconstruct.
  • Variant pages leave report.pages, the structure counts and the summary lists, so totalPages, meta, structure sections and affected-page counts are canonical groups. Their checks move onto the canonical page's checks and still feed the tallies and score, so nothing in the score moves.
  • The report says it: meta.canonicalVariants, a note on the Scan: line (text, markdown, html), canonical-variants on <scan-scope> in the LLM output, scanScope.canonicalVariants persisted so squirrel report rebuilds the same.
  • scanScope.capped still counts every crawled page.

Before / after on the e2e fixture (6 crawled URLs: /, /contact, /about, /blog, /blog?page=2 with its own canonical, /contact?subject=Billing canonical /contact): before totalPages 6 and the meta-description finding lists 6 affected pages; after totalPages 5, 5 affected pages, canonicalVariants: 1, the paginated blog page stays separate, score identical. With no variants the map is empty and the report is byte-identical.

Tests: packages/audit-engine/tests/canonical-groups-858.test.ts (helpers, incl. controls and chains/loops) and apps/cli/tests/cli/audit-canonical-variants-858-e2e.test.ts (real CLI: json, text, llm agree). Known limits, in the docs: the entity map still lists every crawled URL; hosted/cloud reports are not folded yet (same helpers, separate wiring); smart-audit unions are not folded.

Docs: docs/cli/audit.mdx (new "Query-string variants"), docs/configuration/output.mdx, CHANGELOG under Unreleased. Skill: none (no CLI surface change).

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1348 (canonical variant grouping). I read the diff only and did not run the tests.

  • (medium) packages/audit-engine/src/canonical-groups.ts foldItem: an item that is itself a page gets its id rewritten to the canonical URL, but items is never deduped. When both /contact and /contact?subject=Billing appear as items of one check, the report ends up with two identical /contact items. pages and sourcePages are deduped; items should be too, or a test should show it can't happen.
  • (medium) apps/cli/src/reports/reconstruct.ts (6b): getPageFeaturesPage errors are swallowed with catchAll(() => []). A storage error therefore silently produces an empty map and ungrouped counts, with no log line and nothing in the report. Please at least log it. The loop also makes an extra full pass over the page features just for the canonical column. It is probably fine, but it is worth confirming against the existing feature pass.
  • (low) canonicalVariantMap matches the declared canonical against crawled by exact string (plus the trailing-slash and fragment variants). The crawler's normalizedUrl may differ from new URL(...).href in other ways, such as percent-encoding case, default ports or tracking-param stripping. Those canonicals fall back to "own page", which is safe but silently misses some groups. A test with an encoded path would pin this.
  • (low) pathKey ignores the query. /blog?page=3 declaring /blog?page=2 as canonical would fold, and so would any filter page whose canonical is another crawled query variant. That fits the stated intent, but add a test that documents it.
  • (low) Folding the variant's checks onto the canonical page makes that page's pageChecks larger. Any per-page issue counts, or summary lists that count checks per page, will now include the variant's findings. The PR says the score is unchanged; please also confirm the per-page issue counts in the JSON output.
  • (nit) canonical-groups.ts and coverage.ts have lines far over the repo's formatter width. oxfmt --check on the changed files would flag them. CI doesn't enforce this for those packages, but the new file is cheap to format.
  • (nit) The CHANGELOG, docs and golden-pin steps in AGENTS.md don't appear in the diff I read. docs/cli/audit.mdx and docs/configuration/output.mdx are touched, but I saw no CHANGELOG bullet, so please check.

The overall design is sound: report-time only, a no-op when there are no variants, and chain and loop handling is covered.

@nc9
nc9 force-pushed the feat/canonical-groups-858 branch from df620bf to 55abc22 Compare October 30, 2026 08:48
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Reviewed the canonical-variant grouping (canonical-groups.ts, reconstruct.ts, report renderers). I read the diff but did not run the tests. The design is sound: the map is empty for most audits, chains and loops are handled in linear time, and the renderers validate the stored counts. Findings:

  • (medium) canonical-groups.ts foldItem: an item with no sourcePages is rewritten when its id equals a variant URL. Item ids are not always page URLs. A link check whose item is the link target would have its id changed if that target is a crawled variant, for example /contact?subject=Billing. Restrict this to checks whose items are known to be pages, or add a test with a non-page item whose id matches a variant URL.
  • (medium) reconstruct.ts (pageChecks): a canonical page's per-page checks now include its variants' checks, unfiltered. If both the canonical and a variant fail the same rule, the page shows that issue twice, and any per-page issue counts or lists inflate. The PR says the score is unchanged, but I did not see a test for per-page counts. Please dedupe by rule id and message, or cover this case.
  • (low) canonicalVariants is the number of variant pages that were iterated, but canonicalVariantPages is built from every entry in variantOf. They disagree when a variant is skipped, for example by a status or filter early-exit. Derive both from one source.
  • (low) canonicalVariantPages is capped at 100 with no marker, so a reader cannot tell the list was truncated. canonicalVariants carries the true count, so this is minor. A short note in the docs would cover it.
  • (low) getPageFeaturesPage errors are swallowed with catchAll(() => succeed([])). A storage failure silently turns grouping off, and the report differs from a healthy run with no indication. Log it or surface it.
  • (nit) pathKey drops the trailing slash but keeps the query string out of the key only through pathname. That is correct, but it is worth a comment that this is intentional, since /a?x=1 and /a?x=2 fold together when each declares the other as canonical.
  • (nit) canonicalVariantsNote in scanScopeLine appends to the Scan: line, so any snapshot that matches the line exactly needs updating. Confirm that the docs and the REPORT_HTML_VERSION bump are covered if the HTML output changed.

…r other items of a touched check #858

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Reviewed the diff (the CLI reconstruct path, canonical-groups.ts, docs and the e2e test). I did not run the tests. I found no blocking problems.

  • (low) apps/cli/src/reports/reconstruct.ts (the 6b block): getPageFeaturesPage errors are swallowed with catchAll into an empty page. A storage error mid-pagination gives a partial canonicalRows, so the report silently folds fewer variants and the page totals shift with no signal. Consider logging, or skipping the fold entirely on error.
  • (low) canonicalVariants counts only the variants seen in the page loop, while canonicalVariantPages slices variantOf itself. If the loop skips pages (limits, non-HTML), the count and the list can disagree. Deriving both from one source would keep them consistent.
  • (nit) A variant is folded into its canonical even if that canonical page is non-2xx. The variant's status is then dropped from the status tallies. This is an edge case, and a unit test would document the intended behaviour.
  • (nit) canonical-groups.ts is not formatted in the oxfmt style used elsewhere. The packages are not CI-checked, so this is optional.
  • (nit) The test coverage looks good: the e2e test covers fold, pagination-stays-separate and the text and LLM formats. Please confirm there are unit tests for chain and loop resolution in canonicalVariantMap. The memoised chain walk is the trickiest part.

Docs: updated. The CHANGELOG bullet is present.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.144 as 5aefb9c9 32bc3315 a12bb84b via #1356. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.144. Closing this original.

nik

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.

Query-string variants of a page are counted as separate affected pages

1 participant