Skip to content

fix(rules): sitemap lastmod drift and churn read a bare year or year-month as that whole period #758 - #771

Merged
nc9 merged 2 commits into
mainfrom
fix/lastmod-partial-dates-758
Oct 14, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/lastmod-partial-dates-758

Conversation

@nc9

@nc9 nc9 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #758.

What changed

The W3C Datetime format sitemaps use allows YYYY and YYYY-MM, which name a whole year or month. Both lastmod rules read them as the first instant of that period (new Date("2024") is 2024-01-01T00:00Z). A year-stamped sitemap looked months behind every page dated later that year (lastmod 2024 vs dateModified 2024-09-10 (253 day(s))), and churn reported a day the sitemap never wrote. #757 made such sitemaps parse, which exposed it.

  • w3cDatePeriod (packages/rules/src/shared/w3c-date-period.ts): turns a lastmod into { start, end, precision }.
    • 2024 covers 2024-01-01T00:00Z to 2024-12-31T23:59:59.999Z.
    • 2024-09 covers that month.
    • Anything finer that Date parses is one instant (start = end).
    • A month outside 01-12, or a value that does not parse, is null.
  • crawl/sitemap-lastmod-drift: a page date inside the period agrees. A page date after the period is behind, measured from its end; a page date before it is ahead, measured from its start. Full datetimes behave exactly as before, since start = end.
  • crawl/sitemap-lastmod-churn: a year or month names no day, so it is left out of the day sample instead of being read as its first day. It is counted as coarseLastmods in the skip details and coarseLastmodsExcluded in the warn and pass details. A news sitemap's values are counted as news first, as before. When counting the coarse values would have reached the 20-URL minimum, the skip says the values are too coarse; otherwise it is still "too few". Message template: N sitemap lastmod value(s) name only a year or month, which says nothing about the day a page changed; M name a day, too few to judge lastmod churn.

Acceptance criteria

  • crawl/sitemap-lastmod-drift treats a YYYY or YYYY-MM lastmod as the whole year or month: a page dateModified inside that period is not drift, and drift outside it is measured from the nearer end of the period. (2024 vs 2024-09-10 passes; 2023 vs 2024-09-10 is 253 days behind, counted from the end of 2023; 2024-09 vs 2024-10-15 is 14 days behind; 2025 vs 2024-09-10 is 113 days ahead.)
  • crawl/sitemap-lastmod-churn never reports a day the sitemap did not write for a YYYY or YYYY-MM lastmod. Such entries are left out and counted.
  • Rule tests cover 2024, 2024-09 and a full datetime for both rules (packages/rules/tests/sitemap-lastmod-partial-dates-758.test.ts).

