@altopelago/sansa 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +150 -0
- package/README.md +107 -4
- package/conformance/README.md +19 -0
- package/conformance/cts-claims.json +53 -0
- package/docs/api-contract.md +541 -14
- package/docs/capabilities.json +210 -4
- package/docs/instruction-tool.md +345 -0
- package/docs/mutate-policy.md +148 -0
- package/docs/query-tool.md +123 -11
- package/docs/releasing.md +2 -2
- package/fixtures/address-v1.json +9 -9
- package/fixtures/query-inventory.aeon +65 -3
- package/fixtures/query-inventory.json +194 -3
- package/package.json +9 -2
- package/scripts/cts-instruction.mjs +284 -0
- package/scripts/cts-mutate.mjs +476 -0
- package/scripts/cts-resolve.mjs +9 -0
- package/scripts/instruction.mjs +423 -0
- package/scripts/query-web.mjs +56 -0
- package/scripts/query.mjs +34 -2
- package/scripts/validate-cts-claims.mjs +133 -0
- package/src/index.d.ts +954 -3
- package/src/index.js +5505 -393
- package/stress-tests/address/valid.sansa-cases +3 -3
- package/tools/mutate-web/app.js +370 -0
- package/tools/mutate-web/examples.mjs +1280 -0
- package/tools/mutate-web/index.html +138 -0
- package/tools/mutate-web/runtime.mjs +1308 -0
- package/tools/mutate-web/styles.css +354 -0
- package/tools/query-web/app.js +8 -1
- package/tools/query-web/examples.mjs +131 -5
- package/tools/query-web/index.html +10 -0
- package/tools/query-web/runtime.mjs +100 -9
- package/tools/query-web/styles.css +1 -1
|
@@ -89,6 +89,148 @@
|
|
|
89
89
|
}
|
|
90
90
|
},
|
|
91
91
|
"children": [
|
|
92
|
+
{
|
|
93
|
+
"name": "consent",
|
|
94
|
+
"address": "$.consent",
|
|
95
|
+
"semanticType": "toggle",
|
|
96
|
+
"representationKind": "toggle",
|
|
97
|
+
"scalarKind": "toggle",
|
|
98
|
+
"value": "yes"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "fallbackConsent",
|
|
102
|
+
"address": "$.fallbackConsent",
|
|
103
|
+
"semanticType": "toggle",
|
|
104
|
+
"representationKind": "toggle",
|
|
105
|
+
"scalarKind": "toggle",
|
|
106
|
+
"value": "on"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"name": "target",
|
|
110
|
+
"address": "$.target",
|
|
111
|
+
"semanticType": "number",
|
|
112
|
+
"representationKind": "number",
|
|
113
|
+
"value": 7
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"name": "targetClone",
|
|
117
|
+
"address": "$.targetClone",
|
|
118
|
+
"semanticType": "number",
|
|
119
|
+
"representationKind": "cloneReference",
|
|
120
|
+
"scalarKind": "referenceForm",
|
|
121
|
+
"value": {
|
|
122
|
+
"type": "CloneReference",
|
|
123
|
+
"path": [
|
|
124
|
+
"target"
|
|
125
|
+
],
|
|
126
|
+
"canonical": "~target"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"name": "targetPointer",
|
|
131
|
+
"address": "$.targetPointer",
|
|
132
|
+
"semanticType": "number",
|
|
133
|
+
"representationKind": "pointerReference",
|
|
134
|
+
"scalarKind": "referenceForm",
|
|
135
|
+
"value": {
|
|
136
|
+
"type": "PointerReference",
|
|
137
|
+
"path": [
|
|
138
|
+
"target"
|
|
139
|
+
],
|
|
140
|
+
"canonical": "~>target"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "types",
|
|
145
|
+
"address": "$.types",
|
|
146
|
+
"representationKind": "object",
|
|
147
|
+
"children": [
|
|
148
|
+
{
|
|
149
|
+
"name": "color",
|
|
150
|
+
"address": "$.types.color",
|
|
151
|
+
"semanticType": "hex",
|
|
152
|
+
"representationKind": "hex",
|
|
153
|
+
"scalarKind": "hex",
|
|
154
|
+
"value": "ff00aa"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"name": "colorCopy",
|
|
158
|
+
"address": "$.types.colorCopy",
|
|
159
|
+
"semanticType": "hex",
|
|
160
|
+
"representationKind": "hex",
|
|
161
|
+
"scalarKind": "hex",
|
|
162
|
+
"value": "ff00aa"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"name": "mask",
|
|
166
|
+
"address": "$.types.mask",
|
|
167
|
+
"semanticType": "radix[16]",
|
|
168
|
+
"representationKind": "radix",
|
|
169
|
+
"scalarKind": "radix",
|
|
170
|
+
"value": "ff00aa"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"name": "payload",
|
|
174
|
+
"address": "$.types.payload",
|
|
175
|
+
"semanticType": "encoding",
|
|
176
|
+
"representationKind": "encoding",
|
|
177
|
+
"scalarKind": "encoding",
|
|
178
|
+
"value": "QmFzZTY0IQ=="
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"name": "version",
|
|
182
|
+
"address": "$.types.version",
|
|
183
|
+
"semanticType": "sep[\".\"]",
|
|
184
|
+
"representationKind": "separator",
|
|
185
|
+
"scalarKind": "separator",
|
|
186
|
+
"value": "0.11.0"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"name": "released",
|
|
190
|
+
"address": "$.types.released",
|
|
191
|
+
"semanticType": "date",
|
|
192
|
+
"representationKind": "date",
|
|
193
|
+
"scalarKind": "date",
|
|
194
|
+
"value": "2026-07-25"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"name": "window",
|
|
198
|
+
"address": "$.types.window",
|
|
199
|
+
"semanticType": "time",
|
|
200
|
+
"representationKind": "time",
|
|
201
|
+
"scalarKind": "time",
|
|
202
|
+
"value": "09:30:00Z"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "stamp",
|
|
206
|
+
"address": "$.types.stamp",
|
|
207
|
+
"semanticType": "datetime",
|
|
208
|
+
"representationKind": "datetime",
|
|
209
|
+
"scalarKind": "datetime",
|
|
210
|
+
"value": "2026-07-25T09:30:00Z"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "zone",
|
|
214
|
+
"address": "$.types.zone",
|
|
215
|
+
"semanticType": "wtc",
|
|
216
|
+
"representationKind": "wtc",
|
|
217
|
+
"scalarKind": "wtc",
|
|
218
|
+
"value": "2026-07-25T09:30:00Z&Australia/Melbourne"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "selector",
|
|
222
|
+
"address": "$.types.selector",
|
|
223
|
+
"semanticType": "sansa",
|
|
224
|
+
"representationKind": "sansa",
|
|
225
|
+
"scalarKind": "sansaAddress",
|
|
226
|
+
"value": {
|
|
227
|
+
"type": "SansaAddressLiteral",
|
|
228
|
+
"address": "$.inventory.items.*.sku",
|
|
229
|
+
"canonical": "$.inventory.items.*.sku"
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
},
|
|
92
234
|
{
|
|
93
235
|
"name": "inventory",
|
|
94
236
|
"address": "$.inventory",
|
|
@@ -632,7 +774,7 @@
|
|
|
632
774
|
"address": "$.labels[0].value",
|
|
633
775
|
"semanticType": "string",
|
|
634
776
|
"representationKind": "string",
|
|
635
|
-
"value": "
|
|
777
|
+
"value": "zebre"
|
|
636
778
|
}
|
|
637
779
|
]
|
|
638
780
|
},
|
|
@@ -646,7 +788,7 @@
|
|
|
646
788
|
"address": "$.labels[1].value",
|
|
647
789
|
"semanticType": "string",
|
|
648
790
|
"representationKind": "string",
|
|
649
|
-
|
|
791
|
+
"value": "éclair"
|
|
650
792
|
}
|
|
651
793
|
]
|
|
652
794
|
},
|
|
@@ -660,7 +802,56 @@
|
|
|
660
802
|
"address": "$.labels[2].value",
|
|
661
803
|
"semanticType": "string",
|
|
662
804
|
"representationKind": "string",
|
|
663
|
-
|
|
805
|
+
"value": "adapter"
|
|
806
|
+
}
|
|
807
|
+
]
|
|
808
|
+
}
|
|
809
|
+
]
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
"name": "parts",
|
|
813
|
+
"address": "$.parts",
|
|
814
|
+
"representationKind": "list",
|
|
815
|
+
"children": [
|
|
816
|
+
{
|
|
817
|
+
"index": 0,
|
|
818
|
+
"address": "$.parts[0]",
|
|
819
|
+
"representationKind": "object",
|
|
820
|
+
"children": [
|
|
821
|
+
{
|
|
822
|
+
"name": "value",
|
|
823
|
+
"address": "$.parts[0].value",
|
|
824
|
+
"semanticType": "string",
|
|
825
|
+
"representationKind": "string",
|
|
826
|
+
"value": "part-10"
|
|
827
|
+
}
|
|
828
|
+
]
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
"index": 1,
|
|
832
|
+
"address": "$.parts[1]",
|
|
833
|
+
"representationKind": "object",
|
|
834
|
+
"children": [
|
|
835
|
+
{
|
|
836
|
+
"name": "value",
|
|
837
|
+
"address": "$.parts[1].value",
|
|
838
|
+
"semanticType": "string",
|
|
839
|
+
"representationKind": "string",
|
|
840
|
+
"value": "part-2"
|
|
841
|
+
}
|
|
842
|
+
]
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
"index": 2,
|
|
846
|
+
"address": "$.parts[2]",
|
|
847
|
+
"representationKind": "object",
|
|
848
|
+
"children": [
|
|
849
|
+
{
|
|
850
|
+
"name": "value",
|
|
851
|
+
"address": "$.parts[2].value",
|
|
852
|
+
"semanticType": "string",
|
|
853
|
+
"representationKind": "string",
|
|
854
|
+
"value": "part-1"
|
|
664
855
|
}
|
|
665
856
|
]
|
|
666
857
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altopelago/sansa",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Semantic Address NameSpace Abstraction parser, resolver, and query toolkit.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"sansa-query": "./scripts/query.mjs"
|
|
16
|
+
"sansa-query": "./scripts/query.mjs",
|
|
17
|
+
"sansa-instruction": "./scripts/instruction.mjs"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"src",
|
|
20
21
|
"docs",
|
|
22
|
+
"conformance",
|
|
21
23
|
"fixtures",
|
|
22
24
|
"scripts",
|
|
23
25
|
"tools",
|
|
@@ -52,9 +54,14 @@
|
|
|
52
54
|
"cts:resolve": "node scripts/cts-resolve.mjs",
|
|
53
55
|
"cts:query": "node scripts/cts-query.mjs",
|
|
54
56
|
"cts:query:experimental": "node scripts/cts-query.mjs --include-experimental",
|
|
57
|
+
"cts:instruction": "node scripts/cts-instruction.mjs",
|
|
58
|
+
"cts:mutate": "node scripts/cts-mutate.mjs",
|
|
59
|
+
"instruction": "node scripts/instruction.mjs",
|
|
55
60
|
"query": "node scripts/query.mjs",
|
|
56
61
|
"query:web": "node scripts/query-web.mjs",
|
|
62
|
+
"mutate:web": "node scripts/query-web.mjs",
|
|
57
63
|
"stress": "node scripts/stress-addresses.mjs",
|
|
64
|
+
"validate:cts-claims": "node scripts/validate-cts-claims.mjs",
|
|
58
65
|
"test": "node --test test/*.test.js"
|
|
59
66
|
},
|
|
60
67
|
"keywords": [
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { lowerInstruction, parseInstruction, planInstruction, validateMutationPlanTarget } from '../src/index.js';
|
|
6
|
+
|
|
7
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const root = resolve(here, '..');
|
|
9
|
+
const ctsRoot = process.env.AEONITE_CTS_ROOT
|
|
10
|
+
? resolve(process.env.AEONITE_CTS_ROOT)
|
|
11
|
+
: resolve(root, '..', '..', 'aeonite-org', 'aeonite-cts', 'cts');
|
|
12
|
+
const manifestPath = readArg('--cts') ?? resolve(ctsRoot, 'sansa', 'v1', 'sansa-instruction-cts.v1.json');
|
|
13
|
+
|
|
14
|
+
const manifest = readJson(manifestPath);
|
|
15
|
+
let pass = 0;
|
|
16
|
+
let fail = 0;
|
|
17
|
+
|
|
18
|
+
console.log('Running experimental SANSA instruction CTS against @altopelago/sansa');
|
|
19
|
+
|
|
20
|
+
for (const suiteRef of manifest.suites ?? []) {
|
|
21
|
+
const suitePath = resolve(dirname(manifestPath), suiteRef.file);
|
|
22
|
+
const suite = readJson(suitePath);
|
|
23
|
+
const namespaces = buildNamespaces(suite.fixtures?.namespaces ?? []);
|
|
24
|
+
console.log(`\n--- Suite: ${suite.title} ---`);
|
|
25
|
+
|
|
26
|
+
for (const test of suite.tests ?? []) {
|
|
27
|
+
const failures = runTest(test, namespaces);
|
|
28
|
+
if (failures.length > 0) {
|
|
29
|
+
fail += 1;
|
|
30
|
+
console.log(`FAIL ${test.id}`);
|
|
31
|
+
for (const failure of failures) console.log(` - ${failure}`);
|
|
32
|
+
} else {
|
|
33
|
+
pass += 1;
|
|
34
|
+
console.log(`PASS ${test.id}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(`\nSummary: pass=${pass} fail=${fail}`);
|
|
40
|
+
process.exit(fail > 0 ? 1 : 0);
|
|
41
|
+
|
|
42
|
+
function runTest(test, namespaces) {
|
|
43
|
+
const failures = [];
|
|
44
|
+
const expected = test.expected ?? {};
|
|
45
|
+
const mode = test.input?.mode ?? 'parse';
|
|
46
|
+
const source = String(test.input?.source ?? '');
|
|
47
|
+
const fixture = test.input?.namespace === undefined ? null : namespaces.get(test.input.namespace);
|
|
48
|
+
if (test.input?.namespace !== undefined && !fixture) {
|
|
49
|
+
failures.push(`unknown namespace fixture: ${test.input.namespace}`);
|
|
50
|
+
return failures;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const result = runMode(mode, source, fixture?.namespace, test.input?.options ?? {});
|
|
54
|
+
|
|
55
|
+
if (mode === 'target') {
|
|
56
|
+
if (!result.ok) {
|
|
57
|
+
compareError(expected, result, failures);
|
|
58
|
+
return failures;
|
|
59
|
+
}
|
|
60
|
+
compareWarnings(expected, result, failures);
|
|
61
|
+
const targetResult = validateMutationPlanTarget(result.plan, test.input?.target ?? 'aeon');
|
|
62
|
+
if (targetResult.ok !== Boolean(expected.ok)) {
|
|
63
|
+
failures.push(`target ok mismatch: expected ${Boolean(expected.ok)}, got ${targetResult.ok}`);
|
|
64
|
+
}
|
|
65
|
+
if (!targetResult.ok) compareError(expected, targetResult, failures);
|
|
66
|
+
if (targetResult.ok) {
|
|
67
|
+
compareArray(expected.targetDiagnostics, (targetResult.diagnostics ?? []).map((diagnostic) => diagnostic.code), 'targetDiagnostics', failures);
|
|
68
|
+
}
|
|
69
|
+
return failures;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (result.ok !== Boolean(expected.ok)) {
|
|
73
|
+
failures.push(`ok mismatch: expected ${Boolean(expected.ok)}, got ${result.ok}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!result.ok) {
|
|
77
|
+
compareError(expected, result, failures);
|
|
78
|
+
return failures;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
compareWarnings(expected, result, failures);
|
|
82
|
+
|
|
83
|
+
if (mode === 'parse') {
|
|
84
|
+
compareField(expected.canonical, result.instruction.canonical, 'canonical', failures);
|
|
85
|
+
compareArray(expected.clauses, result.instruction.clauses, 'clauses', failures);
|
|
86
|
+
compareField(expected.provenanceReason, result.instruction.provenance?.reason, 'provenanceReason', failures);
|
|
87
|
+
compareField(expected.provenanceClaimedAuthor, result.instruction.provenance?.claimedAuthor, 'provenanceClaimedAuthor', failures);
|
|
88
|
+
return failures;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (mode === 'lower') {
|
|
92
|
+
compareLoweredOperations(expected.operations ?? [], result.request, failures);
|
|
93
|
+
compareLoweredPreconditions(expected.preconditions, result.request, failures);
|
|
94
|
+
return failures;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (mode === 'plan') {
|
|
98
|
+
comparePlannedOperations(expected.operations ?? [], result.plan.operations, failures);
|
|
99
|
+
compareArray(expected.preconditions, result.plan.preconditions.map((precondition) => precondition.canonical), 'preconditions', failures);
|
|
100
|
+
compareField(expected.sourceProvenanceType, result.plan.sourceProvenance?.type, 'sourceProvenanceType', failures);
|
|
101
|
+
compareField(expected.sourceProvenanceReason, result.plan.sourceProvenance?.reason, 'sourceProvenanceReason', failures);
|
|
102
|
+
compareField(expected.sourceProvenanceClaimedAuthor, result.plan.sourceProvenance?.claimedAuthor, 'sourceProvenanceClaimedAuthor', failures);
|
|
103
|
+
return failures;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
failures.push(`unsupported mode: ${mode}`);
|
|
107
|
+
return failures;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function runMode(mode, source, namespace, options) {
|
|
111
|
+
if (mode === 'parse') return parseInstruction(source, options.parse ?? options);
|
|
112
|
+
if (mode === 'lower') return lowerInstruction(source, namespace, options);
|
|
113
|
+
if (mode === 'plan' || mode === 'target') return planInstruction(source, namespace, options);
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
errors: [{ code: 'CTS_UNSUPPORTED_MODE', message: `Unsupported instruction CTS mode '${mode}'` }],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function compareError(expected, result, failures) {
|
|
121
|
+
if (typeof expected.error === 'string') {
|
|
122
|
+
const actualCode = result.errors?.[0]?.code ?? null;
|
|
123
|
+
if (actualCode !== expected.error) {
|
|
124
|
+
failures.push(`error mismatch: expected ${expected.error}, got ${actualCode}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (typeof expected.errorPhase === 'string') {
|
|
128
|
+
const actualPhase = result.phase ?? result.errors?.[0]?.phase ?? null;
|
|
129
|
+
if (actualPhase !== expected.errorPhase) {
|
|
130
|
+
failures.push(`errorPhase mismatch: expected ${expected.errorPhase}, got ${actualPhase}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (typeof expected.errorTargetFormat === 'string') {
|
|
134
|
+
const actualTargetFormat = result.errors?.[0]?.targetFormat ?? null;
|
|
135
|
+
if (actualTargetFormat !== expected.errorTargetFormat) {
|
|
136
|
+
failures.push(`errorTargetFormat mismatch: expected ${expected.errorTargetFormat}, got ${actualTargetFormat}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (typeof expected.errorDatatype === 'string') {
|
|
140
|
+
const actualDatatype = result.errors?.[0]?.datatype ?? null;
|
|
141
|
+
if (actualDatatype !== expected.errorDatatype) {
|
|
142
|
+
failures.push(`errorDatatype mismatch: expected ${expected.errorDatatype}, got ${actualDatatype}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (typeof expected.errorValuePath === 'string') {
|
|
146
|
+
const actualValuePath = result.errors?.[0]?.valuePath ?? null;
|
|
147
|
+
if (actualValuePath !== expected.errorValuePath) {
|
|
148
|
+
failures.push(`errorValuePath mismatch: expected ${expected.errorValuePath}, got ${actualValuePath}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function compareWarnings(expected, result, failures) {
|
|
154
|
+
compareArray(expected.warnings, (result.warnings ?? []).map((warning) => warning.code), 'warnings', failures);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function compareLoweredOperations(expected, actual, failures) {
|
|
158
|
+
const operations = Array.isArray(actual)
|
|
159
|
+
? actual
|
|
160
|
+
: Array.isArray(actual?.operations)
|
|
161
|
+
? actual.operations
|
|
162
|
+
: [actual];
|
|
163
|
+
if (expected.length !== operations.length) {
|
|
164
|
+
failures.push(`operations length mismatch: expected ${expected.length}, got ${operations.length}`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
for (let index = 0; index < expected.length; index += 1) {
|
|
168
|
+
const current = operations[index] ?? {};
|
|
169
|
+
compareField(expected[index].op, current.op, `operations[${index}].op`, failures);
|
|
170
|
+
compareField(expected[index].target, current.target ?? current.parent ?? current.container ?? current.source, `operations[${index}].target`, failures);
|
|
171
|
+
compareField(expected[index].parent, current.parent, `operations[${index}].parent`, failures);
|
|
172
|
+
compareField(expected[index].container, current.container, `operations[${index}].container`, failures);
|
|
173
|
+
compareField(expected[index].source, current.source, `operations[${index}].source`, failures);
|
|
174
|
+
compareField(expected[index].name, current.name, `operations[${index}].name`, failures);
|
|
175
|
+
compareField(expected[index].datatype, current.datatype, `operations[${index}].datatype`, failures);
|
|
176
|
+
compareField(expected[index].kind, current.kind, `operations[${index}].kind`, failures);
|
|
177
|
+
comparePlacement(expected[index].placement, current.placement, `operations[${index}].placement`, failures);
|
|
178
|
+
if (Object.hasOwn(expected[index], 'value')) compareJsonLike(expected[index].value, current.value, `operations[${index}].value`, failures);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function compareLoweredPreconditions(expected, actual, failures) {
|
|
183
|
+
if (expected === undefined) return;
|
|
184
|
+
const preconditions = Array.isArray(actual?.preconditions) ? actual.preconditions : [];
|
|
185
|
+
compareJsonLike(expected, preconditions, 'preconditions', failures);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function comparePlannedOperations(expected, actual, failures) {
|
|
189
|
+
if (expected.length !== actual.length) {
|
|
190
|
+
failures.push(`operations length mismatch: expected ${expected.length}, got ${actual.length}`);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
for (let index = 0; index < expected.length; index += 1) {
|
|
194
|
+
const current = actual[index] ?? {};
|
|
195
|
+
compareField(expected[index].op, current.op, `operations[${index}].op`, failures);
|
|
196
|
+
const actualTarget = current.target?.canonicalAddress
|
|
197
|
+
?? current.source?.canonicalAddress
|
|
198
|
+
?? current.parent?.canonicalAddress
|
|
199
|
+
?? current.container?.canonicalAddress;
|
|
200
|
+
compareField(expected[index].target, actualTarget, `operations[${index}].target`, failures);
|
|
201
|
+
compareField(expected[index].parent, current.parent?.canonicalAddress, `operations[${index}].parent`, failures);
|
|
202
|
+
compareField(expected[index].container, current.container?.canonicalAddress, `operations[${index}].container`, failures);
|
|
203
|
+
compareField(expected[index].source, current.source?.canonicalAddress, `operations[${index}].source`, failures);
|
|
204
|
+
compareField(expected[index].name, current.name, `operations[${index}].name`, failures);
|
|
205
|
+
compareField(expected[index].datatype, current.datatype, `operations[${index}].datatype`, failures);
|
|
206
|
+
compareField(expected[index].kind, current.kind, `operations[${index}].kind`, failures);
|
|
207
|
+
const actualPlacement = current.placement === undefined
|
|
208
|
+
? undefined
|
|
209
|
+
: {
|
|
210
|
+
kind: current.placement.kind,
|
|
211
|
+
...(current.placement.anchor?.canonicalAddress === undefined ? {} : { anchor: current.placement.anchor.canonicalAddress }),
|
|
212
|
+
};
|
|
213
|
+
comparePlacement(expected[index].placement, actualPlacement, `operations[${index}].placement`, failures);
|
|
214
|
+
if (Object.hasOwn(expected[index], 'value')) compareJsonLike(expected[index].value, current.value, `operations[${index}].value`, failures);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function comparePlacement(expected, actual, label, failures) {
|
|
219
|
+
if (expected === undefined) return;
|
|
220
|
+
compareJsonLike(expected, actual, label, failures);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function compareJsonLike(expected, actual, label, failures) {
|
|
224
|
+
const expectedJson = JSON.stringify(expected);
|
|
225
|
+
const actualJson = JSON.stringify(actual);
|
|
226
|
+
if (expectedJson !== actualJson) {
|
|
227
|
+
failures.push(`${label} mismatch: expected ${expectedJson}, got ${actualJson}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function compareField(expected, actual, label, failures) {
|
|
232
|
+
if (expected === undefined) return;
|
|
233
|
+
if (!Object.is(expected, actual)) {
|
|
234
|
+
failures.push(`${label} mismatch: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function compareArray(expected, actual, label, failures) {
|
|
239
|
+
if (expected === undefined) return;
|
|
240
|
+
if (expected.length !== actual.length) {
|
|
241
|
+
failures.push(`${label} length mismatch: expected ${expected.length}, got ${actual.length}`);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
for (let index = 0; index < expected.length; index += 1) {
|
|
245
|
+
if (!Object.is(expected[index], actual[index])) {
|
|
246
|
+
failures.push(`${label}[${index}] mismatch: expected ${JSON.stringify(expected[index])}, got ${JSON.stringify(actual[index])}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function buildNamespaces(entries) {
|
|
252
|
+
const output = new Map();
|
|
253
|
+
for (const entry of entries) {
|
|
254
|
+
const rootBinding = structuredClone(entry.root);
|
|
255
|
+
indexBindingTree(rootBinding);
|
|
256
|
+
output.set(entry.id, {
|
|
257
|
+
namespace: {
|
|
258
|
+
root: rootBinding,
|
|
259
|
+
children: (binding) => binding.children ?? [],
|
|
260
|
+
parent: (binding) => binding.parent,
|
|
261
|
+
bindingHandle: (binding) => binding.id ?? binding.address,
|
|
262
|
+
observedState: (binding) => binding.revision,
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
return output;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function indexBindingTree(binding, parent = null) {
|
|
270
|
+
binding.parent = parent;
|
|
271
|
+
for (const child of binding.children ?? []) indexBindingTree(child, binding);
|
|
272
|
+
if (binding.attributeSpace) indexBindingTree(binding.attributeSpace, binding);
|
|
273
|
+
for (const localSpace of Object.values(binding.localSpaces ?? {})) indexBindingTree(localSpace, binding);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function readArg(name) {
|
|
277
|
+
const index = process.argv.indexOf(name);
|
|
278
|
+
if (index < 0) return null;
|
|
279
|
+
return process.argv[index + 1] ? resolve(process.argv[index + 1]) : null;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function readJson(file) {
|
|
283
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
284
|
+
}
|