/** * Peak-window logic tests. * * The DeepSeek vectors are ported from the CC0 conformance table at * https://github.com/xyzs996/deepseek-peak-hours (read 2026-08-28). They pin: * window edges (inclusive start, exclusive end), the weekend override, the * non-retroactive effective-date gate, and the weekday axis being read on * the Beijing calendar (synthetic schedule), not on UTC. */ import assert from "node:assert/strict"; import test from "node:test"; import { DEEPSEEK, GLM, type PeakSchedule } from "../src/schedules.ts"; import { isPeakAt, nextChangeAt } from "../src/windows.ts"; const at = (iso: string): Date => new Date(iso); /** CC0 synthetic schedule: peak window deliberately covers 16:00-22:00 UTC, * the only stretch where the UTC and Beijing calendars disagree. */ const SYNTHETIC: PeakSchedule = { ...DEEPSEEK, windows: [{ start: "00:00", end: "06:00" }], // 16:00-22:00 UTC on a UTC+8 calendar }; test("DeepSeek phase vectors (CC0 port)", async (t) => { const cases: Array<[string, boolean, string]> = [ ["2026-08-24T01:30:00Z", true, "Mon 09:30 Beijing — inside the first daily peak window"], ["2026-08-24T04:00:00Z", false, "Mon 12:00 Beijing — window end is exclusive"], ["2026-08-24T05:59:59Z", false, "Mon 13:59:59 Beijing — gap between the two daily windows"], ["2026-08-24T06:00:00Z", true, "Mon 14:00 Beijing — window start is inclusive"], ["2026-08-24T09:59:59Z", true, "Mon 17:59:59 Beijing — last second of the second window"], ["2026-08-24T10:00:00Z", false, "Mon 18:00 Beijing — window end is exclusive"], ["2026-08-23T01:30:00Z", false, "Sun 09:30 Beijing — weekend overrides a daily peak window"], ["2026-08-23T07:00:00Z", false, "Sun 15:00 Beijing — weekend overrides the second window"], ["2026-08-29T02:00:00Z", false, "Sat 10:00 Beijing — Saturday is off-peak all day"], ["2026-08-22T01:30:00Z", true, "Sat 09:30 Beijing — before the rule took effect: not retroactive"], ["2026-08-22T09:59:59Z", true, "Sat 17:59:59 Beijing — last peak second before the rule took effect"], ["2026-08-22T16:00:00Z", false, "Sun 00:00 Beijing — the first instant the rule applies"], ]; for (const [iso, expectPeak, why] of cases) { await t.test(`${iso} → ${expectPeak ? "peak" : "offpeak"} (${why})`, () => { assert.equal(isPeakAt(DEEPSEEK, at(iso)), expectPeak); }); } }); test("DeepSeek next-boundary vectors (CC0 port)", async (t) => { const cases: Array<[string, string, boolean, string]> = [ [ "2026-08-28T10:30:00Z", "2026-08-31T01:00:00Z", true, "Fri 18:30 Beijing → next real change is Mon 09:00 Beijing, ~63h out; weekend-resident edges are skipped", ], [ "2026-08-24T02:00:00Z", "2026-08-24T04:00:00Z", false, "ordinary in-window case", ], [ "2026-08-21T18:00:00Z", "2026-08-22T01:00:00Z", true, "before the effective instant the weekend must not be skipped; the gate is on the candidate instant, not on now", ], ]; for (const [fromIso, expectIso, expectPeak, why] of cases) { await t.test(`${fromIso} → ${expectIso} (${why})`, () => { const change = nextChangeAt(DEEPSEEK, at(fromIso)); assert.ok(change, "expected a change within the scan horizon"); assert.equal(change.at.getTime(), Date.parse(expectIso)); assert.equal(change.peak, expectPeak); }); } }); test("Weekday axis is read on the billing calendar, not UTC", async (t) => { await t.test("2026-08-28T16:30Z — UTC says Friday, Beijing says Saturday → off-peak", () => { assert.equal(isPeakAt(SYNTHETIC, at("2026-08-28T16:30:00Z")), false); }); await t.test("2026-08-30T16:30Z — UTC says Sunday, Beijing says Monday → peak", () => { assert.equal(isPeakAt(SYNTHETIC, at("2026-08-30T16:30:00Z")), true); }); await t.test("2026-08-29T17:00Z — both calendars say weekend → off-peak", () => { assert.equal(isPeakAt(SYNTHETIC, at("2026-08-29T17:00:00Z")), false); }); await t.test("schedules with Saturday in peakWeekdays peak on a Beijing Saturday", () => { const sixDay: PeakSchedule = { ...SYNTHETIC, peakWeekdays: [1, 2, 3, 4, 5, 6] }; assert.equal(isPeakAt(sixDay, at("2026-08-28T16:30:00Z")), true); }); }); test("GLM Coding Plan windows (Mon-Fri 14:00-18:00 UTC+8)", async (t) => { await t.test("Mon 13:00 Singapore — before the window", () => { assert.equal(isPeakAt(GLM, at("2026-08-24T05:00:00Z")), false); }); await t.test("Mon 14:00 Singapore — window start inclusive", () => { assert.equal(isPeakAt(GLM, at("2026-08-24T06:00:00Z")), true); }); await t.test("Mon 17:59:59 — last second of the window", () => { assert.equal(isPeakAt(GLM, at("2026-08-24T09:59:59Z")), true); }); await t.test("Mon 18:00 — window end exclusive", () => { assert.equal(isPeakAt(GLM, at("2026-08-24T10:00:00Z")), false); }); await t.test("Sat 14:00 Singapore — weekend off-peak", () => { assert.equal(isPeakAt(GLM, at("2026-08-29T06:00:00Z")), false); }); await t.test("Fri 18:30 → next change is Mon 14:00 Singapore", () => { const change = nextChangeAt(GLM, at("2026-08-28T10:30:00Z")); assert.ok(change); assert.equal(change.at.getTime(), Date.parse("2026-08-31T06:00:00Z")); assert.equal(change.peak, true); }); await t.test("Mon 13:00 → next change is 14:00 the same day", () => { const change = nextChangeAt(GLM, at("2026-08-24T05:00:00Z")); assert.ok(change); assert.equal(change.at.getTime(), Date.parse("2026-08-24T06:00:00Z")); assert.equal(change.peak, true); }); });