@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/dist/cli.cjs CHANGED
@@ -34,63 +34,244 @@ var import_promises = require("fs/promises");
34
34
  var import_node_path = require("path");
35
35
 
36
36
  // src/canonical-json.ts
37
- function isPlainObject(value) {
38
- const prototype = Object.getPrototypeOf(value);
39
- return prototype === Object.prototype || prototype === null;
37
+ var GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
38
+ maximumDepth: 64,
39
+ maximumNodes: 262144,
40
+ maximumProperties: 131072,
41
+ maximumElements: 131072,
42
+ maximumArrayLength: 1e5,
43
+ maximumStringBytes: 1024 * 1024,
44
+ maximumAggregateStringBytes: 8 * 1024 * 1024,
45
+ maximumAggregateBytes: 16 * 1024 * 1024,
46
+ maximumInputBytes: 16 * 1024 * 1024
47
+ });
48
+ var QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
49
+ maximumDepth: 96,
50
+ maximumNodes: 4e6,
51
+ maximumProperties: 2e6,
52
+ maximumElements: 2e6,
53
+ maximumArrayLength: 25e4,
54
+ maximumStringBytes: 4 * 1024 * 1024,
55
+ maximumAggregateStringBytes: 128 * 1024 * 1024,
56
+ maximumAggregateBytes: 256 * 1024 * 1024,
57
+ maximumInputBytes: 256 * 1024 * 1024
58
+ });
59
+ var FAILURE_MESSAGES = Object.freeze({
60
+ "aggregate-bytes": "GPU contract snapshot exceeds the aggregate byte limit.",
61
+ "aggregate-string-bytes": "GPU contract snapshot exceeds the aggregate string byte limit.",
62
+ "array-length": "GPU contract snapshot exceeds the single-array element limit.",
63
+ cycle: "GPU contract snapshot contains a circular reference.",
64
+ depth: "GPU contract snapshot exceeds the nesting-depth limit.",
65
+ elements: "GPU contract snapshot exceeds the total element limit.",
66
+ inspection: "GPU contract snapshot rejected unsafe object inspection.",
67
+ nodes: "GPU contract snapshot exceeds the total node limit.",
68
+ "non-finite": "GPU contract snapshot contains a non-finite number.",
69
+ properties: "GPU contract snapshot exceeds the total property limit.",
70
+ shape: "GPU contract snapshot requires plain JSON objects with own enumerable data properties and dense arrays.",
71
+ "string-bytes": "GPU contract snapshot exceeds the individual string byte limit.",
72
+ unicode: "GPU contract snapshot contains an invalid Unicode scalar string or unpaired UTF-16 surrogate.",
73
+ value: "GPU contract snapshot contains undefined or another value that JSON cannot represent."
74
+ });
75
+ var GpuContractSnapshotError = class extends TypeError {
76
+ code;
77
+ constructor(code) {
78
+ super(FAILURE_MESSAGES[code]);
79
+ this.name = "GpuContractSnapshotError";
80
+ this.code = code;
81
+ }
82
+ };
83
+ var TYPED_ARRAY_PROTOTYPE = Reflect.getPrototypeOf(Uint8Array.prototype);
84
+ var TYPED_ARRAY_BYTE_LENGTH = Reflect.getOwnPropertyDescriptor(
85
+ TYPED_ARRAY_PROTOTYPE,
86
+ "byteLength"
87
+ )?.get;
88
+ var TYPED_ARRAY_TAG = Reflect.getOwnPropertyDescriptor(
89
+ TYPED_ARRAY_PROTOTYPE,
90
+ Symbol.toStringTag
91
+ )?.get;
92
+ var UINT8_ARRAY_SET = Uint8Array.prototype.set;
93
+ function snapshotUint8Array(value, maximumBytes) {
94
+ if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
95
+ throw new TypeError("GPU contract byte limit must be a non-negative safe integer.");
96
+ }
97
+ let byteLength;
98
+ let tag;
99
+ try {
100
+ if (!TYPED_ARRAY_BYTE_LENGTH || !TYPED_ARRAY_TAG) throw new TypeError();
101
+ byteLength = Reflect.apply(TYPED_ARRAY_BYTE_LENGTH, value, []);
102
+ tag = Reflect.apply(TYPED_ARRAY_TAG, value, []);
103
+ } catch {
104
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
105
+ }
106
+ if (tag !== "Uint8Array" || !Number.isSafeInteger(byteLength) || byteLength > maximumBytes) {
107
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
108
+ }
109
+ const output = new Uint8Array(byteLength);
110
+ try {
111
+ Reflect.apply(UINT8_ARRAY_SET, output, [value]);
112
+ } catch {
113
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
114
+ }
115
+ return output;
116
+ }
117
+ function fail(reason) {
118
+ throw new GpuContractSnapshotError(reason);
40
119
  }
