From 257c52ea91b4179a3fbe60c30be0f6879fd343c8 Mon Sep 17 00:00:00 2001 From: John Dvorak Date: Sun, 2 Aug 2026 11:03:10 -0700 Subject: [PATCH] tests: migrate Date.now patching to the pinned-clock parameter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The now parameter (and partialGraph.now) replaced the need for global Date.now patching in tests. The ttl-expiry parity campaign's module-scope patch and the relational-comparator Time-Based Decay tests' before/after patches now pass the clock explicitly through check options — no global mutation, no restore-order fragility, and the pinned-clock cache bypass keeps every evaluation honest. No stale references to the removed compiled evaluator or useCompiled option remain in the test suite. --- tests/rigor/ttl-expiry-parity.test.js | 4 +--- tests/rules/relational-comparator.test.js | 12 ++---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/rigor/ttl-expiry-parity.test.js b/tests/rigor/ttl-expiry-parity.test.js index aa69e55..933bfea 100644 --- a/tests/rigor/ttl-expiry-parity.test.js +++ b/tests/rigor/ttl-expiry-parity.test.js @@ -23,9 +23,7 @@ const TTL = 5000; const DOCS = 2; const docKey = (i) => `doc:${i}`; -const realNow = Date.now; let engineNow = 1_000_000_000_000; -Date.now = () => engineNow; function makeWrapper(disableCaching) { const arbiter = new Arbiter(disableCaching ? { disableCaching: true } : {}); @@ -69,7 +67,7 @@ function makeWrapper(disableCaching) { return { ok: true, now: engineNow }; }, check(doc) { - const result = arbiter.check('user:alice', 'premium', docKey(doc)); + const result = arbiter.check('user:alice', 'premium', docKey(doc), { now: engineNow }); const b = balance.get(doc); const p = price.get(doc); const bFresh = b !== undefined && engineNow - b.ts <= TTL; diff --git a/tests/rules/relational-comparator.test.js b/tests/rules/relational-comparator.test.js index 9cca6f8..7a8e0ad 100644 --- a/tests/rules/relational-comparator.test.js +++ b/tests/rules/relational-comparator.test.js @@ -294,8 +294,6 @@ describe('RelationalComparatorRule Tests', () => { describe('Time-Based Decay', () => { it('ignores stale timestamps when no decay is applied', () => { const now = 1_000_000_000_000; - const originalDateNow = Date.now; - Date.now = () => now; const arbiter = setupRelationalComparatorTestGraph(); arbiter.addNode('user:decay-test', 'user'); @@ -334,16 +332,12 @@ describe('RelationalComparatorRule Tests', () => { marginOfSafety: 1.0, fallbackBehavior: 'deny' }); - const result = arbiter.check('user:decay-test', 'can_access_decay_test', 'feature:decay-test'); + const result = arbiter.check('user:decay-test', 'can_access_decay_test', 'feature:decay-test', { now }); assert.equal(result.possibility, 1); - - Date.now = originalDateNow; }); it('keeps comparison crisp even for older timestamps', () => { const arbiter = setupRelationalComparatorTestGraph(); const now = 1_000_000_000_000; - const originalDateNow = Date.now; - Date.now = () => now; arbiter.addNode('user:usage-test', 'user'); arbiter.addNode('service:limited', 'service'); @@ -383,10 +377,8 @@ describe('RelationalComparatorRule Tests', () => { comparator: '<=', fallbackBehavior: 'deny' }); - const result = arbiter.check('user:usage-test', 'within_quota', 'service:limited'); + const result = arbiter.check('user:usage-test', 'within_quota', 'service:limited', { now }); assert.equal(result.possibility, 1); - - Date.now = originalDateNow; }); });