feat: sources wired as recency-gated injectables; transitive closure, NOT scoping, recompile-scope uninstall; targeted parse errors
BEHAVES AS transitive now emits bounded multi_hop configs (direct checks and evidence references), fixing a silent no-op. NOT builds keep _subjectAsObject scoping so unary predicates negate the right node, and value-typed evidence objects gate by exact edge value. Recompiling a scope uninstalls its stale relation configs (compileMultiple coexistence preserved). Sources become injectable relations honored by requiredFacts with a within-X recency gate. Duplicate definition fields and three common declaration mistakes (within on a fact, two BEHAVES clauses, limit on a non-pattern body) now produce targeted errors. Provider edges referencing unknown nodes are warned and dropped.
This commit is contained in:
@@ -93,4 +93,44 @@ describe('DSLRuntime typing', () => {
|
||||
rt.registerFact('owns', async () => ({ possibility: 2.0 }));
|
||||
await assert.rejects(() => rt.check('u:1', 'can_read', 'doc:9'), /invalid possibility/);
|
||||
});
|
||||
|
||||
it('enforces a literal value in evidence as an exact edge-value gate', async () => {
|
||||
const rt = new DSLRuntime(new Arbiter()).compile(`
|
||||
definition Employee { id: string? }
|
||||
fact balance(user: Employee, amount: number)
|
||||
evidence can_afford(user: Employee) { balance(user, 5) }
|
||||
`, 'rt-expected-value');
|
||||
rt.addNode('u:1', 'Employee', {});
|
||||
// An edge carrying amount 3 must NOT satisfy balance(user, 5) — without the
|
||||
// gate every balance edge matched regardless of amount (silent over-grant).
|
||||
rt.addRelation('u:1', 'balance', 'u:1', { possibility: 1.0, value: 3 });
|
||||
const denied = await rt.check('u:1', 'can_afford', 'u:1');
|
||||
assert.equal(denied.possibility, 0, 'value-3 edge must not satisfy balance(user, 5)');
|
||||
rt.addRelation('u:1', 'balance', 'u:1', { possibility: 0.8, value: 5 });
|
||||
const granted = await rt.check('u:1', 'can_afford', 'u:1');
|
||||
assert.equal(granted.possibility, 0.8, 'value-5 edge must satisfy balance(user, 5)');
|
||||
});
|
||||
|
||||
it('treats a value-typed evidence OBJECT param as the expected edge value', async () => {
|
||||
const rt = new DSLRuntime(new Arbiter()).compile(`
|
||||
definition Employee { id: string? }
|
||||
fact balance(user: Employee, amount: number)
|
||||
evidence can_withdraw(user: Employee, amount: number) { balance(user, amount) }
|
||||
`, 'rt-value-object');
|
||||
rt.addNode('u:1', 'Employee', {});
|
||||
rt.addRelation('u:1', 'balance', 'u:1', { possibility: 0.9, value: 5 });
|
||||
// The check object is the VALUE, not a node key: grant only on exact match.
|
||||
const granted = await rt.check('u:1', 'can_withdraw', 5);
|
||||
assert.equal(granted.possibility, 0.9, 'value-5 check must match the value-5 edge');
|
||||
const denied = await rt.check('u:1', 'can_withdraw', 3);
|
||||
assert.equal(denied.possibility, 0, 'value-3 check must not match the value-5 edge');
|
||||
// Re-checking the granted value must not hit a value-3 cache entry.
|
||||
const again = await rt.check('u:1', 'can_withdraw', 5);
|
||||
assert.equal(again.possibility, 0.9, 'value-5 re-check must not be served the value-3 result');
|
||||
// Direct fact check with a value object works the same way.
|
||||
const direct = await rt.check('u:1', 'balance', 5);
|
||||
assert.equal(direct.possibility, 0.9, 'direct balance(user, 5) must match the value-5 edge');
|
||||
// A non-scalar object for a value-typed param is rejected loudly.
|
||||
await assert.rejects(() => rt.check('u:1', 'can_withdraw', 'u:1'), /must be number/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user