@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,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const root = resolve(here, '..');
|
|
8
|
+
const ctsRoot = resolve(readArg('--cts-root') ?? process.env.AEONITE_CTS_ROOT ?? resolve(root, '..', '..', 'aeonite-org', 'aeonite-cts', 'cts'));
|
|
9
|
+
const claimsPath = resolve(readArg('--claims') ?? resolve(root, 'conformance', 'cts-claims.json'));
|
|
10
|
+
|
|
11
|
+
const errors = [];
|
|
12
|
+
|
|
13
|
+
if (!existsSync(claimsPath)) {
|
|
14
|
+
fail(`claims file does not exist: ${claimsPath}`);
|
|
15
|
+
}
|
|
16
|
+
if (!existsSync(ctsRoot)) {
|
|
17
|
+
fail(`CTS root does not exist: ${ctsRoot}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const claimsDocument = readJson(claimsPath, 'claims file');
|
|
21
|
+
const snapshotIds = readCtsSnapshotIds(ctsRoot);
|
|
22
|
+
const claims = collectClaims(claimsDocument);
|
|
23
|
+
|
|
24
|
+
if (claimsDocument.claim_format !== 'aeonite.cts-claims.v1') {
|
|
25
|
+
errors.push(`claim_format must be "aeonite.cts-claims.v1"`);
|
|
26
|
+
}
|
|
27
|
+
if (typeof claimsDocument.cts_protocol !== 'string' || claimsDocument.cts_protocol.length === 0) {
|
|
28
|
+
errors.push('cts_protocol must be a non-empty string');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
claims.forEach((claim, index) => validateClaim(claim, index, snapshotIds, errors));
|
|
32
|
+
|
|
33
|
+
if (errors.length > 0) {
|
|
34
|
+
console.error(`CTS claim validation failed: ${errors.length} issue(s)`);
|
|
35
|
+
for (const error of errors) console.error(`- ${error}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log(`CTS claim validation passed: claims=${claims.length} cts_snapshots=${snapshotIds.size}`);
|
|
40
|
+
|
|
41
|
+
function readArg(name) {
|
|
42
|
+
const index = process.argv.indexOf(name);
|
|
43
|
+
if (index < 0) return null;
|
|
44
|
+
return process.argv[index + 1] ?? null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readJson(file, label) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(readFileSync(file, 'utf8'));
|
|
50
|
+
} catch (error) {
|
|
51
|
+
fail(`invalid JSON in ${label}: ${file}: ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function collectClaims(document) {
|
|
56
|
+
if (Array.isArray(document.claims)) return document.claims;
|
|
57
|
+
if (!Array.isArray(document.claim_sets)) {
|
|
58
|
+
errors.push('claims document must contain claims or claim_sets');
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
return document.claim_sets.flatMap((claimSet, claimSetIndex) => {
|
|
62
|
+
if (!claimSet || typeof claimSet !== 'object') {
|
|
63
|
+
errors.push(`claim_sets[${claimSetIndex}] must be an object`);
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
if (typeof claimSet.implementation !== 'string' || claimSet.implementation.length === 0) {
|
|
67
|
+
errors.push(`claim_sets[${claimSetIndex}].implementation must be a non-empty string`);
|
|
68
|
+
}
|
|
69
|
+
if (!Array.isArray(claimSet.claims)) {
|
|
70
|
+
errors.push(`claim_sets[${claimSetIndex}].claims must be a list`);
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
return claimSet.claims.map((claim) => ({ ...claim, __claimSetIndex: claimSetIndex }));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function validateClaim(claim, index, knownSnapshotIds, output) {
|
|
78
|
+
if (!claim || typeof claim !== 'object') {
|
|
79
|
+
output.push(`claims[${index}] must be an object`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (typeof claim.surface !== 'string' || claim.surface.length === 0) {
|
|
83
|
+
output.push(`claims[${index}].surface must be a non-empty string`);
|
|
84
|
+
}
|
|
85
|
+
if (typeof claim.snapshot_id !== 'string' || claim.snapshot_id.length === 0) {
|
|
86
|
+
output.push(`claims[${index}].snapshot_id must be a non-empty string`);
|
|
87
|
+
} else if (!knownSnapshotIds.has(claim.snapshot_id)) {
|
|
88
|
+
output.push(`claims[${index}].snapshot_id is not present in CTS manifests: ${claim.snapshot_id}`);
|
|
89
|
+
}
|
|
90
|
+
if (!['claimed', 'experimental', 'advisory'].includes(claim.status)) {
|
|
91
|
+
output.push(`claims[${index}].status must be one of claimed, experimental, advisory`);
|
|
92
|
+
}
|
|
93
|
+
if (claim.command !== undefined && (typeof claim.command !== 'string' || claim.command.length === 0)) {
|
|
94
|
+
output.push(`claims[${index}].command must be a non-empty string when present`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readCtsSnapshotIds(rootDir) {
|
|
99
|
+
const ids = new Set();
|
|
100
|
+
for (const file of walkJsonFiles(rootDir)) {
|
|
101
|
+
const manifest = readJson(file, 'CTS manifest');
|
|
102
|
+
if (Array.isArray(manifest.suites) && typeof manifest.meta?.snapshot_id === 'string') {
|
|
103
|
+
ids.add(manifest.meta.snapshot_id);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return ids;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function walkJsonFiles(dir) {
|
|
110
|
+
const output = [];
|
|
111
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
112
|
+
const fullPath = join(dir, entry.name);
|
|
113
|
+
if (entry.isDirectory()) output.push(...walkJsonFiles(fullPath));
|
|
114
|
+
else if (entry.isFile() && entry.name.endsWith('.json')) output.push(fullPath);
|
|
115
|
+
}
|
|
116
|
+
return output;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function fail(message) {
|
|
120
|
+
console.error(`CTS claim validation failed: ${message}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|