41
- function assertUnicodeScalarString(value, path2) {
120
+ function inspected(operation) {
121
+ try {
122
+ return operation();
123
+ } catch {
124
+ return fail("inspection");
125
+ }
126
+ }
127
+ function assertLimit(value, maximum, reason) {
128
+ if (!Number.isSafeInteger(value) || value > maximum) fail(reason);
129
+ }
130
+ function quotedJsonByteLength(value, maximum) {
131
+ let raw = 0;
132
+ let quoted = 2;
42
133
  for (let index = 0; index < value.length; index += 1) {
43
134
  const code = value.charCodeAt(index);
44
- if (code >= 55296 && code <= 56319) {
135
+ if (code <= 127) {
136
+ raw += 1;
137
+ if (code <= 31) quoted += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
138
+ else quoted += code === 34 || code === 92 ? 2 : 1;
139
+ } else if (code <= 2047) {
140
+ raw += 2;
141
+ quoted += 2;
142
+ } else if (code >= 55296 && code <= 56319) {
45
143
  const next = value.charCodeAt(index + 1);
46
- if (!(next >= 56320 && next <= 57343)) throw new TypeError(`${path2} contains an unpaired UTF-16 surrogate.`);
144
+ if (!(next >= 56320 && next <= 57343)) fail("unicode");
145
+ raw += 4;
146
+ quoted += 4;
47
147
  index += 1;
48
- } else if (code >= 56320 && code <= 57343) throw new TypeError(`${path2} contains an unpaired UTF-16 surrogate.`);
148
+ } else if (code >= 56320 && code <= 57343) fail("unicode");
149
+ else {
150
+ raw += 3;
151
+ quoted += 3;
152
+ }
153
+ if (raw > maximum) fail("string-bytes");
49
154
  }
155
+ return { raw, quoted };
50
156
  }
51
- function canonicalizeGpuContract(value) {
157
+ function assertLimits(limits) {
158
+ for (const value of Object.values(limits)) {
159
+ if (!Number.isSafeInteger(value) || value < 1) throw new TypeError("GPU contract snapshot limits must be positive safe integers.");
160
+ }
161
+ }
162
+ function snapshotGpuContract(value, limits = GPU_CONTRACT_SNAPSHOT_LIMITS) {
163
+ assertLimits(limits);
52
164
  const ancestors = /* @__PURE__ */ new Set();
53
- const visit = (current, path2) => {
54
- if (current === null) return "null";
55
- if (typeof current === "string" || typeof current === "boolean") {
56
- if (typeof current === "string") assertUnicodeScalarString(current, path2);
57
- return JSON.stringify(current);
165
+ let nodes = 0;
166
+ let properties = 0;
167
+ let elements = 0;
168
+ let aggregateStringBytes = 0;
169
+ let aggregateBytes = 0;
170
+ const addAggregate = (bytes2) => {
171
+ aggregateBytes += bytes2;
172
+ assertLimit(aggregateBytes, limits.maximumAggregateBytes, "aggregate-bytes");
173
+ };
174
+ const addString = (text2) => {
175
+ const measured = quotedJsonByteLength(text2, limits.maximumStringBytes);
176
+ aggregateStringBytes += measured.raw;
177
+ assertLimit(aggregateStringBytes, limits.maximumAggregateStringBytes, "aggregate-string-bytes");
178
+ return measured.quoted;
179
+ };
180
+ const visit = (current, depth) => {
181
+ if (depth > limits.maximumDepth) fail("depth");
182
+ nodes += 1;
183
+ assertLimit(nodes, limits.maximumNodes, "nodes");
184
+ if (current === null) {
185
+ addAggregate(4);
186
+ return null;
187
+ }
188
+ if (typeof current === "string") {
189
+ addAggregate(addString(current));
190
+ return current;
191
+ }
192
+ if (typeof current === "boolean") {
193
+ addAggregate(current ? 4 : 5);
194
+ return current;
58
195
  }
59
196
  if (typeof current === "number") {
60
- if (!Number.isFinite(current)) {
61
- throw new TypeError(`${path2} contains a non-finite number.`);
62
- }
63
- return Object.is(current, -0) ? "0" : JSON.stringify(current);
64
- }
65
- if (typeof current !== "object") {
66
- throw new TypeError(`${path2} contains a value that JSON cannot represent.`);
67
- }
68
- if (ancestors.has(current)) {
69
- throw new TypeError(`${path2} contains a circular reference.`);
70
- }
197
+ if (!Number.isFinite(current)) fail("non-finite");
198
+ const normalized = Object.is(current, -0) ? 0 : current;
199
+ addAggregate(JSON.stringify(normalized).length);
200
+ return normalized;
201
+ }
202
+ if (typeof current !== "object") fail("value");
203
+ if (ancestors.has(current)) fail("cycle");
204
+ const isArray = inspected(() => Array.isArray(current));
205
+ const prototype = inspected(() => Reflect.getPrototypeOf(current));
206
+ if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) fail("shape");
71
207
  ancestors.add(current);
72
208
  try {
73
- if (Array.isArray(current)) {
74
- return `[${current.map((item, index) => visit(item, `${path2}[${index}]`)).join(",")}]`;
75
- }
76
- if (!isPlainObject(current)) {
77
- throw new TypeError(`${path2} must contain only plain JSON objects.`);
78
- }
79
- const keys2 = Object.keys(current).sort();
80
- const properties = keys2.map((key) => {
81
- assertUnicodeScalarString(key, `${path2} key`);
82
- const member = current[key];
83
- if (member === void 0) {
84
- throw new TypeError(`${path2}.${key} is undefined.`);
209
+ if (isArray) {
210
+ const lengthDescriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, "length"));
211
+ if (!lengthDescriptor || !Object.hasOwn(lengthDescriptor, "value") || lengthDescriptor.enumerable || typeof lengthDescriptor.value !== "number" || !Number.isSafeInteger(lengthDescriptor.value) || lengthDescriptor.value < 0) fail("shape");
212
+ const length = lengthDescriptor.value;
213
+ assertLimit(length, limits.maximumArrayLength, "array-length");
214
+ elements += length;
215
+ assertLimit(elements, limits.maximumElements, "elements");
216
+ const ownKeys2 = inspected(() => Reflect.ownKeys(current));
217
+ if (ownKeys2.some((key) => typeof key !== "string")) fail("shape");
218
+ if (ownKeys2.length !== length + 1) fail("shape");
219
+ const keySet = new Set(ownKeys2);
220
+ if (!keySet.delete("length")) fail("shape");
221
+ const output2 = new Array(length);
222
+ addAggregate(2 + Math.max(0, length - 1));
223
+ for (let index = 0; index < length; index += 1) {
224
+ const key = String(index);
225
+ if (!keySet.delete(key)) fail("shape");
226
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
227
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
228
+ Object.defineProperty(output2, key, {
229
+ configurable: true,
230
+ enumerable: true,
231
+ value: visit(descriptor.value, depth + 1),
232
+ writable: true
233
+ });
85
234
  }
86
- return `${JSON.stringify(key)}:${visit(member, `${path2}.${key}`)}`;
87
- });
88
- return `{${properties.join(",")}}`;
235
+ if (keySet.size !== 0) fail("shape");
236
+ return output2;
237
+ }
238
+ const ownKeys = inspected(() => Reflect.ownKeys(current));
239
+ if (ownKeys.some((key) => typeof key !== "string")) fail("shape");
240
+ properties += ownKeys.length;
241
+ assertLimit(properties, limits.maximumProperties, "properties");
242
+ addAggregate(2 + Math.max(0, ownKeys.length - 1) + ownKeys.length);
243
+ const output = {};
244
+ for (const key of ownKeys) {
245
+ addAggregate(addString(key));
246
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
247
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
248
+ Object.defineProperty(output, key, {
249
+ configurable: true,
250
+ enumerable: true,
251
+ value: visit(descriptor.value, depth + 1),
252
+ writable: true
253
+ });
254
+ }
255
+ return output;
89
256
  } finally {
90
257
  ancestors.delete(current);
91
258
  }
92
259
  };
93
- return visit(value, "$root");
260
+ return visit(value, 0);
261
+ }
262
+ function serializeSnapshot(value) {
263
+ if (value === null) return "null";
264
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
265
+ if (typeof value === "number") return JSON.stringify(value);
266
+ if (Array.isArray(value)) return `[${value.map(serializeSnapshot).join(",")}]`;
267
+ const input = value;
268
+ return `{${Object.keys(input).sort().map((key) => `${JSON.stringify(key)}:${serializeSnapshot(input[key])}`).join(",")}}`;
269
+ }
270
+ function canonicalizeGpuContract(value) {
271
+ return serializeSnapshot(snapshotGpuContract(value));
272
+ }
273
+ function canonicalizeQualificationGpuContract(value) {
274
+ return serializeSnapshot(snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS));
94
275
  }
