Skip to content

fix(audit-engine,cli): entity map and the report builder count query-string variants with their canonical page #1350 - #1371

Closed
nc9 wants to merge 2 commits into
mainfrom
feat/canonical-fold-cloud-1350
Closed

nc9 wants to merge 2 commits into
mainfrom
feat/canonical-fold-cloud-1350

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1350

Public part of #1350 (the hosted wiring and the smart-audit union need the private surface; tracked in squirrelscan/repo#3691). No dependency on #1348.

  • buildV1Report (the builder the hosted container uses) takes foldCanonicalVariants: variants are counted with their canonical (totalPages, pages, checks' pages, canonicalVariants/canonicalVariantPages), folded after the score so the score does not move. Off by default; a site with no variants is byte-identical either way (test). It rewrites the caller's ruleResults checks in place (documented).
  • foldEntityMapVariants (exported from the entity-map barrel, core-contracts only) counts a variant's entities under its canonical page so entities.summary.pagesTotal equals meta.totalPages; entityMapVariantKeys re-keys the fold to the final URLs the entity map uses, so a redirected variant or canonical still folds (e2e). The stored map keeps every crawled page. morePages on nodes and edges is not re-counted.
  • "Wired into squirrel audit" means the entity-map fold only; the report builder flag is not on in any caller yet.
  • Tests: builder fold, no-variant parity, entity fold, re-keying, CLI e2e (plain and redirected variant); docs and CHANGELOG.

Skill change: none.

nik

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of the production code (I did not read the test files in depth). I found nothing that should block merge.

  • (low) report-stream.ts: canonicalVariantPages is built from variantOf, while canonicalVariants is the count of variant pages seen in the page batch. If page_features holds a row for a page that is not in the pages table, the two can disagree. A small test, or deriving the list from the pages actually seen, would keep them aligned.
  • (low) canonical-groups.ts: readCanonicalVariants swallows storage errors with catchAll and returns a partial or empty map. A failed read then silently turns folding off, and the entity map and the report can disagree. A logger.warn would help.
  • (low) readCanonicalVariants reaches getPageFeaturesPage through an as unknown as cast. That is fine as a duck-typed guard for non-SQLite storage, but a comment saying so would make the intent clear.
  • (nit) fold-variants.ts: entityCount takes the max across the canonical page and its variants. That is a reasonable heuristic. Say so in the docs if the number is user-visible.
  • (nit) audit.ts: the hardcoded batch size 500 could be a named constant.

Behaviour looks right. Folding happens after the score, the default is off, and foldEntityMapVariants returns the original map when nothing folds. Docs and CHANGELOG are updated.

nc9 added 2 commits October 31, 2026 07:33
… query-string variants with their canonical page #1350

Signed-off-by: Nik Cubrilovic <[email protected]>
… pages under; document in-place fold and morePages #1350

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the feat/canonical-fold-cloud-1350 branch from 1719087 to c560ed5 Compare October 30, 2026 20:35
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Reviewed the diff and found no blocking issues. The keyset and offset pagination match the storage implementations in packages/crawler/src/storage/sqlite.ts. The fold runs on a copy, so the stored entity map is untouched. I did not run the tests.

  • (low) canonical-groups.ts (readCanonicalVariants, entityMapVariantKeys): a storage read error is swallowed with Effect.catchAll(() => succeed([])) and the partial batch is used. A mid-scan failure yields a partially folded map or report with no log line. Consider a logger.warn so the mismatch with meta.totalPages can be diagnosed.
  • (low) fold-variants.ts: entityCount is merged with Math.max. If a variant carries entities the canonical page does not, the folded page's entityCount can be lower than its declares.length + references.length, depending on how the builder counts. Check that this matches the builder's definition of the count.
  • (nit) audit.ts: the nested Effect.runPromise calls inside the conditional are hard to read. Hoist them into a small local helper or a named variable.
  • (nit) report-stream.ts: foldChecksToCanonical rewrites ruleResults in place. The doc comment on foldCanonicalVariants says so, but a test asserting that a second buildV1Report call over the same results gives the same output would lock the idempotence in.

CHANGELOG, docs and tests are included.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.145 as 9465a86a cd0db522 via #1377. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.145. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 2026
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.

1 participant