feat: chain condition steps — defeasible/logical evidence as final chain hop
A chain's FINAL (object-side) step may now reference a defeasible/logical
evidence. The compiler lowers it to a condition step
({ rule: <config>, conditionStep: true }) that the engine verifies at
(intermediate, object) instead of traversing an edge. Requires
@arbiter/core@^1.0.3 (ChainRule condition-step support).
- _expandChainSteps: a logical/defeasible/comparator evidence is expressible
as a final condition step; non-final such steps remain a compile error
(a condition cannot discover intermediate nodes).
- Dependency collection (generator + DSLRuntime) descends into condition-step
rule configs, so partial-graph requirements reach through them.
Tests: ChainConditionStep (defeasible + ALWAYS steps, independent checkability,
parallel aggregation), oracle campaign chain_condition_step construct
(oracle = min(pm, pv*(1-pb))), DSLRuntime transitive required facts through a
condition step.
This commit is contained in:
@@ -34,6 +34,7 @@ const FACTS = `
|
||||
fact granted(user: Employee, doc: Doc)
|
||||
fact group_perm(group: Group, doc: Doc)
|
||||
fact banned(user: Employee)
|
||||
fact group_banned(group: Group)
|
||||
fact mfa(user: Employee)
|
||||
`;
|
||||
|
||||
@@ -128,6 +129,19 @@ function buildProgram(kind, ps) {
|
||||
oracle = Math.min(pm, pv);
|
||||
break;
|
||||
}
|
||||
case 'chain_condition_step': {
|
||||
// gated (a defeasible evidence) as the FINAL chain step → a condition
|
||||
// step: the engine verifies gated at (intermediate, object). The oracle
|
||||
// is the chain's min combined with the condition's base*(1-defeat).
|
||||
const [pm, pv, pb] = ps;
|
||||
evidence = `evidence gated(group: Group, doc: Doc) { WHEN group_perm(group, doc) UNLESS group_banned(group) }
|
||||
evidence can_via(user: Employee, doc: Doc) { member_of(user, *g) { gated(g, doc) } }`;
|
||||
edges.push({ src: 'u:1', relation: 'member_of', dst: 'g:1', possibility: pm });
|
||||
edges.push({ src: 'g:1', relation: 'group_perm', dst: 'doc:9', possibility: pv });
|
||||
edges.push({ src: 'g:1', relation: 'group_banned', dst: 'g:1', possibility: pb });
|
||||
oracle = Math.min(pm, pv * (1 - pb));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`unknown construct: ${kind}`);
|
||||
}
|
||||
@@ -163,7 +177,8 @@ function runCheck({ kind, ps }) {
|
||||
}
|
||||
|
||||
const CONSTRUCTS = ['direct', 'chain', 'tuple_to_userset', 'fusion_min', 'fusion_max',
|
||||
'when_unless', 'never_always', 'requires_when', 'composition', 'chain_step_composition'];
|
||||
'when_unless', 'never_always', 'requires_when', 'composition', 'chain_step_composition',
|
||||
'chain_condition_step'];
|
||||
|
||||
describe('DSL generative oracle parity (rigor)', () => {
|
||||
it('generated legal DSL compiles and every check matches the oracle', async () => {
|
||||
@@ -174,7 +189,7 @@ describe('DSL generative oracle parity (rigor)', () => {
|
||||
kind: rigor.gen.oneOf(CONSTRUCTS),
|
||||
// exactly two edge possibilities (direct uses only the first);
|
||||
// a shorter array would leave pB undefined and produce a NaN oracle
|
||||
ps: rigor.gen.tuple(rigor.gen.oneOf(P), rigor.gen.oneOf(P))
|
||||
ps: rigor.gen.tuple(rigor.gen.oneOf(P), rigor.gen.oneOf(P), rigor.gen.oneOf(P))
|
||||
})
|
||||
))
|
||||
],
|
||||
@@ -192,13 +207,14 @@ describe('DSL generative oracle parity (rigor)', () => {
|
||||
});
|
||||
|
||||
it('exhaustive deterministic sweep: every construct x every possibility value', () => {
|
||||
// Anti-vacuity complement to the campaign: sweep the full P × P grid per
|
||||
// construct without any RNG, so a construct the campaign skipped would
|
||||
// Anti-vacuity complement to the campaign: sweep the full P × P × P grid
|
||||
// per construct without any RNG, so a construct the campaign skipped would
|
||||
// still be caught here.
|
||||
for (const kind of CONSTRUCTS) {
|
||||
for (const a of P) {
|
||||
for (const b of P) {
|
||||
const ps = kind === 'direct' ? [a] : [a, b];
|
||||
for (const c of P) {
|
||||
const ps = kind === 'direct' ? [a] : [a, b, c];
|
||||
const { dsl, edges, oracle, relation } = buildProgram(kind, ps);
|
||||
const arbiter = new Arbiter();
|
||||
arbiter.addNode('u:1', 'Employee');
|
||||
@@ -212,6 +228,7 @@ describe('DSL generative oracle parity (rigor)', () => {
|
||||
Math.abs(result.possibility - oracle) <= EPS,
|
||||
`${kind} ps=[${ps}] check=${result.possibility}(${result.reason}) vs oracle=${oracle}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user