From 9a2adcf61d41ae70d1dbdfb326a5503073a78135 Mon Sep 17 00:00:00 2001 From: ci-check Date: Sun, 15 Nov 2026 00:37:50 +0800 Subject: [PATCH] test: stamp log-retention test generations the way the logger writes them writeGeneration planted head lines as UTC wall-clock strings with the Z stripped; the coverage reader (STAMP_RE + Date.parse) treats a zone-less stamp as local time, so in any non-UTC zone the measured span shifted by the offset. The 40h-vs-48h boundary test ("out-of-order stamps are NOT evidence of missing history") flipped in UTC+8: the 40h oldest stamp read back 8h earlier, the span reached the 48h target, and the targetSpanMet=false assertion failed. Found while reviewing #6742; pre-existing on master, unrelated to that PR's diff. Use logTimestamp - the real writer's formatter - so the planted lines round-trip exactly in every zone. Verified 23/23 under UTC+8, UTC and America/New_York. --- tests/log-retention.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/log-retention.test.ts b/tests/log-retention.test.ts index 30e2626c9a..ad582800da 100644 --- a/tests/log-retention.test.ts +++ b/tests/log-retention.test.ts @@ -22,6 +22,7 @@ import { stampNewLog, } from "../src/log-retention.ts"; import { continuityOf, formatWindow, oldestLogLineMs } from "../src/log-retention-coverage.ts"; +import { logTimestamp } from "../src/logger.ts"; import { rmrf } from "./tmp-rm.ts"; const HOUR = 60 * 60 * 1000; @@ -41,7 +42,11 @@ function writeGeneration(logPath: string, at: number, bytes: number, counter: st const dir = path.join(archiveOf(logPath), `${generationStamp(at)}-${pid}-${counter}`); fs.mkdirSync(dir, { recursive: true, mode: LOG_DIR_MODE }); const file = path.join(dir, "bili.log"); - const head = `${new Date(at).toISOString().slice(0, 23)} [info] [v=0] seal ${counter}\n`; + // Stamp the head line the way the real logger does (local wall-clock, no + // zone suffix, logTimestamp): the coverage reader parses a zone-less stamp + // as local time, so a UTC string read back in a non-UTC zone shifts the + // measured span by the offset (the 40h/48h boundary test flipped in UTC+8). + const head = `${logTimestamp(new Date(at))} [info] [v=0] seal ${counter}\n`; fs.writeFileSync(file, head + "x".repeat(Math.max(0, bytes - head.length))); return file; }