Repository navigation
fix(rules): sitemap lastmod drift and churn read a bare year or year-month as that whole period #758 - #771
Conversation
|
Review of #771: I found no blocking issues. I read the diff only and did not run the tests.
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. |
…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]>
2073bac to
f239154
Compare
|
Reviewed the diff. I found no correctness, security or performance problems. I read the code but did not run the tests.
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. |
…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]>
Closes #758.
What changed
The W3C Datetime format sitemaps use allows
YYYYandYYYY-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 }.2024covers 2024-01-01T00:00Z to 2024-12-31T23:59:59.999Z.2024-09covers that month.Dateparses is one instant (start = end).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 ascoarseLastmodsin the skip details andcoarseLastmodsExcludedin 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-drifttreats aYYYYorYYYY-MMlastmod as the whole year or month: a pagedateModifiedinside that period is not drift, and drift outside it is measured from the nearer end of the period. (2024vs 2024-09-10 passes;2023vs 2024-09-10 is 253 days behind, counted from the end of 2023;2024-09vs 2024-10-15 is 14 days behind;2025vs 2024-09-10 is 113 days ahead.)crawl/sitemap-lastmod-churnnever reports a day the sitemap did not write for aYYYYorYYYY-MMlastmod. Such entries are left out and counted.2024,2024-09and 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, year0099(built withsetUTCFullYear, sinceDate.UTCmaps 0 to 99 onto 19xx), and both skip choices. 4 of the original 7 fail against main's rules.sitemap-lastmod-drift,sitemap-lastmod-churnandsitemap-validtests pass (54 with the new file).packages/audit-engine:streaming-rules-canonical-goldenandcloaking-probepass, with no re-pin.tsgo --noEmitinpackages/rulesis clean, and oxlint is clean on the changed files. The new files are oxfmt-clean, and detect-secrets is clean.docs/:tangly check --strictpasses. The drift and churn rule pages say how a year or month lastmod is read.Agent skill
No change needed.