Repository navigation
fix(public): refresh the study figures to the 2026-08-12 scan and guard the daily-refresh promise #156
fix(public): refresh the study figures to the 2026-08-12 scan and guard the daily-refresh promise #156
Changes from 4 commits
54337e5
a97da36
db69b93
b21a2da
79aa9f6
2e35acc
5d269b2
5fa87c0
cce417b
ce18637
efe9abd
4b19d73
0141e78
b0a2bae
28115cf
e01c789
dcad042
28d027c
a5ebba0
1e0b530
40cf96d
b6b3315
ded1d8b
6bd974d
d56a987
d3fe68f
b38fc57
70cb623
68caf4d
9032ef9
0474344
c21ad10
9fd8d69
a42b118
0b683aa
8830755
760f7a3
8030823
d1cc1cf
da3a6dc
e3c37c1
699bf02
0f429b3
4b668a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // The public pages promise "refreshed daily" and "this number is today's" | ||
| // (index.html, audit.html, pricing.html, specimen.html). These guards make | ||
| // that promise durable: | ||
| // | ||
| // 1. render.py --check — the pages' data-study spans must match the newest | ||
| // snapshot in study/snapshots/. A partial import (snapshot without | ||
| // render, or render without snapshot) fails here. | ||
| // 2. Freshness — the newest snapshot must be recent enough to back the | ||
| // daily-refresh claim. The scan runs daily at 07:00 IST in the scan | ||
| // checkout and the snapshots are imported into this repo by hand, so a | ||
| // small window is allowed; a multi-day drift (the 2026-08-06 -> 08-12 | ||
| // gap this guard was written against) turns red. | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { execFileSync } from "node:child_process"; | ||
| import { readdirSync } from "node:fs"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const HERE = path.dirname(fileURLToPath(import.meta.url)); | ||
| const ROOT = path.resolve(HERE, ".."); | ||
| const MAX_SNAPSHOT_AGE_DAYS = 4; | ||
|
|
||
| function newestSnapshotFile() { | ||
| const snaps = readdirSync(path.join(ROOT, "study", "snapshots")) | ||
| .filter((name) => name.endsWith(".json")) | ||
| .sort(); | ||
| assert.ok(snaps.length > 0, "study/snapshots/ must contain at least one dated snapshot"); | ||
| return snaps[snaps.length - 1]; | ||
| } | ||
|
|
||
| test("public pages are rendered from the newest study snapshot", () => { | ||
| execFileSync("python3", ["study/render.py", "--check"], { cwd: ROOT, stdio: "pipe" }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The imported snapshot can pass this check even though it was produced from a different study set: at this commit Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a future snapshot changes its Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a manually imported snapshot has incorrect or partially regenerated top-level totals, this check still passes because Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On Windows and minimal Node environments where Useful? React with 👍 / 👎. |
||
| }); | ||
|
|
||
| test("the newest study snapshot is fresh enough to back the daily-refresh promise", () => { | ||
| const file = newestSnapshotFile(); | ||
| const date = file.replace(/\.json$/, ""); | ||
| const snapshotEnd = Date.parse(`${date}T23:59:59Z`); | ||
|
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a snapshot is manually imported under the wrong filename, this check treats the filename as its acquisition date and never inspects the payload's existing Useful? React with 👍 / 👎. |
||
| assert.ok(Number.isFinite(snapshotEnd), `snapshot filename ${file} must be an ISO date (YYYY-MM-DD.json)`); | ||
|
|
||
| const ageDays = (Date.now() - snapshotEnd) / 86_400_000; | ||
| assert.ok( | ||
| ageDays <= MAX_SNAPSHOT_AGE_DAYS, | ||
|
Comment on lines
+42
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the repository has no pushes or pull requests for several days, this assertion is never reevaluated: the checked Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the scan host's clock is wrong or a snapshot is accidentally imported with a future filename, Useful? React with 👍 / 👎. |
||
| `newest snapshot is ${date} (${Math.floor(ageDays)} days old) but the site promises "refreshed daily" — import the newer snapshots from the scan checkout and re-run study/render.py (max allowed age: ${MAX_SNAPSHOT_AGE_DAYS} days)` | ||
|
Comment on lines
+36
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Validate freshness from snapshot metadata. Line 39 uses the end of the filename date instead of the scan time. A snapshot scanned at Read the selected JSON file. Validate that its 🤖 Prompt for AI Agents |
||
| ); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with correctly dated snapshots and a scheduled test run, this four-day allowance lets a scan/import run only every fourth day while the suite remains green, so the public pages can continue saying the figures are “today's” and “refreshed daily” for several days after the last scan. Require approximately daily data freshness, or weaken the public claim to match the tolerated cadence.
Useful? React with 👍 / 👎.