4fd4e20bd0
Systemic reliability gap found by the probe sweep: the compiled evaluation paths never emitted the reliability the engine computes. - Compiled _evaluateDirect omitted the relation's reliability, and the chain/multi_hop rules hardcoded reliability: 1.0 — so check() results reported 1.0 for any rule whose decision came through a chain, multi_hop, union, intersection, exclusion, or defeasible combination. - The chain and multi_hop traversals now track per-path reliability (product of edge reliabilities) and report the winning path's value; the compiled and fallback logical operators (union/intersection/exclusion, direct_list fast path, early exits) report the selected child's reliability (max/min child or OWA trace index; exclusion multiplies both legs), and normal-mode defeasible combines base x requires x defeater reliabilities. - The checker's logical fast path dropped collectedValues from union/ intersection/exclusion results; it now passes them through. - MultiHopRule.valueManager was read off relationManager where the real arbiter keeps it on the arbiter — collectValues: true on a multi_hop rule with a value-carrying edge crashed the evaluation (error result, silent denial). Now resolved at the arbiter level with a relationManager fallback for stubs. Campaign pins: reliability per kind (chain/multi_hop product, union/intersection selected child, exclusion/defeasible product), and multi_hop value collection through persistent and partial contexts.
148 lines
5.4 KiB
JavaScript
148 lines
5.4 KiB
JavaScript
/**
|
|
* rigor/overlay-precedence.test.js — js-rigor property tests for partial
|
|
* graph overlay semantics.
|
|
*
|
|
* Properties verified:
|
|
*
|
|
* - PERSISTENT OVER PARTIAL: when both a persistent fact and a partial
|
|
* graph fact describe the same triple, the persistent fact wins by
|
|
* trust precedence — the check reflects the persistent possibility
|
|
* (even when it is 0).
|
|
* - SURFACING: removing the persistent fact lets the partial fact
|
|
* surface; the check then reflects the partial possibility.
|
|
* - RE-ESTABLISHMENT: re-adding the persistent fact re-asserts its
|
|
* precedence immediately (no stale partial-only state).
|
|
* - LAYER PRECEDENCE: two partial facts for the same triple at
|
|
* different layers resolve to the higher-trust layer.
|
|
*/
|
|
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { rigor } from '@rigor/core';
|
|
import { Arbiter } from '../../src/index.js';
|
|
|
|
const EPS = 1e-9;
|
|
const POS = [0, 0.25, 0.5, 0.75, 1];
|
|
|
|
function fail(message) {
|
|
throw new Error(message);
|
|
}
|
|
|
|
function buildArbiter() {
|
|
const arbiter = new Arbiter();
|
|
arbiter.addNode('user:1', 'user');
|
|
arbiter.addNode('doc:1', 'doc');
|
|
arbiter.setRelationConfig('can_read', { type: 'direct' });
|
|
return arbiter;
|
|
}
|
|
|
|
function partialGraphWith(relation, possibility, layer = null) {
|
|
const fact = {
|
|
src: 'user:1',
|
|
relation,
|
|
dst: 'doc:1',
|
|
possibility
|
|
};
|
|
if (layer) fact.layer_name = layer;
|
|
return { relations: [fact] };
|
|
}
|
|
|
|
describe('Partial graph overlay precedence (rigor)', () => {
|
|
it('PERSISTENT OVER PARTIAL: persistent facts win by trust precedence; partial surfaces on removal', async () => {
|
|
async function check({ pPersistent, pPartial }) {
|
|
const arbiter = buildArbiter();
|
|
arbiter.addRelation('user:1', 'can_read', 'doc:1', { possibility: pPersistent });
|
|
|
|
const partialGraph = partialGraphWith('can_read', pPartial);
|
|
|
|
// Persistent present: persistent wins regardless of partial strength
|
|
const withBoth = arbiter.check('user:1', 'can_read', 'doc:1', { partialGraph });
|
|
if (Math.abs(withBoth.possibility - pPersistent) > EPS) {
|
|
fail(`persistent+partial: expected persistent ${pPersistent}, got ${withBoth.possibility}`);
|
|
}
|
|
|
|
// Remove persistent: partial surfaces
|
|
arbiter.removeRelation('user:1', 'can_read', 'doc:1');
|
|
const partialOnly = arbiter.check('user:1', 'can_read', 'doc:1', { partialGraph });
|
|
if (Math.abs(partialOnly.possibility - pPartial) > EPS) {
|
|
fail(`partial-only: expected ${pPartial}, got ${partialOnly.possibility}`);
|
|
}
|
|
|
|
// Re-add persistent: precedence re-asserts immediately
|
|
arbiter.addRelation('user:1', 'can_read', 'doc:1', { possibility: pPersistent });
|
|
const reasserted = arbiter.check('user:1', 'can_read', 'doc:1', { partialGraph });
|
|
if (Math.abs(reasserted.possibility - pPersistent) > EPS) {
|
|
fail(`re-asserted: expected ${pPersistent}, got ${reasserted.possibility}`);
|
|
}
|
|
return { withBoth, partialOnly, reasserted };
|
|
}
|
|
|
|
const report = await rigor.campaign(
|
|
[
|
|
rigor.fn('check', check, rigor.args(
|
|
rigor.gen.object({
|
|
pPersistent: rigor.gen.oneOf(POS),
|
|
pPartial: rigor.gen.oneOf(POS)
|
|
})
|
|
))
|
|
],
|
|
rigor.crucible([
|
|
rigor.invariant('persistent-precedence', ({ error, errorMessage }) => !error && !errorMessage)
|
|
])
|
|
).run({ effort: 500, seed: 'overlay-persistent-precedence' , artifacts: { dir: '', persist: 'never' }});
|
|
|
|
const inv = report.crucibleVerdict?.invariants?.find(i => i.name === 'persistent-precedence');
|
|
assert.ok(inv);
|
|
assert.equal(inv.passed, true, `PERSISTENT OVER PARTIAL violated in ${inv.failureCount} cases`);
|
|
});
|
|
|
|
it('LAYER PRECEDENCE: higher-trust layer wins between partial facts', async () => {
|
|
async function check({ pHigh, pLow }) {
|
|
const arbiter = buildArbiter();
|
|
// Two partial facts, same triple, different layers:
|
|
// token_projection (trust 70) > request_observed (trust 50)
|
|
const partialGraph = {
|
|
relations: [
|
|
{
|
|
src: 'user:1',
|
|
relation: 'can_read',
|
|
dst: 'doc:1',
|
|
possibility: pHigh,
|
|
layer_name: 'token_projection'
|
|
},
|
|
{
|
|
src: 'user:1',
|
|
relation: 'can_read',
|
|
dst: 'doc:1',
|
|
possibility: pLow,
|
|
layer_name: 'request_observed'
|
|
}
|
|
]
|
|
};
|
|
|
|
const result = arbiter.check('user:1', 'can_read', 'doc:1', { partialGraph });
|
|
if (Math.abs(result.possibility - pHigh) > EPS) {
|
|
fail(`layer precedence: expected high-trust ${pHigh}, got ${result.possibility}`);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const report = await rigor.campaign(
|
|
[
|
|
rigor.fn('check', check, rigor.args(
|
|
rigor.gen.object({
|
|
pHigh: rigor.gen.oneOf(POS),
|
|
pLow: rigor.gen.oneOf(POS)
|
|
})
|
|
))
|
|
],
|
|
rigor.crucible([
|
|
rigor.invariant('layer-precedence', ({ error, errorMessage }) => !error && !errorMessage)
|
|
])
|
|
).run({ effort: 400, seed: 'overlay-layer-precedence' , artifacts: { dir: '', persist: 'never' }});
|
|
|
|
const inv = report.crucibleVerdict?.invariants?.find(i => i.name === 'layer-precedence');
|
|
assert.ok(inv);
|
|
assert.equal(inv.passed, true, `LAYER PRECEDENCE violated in ${inv.failureCount} cases`);
|
|
});
|
|
});
|