@altopelago/sansa 0.9.0 → 0.9.1
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 +117 -0
- package/README.md +107 -4
- package/conformance/README.md +19 -0
- package/conformance/cts-claims.json +53 -0
- package/docs/api-contract.md +536 -10
- package/docs/capabilities.json +172 -3
- 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/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 +122 -0
- package/src/index.d.ts +811 -2
- package/src/index.js +5154 -381
- 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
|
@@ -0,0 +1,476 @@
|
|
|
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 { applyMutationPlan, planMutation, validateMutationPlanTarget } from '../src/index.js';
|
|
6
|
+
import { enforceMutationPolicyForWorkbench } from '../tools/mutate-web/runtime.mjs';
|
|
7
|
+
|
|
8
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const root = resolve(here, '..');
|
|
10
|
+
const ctsRoot = process.env.AEONITE_CTS_ROOT
|
|
11
|
+
? resolve(process.env.AEONITE_CTS_ROOT)
|
|
12
|
+
: resolve(root, '..', '..', 'aeonite-org', 'aeonite-cts', 'cts');
|
|
13
|
+
const manifestPath = readArg('--cts') ?? resolve(ctsRoot, 'sansa', 'v1', 'sansa-mutate-cts.v1.json');
|
|
14
|
+
|
|
15
|
+
const manifest = readJson(manifestPath);
|
|
16
|
+
let pass = 0;
|
|
17
|
+
let fail = 0;
|
|
18
|
+
|
|
19
|
+
console.log('Running experimental SANSA mutate CTS against @altopelago/sansa');
|
|
20
|
+
|
|
21
|
+
for (const suiteRef of manifest.suites ?? []) {
|
|
22
|
+
const suitePath = resolve(dirname(manifestPath), suiteRef.file);
|
|
23
|
+
const suite = readJson(suitePath);
|
|
24
|
+
console.log(`\n--- Suite: ${suite.title} ---`);
|
|
25
|
+
|
|
26
|
+
for (const test of suite.tests ?? []) {
|
|
27
|
+
const namespaces = buildNamespaces(suite.fixtures?.namespaces ?? []);
|
|
28
|
+
const failures = runTest(test, namespaces);
|
|
29
|
+
if (failures.length > 0) {
|
|
30
|
+
fail += 1;
|
|
31
|
+
console.log(`FAIL ${test.id}`);
|
|
32
|
+
for (const failure of failures) console.log(` - ${failure}`);
|
|
33
|
+
} else {
|
|
34
|
+
pass += 1;
|
|
35
|
+
console.log(`PASS ${test.id}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log(`\nSummary: pass=${pass} fail=${fail}`);
|
|
41
|
+
process.exit(fail > 0 ? 1 : 0);
|
|
42
|
+
|
|
43
|
+
function runTest(test, namespaces) {
|
|
44
|
+
const failures = [];
|
|
45
|
+
const expected = test.expected ?? {};
|
|
46
|
+
const fixture = namespaces.get(test.input?.namespace);
|
|
47
|
+
if (!fixture) {
|
|
48
|
+
failures.push(`unknown namespace fixture: ${test.input?.namespace ?? null}`);
|
|
49
|
+
return failures;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const operations = Array.isArray(test.input?.operations)
|
|
53
|
+
? test.input.operations
|
|
54
|
+
: [test.input?.operation];
|
|
55
|
+
const request = test.input?.request !== undefined
|
|
56
|
+
? test.input.request
|
|
57
|
+
: Array.isArray(test.input?.preconditions)
|
|
58
|
+
? {
|
|
59
|
+
operations,
|
|
60
|
+
preconditions: test.input.preconditions,
|
|
61
|
+
...(test.input.provenance === undefined ? {} : { provenance: test.input.provenance }),
|
|
62
|
+
}
|
|
63
|
+
: operations.length === 1
|
|
64
|
+
? operations[0]
|
|
65
|
+
: operations;
|
|
66
|
+
const planOptions = test.input?.planOptions ?? test.input?.options ?? {};
|
|
67
|
+
const applyOptions = test.input?.applyOptions ?? test.input?.options ?? {};
|
|
68
|
+
const planResult = planMutation(request, fixture.namespace, planOptions);
|
|
69
|
+
const mode = test.input?.mode ?? 'plan';
|
|
70
|
+
const target = test.input?.target;
|
|
71
|
+
if (mode === 'policy' && test.input?.policy === undefined) {
|
|
72
|
+
failures.push('policy mode requires input.policy');
|
|
73
|
+
return failures;
|
|
74
|
+
}
|
|
75
|
+
const result = target && planResult.ok
|
|
76
|
+
? validateMutationPlanTarget(planResult.plan, target)
|
|
77
|
+
: mode === 'policy' && planResult.ok
|
|
78
|
+
? enforceMutationPolicyForWorkbench(planResult.plan, fixture.namespace, JSON.stringify(test.input?.policy ?? {}))
|
|
79
|
+
: mode === 'apply' && planResult.ok
|
|
80
|
+
? applyPlannedMutation(test, planResult.plan, fixture, applyOptions)
|
|
81
|
+
: planResult;
|
|
82
|
+
|
|
83
|
+
if (result.ok !== Boolean(expected.ok)) {
|
|
84
|
+
failures.push(`ok mismatch: expected ${Boolean(expected.ok)}, got ${result.ok}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!result.ok) {
|
|
88
|
+
const expectedCode = expected.error;
|
|
89
|
+
if (typeof expectedCode === 'string') {
|
|
90
|
+
const actualCode = result.errors?.[0]?.code ?? null;
|
|
91
|
+
if (actualCode !== expectedCode) {
|
|
92
|
+
failures.push(`error mismatch: expected ${expectedCode}, got ${actualCode}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (Number.isInteger(expected.operationIndex)) {
|
|
96
|
+
const actualIndex = result.errors?.[0]?.operationIndex;
|
|
97
|
+
if (actualIndex !== expected.operationIndex) {
|
|
98
|
+
failures.push(`operationIndex mismatch: expected ${expected.operationIndex}, got ${actualIndex ?? null}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (Number.isInteger(expected.ruleIndex)) {
|
|
102
|
+
const actualIndex = result.errors?.[0]?.ruleIndex;
|
|
103
|
+
if (actualIndex !== expected.ruleIndex) {
|
|
104
|
+
failures.push(`ruleIndex mismatch: expected ${expected.ruleIndex}, got ${actualIndex ?? null}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (typeof expected.errorPolicyField === 'string') {
|
|
108
|
+
const actualPolicyField = result.errors?.[0]?.policyField ?? null;
|
|
109
|
+
if (actualPolicyField !== expected.errorPolicyField) {
|
|
110
|
+
failures.push(`errorPolicyField mismatch: expected ${expected.errorPolicyField}, got ${actualPolicyField}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (typeof expected.errorPolicyScope === 'string') {
|
|
114
|
+
const actualPolicyScope = result.errors?.[0]?.policyScope ?? null;
|
|
115
|
+
if (actualPolicyScope !== expected.errorPolicyScope) {
|
|
116
|
+
failures.push(`errorPolicyScope mismatch: expected ${expected.errorPolicyScope}, got ${actualPolicyScope}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (typeof expected.errorPolicyAddress === 'string') {
|
|
120
|
+
const actualPolicyAddress = result.errors?.[0]?.policyAddress ?? null;
|
|
121
|
+
if (actualPolicyAddress !== expected.errorPolicyAddress) {
|
|
122
|
+
failures.push(`errorPolicyAddress mismatch: expected ${expected.errorPolicyAddress}, got ${actualPolicyAddress}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (typeof expected.errorOperationField === 'string') {
|
|
126
|
+
const actualOperationField = result.errors?.[0]?.operationField ?? null;
|
|
127
|
+
if (actualOperationField !== expected.errorOperationField) {
|
|
128
|
+
failures.push(`errorOperationField mismatch: expected ${expected.errorOperationField}, got ${actualOperationField}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (typeof expected.errorRequestField === 'string') {
|
|
132
|
+
const actualRequestField = result.errors?.[0]?.requestField ?? null;
|
|
133
|
+
if (actualRequestField !== expected.errorRequestField) {
|
|
134
|
+
failures.push(`errorRequestField mismatch: expected ${expected.errorRequestField}, got ${actualRequestField}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (typeof expected.errorPhase === 'string') {
|
|
138
|
+
const actualPhase = result.errors?.[0]?.phase ?? null;
|
|
139
|
+
if (actualPhase !== expected.errorPhase) {
|
|
140
|
+
failures.push(`errorPhase mismatch: expected ${expected.errorPhase}, got ${actualPhase}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (typeof expected.errorTargetFormat === 'string') {
|
|
144
|
+
const actualTargetFormat = result.errors?.[0]?.targetFormat ?? null;
|
|
145
|
+
if (actualTargetFormat !== expected.errorTargetFormat) {
|
|
146
|
+
failures.push(`errorTargetFormat mismatch: expected ${expected.errorTargetFormat}, got ${actualTargetFormat}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (typeof expected.errorDatatype === 'string') {
|
|
150
|
+
const actualDatatype = result.errors?.[0]?.datatype ?? null;
|
|
151
|
+
if (actualDatatype !== expected.errorDatatype) {
|
|
152
|
+
failures.push(`errorDatatype mismatch: expected ${expected.errorDatatype}, got ${actualDatatype}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (typeof expected.errorValuePath === 'string') {
|
|
156
|
+
const actualValuePath = result.errors?.[0]?.valuePath ?? null;
|
|
157
|
+
if (actualValuePath !== expected.errorValuePath) {
|
|
158
|
+
failures.push(`errorValuePath mismatch: expected ${expected.errorValuePath}, got ${actualValuePath}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (typeof expected.errorBudget === 'string') {
|
|
162
|
+
const actualBudget = result.errors?.[0]?.budget ?? null;
|
|
163
|
+
if (actualBudget !== expected.errorBudget) {
|
|
164
|
+
failures.push(`errorBudget mismatch: expected ${expected.errorBudget}, got ${actualBudget}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (Number.isSafeInteger(expected.errorLimit)) {
|
|
168
|
+
const actualLimit = result.errors?.[0]?.limit ?? null;
|
|
169
|
+
if (actualLimit !== expected.errorLimit) {
|
|
170
|
+
failures.push(`errorLimit mismatch: expected ${expected.errorLimit}, got ${actualLimit}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (Number.isSafeInteger(expected.errorObserved)) {
|
|
174
|
+
const actualObserved = result.errors?.[0]?.observed ?? null;
|
|
175
|
+
if (actualObserved !== expected.errorObserved) {
|
|
176
|
+
failures.push(`errorObserved mismatch: expected ${expected.errorObserved}, got ${actualObserved}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
compareApplyResultExpectations(expected, result, failures);
|
|
180
|
+
compareValuesByAddress(expected.valuesByAddress ?? {}, fixture.byAddress, failures);
|
|
181
|
+
compareChildrenByAddress(expected.childrenByAddress ?? {}, fixture.byAddress, 'name', failures);
|
|
182
|
+
compareChildrenByAddress(expected.childrenValuesByAddress ?? {}, fixture.byAddress, 'value', failures);
|
|
183
|
+
return failures;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (target) {
|
|
187
|
+
if (Array.isArray(expected.targetDiagnostics)) {
|
|
188
|
+
compareArray(
|
|
189
|
+
expected.targetDiagnostics,
|
|
190
|
+
(result.diagnostics ?? []).map((diagnostic) => diagnostic.code),
|
|
191
|
+
'targetDiagnostics',
|
|
192
|
+
failures,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return failures;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (mode === 'plan') {
|
|
199
|
+
comparePlannedOperations(expected.operations ?? [], result.plan.operations, failures);
|
|
200
|
+
if (Object.hasOwn(expected, 'sourceProvenance')) {
|
|
201
|
+
compareJsonLike(expected.sourceProvenance, result.plan.sourceProvenance, 'sourceProvenance', failures);
|
|
202
|
+
}
|
|
203
|
+
if (Array.isArray(expected.portabilityWarnings)) {
|
|
204
|
+
compareArray(
|
|
205
|
+
expected.portabilityWarnings,
|
|
206
|
+
(result.plan.portabilityWarnings ?? []).map((warning) => warning.code),
|
|
207
|
+
'portabilityWarnings',
|
|
208
|
+
failures,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
if (Array.isArray(expected.preconditions)) {
|
|
212
|
+
compareArray(
|
|
213
|
+
expected.preconditions,
|
|
214
|
+
result.plan.preconditions.map((entry) => entry.canonical),
|
|
215
|
+
'preconditions',
|
|
216
|
+
failures,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
return failures;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
compareApplyResultExpectations(expected, result, failures);
|
|
223
|
+
compareValuesByAddress(expected.valuesByAddress ?? {}, fixture.byAddress, failures);
|
|
224
|
+
compareChildrenByAddress(expected.childrenByAddress ?? {}, fixture.byAddress, 'name', failures);
|
|
225
|
+
compareChildrenByAddress(expected.childrenValuesByAddress ?? {}, fixture.byAddress, 'value', failures);
|
|
226
|
+
return failures;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function applyPlannedMutation(test, plan, fixture, options) {
|
|
230
|
+
applyDrift(test.input?.driftBeforeApply, fixture);
|
|
231
|
+
fixture.control.hookFailureBeforeApply = test.input?.hookFailureBeforeApply ?? null;
|
|
232
|
+
try {
|
|
233
|
+
return applyMutationPlan(plan, fixture.namespace, options);
|
|
234
|
+
} finally {
|
|
235
|
+
fixture.control.hookFailureBeforeApply = null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function compareApplyResultExpectations(expected, result, failures) {
|
|
240
|
+
if (Array.isArray(expected.operationStatuses)) {
|
|
241
|
+
compareArray(
|
|
242
|
+
expected.operationStatuses,
|
|
243
|
+
(result.operationResults ?? []).map((entry) => entry.status),
|
|
244
|
+
'operationStatuses',
|
|
245
|
+
failures,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (Array.isArray(expected.operationReports)) {
|
|
249
|
+
compareOperationReports(expected.operationReports, result.operationResults ?? [], failures);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function comparePlannedOperations(expected, actual, failures) {
|
|
254
|
+
if (expected.length !== actual.length) {
|
|
255
|
+
failures.push(`operations length mismatch: expected ${expected.length}, got ${actual.length}`);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
for (let index = 0; index < expected.length; index += 1) {
|
|
259
|
+
if (expected[index].op !== actual[index].op) {
|
|
260
|
+
failures.push(`operations[${index}].op mismatch: expected ${expected[index].op}, got ${actual[index].op}`);
|
|
261
|
+
}
|
|
262
|
+
if (typeof expected[index].target === 'string') {
|
|
263
|
+
const actualTarget = actual[index].target?.canonicalAddress
|
|
264
|
+
?? actual[index].source?.canonicalAddress
|
|
265
|
+
?? actual[index].parent?.canonicalAddress
|
|
266
|
+
?? actual[index].container?.canonicalAddress;
|
|
267
|
+
if (expected[index].target !== actualTarget) {
|
|
268
|
+
failures.push(`operations[${index}].target mismatch: expected ${expected[index].target}, got ${actualTarget ?? null}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (Object.hasOwn(expected[index], 'datatype') && expected[index].datatype !== actual[index].datatype) {
|
|
272
|
+
failures.push(`operations[${index}].datatype mismatch: expected ${expected[index].datatype}, got ${actual[index].datatype ?? null}`);
|
|
273
|
+
}
|
|
274
|
+
if (Object.hasOwn(expected[index], 'kind') && expected[index].kind !== actual[index].kind) {
|
|
275
|
+
failures.push(`operations[${index}].kind mismatch: expected ${expected[index].kind}, got ${actual[index].kind ?? null}`);
|
|
276
|
+
}
|
|
277
|
+
if (Object.hasOwn(expected[index], 'provenance')) {
|
|
278
|
+
compareJsonLike(expected[index].provenance, actual[index].provenance, `operations[${index}].provenance`, failures);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function compareValuesByAddress(expected, byAddress, failures) {
|
|
284
|
+
for (const [address, value] of Object.entries(expected)) {
|
|
285
|
+
const binding = byAddress.get(address);
|
|
286
|
+
if (!binding) {
|
|
287
|
+
failures.push(`valuesByAddress missing binding: ${address}`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (!Object.is(binding.value, value)) {
|
|
291
|
+
failures.push(`valuesByAddress[${address}] mismatch: expected ${JSON.stringify(value)}, got ${JSON.stringify(binding.value)}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function compareChildrenByAddress(expected, byAddress, field, failures) {
|
|
297
|
+
for (const [address, values] of Object.entries(expected)) {
|
|
298
|
+
const binding = byAddress.get(address);
|
|
299
|
+
if (!binding) {
|
|
300
|
+
failures.push(`childrenByAddress missing binding: ${address}`);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
compareArray(values, (binding.children ?? []).map((child) => child[field]), `${field} children at ${address}`, failures);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function compareOperationReports(expected, actual, failures) {
|
|
308
|
+
if (expected.length !== actual.length) {
|
|
309
|
+
failures.push(`operationReports length mismatch: expected ${expected.length}, got ${actual.length}`);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
for (let index = 0; index < expected.length; index += 1) {
|
|
313
|
+
for (const [field, expectedValue] of Object.entries(expected[index])) {
|
|
314
|
+
const actualValue = actual[index]?.[field];
|
|
315
|
+
if (!Object.is(expectedValue, actualValue)) {
|
|
316
|
+
failures.push(`operationReports[${index}].${field} mismatch: expected ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actualValue)}`);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function compareJsonLike(expected, actual, label, failures) {
|
|
323
|
+
const expectedJson = JSON.stringify(expected);
|
|
324
|
+
const actualJson = JSON.stringify(actual);
|
|
325
|
+
if (expectedJson !== actualJson) {
|
|
326
|
+
failures.push(`${label} mismatch: expected ${expectedJson}, got ${actualJson}`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function buildNamespaces(entries) {
|
|
331
|
+
const output = new Map();
|
|
332
|
+
for (const entry of entries) {
|
|
333
|
+
const rootBinding = structuredClone(entry.root);
|
|
334
|
+
const byAddress = new Map();
|
|
335
|
+
indexBindingTree(rootBinding, byAddress);
|
|
336
|
+
const control = { hookFailureBeforeApply: null };
|
|
337
|
+
output.set(entry.id, {
|
|
338
|
+
byAddress,
|
|
339
|
+
control,
|
|
340
|
+
namespace: {
|
|
341
|
+
root: rootBinding,
|
|
342
|
+
children: (binding) => binding.children ?? [],
|
|
343
|
+
parent: (binding) => binding.parent,
|
|
344
|
+
bindingHandle: (binding) => binding.id ?? binding.address,
|
|
345
|
+
observedState: (binding) => binding.revision,
|
|
346
|
+
...(entry.supportsMutation === true
|
|
347
|
+
? { mutate: mutationAdapter(entry, byAddress, control) }
|
|
348
|
+
: {}),
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return output;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function mutationAdapter(entry, byAddress, control) {
|
|
356
|
+
return {
|
|
357
|
+
...(entry.supportsCreate === undefined ? {} : { supportsCreate: entry.supportsCreate }),
|
|
358
|
+
...(entry.supportsReplace === undefined ? {} : { supportsReplace: entry.supportsReplace }),
|
|
359
|
+
...(entry.supportsRemove === undefined ? {} : { supportsRemove: entry.supportsRemove }),
|
|
360
|
+
...(entry.supportsOrderedInsert === undefined ? {} : { supportsOrderedInsert: entry.supportsOrderedInsert }),
|
|
361
|
+
...(entry.supportsMove === undefined ? {} : { supportsMove: entry.supportsMove }),
|
|
362
|
+
...(entry.supportsStableBindingIdentity === undefined ? {} : { supportsStableBindingIdentity: entry.supportsStableBindingIdentity }),
|
|
363
|
+
supportsAtomicApply: entry.supportsAtomicApply === true,
|
|
364
|
+
sameBinding: (left, right) => left === right,
|
|
365
|
+
create(parent, name, value) {
|
|
366
|
+
const childAddress = `${parent.address}.${name}`;
|
|
367
|
+
const child = {
|
|
368
|
+
id: childAddress,
|
|
369
|
+
name,
|
|
370
|
+
address: childAddress,
|
|
371
|
+
representationKind: typeof value,
|
|
372
|
+
value,
|
|
373
|
+
parent,
|
|
374
|
+
children: [],
|
|
375
|
+
};
|
|
376
|
+
parent.children = [...(parent.children ?? []), child];
|
|
377
|
+
byAddress.set(child.address, child);
|
|
378
|
+
return { binding: child, resultingAddress: child.address };
|
|
379
|
+
},
|
|
380
|
+
replace(target, value) {
|
|
381
|
+
const failure = hookFailure(control, 'replace', target.address);
|
|
382
|
+
if (failure) return failure;
|
|
383
|
+
target.value = value;
|
|
384
|
+
target.revision = (target.revision ?? 0) + 1;
|
|
385
|
+
return { binding: target, resultingAddress: target.address };
|
|
386
|
+
},
|
|
387
|
+
remove(target) {
|
|
388
|
+
target.parent.children = target.parent.children.filter((child) => child !== target);
|
|
389
|
+
byAddress.delete(target.address);
|
|
390
|
+
return { binding: target };
|
|
391
|
+
},
|
|
392
|
+
insert(container, placement, value) {
|
|
393
|
+
const child = {
|
|
394
|
+
id: `${container.address}:inserted:${String(value)}`,
|
|
395
|
+
address: `${container.address}[inserted]`,
|
|
396
|
+
representationKind: typeof value,
|
|
397
|
+
value,
|
|
398
|
+
parent: container,
|
|
399
|
+
children: [],
|
|
400
|
+
};
|
|
401
|
+
const index = placementIndex(container, placement);
|
|
402
|
+
container.children = [...(container.children ?? [])];
|
|
403
|
+
container.children.splice(index, 0, child);
|
|
404
|
+
byAddress.set(child.address, child);
|
|
405
|
+
return { binding: child, resultingAddress: child.address };
|
|
406
|
+
},
|
|
407
|
+
move(source, container, placement) {
|
|
408
|
+
container.children = (container.children ?? []).filter((child) => child !== source);
|
|
409
|
+
const index = placementIndex(container, placement);
|
|
410
|
+
container.children.splice(index, 0, source);
|
|
411
|
+
return { binding: source, resultingAddress: source.address };
|
|
412
|
+
},
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function hookFailure(control, op, address) {
|
|
417
|
+
const failure = control.hookFailureBeforeApply;
|
|
418
|
+
if (!failure || failure.op !== op || failure.address !== address) return null;
|
|
419
|
+
if (failure.throw === true) {
|
|
420
|
+
throw new Error(failure.message ?? `CTS hook failure for ${op} at ${address}`);
|
|
421
|
+
}
|
|
422
|
+
return { ok: false, message: failure.message ?? `CTS hook failure for ${op} at ${address}` };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function placementIndex(container, placement) {
|
|
426
|
+
if (placement.kind === 'first') return 0;
|
|
427
|
+
if (placement.kind === 'last') return (container.children ?? []).length;
|
|
428
|
+
const anchorIndex = (container.children ?? []).indexOf(placement.anchor.binding);
|
|
429
|
+
return anchorIndex + (placement.kind === 'after' ? 1 : 0);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function applyDrift(drift, fixture) {
|
|
433
|
+
if (!drift?.replaceBindingAtAddress) return;
|
|
434
|
+
const target = fixture.byAddress.get(drift.replaceBindingAtAddress);
|
|
435
|
+
if (!target || !target.parent) return;
|
|
436
|
+
if (Object.hasOwn(drift, 'value')) {
|
|
437
|
+
target.value = drift.value;
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
const replacement = structuredClone(drift.with);
|
|
441
|
+
replacement.parent = target.parent;
|
|
442
|
+
const siblings = target.parent.children ?? [];
|
|
443
|
+
const index = siblings.indexOf(target);
|
|
444
|
+
if (index >= 0) siblings[index] = replacement;
|
|
445
|
+
fixture.byAddress.set(replacement.address, replacement);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function indexBindingTree(binding, output, parent = null) {
|
|
449
|
+
binding.parent = parent;
|
|
450
|
+
output.set(binding.address, binding);
|
|
451
|
+
for (const child of binding.children ?? []) indexBindingTree(child, output, binding);
|
|
452
|
+
if (binding.attributeSpace) indexBindingTree(binding.attributeSpace, output, binding);
|
|
453
|
+
for (const localSpace of Object.values(binding.localSpaces ?? {})) indexBindingTree(localSpace, output, binding);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function compareArray(expected, actual, label, failures) {
|
|
457
|
+
if (expected.length !== actual.length) {
|
|
458
|
+
failures.push(`${label} length mismatch: expected ${expected.length}, got ${actual.length}`);
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
for (let index = 0; index < expected.length; index += 1) {
|
|
462
|
+
if (!Object.is(expected[index], actual[index])) {
|
|
463
|
+
failures.push(`${label}[${index}] mismatch: expected ${JSON.stringify(expected[index])}, got ${JSON.stringify(actual[index])}`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function readArg(name) {
|
|
469
|
+
const index = process.argv.indexOf(name);
|
|
470
|
+
if (index < 0) return null;
|
|
471
|
+
return process.argv[index + 1] ? resolve(process.argv[index + 1]) : null;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function readJson(file) {
|
|
475
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
476
|
+
}
|
package/scripts/cts-resolve.mjs
CHANGED
|
@@ -65,6 +65,9 @@ function runTest(test, namespaces) {
|
|
|
65
65
|
if (test.input?.failOnParentFromEffectiveRoot === true) {
|
|
66
66
|
options.failOnParentFromEffectiveRoot = true;
|
|
67
67
|
}
|
|
68
|
+
if (Number.isSafeInteger(test.input?.maxBindings)) {
|
|
69
|
+
options.maxBindings = test.input.maxBindings;
|
|
70
|
+
}
|
|
68
71
|
|
|
69
72
|
const result = resolveAddress(source, fixture.namespace, options);
|
|
70
73
|
|
|
@@ -86,6 +89,12 @@ function runTest(test, namespaces) {
|
|
|
86
89
|
failures.push(`selectorIndex mismatch: expected ${expected.selectorIndex}, got ${actualSelectorIndex ?? null}`);
|
|
87
90
|
}
|
|
88
91
|
}
|
|
92
|
+
if (Number.isSafeInteger(expected.limit) && result.errors?.[0]?.limit !== expected.limit) {
|
|
93
|
+
failures.push(`limit mismatch: expected ${expected.limit}, got ${result.errors?.[0]?.limit ?? null}`);
|
|
94
|
+
}
|
|
95
|
+
if (Number.isSafeInteger(expected.observed) && result.errors?.[0]?.observed !== expected.observed) {
|
|
96
|
+
failures.push(`observed mismatch: expected ${expected.observed}, got ${result.errors?.[0]?.observed ?? null}`);
|
|
97
|
+
}
|
|
89
98
|
return failures;
|
|
90
99
|
}
|
|
91
100
|
|