Skip to content

fix(rules): scope sitemap-lastmod-drift to the document's own JSON-LD node - #161

Merged
nc9 merged 3 commits into
mainfrom
fix/lastmod-drift-type-filter
Aug 31, 2026
Merged

nc9 merged 3 commits into
mainfrom
fix/lastmod-drift-type-filter

Conversation

@nc9

@nc9 nc9 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

crawl/sitemap-lastmod-drift compares a sitemap's lastmod against the page's own dateModified. Its schemaDateModified() took the first flattened JSON-LD node carrying any dateModified, with no @type filter.

So a page whose Article.dateModified agreed with its sitemap exactly still warned, as long as a sitewide node carried a stale date and happened to be written first:

A: @graph = [ {"@type":"WebSite", dateModified:"2020-01-01"},
              {"@type":"Article", dateModified:"2024-06-01"} ]   lastmod 2024-06-01
   -> [warn] sitemap-lastmod-ahead-of-page ... (1613 day(s))

B: same two nodes, Article first
   -> [pass]

Yoast and Rank Math emit the sitewide node ahead of the Article in @graph, so that is the common ordering, not the exotic one. The verdict should never have turned on it.

What changed

Only document-describing nodes feed the comparison — the guard the sibling rule content/date-agreement already shipped with. Rather than a second copy, the type vocabulary, the @type reader and the {"@value"} date unwrapper move to packages/rules/src/shared/schema-document.ts and both rules use it.

documentTypes(node) returns the node's document types in the order written, leaving the selection policy to each rule:

  • content/date-agreement takes [0] — its previous first-one-wins behaviour, unchanged.
  • crawl/sitemap-lastmod-drift prefers an Article-family node wherever it sits, and treats a node claiming both (["WebPage","BlogPosting"]) as the article either way round. No part of its verdict depends on node order now.

Unparseable values are skipped while scanning rather than returned, so a malformed date cannot hide a good one later in the graph or later in the same node's date list. With no document node carrying a usable dateModified the answer is nothing, and the rule falls through to the page's own meta/visible dates rather than borrowing a sitewide one. A page with no signal at all stays skipped, as before.

Second commit, separable: deltaDays used Math.round, putting the effective thresholds half a day past the documented ones. A 7.5-day gap warned and was quoted back as 8 day(s) under a message reading "older ... by more than 7 day(s)" — both the verdict and the number overstated. Math.floor makes the rule agree with its own copy, and makes the comment above it true (with behind_days: 0, a 20-hour same-day difference no longer warns with deltaDays: 1).

Behaviour changes a user could notice

  • Pages carrying a dated sitewide node ahead of their article node stop warning. That is the bug.
  • Pages whose only dated JSON-LD is sitewide no longer produce a drift finding from it. They fall to meta/visible dates, or are skipped as before.
  • The vocabulary now also recognises a @type written as a full IRI (https://schema.org/Article) or against the schema: prefix, and a whitespace-padded one. Neither rule read those before; content/date-agreement is affected by this widening too (such a node is now the document node rather than a reported fallback).
  • The drift rule now accepts a {"@value": ...} wrapper and a list of dates, which it previously ignored in favour of weaker signals.

All four are documented on the rule's docs page.

Tests

packages/rules/tests/sitemap-lastmod-drift.test.ts, 31 tests (was 20). The traps are asserted in both node orders, and in @graph and flat-array shapes, so none can pass on ordering luck. 8 of the new tests fail against the pre-fix rule, verified by checking out origin/main's copy of the rule under the new test file.

The old "dual-path parity" test called the same rule twice on the same object and could not fail. It is replaced with one that feeds a DOM contradicting the parsed scalars: verified falsifiable by mutating the rule to consult parsed.document, which the old test did not catch.

Green: 1,395 rules tests, 1,791 CLI tests, tsgo --noEmit across all packages, bun run format:check, make validate in docs/.

Reviewed with Codex over two rounds; every finding is addressed in the branch rather than deferred.

Refs squirrelscan/repo#1570

nc9 added 2 commits September 1, 2026 07:22
… node

schemaDateModified took the FIRST flattened node carrying any dateModified,
with no @type filter, so a page whose Article.dateModified agreed with its
sitemap lastmod exactly still warned when a sitewide WebSite node carried a
stale date - and passed once the same two nodes were reversed. Yoast and Rank
Math emit the sitewide node first in @graph, so that ordering is the common
one, and the verdict should never have depended on it.

Only nodes whose @type describes the DOCUMENT now feed the comparison, the
guard content/date-agreement already shipped with. The two rules share one copy
of it: the type vocabulary, the @type reader and the {"@value"} date unwrapper
move to shared/schema-document.ts, and date-agreement drops its local copies.
The vocabulary now also recognises a @type written as a full IRI
(https://schema.org/Article) or against the schema: prefix, which neither rule
read before; documentTypes returns the node's document types in the order
written, so date-agreement keeps its own first-one-wins policy unchanged.

Drift is stricter than that: an Article-family node wins wherever it sits, and
a node claiming both (["WebPage","BlogPosting"]) counts as the article either
way round, so no part of the verdict turns on node order. Unparseable values
are skipped while scanning rather than returned, so one node's malformed date
cannot hide a later node's good one. With no document node carrying a usable
dateModified the answer is nothing, and the rule falls through to the page's
own meta/visible dates rather than borrowing a sitewide one; a page with no
signal at all stays skipped, as before.

Every new fixture is asserted in both node orders, in @graph and flat-array
shapes. The dual-path parity test is replaced: it ran the same rule twice on
the same object and could not fail. It now feeds a DOM that contradicts the
parsed scalars, so a DOM fallback would diverge the two paths.

Refs #1570

Signed-off-by: Nik Cubrilovic <[email protected]>
deltaDays rounded, so the effective thresholds sat half a day past the
documented ones: with the default behind_days of 7, a 7.5-day gap warned and
was quoted back to the user as "8 day(s)" under a message reading "older ...
by more than 7 day(s)". Both the verdict and the number overstated the gap.

Truncating instead makes the rule agree with its own copy, and makes the
comment above it true: with behind_days at 0 a 20-hour same-day difference no
longer warns with deltaDays 1.

Refs #1570

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/lastmod-drift-type-filter branch from 0c29a0c to adaae05 Compare August 31, 2026 21:22
@nc9
nc9 merged commit 08294e6 into main Aug 31, 2026
13 checks passed
@nc9
nc9 deleted the fix/lastmod-drift-type-filter branch August 31, 2026 23:46
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