Skip to content

feat(rules): add crawl/sitemap-lastmod-drift (#107) - #114

Merged
nc9 merged 1 commit into
mainfrom
loop/107-rules-crawl-sitemap-lastmod-drifts-from-
Aug 19, 2026
Merged

nc9 merged 1 commit into
mainfrom
loop/107-rules-crawl-sitemap-lastmod-drifts-from-

Conversation

@nc9

@nc9 nc9 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Closes #107

New site-scope rule crawl/sitemap-lastmod-drift: for every crawled page present in a sitemap with a lastmod, compare that lastmod against the page's own strongest date signal and report the two directions separately, because they point at different code.

Check Fires when Usual cause
sitemap-lastmod-behind-page lastmod older than the page's dateModified by > behind_days (7) stale cached sitemap, or a generator resolving publishedAt ?? updatedAt while the route renders updatedAt ?? publishedAt
sitemap-lastmod-ahead-of-page lastmod newer by > ahead_days (30, configurable) lastmod stamped at build/deploy time

Each finding carries both dates, the source tier of the page date, and the delta in days; findings are sorted worst-first (URL tie-break) and capped at 50 items with the real total in details.

Page-date tiers: schema dateModified (flattened JSON-LD, @graph included) → the dateModified-equivalent markup the parser lifts from [itemprop="dateModified"] meta/<time> (visibleDateModified) → visible published date. Pages with none of these are skipped — that is content/freshness territory, not drift.

Acceptance criteria

  • New site-scope rule crawl/sitemap-lastmod-drift under packages/rules/src/crawl/, registered in the rules catalog
  • For each crawled page present in the sitemap, compares sitemap lastmod against the page's own strongest date signal (schema dateModified, else dateModified equivalent meta, else visible date)
  • Warns when lastmod is older than the page's dateModified by more than 7 days, reported as a distinct check name from the ahead case
  • Warns when lastmod is newer than the page's dateModified by more than a configurable threshold (default 30 days)
  • Each finding reports the two dates and the delta in days
  • Skips pages with no page-side date signal at all
  • Does NOT warn on same-day or within-threshold differences
  • Passes on a fixture where lastmod tracks dateModified per page
  • Byte-identical output across the legacy and siteQuery paths
  • Rule page added to docs/ (plus docs.json nav and the Crawlability card grid)
  • streaming-rules-canonical-golden.test.ts updated: v1.findings.length 98217 → 98218 and v1.perRuleTally.length 274 → 275, each with a comment naming this rule, matching the convention used for the rules above it

Notes

  • Dual-path parity: the rule reads only parsed-page scalars (parsed.schema.raw, visibleDateModified, visibleDatePublished) and never parsed.document, so the streaming site pass — where every DOM is dropped before site rules run and siteQuery is threaded — sees identical input and emits identical checks. It does not branch on ctx.siteQuery; a unit test asserts the output is unchanged when one is present, and the canonical 518-page v1↔v2 gate covers it end to end.
  • The "meta" tier resolves through the parser's existing [itemprop="dateModified"] meta/<time> extraction. OG article:modified_time is not carried as a parsed scalar today, so picking it up would need a new parser field across the parser and both audit adapters — deliberately left out of this rule's diff.
  • On the canonical golden fixture the sitemap carries no lastmod at all, so the rule contributes exactly one skipped check (hence +1 finding, +1 tally key, health score unmoved).
  • Local verification: bun/node execution is blocked in this environment (every invocation required an approval that could not be granted non-interactively), so the new tests, typecheck and make validate in docs/ were not run locally — CI (quality / cli-tests / engine-tests / docs) is the first execution of this change.

Site-scope rule comparing each sitemap lastmod against the page's own
strongest date signal (schema dateModified, else the dateModified-equivalent
itemprop/meta markup, else the visible date).

Two directions, distinct check names, since they point at different code:
- sitemap-lastmod-behind-page: lastmod older than dateModified by >7d
  (stale sitemap / inverted `publishedAt ?? updatedAt` precedence)
- sitemap-lastmod-ahead-of-page: lastmod newer by >30d, configurable
  (lastmod stamped at build time)

Each finding reports both dates plus the delta in days. Pages with no
page-side date are skipped (content/freshness territory), and same-day /
within-threshold gaps never warn. Reads only parsed-page scalars, never a
DOM, so output is identical on the legacy and siteQuery/streaming paths.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 merged commit 7733e1f into main Aug 19, 2026
14 checks passed
@nc9
nc9 deleted the loop/107-rules-crawl-sitemap-lastmod-drifts-from- branch August 19, 2026 10:25
nc9 added a commit that referenced this pull request Sep 12, 2026
…nce (squirrelscan/repo#2063) (#326)

* fix(audit-engine): refuse producer-carried checks as this run's evidence

A published report is the UNION of the crawl and the producer's own finding
store, with the replayed half tagged `provenance: "carried"`. The cloud merge
read every check's `pageUrl` as a page crawled this run, so a machine whose
local store still held an old audit turned it into cloud state: findings first
seen at the publish instant on pages the crawl never opened, and 129 "audited
pages" for a 16-page crawl. Two runs of the same site three minutes apart scored
50 and 88.

- `runCloudSmartAudits` drops carried/unrendered checks from `crawledUrls`,
  `freshFindings`, the union's fresh side and the #1167 sample sets. The cloud's
  OWN carry is unaffected: it is replayed from the store with the date the cloud
  last saw it. Surfaced as `replayedChecksDropped`.
- `foldOverflowChecks` keys groups on provenance as well as issue class. A mixed
  group folded to an aggregate with no provenance, which reads as evidence from
  this run, so a rule with enough carried pages to overflow the cap laundered
  every one of them.
- `buildStreamFindings` / `buildSkippedPassCounts` apply the same exclusion on
  the complete-store path, and `buildResolutionSignal` stops spending its budget
  on pages the run never evaluated.

Second half of the same bug: page identity was query-BLIND, so 384 `?id=N` pages
collapsed into one stored URL carrying 362 copies of one rule's finding. Adds
`normalizePageUrl` (query-preserving, everything else unchanged) and uses it for
page identity in the merge, the streamed findings and the resolution hashes.
`normalizeUrl` keeps its query-blind semantics for the comparisons that want
them (sitemap matching, link-count buckets, cache keys). The merge accepts a
resolution hash under either spelling, so an older publisher over-carries rather
than resolving a finding that is still there.

Closes #2063

Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA
Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(audit-engine): count provenance-split fold classes in the bounded report

Review follow-up to the #2063 fold change. `complete-store-fold` counted
`(name, status)` classes and used that count as the re-fold's `maxChecks`, so a
class that now splits into a carried and an unrendered aggregate was capped at
one: the two merged, an occurrence went missing, and the survivor was then
reconciled against a class key it no longer matched, which deleted its
provenance and last-seen. Keys the accumulator, the cap and the reconciliation
on the shared `foldGroupKey`.

Also tie-breaks the fold's sort on that key. Provenance splits a class into up to
three aggregates, which `(name, status)` no longer separates, leaving their order
to rule execution order — nondeterministic (#114), so a repeat audit could emit a
different byte sequence.

Two existing tests asserted the old mixed-provenance behaviour and now assert the
split; one fixture gains a `site_pages` row so the drop it exercises still
happens.

Documents the complete-store identity contract (producer and consumer must run
one engine build) and why coverage counts evidenced pages rather than the raw
crawl count; the residual sampling gap is #2067.

Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA
Signed-off-by: Nik Cubrilovic <[email protected]>

* feat(audit-engine): report how many replayed pages the cloud has never seen

#2063 ran for a month with nothing saying it was happening. The count of refused
checks cannot say it either: an ordinary partial re-audit replays thousands of
them for pages the cloud knows, and carries those from its own store as always.

`replayedUnknownPages` counts the pages a producer's replayed checks named that
this site has no record of — not crawled this run, not known from any earlier
audit. That is the mechanism, not a proxy for it: 508 such pages against a
16-page crawl was the incident. The set is bounded by pages, built only in the
sampled branch, and dropped once counted.

Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA
Signed-off-by: Nik Cubrilovic <[email protected]>

* fix(audit-engine): keep replays out of the complete-store union too

Acceptance review found the sampled branch covered and the complete-store branch
not. It copied the staged shell's checks into `freshResults` unchanged, and the
shell is that path's report body: a producer's replayed check reached
`freshForUnion` and the union, landing beside the cloud's own carry for the same
page, with the producer's date, on a page the crawl never fetched. Reproduced in
both the materialized and the streamed variant.

Complete mode deliberately does not unfold — the shell's aggregates ARE its
display surface — so a replay arrives there as a per-page check OR as a folded
aggregate naming its pages. `isReplayedCheck` now matches both, using
`unfoldAggregateCheck`'s own gate so the two branches agree on what an aggregate
is. Genuine site-scope checks stay: the tally fold scores those verbatim.

Every rule keeps its key even when all of its checks go, because the fold reads
rule membership to decide which rules the shell already handled. The filtered
shell is what both tally-fold entry points read now, rather than the raw input.

Tests, each checked by removing the one line it protects: a genuinely truncated
carried aggregate whose sample names a page the fresh aggregate clipped out (the
shape that resolves a finding the crawl never re-examined), both complete-store
variants asserting union contents, `unrendered` as check and as aggregate, and
the two `stream-findings` guards.

Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA
Signed-off-by: Nik Cubrilovic <[email protected]>

* test(audit-engine): pin the pass count of a rule the replay filter empties

Review nit on the previous commit: the complete-store tests asserted union
contents but never the tallies, and every rule in them kept a check — so nothing
failed when the emptied rules were dropped from the shell or when the folds were
handed the raw input.

A page rule whose every published check is a replay ends up with no checks and
must still keep its KEY, because `foldShellRules` reads rule membership to give
it the fresh-clean pass count for the pages the crawl found nothing on. Dropping
it loses those passes out of the denominator, which is #918 in miniature. The new
test asserts that tally directly and fails if the key goes.

Also corrects two comments the review caught: dropping an emptied rule loses
fresh-clean passes rather than double-counting, and the page-attribution gate
reads the CHECK's shape rather than the rule's scope — an aggregate naming pages
is a page replay whichever rule emitted it. Documents that the refused-check
counter's unit differs by mode, since the sampled branch unfolds before it
filters and complete mode never unfolds.

Claude-Session: https://claude.ai/code/session_0174D96WamG9ZhJxRudpeniA
Signed-off-by: Nik Cubrilovic <[email protected]>

---------

Signed-off-by: Nik Cubrilovic <[email protected]>
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(crawl): sitemap lastmod drifts from the page's own dateModified

1 participant