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:
+16
-12
@@ -105,6 +105,7 @@ describe('Integration Tests', () => {
|
||||
fact hasAccess(user: Employee, resource: Resource, level: string) CACHE lazy
|
||||
fact isColleague(user: any, colleague: any) symmetrical CACHE lazy limit 50
|
||||
fact isParentOf(parent: Employee, child: Employee) transitive CACHE eager limit 3
|
||||
fact reachable(user: any, doc: any) CACHE lazy
|
||||
fact hasClearance(user: Employee, level: string) CACHE eager
|
||||
fact parentOf(user: any, parent: any) CACHE eager
|
||||
fact similar(a: any, b: any) CACHE lazy
|
||||
@@ -119,15 +120,15 @@ describe('Integration Tests', () => {
|
||||
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)
|
||||
@@ -137,7 +138,7 @@ describe('Integration Tests', () => {
|
||||
owns(user, doc)
|
||||
|
||||
isMember(user, *group) {
|
||||
canWrite(group, doc)
|
||||
reachable(group, doc)
|
||||
} limit 3
|
||||
|
||||
WHEN hasRole(user, 'admin') UNLESS isSuspended(user)
|
||||
@@ -330,6 +331,7 @@ describe('Integration Tests', () => {
|
||||
|
||||
fact isMember(user: any, org: any) transitive CACHE lazy limit 5
|
||||
fact isParentOf(parent: Organization, child: Organization) transitive CACHE eager limit 3
|
||||
fact reachable(user: any, doc: any) CACHE lazy
|
||||
fact hasRole(user: Employee, role: string) CACHE eager
|
||||
fact hasClearance(user: Employee, level: string) CACHE eager
|
||||
fact isSuspended(user: any) CACHE lazy
|
||||
@@ -339,7 +341,7 @@ describe('Integration Tests', () => {
|
||||
isMember(user, org)
|
||||
|
||||
isParentOf(org, *parentOrg) {
|
||||
canAccessOrg(user, parentOrg)
|
||||
reachable(user, parentOrg)
|
||||
} limit 3
|
||||
|
||||
WHEN hasRole(user, 'admin') UNLESS isSuspended(user)
|
||||
@@ -347,11 +349,11 @@ describe('Integration Tests', () => {
|
||||
|
||||
evidence canAccessResource(user: Employee, resource: Resource) {
|
||||
isMember(user, *org) {
|
||||
canAccessResource(org, resource)
|
||||
reachable(org, resource)
|
||||
} limit 5
|
||||
|
||||
parentOf(user, *parent) {
|
||||
canAccessResource(parent, resource)
|
||||
reachable(parent, resource)
|
||||
} limit 2
|
||||
}
|
||||
`;
|
||||
@@ -379,6 +381,7 @@ describe('Integration Tests', () => {
|
||||
fact hasInterest(user: any, interest: string) CACHE lazy
|
||||
fact hasTag(doc: any, tag: string) CACHE lazy
|
||||
fact owns(user: any, doc: any) CACHE eager
|
||||
fact reachable(user: any, doc: any) CACHE lazy
|
||||
fact similar(a: any, b: any) CACHE lazy
|
||||
fact isPublic(doc: any) CACHE eager
|
||||
fact hasInterests(user: any) CACHE lazy
|
||||
@@ -390,12 +393,12 @@ describe('Integration Tests', () => {
|
||||
owns(user, doc)
|
||||
|
||||
similar(doc, *similar) |similarity| {
|
||||
canRead(user, similar)
|
||||
reachable(user, similar)
|
||||
isPublic(similar)
|
||||
} limit 10 with similarity > 0.7
|
||||
|
||||
isFriend(user, *friend) {
|
||||
canRead(friend, doc)
|
||||
reachable(friend, doc)
|
||||
} limit 5
|
||||
|
||||
fusion majority {
|
||||
@@ -406,7 +409,7 @@ describe('Integration Tests', () => {
|
||||
|
||||
evidence canRecommend(user: Employee, doc: Document) {
|
||||
similar(user, *similarUser) |similarity| {
|
||||
canRead(similarUser, doc)
|
||||
reachable(similarUser, doc)
|
||||
} limit 20 with similarity > 0.8
|
||||
|
||||
fusion average {
|
||||
@@ -556,13 +559,14 @@ describe('Integration Tests', () => {
|
||||
fact isFriend(user: any, friend: any) symmetrical CACHE eager limit 50
|
||||
fact hasPermission(user: Employee, resource: Resource, action: string) CACHE eager
|
||||
fact owns(user: Employee, resource: Resource) CACHE eager
|
||||
fact reachable(user: any, doc: any) CACHE lazy
|
||||
|
||||
// Optimized evidence rules
|
||||
evidence canAccess(user: Employee, resource: Resource) {
|
||||
owns(user, resource)
|
||||
|
||||
isMember(user, *group) {
|
||||
canAccess(group, resource)
|
||||
reachable(group, resource)
|
||||
} limit 3
|
||||
|
||||
WHEN hasPermission(user, resource, 'read')
|
||||
@@ -572,7 +576,7 @@ describe('Integration Tests', () => {
|
||||
owns(user, resource)
|
||||
|
||||
isMember(user, *group) {
|
||||
canModify(group, resource)
|
||||
reachable(group, resource)
|
||||
} limit 2
|
||||
|
||||
WHEN hasPermission(user, resource, 'write')
|
||||
|
||||
Reference in New Issue
Block a user