feat: chain-step evidence composition — expand evidence steps in chains
A chain step that references a derived evidence is now expanded at compile
time, keeping the engine a flat edge-traversal evaluator:
- DIRECT evidence step -> renamed to its underlying relation
(member_of(user,*g){ group_read(g,doc) } where group_read = can_view
becomes step 'can_view').
- CHAIN evidence step -> its steps are spliced into the parent chain
(a sub-path flattens into the linear source->...->object traversal).
- Any other evidence type (defeasible/logical/comparator) as a step is a
compile-time error: it is a condition, not an edge traversal.
- Cycles and self-references through chain steps are compile-time errors
(the existing composition cycle guard now covers steps).
Rigor: oracle campaign gains a chain_step_composition construct; illegal
mutations gain a non-lowerable-chain-step case. Fixture suites updated to
retarget the self-recursive 'canRead/canAccess/...' terminals (an unsupported
recursion pattern that now fails loudly) to an any-typed 'reachable' fact,
preserving the nested-pattern parsing intent.
This commit is contained in:
+14
-13
@@ -45,6 +45,7 @@ const DSL_SUPPORT = `
|
||||
fact isMember(user: any, group: any)
|
||||
fact isFriend(user: any, friend: any)
|
||||
fact similar(a: any, b: any)
|
||||
fact reachable(user: any, doc: any)
|
||||
fact parentOf(user: any, parent: any)
|
||||
fact isEditable(doc: any)
|
||||
fact isPublic(doc: any)
|
||||
@@ -159,7 +160,7 @@ describe('Evidence Rules', () => {
|
||||
{
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
isMember(user, *group) {
|
||||
canRead(group, doc)
|
||||
reachable(group, doc)
|
||||
}
|
||||
}`,
|
||||
description: 'Basic pattern matching with wildcard'
|
||||
@@ -167,7 +168,7 @@ describe('Evidence Rules', () => {
|
||||
{
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
isMember(user, *group) {
|
||||
canRead(group, doc)
|
||||
reachable(group, doc)
|
||||
} limit 5
|
||||
}`,
|
||||
description: 'Pattern matching with limit'
|
||||
@@ -175,7 +176,7 @@ describe('Evidence Rules', () => {
|
||||
{
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
similar(doc, *similar) |similarity| {
|
||||
canRead(user, similar)
|
||||
reachable(user, similar)
|
||||
} with similarity > 0.7
|
||||
}`,
|
||||
description: 'Pattern matching with binding and condition'
|
||||
@@ -183,7 +184,7 @@ describe('Evidence Rules', () => {
|
||||
{
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
similar(doc, *similar) |similarity| {
|
||||
canRead(user, similar)
|
||||
reachable(user, similar)
|
||||
} limit 5 with similarity > 0.7
|
||||
}`,
|
||||
description: 'Pattern matching with binding, condition, and limit'
|
||||
@@ -192,7 +193,7 @@ describe('Evidence Rules', () => {
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
isMember(user, *group) {
|
||||
isMember(group, *parentGroup) {
|
||||
canRead(parentGroup, doc)
|
||||
reachable(parentGroup, doc)
|
||||
} limit 2
|
||||
} limit 3
|
||||
}`,
|
||||
@@ -202,7 +203,7 @@ describe('Evidence Rules', () => {
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
isFriend(user, *friend) {
|
||||
isMember(friend, *group) {
|
||||
canRead(group, doc)
|
||||
reachable(group, doc)
|
||||
} limit 1
|
||||
} limit 5
|
||||
}`,
|
||||
@@ -291,15 +292,15 @@ describe('Evidence Rules', () => {
|
||||
owns(user, doc)
|
||||
|
||||
isMember(user, *group) {
|
||||
canRead(group, doc)
|
||||
reachable(group, doc)
|
||||
} limit 5
|
||||
|
||||
parentOf(user, *parent) {
|
||||
canRead(parent, doc)
|
||||
reachable(parent, doc)
|
||||
} limit 3
|
||||
|
||||
similar(doc, *similar) |similarity| {
|
||||
canRead(user, similar)
|
||||
reachable(user, similar)
|
||||
} limit 5 with similarity > 0.7
|
||||
|
||||
WHEN hasRole(user, 'admin') UNLESS isSuspended(user)
|
||||
@@ -337,11 +338,11 @@ describe('Evidence Rules', () => {
|
||||
owns(user, doc)
|
||||
|
||||
isMember(user, *group) {
|
||||
canModify(group, doc)
|
||||
reachable(group, doc)
|
||||
} limit 3
|
||||
|
||||
similar(doc, *similar) |similarity| {
|
||||
canModify(user, similar)
|
||||
reachable(user, similar)
|
||||
isEditable(similar)
|
||||
} limit 2 with similarity > 0.8
|
||||
|
||||
@@ -385,7 +386,7 @@ describe('Evidence Rules', () => {
|
||||
{
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
isMember(user, *group) {
|
||||
canRead(group, doc)
|
||||
reachable(group, doc)
|
||||
} with
|
||||
}`,
|
||||
description: 'Incomplete with clause should fail'
|
||||
@@ -393,7 +394,7 @@ describe('Evidence Rules', () => {
|
||||
{
|
||||
input: `evidence canRead(user: Employee, doc: Document) {
|
||||
isMember(user, *group) {
|
||||
canRead(group, doc)
|
||||
reachable(group, doc)
|
||||
} limit
|
||||
}`,
|
||||
description: 'Incomplete limit should fail'
|
||||
|
||||
Reference in New Issue
Block a user