95
276
 
96
277
  // src/codec/codec.ts
@@ -562,39 +743,41 @@ function modelProjection(manifest) {
562
743
  };
563
744
  }
564
745
  async function computeGpuAbiHash(input) {
565
- if (input.kind === "model") {
746
+ const snapshot = snapshotGpuContract(input);
747
+ if (snapshot.kind === "model") {
566
748
  return computeSha256(
567
749
  `plasius.gpu.model-abi/v1
568
- ${canonicalizeGpuContract(modelProjection(input.interface))}`
750
+ ${canonicalizeGpuContract(modelProjection(snapshot.interface))}`
569
751
  );
570
752
  }
571
- if (input.kind === "interface") {
753
+ if (snapshot.kind === "interface") {
572
754
  return computeSha256(
573
755
  `plasius.gpu.interface-abi/v1
574
- ${canonicalizeGpuContract(interfaceProjection(input.interface))}`
756
+ ${canonicalizeGpuContract(interfaceProjection(snapshot.interface))}`
575
757
  );
576
758
  }
577
759
  const pipelines = sorted(
578
- input.pipelines,
760
+ snapshot.pipelines,
579
761
  (left, right) => compareString(left.pipelineId, right.pipelineId)
580
762
  );
581
763
  const requirements = {
582
- semantics: [...input.requirements.semantics].sort(),
583
- features: [...input.requirements.features].sort(),
584
- limits: sorted(input.requirements.limits, (left, right) => compareString(left.name, right.name)),
585
- formats: [...input.requirements.formats].sort()
764
+ semantics: [...snapshot.requirements.semantics].sort(),
765
+ features: [...snapshot.requirements.features].sort(),
766
+ limits: sorted(snapshot.requirements.limits, (left, right) => compareString(left.name, right.name)),
767
+ formats: [...snapshot.requirements.formats].sort()
586
768
  };
587
769
  return computeSha256(
588
770
  `plasius.gpu.shader-abi/v1
589
771
  ${canonicalizeGpuContract({
590
- interface: interfaceProjection(input.interface),
772
+ interface: interfaceProjection(snapshot.interface),
591
773
  pipelines,
592
774
  requirements
593
775
  })}`
594
776
  );
595
777
  }
596
778
  async function computeShaderManifestCoreSha256(manifest) {
597
- const core = Object.fromEntries(Object.entries(manifest).filter(
779
+ const snapshot = snapshotGpuContract(manifest);
780
+ const core = Object.fromEntries(Object.entries(snapshot).filter(
598
781
  ([key]) => key !== "validationEvidence" && key !== "additionalValidationEvidence"
599
782
  ));
600
783
  return computeSha256(
@@ -974,11 +1157,10 @@ var stages = ["vertex", "fragment", "compute"];
974
1157
  var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
975
1158
  function detachedJson(value, path2) {
976
1159
  try {
977
- return JSON.parse(canonicalizeGpuContract(value));
1160
+ return snapshotGpuContract(value);
978
1161
  } catch (cause) {
979
- const detail = cause instanceof Error ? cause.message : "Contract snapshot failed.";
980
- const boundedDetail = [...detail].slice(0, 512).join("");
981
- throw new TypeError(`${path2} must contain detached JSON contract data: ${boundedDetail}`, { cause });
1162
+ const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
1163
+ throw new TypeError(`${path2} must contain bounded detached JSON contract data.${detail}`);
982
1164
  }
983
1165
  }
984
1166
  function object(value, path2) {
@@ -988,7 +1170,7 @@ function object(value, path2) {
988
1170
  function exact(value, keys2, path2) {
989
1171
  const allowed = new Set(keys2);
990
1172
  for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
991
- for (const key of keys2) if (!(key in value)) throw new TypeError(`${path2}.${key} is required.`);
1173
+ for (const key of keys2) if (!Object.hasOwn(value, key)) throw new TypeError(`${path2}.${key} is required.`);
992
1174
  }
993
1175
  function text(value, path2, maximum = 512) {
994
1176
  if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
@@ -1004,11 +1186,8 @@ function token(value, path2) {
1004
1186
  function immutableVersion(value, path2) {
1005
1187
  try {
1006
1188
  return assertImmutableAssetVersion(value);
1007
- } catch (cause) {
1008
- throw new TypeError(
1009
- `${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
1010
- { cause }
1011
- );
1189
+ } catch {
1190
+ throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
1012
1191
  }
1013
1192
  }
1014
1193
  function enumeration(value, values, path2) {
@@ -1038,8 +1217,8 @@ function nullableToken(value, path2) {
1038
1217
  function digest(value, path2) {
1039
1218
  try {
1040
1219
  return asSha256Hex(text(value, path2, 64));
1041
- } catch (cause) {
1042
- throw new TypeError(`${path2} must be a lowercase SHA-256 digest.`, { cause });
1220
+ } catch {
1221
+ throw new TypeError(`${path2} must be a lowercase SHA-256 digest.`);
1043
1222
  }
1044
1223
  }
1045
1224
  function uri(value, path2) {
@@ -1047,8 +1226,8 @@ function uri(value, path2) {
1047
1226
  let parsed;
1048
1227
  try {
1049
1228
  parsed = new URL(result);
1050
- } catch (cause) {
1051
- throw new TypeError(`${path2} must be an absolute immutable asset URI.`, { cause });
1229
+ } catch {
1230
+ throw new TypeError(`${path2} must be an absolute immutable asset URI.`);
1052
1231
  }
1053
1232
  if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash) throw new TypeError(`${path2} must be credential-free HTTPS without a fragment.`);
1054
1233
  const keys2 = [...parsed.searchParams.keys()].map((key) => key.toLowerCase());
@@ -1892,7 +2071,7 @@ function freezeJson(value) {
1892
2071
  }
1893
2072
  function exactKeys(value, keys2) {
1894
2073
  const expected = new Set(keys2);
1895
- return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => key in value);
2074
+ return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => Object.hasOwn(value, key));
1896
2075
  }
1897
2076
  function safeToken(value) {
1898
2077
  return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
@@ -1916,13 +2095,13 @@ function validSha(value) {
1916
2095
  function validateCompileUnitInventory(value) {
1917
2096
  let snapshot;
1918
2097
  try {
1919
- snapshot = JSON.parse(canonicalizeGpuContract(value));
1920
- } catch (cause) {
2098
+ snapshot = snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
2099
+ } catch {
1921
2100
  return {
1922
2101
  ok: false,
1923
2102
  diagnostics: [issue(
1924
2103
  "invalid-contract",
1925
- cause instanceof Error ? cause.message : "Compile-unit inventory must contain detached JSON data."
2104
+ "Compile-unit inventory must contain bounded detached JSON contract data."
1926
2105
  )]
1927
2106
  };
1928
2107
  }
@@ -2163,9 +2342,9 @@ function object3(value, path2) {
2163
2342
  }
2164
2343
  function detachedJson2(value, label) {
2165
2344
  try {
2166
- return JSON.parse(canonicalizeGpuContract(value));
2167
- } catch (cause) {
2168
- throw new TypeError(`${label} must contain detached JSON contract data.`, { cause });
2345
+ return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
2346
+ } catch {
2347
+ throw new TypeError(`${label} must contain bounded detached JSON contract data.`);
2169
2348
  }
2170
2349
  }
2171
2350
  function freezeJson2(value) {
@@ -2175,7 +2354,7 @@ function freezeJson2(value) {
2175
2354
  }
2176
2355
  function exact2(value, keys2, path2) {
2177
2356
  const expected = new Set(keys2);
2178
- if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
2357
+ 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.`);
2179
2358
  }
2180
2359
  function token2(value, path2) {
2181
2360
  if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
@@ -2184,11 +2363,8 @@ function token2(value, path2) {
2184
2363
  function immutableVersion3(value, path2) {
2185
2364
  try {
2186
2365
  return assertImmutableAssetVersion(value);
2187
- } catch (cause) {
2188
- throw new TypeError(
2189
- `${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
2190
- { cause }
2191
- );
2366
+ } catch {
2367
+ throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
2192
2368
  }
2193
2369
  }
2194
2370
  function path(value, label, extensions) {
@@ -2200,8 +2376,8 @@ function path(value, label, extensions) {
2200
2376
  function sha(value, label) {
2201
2377
  try {
2202
2378
  return asSha256Hex(String(value));
2203
- } catch (cause) {
2204
- throw new TypeError(`${label} must be a lowercase SHA-256 digest.`, { cause });
2379
+ } catch {
2380
+ throw new TypeError(`${label} must be a lowercase SHA-256 digest.`);
2205
2381
  }
2206
2382
  }
2207
2383
  function integer4(value, label, minimum = 0, maximum = 4294967295) {
@@ -2325,6 +2501,7 @@ function jsonValue(value, label, depth = 0) {
2325
2501
  }
2326
2502
  function validateQualificationFixture(value, unit) {
2327
2503
  try {
2504
+ const compileUnit = unit === void 0 ? void 0 : detachedJson2(unit, "compile unit");
2328
2505
  const fixture = object3(detachedJson2(value, "fixture"), "fixture");
2329
2506
  exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
2330
2507
  if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
@@ -2455,14 +2632,14 @@ function validateQualificationFixture(value, unit) {
2455
2632
  unique2(bindingIds, `${label}.entries`);
2456
2633
  bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
2457
2634
  }
2458
- const pipelines = new Map(unit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
2635
+ const pipelines = new Map(compileUnit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
2459
2636
  const pipelineIds = new Set(pipelines.keys());
2460
2637
  const commandBindGroups = (value2, pipelineId, label) => {
2461
2638
  const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
2462
2639
  unique2(ids, label);
2463
2640
  const pipeline2 = pipelines.get(pipelineId);
2464
2641
  if (!pipeline2) {
2465
- if (unit) throw new TypeError(`${label} pipeline is missing.`);
2642
+ if (compileUnit) throw new TypeError(`${label} pipeline is missing.`);
2466
2643
  return;
2467
2644
  }
2468
2645
  const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
@@ -2487,7 +2664,7 @@ function validateQualificationFixture(value, unit) {
2487
2664
  executionCommands += 1;
2488
2665
  exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
2489
2666
  const id = token2(command.pipelineId, `${label}.pipelineId`);
2490
- if (unit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
2667
+ if (compileUnit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
2491
2668
  commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
2492
2669
  const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
2493
2670
  if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
@@ -8867,7 +9044,7 @@ function validatePipelineInterfaces(input) {
8867
9044
  // package.json
8868
9045
  var package_default = {
8869
9046
  name: "@plasius/gpu-shader",
8870
- version: "0.1.2",
9047
+ version: "0.1.3",
8871
9048
  description: "Reflection-first WebGPU WGSL interfaces, CPU codecs, compatibility validation, style profiles, and qualification tooling",
8872
9049
  type: "module",
8873
9050
  sideEffects: false,
@@ -8959,6 +9136,7 @@ var package_default = {
8959
9136
  access: "public"
8960
9137
  },
8961
9138
  overrides: {
9139
+ esbuild: "^0.28.1",
8962
9140
  minimatch: "^10.2.1"
8963
9141
  },
8964
9142
  engines: {
@@ -10130,7 +10308,37 @@ function object4(value, path2) {
10130
10308
  }
10131
10309
  function exact3(value, keys2, path2) {
10132
10310
  const expected = new Set(keys2);
10133
- if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
10311
+ 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.`);
10312
+ }
10313
+ function detachedQualificationContract(value) {
10314
+ try {
10315
+ return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
10316
+ } catch {
10317
+ throw new TypeError("Qualification data must contain bounded detached JSON contract data.");
10318
+ }
10319
+ }
10320
+ function parseQualificationJsonBytes(bytes2, label) {
10321
+ let snapshot;
10322
+ try {
10323
+ snapshot = snapshotUint8Array(
10324
+ bytes2,
10325
+ QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
10326
+ );
10327
+ } catch {
10328
+ throw new TypeError(`${label} is not bounded UTF-8 JSON.`);
10329
+ }
10330
+ let parsed;
10331
+ try {
10332
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
10333
+ } catch {
10334
+ throw new TypeError(`${label} is not valid UTF-8 JSON.`);
10335
+ }
10336
+ return detachedQualificationContract(parsed);
10337
+ }
10338
+ function freezeJson3(value) {
10339
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
10340
+ for (const child of Object.values(value)) freezeJson3(child);
10341
+ return Object.freeze(value);
10134
10342
  }
10135
10343
  function token3(value, path2, maximum = 512) {
10136
10344
  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.`);
@@ -10139,8 +10347,8 @@ function token3(value, path2, maximum = 512) {
10139
10347
  function sha2(value, path2) {
10140
10348
  try {
10141
10349
  return asSha256Hex(token3(value, path2, 64));
10142
- } catch (cause) {
10143
- throw new TypeError(`${path2} is not a SHA-256 digest.`, { cause });
10350
+ } catch {
10351
+ throw new TypeError(`${path2} is not a SHA-256 digest.`);
10144
10352
  }
10145
10353
  }
10146
10354
  function integer5(value, path2, minimum = 0) {
@@ -10173,7 +10381,7 @@ function trustedWorkflowRef(value, path2) {
10173
10381
  return result;
10174
10382
  }
10175
10383
  function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
10176
- const input = object4(value, path2);
10384
+ const input = object4(detachedQualificationContract(value), path2);
10177
10385
  exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
10178
10386
  const repository = token3(input.repository, `${path2}.repository`);
10179
10387
  if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
@@ -10192,10 +10400,10 @@ function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
10192
10400
  token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
10193
10401
  sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
10194
10402
  timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
10195
- return input;
10403
+ return freezeJson3(input);
10196
10404
  }
10197
10405
  function parseQualificationExecutionProducer(value, path2 = "producer") {
10198
- const input = object4(value, path2);
10406
+ const input = object4(detachedQualificationContract(value), path2);
10199
10407
  exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
10200
10408
  const repository = token3(input.repository, `${path2}.repository`);
10201
10409
  if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
@@ -10213,7 +10421,7 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
10213
10421
  if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
10214
10422
  token3(runner.os, `${path2}.runner.os`);
10215
10423
  token3(runner.architecture, `${path2}.runner.architecture`);
10216
- return input;
10424
+ return freezeJson3(input);
10217
10425
  }
10218
10426
  function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
10219
10427
  if (producer.repository !== provenance.repository || !canonicalEqual(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 || !canonicalEqual(producer.trustedWorkflowSha, provenance.workflowSha) || producer.job !== expectedJob) throw new TypeError(`${path2} does not match the exact qualification workflow run or subject.`);
@@ -10222,26 +10430,32 @@ function assertProducerMatchesPreflight(producer, provenance, cell, path2, expec
10222
10430
  if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
10223
10431
  }
10224
10432
  function canonicalEqual(left, right) {
10225
- return canonicalizeGpuContract(left) === canonicalizeGpuContract(right);
10433
+ return canonicalizeQualificationGpuContract(left) === canonicalizeQualificationGpuContract(right);
10226
10434
  }
10227
10435
  function foldRunnerLabel(value) {
10228
10436
  return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
10229
10437
  }
10230
10438
  async function computeQualificationInventorySha256(bundle) {
10231
- return computeSha256(canonicalizeGpuContract(bundle.inventory));
10439
+ const snapshot = detachedQualificationContract(bundle);
10440
+ return computeSha256(canonicalizeQualificationGpuContract(snapshot.inventory));
10232
10441
  }
10233
10442
  async function computeQualificationSubjectBinding(input) {
10234
10443
  return computeSha256(`plasius.gpu.qualification-subject/v1
10235
- ${canonicalizeGpuContract(input)}`);
10444
+ ${canonicalizeQualificationGpuContract(input)}`);
10236
10445
  }
10237
10446
  async function computeValidationEvidenceId(value) {
10238
10447
  const input = object4(value, "evidence identity input");
10239
10448
  const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
10240
10449
  return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
10241
- ${canonicalizeGpuContract(projection)}`)).slice(0, 24)}`;
10450
+ ${canonicalizeQualificationGpuContract(projection)}`)).slice(0, 24)}`;
10242
10451
  }
10243
10452
  function immutableBlobUri(value) {
10244
- const url = new URL(value);
10453
+ let url;
10454
+ try {
10455
+ url = new URL(value);
10456
+ } catch {
10457
+ throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
10458
+ }
10245
10459
  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 === ".."))) {
10246
10460
  throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
10247
10461
  }
@@ -10251,12 +10465,7 @@ function immutableBlobUri(value) {
10251
10465
  }
10252
10466
  async function createQualificationPreflight(input) {
10253
10467
  token3(input.qualificationId, "qualificationId");
10254
- let parsedMatrix;
10255
- try {
10256
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10257
- } catch (cause) {
10258
- throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
10259
- }
10468
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Selected matrix artifact");
10260
10469
  if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
10261
10470
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
10262
10471
  if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
@@ -10426,12 +10635,7 @@ function syntheticResult(unitId, cell, status, message, now) {
10426
10635
  async function aggregateShaderValidationEvidence(input) {
10427
10636
  const verifyArtifact = async (artifact2, label) => {
10428
10637
  if (await computeSha256(artifact2.bytes) !== artifact2.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
10429
- let parsed;
10430
- try {
10431
- parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact2.bytes));
10432
- } catch (cause) {
10433
- throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
10434
- }
10638
+ const parsed = parseQualificationJsonBytes(artifact2.bytes, `${label} bytes`);
10435
10639
  if (!canonicalEqual(parsed, artifact2.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
10436
10640
  };
10437
10641
  await verifyArtifact(input.preflight, "Qualification preflight");
@@ -10453,12 +10657,7 @@ async function aggregateShaderValidationEvidence(input) {
10453
10657
  exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
10454
10658
  const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
10455
10659
  if (!canonicalEqual(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
10456
- let parsedMatrix;
10457
- try {
10458
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10459
- } catch (cause) {
10460
- throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
10461
- }
10660
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
10462
10661
  if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10463
10662
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
10464
10663
  if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
@@ -10532,7 +10731,7 @@ async function aggregateShaderValidationEvidence(input) {
10532
10731
  if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
10533
10732
  for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
10534
10733
  const cellResults = results.slice(-units.size);
10535
- cellRuns.push({ cellId: cell.cellId, source: "runner-preflight", sourceArtifactSha256: runner.sha256, resultsSha256: await computeSha256(canonicalizeGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: runner.value.producer, harness: input.harness, automation: null, resultCount: units.size, status: "runner-unavailable" });
10734
+ 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" });
10536
10735
  continue;
10537
10736
  }
10538
10737
  if (diagnostic) {
@@ -10547,7 +10746,7 @@ async function aggregateShaderValidationEvidence(input) {
10547
10746
  const status2 = value2.status === "timeout" ? "timeout" : "failed";
10548
10747
  for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
10549
10748
  const cellResults = results.slice(-units.size);
10550
- cellRuns.push({ cellId: cell.cellId, source: "workflow-diagnostic", sourceArtifactSha256: diagnostic.sha256, resultsSha256: await computeSha256(canonicalizeGpuContract(cellResults)), qualificationPreflightProvenance: preflight.provenance, producer: value2.producer, harness: input.harness, automation: null, resultCount: units.size, status: status2 });
10749
+ 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 });
10551
10750
  continue;
10552
10751
  }
10553
10752
  if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
@@ -10555,7 +10754,7 @@ async function aggregateShaderValidationEvidence(input) {
10555
10754
  if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
10556
10755
  const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
10557
10756
  results.push(...value.results);
10558
- cellRuns.push({ cellId: cell.cellId, source: "cell-evidence", sourceArtifactSha256: cellArtifact.sha256, resultsSha256: await computeSha256(canonicalizeGpuContract(value.results)), qualificationPreflightProvenance: value.qualificationPreflightProvenance, producer: value.producer, harness: value.harness, automation: value.automation, resultCount: value.results.length, status: "passed" });
10757
+ 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" });
10559
10758
  }
10560
10759
  const expectedResults = units.size * cells.size;
10561
10760
  if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
@@ -10578,34 +10777,31 @@ async function aggregateShaderValidationEvidence(input) {
10578
10777
  }
10579
10778
  async function validateShaderValidationEvidence(input) {
10580
10779
  try {
10581
- const evidence = object4(input.evidence, "evidence");
10780
+ const evidence = object4(detachedQualificationContract(input.evidence), "evidence");
10781
+ const bundle = detachedQualificationContract(input.bundle);
10782
+ const matrix = detachedQualificationContract(input.matrix);
10582
10783
  exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
10583
10784
  if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
10584
10785
  const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
10585
10786
  const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
10586
10787
  const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
10587
10788
  if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
10588
- let parsedMatrix;
10589
- try {
10590
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10591
- } catch (cause) {
10592
- throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
10593
- }
10594
- if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10789
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
10790
+ if (!canonicalEqual(parsedMatrix, matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10595
10791
  const matrixSha256 = await computeSha256(input.matrixBytes);
10596
- const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
10597
- if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
10792
+ const inventorySha256 = await computeQualificationInventorySha256(bundle);
10793
+ if (inventorySha256 !== bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
10598
10794
  const subject = object4(evidence.subject, "evidence.subject");
10599
- const expectedSubjectKeys = [...Object.keys(input.bundle.subject), "dataBundleSha256"];
10795
+ const expectedSubjectKeys = [...Object.keys(bundle.subject), "dataBundleSha256"];
10600
10796
  exact3(subject, expectedSubjectKeys, "evidence.subject");
10601
10797
  const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
10602
- if (!canonicalEqual(candidateSubject, input.bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
10798
+ if (!canonicalEqual(candidateSubject, bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
10603
10799
  const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
10604
10800
  if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
10605
10801
  if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
10606
10802
  const matrixRef = object4(evidence.matrixRef, "evidence.matrixRef");
10607
10803
  exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
10608
- if (matrixRef.matrixId !== input.matrix.matrixId || matrixRef.version !== input.matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
10804
+ if (matrixRef.matrixId !== matrix.matrixId || matrixRef.version !== matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
10609
10805
  const toolchain = object4(evidence.toolchain, "evidence.toolchain");
10610
10806
  exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
10611
10807
  token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
@@ -10617,11 +10813,11 @@ async function validateShaderValidationEvidence(input) {
10617
10813
  const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
10618
10814
  const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
10619
10815
  if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
10620
- const expectedBinding = await computeQualificationSubjectBinding({ subject: input.bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
10816
+ const expectedBinding = await computeQualificationSubjectBinding({ subject: bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
10621
10817
  if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
10622
10818
  if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
10623
- const units = new Set(input.bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
10624
- const cells = new Map(input.matrix.cells.map((cell) => [cell.cellId, cell]));
10819
+ const units = new Set(bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
10820
+ const cells = new Map(matrix.cells.map((cell) => [cell.cellId, cell]));
10625
10821
  const expected = units.size * cells.size;
10626
10822
  const results = array2(evidence.results, "evidence.results");
10627
10823
  if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
@@ -10671,7 +10867,7 @@ async function validateShaderValidationEvidence(input) {
10671
10867
  sha2(automation2.sha256, `${path2}.automation.sha256`);
10672
10868
  } else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
10673
10869
  const cellResults = parsedResults.filter((result) => result.cellId === cellId);
10674
- if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
10870
+ if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeQualificationGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
10675
10871
  const resultStatuses = new Set(cellResults.map((result) => result.status));
10676
10872
  if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
10677
10873
  if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
@@ -10680,7 +10876,7 @@ async function validateShaderValidationEvidence(input) {
10680
10876
  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.`);
10681
10877
  }
10682
10878
  if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
10683
- return { ok: true, value: evidence };
10879
+ return { ok: true, value: freezeJson3(evidence) };
10684
10880
  } catch (cause) {
10685
10881
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
10686
10882
  }
@@ -10695,7 +10891,12 @@ function object5(value) {
10695
10891
  }
10696
10892
  function keys(value, expected) {
10697
10893
  const set = new Set(expected);
10698
- return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key in value);
10894
+ return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => Object.hasOwn(value, key));
10895
+ }
10896
+ function freezeJson4(value) {
10897
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
10898
+ for (const child of Object.values(value)) freezeJson4(child);
10899
+ return Object.freeze(value);
10699
10900
  }
10700
10901
  function canonicalEqual2(left, right) {
10701
10902
  try {
@@ -10745,7 +10946,13 @@ var BASELINE = /* @__PURE__ */ new Map([
10745
10946
  ["win11-nvidia-edge-d3d12", "edge|windows|x64|physical|nvidia|qualified-nvidia|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-nvidia,d3d12"]
10746
10947
  ]);
10747
10948
  function validateStableWebGpuMatrix(value) {
10748
- const matrix = object5(value);
10949
+ let snapshot;
10950
+ try {
10951
+ snapshot = snapshotGpuContract(value);
10952
+ } catch {
10953
+ return { ok: false, diagnostics: [issue3("Matrix must contain bounded detached JSON contract data.")] };
10954
+ }
10955
+ const matrix = object5(snapshot);
10749
10956
  const diagnostics = [];
10750
10957
  if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
10751
10958
  return { ok: false, diagnostics: [issue3("Matrix has unknown or missing top-level fields.")] };
@@ -10818,7 +11025,7 @@ function validateStableWebGpuMatrix(value) {
10818
11025
  }
10819
11026
  }
10820
11027
  if (physical !== 15 || blocking !== 16 || software !== 1 || ids.size !== BASELINE.size) diagnostics.push(issue3("Matrix must contain the exact 15 physical baseline cells plus one SwiftShader smoke cell."));
10821
- return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
11028
+ return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson4(matrix) };
10822
11029
  }
10823
11030
 
10824
11031
  // src/testing/runner/playwright-swiftshader.ts
@@ -12127,9 +12334,6 @@ function error(code, message, path2) {
12127
12334
  function interfaceMatches(item, model) {
12128
12335
  return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
12129
12336
  }
12130
- function detachedContract(value) {
12131
- return JSON.parse(canonicalizeGpuContract(value));
12132
- }
12133
12337
  function hasValidationEvidence(value) {
12134
12338
  return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
12135
12339
  }
@@ -12177,16 +12381,25 @@ function validateModelShaderCompatibility(input) {
12177
12381
  let profile;
12178
12382
  let capabilities;
12179
12383
  try {
12180
- const modelSnapshot = detachedContract(input.model);
12181
- const shaderSnapshot = detachedContract(input.shader);
12182
- const gpuInterfaceSnapshot = detachedContract(input.gpuInterface);
12183
- const profileValue = input.profile;
12184
- const profileSnapshot = profileValue === void 0 ? void 0 : detachedContract(profileValue);
12384
+ const snapshot = snapshotGpuContract(input);
12385
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
12386
+ throw new TypeError("GPU compatibility input must be a bounded contract object.");
12387
+ }
12388
+ const envelope = snapshot;
12389
+ const keys2 = Object.keys(envelope);
12390
+ const allowed = /* @__PURE__ */ new Set(["model", "shader", "gpuInterface", "profile", "capabilities"]);
12391
+ if (keys2.some((key) => !allowed.has(key)) || !["model", "shader", "gpuInterface"].every((key) => Object.hasOwn(envelope, key))) {
12392
+ throw new TypeError("GPU compatibility input has unknown or missing fields.");
12393
+ }
12394
+ const modelSnapshot = envelope.model;
12395
+ const shaderSnapshot = envelope.shader;
12396
+ const gpuInterfaceSnapshot = envelope.gpuInterface;
12397
+ const profileSnapshot = Object.hasOwn(envelope, "profile") ? envelope.profile : void 0;
12185
12398
  model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
12186
12399
  shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
12187
12400
  gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
12188
12401
  profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
12189
- capabilities = input.capabilities;
12402
+ capabilities = Object.hasOwn(envelope, "capabilities") ? envelope.capabilities : void 0;
12190
12403
  } catch (cause) {
12191
12404
  return {
12192
12405
  ok: false,