@plasius/gpu-shader 0.1.1 → 0.1.3
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/README.md +50 -2
- package/dist/cli.cjs +539 -143
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +539 -143
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +738 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +737 -218
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +329 -86
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +329 -86
- package/dist/node.js.map +1 -1
- package/dist/testing.cjs +436 -115
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +436 -115
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
package/dist/testing.cjs
CHANGED
|
@@ -53,63 +53,267 @@ Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
|
|
|
53
53
|
var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
|
|
54
54
|
|
|
55
55
|
// src/canonical-json.ts
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
var GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
|
|
57
|
+
maximumDepth: 64,
|
|
58
|
+
maximumNodes: 262144,
|
|
59
|
+
maximumProperties: 131072,
|
|
60
|
+
maximumElements: 131072,
|
|
61
|
+
maximumArrayLength: 1e5,
|
|
62
|
+
maximumStringBytes: 1024 * 1024,
|
|
63
|
+
maximumAggregateStringBytes: 8 * 1024 * 1024,
|
|
64
|
+
maximumAggregateBytes: 16 * 1024 * 1024,
|
|
65
|
+
maximumInputBytes: 16 * 1024 * 1024
|
|
66
|
+
});
|
|
67
|
+
var QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
|
|
68
|
+
maximumDepth: 96,
|
|
69
|
+
maximumNodes: 4e6,
|
|
70
|
+
maximumProperties: 2e6,
|
|
71
|
+
maximumElements: 2e6,
|
|
72
|
+
maximumArrayLength: 25e4,
|
|
73
|
+
maximumStringBytes: 4 * 1024 * 1024,
|
|
74
|
+
maximumAggregateStringBytes: 128 * 1024 * 1024,
|
|
75
|
+
maximumAggregateBytes: 256 * 1024 * 1024,
|
|
76
|
+
maximumInputBytes: 256 * 1024 * 1024
|
|
77
|
+
});
|
|
78
|
+
var FAILURE_MESSAGES = Object.freeze({
|
|
79
|
+
"aggregate-bytes": "GPU contract snapshot exceeds the aggregate byte limit.",
|
|
80
|
+
"aggregate-string-bytes": "GPU contract snapshot exceeds the aggregate string byte limit.",
|
|
81
|
+
"array-length": "GPU contract snapshot exceeds the single-array element limit.",
|
|
82
|
+
cycle: "GPU contract snapshot contains a circular reference.",
|
|
83
|
+
depth: "GPU contract snapshot exceeds the nesting-depth limit.",
|
|
84
|
+
elements: "GPU contract snapshot exceeds the total element limit.",
|
|
85
|
+
inspection: "GPU contract snapshot rejected unsafe object inspection.",
|
|
86
|
+
nodes: "GPU contract snapshot exceeds the total node limit.",
|
|
87
|
+
"non-finite": "GPU contract snapshot contains a non-finite number.",
|
|
88
|
+
properties: "GPU contract snapshot exceeds the total property limit.",
|
|
89
|
+
shape: "GPU contract snapshot requires plain JSON objects with own enumerable data properties and dense arrays.",
|
|
90
|
+
"string-bytes": "GPU contract snapshot exceeds the individual string byte limit.",
|
|
91
|
+
unicode: "GPU contract snapshot contains an invalid Unicode scalar string or unpaired UTF-16 surrogate.",
|
|
92
|
+
value: "GPU contract snapshot contains undefined or another value that JSON cannot represent."
|
|
93
|
+
});
|
|
94
|
+
var GpuContractSnapshotError = class extends TypeError {
|
|
95
|
+
code;
|
|
96
|
+
constructor(code) {
|
|
97
|
+
super(FAILURE_MESSAGES[code]);
|
|
98
|
+
this.name = "GpuContractSnapshotError";
|
|
99
|
+
this.code = code;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
var TYPED_ARRAY_PROTOTYPE = Reflect.getPrototypeOf(Uint8Array.prototype);
|
|
103
|
+
var TYPED_ARRAY_BYTE_LENGTH = Reflect.getOwnPropertyDescriptor(
|
|
104
|
+
TYPED_ARRAY_PROTOTYPE,
|
|
105
|
+
"byteLength"
|
|
106
|
+
)?.get;
|
|
107
|
+
var TYPED_ARRAY_TAG = Reflect.getOwnPropertyDescriptor(
|
|
108
|
+
TYPED_ARRAY_PROTOTYPE,
|
|
109
|
+
Symbol.toStringTag
|
|
110
|
+
)?.get;
|
|
111
|
+
var UINT8_ARRAY_SET = Uint8Array.prototype.set;
|
|
112
|
+
function snapshotUint8Array(value, maximumBytes) {
|
|
113
|
+
if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
|
|
114
|
+
throw new TypeError("GPU contract byte limit must be a non-negative safe integer.");
|
|
115
|
+
}
|
|
116
|
+
let byteLength;
|
|
117
|
+
let tag;
|
|
118
|
+
try {
|
|
119
|
+
if (!TYPED_ARRAY_BYTE_LENGTH || !TYPED_ARRAY_TAG) throw new TypeError();
|
|
120
|
+
byteLength = Reflect.apply(TYPED_ARRAY_BYTE_LENGTH, value, []);
|
|
121
|
+
tag = Reflect.apply(TYPED_ARRAY_TAG, value, []);
|
|
122
|
+
} catch {
|
|
123
|
+
throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
|
|
124
|
+
}
|
|
125
|
+
if (tag !== "Uint8Array" || !Number.isSafeInteger(byteLength) || byteLength > maximumBytes) {
|
|
126
|
+
throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
|
|
127
|
+
}
|
|
128
|
+
const output = new Uint8Array(byteLength);
|
|
129
|
+
try {
|
|
130
|
+
Reflect.apply(UINT8_ARRAY_SET, output, [value]);
|
|
131
|
+
} catch {
|
|
132
|
+
throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
|
|
133
|
+
}
|
|
134
|
+
return output;
|
|
135
|
+
}
|
|
136
|
+
function fail(reason) {
|
|
137
|
+
throw new GpuContractSnapshotError(reason);
|
|
59
138
|
}
|
|
60
|
-
function
|
|
139
|
+
function inspected(operation) {
|
|
140
|
+
try {
|
|
141
|
+
return operation();
|
|
142
|
+
} catch {
|
|
143
|
+
return fail("inspection");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function assertLimit(value, maximum, reason) {
|
|
147
|
+
if (!Number.isSafeInteger(value) || value > maximum) fail(reason);
|
|
148
|
+
}
|
|
149
|
+
function quotedJsonByteLength(value, maximum) {
|
|
150
|
+
let raw = 0;
|
|
151
|
+
let quoted = 2;
|
|
61
152
|
for (let index = 0; index < value.length; index += 1) {
|
|
62
153
|
const code = value.charCodeAt(index);
|
|
63
|
-
if (code
|
|
154
|
+
if (code <= 127) {
|
|
155
|
+
raw += 1;
|
|
156
|
+
if (code <= 31) quoted += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
|
|
157
|
+
else quoted += code === 34 || code === 92 ? 2 : 1;
|
|
158
|
+
} else if (code <= 2047) {
|
|
159
|
+
raw += 2;
|
|
160
|
+
quoted += 2;
|
|
161
|
+
} else if (code >= 55296 && code <= 56319) {
|
|
64
162
|
const next = value.charCodeAt(index + 1);
|
|
65
|
-
if (!(next >= 56320 && next <= 57343))
|
|
163
|
+
if (!(next >= 56320 && next <= 57343)) fail("unicode");
|
|
164
|
+
raw += 4;
|
|
165
|
+
quoted += 4;
|
|
66
166
|
index += 1;
|
|
67
|
-
} else if (code >= 56320 && code <= 57343)
|
|
167
|
+
} else if (code >= 56320 && code <= 57343) fail("unicode");
|
|
168
|
+
else {
|
|
169
|
+
raw += 3;
|
|
170
|
+
quoted += 3;
|
|
171
|
+
}
|
|
172
|
+
if (raw > maximum) fail("string-bytes");
|
|
68
173
|
}
|
|
174
|
+
return { raw, quoted };
|
|
69
175
|
}
|
|
70
|
-
function
|
|
176
|
+
function assertLimits(limits) {
|
|
177
|
+
for (const value of Object.values(limits)) {
|
|
178
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new TypeError("GPU contract snapshot limits must be positive safe integers.");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function snapshotGpuContract(value, limits = GPU_CONTRACT_SNAPSHOT_LIMITS) {
|
|
182
|
+
assertLimits(limits);
|
|
71
183
|
const ancestors = /* @__PURE__ */ new Set();
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
184
|
+
let nodes = 0;
|
|
185
|
+
let properties = 0;
|
|
186
|
+
let elements = 0;
|
|
187
|
+
let aggregateStringBytes = 0;
|
|
188
|
+
let aggregateBytes = 0;
|
|
189
|
+
const addAggregate = (bytes) => {
|
|
190
|
+
aggregateBytes += bytes;
|
|
191
|
+
assertLimit(aggregateBytes, limits.maximumAggregateBytes, "aggregate-bytes");
|
|
192
|
+
};
|
|
193
|
+
const addString = (text2) => {
|
|
194
|
+
const measured = quotedJsonByteLength(text2, limits.maximumStringBytes);
|
|
195
|
+
aggregateStringBytes += measured.raw;
|
|
196
|
+
assertLimit(aggregateStringBytes, limits.maximumAggregateStringBytes, "aggregate-string-bytes");
|
|
197
|
+
return measured.quoted;
|
|
198
|
+
};
|
|
199
|
+
const visit = (current, depth) => {
|
|
200
|
+
if (depth > limits.maximumDepth) fail("depth");
|
|
201
|
+
nodes += 1;
|
|
202
|
+
assertLimit(nodes, limits.maximumNodes, "nodes");
|
|
203
|
+
if (current === null) {
|
|
204
|
+
addAggregate(4);
|
|
205
|
+
return null;
|
|
77
206
|
}
|
|
78
|
-
if (typeof current === "
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
return Object.is(current, -0) ? "0" : JSON.stringify(current);
|
|
207
|
+
if (typeof current === "string") {
|
|
208
|
+
addAggregate(addString(current));
|
|
209
|
+
return current;
|
|
83
210
|
}
|
|
84
|
-
if (typeof current
|
|
85
|
-
|
|
211
|
+
if (typeof current === "boolean") {
|
|
212
|
+
addAggregate(current ? 4 : 5);
|
|
213
|
+
return current;
|
|
86
214
|
}
|
|
87
|
-
if (
|
|
88
|
-
|
|
215
|
+
if (typeof current === "number") {
|
|
216
|
+
if (!Number.isFinite(current)) fail("non-finite");
|
|
217
|
+
const normalized = Object.is(current, -0) ? 0 : current;
|
|
218
|
+
addAggregate(JSON.stringify(normalized).length);
|
|
219
|
+
return normalized;
|
|
89
220
|
}
|
|
221
|
+
if (typeof current !== "object") fail("value");
|
|
222
|
+
if (ancestors.has(current)) fail("cycle");
|
|
223
|
+
const isArray = inspected(() => Array.isArray(current));
|
|
224
|
+
const prototype = inspected(() => Reflect.getPrototypeOf(current));
|
|
225
|
+
if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) fail("shape");
|
|
90
226
|
ancestors.add(current);
|
|
91
227
|
try {
|
|
92
|
-
if (
|
|
93
|
-
|
|
228
|
+
if (isArray) {
|
|
229
|
+
const lengthDescriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, "length"));
|
|
230
|
+
if (!lengthDescriptor || !Object.hasOwn(lengthDescriptor, "value") || lengthDescriptor.enumerable || typeof lengthDescriptor.value !== "number" || !Number.isSafeInteger(lengthDescriptor.value) || lengthDescriptor.value < 0) fail("shape");
|
|
231
|
+
const length = lengthDescriptor.value;
|
|
232
|
+
assertLimit(length, limits.maximumArrayLength, "array-length");
|
|
233
|
+
elements += length;
|
|
234
|
+
assertLimit(elements, limits.maximumElements, "elements");
|
|
235
|
+
const ownKeys2 = inspected(() => Reflect.ownKeys(current));
|
|
236
|
+
if (ownKeys2.some((key) => typeof key !== "string")) fail("shape");
|
|
237
|
+
if (ownKeys2.length !== length + 1) fail("shape");
|
|
238
|
+
const keySet = new Set(ownKeys2);
|
|
239
|
+
if (!keySet.delete("length")) fail("shape");
|
|
240
|
+
const output2 = new Array(length);
|
|
241
|
+
addAggregate(2 + Math.max(0, length - 1));
|
|
242
|
+
for (let index = 0; index < length; index += 1) {
|
|
243
|
+
const key = String(index);
|
|
244
|
+
if (!keySet.delete(key)) fail("shape");
|
|
245
|
+
const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
|
|
246
|
+
if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
|
|
247
|
+
Object.defineProperty(output2, key, {
|
|
248
|
+
configurable: true,
|
|
249
|
+
enumerable: true,
|
|
250
|
+
value: visit(descriptor.value, depth + 1),
|
|
251
|
+
writable: true
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
if (keySet.size !== 0) fail("shape");
|
|
255
|
+
return output2;
|
|
94
256
|
}
|
|
95
|
-
|
|
96
|
-
|
|
257
|
+
const ownKeys = inspected(() => Reflect.ownKeys(current));
|
|
258
|
+
if (ownKeys.some((key) => typeof key !== "string")) fail("shape");
|
|
259
|
+
properties += ownKeys.length;
|
|
260
|
+
assertLimit(properties, limits.maximumProperties, "properties");
|
|
261
|
+
addAggregate(2 + Math.max(0, ownKeys.length - 1) + ownKeys.length);
|
|
262
|
+
const output = {};
|
|
263
|
+
for (const key of ownKeys) {
|
|
264
|
+
addAggregate(addString(key));
|
|
265
|
+
const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
|
|
266
|
+
if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
|
|
267
|
+
Object.defineProperty(output, key, {
|
|
268
|
+
configurable: true,
|
|
269
|
+
enumerable: true,
|
|
270
|
+
value: visit(descriptor.value, depth + 1),
|
|
271
|
+
writable: true
|
|
272
|
+
});
|
|
97
273
|
}
|
|
98
|
-
|
|
99
|
-
const properties = keys2.map((key) => {
|
|
100
|
-
assertUnicodeScalarString(key, `${path2} key`);
|
|
101
|
-
const member = current[key];
|
|
102
|
-
if (member === void 0) {
|
|
103
|
-
throw new TypeError(`${path2}.${key} is undefined.`);
|
|
104
|
-
}
|
|
105
|
-
return `${JSON.stringify(key)}:${visit(member, `${path2}.${key}`)}`;
|
|
106
|
-
});
|
|
107
|
-
return `{${properties.join(",")}}`;
|
|
274
|
+
return output;
|
|
108
275
|
} finally {
|
|
109
276
|
ancestors.delete(current);
|
|
110
277
|
}
|
|
111
278
|
};
|
|
112
|
-
return visit(value,
|
|
279
|
+
return visit(value, 0);
|
|
280
|
+
}
|
|
281
|
+
function serializeSnapshot(value) {
|
|
282
|
+
if (value === null) return "null";
|
|
283
|
+
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
284
|
+
if (typeof value === "number") return JSON.stringify(value);
|
|
285
|
+
if (Array.isArray(value)) return `[${value.map(serializeSnapshot).join(",")}]`;
|
|
286
|
+
const input = value;
|
|
287
|
+
return `{${Object.keys(input).sort().map((key) => `${JSON.stringify(key)}:${serializeSnapshot(input[key])}`).join(",")}}`;
|
|
288
|
+
}
|
|
289
|
+
function canonicalizeGpuContract(value) {
|
|
290
|
+
return serializeSnapshot(snapshotGpuContract(value));
|
|
291
|
+
}
|
|
292
|
+
function canonicalizeQualificationGpuContract(value) {
|
|
293
|
+
return serializeSnapshot(snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/asset-version.ts
|
|
297
|
+
var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
|
|
298
|
+
var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
|
|
299
|
+
"latest",
|
|
300
|
+
"current",
|
|
301
|
+
"stable",
|
|
302
|
+
"preview",
|
|
303
|
+
"default",
|
|
304
|
+
"production",
|
|
305
|
+
"canary",
|
|
306
|
+
"next",
|
|
307
|
+
"head",
|
|
308
|
+
"main"
|
|
309
|
+
]);
|
|
310
|
+
var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
|
|
311
|
+
var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
|
|
312
|
+
function assertImmutableAssetVersion(value) {
|
|
313
|
+
if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
|
|
314
|
+
throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
|
|
315
|
+
}
|
|
316
|
+
return value;
|
|
113
317
|
}
|
|
114
318
|
|
|
115
319
|
// src/hash.ts
|
|
@@ -134,6 +338,14 @@ async function computeSha256(value) {
|
|
|
134
338
|
|
|
135
339
|
// src/manifest-validation.ts
|
|
136
340
|
var stages = ["vertex", "fragment", "compute"];
|
|
341
|
+
function detachedJson(value, path2) {
|
|
342
|
+
try {
|
|
343
|
+
return snapshotGpuContract(value);
|
|
344
|
+
} catch (cause) {
|
|
345
|
+
const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
|
|
346
|
+
throw new TypeError(`${path2} must contain bounded detached JSON contract data.${detail}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
137
349
|
function object(value, path2) {
|
|
138
350
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
139
351
|
return value;
|
|
@@ -141,7 +353,7 @@ function object(value, path2) {
|
|
|
141
353
|
function exact(value, keys2, path2) {
|
|
142
354
|
const allowed = new Set(keys2);
|
|
143
355
|
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
|
|
144
|
-
for (const key of keys2) if (!(key
|
|
356
|
+
for (const key of keys2) if (!Object.hasOwn(value, key)) throw new TypeError(`${path2}.${key} is required.`);
|
|
145
357
|
}
|
|
146
358
|
function text(value, path2, maximum = 512) {
|
|
147
359
|
if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
|
|
@@ -346,7 +558,7 @@ function pipeline(value, path2, moduleIds) {
|
|
|
346
558
|
return input;
|
|
347
559
|
}
|
|
348
560
|
function parseSerializableGpuPipelineDescriptors(value, moduleIds, path2 = "pipelines") {
|
|
349
|
-
const parsed = array(value, path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
561
|
+
const parsed = array(detachedJson(value, path2), path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
|
|
350
562
|
unique(parsed, (item) => item.pipelineId, path2);
|
|
351
563
|
return freeze(parsed);
|
|
352
564
|
}
|
|
@@ -364,13 +576,26 @@ function issue(code, message, path2) {
|
|
|
364
576
|
function object2(value) {
|
|
365
577
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
366
578
|
}
|
|
579
|
+
function freezeJson(value) {
|
|
580
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
581
|
+
for (const child of Object.values(value)) freezeJson(child);
|
|
582
|
+
return Object.freeze(value);
|
|
583
|
+
}
|
|
367
584
|
function exactKeys(value, keys2) {
|
|
368
585
|
const expected = new Set(keys2);
|
|
369
|
-
return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => key
|
|
586
|
+
return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => Object.hasOwn(value, key));
|
|
370
587
|
}
|
|
371
588
|
function safeToken(value) {
|
|
372
589
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
|
|
373
590
|
}
|
|
591
|
+
function immutableVersion(value) {
|
|
592
|
+
try {
|
|
593
|
+
assertImmutableAssetVersion(value);
|
|
594
|
+
return true;
|
|
595
|
+
} catch {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
374
599
|
function validSha(value) {
|
|
375
600
|
try {
|
|
376
601
|
asSha256Hex(String(value));
|
|
@@ -383,8 +608,20 @@ function defineShaderCompileUnit(unit) {
|
|
|
383
608
|
return Object.freeze(unit);
|
|
384
609
|
}
|
|
385
610
|
function validateCompileUnitInventory(value) {
|
|
386
|
-
|
|
387
|
-
|
|
611
|
+
let snapshot;
|
|
612
|
+
try {
|
|
613
|
+
snapshot = snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
614
|
+
} catch {
|
|
615
|
+
return {
|
|
616
|
+
ok: false,
|
|
617
|
+
diagnostics: [issue(
|
|
618
|
+
"invalid-contract",
|
|
619
|
+
"Compile-unit inventory must contain bounded detached JSON contract data."
|
|
620
|
+
)]
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
const envelope = object2(snapshot);
|
|
624
|
+
const candidate = envelope && Object.hasOwn(envelope, "inventory") ? object2(snapshot.inventory) : envelope;
|
|
388
625
|
const diagnostics = [];
|
|
389
626
|
if (!candidate || !exactKeys(candidate, ["contractVersion", "fragments", "compileUnits"])) {
|
|
390
627
|
return { ok: false, diagnostics: [issue("invalid-contract", "Compile-unit inventory has unknown or missing fields.")] };
|
|
@@ -515,7 +752,7 @@ function validateCompileUnitInventory(value) {
|
|
|
515
752
|
diagnostics.push(issue("invalid-contract", cause instanceof Error ? cause.message : "Compile-unit pipelines are invalid.", `${path2}.pipelines`));
|
|
516
753
|
}
|
|
517
754
|
const interfaceRef = object2(unit.interfaceRef);
|
|
518
|
-
if (!interfaceRef || !exactKeys(interfaceRef, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef.interfaceId) || !
|
|
755
|
+
if (!interfaceRef || !exactKeys(interfaceRef, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef.interfaceId) || !immutableVersion(interfaceRef.interfaceVersion) || typeof interfaceRef.manifestUri !== "string" || !interfaceRef.manifestUri.startsWith("https://") || !validSha(interfaceRef.manifestSha256) || !validSha(interfaceRef.interfaceAbiHash) || !validSha(interfaceRef.modelAbiHash)) {
|
|
519
756
|
diagnostics.push(issue("invalid-contract", "Compile-unit interfaceRef is invalid.", `${path2}.interfaceRef`));
|
|
520
757
|
}
|
|
521
758
|
const fixture = object2(unit.qualificationFixture);
|
|
@@ -526,7 +763,7 @@ function validateCompileUnitInventory(value) {
|
|
|
526
763
|
for (const fragmentId of fragmentIds) {
|
|
527
764
|
if (!covered.has(fragmentId)) diagnostics.push(issue("uncovered-fragment", `WGSL fragment ${fragmentId} has no compile unit.`));
|
|
528
765
|
}
|
|
529
|
-
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: candidate };
|
|
766
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson(candidate) };
|
|
530
767
|
}
|
|
531
768
|
|
|
532
769
|
// src/testing/matrix.ts
|
|
@@ -538,7 +775,12 @@ function object3(value) {
|
|
|
538
775
|
}
|
|
539
776
|
function keys(value, expected) {
|
|
540
777
|
const set = new Set(expected);
|
|
541
|
-
return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key
|
|
778
|
+
return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => Object.hasOwn(value, key));
|
|
779
|
+
}
|
|
780
|
+
function freezeJson2(value) {
|
|
781
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
782
|
+
for (const child of Object.values(value)) freezeJson2(child);
|
|
783
|
+
return Object.freeze(value);
|
|
542
784
|
}
|
|
543
785
|
function canonicalEqual(left, right) {
|
|
544
786
|
try {
|
|
@@ -588,7 +830,13 @@ var BASELINE = /* @__PURE__ */ new Map([
|
|
|
588
830
|
["win11-nvidia-edge-d3d12", "edge|windows|x64|physical|nvidia|qualified-nvidia|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-nvidia,d3d12"]
|
|
589
831
|
]);
|
|
590
832
|
function validateStableWebGpuMatrix(value) {
|
|
591
|
-
|
|
833
|
+
let snapshot;
|
|
834
|
+
try {
|
|
835
|
+
snapshot = snapshotGpuContract(value);
|
|
836
|
+
} catch {
|
|
837
|
+
return { ok: false, diagnostics: [issue2("Matrix must contain bounded detached JSON contract data.")] };
|
|
838
|
+
}
|
|
839
|
+
const matrix = object3(snapshot);
|
|
592
840
|
const diagnostics = [];
|
|
593
841
|
if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
|
|
594
842
|
return { ok: false, diagnostics: [issue2("Matrix has unknown or missing top-level fields.")] };
|
|
@@ -661,7 +909,7 @@ function validateStableWebGpuMatrix(value) {
|
|
|
661
909
|
}
|
|
662
910
|
}
|
|
663
911
|
if (physical !== 15 || blocking !== 16 || software !== 1 || ids.size !== BASELINE.size) diagnostics.push(issue2("Matrix must contain the exact 15 physical baseline cells plus one SwiftShader smoke cell."));
|
|
664
|
-
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
|
|
912
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson2(matrix) };
|
|
665
913
|
}
|
|
666
914
|
|
|
667
915
|
// src/testing/qualification-bundle.ts
|
|
@@ -753,14 +1001,33 @@ function object4(value, path2) {
|
|
|
753
1001
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
|
|
754
1002
|
return value;
|
|
755
1003
|
}
|
|
1004
|
+
function detachedJson2(value, label) {
|
|
1005
|
+
try {
|
|
1006
|
+
return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
1007
|
+
} catch {
|
|
1008
|
+
throw new TypeError(`${label} must contain bounded detached JSON contract data.`);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function freezeJson3(value) {
|
|
1012
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
1013
|
+
for (const child of Object.values(value)) freezeJson3(child);
|
|
1014
|
+
return Object.freeze(value);
|
|
1015
|
+
}
|
|
756
1016
|
function exact2(value, keys2, path2) {
|
|
757
1017
|
const expected = new Set(keys2);
|
|
758
|
-
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key
|
|
1018
|
+
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => Object.hasOwn(value, key))) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
759
1019
|
}
|
|
760
1020
|
function token2(value, path2) {
|
|
761
1021
|
if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
762
1022
|
return value;
|
|
763
1023
|
}
|
|
1024
|
+
function immutableVersion2(value, path2) {
|
|
1025
|
+
try {
|
|
1026
|
+
return assertImmutableAssetVersion(value);
|
|
1027
|
+
} catch {
|
|
1028
|
+
throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
764
1031
|
function path(value, label, extensions) {
|
|
765
1032
|
if (typeof value !== "string" || !SAFE_PATH2.test(value) || !extensions.some((extension) => value.endsWith(extension))) {
|
|
766
1033
|
throw new TypeError(`${label} must be a safe data-only bundle path (${extensions.join(", ")}).`);
|
|
@@ -770,8 +1037,8 @@ function path(value, label, extensions) {
|
|
|
770
1037
|
function sha(value, label) {
|
|
771
1038
|
try {
|
|
772
1039
|
return asSha256Hex(String(value));
|
|
773
|
-
} catch
|
|
774
|
-
throw new TypeError(`${label} must be a lowercase SHA-256 digest
|
|
1040
|
+
} catch {
|
|
1041
|
+
throw new TypeError(`${label} must be a lowercase SHA-256 digest.`);
|
|
775
1042
|
}
|
|
776
1043
|
}
|
|
777
1044
|
function integer2(value, label, minimum = 0, maximum = 4294967295) {
|
|
@@ -895,7 +1162,8 @@ function jsonValue(value, label, depth = 0) {
|
|
|
895
1162
|
}
|
|
896
1163
|
function validateQualificationFixture(value, unit) {
|
|
897
1164
|
try {
|
|
898
|
-
const
|
|
1165
|
+
const compileUnit = unit === void 0 ? void 0 : detachedJson2(unit, "compile unit");
|
|
1166
|
+
const fixture = object4(detachedJson2(value, "fixture"), "fixture");
|
|
899
1167
|
exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
|
|
900
1168
|
if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
|
|
901
1169
|
token2(fixture.fixtureId, "fixture.fixtureId");
|
|
@@ -1025,14 +1293,14 @@ function validateQualificationFixture(value, unit) {
|
|
|
1025
1293
|
unique2(bindingIds, `${label}.entries`);
|
|
1026
1294
|
bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
|
|
1027
1295
|
}
|
|
1028
|
-
const pipelines = new Map(
|
|
1296
|
+
const pipelines = new Map(compileUnit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
|
|
1029
1297
|
const pipelineIds = new Set(pipelines.keys());
|
|
1030
1298
|
const commandBindGroups = (value2, pipelineId, label) => {
|
|
1031
1299
|
const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
|
|
1032
1300
|
unique2(ids, label);
|
|
1033
1301
|
const pipeline2 = pipelines.get(pipelineId);
|
|
1034
1302
|
if (!pipeline2) {
|
|
1035
|
-
if (
|
|
1303
|
+
if (compileUnit) throw new TypeError(`${label} pipeline is missing.`);
|
|
1036
1304
|
return;
|
|
1037
1305
|
}
|
|
1038
1306
|
const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
|
|
@@ -1057,7 +1325,7 @@ function validateQualificationFixture(value, unit) {
|
|
|
1057
1325
|
executionCommands += 1;
|
|
1058
1326
|
exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
|
|
1059
1327
|
const id = token2(command.pipelineId, `${label}.pipelineId`);
|
|
1060
|
-
if (
|
|
1328
|
+
if (compileUnit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
|
|
1061
1329
|
commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
|
|
1062
1330
|
const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
|
|
1063
1331
|
if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
|
|
@@ -1231,14 +1499,14 @@ function validateQualificationFixture(value, unit) {
|
|
|
1231
1499
|
}
|
|
1232
1500
|
unique2(probeIds, "fixture.layoutProbes probe IDs");
|
|
1233
1501
|
unique2(probeSources, "fixture.layoutProbes model sources");
|
|
1234
|
-
return { ok: true, value: fixture };
|
|
1502
|
+
return { ok: true, value: freezeJson3(fixture) };
|
|
1235
1503
|
} catch (cause) {
|
|
1236
1504
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
|
|
1237
1505
|
}
|
|
1238
1506
|
}
|
|
1239
1507
|
function validateQualificationBundleManifest(value) {
|
|
1240
1508
|
try {
|
|
1241
|
-
const bundle = object4(value, "qualification");
|
|
1509
|
+
const bundle = object4(detachedJson2(value, "qualification"), "qualification");
|
|
1242
1510
|
exact2(bundle, ["contractVersion", "inventory", "subject", "shaderManifestCorePath", "gpuInterfaceManifest", "modelCompatibilityFixtures", "modules", "fixtures"], "qualification");
|
|
1243
1511
|
if (bundle.contractVersion !== SHADER_QUALIFICATION_BUNDLE_VERSION) throw new TypeError("Unsupported qualification bundle version.");
|
|
1244
1512
|
const inventory = validateCompileUnitInventory(bundle.inventory);
|
|
@@ -1248,7 +1516,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
1248
1516
|
const candidate = object4(subject.shaderManifestCore, "qualification.subject.shaderManifestCore");
|
|
1249
1517
|
exact2(candidate, ["shaderId", "version", "sha256"], "qualification.subject.shaderManifestCore");
|
|
1250
1518
|
token2(candidate.shaderId, "qualification.subject.shaderManifestCore.shaderId");
|
|
1251
|
-
|
|
1519
|
+
immutableVersion2(candidate.version, "qualification.subject.shaderManifestCore.version");
|
|
1252
1520
|
sha(candidate.sha256, "qualification.subject.shaderManifestCore.sha256");
|
|
1253
1521
|
path(bundle.shaderManifestCorePath, "qualification.shaderManifestCorePath", [".json"]);
|
|
1254
1522
|
const interfaceManifest = object4(bundle.gpuInterfaceManifest, "qualification.gpuInterfaceManifest");
|
|
@@ -1308,7 +1576,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
1308
1576
|
const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
|
|
1309
1577
|
if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
|
|
1310
1578
|
orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
|
|
1311
|
-
return { ok: true, value: bundle };
|
|
1579
|
+
return { ok: true, value: freezeJson3(bundle) };
|
|
1312
1580
|
} catch (cause) {
|
|
1313
1581
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
|
|
1314
1582
|
}
|
|
@@ -1321,7 +1589,37 @@ function object5(value, path2) {
|
|
|
1321
1589
|
}
|
|
1322
1590
|
function exact3(value, keys2, path2) {
|
|
1323
1591
|
const expected = new Set(keys2);
|
|
1324
|
-
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key
|
|
1592
|
+
if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => Object.hasOwn(value, key))) throw new TypeError(`${path2} has unknown or missing fields.`);
|
|
1593
|
+
}
|
|
1594
|
+
function detachedQualificationContract(value) {
|
|
1595
|
+
try {
|
|
1596
|
+
return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
1597
|
+
} catch {
|
|
1598
|
+
throw new TypeError("Qualification data must contain bounded detached JSON contract data.");
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
function parseQualificationJsonBytes(bytes, label) {
|
|
1602
|
+
let snapshot;
|
|
1603
|
+
try {
|
|
1604
|
+
snapshot = snapshotUint8Array(
|
|
1605
|
+
bytes,
|
|
1606
|
+
QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
|
|
1607
|
+
);
|
|
1608
|
+
} catch {
|
|
1609
|
+
throw new TypeError(`${label} is not bounded UTF-8 JSON.`);
|
|
1610
|
+
}
|
|
1611
|
+
let parsed;
|
|
1612
|
+
try {
|
|
1613
|
+
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
|
|
1614
|
+
} catch {
|
|
1615
|
+
throw new TypeError(`${label} is not valid UTF-8 JSON.`);
|
|
1616
|
+
}
|
|
1617
|
+
return detachedQualificationContract(parsed);
|
|
1618
|
+
}
|
|
1619
|
+
function freezeJson4(value) {
|
|
1620
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
1621
|
+
for (const child of Object.values(value)) freezeJson4(child);
|
|
1622
|
+
return Object.freeze(value);
|
|
1325
1623
|
}
|
|
1326
1624
|
function token3(value, path2, maximum = 512) {
|
|
1327
1625
|
if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) throw new TypeError(`${path2} is not a bounded string.`);
|
|
@@ -1330,8 +1628,8 @@ function token3(value, path2, maximum = 512) {
|
|
|
1330
1628
|
function sha2(value, path2) {
|
|
1331
1629
|
try {
|
|
1332
1630
|
return asSha256Hex(token3(value, path2, 64));
|
|
1333
|
-
} catch
|
|
1334
|
-
throw new TypeError(`${path2} is not a SHA-256 digest
|
|
1631
|
+
} catch {
|
|
1632
|
+
throw new TypeError(`${path2} is not a SHA-256 digest.`);
|
|
1335
1633
|
}
|
|
1336
1634
|
}
|
|
1337
1635
|
function integer3(value, path2, minimum = 0) {
|
|
@@ -1364,7 +1662,7 @@ function trustedWorkflowRef(value, path2) {
|
|
|
1364
1662
|
return result;
|
|
1365
1663
|
}
|
|
1366
1664
|
function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
1367
|
-
const input = object5(value, path2);
|
|
1665
|
+
const input = object5(detachedQualificationContract(value), path2);
|
|
1368
1666
|
exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
|
|
1369
1667
|
const repository = token3(input.repository, `${path2}.repository`);
|
|
1370
1668
|
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
@@ -1383,10 +1681,10 @@ function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
|
1383
1681
|
token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
|
|
1384
1682
|
sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
|
|
1385
1683
|
timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
|
|
1386
|
-
return input;
|
|
1684
|
+
return freezeJson4(input);
|
|
1387
1685
|
}
|
|
1388
1686
|
function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
1389
|
-
const input = object5(value, path2);
|
|
1687
|
+
const input = object5(detachedQualificationContract(value), path2);
|
|
1390
1688
|
exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
|
|
1391
1689
|
const repository = token3(input.repository, `${path2}.repository`);
|
|
1392
1690
|
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
@@ -1404,7 +1702,7 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
|
1404
1702
|
if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
|
|
1405
1703
|
token3(runner.os, `${path2}.runner.os`);
|
|
1406
1704
|
token3(runner.architecture, `${path2}.runner.architecture`);
|
|
1407
|
-
return input;
|
|
1705
|
+
return freezeJson4(input);
|
|
1408
1706
|
}
|
|
1409
1707
|
function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
|
|
1410
1708
|
if (producer.repository !== provenance.repository || !canonicalEqual2(producer.commit, provenance.commit) || producer.ref !== provenance.ref || producer.runId !== provenance.runId || producer.runAttempt !== provenance.runAttempt || producer.trustedWorkflowRepository !== "Plasius-LTD/gpu-shader" || producer.trustedWorkflowRef !== provenance.workflowRef || !canonicalEqual2(producer.trustedWorkflowSha, provenance.workflowSha) || producer.job !== expectedJob) throw new TypeError(`${path2} does not match the exact qualification workflow run or subject.`);
|
|
@@ -1413,26 +1711,32 @@ function assertProducerMatchesPreflight(producer, provenance, cell, path2, expec
|
|
|
1413
1711
|
if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
|
|
1414
1712
|
}
|
|
1415
1713
|
function canonicalEqual2(left, right) {
|
|
1416
|
-
return
|
|
1714
|
+
return canonicalizeQualificationGpuContract(left) === canonicalizeQualificationGpuContract(right);
|
|
1417
1715
|
}
|
|
1418
1716
|
function foldRunnerLabel(value) {
|
|
1419
1717
|
return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
|
|
1420
1718
|
}
|
|
1421
1719
|
async function computeQualificationInventorySha256(bundle) {
|
|
1422
|
-
|
|
1720
|
+
const snapshot = detachedQualificationContract(bundle);
|
|
1721
|
+
return computeSha256(canonicalizeQualificationGpuContract(snapshot.inventory));
|
|
1423
1722
|
}
|
|
1424
1723
|
async function computeQualificationSubjectBinding(input) {
|
|
1425
1724
|
return computeSha256(`plasius.gpu.qualification-subject/v1
|
|
1426
|
-
${
|
|
1725
|
+
${canonicalizeQualificationGpuContract(input)}`);
|
|
1427
1726
|
}
|
|
1428
1727
|
async function computeValidationEvidenceId(value) {
|
|
1429
1728
|
const input = object5(value, "evidence identity input");
|
|
1430
1729
|
const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
|
|
1431
1730
|
return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
|
|
1432
|
-
${
|
|
1731
|
+
${canonicalizeQualificationGpuContract(projection)}`)).slice(0, 24)}`;
|
|
1433
1732
|
}
|
|
1434
1733
|
function immutableBlobUri(value) {
|
|
1435
|
-
|
|
1734
|
+
let url;
|
|
1735
|
+
try {
|
|
1736
|
+
url = new URL(value);
|
|
1737
|
+
} catch {
|
|
1738
|
+
throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
|
|
1739
|
+
}
|
|
1436
1740
|
if (url.protocol !== "https:" || url.username || url.password || url.hash || url.port || !/^[a-z0-9]{3,24}\.blob\.core\.windows\.net$/u.test(url.hostname) || !/^[A-Za-z0-9][A-Za-z0-9._/-]*\.tar$/u.test(url.pathname.slice(1)) || url.pathname.split("/").some((segment, index) => index > 0 && (!segment || segment === "." || segment === ".."))) {
|
|
1437
1741
|
throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
|
|
1438
1742
|
}
|
|
@@ -1442,12 +1746,7 @@ function immutableBlobUri(value) {
|
|
|
1442
1746
|
}
|
|
1443
1747
|
async function createQualificationPreflight(input) {
|
|
1444
1748
|
token3(input.qualificationId, "qualificationId");
|
|
1445
|
-
|
|
1446
|
-
try {
|
|
1447
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1448
|
-
} catch (cause) {
|
|
1449
|
-
throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
|
|
1450
|
-
}
|
|
1749
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Selected matrix artifact");
|
|
1451
1750
|
if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
|
|
1452
1751
|
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
1453
1752
|
if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
|
|
@@ -1617,12 +1916,7 @@ function syntheticResult(unitId, cell, status, message, now) {
|
|
|
1617
1916
|
async function aggregateShaderValidationEvidence(input) {
|
|
1618
1917
|
const verifyArtifact = async (artifact, label) => {
|
|
1619
1918
|
if (await computeSha256(artifact.bytes) !== artifact.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
|
|
1620
|
-
|
|
1621
|
-
try {
|
|
1622
|
-
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact.bytes));
|
|
1623
|
-
} catch (cause) {
|
|
1624
|
-
throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
|
|
1625
|
-
}
|
|
1919
|
+
const parsed = parseQualificationJsonBytes(artifact.bytes, `${label} bytes`);
|
|
1626
1920
|
if (!canonicalEqual2(parsed, artifact.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
|
|
1627
1921
|
};
|
|
1628
1922
|
await verifyArtifact(input.preflight, "Qualification preflight");
|
|
@@ -1644,12 +1938,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1644
1938
|
exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
|
|
1645
1939
|
const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
|
|
1646
1940
|
if (!canonicalEqual2(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
|
|
1647
|
-
|
|
1648
|
-
try {
|
|
1649
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1650
|
-
} catch (cause) {
|
|
1651
|
-
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
1652
|
-
}
|
|
1941
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
|
|
1653
1942
|
if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
1654
1943
|
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
1655
1944
|
if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
|
|
@@ -1723,7 +2012,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1723
2012
|
if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
|
|
1724
2013
|
for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
|
|
1725
2014
|
const cellResults = results.slice(-units.size);
|
|
1726
|
-
cellRuns.push({ cellId: cell.cellId, source: "runner-preflight", sourceArtifactSha256: runner.sha256, resultsSha256: await computeSha256(
|
|
2015
|
+
cellRuns.push({ cellId: cell.cellId, source: "runner-preflight", sourceArtifactSha256: runner.sha256, resultsSha256: await computeSha256(canonicalizeQualificationGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: runner.value.producer, harness: input.harness, automation: null, resultCount: units.size, status: "runner-unavailable" });
|
|
1727
2016
|
continue;
|
|
1728
2017
|
}
|
|
1729
2018
|
if (diagnostic) {
|
|
@@ -1738,7 +2027,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1738
2027
|
const status2 = value2.status === "timeout" ? "timeout" : "failed";
|
|
1739
2028
|
for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
|
|
1740
2029
|
const cellResults = results.slice(-units.size);
|
|
1741
|
-
cellRuns.push({ cellId: cell.cellId, source: "workflow-diagnostic", sourceArtifactSha256: diagnostic.sha256, resultsSha256: await computeSha256(
|
|
2030
|
+
cellRuns.push({ cellId: cell.cellId, source: "workflow-diagnostic", sourceArtifactSha256: diagnostic.sha256, resultsSha256: await computeSha256(canonicalizeQualificationGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: value2.producer, harness: input.harness, automation: null, resultCount: units.size, status: status2 });
|
|
1742
2031
|
continue;
|
|
1743
2032
|
}
|
|
1744
2033
|
if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
|
|
@@ -1746,7 +2035,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1746
2035
|
if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
|
|
1747
2036
|
const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
|
|
1748
2037
|
results.push(...value.results);
|
|
1749
|
-
cellRuns.push({ cellId: cell.cellId, source: "cell-evidence", sourceArtifactSha256: cellArtifact.sha256, resultsSha256: await computeSha256(
|
|
2038
|
+
cellRuns.push({ cellId: cell.cellId, source: "cell-evidence", sourceArtifactSha256: cellArtifact.sha256, resultsSha256: await computeSha256(canonicalizeQualificationGpuContract(value.results)), qualificationPreflightProvenance: value.qualificationPreflightProvenance, producer: value.producer, harness: value.harness, automation: value.automation, resultCount: value.results.length, status: "passed" });
|
|
1750
2039
|
}
|
|
1751
2040
|
const expectedResults = units.size * cells.size;
|
|
1752
2041
|
if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
|
|
@@ -1769,34 +2058,31 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1769
2058
|
}
|
|
1770
2059
|
async function validateShaderValidationEvidence(input) {
|
|
1771
2060
|
try {
|
|
1772
|
-
const evidence = object5(input.evidence, "evidence");
|
|
2061
|
+
const evidence = object5(detachedQualificationContract(input.evidence), "evidence");
|
|
2062
|
+
const bundle = detachedQualificationContract(input.bundle);
|
|
2063
|
+
const matrix = detachedQualificationContract(input.matrix);
|
|
1773
2064
|
exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
|
|
1774
2065
|
if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
|
|
1775
2066
|
const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
|
|
1776
2067
|
const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
|
|
1777
2068
|
const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
|
|
1778
2069
|
if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1782
|
-
} catch (cause) {
|
|
1783
|
-
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
1784
|
-
}
|
|
1785
|
-
if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
2070
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
|
|
2071
|
+
if (!canonicalEqual2(parsedMatrix, matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
1786
2072
|
const matrixSha256 = await computeSha256(input.matrixBytes);
|
|
1787
|
-
const inventorySha256 = await computeQualificationInventorySha256(
|
|
1788
|
-
if (inventorySha256 !==
|
|
2073
|
+
const inventorySha256 = await computeQualificationInventorySha256(bundle);
|
|
2074
|
+
if (inventorySha256 !== bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
|
|
1789
2075
|
const subject = object5(evidence.subject, "evidence.subject");
|
|
1790
|
-
const expectedSubjectKeys = [...Object.keys(
|
|
2076
|
+
const expectedSubjectKeys = [...Object.keys(bundle.subject), "dataBundleSha256"];
|
|
1791
2077
|
exact3(subject, expectedSubjectKeys, "evidence.subject");
|
|
1792
2078
|
const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
|
|
1793
|
-
if (!canonicalEqual2(candidateSubject,
|
|
2079
|
+
if (!canonicalEqual2(candidateSubject, bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
|
|
1794
2080
|
const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
|
|
1795
2081
|
if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
|
|
1796
2082
|
if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
|
|
1797
2083
|
const matrixRef = object5(evidence.matrixRef, "evidence.matrixRef");
|
|
1798
2084
|
exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
|
|
1799
|
-
if (matrixRef.matrixId !==
|
|
2085
|
+
if (matrixRef.matrixId !== matrix.matrixId || matrixRef.version !== matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
|
|
1800
2086
|
const toolchain = object5(evidence.toolchain, "evidence.toolchain");
|
|
1801
2087
|
exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
|
|
1802
2088
|
token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
|
|
@@ -1808,11 +2094,11 @@ async function validateShaderValidationEvidence(input) {
|
|
|
1808
2094
|
const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
|
|
1809
2095
|
const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
|
|
1810
2096
|
if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
|
|
1811
|
-
const expectedBinding = await computeQualificationSubjectBinding({ subject:
|
|
2097
|
+
const expectedBinding = await computeQualificationSubjectBinding({ subject: bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
|
|
1812
2098
|
if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
|
|
1813
2099
|
if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
|
|
1814
|
-
const units = new Set(
|
|
1815
|
-
const cells = new Map(
|
|
2100
|
+
const units = new Set(bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
|
|
2101
|
+
const cells = new Map(matrix.cells.map((cell) => [cell.cellId, cell]));
|
|
1816
2102
|
const expected = units.size * cells.size;
|
|
1817
2103
|
const results = array2(evidence.results, "evidence.results");
|
|
1818
2104
|
if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
|
|
@@ -1862,7 +2148,7 @@ async function validateShaderValidationEvidence(input) {
|
|
|
1862
2148
|
sha2(automation2.sha256, `${path2}.automation.sha256`);
|
|
1863
2149
|
} else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
|
|
1864
2150
|
const cellResults = parsedResults.filter((result) => result.cellId === cellId);
|
|
1865
|
-
if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(
|
|
2151
|
+
if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeQualificationGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
|
|
1866
2152
|
const resultStatuses = new Set(cellResults.map((result) => result.status));
|
|
1867
2153
|
if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
|
|
1868
2154
|
if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
|
|
@@ -1871,13 +2157,13 @@ async function validateShaderValidationEvidence(input) {
|
|
|
1871
2157
|
if (run.source === "cell-evidence" && cellResults.some((result) => result.observed.runner.id !== producer.runner.name)) throw new TypeError(`${path2} producer runner differs from its results.`);
|
|
1872
2158
|
}
|
|
1873
2159
|
if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
|
|
1874
|
-
return { ok: true, value: evidence };
|
|
2160
|
+
return { ok: true, value: freezeJson4(evidence) };
|
|
1875
2161
|
} catch (cause) {
|
|
1876
2162
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
|
|
1877
2163
|
}
|
|
1878
2164
|
}
|
|
1879
2165
|
function parseShaderValidationEvidenceAttestationRef(value) {
|
|
1880
|
-
const input = object5(value, "attestationRef");
|
|
2166
|
+
const input = object5(detachedQualificationContract(value), "attestationRef");
|
|
1881
2167
|
exact3(input, ["contractVersion", "kind", "evidence", "attestation", "producer"], "attestationRef");
|
|
1882
2168
|
if (input.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || input.kind !== "shader-validation-evidence-attestation-ref") throw new TypeError("Unsupported evidence attestation ref.");
|
|
1883
2169
|
const producer = object5(input.producer, "attestationRef.producer");
|
|
@@ -1897,7 +2183,12 @@ function parseShaderValidationEvidenceAttestationRef(value) {
|
|
|
1897
2183
|
const attestation = object5(input.attestation, "attestationRef.attestation");
|
|
1898
2184
|
exact3(attestation, ["id", "url", "bundle"], "attestationRef.attestation");
|
|
1899
2185
|
token3(attestation.id, "attestationRef.attestation.id");
|
|
1900
|
-
|
|
2186
|
+
let url;
|
|
2187
|
+
try {
|
|
2188
|
+
url = new URL(token3(attestation.url, "attestationRef.attestation.url", 2048));
|
|
2189
|
+
} catch {
|
|
2190
|
+
throw new TypeError("Attestation URL must be an exact GitHub repository attestation URL.");
|
|
2191
|
+
}
|
|
1901
2192
|
const expectedPrefix = `/${repository}/attestations/`;
|
|
1902
2193
|
if (url.protocol !== "https:" || url.hostname !== "github.com" || url.port || url.username || url.password || url.search || url.hash || !url.pathname.startsWith(expectedPrefix) || url.pathname.length <= expectedPrefix.length) throw new TypeError("Attestation URL must be an exact GitHub repository attestation URL.");
|
|
1903
2194
|
const bundle = object5(attestation.bundle, "attestationRef.attestation.bundle");
|
|
@@ -1905,13 +2196,43 @@ function parseShaderValidationEvidenceAttestationRef(value) {
|
|
|
1905
2196
|
const bundleName = token3(bundle.name, "attestationRef.attestation.bundle.name");
|
|
1906
2197
|
if (!/^[A-Za-z0-9._-]+\.json$/u.test(bundleName)) throw new TypeError("Attestation bundle name must be a JSON basename.");
|
|
1907
2198
|
sha2(bundle.sha256, "attestationRef.attestation.bundle.sha256");
|
|
1908
|
-
return input;
|
|
2199
|
+
return freezeJson4(input);
|
|
1909
2200
|
}
|
|
1910
2201
|
async function verifyShaderValidationEvidenceAttestation(input) {
|
|
1911
2202
|
try {
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
2203
|
+
if (typeof input !== "object" || input === null) throw new TypeError("Evidence attestation verification input is invalid.");
|
|
2204
|
+
let values;
|
|
2205
|
+
try {
|
|
2206
|
+
const keys2 = Reflect.ownKeys(input);
|
|
2207
|
+
const expected = ["ref", "evidenceBytes", "bundleBytes", "verifyCryptographicBundle"];
|
|
2208
|
+
if (keys2.length !== expected.length || keys2.some((key) => typeof key !== "string" || !expected.includes(key))) throw new TypeError();
|
|
2209
|
+
values = expected.map((key) => {
|
|
2210
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(input, key);
|
|
2211
|
+
if (!descriptor?.enumerable || !Object.hasOwn(descriptor, "value")) throw new TypeError();
|
|
2212
|
+
return descriptor;
|
|
2213
|
+
});
|
|
2214
|
+
} catch {
|
|
2215
|
+
throw new TypeError("Evidence attestation verification input is invalid.");
|
|
2216
|
+
}
|
|
2217
|
+
const [refValue, evidenceValue, bundleValue, verifierValue] = values;
|
|
2218
|
+
if (typeof verifierValue?.value !== "function") throw new TypeError("Evidence attestation verification input is invalid.");
|
|
2219
|
+
const evidenceBytes = snapshotUint8Array(
|
|
2220
|
+
evidenceValue?.value,
|
|
2221
|
+
QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
|
|
2222
|
+
);
|
|
2223
|
+
const bundleBytes = snapshotUint8Array(
|
|
2224
|
+
bundleValue?.value,
|
|
2225
|
+
QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
|
|
2226
|
+
);
|
|
2227
|
+
const ref = parseShaderValidationEvidenceAttestationRef(refValue?.value);
|
|
2228
|
+
if (await computeSha256(evidenceBytes) !== ref.evidence.sha256 || await computeSha256(bundleBytes) !== ref.attestation.bundle.sha256) throw new TypeError("Attested evidence or bundle digest differs.");
|
|
2229
|
+
let verified;
|
|
2230
|
+
try {
|
|
2231
|
+
verified = await Reflect.apply(verifierValue.value, void 0, [{ ref, evidenceBytes, bundleBytes }]);
|
|
2232
|
+
} catch {
|
|
2233
|
+
throw new TypeError("External build-provenance cryptographic verification failed.");
|
|
2234
|
+
}
|
|
2235
|
+
if (verified !== true) throw new TypeError("External build-provenance cryptographic verification failed.");
|
|
1915
2236
|
return { ok: true, value: ref };
|
|
1916
2237
|
} catch (cause) {
|
|
1917
2238
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Evidence attestation verification failed." }] };
|