initial commit: @arbiter/core authorization engine with js-rigor hardening
Zanzibar-style authorization graph engine (direct/chain/TTU/defeasible/ binary modes, condensed snapshots, value relations) with 39 rigor test campaigns. Includes fixes for snapshot binary writer/reader format mismatch (snapshot-of-snapshot corruption), possibility write-boundary validation, empty-graph snapshot serialization, relation lookup cache direction collision, config-redefinition cache invalidation, binary threshold semantics, defeasible compiled routing, and comparator reason whitelisting.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, test } from 'node:test';
|
||||
import { SuccinctGraph } from '../../src/core/succinct/SuccinctGraph.js';
|
||||
|
||||
describe('SuccinctGraph (Copied from graph-core)', () => {
|
||||
test('basic graph construction', () => {
|
||||
const graph = new SuccinctGraph();
|
||||
|
||||
graph.addNode('user:alice');
|
||||
graph.addNode('user:bob');
|
||||
graph.addNode('doc:report');
|
||||
|
||||
graph.addOutEdge('user:alice', 'user:bob');
|
||||
graph.addOutEdge('user:alice', 'doc:finance');
|
||||
graph.addOutEdge('user:bob', 'doc:report');
|
||||
|
||||
assert.strictEqual(graph.n, 3);
|
||||
assert.strictEqual(graph.numEdges(), 3);
|
||||
});
|
||||
|
||||
test('get outgoing edges', () => {
|
||||
const graph = new SuccinctGraph();
|
||||
|
||||
graph.addNode('user:alice');
|
||||
graph.addNode('user:bob');
|
||||
graph.addNode('doc:report');
|
||||
|
||||
graph.addOutEdge('user:alice', 'owner', 'doc:report');
|
||||
graph.addOutEdge('user:alice', 'viewer', 'doc:report');
|
||||
|
||||
const edges = graph.getOutEdges('user:alice');
|
||||
assert.strictEqual(edges.length, 2);
|
||||
});
|
||||
|
||||
test('find edge by relation', () => {
|
||||
const graph = new SuccinctGraph();
|
||||
|
||||
graph.addNode('user:alice');
|
||||
graph.addNode('doc:report');
|
||||
graph.addNode('doc:finance');
|
||||
graph.addOutEdge('user:alice', 'owner', 'doc:report');
|
||||
|
||||
const idx = graph.findEdge('user:alice', graph.getRelationId('owner'), 'doc:report');
|
||||
assert.ok(idx !== null, 'Should find owner edge');
|
||||
|
||||
const edge = graph.getEdge(idx);
|
||||
assert.strictEqual(edge.src, 'user:alice');
|
||||
assert.strictEqual(edge.dst, 'doc:report');
|
||||
});
|
||||
|
||||
test('iteration performance', () => {
|
||||
const graph = new SuccinctGraph();
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
graph.addNode(`user:${i}`);
|
||||
graph.addOutEdge(`user:${i}`, 'relation', `user:${i + 1}`);
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
graph.forEachOutEdge('user:5', (edge) => {
|
||||
count++;
|
||||
});
|
||||
|
||||
assert.strictEqual(count, 1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user