Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7898a7990a |
@@ -26,6 +26,8 @@ jobs:
|
|||||||
echo "//hub.kl1.tenere.ai/api/packages/Arbiter/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
echo "//hub.kl1.tenere.ai/api/packages/Arbiter/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
echo "@tenere:registry=https://hub.kl1.tenere.ai/api/packages/Tenere/npm/" >> .npmrc
|
echo "@tenere:registry=https://hub.kl1.tenere.ai/api/packages/Tenere/npm/" >> .npmrc
|
||||||
echo "//hub.kl1.tenere.ai/api/packages/Tenere/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
echo "//hub.kl1.tenere.ai/api/packages/Tenere/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
|
echo "@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/" >> .npmrc
|
||||||
|
echo "//hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
echo "@rigor:registry=https://hub.kl1.tenere.ai/api/packages/Rigor/npm/" >> .npmrc
|
echo "@rigor:registry=https://hub.kl1.tenere.ai/api/packages/Rigor/npm/" >> .npmrc
|
||||||
echo "//hub.kl1.tenere.ai/api/packages/Rigor/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
echo "//hub.kl1.tenere.ai/api/packages/Rigor/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
|
|
||||||
@@ -52,6 +54,8 @@ jobs:
|
|||||||
echo "//hub.kl1.tenere.ai/api/packages/Arbiter/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
echo "//hub.kl1.tenere.ai/api/packages/Arbiter/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
echo "@tenere:registry=https://hub.kl1.tenere.ai/api/packages/Tenere/npm/" >> .npmrc
|
echo "@tenere:registry=https://hub.kl1.tenere.ai/api/packages/Tenere/npm/" >> .npmrc
|
||||||
echo "//hub.kl1.tenere.ai/api/packages/Tenere/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
echo "//hub.kl1.tenere.ai/api/packages/Tenere/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
|
echo "@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/" >> .npmrc
|
||||||
|
echo "//hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
echo "@rigor:registry=https://hub.kl1.tenere.ai/api/packages/Rigor/npm/" >> .npmrc
|
echo "@rigor:registry=https://hub.kl1.tenere.ai/api/packages/Rigor/npm/" >> .npmrc
|
||||||
echo "//hub.kl1.tenere.ai/api/packages/Rigor/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
echo "//hub.kl1.tenere.ai/api/packages/Rigor/npm/:_authToken=${{ secrets.PACKAGE_TOKEN }}" >> .npmrc
|
||||||
|
|
||||||
|
|||||||
@@ -4,3 +4,5 @@
|
|||||||
//hub.kl1.tenere.ai/api/packages/Tenere/npm/:_authToken=${PACKAGE_TOKEN}
|
//hub.kl1.tenere.ai/api/packages/Tenere/npm/:_authToken=${PACKAGE_TOKEN}
|
||||||
@rigor:registry=https://hub.kl1.tenere.ai/api/packages/Rigor/npm/
|
@rigor:registry=https://hub.kl1.tenere.ai/api/packages/Rigor/npm/
|
||||||
//hub.kl1.tenere.ai/api/packages/Rigor/npm/:_authToken=${PACKAGE_TOKEN}
|
//hub.kl1.tenere.ai/api/packages/Rigor/npm/:_authToken=${PACKAGE_TOKEN}
|
||||||
|
@push-stream-std:registry=https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/
|
||||||
|
//hub.kl1.tenere.ai/api/packages/push-stream-std/npm/:_authToken=${PACKAGE_TOKEN}
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// DSLValueGraph measure hotpath (async retrieval for authorization checks).
|
||||||
|
import { performance } from 'node:perf_hooks';
|
||||||
|
import { DSLRuntime, DSLValueGraph } from '../src/index.js';
|
||||||
|
import { Arbiter } from '@arbiter/core';
|
||||||
|
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile('measure budget(user: string) { } PROVIDES number', 'bench');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
dvg.setValue('budget', { __subject: 'u:1', user: 'u:1' }, 1250);
|
||||||
|
|
||||||
|
async function measureCached() { return dvg.measure('budget', { __subject: 'u:1', user: 'u:1' }); }
|
||||||
|
await measureCached(); // warm
|
||||||
|
let t0 = performance.now();
|
||||||
|
let N = 20_000;
|
||||||
|
for (let i = 0; i < N; i++) await measureCached();
|
||||||
|
console.log(`dvg.measure cached (async) ${(((performance.now() - t0) / N) * 1e6).toFixed(0).padStart(8)} ns/op ${Math.round(N / ((performance.now() - t0) / 1000)).toLocaleString()} ops/sec`);
|
||||||
|
|
||||||
|
// cold: a fresh measure with an external resolver computing on the fly
|
||||||
|
const cold = new DSLValueGraph(new DSLRuntime(new Arbiter()).compile('measure b(user: string) { } PROVIDES number', 'b'));
|
||||||
|
cold.resolve('b', (s) => 99);
|
||||||
|
async function measureCold() { return cold.measure('b', { __subject: 'u:1', user: 'u:1' }); }
|
||||||
|
await measureCold();
|
||||||
|
t0 = performance.now();
|
||||||
|
N = 20_000;
|
||||||
|
for (let i = 0; i < N; i++) await measureCold();
|
||||||
|
console.log(`dvg.measure cold (resolver) ${(((performance.now() - t0) / N) * 1e6).toFixed(0).padStart(8)} ns/op`);
|
||||||
Generated
+111
-81
@@ -1,25 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "@arbiter/evidence-dsl",
|
"name": "@arbiter/evidence-dsl",
|
||||||
"version": "1.12.1",
|
"version": "1.13.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@arbiter/evidence-dsl",
|
"name": "@arbiter/evidence-dsl",
|
||||||
"version": "1.12.1",
|
"version": "1.13.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@arbiter/core": "^1.0.8"
|
"@arbiter/core": "^1.0.8",
|
||||||
|
"@arbiter/value-graph": "^0.1.0",
|
||||||
|
"@rigor/probe": "^0.0.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rigor/core": "^3.1.0",
|
"@rigor/core": "^3.1.2",
|
||||||
"peggy": "^5.0.6"
|
"peggy": "^5.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@arbiter/core": {
|
"node_modules/@arbiter/core": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Arbiter/npm/%40arbiter%2Fcore/-/1.0.8/core-1.0.8.tgz",
|
|
||||||
"integrity": "sha512-x/nWymJca0AHoUaLrq09ENeiPBplaCcuQbX1zHKVUk1fYoYVfW9ZmmrApoKPsK58WkcPwBWo1cB6VSrGk9//WA==",
|
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tenere/pltc-core": "^0.6.3",
|
"@tenere/pltc-core": "^0.6.3",
|
||||||
@@ -27,10 +27,19 @@
|
|||||||
"uuidv7": "^1.0.2"
|
"uuidv7": "^1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@arbiter/value-graph": {
|
||||||
|
"version": "0.1.0",
|
||||||
|
"resolved": "https://hub.kl1.tenere.ai/api/packages/Arbiter/npm/%40arbiter%2Fvalue-graph/-/0.1.0/value-graph-0.1.0.tgz",
|
||||||
|
"integrity": "sha512-sofmF6O/o3bUf2Vzg24MxSB6NLQR8s2xjaBqL+k2LbGhlmt4/lHD9J6l/CjgObn+4UsXjb/QEccZ8rX0BFOUKg==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@push-stream-std/push-pushable": "*",
|
||||||
|
"@push-stream-std/push-stream-base": "*",
|
||||||
|
"@rigor/probe": "^0.0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@peggyjs/from-mem": {
|
"node_modules/@peggyjs/from-mem": {
|
||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/@peggyjs/from-mem/-/from-mem-3.1.3.tgz",
|
|
||||||
"integrity": "sha512-LLlgtfXIaeYXoOYovOI0spLM8ZXaqkAlmcRRrLzHJzLMqkU6Sw0R4KMoCoHx1PjaP815pSCBlS+BN6aD8t1Jgg==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -40,53 +49,70 @@
|
|||||||
"node": ">=20.8"
|
"node": ">=20.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@push-stream-std/push-pushable": {
|
||||||
|
"version": "0.0.10",
|
||||||
|
"resolved": "https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/%40push-stream-std%2Fpush-pushable/-/0.0.10/push-pushable-0.0.10.tgz",
|
||||||
|
"integrity": "sha512-xf8nt50zckM8G+WRKV5RTNl4EEe6rhzuplNfqpdZ/b8kx0HnuTawDHlL0R449PKqG9X4DOQ5RzBrX2jYAnfY2A==",
|
||||||
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
|
"dependencies": {
|
||||||
|
"@push-stream-std/push-stream-base": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@push-stream-std/push-stream-base": {
|
||||||
|
"version": "0.0.9",
|
||||||
|
"resolved": "https://hub.kl1.tenere.ai/api/packages/push-stream-std/npm/%40push-stream-std%2Fpush-stream-base/-/0.0.9/push-stream-base-0.0.9.tgz",
|
||||||
|
"integrity": "sha512-RCbTwQz88XR0j0f/0NWIWgQ3NBQUUICu+CRHzOAvYfG2YQ8j+aTczYWTEedJJhGA+svcFrAQ8Oai/UnjtQ0l3Q==",
|
||||||
|
"license": "SEE LICENSE IN LICENSE"
|
||||||
|
},
|
||||||
"node_modules/@rigor/analysis": {
|
"node_modules/@rigor/analysis": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fanalysis/-/0.0.7/analysis-0.0.7.tgz",
|
|
||||||
"integrity": "sha512-CH9g9gU5P+aWZfneL7l91Q8wgZ0kwteYTpOdShqi6VFg2aoOSk4HMl8RTzkO4suxWa2VQ/mMnFJ/TAiHwJOobA==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/instrument": "*",
|
"@rigor/instrument": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/artifact": {
|
"node_modules/@rigor/artifact": {
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fartifact/-/0.1.3/artifact-0.1.3.tgz",
|
|
||||||
"integrity": "sha512-/SP5veJOpZ7y0dEBYOm+iBKQnBqZbTQzCXGd/LvQvmDtMGL7KJv2UbU7blnWp9CIwD8qU8t9U9c9oKO+qupUcA==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/benchmark": {
|
"node_modules/@rigor/benchmark": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fbenchmark/-/0.0.6/benchmark-0.0.6.tgz",
|
|
||||||
"integrity": "sha512-uCCtEhCeY0t81aSgvV1Q7D3cgNU1WufEGJ/vcljhjXnx05hdMWnlK0NPdI/qkWRbRiz+4sSpcGOGO9NBFk7ExQ==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/artifact": "*",
|
"@rigor/artifact": "*",
|
||||||
"@rigor/complexity": "*",
|
"@rigor/complexity": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/complexity": {
|
"node_modules/@rigor/complexity": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fcomplexity/-/0.0.7/complexity-0.0.7.tgz",
|
|
||||||
"integrity": "sha512-RfrkXLykb37WFwmB6OfZoXYMEZJLG78r2HqfDB27jWQmGt5l/4Hb9Zh77dEKl2CsUx2fgd5NafdDl9qFtTE6bg==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/core": {
|
"node_modules/@rigor/core": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.2",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fcore/-/3.1.0/core-3.1.0.tgz",
|
|
||||||
"integrity": "sha512-gUuq2YuaM0LNjdmHABcRbEW6FvPhO+U1ErokQ6ftPKpPBb38vDc+pPqu7KgGtr3R9NDU3Vj9OBV1Wq9AlzfraA==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -110,24 +136,25 @@
|
|||||||
"@rigor/spec": "*",
|
"@rigor/spec": "*",
|
||||||
"@rigor/storage": "*",
|
"@rigor/storage": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/fault": {
|
"node_modules/@rigor/fault": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Ffault/-/0.0.5/fault-0.0.5.tgz",
|
|
||||||
"integrity": "sha512-MxzAEk8tx/Nc9CL3dQZZwKXj7eqBgnfTC9dI9TiU9b1u3zW7EIoL28vGqtrr1ucqSTeNwD8BGGAenan2tvb1ZQ==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/shrink": "*",
|
"@rigor/shrink": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/fuzzer": {
|
"node_modules/@rigor/fuzzer": {
|
||||||
"version": "0.0.4",
|
"version": "0.0.4",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Ffuzzer/-/0.0.4/fuzzer-0.0.4.tgz",
|
|
||||||
"integrity": "sha512-cJu9bL0GqpkTsIne9PLMcsLtRfBlDz18DqPiarSi+MetH9R0joh7C+fp/e4guo0y+Q2RBJZwulA8gOh9AwgEaQ==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -135,40 +162,43 @@
|
|||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/shrink": "*",
|
"@rigor/shrink": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/gen": {
|
"node_modules/@rigor/gen": {
|
||||||
"version": "0.0.11",
|
"version": "0.0.11",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fgen/-/0.0.11/gen-0.0.11.tgz",
|
|
||||||
"integrity": "sha512-PJG40PtiRJRbNDajdpGaachLYYR+tkSK/0ToIbG5BlG+l/enw7g80hkH674Vw4jeWoftzuwe2NM4dC9rj9rHbg==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/rng": "*"
|
"@rigor/rng": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/instrument": {
|
"node_modules/@rigor/instrument": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Finstrument/-/0.0.5/instrument-0.0.5.tgz",
|
|
||||||
"integrity": "sha512-GXJa6kcEAbd86yM57hR+2g0vcxJlpBfBOoMldWk3mzLmAcCkyYXNSjJekTAwNovfUrtIcnYgQ187Zj3A2d8Tcw==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/probe": "*",
|
"@rigor/probe": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/linearizability": {
|
"node_modules/@rigor/linearizability": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Flinearizability/-/0.0.5/linearizability-0.0.5.tgz",
|
|
||||||
"integrity": "sha512-Ruw+/Zc1hiMfs6i/4qYxYuvUsBtCm5SUmpuXrrixSRglvJ9PYfL/H8xb/Pk3Ve1dFBj8TQN6M3AnwCeaJF2/tg==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE"
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/model": {
|
"node_modules/@rigor/model": {
|
||||||
"version": "0.2.13",
|
"version": "0.2.13",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fmodel/-/0.2.13/model-0.2.13.tgz",
|
|
||||||
"integrity": "sha512-eZ/888p1zGJGCBFVMA9suvS2mUNX+iHhZn+Uwl9lWa9CSHVRUWH9dTYYB+Qr1hNrCSGIDjV7rOC34wzT+QA4fw==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -180,12 +210,13 @@
|
|||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/shrink": "*",
|
"@rigor/shrink": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/network": {
|
"node_modules/@rigor/network": {
|
||||||
"version": "0.0.4",
|
"version": "0.0.4",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fnetwork/-/0.0.4/network-0.0.4.tgz",
|
|
||||||
"integrity": "sha512-iNmiQA5QiCNkXnjAMPibGYzDk3Lf5hsgwXQGwRcSSVlZNBfVVw5fURzTsNen3TeAnqh9nozJnhD52yp3zdfP6Q==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -193,24 +224,25 @@
|
|||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/scheduler": "*",
|
"@rigor/scheduler": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/probe": {
|
"node_modules/@rigor/probe": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.8",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fprobe/-/0.0.6/probe-0.0.6.tgz",
|
|
||||||
"integrity": "sha512-vUGY6vwciwYqxMaUYa3L2IIwipnnXdPANG8GONx+PrlII2eSbMCjb7BLZGso4yG/iaheRR0JwAnjV8mvtvUOOA==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/fault": "*",
|
"@rigor/fault": "*",
|
||||||
"@rigor/gen": "*",
|
"@rigor/gen": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/prop": {
|
"node_modules/@rigor/prop": {
|
||||||
"version": "0.0.4",
|
"version": "0.0.4",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fprop/-/0.0.4/prop-0.0.4.tgz",
|
|
||||||
"integrity": "sha512-z3+STJPeNpz080ZfFbw5h6LpNFjCNnSymoQPUsjyaSovq3euyJrGx9sqtosVgVVE7Rzld6K4QwchJSJOqIi73w==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -221,30 +253,32 @@
|
|||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/shrink": "*",
|
"@rigor/shrink": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/reporters": {
|
"node_modules/@rigor/reporters": {
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Freporters/-/0.0.5/reporters-0.0.5.tgz",
|
|
||||||
"integrity": "sha512-+YYfOMlYDsmGIi9rKiJm7ZAptQ0rTeTU1Sp2uVG9UJteuVKW2eKZIC6TeJuM1qvjQmh7/IzBkl3PZVX9pKnYaw==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/artifact": "*",
|
"@rigor/artifact": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/rng": {
|
"node_modules/@rigor/rng": {
|
||||||
"version": "0.0.3",
|
"version": "0.0.3",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Frng/-/0.0.3/rng-0.0.3.tgz",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"integrity": "sha512-OFERK5HlI6eV1yUadHoz9n88twqsd/lstAxMzBWFJiN1CCM0xG7IHUYMBCnYK6Di3TTcAarFNFL16Bchm3LrKg==",
|
"engines": {
|
||||||
"dev": true,
|
"node": ">=18.0.0"
|
||||||
"license": "SEE LICENSE IN LICENSE"
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/scheduler": {
|
"node_modules/@rigor/scheduler": {
|
||||||
"version": "0.0.4",
|
"version": "0.0.4",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fscheduler/-/0.0.4/scheduler-0.0.4.tgz",
|
|
||||||
"integrity": "sha512-tY7KASEfufOw4L1vIGeD1bTArCv+zAEPqT/XqiXFz+fckGxY8Nux6zDhGcjkur3qWOUNoWap6KOjSZSORHhXiw==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -252,40 +286,43 @@
|
|||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/shrink": "*",
|
"@rigor/shrink": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/search": {
|
"node_modules/@rigor/search": {
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fsearch/-/0.1.3/search-0.1.3.tgz",
|
|
||||||
"integrity": "sha512-NAq5zbUSc6QQO4YIUFq16+hPtrtkNrjAn75lH/4VDPpbCdQPbKvS6zsQ3v954u1u7I6x2jI5uilpX6/xfr69yA==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/gen": "*",
|
"@rigor/gen": "*",
|
||||||
"@rigor/shrink": "*"
|
"@rigor/shrink": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/shrink": {
|
"node_modules/@rigor/shrink": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fshrink/-/0.0.7/shrink-0.0.7.tgz",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"integrity": "sha512-z0yaZqmyysn40BBqAnqTQlymLuaIIU5u2BijjayX0+XZxhhcPIyvs4PISzJ4nmfkx2yE6qKABe2HHub9wVVUQw==",
|
"engines": {
|
||||||
"dev": true,
|
"node": ">=18.0.0"
|
||||||
"license": "SEE LICENSE IN LICENSE"
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/spec": {
|
"node_modules/@rigor/spec": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fspec/-/2.0.1/spec-2.0.1.tgz",
|
|
||||||
"integrity": "sha512-0/lg19KenJy1e8D87+WqaMRh8Xad4h209/CgK6ofCQapwz/IcriMPHgOZZbHMA4C8G3B6/luVbSVT0EHZoJ8qg==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rigor/gen": "*"
|
"@rigor/gen": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/storage": {
|
"node_modules/@rigor/storage": {
|
||||||
"version": "0.0.4",
|
"version": "0.0.4",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Fstorage/-/0.0.4/storage-0.0.4.tgz",
|
|
||||||
"integrity": "sha512-7XapdgmvEg/C/kERldqFlw3mT1JkpjPMNK6fEcB2Ggx7+UR3ZeE9GyaodJ29my61b28SrQUWxLBHT5bm0bIVaA==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -293,34 +330,37 @@
|
|||||||
"@rigor/rng": "*",
|
"@rigor/rng": "*",
|
||||||
"@rigor/scheduler": "*",
|
"@rigor/scheduler": "*",
|
||||||
"@rigor/trace": "*"
|
"@rigor/trace": "*"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@rigor/trace": {
|
"node_modules/@rigor/trace": {
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Rigor/npm/%40rigor%2Ftrace/-/0.0.7/trace-0.0.7.tgz",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"integrity": "sha512-vCLF+WTSdy0pwe9sTonPt8HnNeSkK9U5SAxNpdIeiT+IBP74t9K7JoHMmfo7ka+S0puWecDjjNtWCSqtvKkjNg==",
|
"engines": {
|
||||||
"dev": true,
|
"node": ">=18.0.0"
|
||||||
"license": "SEE LICENSE IN LICENSE"
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tenere/graph-core": {
|
"node_modules/@tenere/graph-core": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Tenere/npm/%40tenere%2Fgraph-core/-/1.0.1/graph-core-1.0.1.tgz",
|
"license": "MIT",
|
||||||
"integrity": "sha512-29EzF1yBVLuaaapmrL+xNGRaWsM2Ln0G+WHVJURNzwQnDUC2ZSgaeVRMGj3aHFOj2K4mfSh9JqBP5Az2ZHU4pw==",
|
"engines": {
|
||||||
"license": "MIT"
|
"node": ">=18.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tenere/pltc-core": {
|
"node_modules/@tenere/pltc-core": {
|
||||||
"version": "0.6.3",
|
"version": "0.6.3",
|
||||||
"resolved": "https://hub.kl1.tenere.ai/api/packages/Tenere/npm/%40tenere%2Fpltc-core/-/0.6.3/pltc-core-0.6.3.tgz",
|
|
||||||
"integrity": "sha512-+XsxNw35fyX8ku19FfyFsb6DgYoaKb6wkAbo1VF+moeyZ0D3AqDTofsBnd2sv5o2y8RpB3XftBxt0Hv1sBcQtg==",
|
|
||||||
"license": "SEE LICENSE IN LICENSE",
|
"license": "SEE LICENSE IN LICENSE",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tenere/graph-core": "^1.0.1"
|
"@tenere/graph-core": "^1.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/commander": {
|
"node_modules/commander": {
|
||||||
"version": "14.0.3",
|
"version": "14.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz",
|
|
||||||
"integrity": "sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -329,14 +369,10 @@
|
|||||||
},
|
},
|
||||||
"node_modules/heapify": {
|
"node_modules/heapify": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/heapify/-/heapify-1.0.2.tgz",
|
|
||||||
"integrity": "sha512-h/b3y12Orh2VsISvDsF/vulkoKH38P7yr223hfWJILo3imy7dX8f9ZrBgkkfLsJG11g8GI1/y6+8POSxgR7YcQ==",
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/peggy": {
|
"node_modules/peggy": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/peggy/-/peggy-5.1.0.tgz",
|
|
||||||
"integrity": "sha512-IEo5aYRZ2kXH4Qby06cjtL114PZnwLoTiA41vUmg2vPZgANn+c87m5BUurhuDr5/cu758ZlpgsAfBVx+hhO5+w==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -353,8 +389,6 @@
|
|||||||
},
|
},
|
||||||
"node_modules/semver": {
|
"node_modules/semver": {
|
||||||
"version": "7.7.4",
|
"version": "7.7.4",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
|
|
||||||
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -366,8 +400,6 @@
|
|||||||
},
|
},
|
||||||
"node_modules/source-map-generator": {
|
"node_modules/source-map-generator": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/source-map-generator/-/source-map-generator-2.0.6.tgz",
|
|
||||||
"integrity": "sha512-IlassDs1Ve8nV6uyQZXF9kdkJpVKnMte2JZQXu13M0A5zwc+vu6+LNHfmxsHBMDtoZE21RHiKI0/xvpecZRCNg==",
|
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -376,8 +408,6 @@
|
|||||||
},
|
},
|
||||||
"node_modules/uuidv7": {
|
"node_modules/uuidv7": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/uuidv7/-/uuidv7-1.2.1.tgz",
|
|
||||||
"integrity": "sha512-4kPkK3/XTQW9Hbm4CaqfICn+kY9LJtDVEOfgsRRra/+n2Ofg4NqzRFceAkxvQ/Ud/6BpHOPzj8cirqM7TzTN5Q==",
|
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uuidv7": "cli.js"
|
"uuidv7": "cli.js"
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@arbiter/evidence-dsl",
|
"name": "@arbiter/evidence-dsl",
|
||||||
"version": "1.12.1",
|
"version": "1.13.0",
|
||||||
"description": "Evidence DSL v2 compiler: translates the natural Evidence DSL (ADR-000) into @arbiter/core relation configurations.",
|
"description": "Evidence DSL v2 compiler: translates the natural Evidence DSL (ADR-000) into @arbiter/core relation configurations.",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -21,13 +21,16 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --test --test-force-exit \"tests/**/*.test.js\"",
|
"test": "node --test --test-force-exit \"tests/**/*.test.js\"",
|
||||||
"generate:parser": "node scripts/generate-parser.js"
|
"generate:parser": "node scripts/generate-parser.js",
|
||||||
|
"bench": "node bench/measure-hotpath.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@arbiter/core": "^1.0.8"
|
"@arbiter/core": "^1.0.8",
|
||||||
|
"@arbiter/value-graph": "^0.1.0",
|
||||||
|
"@rigor/probe": "^0.0.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rigor/core": "^3.1.0",
|
"@rigor/core": "^3.1.2",
|
||||||
"peggy": "^5.0.6"
|
"peggy": "^5.0.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export { validateDslText } from './validation/DSLValidation.js';
|
|||||||
// Runtime
|
// Runtime
|
||||||
export { DSLRuntime } from './runtime/DSLRuntime.js';
|
export { DSLRuntime } from './runtime/DSLRuntime.js';
|
||||||
|
|
||||||
|
// Value-graph integration — DSL-declared measures as value-graph nodes
|
||||||
|
export { DSLValueGraph } from './value-graph/DSLValueGraph.js';
|
||||||
|
|
||||||
// All AST nodes
|
// All AST nodes
|
||||||
export * from './nodes/index.js';
|
export * from './nodes/index.js';
|
||||||
|
|
||||||
|
|||||||
+146
-1
@@ -44,6 +44,7 @@ export class DSLRuntime {
|
|||||||
this.arbiter = arbiter;
|
this.arbiter = arbiter;
|
||||||
this.compiler = new DSLCompiler(this.arbiter);
|
this.compiler = new DSLCompiler(this.arbiter);
|
||||||
this.factProviders = options.factProviders || {};
|
this.factProviders = options.factProviders || {};
|
||||||
|
this.measureProviders = new Map(); // measure name -> async (args, ctx) => { value, unit? }
|
||||||
this.strictTypes = options.policy?.strictTypes !== false;
|
this.strictTypes = options.policy?.strictTypes !== false;
|
||||||
this.program = null;
|
this.program = null;
|
||||||
this.types = new Map(); // typeName -> { fields: Map(field -> {type,isArray}) }
|
this.types = new Map(); // typeName -> { fields: Map(field -> {type,isArray}) }
|
||||||
@@ -120,7 +121,10 @@ export class DSLRuntime {
|
|||||||
params: r.params,
|
params: r.params,
|
||||||
dependsOn: [...(this.dependsOn.get(name) || [])]
|
dependsOn: [...(this.dependsOn.get(name) || [])]
|
||||||
}));
|
}));
|
||||||
return { types, facts, sources, evidence, providers: this.registeredFacts() };
|
const measures = [...this.relations.entries()]
|
||||||
|
.filter(([, r]) => r.kind === 'measure')
|
||||||
|
.map(([name, r]) => ({ name, params: r.params, returnType: r.returnType }));
|
||||||
|
return { types, facts, sources, evidence, measures, providers: this.registeredFacts() };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** All relation names declared by the program (facts + evidence). */
|
/** All relation names declared by the program (facts + evidence). */
|
||||||
@@ -171,6 +175,19 @@ export class DSLRuntime {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Measures are derived-value lookups (kind: 'measure'). Their VALUES come
|
||||||
|
// from a registered provider (the ARRA adapter / value-graph), not the
|
||||||
|
// graph. `provides` declares the return type.
|
||||||
|
for (const m of this.program.measures || []) {
|
||||||
|
const provides = m.provides?.type || m.provides || 'number';
|
||||||
|
this.relations.set(m.name, {
|
||||||
|
kind: 'measure',
|
||||||
|
params: (m.params || []).map(p => ({ name: p.name, type: p.paramType, isArray: !!p.isArray })),
|
||||||
|
returnType: provides,
|
||||||
|
injectable: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Index each evidence's fact dependencies from the compiled arbiter configs.
|
// Index each evidence's fact dependencies from the compiled arbiter configs.
|
||||||
for (const ev of this.program.evidence || []) {
|
for (const ev of this.program.evidence || []) {
|
||||||
const config = this.arbiter.relationConfigs.get(ev.name);
|
const config = this.arbiter.relationConfigs.get(ev.name);
|
||||||
@@ -250,6 +267,66 @@ export class DSLRuntime {
|
|||||||
return Object.keys(this.factProviders);
|
return Object.keys(this.factProviders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a measure provider. A measure is a derived-value lookup declared
|
||||||
|
* in the DSL (`measure name(...) { ... } provides <type>`); its VALUE comes
|
||||||
|
* from a registered provider (e.g. the ARRA adapter bridging the value-graph),
|
||||||
|
* not from the graph.
|
||||||
|
*
|
||||||
|
* @param {string} name - declared measure name
|
||||||
|
* @param {Function} provider - async (args, ctx) => { value, unit? } | number
|
||||||
|
*/
|
||||||
|
registerMeasure(name, provider) {
|
||||||
|
const meta = this.relations.get(name);
|
||||||
|
if (!meta || meta.kind !== 'measure') {
|
||||||
|
throw new Error(`DSLRuntime: '${name}' is not a declared measure`);
|
||||||
|
}
|
||||||
|
if (typeof provider !== 'function') {
|
||||||
|
throw new Error(`DSLRuntime: provider for measure '${name}' must be a function`);
|
||||||
|
}
|
||||||
|
this.measureProviders.set(name, provider);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unregister a measure provider. */
|
||||||
|
unregisterMeasure(name) {
|
||||||
|
this.measureProviders.delete(name);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a measure value by its parameter bindings.
|
||||||
|
* @param {string} name - declared measure name
|
||||||
|
* @param {Object} args - positional or named args (positional for unary/arity-1)
|
||||||
|
* @returns {Promise<{value: *, unit?: string|null, source?: string}>}
|
||||||
|
*/
|
||||||
|
async measure(name, args = {}) {
|
||||||
|
const meta = this.relations.get(name);
|
||||||
|
if (!meta || meta.kind !== 'measure') {
|
||||||
|
if (this.strictTypes) throw new Error(`DSLRuntime: unknown measure '${name}'`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const provider = this.measureProviders.get(name);
|
||||||
|
if (!provider) {
|
||||||
|
throw new Error(`DSLRuntime: no provider registered for measure '${name}'`);
|
||||||
|
}
|
||||||
|
const params = meta.params || [];
|
||||||
|
// Normalize positional args (e.g. measure(userKey)) to named bindings.
|
||||||
|
let bindings = args;
|
||||||
|
if (Array.isArray(args)) {
|
||||||
|
bindings = {};
|
||||||
|
for (let i = 0; i < params.length; i++) bindings[params[i].name] = args[i];
|
||||||
|
}
|
||||||
|
const result = await provider(bindings, { runtime: this });
|
||||||
|
if (typeof result === 'number' || typeof result === 'string' || typeof result === 'boolean') {
|
||||||
|
return { value: result, unit: null };
|
||||||
|
}
|
||||||
|
if (result && typeof result === 'object' && 'value' in result) {
|
||||||
|
return { value: result.value, unit: result.unit ?? null, source: result.source };
|
||||||
|
}
|
||||||
|
throw new Error(`DSLRuntime: provider for measure '${name}' must return a value or { value, unit }`);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Provider-result caching
|
// Provider-result caching
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -595,6 +672,23 @@ export class DSLRuntime {
|
|||||||
return required;
|
return required;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The MEASURE requirements of an evidence relation: the derived measures its
|
||||||
|
* comparator operands reference (valueRelation deps that are `kind: measure`).
|
||||||
|
* These compose the measure system into the evidence system — the evidence's
|
||||||
|
* truth depends on a measure VALUE, which `check()` resolves and injects.
|
||||||
|
*/
|
||||||
|
requiredMeasures(relation) {
|
||||||
|
const deps = this.dependsOn.get(relation);
|
||||||
|
if (!deps) return [];
|
||||||
|
const required = [];
|
||||||
|
for (const dep of deps) {
|
||||||
|
const meta = this.relations.get(dep);
|
||||||
|
if (meta && meta.kind === 'measure') required.push(dep);
|
||||||
|
}
|
||||||
|
return required;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// DSL-informed check
|
// DSL-informed check
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -761,6 +855,57 @@ export class DSLRuntime {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Measure + evidence composition ---
|
||||||
|
// An evidence whose comparator references a measure (a valueRelation with
|
||||||
|
// `_needsValues`) needs the measure VALUE in the partial graph before the
|
||||||
|
// core evaluator runs. Measures inject as value-carrying self-edges on the
|
||||||
|
// subject, resolved through `this.measure()` — which is the attached
|
||||||
|
// value-graph when DSLValueGraph is wired, so both systems compose.
|
||||||
|
const measureRequirements = this.requiredMeasures(relation);
|
||||||
|
if (measureRequirements.length > 0) {
|
||||||
|
const bound = {};
|
||||||
|
for (let i = 0; i < (meta?.params || []).length; i++) {
|
||||||
|
if (i === 0) bound[meta.params[i].name] = user;
|
||||||
|
else if (i === 1 && !this._isValueType(meta.params[i].type)) bound[meta.params[i].name] = object;
|
||||||
|
}
|
||||||
|
for (const measure of measureRequirements) {
|
||||||
|
if (satisfied.has(measure)) continue;
|
||||||
|
const measureMeta = this.relations.get(measure);
|
||||||
|
// `__subject` aligns with the value-graph's subjectOf default so the
|
||||||
|
// attached DSLValueGraph resolves the same key setValue() wrote.
|
||||||
|
const args = { __subject: user };
|
||||||
|
for (const p of (measureMeta?.params || [])) args[p.name] = (p.name in bound ? bound[p.name] : user);
|
||||||
|
let resolved = null;
|
||||||
|
let err = null;
|
||||||
|
try {
|
||||||
|
resolved = await this.measure(measure, args);
|
||||||
|
} catch (e) {
|
||||||
|
err = e;
|
||||||
|
}
|
||||||
|
if (err || resolved === null || resolved === undefined) {
|
||||||
|
missingFacts.push({ relation: measure, reason: err ? err.message : 'not_provided' });
|
||||||
|
satisfied.add(measure);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
partialRelations.push({
|
||||||
|
relation: measure,
|
||||||
|
src: user,
|
||||||
|
dst: user,
|
||||||
|
value: resolved.value,
|
||||||
|
possibility: 1,
|
||||||
|
...(resolved.unit != null ? { unit: resolved.unit } : {})
|
||||||
|
});
|
||||||
|
satisfied.add(measure);
|
||||||
|
injectedRelations.push({ relation: measure, edges: 1, round: 'measure', cacheHit: false });
|
||||||
|
}
|
||||||
|
if (partialRelations.length > 0) {
|
||||||
|
checkOptions.partialGraph = {
|
||||||
|
...(checkOptions.partialGraph || {}),
|
||||||
|
relations: partialRelations
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A value-typed object parameter means the check object IS the expected
|
// A value-typed object parameter means the check object IS the expected
|
||||||
// edge value, not a node key. Value-carrying facts store edges as
|
// edge value, not a node key. Value-carrying facts store edges as
|
||||||
// self-edges on the subject, so the underlying check runs on the subject
|
// self-edges on the subject, so the underlying check runs on the subject
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { parse } from '../parser/GeneratedParser.js';
|
import { parse } from '../parser/GeneratedParser.js';
|
||||||
import { DSL_PRELUDE } from './DSLPrelude.js';
|
import { DSL_PRELUDE } from './DSLPrelude.js';
|
||||||
|
|
||||||
const BUILTIN_TYPES = new Set(['string', 'number', 'boolean', 'timestamp', 'duration', 'object', 'any']);
|
// NO JS bigint in the value model — large integers are `buffer` (Uint8Array),
|
||||||
|
// matching the value-graph's JSON-free/bigint-free wire format.
|
||||||
|
const BUILTIN_TYPES = new Set(['string', 'number', 'boolean', 'timestamp', 'duration', 'object', 'any', 'buffer', 'array', 'interval']);
|
||||||
const BUILTIN_CHALLENGES = new Set([
|
const BUILTIN_CHALLENGES = new Set([
|
||||||
'mfa',
|
'mfa',
|
||||||
'webauthn',
|
'webauthn',
|
||||||
|
|||||||
@@ -0,0 +1,256 @@
|
|||||||
|
/**
|
||||||
|
* DSLValueGraph — wires a DSLRuntime's declared MEASURES to a @arbiter/value-graph.
|
||||||
|
*
|
||||||
|
* The DSL is the schema authority: each `measure name(params) { ... } PROVIDES type`
|
||||||
|
* becomes a value-graph relation whose spec carries the declared return type and
|
||||||
|
* parameter types. The value-graph is then:
|
||||||
|
*
|
||||||
|
* - the STORAGE substrate for values/attributes that are supplied directly
|
||||||
|
* (not cached or computed) — `setValue(name, args, value)` writes them;
|
||||||
|
* - the RETRIEVAL substrate for measure lookups — `measure(name, args)` (and,
|
||||||
|
* after `attach()`, `runtime.measure(...)`) read through `valueGraph.get(...)`,
|
||||||
|
* so authorization evaluation pulls values "for partial graph purposes";
|
||||||
|
* - the COMPUTE substrate for external value resolvers — `resolve(name, fn)`
|
||||||
|
* registers a callback/sync resolver that becomes the node's operator fn
|
||||||
|
* (ARRA/Overlay adapters plug here).
|
||||||
|
*
|
||||||
|
* Typing / validation: values written or resolved must match the DSL-declared
|
||||||
|
* PROVIDES type (enforced both here and by the value-graph itself), and bindings
|
||||||
|
* are validated against the declared parameter types. Unknown measure names and
|
||||||
|
* type mismatches fail loudly.
|
||||||
|
*/
|
||||||
|
import { ValueGraph, validateValueType } from '@arbiter/value-graph';
|
||||||
|
|
||||||
|
const CONTROL_KEYS = new Set(['__subject', '__actor', '__source', '__meta']);
|
||||||
|
|
||||||
|
function isControlKey(key) {
|
||||||
|
return CONTROL_KEYS.has(key) || (typeof key === 'string' && key.startsWith('_'));
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DSLValueGraph {
|
||||||
|
/**
|
||||||
|
* @param {DSLRuntime} runtime - an already-compiled DSLRuntime
|
||||||
|
* @param {Object} [options]
|
||||||
|
* @param {ValueGraph} [options.valueGraph] - shared graph (default: a fresh one)
|
||||||
|
* @param {number} [options.defaultTTL] - per-node TTL for declared measures (default 0 = persist until set/invalidate)
|
||||||
|
* @param {Function} [options.subjectOf] - (name, args) => subject key (default: args.__subject ?? 'global')
|
||||||
|
* @param {boolean} [options.strict] - throw on unknown measures (default true)
|
||||||
|
*/
|
||||||
|
constructor(runtime, options = {}) {
|
||||||
|
this.runtime = runtime;
|
||||||
|
this.vg = options.valueGraph || new ValueGraph({ defaultTTL: options.defaultTTL ?? 0 });
|
||||||
|
this.subjectOf = options.subjectOf || ((name, args) => (args && args.__subject) || 'global');
|
||||||
|
this.strict = options.strict !== false;
|
||||||
|
this.resolvers = new Map(); // measure name -> callback/sync resolver
|
||||||
|
this.measures = new Map(); // measure name -> { params, returnType }
|
||||||
|
this._attached = new Set(); // measure names attach() registered on the runtime
|
||||||
|
this._registerFromSchema();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Schema registration — DSL declares the value-graph's typing / structure.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_registerFromSchema() {
|
||||||
|
return this.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-read the runtime schema and re-register measure nodes. Call after the
|
||||||
|
* runtime recompiles a new program: new measures get value-graph nodes, removed
|
||||||
|
* ones are dropped, and changed return types/params are updated in place.
|
||||||
|
*/
|
||||||
|
sync() {
|
||||||
|
const schema = this.runtime.getSchema();
|
||||||
|
const seen = new Set();
|
||||||
|
for (const m of schema.measures || []) {
|
||||||
|
const name = m.name;
|
||||||
|
seen.add(name);
|
||||||
|
const params = (m.params || []).map((p) => ({ name: p.name, type: p.type, isArray: !!p.isArray }));
|
||||||
|
const returnType = m.returnType || 'number';
|
||||||
|
const existing = this.measures.get(name);
|
||||||
|
if (existing) {
|
||||||
|
existing.params = params;
|
||||||
|
existing.returnType = returnType;
|
||||||
|
} else {
|
||||||
|
this.measures.set(name, { params, returnType });
|
||||||
|
this.vg.define(name, {
|
||||||
|
operator: 'source',
|
||||||
|
returnType,
|
||||||
|
params,
|
||||||
|
fn: (subject, bindings, ctx, cb) => this._resolve(name, subject, bindings, ctx, cb)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const name of [...this.measures.keys()]) {
|
||||||
|
if (!seen.has(name)) this.measures.delete(name);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The value-graph node schema derived from the DSL (name → spec). */
|
||||||
|
schema() {
|
||||||
|
const out = {};
|
||||||
|
for (const [name] of this.measures) out[name] = this.vg.relationSpec(name);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Measure metadata + binding normalization + validation
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_measure(name) {
|
||||||
|
const meta = this.measures.get(name);
|
||||||
|
if (!meta) {
|
||||||
|
if (this.strict) throw new Error(`DSLValueGraph: '${name}' is not a declared measure`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize positional (array) args to named bindings, strip control keys
|
||||||
|
* (`_subject` etc.), and validate the bound values against declared params.
|
||||||
|
* Positional args must match the declared arity exactly — otherwise the cache
|
||||||
|
* key would silently diverge from the caller's intent.
|
||||||
|
*/
|
||||||
|
_bindings(name, args) {
|
||||||
|
const meta = this._measure(name);
|
||||||
|
if (!meta) return {};
|
||||||
|
let raw = args;
|
||||||
|
if (Array.isArray(args)) {
|
||||||
|
if (args.length !== meta.params.length) {
|
||||||
|
throw new Error(
|
||||||
|
`DSLValueGraph: measure '${name}' expects ${meta.params.length} positional argument(s), got ${args.length}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
raw = {};
|
||||||
|
for (let i = 0; i < meta.params.length; i++) raw[meta.params[i].name] = args[i];
|
||||||
|
}
|
||||||
|
const bindings = {};
|
||||||
|
for (const [key, value] of Object.entries(raw || {})) {
|
||||||
|
if (isControlKey(key)) continue;
|
||||||
|
bindings[key] = value;
|
||||||
|
}
|
||||||
|
for (const p of meta.params) {
|
||||||
|
if (!(p.name in bindings)) continue;
|
||||||
|
const v = bindings[p.name];
|
||||||
|
if (p.isArray) {
|
||||||
|
if (!Array.isArray(v)) throw new Error(`DSLValueGraph: parameter '${p.name}' of '${name}' must be an array`);
|
||||||
|
} else if (!validateValueType(v, p.type)) {
|
||||||
|
throw new Error(`DSLValueGraph: parameter '${p.name}' of '${name}' must match declared type '${p.type}'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Resolvers (the compute substrate)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_resolve(name, subject, bindings, ctx, cb) {
|
||||||
|
const resolver = this.resolvers.get(name);
|
||||||
|
if (resolver) return resolver(subject, bindings, ctx, cb);
|
||||||
|
cb(null, null); // stored-only measure with nothing stored → null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an external value resolver for a declared measure. The resolver is
|
||||||
|
* a value-graph callback/sync resolver: `(subject, params, ctx, cb)` → calls
|
||||||
|
* `cb(err, value)` (or `{ value, unit, source }`) or returns a value synchronously.
|
||||||
|
* Unknown measures are a no-op in non-strict mode, an error in strict mode.
|
||||||
|
*/
|
||||||
|
resolve(name, fn) {
|
||||||
|
if (!this._measure(name)) return this;
|
||||||
|
if (typeof fn !== 'function') throw new Error(`DSLValueGraph: resolver for '${name}' must be a function`);
|
||||||
|
this.resolvers.set(name, fn);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Storage — values/attributes that are NOT cached or computed.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a value/attribute directly into the value-graph. The value is validated
|
||||||
|
* against the measure's declared PROVIDES type and readable back via getValue /
|
||||||
|
* measure / runtime.measure until overwritten or invalidated.
|
||||||
|
* Unknown measures are a no-op in non-strict mode, an error in strict mode.
|
||||||
|
*/
|
||||||
|
setValue(name, args, value, { unit = null, source = 'dsl' } = {}) {
|
||||||
|
const meta = this._measure(name);
|
||||||
|
if (!meta) return this;
|
||||||
|
if (!validateValueType(value, meta.returnType)) {
|
||||||
|
throw new Error(`DSLValueGraph: value for '${name}' must match declared type '${meta.returnType}'`);
|
||||||
|
}
|
||||||
|
const bindings = this._bindings(name, args);
|
||||||
|
const subject = this.subjectOf(name, args);
|
||||||
|
this.vg.set(subject, name, bindings, { value, unit, source });
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Retrieval — partial-graph purposes.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronously retrieve a value from the value-graph (stored or resolved).
|
||||||
|
* Returns the entry `{ value, unit, at, source, fresh }` or `null`.
|
||||||
|
* Unknown measures are null in non-strict mode, an error in strict mode.
|
||||||
|
*/
|
||||||
|
getValue(name, args) {
|
||||||
|
const meta = this._measure(name);
|
||||||
|
if (!meta) return null;
|
||||||
|
const bindings = this._bindings(name, args);
|
||||||
|
const subject = this.subjectOf(name, args);
|
||||||
|
let out = null;
|
||||||
|
let errOut = null;
|
||||||
|
this.vg.get(subject, name, bindings, (err, entry) => { errOut = err; out = entry; });
|
||||||
|
if (errOut) throw errOut;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Async measure retrieval matching `DSLRuntime.measure`'s shape:
|
||||||
|
* `{ value, unit, source }`. Missing → `{ value: null, unit: null, source: null }`.
|
||||||
|
* Unknown measures are `{ value: null, ... }` in non-strict mode, an error in strict mode.
|
||||||
|
*/
|
||||||
|
async measure(name, args = {}) {
|
||||||
|
const meta = this._measure(name);
|
||||||
|
if (!meta) return { value: null, unit: null, source: null };
|
||||||
|
const bindings = this._bindings(name, args);
|
||||||
|
const subject = this.subjectOf(name, args);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.vg.get(subject, name, bindings, (err, entry) => {
|
||||||
|
if (err) return reject(err);
|
||||||
|
resolve(entry
|
||||||
|
? { value: entry.value, unit: entry.unit, source: entry.source }
|
||||||
|
: { value: null, unit: null, source: null });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wire `runtime.measure(name, args)` through the value-graph by registering a
|
||||||
|
* value-graph-backed provider for every DECLARED measure. Re-syncs first, so a
|
||||||
|
* recompiled runtime picks up new measures and drops attach-registered
|
||||||
|
* providers for removed ones. A later manual `registerMeasure` overrides it
|
||||||
|
* until the next attach.
|
||||||
|
*/
|
||||||
|
attach() {
|
||||||
|
this.sync();
|
||||||
|
const declared = new Set(this.measures.keys());
|
||||||
|
for (const name of this._attached) {
|
||||||
|
if (!declared.has(name) && this.runtime.measureProviders.has(name)) {
|
||||||
|
this.runtime.unregisterMeasure(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const name of declared) {
|
||||||
|
this.runtime.registerMeasure(name, async (bindings) => this.measure(name, bindings));
|
||||||
|
this._attached.add(name);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DSLValueGraph;
|
||||||
@@ -194,4 +194,40 @@ describe('DSLRuntime extended', () => {
|
|||||||
assert.ok(!rt.arbiter.relationConfigs.has('owns'));
|
assert.ok(!rt.arbiter.relationConfigs.has('owns'));
|
||||||
assert.ok(rt.arbiter.relationConfigs.has('can_share'));
|
assert.ok(rt.arbiter.relationConfigs.has('can_share'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('indexes measures and resolves them via a registered provider', async () => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(`
|
||||||
|
definition Employee { id: string? }
|
||||||
|
definition Project { id: string? }
|
||||||
|
measure budget_available(tenant: Employee, feature: string) { } PROVIDES number
|
||||||
|
measure clearance(user: Employee) { } PROVIDES string
|
||||||
|
`, 'rt-measures');
|
||||||
|
// Schema exposes measures with their return type.
|
||||||
|
const schema = rt.getSchema();
|
||||||
|
const budget = schema.measures.find(m => m.name === 'budget_available');
|
||||||
|
assert.ok(budget);
|
||||||
|
assert.equal(budget.returnType, 'number');
|
||||||
|
assert.deepEqual(budget.params.map(p => p.name), ['tenant', 'feature']);
|
||||||
|
assert.ok(rt.relationNames().includes('clearance'));
|
||||||
|
|
||||||
|
// No provider yet → resolution fails loudly.
|
||||||
|
await assert.rejects(() => rt.measure('budget_available', { tenant: 'tenant:acme', feature: 'tokens_in:gpt-4' }), /no provider registered/);
|
||||||
|
|
||||||
|
// Register a provider (the ARRA adapter would bridge the value-graph).
|
||||||
|
rt.registerMeasure('budget_available', async ({ tenant, feature }) => {
|
||||||
|
assert.equal(tenant, 'tenant:acme');
|
||||||
|
assert.equal(feature, 'tokens_in:gpt-4');
|
||||||
|
return { value: 1250, unit: 'tokens' };
|
||||||
|
});
|
||||||
|
const resolved = await rt.measure('budget_available', { tenant: 'tenant:acme', feature: 'tokens_in:gpt-4' });
|
||||||
|
assert.equal(resolved.value, 1250);
|
||||||
|
assert.equal(resolved.unit, 'tokens');
|
||||||
|
|
||||||
|
// Positional args bind by param order for unary measures.
|
||||||
|
rt.registerMeasure('clearance', async () => ({ value: 'secret' }));
|
||||||
|
assert.equal((await rt.measure('clearance', ['user:alice'])).value, 'secret');
|
||||||
|
|
||||||
|
// registerMeasure rejects undeclared names.
|
||||||
|
assert.throws(() => rt.registerMeasure('nope', async () => 1), /not a declared measure/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,201 @@
|
|||||||
|
/**
|
||||||
|
* DSLValueGraph — evidence DSL declares the value-graph's typing/structures;
|
||||||
|
* measures retrieve through the graph (partial-graph purposes), and attributes
|
||||||
|
* that are neither cached nor computed are stored directly via setValue.
|
||||||
|
*/
|
||||||
|
import { describe, it } from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { Arbiter } from '@arbiter/core';
|
||||||
|
import { ValueGraph } from '@arbiter/value-graph';
|
||||||
|
import { DSLRuntime, DSLValueGraph } from '../src/index.js';
|
||||||
|
|
||||||
|
function makeRuntime(dsl) {
|
||||||
|
return new DSLRuntime(new Arbiter()).compile(dsl, 'vg-test');
|
||||||
|
}
|
||||||
|
|
||||||
|
const DSL = `
|
||||||
|
definition Employee { id: string? }
|
||||||
|
definition Project { id: string? }
|
||||||
|
measure budget_available(tenant: Employee, feature: string) { } PROVIDES number
|
||||||
|
measure clearance(user: Employee) { } PROVIDES string
|
||||||
|
measure is_active(user: Employee) { } PROVIDES boolean
|
||||||
|
`;
|
||||||
|
|
||||||
|
describe('DSLValueGraph integration', () => {
|
||||||
|
it('derives the value-graph node schema from the DSL measures', () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
const schema = dvg.schema();
|
||||||
|
assert.equal(schema.budget_available.returnType, 'number');
|
||||||
|
assert.deepEqual(schema.budget_available.params.map((p) => p.name), ['tenant', 'feature']);
|
||||||
|
assert.equal(schema.clearance.returnType, 'string');
|
||||||
|
assert.equal(schema.is_active.returnType, 'boolean');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stores attributes that are neither cached nor computed, and reads them back', () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
dvg.setValue('budget_available', { __subject: 'tenant:acme', tenant: 'tenant:acme', feature: 'tokens_in:gpt-4' }, 1250, { unit: 'tokens' });
|
||||||
|
const entry = dvg.getValue('budget_available', { __subject: 'tenant:acme', tenant: 'tenant:acme', feature: 'tokens_in:gpt-4' });
|
||||||
|
assert.equal(entry.value, 1250);
|
||||||
|
assert.equal(entry.unit, 'tokens');
|
||||||
|
assert.equal(entry.source, 'dsl');
|
||||||
|
assert.equal(entry.fresh, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('measure() retrieves through the value-graph (partial-graph purposes)', async () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
dvg.setValue('clearance', { __subject: 'user:alice', user: 'user:alice' }, 'secret');
|
||||||
|
const resolved = await dvg.measure('clearance', { __subject: 'user:alice', user: 'user:alice' });
|
||||||
|
assert.equal(resolved.value, 'secret');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('attach() wires runtime.measure() through the value-graph', async () => {
|
||||||
|
const rt = makeRuntime(DSL);
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.setValue('is_active', { __subject: 'user:alice', user: 'user:alice' }, true);
|
||||||
|
dvg.attach();
|
||||||
|
const resolved = await rt.measure('is_active', { __subject: 'user:alice', user: 'user:alice' });
|
||||||
|
assert.equal(resolved.value, true);
|
||||||
|
// A measure with nothing stored resolves to null — no provider explosion.
|
||||||
|
const missing = await rt.measure('clearance', { __subject: 'user:bob', user: 'user:bob' });
|
||||||
|
assert.equal(missing.value, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves a value via an external callback resolver (the compute substrate)', async () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
dvg.resolve('budget_available', (subject, params, ctx, cb) => {
|
||||||
|
cb(null, { value: 999, unit: 'tokens', source: 'overlay:balances' });
|
||||||
|
});
|
||||||
|
const entry = await dvg.measure('budget_available', { __subject: 'tenant:acme', tenant: 'tenant:acme', feature: 'x' });
|
||||||
|
assert.equal(entry.value, 999);
|
||||||
|
assert.equal(entry.unit, 'tokens');
|
||||||
|
assert.equal(entry.source, 'overlay:balances');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('validates stored values against the declared PROVIDES type', () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
assert.throws(() => dvg.setValue('budget_available', { feature: 'x' }, 'not-a-number'), /must match declared type 'number'/);
|
||||||
|
assert.throws(() => dvg.setValue('clearance', { user: 'u' }, 42), /must match declared type 'string'/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('validates parameter bindings against the declared parameter types', () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
assert.throws(() => dvg.setValue('budget_available', { tenant: 't', feature: 42 }, 5),
|
||||||
|
/parameter 'feature' of 'budget_available' must match declared type 'string'/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects unknown measure names', async () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
assert.throws(() => dvg.setValue('nope', {}, 1), /not a declared measure/);
|
||||||
|
assert.throws(() => dvg.getValue('nope', {}), /not a declared measure/);
|
||||||
|
assert.throws(() => dvg.resolve('nope', () => 1), /not a declared measure/);
|
||||||
|
await assert.rejects(() => dvg.measure('nope', {}), /not a declared measure/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('binds positional args by declared parameter order', () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
dvg.setValue('budget_available', ['tenant:acme', 'tokens_in:gpt-4'], 50);
|
||||||
|
const entry = dvg.getValue('budget_available', ['tenant:acme', 'tokens_in:gpt-4']);
|
||||||
|
assert.equal(entry.value, 50);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('the value-graph itself enforces declared return types on resolver results', async () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
dvg.resolve('clearance', (s, p, ctx, cb) => cb(null, 12345)); // number, but PROVIDES string
|
||||||
|
const err = await dvg.measure('clearance', { __subject: 'user:alice', user: 'user:alice' }).then(() => null, (e) => e);
|
||||||
|
assert.ok(err, 'a wrong-typed resolver result must be rejected');
|
||||||
|
assert.match(err.message, /must match declared type 'string'/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shares a caller-supplied value graph and supports subjectOf', () => {
|
||||||
|
const vg = new ValueGraph();
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL), {
|
||||||
|
valueGraph: vg,
|
||||||
|
subjectOf: (name, args) => args.tenant || args.user || 'global'
|
||||||
|
});
|
||||||
|
assert.equal(dvg.vg, vg);
|
||||||
|
dvg.setValue('clearance', { user: 'user:alice' }, 'top-secret');
|
||||||
|
assert.equal(dvg.getValue('clearance', { user: 'user:alice' }).value, 'top-secret');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rigor: setValue/getValue round-trips always return the stored value', async () => {
|
||||||
|
const { rigor } = await import('@rigor/core');
|
||||||
|
const report = await rigor.campaign(
|
||||||
|
[rigor.fn('roundtrip', (value) => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
dvg.setValue('budget_available', { __subject: 'tenant:acme', tenant: 'tenant:acme', feature: 'f' }, value);
|
||||||
|
const e = dvg.getValue('budget_available', { __subject: 'tenant:acme', tenant: 'tenant:acme', feature: 'f' });
|
||||||
|
return e ? e.value : 'MISSING';
|
||||||
|
}, rigor.args(rigor.gen.int(-100000, 100000)))],
|
||||||
|
rigor.crucible([rigor.invariant('roundtrip', (ctx) => ctx.actual === ctx.args[0])])
|
||||||
|
).run({ effort: 150, seed: 'dsl-vg-roundtrip' });
|
||||||
|
if (report.status !== 'passed') {
|
||||||
|
throw new Error(`DSLValueGraph rigor roundtrip failed: ${JSON.stringify((report.failures || []).slice(0, 3))}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rigor: setValue rejects wrong-typed values for every generated value', async () => {
|
||||||
|
const { rigor } = await import('@rigor/core');
|
||||||
|
const report = await rigor.campaign(
|
||||||
|
[rigor.fn('typed-reject', (value) => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(DSL));
|
||||||
|
try {
|
||||||
|
dvg.setValue('clearance', { user: 'u' }, value); // PROVIDES string
|
||||||
|
return { ok: true };
|
||||||
|
} catch (e) {
|
||||||
|
return { ok: false, error: e.message };
|
||||||
|
}
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100)))],
|
||||||
|
rigor.crucible([rigor.invariant('rejects', (ctx) => ctx.actual.ok === false && /must match declared type 'string'/.test(ctx.actual.error))])
|
||||||
|
).run({ effort: 150, seed: 'dsl-vg-typecheck' });
|
||||||
|
if (report.status !== 'passed') {
|
||||||
|
throw new Error(`DSLValueGraph rigor typecheck failed: ${JSON.stringify((report.failures || []).slice(0, 3))}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('the aligned type vocabulary round-trips buffer/interval/any/duration', () => {
|
||||||
|
const dvg = new DSLValueGraph(makeRuntime(`
|
||||||
|
definition T { id: string }
|
||||||
|
measure quota(user: string) { } PROVIDES buffer
|
||||||
|
measure span(user: string) { } PROVIDES interval
|
||||||
|
measure whatever(user: string) { } PROVIDES any
|
||||||
|
measure window(user: string) { } PROVIDES duration
|
||||||
|
`));
|
||||||
|
const bytes = new Uint8Array([1, 2, 3, 254, 255]);
|
||||||
|
dvg.setValue('quota', { __subject: 'u', user: 'u' }, bytes);
|
||||||
|
assert.deepEqual([...dvg.getValue('quota', { __subject: 'u', user: 'u' }).value], [...bytes]);
|
||||||
|
dvg.setValue('span', { __subject: 'u', user: 'u' }, { lower: 100, upper: 200 });
|
||||||
|
assert.deepEqual(dvg.getValue('span', { __subject: 'u', user: 'u' }).value, { lower: 100, upper: 200 });
|
||||||
|
dvg.setValue('whatever', { __subject: 'u', user: 'u' }, 42); // any → accepted
|
||||||
|
assert.equal(dvg.getValue('whatever', { __subject: 'u', user: 'u' }).value, 42);
|
||||||
|
dvg.setValue('window', { __subject: 'u', user: 'u' }, '1h');
|
||||||
|
assert.equal(dvg.getValue('window', { __subject: 'u', user: 'u' }).value, '1h');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sync() re-registers measures after the runtime recompiles', () => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile('measure a() { } PROVIDES number', 'v1');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
rt.compile('measure b() { } PROVIDES string', 'v2'); // a removed, b added
|
||||||
|
// Before sync: stale schema.
|
||||||
|
assert.throws(() => dvg.setValue('b', {}, 'x'), /not a declared measure/);
|
||||||
|
// After sync: b is usable, a is gone.
|
||||||
|
dvg.sync();
|
||||||
|
dvg.setValue('b', {}, 'x');
|
||||||
|
assert.equal(dvg.getValue('b', {}).value, 'x');
|
||||||
|
assert.throws(() => dvg.setValue('a', {}, 1), /not a declared measure/);
|
||||||
|
// schema() reflects the current measure set
|
||||||
|
assert.ok(dvg.schema().b);
|
||||||
|
assert.ok(!dvg.schema().a);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('attach() re-syncs and unregisters providers for removed measures after recompile', async () => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile('measure a() { } PROVIDES number', 'v1');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
rt.compile('measure b() { } PROVIDES string', 'v2');
|
||||||
|
dvg.attach(); // re-sync + re-wire
|
||||||
|
dvg.setValue('b', { __subject: 't' }, 'hello');
|
||||||
|
assert.equal((await rt.measure('b', { __subject: 't' })).value, 'hello');
|
||||||
|
// a is no longer declared after the recompile → the runtime rejects it
|
||||||
|
await assert.rejects(() => rt.measure('a', { __subject: 't' }), /unknown measure/);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -12,6 +12,8 @@ import { describe, it } from 'node:test';
|
|||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import { Arbiter } from '@arbiter/core';
|
import { Arbiter } from '@arbiter/core';
|
||||||
import { DSLCompiler } from '../src/DSLCompiler.js';
|
import { DSLCompiler } from '../src/DSLCompiler.js';
|
||||||
|
import { DSLRuntime } from '../src/runtime/DSLRuntime.js';
|
||||||
|
import { DSLValueGraph } from '../src/value-graph/DSLValueGraph.js';
|
||||||
|
|
||||||
const DEFS = `
|
const DEFS = `
|
||||||
definition Employee { id: string }
|
definition Employee { id: string }
|
||||||
@@ -151,4 +153,64 @@ describe('Evidence composition', () => {
|
|||||||
assert.equal(arb.check('u:1', 'can_read', 'doc:9').possibility, 0.5);
|
assert.equal(arb.check('u:1', 'can_read', 'doc:9').possibility, 0.5);
|
||||||
assert.equal(arb.check('u:1', 'can_browse', 'doc:9').possibility, 0.5);
|
assert.equal(arb.check('u:1', 'can_browse', 'doc:9').possibility, 0.5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('measure + evidence composition', () => {
|
||||||
|
const M_DEFS = `
|
||||||
|
definition Employee { id: string }
|
||||||
|
measure budget_used(user: Employee) { } PROVIDES number
|
||||||
|
measure budget_limit(user: Employee) { } PROVIDES number
|
||||||
|
evidence can_use(user: Employee, doc: string) { budget_used(user) <= budget_limit(user) }
|
||||||
|
`;
|
||||||
|
|
||||||
|
it('compiles an evidence comparator over measure valueRelations', () => {
|
||||||
|
const { arb, result } = compile(M_DEFS, 'm+e-compile');
|
||||||
|
assert.ok(result.success, JSON.stringify(result.errors));
|
||||||
|
const cfg = arb.relationConfigs.get('can_use');
|
||||||
|
assert.equal(cfg.type, 'relational_comparator');
|
||||||
|
assert.equal(cfg.left.valueRelation, 'budget_used');
|
||||||
|
assert.equal(cfg.right.valueRelation, 'budget_limit');
|
||||||
|
assert.deepEqual(cfg.dependsOn, ['budget_used', 'budget_limit']);
|
||||||
|
assert.equal(cfg._needsValues, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('evaluates with measure values from registered providers (measure → evidence)', async () => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(M_DEFS, 'm+e-provider');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach(); // wires runtime.measure through the value-graph
|
||||||
|
rt.registerMeasure('budget_used', async () => ({ value: 900 }));
|
||||||
|
rt.registerMeasure('budget_limit', async () => ({ value: 1000 }));
|
||||||
|
rt.arbiter.addNode('u:1', 'Employee');
|
||||||
|
|
||||||
|
// Both systems live: the measure resolves standalone...
|
||||||
|
assert.equal((await rt.measure('budget_used', { user: 'u:1' })).value, 900);
|
||||||
|
// ...and composes into the evidence comparator.
|
||||||
|
const allow = await rt.check('u:1', 'can_use', 'doc:9');
|
||||||
|
assert.equal(allow.possibility, 1);
|
||||||
|
assert.equal(allow.reason, 'allow_rule_matched');
|
||||||
|
assert.ok(allow.providedFacts.includes('budget_used'), 'measure injected as a partial-graph edge');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('evaluates with measure values stored in the value-graph (setValue)', async () => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(M_DEFS, 'm+e-vg');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
dvg.setValue('budget_used', { __subject: 'u:1', user: 'u:1' }, 900);
|
||||||
|
dvg.setValue('budget_limit', { __subject: 'u:1', user: 'u:1' }, 1000);
|
||||||
|
rt.arbiter.addNode('u:1', 'Employee');
|
||||||
|
|
||||||
|
const allow = await rt.check('u:1', 'can_use', 'doc:9');
|
||||||
|
assert.equal(allow.possibility, 1, 'in-budget evidence allowed from graph-sourced measures');
|
||||||
|
|
||||||
|
// Over budget → the comparator denies.
|
||||||
|
const rt2 = new DSLRuntime(new Arbiter()).compile(M_DEFS, 'm+e-vg2');
|
||||||
|
const dvg2 = new DSLValueGraph(rt2);
|
||||||
|
dvg2.attach();
|
||||||
|
dvg2.setValue('budget_used', { __subject: 'u:1', user: 'u:1' }, 1200);
|
||||||
|
dvg2.setValue('budget_limit', { __subject: 'u:1', user: 'u:1' }, 1000);
|
||||||
|
rt2.arbiter.addNode('u:1', 'Employee');
|
||||||
|
const deny = await rt2.check('u:1', 'can_use', 'doc:9');
|
||||||
|
assert.equal(deny.possibility, 0);
|
||||||
|
assert.equal(deny.reason, 'values_compared_comparison_false');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,338 @@
|
|||||||
|
/**
|
||||||
|
* tests/rigor/dsl-value-graph-robustness.test.js — js-rigor invariants for the
|
||||||
|
* DSLValueGraph wrapper's robustness: attach() semantics, resolver failure modes,
|
||||||
|
* stored-value lifecycle (overwrite / invalidation isolation / TTL), binding
|
||||||
|
* edge cases, strict-mode behavior, and concurrent retrieval.
|
||||||
|
*/
|
||||||
|
import { describe, it } from 'node:test';
|
||||||
|
import { rigor, reducers } from '@rigor/core';
|
||||||
|
import { Arbiter } from '@arbiter/core';
|
||||||
|
import { ValueGraph } from '@arbiter/value-graph';
|
||||||
|
import { DSLRuntime, DSLValueGraph } from '../../src/index.js';
|
||||||
|
|
||||||
|
const DSL = `
|
||||||
|
definition Tenant { id: string }
|
||||||
|
measure budget(tenant: Tenant, feature: string) { } PROVIDES number
|
||||||
|
measure label(user: string) { } PROVIDES string
|
||||||
|
`;
|
||||||
|
|
||||||
|
function makeDvg() {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'vg-robust');
|
||||||
|
return new DSLValueGraph(rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function expectPass(name, actions, checks, config = {}) {
|
||||||
|
const report = await rigor.campaign(actions, rigor.crucible(checks))
|
||||||
|
.run({ seed: `dsl-vg-robust-${name}`, effort: 100, artifacts: { dir: '', persist: 'never' }, ...config });
|
||||||
|
if (report.status !== 'passed') {
|
||||||
|
const detail = (report.failures || []).slice(0, 5)
|
||||||
|
.map((f) => JSON.stringify({ action: f.actionName || f.action, inv: f.name, args: f.args, msg: f.message }));
|
||||||
|
throw new Error(`campaign '${name}' failed.\n${detail.join('\n')}`);
|
||||||
|
}
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('DSLValueGraph robustness (rigor)', () => {
|
||||||
|
it('attach() is idempotent and a manual registerMeasure overrides it', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('attach_idempotent', (value, cb) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
dvg.attach(); // idempotent
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, value);
|
||||||
|
rt.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, r.value), (e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('attach_override', (cb) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
rt.registerMeasure('budget', async () => ({ value: 12345, unit: 'manual' }));
|
||||||
|
rt.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, r.value), (e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('attach_idempotent', (ctx) => ctx.error == null && ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('attach_override', (ctx) => ctx.error == null && ctx.actual === 12345),
|
||||||
|
];
|
||||||
|
await expectPass('attach', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolver failure modes: sync-return, error propagation, wrong-typed result', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('resolver_sync', (value, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p) => value * 2); // sync return
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, r.value), (e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 50), rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('resolver_error', (cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p, ctx, done) => { done(new Error('provider down')); });
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, { ok: true, v: r.value }),
|
||||||
|
(e) => cb(null, { ok: false, msg: e.message })
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('resolver_wrong_type', (cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p, ctx, done) => { done(null, 'not-a-number'); });
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, { ok: true, v: r.value }),
|
||||||
|
(e) => cb(null, { ok: false, msg: e.message })
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('resolver_sync', (ctx) => ctx.error == null && ctx.actual === ctx.args[0] * 2),
|
||||||
|
rigor.after('resolver_error', (ctx) => ctx.actual.ok === false && /provider down/.test(ctx.actual.msg)),
|
||||||
|
rigor.after('resolver_wrong_type', (ctx) => ctx.actual.ok === false && /must match declared type 'number'/.test(ctx.actual.msg)),
|
||||||
|
];
|
||||||
|
await expectPass('resolvers', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stored-value lifecycle: overwrite wins, cross-measure invalidation is isolated, TTL expires', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('overwrite', (a, b) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, a);
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, b); // last-write-wins
|
||||||
|
return dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' }).value;
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('cross_measure_invalidate', (a, b) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, a);
|
||||||
|
dvg.setValue('label', { __subject: 't', user: 'u' }, String(b));
|
||||||
|
dvg.vg.invalidate('t', 'budget', { tenant: 't', feature: 'x' });
|
||||||
|
const budget = dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' });
|
||||||
|
const label = dvg.getValue('label', { __subject: 't', user: 'u' });
|
||||||
|
return { budget: budget === null ? 'null' : budget.value, label: label.value };
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('ttl_expiry', (value, cb) => {
|
||||||
|
let t = 0;
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt, {
|
||||||
|
valueGraph: new ValueGraph({ clock: () => t, defaultTTL: 100 })
|
||||||
|
});
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, value);
|
||||||
|
const before = dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' }).value;
|
||||||
|
t = 200;
|
||||||
|
const after = dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' });
|
||||||
|
cb(null, { before, after: after === null ? 'null' : after.value });
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('overwrite', (ctx) => ctx.actual === ctx.args[1]),
|
||||||
|
rigor.after('cross_measure_invalidate', (ctx) => ctx.actual.budget === 'null' && ctx.actual.label === String(ctx.args[1])),
|
||||||
|
rigor.after('ttl_expiry', (ctx) => ctx.actual.before === ctx.args[0] && ctx.actual.after === 'null'),
|
||||||
|
];
|
||||||
|
await expectPass('lifecycle', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('binding edge cases: array params, extra keys preserved, positional arity, unit/source', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('array_param', (arr, cb) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(`measure tags(user: string, xs: array) { } PROVIDES number`, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.setValue('tags', { __subject: 't', user: 'u', xs: arr }, 7);
|
||||||
|
const e = dvg.getValue('tags', { __subject: 't', user: 'u', xs: arr });
|
||||||
|
cb(null, e ? e.value : 'MISSING');
|
||||||
|
}, rigor.args(rigor.gen.array(rigor.gen.int(0, 9), 0, 4), rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('extra_keys', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x', extra: 'zzz' }, v);
|
||||||
|
return dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x', extra: 'zzz' }).value;
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('positional_arity', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', ['t', 'x'], v);
|
||||||
|
return dvg.getValue('budget', ['t', 'x']).value;
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('unit_preserved', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, v, { unit: 'tokens', source: 'ledger' });
|
||||||
|
const e = dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' });
|
||||||
|
return { value: e.value, unit: e.unit, source: e.source };
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('array_param', (ctx) => ctx.error == null && ctx.actual === 7),
|
||||||
|
rigor.after('extra_keys', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('positional_arity', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('unit_preserved', (ctx) => ctx.actual.value === ctx.args[0] && ctx.actual.unit === 'tokens' && ctx.actual.source === 'ledger'),
|
||||||
|
];
|
||||||
|
await expectPass('bindings', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('strict:false degrades gracefully for unknown measures; strict mode throws', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('strict_false', (cb) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt, { strict: false });
|
||||||
|
dvg.setValue('nope', {}, 1); // no-op
|
||||||
|
dvg.resolve('nope', () => 1); // no-op
|
||||||
|
const g = dvg.getValue('nope', {}); // null
|
||||||
|
dvg.measure('nope', {}).then(
|
||||||
|
(r) => cb(null, { get: g, measure: r.value }),
|
||||||
|
() => cb(null, { get: g, measure: 'rejected' })
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('no_value_null', () => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
return dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' }) === null ? 'null' : 'value';
|
||||||
|
}, rigor.args()),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('strict_false', (ctx) => ctx.actual.get === null && ctx.actual.measure === null),
|
||||||
|
rigor.after('no_value_null', (ctx) => ctx.actual === 'null'),
|
||||||
|
];
|
||||||
|
await expectPass('strict', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('concurrent measure retrievals all resolve to the same stored value', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('concurrent_measure', (value, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, value);
|
||||||
|
const N = 5;
|
||||||
|
const calls = [];
|
||||||
|
for (let i = 0; i < N; i++) {
|
||||||
|
calls.push(dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then((r) => r.value));
|
||||||
|
}
|
||||||
|
Promise.all(calls).then((values) => cb(null, values), (e) => cb(e));
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('concurrent_measure', (ctx) =>
|
||||||
|
ctx.error == null && Array.isArray(ctx.actual) && ctx.actual.length === 5 && ctx.actual.every((v) => v === ctx.args[0])),
|
||||||
|
];
|
||||||
|
await expectPass('concurrent', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stored values and resolvers coexist per subject (stored wins on its own subject)', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('subject_resolver_mix', (a, b, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 'A', tenant: 'A', feature: 'x' }, a);
|
||||||
|
dvg.resolve('budget', (s) => b);
|
||||||
|
dvg.measure('budget', { __subject: 'A', tenant: 'A', feature: 'x' }).then(
|
||||||
|
(r1) => dvg.measure('budget', { __subject: 'B', tenant: 'B', feature: 'x' }).then(
|
||||||
|
(r2) => cb(null, { a: r1.value, b: r2.value }),
|
||||||
|
(e) => cb(e)
|
||||||
|
),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('subject_resolver_mix', (ctx) =>
|
||||||
|
ctx.error == null && ctx.actual.a === ctx.args[0] && ctx.actual.b === ctx.args[1]),
|
||||||
|
];
|
||||||
|
await expectPass('subject-resolver-mix', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('final confirmation: positional arity enforced, zero-param measures, control keys stripped', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('arity_too_many', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
try { dvg.setValue('budget', ['t', 'x', 'extra'], v); return { ok: true }; }
|
||||||
|
catch (e) { return { ok: false, msg: e.message }; }
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('arity_too_few', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
try { dvg.setValue('budget', ['t'], v); return { ok: true }; }
|
||||||
|
catch (e) { return { ok: false, msg: e.message }; }
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('arity_exact', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', ['t', 'x'], v);
|
||||||
|
return dvg.getValue('budget', ['t', 'x']).value;
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('zero_param_measure', (v) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(`measure heartbeat() { } PROVIDES number`, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.setValue('heartbeat', {}, v);
|
||||||
|
const e = dvg.getValue('heartbeat', {});
|
||||||
|
return e ? e.value : 'MISSING';
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
rigor.fn('actor_stripped', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
// __actor is a control key → stripped from the cache key, so differing
|
||||||
|
// actors hit the SAME stored entry.
|
||||||
|
dvg.setValue('budget', { __actor: 'actor:1', __subject: 't', tenant: 't', feature: 'x' }, v);
|
||||||
|
return dvg.getValue('budget', { __actor: 'actor:2', __subject: 't', tenant: 't', feature: 'x' }).value;
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('arity_too_many', (ctx) => ctx.actual.ok === false && /expects 2 positional argument\(s\), got 3/.test(ctx.actual.msg)),
|
||||||
|
rigor.after('arity_too_few', (ctx) => ctx.actual.ok === false && /expects 2 positional argument\(s\), got 1/.test(ctx.actual.msg)),
|
||||||
|
rigor.after('arity_exact', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('zero_param_measure', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('actor_stripped', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
];
|
||||||
|
await expectPass('final-confirm', actions, checks);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('hardening: retrieval paths, sync-throw resolvers, unregister, param-driven resolvers, NaN', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('get_sync_vs_measure_async', (value, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p, ctx, done) => { setTimeout(() => done(null, value), 1); });
|
||||||
|
const syncPath = dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' });
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, { sync: syncPath === null ? 'null' : syncPath.value, async: r.value }),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('resolver_throws_sync', (cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', () => { throw new Error('boom'); });
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, { ok: true, v: r.value }),
|
||||||
|
(e) => cb(null, { ok: false, msg: e.message })
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('unregister_after_attach', (cb) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'r');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
rt.unregisterMeasure('budget');
|
||||||
|
rt.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, { ok: true, v: r.value }),
|
||||||
|
(e) => cb(null, { ok: false, msg: e.message })
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('resolver_from_params', (x, y, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p, ctx, done) => done(null, p.feature === 'a' ? x : y));
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'a' }).then(
|
||||||
|
(r1) => dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'b' }).then(
|
||||||
|
(r2) => cb(null, { a: r1.value, b: r2.value }),
|
||||||
|
(e) => cb(e)
|
||||||
|
),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('nan_rejected', () => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
try { dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, Number.NaN); return { ok: true }; }
|
||||||
|
catch (e) { return { ok: false, msg: e.message }; }
|
||||||
|
}, rigor.args()),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('get_sync_vs_measure_async', (ctx) =>
|
||||||
|
ctx.error == null && ctx.actual.sync === 'null' && ctx.actual.async === ctx.args[0]),
|
||||||
|
rigor.after('resolver_throws_sync', (ctx) => ctx.actual.ok === false && /boom/.test(ctx.actual.msg)),
|
||||||
|
rigor.after('unregister_after_attach', (ctx) => ctx.actual.ok === false && /no provider registered/.test(ctx.actual.msg)),
|
||||||
|
rigor.after('resolver_from_params', (ctx) =>
|
||||||
|
ctx.error == null && ctx.actual.a === ctx.args[0] && ctx.actual.b === ctx.args[1]),
|
||||||
|
rigor.after('nan_rejected', (ctx) => ctx.actual.ok === false && /must match declared type 'number'/.test(ctx.actual.msg)),
|
||||||
|
];
|
||||||
|
await expectPass('hardening', actions, checks);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,226 @@
|
|||||||
|
/**
|
||||||
|
* tests/rigor/dsl-value-graph.test.js — js-rigor deep tests for the
|
||||||
|
* DSLValueGraph integration (evidence DSL declares the value-graph's typing;
|
||||||
|
* measures retrieve through the graph; attributes are stored directly).
|
||||||
|
*
|
||||||
|
* Covers, as property campaigns:
|
||||||
|
* - setValue/getValue round-trips across every declared value type
|
||||||
|
* - type enforcement (wrong-typed writes always reject)
|
||||||
|
* - parameter-binding validation (wrong-typed params always reject)
|
||||||
|
* - subject scoping (different subjects never share entries)
|
||||||
|
* - attach() parity (runtime.measure === value-graph retrieval)
|
||||||
|
* - external resolvers compute, and a stored value wins over the resolver
|
||||||
|
* - invalidation clears a stored value (next retrieval → null)
|
||||||
|
* - schema derivation from generated measure declarations
|
||||||
|
* - multi-measure independence
|
||||||
|
*/
|
||||||
|
import { describe, it } from 'node:test';
|
||||||
|
import { rigor, reducers } from '@rigor/core';
|
||||||
|
import { Arbiter } from '@arbiter/core';
|
||||||
|
import { DSLRuntime, DSLValueGraph } from '../../src/index.js';
|
||||||
|
|
||||||
|
const DSL = `
|
||||||
|
definition Tenant { id: string }
|
||||||
|
measure budget(tenant: Tenant, feature: string) { } PROVIDES number
|
||||||
|
measure label(user: string) { } PROVIDES string
|
||||||
|
measure active(user: string) { } PROVIDES boolean
|
||||||
|
measure tags(user: string) { } PROVIDES array
|
||||||
|
`;
|
||||||
|
|
||||||
|
function makeDvg() {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'vg-rigor');
|
||||||
|
return new DSLValueGraph(rt);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function expectPass(name, actions, checks, config = {}) {
|
||||||
|
const report = await rigor.campaign(actions, rigor.crucible(checks))
|
||||||
|
.run({ seed: `dsl-vg-${name}`, effort: 120, artifacts: { dir: '', persist: 'never' }, ...config });
|
||||||
|
if (report.status !== 'passed') {
|
||||||
|
const detail = (report.failures || []).slice(0, 5)
|
||||||
|
.map((f) => JSON.stringify({ action: f.actionName || f.action, inv: f.name, args: f.args, msg: f.message }));
|
||||||
|
throw new Error(`campaign '${name}' failed.\n${detail.join('\n')}`);
|
||||||
|
}
|
||||||
|
return report;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('DSLValueGraph integration (rigor)', () => {
|
||||||
|
it('setValue/getValue round-trips every declared value type', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('rt_number', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, v);
|
||||||
|
const e = dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' });
|
||||||
|
return e ? e.value : 'MISSING';
|
||||||
|
}, rigor.args(rigor.gen.int(-100000, 100000))),
|
||||||
|
rigor.fn('rt_string', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('label', { __subject: 't', user: 'u' }, v);
|
||||||
|
const e = dvg.getValue('label', { __subject: 't', user: 'u' });
|
||||||
|
return e ? e.value : 'MISSING';
|
||||||
|
}, rigor.args(rigor.gen.asciiString())),
|
||||||
|
rigor.fn('rt_bool', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('active', { __subject: 't', user: 'u' }, v);
|
||||||
|
const e = dvg.getValue('active', { __subject: 't', user: 'u' });
|
||||||
|
return e ? e.value : 'MISSING';
|
||||||
|
}, rigor.args(rigor.gen.boolean())),
|
||||||
|
rigor.fn('rt_array', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('tags', { __subject: 't', user: 'u' }, v);
|
||||||
|
const e = dvg.getValue('tags', { __subject: 't', user: 'u' });
|
||||||
|
return e ? e.value : null;
|
||||||
|
}, rigor.args(rigor.gen.array(rigor.gen.string(), 0, 5))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('rt_number', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('rt_string', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('rt_bool', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('rt_array', (ctx) => JSON.stringify(ctx.actual) === JSON.stringify(ctx.args[0])),
|
||||||
|
];
|
||||||
|
await expectPass('roundtrip', actions, checks, { effort: 200 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('type enforcement: wrong-typed writes always reject, right-typed always pass', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('type_ok', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, v);
|
||||||
|
return dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' }).value;
|
||||||
|
}, rigor.args(rigor.gen.int(-100, 100))),
|
||||||
|
rigor.fn('type_reject', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
try { dvg.setValue('label', { user: 'u' }, v); return { ok: true }; }
|
||||||
|
catch (e) { return { ok: false, msg: e.message }; }
|
||||||
|
}, rigor.args(rigor.gen.oneOf([rigor.gen.int(0, 100), rigor.gen.boolean(), rigor.gen.array(rigor.gen.int(0, 9), 1, 3)]))),
|
||||||
|
rigor.fn('param_reject', (v) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
try { dvg.setValue('budget', { tenant: 't', feature: v }, 1); return { ok: true }; }
|
||||||
|
catch (e) { return { ok: false, msg: e.message }; }
|
||||||
|
}, rigor.args(rigor.gen.oneOf([rigor.gen.constant(42), rigor.gen.boolean(), rigor.gen.array(rigor.gen.int(0, 9), 1, 2)]))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('type_ok', (ctx) => ctx.actual === ctx.args[0]),
|
||||||
|
rigor.after('type_reject', (ctx) => ctx.actual.ok === false && /must match declared type 'string'/.test(ctx.actual.msg)),
|
||||||
|
rigor.after('param_reject', (ctx) => ctx.actual.ok === false && /parameter 'feature'/.test(ctx.actual.msg)),
|
||||||
|
];
|
||||||
|
await expectPass('typecheck', actions, checks, { effort: 200 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('subjects never share entries', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('subject_isolation', (a, b) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 'A', tenant: 'A', feature: 'x' }, a);
|
||||||
|
dvg.setValue('budget', { __subject: 'B', tenant: 'B', feature: 'x' }, b);
|
||||||
|
const ea = dvg.getValue('budget', { __subject: 'A', tenant: 'A', feature: 'x' });
|
||||||
|
const eb = dvg.getValue('budget', { __subject: 'B', tenant: 'B', feature: 'x' });
|
||||||
|
return { a: ea ? ea.value : null, b: eb ? eb.value : null };
|
||||||
|
}, rigor.args(rigor.gen.int(-50, 50), rigor.gen.int(-50, 50))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('subject_isolation', (ctx) => ctx.actual.a === ctx.args[0] && ctx.actual.b === ctx.args[1]),
|
||||||
|
];
|
||||||
|
await expectPass('subjects', actions, checks, { effort: 120 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('attach() makes runtime.measure retrieve through the value-graph', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('attach_parity', (value, cb) => {
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(DSL, 'vg-rigor');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
dvg.attach();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, value);
|
||||||
|
rt.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, r.value),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('attach_parity', (ctx) => ctx.error == null && ctx.actual === ctx.args[0]),
|
||||||
|
];
|
||||||
|
await expectPass('attach', actions, checks, { effort: 120 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('external resolvers compute; a stored value wins over the resolver', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('resolver_compute', (value, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p, ctx, done) => done(null, { value, unit: 'tokens', source: 'resolver' }));
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, { value: r.value, source: r.source }),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
rigor.fn('stored_wins', (value, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.resolve('budget', (s, p, ctx, done) => done(null, 999));
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, value);
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, r.value),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('resolver_compute', (ctx) => ctx.error == null && ctx.actual.value === ctx.args[0] && ctx.actual.source === 'resolver'),
|
||||||
|
rigor.after('stored_wins', (ctx) => ctx.error == null && ctx.actual === ctx.args[0]),
|
||||||
|
];
|
||||||
|
await expectPass('resolvers', actions, checks, { effort: 120 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('invalidation clears a stored value; the next retrieval is null', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('invalidate_clears', (value, cb) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, value);
|
||||||
|
dvg.vg.invalidate('t', 'budget', { tenant: 't', feature: 'x' });
|
||||||
|
dvg.measure('budget', { __subject: 't', tenant: 't', feature: 'x' }).then(
|
||||||
|
(r) => cb(null, r.value),
|
||||||
|
(e) => cb(e)
|
||||||
|
);
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.handler(reducers.first()))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('invalidate_clears', (ctx) => ctx.error == null && ctx.actual === null),
|
||||||
|
];
|
||||||
|
await expectPass('invalidate', actions, checks, { effort: 120 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('schema derivation: every generated measure gets its declared returnType and params', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('schema_ok', (name, type) => {
|
||||||
|
const dsl = `definition T { id: string } measure ${name}(p: T) { } PROVIDES ${type}`;
|
||||||
|
const rt = new DSLRuntime(new Arbiter()).compile(dsl, 'gen');
|
||||||
|
const dvg = new DSLValueGraph(rt);
|
||||||
|
const spec = dvg.schema()[name];
|
||||||
|
return { returnType: spec && spec.returnType, params: spec ? spec.params.map((x) => x.name) : null };
|
||||||
|
}, rigor.args(
|
||||||
|
rigor.gen.oneOf(['balance', 'rate', 'quota', 'volume', 'meter']),
|
||||||
|
rigor.gen.oneOf(['number', 'string', 'boolean', 'array'])
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('schema_ok', (ctx) => ctx.actual.returnType === ctx.args[1] && JSON.stringify(ctx.actual.params) === JSON.stringify(['p'])),
|
||||||
|
];
|
||||||
|
await expectPass('schema', actions, checks, { effort: 120 });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('measures are independent (no cross-measure cache sharing)', async () => {
|
||||||
|
const actions = [
|
||||||
|
rigor.fn('multi_measure', (a, b) => {
|
||||||
|
const dvg = makeDvg();
|
||||||
|
dvg.setValue('budget', { __subject: 't', tenant: 't', feature: 'x' }, a);
|
||||||
|
dvg.setValue('label', { __subject: 't', user: 'u' }, String(b));
|
||||||
|
return {
|
||||||
|
budget: dvg.getValue('budget', { __subject: 't', tenant: 't', feature: 'x' }).value,
|
||||||
|
label: dvg.getValue('label', { __subject: 't', user: 'u' }).value
|
||||||
|
};
|
||||||
|
}, rigor.args(rigor.gen.int(0, 100), rigor.gen.int(0, 100))),
|
||||||
|
];
|
||||||
|
const checks = [
|
||||||
|
rigor.after('multi_measure', (ctx) => ctx.actual.budget === ctx.args[0] && ctx.actual.label === String(ctx.args[1])),
|
||||||
|
];
|
||||||
|
await expectPass('independence', actions, checks, { effort: 120 });
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user