@plasius/gpu-shader 0.1.2 → 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 +36 -0
- package/dist/cli.cjs +360 -147
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +360 -147
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +543 -146
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +543 -146
- package/dist/index.js.map +1 -1
- package/dist/node.cjs +235 -84
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +235 -84
- package/dist/node.js.map +1 -1
- package/dist/testing.cjs +366 -124
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +366 -124
- package/dist/testing.js.map +1 -1
- package/package.json +2 -1
package/dist/testing.cjs
CHANGED
|
@@ -53,63 +53,244 @@ 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));
|
|
113
294
|
}
|
|
114
295
|
|
|
115
296
|
// src/asset-version.ts
|
|
@@ -159,11 +340,10 @@ async function computeSha256(value) {
|
|
|
159
340
|
var stages = ["vertex", "fragment", "compute"];
|
|
160
341
|
function detachedJson(value, path2) {
|
|
161
342
|
try {
|
|
162
|
-
return
|
|
343
|
+
return snapshotGpuContract(value);
|
|
163
344
|
} catch (cause) {
|
|
164
|
-
const detail = cause instanceof
|
|
165
|
-
|
|
166
|
-
throw new TypeError(`${path2} must contain detached JSON contract data: ${boundedDetail}`, { cause });
|
|
345
|
+
const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
|
|
346
|
+
throw new TypeError(`${path2} must contain bounded detached JSON contract data.${detail}`);
|
|
167
347
|
}
|
|
168
348
|
}
|
|
169
349
|
function object(value, path2) {
|
|
@@ -173,7 +353,7 @@ function object(value, path2) {
|
|
|
173
353
|
function exact(value, keys2, path2) {
|
|
174
354
|
const allowed = new Set(keys2);
|
|
175
355
|
for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
|
|
176
|
-
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.`);
|
|
177
357
|
}
|
|
178
358
|
function text(value, path2, maximum = 512) {
|
|
179
359
|
if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
|
|
@@ -403,7 +583,7 @@ function freezeJson(value) {
|
|
|
403
583
|
}
|
|
404
584
|
function exactKeys(value, keys2) {
|
|
405
585
|
const expected = new Set(keys2);
|
|
406
|
-
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));
|
|
407
587
|
}
|
|
408
588
|
function safeToken(value) {
|
|
409
589
|
return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
|
|
@@ -430,13 +610,13 @@ function defineShaderCompileUnit(unit) {
|
|
|
430
610
|
function validateCompileUnitInventory(value) {
|
|
431
611
|
let snapshot;
|
|
432
612
|
try {
|
|
433
|
-
snapshot =
|
|
434
|
-
} catch
|
|
613
|
+
snapshot = snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
614
|
+
} catch {
|
|
435
615
|
return {
|
|
436
616
|
ok: false,
|
|
437
617
|
diagnostics: [issue(
|
|
438
618
|
"invalid-contract",
|
|
439
|
-
|
|
619
|
+
"Compile-unit inventory must contain bounded detached JSON contract data."
|
|
440
620
|
)]
|
|
441
621
|
};
|
|
442
622
|
}
|
|
@@ -595,7 +775,12 @@ function object3(value) {
|
|
|
595
775
|
}
|
|
596
776
|
function keys(value, expected) {
|
|
597
777
|
const set = new Set(expected);
|
|
598
|
-
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);
|
|
599
784
|
}
|
|
600
785
|
function canonicalEqual(left, right) {
|
|
601
786
|
try {
|
|
@@ -645,7 +830,13 @@ var BASELINE = /* @__PURE__ */ new Map([
|
|
|
645
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"]
|
|
646
831
|
]);
|
|
647
832
|
function validateStableWebGpuMatrix(value) {
|
|
648
|
-
|
|
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);
|
|
649
840
|
const diagnostics = [];
|
|
650
841
|
if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
|
|
651
842
|
return { ok: false, diagnostics: [issue2("Matrix has unknown or missing top-level fields.")] };
|
|
@@ -718,7 +909,7 @@ function validateStableWebGpuMatrix(value) {
|
|
|
718
909
|
}
|
|
719
910
|
}
|
|
720
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."));
|
|
721
|
-
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
|
|
912
|
+
return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson2(matrix) };
|
|
722
913
|
}
|
|
723
914
|
|
|
724
915
|
// src/testing/qualification-bundle.ts
|
|
@@ -812,19 +1003,19 @@ function object4(value, path2) {
|
|
|
812
1003
|
}
|
|
813
1004
|
function detachedJson2(value, label) {
|
|
814
1005
|
try {
|
|
815
|
-
return
|
|
816
|
-
} catch
|
|
817
|
-
throw new TypeError(`${label} must contain detached JSON contract data
|
|
1006
|
+
return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
|
|
1007
|
+
} catch {
|
|
1008
|
+
throw new TypeError(`${label} must contain bounded detached JSON contract data.`);
|
|
818
1009
|
}
|
|
819
1010
|
}
|
|
820
|
-
function
|
|
1011
|
+
function freezeJson3(value) {
|
|
821
1012
|
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
|
|
822
|
-
for (const child of Object.values(value))
|
|
1013
|
+
for (const child of Object.values(value)) freezeJson3(child);
|
|
823
1014
|
return Object.freeze(value);
|
|
824
1015
|
}
|
|
825
1016
|
function exact2(value, keys2, path2) {
|
|
826
1017
|
const expected = new Set(keys2);
|
|
827
|
-
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.`);
|
|
828
1019
|
}
|
|
829
1020
|
function token2(value, path2) {
|
|
830
1021
|
if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
|
|
@@ -833,11 +1024,8 @@ function token2(value, path2) {
|
|
|
833
1024
|
function immutableVersion2(value, path2) {
|
|
834
1025
|
try {
|
|
835
1026
|
return assertImmutableAssetVersion(value);
|
|
836
|
-
} catch
|
|
837
|
-
throw new TypeError(
|
|
838
|
-
`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
|
|
839
|
-
{ cause }
|
|
840
|
-
);
|
|
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.`);
|
|
841
1029
|
}
|
|
842
1030
|
}
|
|
843
1031
|
function path(value, label, extensions) {
|
|
@@ -849,8 +1037,8 @@ function path(value, label, extensions) {
|
|
|
849
1037
|
function sha(value, label) {
|
|
850
1038
|
try {
|
|
851
1039
|
return asSha256Hex(String(value));
|
|
852
|
-
} catch
|
|
853
|
-
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.`);
|
|
854
1042
|
}
|
|
855
1043
|
}
|
|
856
1044
|
function integer2(value, label, minimum = 0, maximum = 4294967295) {
|
|
@@ -974,6 +1162,7 @@ function jsonValue(value, label, depth = 0) {
|
|
|
974
1162
|
}
|
|
975
1163
|
function validateQualificationFixture(value, unit) {
|
|
976
1164
|
try {
|
|
1165
|
+
const compileUnit = unit === void 0 ? void 0 : detachedJson2(unit, "compile unit");
|
|
977
1166
|
const fixture = object4(detachedJson2(value, "fixture"), "fixture");
|
|
978
1167
|
exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
|
|
979
1168
|
if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
|
|
@@ -1104,14 +1293,14 @@ function validateQualificationFixture(value, unit) {
|
|
|
1104
1293
|
unique2(bindingIds, `${label}.entries`);
|
|
1105
1294
|
bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
|
|
1106
1295
|
}
|
|
1107
|
-
const pipelines = new Map(
|
|
1296
|
+
const pipelines = new Map(compileUnit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
|
|
1108
1297
|
const pipelineIds = new Set(pipelines.keys());
|
|
1109
1298
|
const commandBindGroups = (value2, pipelineId, label) => {
|
|
1110
1299
|
const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
|
|
1111
1300
|
unique2(ids, label);
|
|
1112
1301
|
const pipeline2 = pipelines.get(pipelineId);
|
|
1113
1302
|
if (!pipeline2) {
|
|
1114
|
-
if (
|
|
1303
|
+
if (compileUnit) throw new TypeError(`${label} pipeline is missing.`);
|
|
1115
1304
|
return;
|
|
1116
1305
|
}
|
|
1117
1306
|
const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
|
|
@@ -1136,7 +1325,7 @@ function validateQualificationFixture(value, unit) {
|
|
|
1136
1325
|
executionCommands += 1;
|
|
1137
1326
|
exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
|
|
1138
1327
|
const id = token2(command.pipelineId, `${label}.pipelineId`);
|
|
1139
|
-
if (
|
|
1328
|
+
if (compileUnit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
|
|
1140
1329
|
commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
|
|
1141
1330
|
const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
|
|
1142
1331
|
if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
|
|
@@ -1310,7 +1499,7 @@ function validateQualificationFixture(value, unit) {
|
|
|
1310
1499
|
}
|
|
1311
1500
|
unique2(probeIds, "fixture.layoutProbes probe IDs");
|
|
1312
1501
|
unique2(probeSources, "fixture.layoutProbes model sources");
|
|
1313
|
-
return { ok: true, value:
|
|
1502
|
+
return { ok: true, value: freezeJson3(fixture) };
|
|
1314
1503
|
} catch (cause) {
|
|
1315
1504
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
|
|
1316
1505
|
}
|
|
@@ -1387,7 +1576,7 @@ function validateQualificationBundleManifest(value) {
|
|
|
1387
1576
|
const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
|
|
1388
1577
|
if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
|
|
1389
1578
|
orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
|
|
1390
|
-
return { ok: true, value:
|
|
1579
|
+
return { ok: true, value: freezeJson3(bundle) };
|
|
1391
1580
|
} catch (cause) {
|
|
1392
1581
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
|
|
1393
1582
|
}
|
|
@@ -1400,7 +1589,37 @@ function object5(value, path2) {
|
|
|
1400
1589
|
}
|
|
1401
1590
|
function exact3(value, keys2, path2) {
|
|
1402
1591
|
const expected = new Set(keys2);
|
|
1403
|
-
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);
|
|
1404
1623
|
}
|
|
1405
1624
|
function token3(value, path2, maximum = 512) {
|
|
1406
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.`);
|
|
@@ -1409,8 +1628,8 @@ function token3(value, path2, maximum = 512) {
|
|
|
1409
1628
|
function sha2(value, path2) {
|
|
1410
1629
|
try {
|
|
1411
1630
|
return asSha256Hex(token3(value, path2, 64));
|
|
1412
|
-
} catch
|
|
1413
|
-
throw new TypeError(`${path2} is not a SHA-256 digest
|
|
1631
|
+
} catch {
|
|
1632
|
+
throw new TypeError(`${path2} is not a SHA-256 digest.`);
|
|
1414
1633
|
}
|
|
1415
1634
|
}
|
|
1416
1635
|
function integer3(value, path2, minimum = 0) {
|
|
@@ -1443,7 +1662,7 @@ function trustedWorkflowRef(value, path2) {
|
|
|
1443
1662
|
return result;
|
|
1444
1663
|
}
|
|
1445
1664
|
function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
1446
|
-
const input = object5(value, path2);
|
|
1665
|
+
const input = object5(detachedQualificationContract(value), path2);
|
|
1447
1666
|
exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
|
|
1448
1667
|
const repository = token3(input.repository, `${path2}.repository`);
|
|
1449
1668
|
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
@@ -1462,10 +1681,10 @@ function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
|
|
|
1462
1681
|
token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
|
|
1463
1682
|
sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
|
|
1464
1683
|
timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
|
|
1465
|
-
return input;
|
|
1684
|
+
return freezeJson4(input);
|
|
1466
1685
|
}
|
|
1467
1686
|
function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
1468
|
-
const input = object5(value, path2);
|
|
1687
|
+
const input = object5(detachedQualificationContract(value), path2);
|
|
1469
1688
|
exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
|
|
1470
1689
|
const repository = token3(input.repository, `${path2}.repository`);
|
|
1471
1690
|
if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
|
|
@@ -1483,7 +1702,7 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
|
|
|
1483
1702
|
if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
|
|
1484
1703
|
token3(runner.os, `${path2}.runner.os`);
|
|
1485
1704
|
token3(runner.architecture, `${path2}.runner.architecture`);
|
|
1486
|
-
return input;
|
|
1705
|
+
return freezeJson4(input);
|
|
1487
1706
|
}
|
|
1488
1707
|
function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
|
|
1489
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.`);
|
|
@@ -1492,26 +1711,32 @@ function assertProducerMatchesPreflight(producer, provenance, cell, path2, expec
|
|
|
1492
1711
|
if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
|
|
1493
1712
|
}
|
|
1494
1713
|
function canonicalEqual2(left, right) {
|
|
1495
|
-
return
|
|
1714
|
+
return canonicalizeQualificationGpuContract(left) === canonicalizeQualificationGpuContract(right);
|
|
1496
1715
|
}
|
|
1497
1716
|
function foldRunnerLabel(value) {
|
|
1498
1717
|
return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
|
|
1499
1718
|
}
|
|
1500
1719
|
async function computeQualificationInventorySha256(bundle) {
|
|
1501
|
-
|
|
1720
|
+
const snapshot = detachedQualificationContract(bundle);
|
|
1721
|
+
return computeSha256(canonicalizeQualificationGpuContract(snapshot.inventory));
|
|
1502
1722
|
}
|
|
1503
1723
|
async function computeQualificationSubjectBinding(input) {
|
|
1504
1724
|
return computeSha256(`plasius.gpu.qualification-subject/v1
|
|
1505
|
-
${
|
|
1725
|
+
${canonicalizeQualificationGpuContract(input)}`);
|
|
1506
1726
|
}
|
|
1507
1727
|
async function computeValidationEvidenceId(value) {
|
|
1508
1728
|
const input = object5(value, "evidence identity input");
|
|
1509
1729
|
const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
|
|
1510
1730
|
return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
|
|
1511
|
-
${
|
|
1731
|
+
${canonicalizeQualificationGpuContract(projection)}`)).slice(0, 24)}`;
|
|
1512
1732
|
}
|
|
1513
1733
|
function immutableBlobUri(value) {
|
|
1514
|
-
|
|
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
|
+
}
|
|
1515
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 === ".."))) {
|
|
1516
1741
|
throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
|
|
1517
1742
|
}
|
|
@@ -1521,12 +1746,7 @@ function immutableBlobUri(value) {
|
|
|
1521
1746
|
}
|
|
1522
1747
|
async function createQualificationPreflight(input) {
|
|
1523
1748
|
token3(input.qualificationId, "qualificationId");
|
|
1524
|
-
|
|
1525
|
-
try {
|
|
1526
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1527
|
-
} catch (cause) {
|
|
1528
|
-
throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
|
|
1529
|
-
}
|
|
1749
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Selected matrix artifact");
|
|
1530
1750
|
if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
|
|
1531
1751
|
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
1532
1752
|
if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
|
|
@@ -1696,12 +1916,7 @@ function syntheticResult(unitId, cell, status, message, now) {
|
|
|
1696
1916
|
async function aggregateShaderValidationEvidence(input) {
|
|
1697
1917
|
const verifyArtifact = async (artifact, label) => {
|
|
1698
1918
|
if (await computeSha256(artifact.bytes) !== artifact.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
|
|
1699
|
-
|
|
1700
|
-
try {
|
|
1701
|
-
parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact.bytes));
|
|
1702
|
-
} catch (cause) {
|
|
1703
|
-
throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
|
|
1704
|
-
}
|
|
1919
|
+
const parsed = parseQualificationJsonBytes(artifact.bytes, `${label} bytes`);
|
|
1705
1920
|
if (!canonicalEqual2(parsed, artifact.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
|
|
1706
1921
|
};
|
|
1707
1922
|
await verifyArtifact(input.preflight, "Qualification preflight");
|
|
@@ -1723,12 +1938,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1723
1938
|
exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
|
|
1724
1939
|
const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
|
|
1725
1940
|
if (!canonicalEqual2(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
|
|
1726
|
-
|
|
1727
|
-
try {
|
|
1728
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1729
|
-
} catch (cause) {
|
|
1730
|
-
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
1731
|
-
}
|
|
1941
|
+
const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
|
|
1732
1942
|
if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
|
|
1733
1943
|
const actualMatrixSha256 = await computeSha256(input.matrixBytes);
|
|
1734
1944
|
if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
|
|
@@ -1802,7 +2012,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1802
2012
|
if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
|
|
1803
2013
|
for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
|
|
1804
2014
|
const cellResults = results.slice(-units.size);
|
|
1805
|
-
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" });
|
|
1806
2016
|
continue;
|
|
1807
2017
|
}
|
|
1808
2018
|
if (diagnostic) {
|
|
@@ -1817,7 +2027,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1817
2027
|
const status2 = value2.status === "timeout" ? "timeout" : "failed";
|
|
1818
2028
|
for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
|
|
1819
2029
|
const cellResults = results.slice(-units.size);
|
|
1820
|
-
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 });
|
|
1821
2031
|
continue;
|
|
1822
2032
|
}
|
|
1823
2033
|
if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
|
|
@@ -1825,7 +2035,7 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1825
2035
|
if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
|
|
1826
2036
|
const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
|
|
1827
2037
|
results.push(...value.results);
|
|
1828
|
-
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" });
|
|
1829
2039
|
}
|
|
1830
2040
|
const expectedResults = units.size * cells.size;
|
|
1831
2041
|
if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
|
|
@@ -1848,34 +2058,31 @@ async function aggregateShaderValidationEvidence(input) {
|
|
|
1848
2058
|
}
|
|
1849
2059
|
async function validateShaderValidationEvidence(input) {
|
|
1850
2060
|
try {
|
|
1851
|
-
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);
|
|
1852
2064
|
exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
|
|
1853
2065
|
if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
|
|
1854
2066
|
const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
|
|
1855
2067
|
const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
|
|
1856
2068
|
const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
|
|
1857
2069
|
if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
|
|
1861
|
-
} catch (cause) {
|
|
1862
|
-
throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
|
|
1863
|
-
}
|
|
1864
|
-
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.");
|
|
1865
2072
|
const matrixSha256 = await computeSha256(input.matrixBytes);
|
|
1866
|
-
const inventorySha256 = await computeQualificationInventorySha256(
|
|
1867
|
-
if (inventorySha256 !==
|
|
2073
|
+
const inventorySha256 = await computeQualificationInventorySha256(bundle);
|
|
2074
|
+
if (inventorySha256 !== bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
|
|
1868
2075
|
const subject = object5(evidence.subject, "evidence.subject");
|
|
1869
|
-
const expectedSubjectKeys = [...Object.keys(
|
|
2076
|
+
const expectedSubjectKeys = [...Object.keys(bundle.subject), "dataBundleSha256"];
|
|
1870
2077
|
exact3(subject, expectedSubjectKeys, "evidence.subject");
|
|
1871
2078
|
const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
|
|
1872
|
-
if (!canonicalEqual2(candidateSubject,
|
|
2079
|
+
if (!canonicalEqual2(candidateSubject, bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
|
|
1873
2080
|
const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
|
|
1874
2081
|
if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
|
|
1875
2082
|
if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
|
|
1876
2083
|
const matrixRef = object5(evidence.matrixRef, "evidence.matrixRef");
|
|
1877
2084
|
exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
|
|
1878
|
-
if (matrixRef.matrixId !==
|
|
2085
|
+
if (matrixRef.matrixId !== matrix.matrixId || matrixRef.version !== matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
|
|
1879
2086
|
const toolchain = object5(evidence.toolchain, "evidence.toolchain");
|
|
1880
2087
|
exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
|
|
1881
2088
|
token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
|
|
@@ -1887,11 +2094,11 @@ async function validateShaderValidationEvidence(input) {
|
|
|
1887
2094
|
const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
|
|
1888
2095
|
const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
|
|
1889
2096
|
if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
|
|
1890
|
-
const expectedBinding = await computeQualificationSubjectBinding({ subject:
|
|
2097
|
+
const expectedBinding = await computeQualificationSubjectBinding({ subject: bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
|
|
1891
2098
|
if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
|
|
1892
2099
|
if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
|
|
1893
|
-
const units = new Set(
|
|
1894
|
-
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]));
|
|
1895
2102
|
const expected = units.size * cells.size;
|
|
1896
2103
|
const results = array2(evidence.results, "evidence.results");
|
|
1897
2104
|
if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
|
|
@@ -1941,7 +2148,7 @@ async function validateShaderValidationEvidence(input) {
|
|
|
1941
2148
|
sha2(automation2.sha256, `${path2}.automation.sha256`);
|
|
1942
2149
|
} else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
|
|
1943
2150
|
const cellResults = parsedResults.filter((result) => result.cellId === cellId);
|
|
1944
|
-
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.`);
|
|
1945
2152
|
const resultStatuses = new Set(cellResults.map((result) => result.status));
|
|
1946
2153
|
if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
|
|
1947
2154
|
if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
|
|
@@ -1950,13 +2157,13 @@ async function validateShaderValidationEvidence(input) {
|
|
|
1950
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.`);
|
|
1951
2158
|
}
|
|
1952
2159
|
if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
|
|
1953
|
-
return { ok: true, value: evidence };
|
|
2160
|
+
return { ok: true, value: freezeJson4(evidence) };
|
|
1954
2161
|
} catch (cause) {
|
|
1955
2162
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
|
|
1956
2163
|
}
|
|
1957
2164
|
}
|
|
1958
2165
|
function parseShaderValidationEvidenceAttestationRef(value) {
|
|
1959
|
-
const input = object5(value, "attestationRef");
|
|
2166
|
+
const input = object5(detachedQualificationContract(value), "attestationRef");
|
|
1960
2167
|
exact3(input, ["contractVersion", "kind", "evidence", "attestation", "producer"], "attestationRef");
|
|
1961
2168
|
if (input.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || input.kind !== "shader-validation-evidence-attestation-ref") throw new TypeError("Unsupported evidence attestation ref.");
|
|
1962
2169
|
const producer = object5(input.producer, "attestationRef.producer");
|
|
@@ -1976,7 +2183,12 @@ function parseShaderValidationEvidenceAttestationRef(value) {
|
|
|
1976
2183
|
const attestation = object5(input.attestation, "attestationRef.attestation");
|
|
1977
2184
|
exact3(attestation, ["id", "url", "bundle"], "attestationRef.attestation");
|
|
1978
2185
|
token3(attestation.id, "attestationRef.attestation.id");
|
|
1979
|
-
|
|
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
|
+
}
|
|
1980
2192
|
const expectedPrefix = `/${repository}/attestations/`;
|
|
1981
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.");
|
|
1982
2194
|
const bundle = object5(attestation.bundle, "attestationRef.attestation.bundle");
|
|
@@ -1984,13 +2196,43 @@ function parseShaderValidationEvidenceAttestationRef(value) {
|
|
|
1984
2196
|
const bundleName = token3(bundle.name, "attestationRef.attestation.bundle.name");
|
|
1985
2197
|
if (!/^[A-Za-z0-9._-]+\.json$/u.test(bundleName)) throw new TypeError("Attestation bundle name must be a JSON basename.");
|
|
1986
2198
|
sha2(bundle.sha256, "attestationRef.attestation.bundle.sha256");
|
|
1987
|
-
return input;
|
|
2199
|
+
return freezeJson4(input);
|
|
1988
2200
|
}
|
|
1989
2201
|
async function verifyShaderValidationEvidenceAttestation(input) {
|
|
1990
2202
|
try {
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
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.");
|
|
1994
2236
|
return { ok: true, value: ref };
|
|
1995
2237
|
} catch (cause) {
|
|
1996
2238
|
return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Evidence attestation verification failed." }] };
|