Verification

  • packages/rules: the new file has 9 tests and passes. They also cover December rollover, leap February, 2024-00, year 0099 (built with setUTCFullYear, since Date.UTC maps 0 to 99 onto 19xx), and both skip choices. 4 of the original 7 fail against main's rules.
  • Date reading elsewhere with the same kind of issue (cloaking-probe recency, page-side dates, the local-time fallback, churn's UTC day for offsets) is Partial and offset dates elsewhere: cloaking-probe recency, page-side dates in lastmod drift, local-time fallback, churn's UTC day #772. The existing sitemap-lastmod-drift, sitemap-lastmod-churn and sitemap-valid tests pass (54 with the new file).
  • packages/audit-engine: streaming-rules-canonical-golden and cloaking-probe pass, with no re-pin.
  • tsgo --noEmit in packages/rules is clean, and oxlint is clean on the changed files. The new files are oxfmt-clean, and detect-secrets is clean.
  • docs/: tangly check --strict passes. The drift and churn rule pages say how a year or month lastmod is read.

Agent skill

No change needed.

@claude

claude Bot commented Oct 14, 2026

Copy link
Copy Markdown

Review of #771: I found no blocking issues. I read the diff only and did not run the tests.

  • (nit) packages/rules/src/shared/w3c-date-period.ts: values like 2024-9 (one-digit month) fall through to new Date(). That parse is engine-dependent and gives an instant, not a month. It is an edge case, and crawl/sitemap-valid is the right place to flag it. A comment saying this is deliberate would help.
  • (nit) sitemap-lastmod-churn.ts: the newsOnly condition now also requires coarseLastmods === 0. A sitemap with some news URLs plus some coarse ones therefore gets the generic or coarse message. That seems right, but no test covers the mixed case.
  • (nit) The drift boundary is covered for the inside, before and after cases. A test with a page date exactly at period.end or period.start would pin the 0-day gap.

The logic looks correct. Start and end are computed in UTC, the December rollover and the sub-100 year handling are right, and full datetimes behave as before because start equals end. The tests cover both rules, and the docs and CHANGELOG are updated.

nc9 added 2 commits October 15, 2026 02:33
…month as that whole period #758

The W3C Datetime format allows `2024` and `2024-09`, which name a whole year
or month. Both rules read them as the first instant (`new Date("2024")` is
2024-01-01T00:00Z), so a year-stamped sitemap looked months behind every
page dated later that year, and churn reported a day nobody wrote. #757
made such sitemaps parse, which exposed it.

A shared w3cDatePeriod turns a lastmod into {start, end, precision}.
Drift treats a page date inside the period as agreeing and measures one
outside it from the nearer end. Churn leaves year and month values out of
its day sample (counted as coarseLastmods / coarseLastmodsExcluded), with a
skip message that says why when they are most of the sample.

Signed-off-by: Nik Cubrilovic <[email protected]>
…arse skip only when they made the difference; years below 100 #758

From review: a news sitemap's year-month lastmods were counted nowhere, so
the news-only skip turned into "Only 0 sitemap URL(s)". The news check now
runs first. The "too coarse" skip is chosen only when counting the coarse
values would have reached the minimum; otherwise it is still "too few".
w3cDatePeriod builds its timestamps with setUTCFullYear, since Date.UTC
maps years 0 to 99 onto 1900 to 1999. Tests cover December rollover, leap
February, 2024-00, year 0099, and both skip choices. Remaining date
reading elsewhere is #772.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/lastmod-partial-dates-758 branch from 2073bac to f239154 Compare October 14, 2026 15:33
@claude

claude Bot commented Oct 14, 2026

Copy link
Copy Markdown

Reviewed the diff. I found no correctness, security or performance problems. I read the code but did not run the tests.

  • (low) packages/rules/src/crawl/sitemap-lastmod-churn.ts (newsOnly / coarseOnly): if a site has news-sitemap lastmods plus a few coarse ones, and fewer than 20 lastmods in total, it falls through to Only 0 sitemap URL(s) carry a lastmod; ... too small. That is misleading, because news lastmods and coarse lastmods do exist. The tests don't cover this mixed case.
  • (nit) sitemap-lastmod-drift.ts still has parseDate for the page-side dates, while w3cDatePeriod has its own new Date(value) fallback for the lastmod side. If the two parsers ever diverge, the drift comparison will mix formats. A comment saying why both exist, or having parseDate call the shared helper, would help.
  • (nit) The YEAR and YEAR_MONTH regexes in w3c-date-period.ts accept surrounding whitespace, but other new Date inputs are also trimmed implicitly. This is consistent, so it needs no action.

The rest looks good. The period maths is correct, including the leap-year February case, December rolling into the next year, and years below 100. The behind/ahead comparisons now use the period boundaries, so a page date inside the period gives a gap of 0, which is right. The tests cover the new helper, drift and churn. The CHANGELOG and docs are updated.

@nc9
nc9 merged commit 603c541 into main Oct 14, 2026
15 checks passed
@nc9
nc9 deleted the fix/lastmod-partial-dates-758 branch October 14, 2026 15:47
nc9 added a commit that referenced this pull request Oct 14, 2026
…758

From #771's review: with a few coarse lastmods beside a news sitemap (fewer
than 20 in all), neither the news-only nor the too-coarse skip applies, and
the generic one said "Only 0 sitemap URL(s) carry a lastmod". It now counts
the coarse values, which do carry a lastmod. Test added.

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.

crawl/sitemap-lastmod-drift and -churn read a bare-year or year-month lastmod as one exact day

1 participant