feat: provider-cache bypass knob; reject non-final comparator chain steps
- check() gains cacheProviderResults (per-check option + policy default): the
provider cache is a STORE-RETRIEVAL cache (wall-clock), independent of the
caller's decision { now }; callers who pin time or want fresh retrieval can
opt out per-check or globally.
- The generator now rejects a comparator evidence referenced at a NON-final
chain position (a comparator compares values at (src, candidate) but
provides no candidate set, so it cannot enumerate intermediate nodes).
Final-position comparators still lower to condition steps.
Tests: cache bypass (per-check + policy), comparator final OK / intermediate
error.
This commit is contained in:
@@ -173,4 +173,31 @@ describe('DSLRuntime provider-result caching', () => {
|
||||
await rt.check('u:1', 'can_spend', 'doc:9');
|
||||
assert.equal(calls, 2, 're-invoked past the DSL-declared 1h TTL');
|
||||
});
|
||||
|
||||
it('cacheProviderResults:false bypasses the cache per check', async () => {
|
||||
const rt = makeRuntime();
|
||||
rt.addNode('u:1', 'Employee', {});
|
||||
rt.addNode('doc:9', 'Doc', {});
|
||||
let calls = 0;
|
||||
rt.registerFact('owns', async () => { calls++; return 0.9; });
|
||||
await rt.check('u:1', 'can_read', 'doc:9');
|
||||
assert.equal(calls, 1);
|
||||
// Bypass forces a fresh retrieval without clearing the cache.
|
||||
await rt.check('u:1', 'can_read', 'doc:9', { cacheProviderResults: false });
|
||||
assert.equal(calls, 2);
|
||||
// Cache still intact for the next default check.
|
||||
await rt.check('u:1', 'can_read', 'doc:9');
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
|
||||
it('policy.cacheProviderResults:false disables caching globally', async () => {
|
||||
const rt = makeRuntime({ policy: { cacheProviderResults: false } });
|
||||
rt.addNode('u:1', 'Employee', {});
|
||||
rt.addNode('doc:9', 'Doc', {});
|
||||
let calls = 0;
|
||||
rt.registerFact('owns', async () => { calls++; return 0.9; });
|
||||
await rt.check('u:1', 'can_read', 'doc:9');
|
||||
await rt.check('u:1', 'can_read', 'doc:9');
|
||||
assert.equal(calls, 2, 'no caching when disabled globally');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user