tests: migrate Date.now patching to the pinned-clock parameter

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.
This commit is contained in:
John Dvorak
2026-08-02 11:03:10 -07:00
parent 0cb0d7c8cb
commit 257c52ea91
2 changed files with 3 additions and 13 deletions
+2 -10
View File
@@ -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;
});
});