/** * earth-now.co * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * File: apps/web/test/consistency.node.test.ts * Purpose: Client/server consistency — counterValue in the NODE environment must match the closed-form values bit-for-bit (Object.is) */ import { describe, expect, it } from "vitest"; import { counterValue, parseIsoUtc } from "@earth-now/counter"; import { INSTANTS, LINEAR_MODEL, SEASONAL_MODEL, linearClosedForm, seasonalClosedForm, } from "./consistency-shared"; describe("counterValue consistency (node environment)", () => { it("runs in a server-like environment (no DOM)", () => { expect(typeof globalThis.window).toBe("undefined"); }); it("value(anchorTime) === anchorValue exactly", () => { const anchorMs = parseIsoUtc(LINEAR_MODEL.anchorTime); expect(Object.is(counterValue(LINEAR_MODEL, anchorMs), LINEAR_MODEL.anchorValue)).toBe(true); expect(Object.is(counterValue(SEASONAL_MODEL, anchorMs), SEASONAL_MODEL.anchorValue)).toBe( true, ); }); it("matches the linear closed form bit-for-bit at all five instants", () => { for (const t of INSTANTS) { expect(Object.is(counterValue(LINEAR_MODEL, t), linearClosedForm(t))).toBe(true); } }); it("matches the seasonal closed form bit-for-bit at all five instants", () => { for (const t of INSTANTS) { expect(Object.is(counterValue(SEASONAL_MODEL, t), seasonalClosedForm(t))).toBe(true); } }); it("is deterministic: re-evaluation yields Object.is-identical numbers", () => { for (const t of INSTANTS) { expect(Object.is(counterValue(LINEAR_MODEL, t), counterValue(LINEAR_MODEL, t))).toBe(true); expect(Object.is(counterValue(SEASONAL_MODEL, t), counterValue(SEASONAL_MODEL, t))).toBe( true, ); } }); });