-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdeep-inspect-schema.test.ts
More file actions
210 lines (195 loc) · 6.39 KB
/
Copy pathdeep-inspect-schema.test.ts
File metadata and controls
210 lines (195 loc) · 6.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import { describe, expect, test } from "bun:test";
import { readdirSync, statSync } from "node:fs";
import { join, relative } from "node:path";
import Ajv, { type ValidateFunction } from "ajv";
import addFormats from "ajv-formats";
const repoRoot = import.meta.dir;
const currentSchemaPath = join(repoRoot, "docs/deep-inspect.schema.json");
const futureSchemaPath = join(repoRoot, "docs/deep-inspect.future.schema.json");
const currentSchema = await Bun.file(currentSchemaPath).json();
const futureSchema = await Bun.file(futureSchemaPath).json();
function makeAjv() {
const ajv = new Ajv({ allErrors: true, strict: true });
addFormats(ajv);
return ajv;
}
function collectDeepInspectArtifacts(dir: string): string[] {
const out: string[] = [];
for (const entry of readdirSync(dir)) {
const path = join(dir, entry);
const stat = statSync(path);
if (stat.isDirectory()) {
out.push(...collectDeepInspectArtifacts(path));
continue;
}
if (/^deep-inspect(?:\.(?:x86|arm64))?\.json$/.test(entry)) {
out.push(path);
}
}
return out.sort();
}
function expectValid(validate: ValidateFunction<unknown>, data: unknown, label: string) {
if (validate(data)) return;
const errors = validate.errors
?.map((error) => `${error.instancePath || "/"} ${error.message}`)
.join("\n");
throw new Error(`${label} failed schema validation:\n${errors}`);
}
function futureShapeExample() {
return {
_meta: {
version: "7.23",
generatedAt: "2026-05-29T19:11:08.121Z",
architecture: "arm64",
apiTransport: "rest",
enrichmentDurationMs: 345371,
crashPathsTested: [],
crashPathsSafe: [],
crashPathsCrashed: [],
completionStats: {
argsTotal: 3,
argsWithCompletion: 1,
argsFailed: 0,
argsTimedOut: 0,
argsBlankOnRetry: 0,
},
mergeStats: {
sharedNodes: 2,
x86OnlyNodes: 0,
arm64OnlyNodes: 1,
completionEnumDriftArgs: 1,
completionPayloadDriftArgs: 0,
typeMismatchNodes: 0,
conflictsTotal: 1,
},
mergePolicy: {
sourcePrecedence: ["arm64", "x86"],
archUniqueNodeSource: "annotate-_source",
completionConflict: "union",
typeMismatch: "fail",
},
packageProvenance: {
strategy: "node-_package",
packages: ["zerotier"],
},
},
zerotier: {
_type: "dir",
_source: "arm64",
_package: "zerotier",
interface: {
_type: "dir",
get: {
_type: "cmd",
disabled: {
_type: "arg",
desc: "yes | no",
_completion: {
"": { style: "none", preference: 96 },
no: { style: "none", preference: 96 },
yes: { style: "none", preference: 96 },
},
},
},
},
},
};
}
describe("deep-inspect JSON Schemas", () => {
const currentAjv = makeAjv();
const currentValidate = currentAjv.compile(currentSchema);
const futureAjv = makeAjv();
const futureValidate = futureAjv.compile(futureSchema);
test("current schema validates every checked-in deep-inspect artifact", async () => {
const artifacts = collectDeepInspectArtifacts(join(repoRoot, "docs"));
expect(artifacts.length).toBeGreaterThan(0);
for (const artifact of artifacts) {
const data = await Bun.file(artifact).json();
expectValid(currentValidate, data, relative(repoRoot, artifact));
}
}, 120_000);
test("future schema remains a superset of current checked-in artifacts", async () => {
const artifacts = collectDeepInspectArtifacts(join(repoRoot, "docs"));
expect(artifacts.length).toBeGreaterThan(0);
for (const artifact of artifacts) {
const data = await Bun.file(artifact).json();
expectValid(futureValidate, data, relative(repoRoot, artifact));
}
}, 120_000);
test("current schema rejects future-only merge/provenance fields", () => {
expect(currentValidate(futureShapeExample())).toBe(false);
});
test("future schema accepts planned merge/source/provenance fields", () => {
expectValid(futureValidate, futureShapeExample(), "future-shape example");
});
test("current and future schemas accept nightly _ab versions", () => {
const abVersions = ["7.25_ab430", "7.25_ab433", "7.25_ab1", "7.25.1_ab99", "7.24_ab0"];
for (const version of abVersions) {
const data = {
_meta: {
version,
generatedAt: "2026-08-13T12:00:00.000Z",
crashPathsTested: [],
crashPathsSafe: [],
crashPathsCrashed: [],
completionStats: {
argsTotal: 1,
argsWithCompletion: 0,
argsFailed: 0,
argsTimedOut: 0,
argsBlankOnRetry: 0,
},
},
ip: { _type: "path" as const },
};
expectValid(currentValidate, data, `current ab ${version}`);
expectValid(futureValidate, data, `future ab ${version}`);
}
// unknown must still pass in both schemas
for (const version of ["unknown", "7.22", "7.22.1", "7.24rc4", "7.24beta2"]) {
const data = {
_meta: {
version,
generatedAt: "2026-08-13T12:00:00.000Z",
crashPathsTested: [],
crashPathsSafe: [],
crashPathsCrashed: [],
completionStats: {
argsTotal: 1,
argsWithCompletion: 0,
argsFailed: 0,
argsTimedOut: 0,
argsBlankOnRetry: 0,
},
},
ip: { _type: "path" as const },
};
expectValid(currentValidate, data, `current ${version}`);
expectValid(futureValidate, data, `future ${version}`);
}
});
test("current and future schemas reject malformed _ab versions", () => {
const bad = ["7.25_ab", "7.25_ab-1", "7.25_abX", "7.25__ab1", "nightly", "_ab430", "7.25ab430"];
for (const version of bad) {
const data = {
_meta: {
version,
generatedAt: "2026-08-13T12:00:00.000Z",
crashPathsTested: [],
crashPathsSafe: [],
crashPathsCrashed: [],
completionStats: {
argsTotal: 1,
argsWithCompletion: 0,
argsFailed: 0,
argsTimedOut: 0,
argsBlankOnRetry: 0,
},
},
ip: { _type: "path" as const },
};
expect(currentValidate(data)).toBe(false);
expect(futureValidate(data)).toBe(false);
}
});
});