Repository navigation
fix(rules): read sitemap and page dates as periods, the same on every machine #772 - #780
Merged
Merged
Conversation
4 tasks done
nc9
force-pushed
the
fix/partial-dates-772
branch
from
October 15, 2026 01:23
1dcca98 to
4038220
Compare
2 tasks done
nc9
marked this pull request as ready for review
October 15, 2026 01:32
|
Review of #780 (shared The refactor is sound. The
Test coverage looks good for the new behaviour. Adding a DST-gap case would cover the medium finding. |
… machine #772 Move the period helper to @squirrelscan/utils/date-period and widen it: a date-only value is its whole day and keeps the day it was written on; a datetime with no zone is read in UTC; a lastmod outside the W3C format is read only when it names its zone. looseDatePeriod reads a page's own date the same way, with zone-less text read as written in UTC. Drift measures the gap between the page's period and the lastmod's, churn counts the day as written, and the cloaking probe measures recency from the end of the period, capped at now. Signed-off-by: Nik Cubrilovic <[email protected]>
Review follow-up. Bun keeps the last zone when TZ is deleted, so the tests mostly ran in one zone and leaked it: restore by assignment and assert the switch. datePeriod replaces looseDatePeriod for lastmods too: a zone is found after stripping comments (AM/PM and short offsets allowed) and the zoneless remainder is read as written, so no fallback trusts Date's own zone handling; ISO-shaped values the W3C forms reject, and values that do not write a whole date, are null; YYYY/MM and "September 2024" are months. w3cDatePeriod is now W3C-only. Cloaking ranks recent pages by period start. Signed-off-by: Nik Cubrilovic <[email protected]>
…eads per machine #772 Delta review. The parenthesised-comment pattern rescanned the rest of a value from every unclosed "(" (2.9 s on page-controlled text): strip comments in one pass and read nothing over 200 characters. A zone that is not at the end, or a second zone, made Date's reading depend on the machine: refuse it. Refuse an offset no zone has, a value with no four-digit year (a time's numbers no longer count), a day Date rolled over (2024/09/31), and a word that only starts like a month (Junk 2024). Churn counts the lastmods it cannot read and says so. Signed-off-by: Nik Cubrilovic <[email protected]>
…he zone patterns #772 Delta review. Date still applied a zone wrapped in punctuation ("EST", EST;, ,+0200) or an offset glued to a time mid-value (12:00+0200 Sep 10 2024), so 324 of 870 generated variants read differently per machine: match a zone token by its neighbours not being letters or digits, and an offset glued to a time. The lookbehinds ran in JSC's slow interpreter, quadratic even under the 200-char cap: anchor the zone patterns without them. Churn's "Only N" now counts unreadable lastmods, news sitemaps' excluded; its docs give the unreadable skip its own bullet. Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
force-pushed
the
fix/partial-dates-772
branch
from
October 15, 2026 01:51
56ad20c to
fd59ffb
Compare
|
Reviewed the diff (utils/date-period, cloaking probe, drift/churn callers). I found no blocking problems.
Tests cover the new helper, the probe and the drift/churn rules. I did not run the suite here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #772.
What was wrong
#771 taught the sitemap lastmod rules that
2024and2024-09name a whole year or month. Five related misreadings were left:Date.parse, so2026was 1 January and a page stamped with the current year was never "recent" (287 days against the default 14), while2026-10was.crawl/sitemap-lastmod-driftstill read the page's own date as an instant: a schemadateModified: "2024"warned 253 days ahead of a lastmod of2024-09-10.2024-9,2024-09-1,2024/09, and a datetime with no zone) fell through tonew Date, which reads them at the host's local time. The result depended on the machine.crawl/sitemap-lastmod-churncounted the UTC day of an offset datetime:2024-09-10T23:30:00-05:00counted as the 11th, a day the sitemap never wrote.2024-12-31warned 8 days behind while2024-12passed at 7.The fix
The period helper moves from the rules package to
@squirrelscan/utils/date-period, so the engine's cloaking probe can share it. It now has two functions:datePeriod, used for every date these checks read: a sitemaplastmod, a schemadateModified, a visible date.daykeeps the calendar day it was written on, whatever its offset;T, is read in UTC.-0500,GMT-05:00,+2,GMT,EST, a trailingZ) is split off;Date's local fields and then as UTC, minus the zone's offset when there is one. No path trustsDate's own zone handling, so the result does not depend on the machine.YYYY/MMandSeptember 2024are months; a value with no time is a day.2024-9,2024-09-31,+002024-09-10), whichDatereads sometimes in UTC and sometimes at local time;Tuesday 2024), whose missing fieldsDatewould invent.w3cDatePeriod: the W3C forms only, for a future check that reports non-W3C lastmods.periodGapMs: 0 when two periods overlap, else the time between their nearer ends.Callers:
datePeriodand measures the gap between the two periods.period.day; a bare year or month is still "coarse".parseLastmod(value, now)returns the end of the lastmod's period, capped atnow; selection uses the injectednow. Recent pages are ranked by the period's start, so a page dated to the day outranks one stamped only with the year.One consequence of item 5 is that a date-only lastmod is measured from the end of its day. An existing drift test (1 March lastmod, page dated 9 March) moved from 8 days to 7, so it now uses 10 March to stay over the threshold.
Tests
packages/utils/tests/date-period.test.ts(new). Every case is checked underTZ= UTC, America/New_York, Asia/Tokyo and Pacific/Kiritimati. The zone is restored by assignment, because Bun keeps the last zone onceTZis deleted, and a first test asserts that each switch takes effect. Cases:periodGapMs.packages/rules/tests/sitemap-lastmod-partial-dates-758.test.ts:2024agrees with a lastmod inside it, and is measured from the end of its year;2024-12-31and2024-12agree;2024/09/10andTue, 10 Sep 2024lastmods agree with a page dated the 10th, in every zone;2024-09-10for2024-09-10T23:30:00-05:00, and for 302024/09/10lastmods in every zone.packages/audit-engine/tests/cloaking-probe.test.ts:parseLastmodfor a day, an RFC date, and periods capped atnow;recent_days; a future year is not;Also run: rules
sitemap-lastmod-drift,sitemap-lastmod-churnand enginestreaming-rules-canonical-golden, all passing.golden-baselinetimed out locally under a load average of about 15. That test checks determinism, not a stored snapshot, and the synthetic fixture has no lastmods. tsgo passes in utils, rules and audit-engine, detect-secrets passes on the changed files, andtangly check --strictpasses on the docs.Docs
rules/crawl/sitemap-lastmod-drift:rules/crawl/sitemap-lastmod-churn: a lastmod counts on the day it was written, whatever its offset or format.rules/integrity/cloaking: how a coarse lastmod counts as recent.CHANGELOG entry under Fixed.
Agent skill
The squirrelscan agent skill needs no change.
Review follow-up (4038220, rebased on v0.0.113 main)
(, which took 2.9 s on page-controlled text. Comments are now stripped in one pass, anddatePeriodreads nothing over 200 characters. A test times 8 hostile shapes at 50k, 100k and 200k characters.Sep 10 2024 EST 12:00,12:00 Sep 10 2024 +0200), or a second zone, madeDate's reading depend on the machine. These are now refused.+99,-0560);Sep 10 12:00: a time's numbers no longer count);Daterolled over (2024/09/31,Feb 30, 2024);Junk 2024).crawl/sitemap-lastmod-churncounts the lastmods it can't read and skips withN sitemap lastmod value(s) are not dates squirrel can read the same way on every machine; M name a day, too few to judge lastmod churninstead ofOnly 0 sitemap URL(s) carry a lastmod.