@plasius/gpu-shader 0.1.2 → 0.1.4

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.js CHANGED
@@ -11,63 +11,244 @@ import { readdir, readFile, lstat } from "fs/promises";
11
11
  import { join, relative, resolve, sep } from "path";
12
12
 
13
13
  // src/canonical-json.ts
14
- function isPlainObject(value) {
15
- const prototype = Object.getPrototypeOf(value);
16
- return prototype === Object.prototype || prototype === null;
14
+ var GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
15
+ maximumDepth: 64,
16
+ maximumNodes: 262144,
17
+ maximumProperties: 131072,
18
+ maximumElements: 131072,
19
+ maximumArrayLength: 1e5,
20
+ maximumStringBytes: 1024 * 1024,
21
+ maximumAggregateStringBytes: 8 * 1024 * 1024,
22
+ maximumAggregateBytes: 16 * 1024 * 1024,
23
+ maximumInputBytes: 16 * 1024 * 1024
24
+ });
25
+ var QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
26
+ maximumDepth: 96,
27
+ maximumNodes: 4e6,
28
+ maximumProperties: 2e6,
29
+ maximumElements: 2e6,
30
+ maximumArrayLength: 25e4,
31
+ maximumStringBytes: 4 * 1024 * 1024,
32
+ maximumAggregateStringBytes: 128 * 1024 * 1024,
33
+ maximumAggregateBytes: 256 * 1024 * 1024,
34
+ maximumInputBytes: 256 * 1024 * 1024
35
+ });
36
+ var FAILURE_MESSAGES = Object.freeze({
37
+ "aggregate-bytes": "GPU contract snapshot exceeds the aggregate byte limit.",
38
+ "aggregate-string-bytes": "GPU contract snapshot exceeds the aggregate string byte limit.",
39
+ "array-length": "GPU contract snapshot exceeds the single-array element limit.",
40
+ cycle: "GPU contract snapshot contains a circular reference.",
41
+ depth: "GPU contract snapshot exceeds the nesting-depth limit.",
42
+ elements: "GPU contract snapshot exceeds the total element limit.",
43
+ inspection: "GPU contract snapshot rejected unsafe object inspection.",
44
+ nodes: "GPU contract snapshot exceeds the total node limit.",
45
+ "non-finite": "GPU contract snapshot contains a non-finite number.",
46
+ properties: "GPU contract snapshot exceeds the total property limit.",
47
+ shape: "GPU contract snapshot requires plain JSON objects with own enumerable data properties and dense arrays.",
48
+ "string-bytes": "GPU contract snapshot exceeds the individual string byte limit.",
49
+ unicode: "GPU contract snapshot contains an invalid Unicode scalar string or unpaired UTF-16 surrogate.",
50
+ value: "GPU contract snapshot contains undefined or another value that JSON cannot represent."
51
+ });
52
+ var GpuContractSnapshotError = class extends TypeError {
53
+ code;
54
+ constructor(code) {
55
+ super(FAILURE_MESSAGES[code]);
56
+ this.name = "GpuContractSnapshotError";
57
+ this.code = code;
58
+ }
59
+ };
60
+ var TYPED_ARRAY_PROTOTYPE = Reflect.getPrototypeOf(Uint8Array.prototype);
61
+ var TYPED_ARRAY_BYTE_LENGTH = Reflect.getOwnPropertyDescriptor(
62
+ TYPED_ARRAY_PROTOTYPE,
63
+ "byteLength"
64
+ )?.get;
65
+ var TYPED_ARRAY_TAG = Reflect.getOwnPropertyDescriptor(
66
+ TYPED_ARRAY_PROTOTYPE,
67
+ Symbol.toStringTag
68
+ )?.get;
69
+ var UINT8_ARRAY_SET = Uint8Array.prototype.set;
70
+ function snapshotUint8Array(value, maximumBytes) {
71
+ if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
72
+ throw new TypeError("GPU contract byte limit must be a non-negative safe integer.");
73
+ }
74
+ let byteLength;
75
+ let tag;
76
+ try {
77
+ if (!TYPED_ARRAY_BYTE_LENGTH || !TYPED_ARRAY_TAG) throw new TypeError();
78
+ byteLength = Reflect.apply(TYPED_ARRAY_BYTE_LENGTH, value, []);
79
+ tag = Reflect.apply(TYPED_ARRAY_TAG, value, []);
80
+ } catch {
81
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
82
+ }
83
+ if (tag !== "Uint8Array" || !Number.isSafeInteger(byteLength) || byteLength > maximumBytes) {
84
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
85
+ }
86
+ const output = new Uint8Array(byteLength);
87
+ try {
88
+ Reflect.apply(UINT8_ARRAY_SET, output, [value]);
89
+ } catch {
90
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
91
+ }
92
+ return output;
93
+ }
94
+ function fail(reason) {
95
+ throw new GpuContractSnapshotError(reason);
17
96
  }
18
- function assertUnicodeScalarString(value, path2) {
97
+ function inspected(operation) {
98
+ try {
99
+ return operation();
100
+ } catch {
101
+ return fail("inspection");
102
+ }
103
+ }
104
+ function assertLimit(value, maximum, reason) {
105
+ if (!Number.isSafeInteger(value) || value > maximum) fail(reason);
106
+ }
107
+ function quotedJsonByteLength(value, maximum) {
108
+ let raw = 0;
109
+ let quoted = 2;
19
110
  for (let index = 0; index < value.length; index += 1) {
20
111
  const code = value.charCodeAt(index);
21
- if (code >= 55296 && code <= 56319) {
112
+ if (code <= 127) {
113
+ raw += 1;
114
+ if (code <= 31) quoted += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
115
+ else quoted += code === 34 || code === 92 ? 2 : 1;
116
+ } else if (code <= 2047) {
117
+ raw += 2;
118
+ quoted += 2;
119
+ } else if (code >= 55296 && code <= 56319) {
22
120
  const next = value.charCodeAt(index + 1);
23
- if (!(next >= 56320 && next <= 57343)) throw new TypeError(`${path2} contains an unpaired UTF-16 surrogate.`);
121
+ if (!(next >= 56320 && next <= 57343)) fail("unicode");
122
+ raw += 4;
123
+ quoted += 4;
24
124
  index += 1;
25
- } else if (code >= 56320 && code <= 57343) throw new TypeError(`${path2} contains an unpaired UTF-16 surrogate.`);
125
+ } else if (code >= 56320 && code <= 57343) fail("unicode");
126
+ else {
127
+ raw += 3;
128
+ quoted += 3;
129
+ }
130
+ if (raw > maximum) fail("string-bytes");
26
131
  }
132
+ return { raw, quoted };
27
133
  }
28
- function canonicalizeGpuContract(value) {
134
+ function assertLimits(limits) {
135
+ for (const value of Object.values(limits)) {
136
+ if (!Number.isSafeInteger(value) || value < 1) throw new TypeError("GPU contract snapshot limits must be positive safe integers.");
137
+ }
138
+ }
139
+ function snapshotGpuContract(value, limits = GPU_CONTRACT_SNAPSHOT_LIMITS) {
140
+ assertLimits(limits);
29
141
  const ancestors = /* @__PURE__ */ new Set();
30
- const visit = (current, path2) => {
31
- if (current === null) return "null";
32
- if (typeof current === "string" || typeof current === "boolean") {
33
- if (typeof current === "string") assertUnicodeScalarString(current, path2);
34
- return JSON.stringify(current);
142
+ let nodes = 0;
143
+ let properties = 0;
144
+ let elements = 0;
145
+ let aggregateStringBytes = 0;
146
+ let aggregateBytes = 0;
147
+ const addAggregate = (bytes2) => {
148
+ aggregateBytes += bytes2;
149
+ assertLimit(aggregateBytes, limits.maximumAggregateBytes, "aggregate-bytes");
150
+ };
151
+ const addString = (text2) => {
152
+ const measured = quotedJsonByteLength(text2, limits.maximumStringBytes);
153
+ aggregateStringBytes += measured.raw;
154
+ assertLimit(aggregateStringBytes, limits.maximumAggregateStringBytes, "aggregate-string-bytes");
155
+ return measured.quoted;
156
+ };
157
+ const visit = (current, depth) => {
158
+ if (depth > limits.maximumDepth) fail("depth");
159
+ nodes += 1;
160
+ assertLimit(nodes, limits.maximumNodes, "nodes");
161
+ if (current === null) {
162
+ addAggregate(4);
163
+ return null;
164
+ }
165
+ if (typeof current === "string") {
166
+ addAggregate(addString(current));
167
+ return current;
168
+ }
169
+ if (typeof current === "boolean") {
170
+ addAggregate(current ? 4 : 5);
171
+ return current;
35
172
  }
36
173
  if (typeof current === "number") {
37
- if (!Number.isFinite(current)) {
38
- throw new TypeError(`${path2} contains a non-finite number.`);
39
- }
40
- return Object.is(current, -0) ? "0" : JSON.stringify(current);
41
- }
42
- if (typeof current !== "object") {
43
- throw new TypeError(`${path2} contains a value that JSON cannot represent.`);
44
- }
45
- if (ancestors.has(current)) {
46
- throw new TypeError(`${path2} contains a circular reference.`);
47
- }
174
+ if (!Number.isFinite(current)) fail("non-finite");
175
+ const normalized = Object.is(current, -0) ? 0 : current;
176
+ addAggregate(JSON.stringify(normalized).length);
177
+ return normalized;
178
+ }
179
+ if (typeof current !== "object") fail("value");
180
+ if (ancestors.has(current)) fail("cycle");
181
+ const isArray = inspected(() => Array.isArray(current));
182
+ const prototype = inspected(() => Reflect.getPrototypeOf(current));
183
+ if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) fail("shape");
48
184
  ancestors.add(current);
49
185
  try {
50
- if (Array.isArray(current)) {
51
- return `[${current.map((item, index) => visit(item, `${path2}[${index}]`)).join(",")}]`;
52
- }
53
- if (!isPlainObject(current)) {
54
- throw new TypeError(`${path2} must contain only plain JSON objects.`);
55
- }
56
- const keys2 = Object.keys(current).sort();
57
- const properties = keys2.map((key) => {
58
- assertUnicodeScalarString(key, `${path2} key`);
59
- const member = current[key];
60
- if (member === void 0) {
61
- throw new TypeError(`${path2}.${key} is undefined.`);
186
+ if (isArray) {
187
+ const lengthDescriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, "length"));
188
+ if (!lengthDescriptor || !Object.hasOwn(lengthDescriptor, "value") || lengthDescriptor.enumerable || typeof lengthDescriptor.value !== "number" || !Number.isSafeInteger(lengthDescriptor.value) || lengthDescriptor.value < 0) fail("shape");
189
+ const length = lengthDescriptor.value;
190
+ assertLimit(length, limits.maximumArrayLength, "array-length");
191
+ elements += length;
192
+ assertLimit(elements, limits.maximumElements, "elements");
193
+ const ownKeys2 = inspected(() => Reflect.ownKeys(current));
194
+ if (ownKeys2.some((key) => typeof key !== "string")) fail("shape");
195
+ if (ownKeys2.length !== length + 1) fail("shape");
196
+ const keySet = new Set(ownKeys2);
197
+ if (!keySet.delete("length")) fail("shape");
198
+ const output2 = new Array(length);
199
+ addAggregate(2 + Math.max(0, length - 1));
200
+ for (let index = 0; index < length; index += 1) {
201
+ const key = String(index);
202
+ if (!keySet.delete(key)) fail("shape");
203
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
204
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
205
+ Object.defineProperty(output2, key, {
206
+ configurable: true,
207
+ enumerable: true,
208
+ value: visit(descriptor.value, depth + 1),
209
+ writable: true
210
+ });
62
211
  }
63
- return `${JSON.stringify(key)}:${visit(member, `${path2}.${key}`)}`;
64
- });
65
- return `{${properties.join(",")}}`;
212
+ if (keySet.size !== 0) fail("shape");
213
+ return output2;
214
+ }
215
+ const ownKeys = inspected(() => Reflect.ownKeys(current));
216
+ if (ownKeys.some((key) => typeof key !== "string")) fail("shape");
217
+ properties += ownKeys.length;
218
+ assertLimit(properties, limits.maximumProperties, "properties");
219
+ addAggregate(2 + Math.max(0, ownKeys.length - 1) + ownKeys.length);
220
+ const output = {};
221
+ for (const key of ownKeys) {
222
+ addAggregate(addString(key));
223
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
224
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
225
+ Object.defineProperty(output, key, {
226
+ configurable: true,
227
+ enumerable: true,
228
+ value: visit(descriptor.value, depth + 1),
229
+ writable: true
230
+ });
231
+ }
232
+ return output;
66
233
  } finally {
67
234
  ancestors.delete(current);
68
235
  }
69
236
  };
70
- return visit(value, "$root");
237
+ return visit(value, 0);
238
+ }
239
+ function serializeSnapshot(value) {
240
+ if (value === null) return "null";
241
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
242
+ if (typeof value === "number") return JSON.stringify(value);
243
+ if (Array.isArray(value)) return `[${value.map(serializeSnapshot).join(",")}]`;
244
+ const input = value;
245
+ return `{${Object.keys(input).sort().map((key) => `${JSON.stringify(key)}:${serializeSnapshot(input[key])}`).join(",")}}`;
246
+ }
247
+ function canonicalizeGpuContract(value) {
248
+ return serializeSnapshot(snapshotGpuContract(value));
249
+ }
250
+ function canonicalizeQualificationGpuContract(value) {
251
+ return serializeSnapshot(snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS));
71
252
  }
72
253
 
73
254
  // src/codec/codec.ts
@@ -539,39 +720,41 @@ function modelProjection(manifest) {
539
720
  };
540
721
  }
541
722
  async function computeGpuAbiHash(input) {
542
- if (input.kind === "model") {
723
+ const snapshot = snapshotGpuContract(input);
724
+ if (snapshot.kind === "model") {
543
725
  return computeSha256(
544
726
  `plasius.gpu.model-abi/v1
545
- ${canonicalizeGpuContract(modelProjection(input.interface))}`
727
+ ${canonicalizeGpuContract(modelProjection(snapshot.interface))}`
546
728
  );
547
729
  }
548
- if (input.kind === "interface") {
730
+ if (snapshot.kind === "interface") {
549
731
  return computeSha256(
550
732
  `plasius.gpu.interface-abi/v1
551
- ${canonicalizeGpuContract(interfaceProjection(input.interface))}`
733
+ ${canonicalizeGpuContract(interfaceProjection(snapshot.interface))}`
552
734
  );
553
735
  }
554
736
  const pipelines = sorted(
555
- input.pipelines,
737
+ snapshot.pipelines,
556
738
  (left, right) => compareString(left.pipelineId, right.pipelineId)
557
739
  );
558
740
  const requirements = {
559
- semantics: [...input.requirements.semantics].sort(),
560
- features: [...input.requirements.features].sort(),
561
- limits: sorted(input.requirements.limits, (left, right) => compareString(left.name, right.name)),
562
- formats: [...input.requirements.formats].sort()
741
+ semantics: [...snapshot.requirements.semantics].sort(),
742
+ features: [...snapshot.requirements.features].sort(),
743
+ limits: sorted(snapshot.requirements.limits, (left, right) => compareString(left.name, right.name)),
744
+ formats: [...snapshot.requirements.formats].sort()
563
745
  };
564
746
  return computeSha256(
565
747
  `plasius.gpu.shader-abi/v1
566
748
  ${canonicalizeGpuContract({
567
- interface: interfaceProjection(input.interface),
749
+ interface: interfaceProjection(snapshot.interface),
568
750
  pipelines,
569
751
  requirements
570
752
  })}`
571
753
  );
572
754
  }
573
755
  async function computeShaderManifestCoreSha256(manifest) {
574
- const core = Object.fromEntries(Object.entries(manifest).filter(
756
+ const snapshot = snapshotGpuContract(manifest);
757
+ const core = Object.fromEntries(Object.entries(snapshot).filter(
575
758
  ([key]) => key !== "validationEvidence" && key !== "additionalValidationEvidence"
576
759
  ));
577
760
  return computeSha256(
@@ -951,11 +1134,10 @@ var stages = ["vertex", "fragment", "compute"];
951
1134
  var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
952
1135
  function detachedJson(value, path2) {
953
1136
  try {
954
- return JSON.parse(canonicalizeGpuContract(value));
1137
+ return snapshotGpuContract(value);
955
1138
  } catch (cause) {
956
- const detail = cause instanceof Error ? cause.message : "Contract snapshot failed.";
957
- const boundedDetail = [...detail].slice(0, 512).join("");
958
- throw new TypeError(`${path2} must contain detached JSON contract data: ${boundedDetail}`, { cause });
1139
+ const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
1140
+ throw new TypeError(`${path2} must contain bounded detached JSON contract data.${detail}`);
959
1141
  }
960
1142
  }
961
1143
  function object(value, path2) {
@@ -965,7 +1147,7 @@ function object(value, path2) {
965
1147
  function exact(value, keys2, path2) {
966
1148
  const allowed = new Set(keys2);
967
1149
  for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
968
- for (const key of keys2) if (!(key in value)) throw new TypeError(`${path2}.${key} is required.`);
1150
+ for (const key of keys2) if (!Object.hasOwn(value, key)) throw new TypeError(`${path2}.${key} is required.`);
969
1151
  }
970
1152
  function text(value, path2, maximum = 512) {
971
1153
  if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
@@ -981,11 +1163,8 @@ function token(value, path2) {
981
1163
  function immutableVersion(value, path2) {
982
1164
  try {
983
1165
  return assertImmutableAssetVersion(value);
984
- } catch (cause) {
985
- throw new TypeError(
986
- `${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
987
- { cause }
988
- );
1166
+ } catch {
1167
+ throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
989
1168
  }
990
1169
  }
991
1170
  function enumeration(value, values, path2) {
@@ -1015,8 +1194,8 @@ function nullableToken(value, path2) {
1015
1194
  function digest(value, path2) {
1016
1195
  try {
1017
1196
  return asSha256Hex(text(value, path2, 64));
1018
- } catch (cause) {
1019
- throw new TypeError(`${path2} must be a lowercase SHA-256 digest.`, { cause });
1197
+ } catch {
1198
+ throw new TypeError(`${path2} must be a lowercase SHA-256 digest.`);
1020
1199
  }
1021
1200
  }
1022
1201
  function uri(value, path2) {
@@ -1024,8 +1203,8 @@ function uri(value, path2) {
1024
1203
  let parsed;
1025
1204
  try {
1026
1205
  parsed = new URL(result);
1027
- } catch (cause) {
1028
- throw new TypeError(`${path2} must be an absolute immutable asset URI.`, { cause });
1206
+ } catch {
1207
+ throw new TypeError(`${path2} must be an absolute immutable asset URI.`);
1029
1208
  }
1030
1209
  if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash) throw new TypeError(`${path2} must be credential-free HTTPS without a fragment.`);
1031
1210
  const keys2 = [...parsed.searchParams.keys()].map((key) => key.toLowerCase());
@@ -1869,7 +2048,7 @@ function freezeJson(value) {
1869
2048
  }
1870
2049
  function exactKeys(value, keys2) {
1871
2050
  const expected = new Set(keys2);
1872
- return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => key in value);
2051
+ return Object.keys(value).every((key) => expected.has(key)) && keys2.every((key) => Object.hasOwn(value, key));
1873
2052
  }
1874
2053
  function safeToken(value) {
1875
2054
  return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
@@ -1893,13 +2072,13 @@ function validSha(value) {
1893
2072
  function validateCompileUnitInventory(value) {
1894
2073
  let snapshot;
1895
2074
  try {
1896
- snapshot = JSON.parse(canonicalizeGpuContract(value));
1897
- } catch (cause) {
2075
+ snapshot = snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
2076
+ } catch {
1898
2077
  return {
1899
2078
  ok: false,
1900
2079
  diagnostics: [issue(
1901
2080
  "invalid-contract",
1902
- cause instanceof Error ? cause.message : "Compile-unit inventory must contain detached JSON data."
2081
+ "Compile-unit inventory must contain bounded detached JSON contract data."
1903
2082
  )]
1904
2083
  };
1905
2084
  }
@@ -2140,9 +2319,9 @@ function object3(value, path2) {
2140
2319
  }
2141
2320
  function detachedJson2(value, label) {
2142
2321
  try {
2143
- return JSON.parse(canonicalizeGpuContract(value));
2144
- } catch (cause) {
2145
- throw new TypeError(`${label} must contain detached JSON contract data.`, { cause });
2322
+ return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
2323
+ } catch {
2324
+ throw new TypeError(`${label} must contain bounded detached JSON contract data.`);
2146
2325
  }
2147
2326
  }
2148
2327
  function freezeJson2(value) {
@@ -2152,7 +2331,7 @@ function freezeJson2(value) {
2152
2331
  }
2153
2332
  function exact2(value, keys2, path2) {
2154
2333
  const expected = new Set(keys2);
2155
- if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
2334
+ 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.`);
2156
2335
  }
2157
2336
  function token2(value, path2) {
2158
2337
  if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
@@ -2161,11 +2340,8 @@ function token2(value, path2) {
2161
2340
  function immutableVersion3(value, path2) {
2162
2341
  try {
2163
2342
  return assertImmutableAssetVersion(value);
2164
- } catch (cause) {
2165
- throw new TypeError(
2166
- `${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
2167
- { cause }
2168
- );
2343
+ } catch {
2344
+ throw new TypeError(`${path2} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
2169
2345
  }
2170
2346
  }
2171
2347
  function path(value, label, extensions) {
@@ -2177,8 +2353,8 @@ function path(value, label, extensions) {
2177
2353
  function sha(value, label) {
2178
2354
  try {
2179
2355
  return asSha256Hex(String(value));
2180
- } catch (cause) {
2181
- throw new TypeError(`${label} must be a lowercase SHA-256 digest.`, { cause });
2356
+ } catch {
2357
+ throw new TypeError(`${label} must be a lowercase SHA-256 digest.`);
2182
2358
  }
2183
2359
  }
2184
2360
  function integer4(value, label, minimum = 0, maximum = 4294967295) {
@@ -2302,6 +2478,7 @@ function jsonValue(value, label, depth = 0) {
2302
2478
  }
2303
2479
  function validateQualificationFixture(value, unit) {
2304
2480
  try {
2481
+ const compileUnit = unit === void 0 ? void 0 : detachedJson2(unit, "compile unit");
2305
2482
  const fixture = object3(detachedJson2(value, "fixture"), "fixture");
2306
2483
  exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
2307
2484
  if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
@@ -2432,14 +2609,14 @@ function validateQualificationFixture(value, unit) {
2432
2609
  unique2(bindingIds, `${label}.entries`);
2433
2610
  bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
2434
2611
  }
2435
- const pipelines = new Map(unit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
2612
+ const pipelines = new Map(compileUnit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
2436
2613
  const pipelineIds = new Set(pipelines.keys());
2437
2614
  const commandBindGroups = (value2, pipelineId, label) => {
2438
2615
  const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
2439
2616
  unique2(ids, label);
2440
2617
  const pipeline2 = pipelines.get(pipelineId);
2441
2618
  if (!pipeline2) {
2442
- if (unit) throw new TypeError(`${label} pipeline is missing.`);
2619
+ if (compileUnit) throw new TypeError(`${label} pipeline is missing.`);
2443
2620
  return;
2444
2621
  }
2445
2622
  const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
@@ -2464,7 +2641,7 @@ function validateQualificationFixture(value, unit) {
2464
2641
  executionCommands += 1;
2465
2642
  exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
2466
2643
  const id = token2(command.pipelineId, `${label}.pipelineId`);
2467
- if (unit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
2644
+ if (compileUnit && pipelines.get(id)?.kind !== "compute") throw new TypeError(`${label} references a missing or non-compute pipeline.`);
2468
2645
  commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
2469
2646
  const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
2470
2647
  if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
@@ -8844,7 +9021,7 @@ function validatePipelineInterfaces(input) {
8844
9021
  // package.json
8845
9022
  var package_default = {
8846
9023
  name: "@plasius/gpu-shader",
8847
- version: "0.1.2",
9024
+ version: "0.1.4",
8848
9025
  description: "Reflection-first WebGPU WGSL interfaces, CPU codecs, compatibility validation, style profiles, and qualification tooling",
8849
9026
  type: "module",
8850
9027
  sideEffects: false,
@@ -8889,6 +9066,7 @@ var package_default = {
8889
9066
  "audit:npm": "npm audit --audit-level=high --omit=dev",
8890
9067
  "audit:test": "vitest run --coverage",
8891
9068
  "pack:check": "node scripts/verify-public-package.cjs",
9069
+ "privacy:check": "node scripts/verify-public-artifacts.cjs --source-only",
8892
9070
  "harness:fingerprint": "node scripts/fingerprint-trusted-harness.cjs .",
8893
9071
  "shader:matrix": "npm run build && node dist/cli.js validate-matrix --matrix matrices/stable-webgpu-2026-07-13.json",
8894
9072
  prepare: "npm run build",
@@ -8917,25 +9095,29 @@ var package_default = {
8917
9095
  wgsl_reflect: "1.5.0"
8918
9096
  },
8919
9097
  optionalDependencies: {
8920
- "playwright-core": "1.61.1"
9098
+ "playwright-core": "1.62.1"
8921
9099
  },
8922
9100
  devDependencies: {
8923
9101
  "@eslint/js": "^10.0.1",
8924
- "@types/node": "^26.0.1",
8925
- "@typescript-eslint/eslint-plugin": "^8.59.3",
8926
- "@typescript-eslint/parser": "^8.59.3",
8927
- "@vitest/coverage-v8": "^4.1.6",
8928
- eslint: "^10.3.0",
8929
- globals: "^17.6.0",
9102
+ "@types/node": "^26.4.0",
9103
+ "@typescript-eslint/eslint-plugin": "^8.69.0",
9104
+ "@typescript-eslint/parser": "^8.69.0",
9105
+ "@vitest/coverage-v8": "^4.1.11",
9106
+ eslint: "^10.9.1",
9107
+ globals: "^17.11.0",
8930
9108
  rimraf: "^6.1.3",
8931
9109
  tsup: "^8.5.1",
8932
9110
  typescript: "^6.0.3",
8933
- vitest: "^4.1.6"
9111
+ vitest: "^4.1.11"
8934
9112
  },
8935
9113
  publishConfig: {
8936
9114
  access: "public"
8937
9115
  },
8938
9116
  overrides: {
9117
+ nanoid: "3.3.18",
9118
+ postcss: "8.5.26",
9119
+ "brace-expansion": "5.0.9",
9120
+ esbuild: "^0.28.1",
8939
9121
  minimatch: "^10.2.1"
8940
9122
  },
8941
9123
  engines: {
@@ -10107,7 +10289,37 @@ function object4(value, path2) {
10107
10289
  }
10108
10290
  function exact3(value, keys2, path2) {
10109
10291
  const expected = new Set(keys2);
10110
- if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
10292
+ 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.`);
10293
+ }
10294
+ function detachedQualificationContract(value) {
10295
+ try {
10296
+ return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
10297
+ } catch {
10298
+ throw new TypeError("Qualification data must contain bounded detached JSON contract data.");
10299
+ }
10300
+ }
10301
+ function parseQualificationJsonBytes(bytes2, label) {
10302
+ let snapshot;
10303
+ try {
10304
+ snapshot = snapshotUint8Array(
10305
+ bytes2,
10306
+ QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
10307
+ );
10308
+ } catch {
10309
+ throw new TypeError(`${label} is not bounded UTF-8 JSON.`);
10310
+ }
10311
+ let parsed;
10312
+ try {
10313
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
10314
+ } catch {
10315
+ throw new TypeError(`${label} is not valid UTF-8 JSON.`);
10316
+ }
10317
+ return detachedQualificationContract(parsed);
10318
+ }
10319
+ function freezeJson3(value) {
10320
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
10321
+ for (const child of Object.values(value)) freezeJson3(child);
10322
+ return Object.freeze(value);
10111
10323
  }
10112
10324
  function token3(value, path2, maximum = 512) {
10113
10325
  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.`);
@@ -10116,8 +10328,8 @@ function token3(value, path2, maximum = 512) {
10116
10328
  function sha2(value, path2) {
10117
10329
  try {
10118
10330
  return asSha256Hex(token3(value, path2, 64));
10119
- } catch (cause) {
10120
- throw new TypeError(`${path2} is not a SHA-256 digest.`, { cause });
10331
+ } catch {
10332
+ throw new TypeError(`${path2} is not a SHA-256 digest.`);
10121
10333
  }
10122
10334
  }
10123
10335
  function integer5(value, path2, minimum = 0) {
@@ -10150,7 +10362,7 @@ function trustedWorkflowRef(value, path2) {
10150
10362
  return result;
10151
10363
  }
10152
10364
  function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
10153
- const input = object4(value, path2);
10365
+ const input = object4(detachedQualificationContract(value), path2);
10154
10366
  exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
10155
10367
  const repository = token3(input.repository, `${path2}.repository`);
10156
10368
  if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
@@ -10169,10 +10381,10 @@ function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
10169
10381
  token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
10170
10382
  sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
10171
10383
  timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
10172
- return input;
10384
+ return freezeJson3(input);
10173
10385
  }
10174
10386
  function parseQualificationExecutionProducer(value, path2 = "producer") {
10175
- const input = object4(value, path2);
10387
+ const input = object4(detachedQualificationContract(value), path2);
10176
10388
  exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
10177
10389
  const repository = token3(input.repository, `${path2}.repository`);
10178
10390
  if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
@@ -10190,7 +10402,7 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
10190
10402
  if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
10191
10403
  token3(runner.os, `${path2}.runner.os`);
10192
10404
  token3(runner.architecture, `${path2}.runner.architecture`);
10193
- return input;
10405
+ return freezeJson3(input);
10194
10406
  }
10195
10407
  function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
10196
10408
  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.`);
@@ -10199,26 +10411,32 @@ function assertProducerMatchesPreflight(producer, provenance, cell, path2, expec
10199
10411
  if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
10200
10412
  }
10201
10413
  function canonicalEqual(left, right) {
10202
- return canonicalizeGpuContract(left) === canonicalizeGpuContract(right);
10414
+ return canonicalizeQualificationGpuContract(left) === canonicalizeQualificationGpuContract(right);
10203
10415
  }
10204
10416
  function foldRunnerLabel(value) {
10205
10417
  return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
10206
10418
  }
10207
10419
  async function computeQualificationInventorySha256(bundle) {
10208
- return computeSha256(canonicalizeGpuContract(bundle.inventory));
10420
+ const snapshot = detachedQualificationContract(bundle);
10421
+ return computeSha256(canonicalizeQualificationGpuContract(snapshot.inventory));
10209
10422
  }
10210
10423
  async function computeQualificationSubjectBinding(input) {
10211
10424
  return computeSha256(`plasius.gpu.qualification-subject/v1
10212
- ${canonicalizeGpuContract(input)}`);
10425
+ ${canonicalizeQualificationGpuContract(input)}`);
10213
10426
  }
10214
10427
  async function computeValidationEvidenceId(value) {
10215
10428
  const input = object4(value, "evidence identity input");
10216
10429
  const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
10217
10430
  return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
10218
- ${canonicalizeGpuContract(projection)}`)).slice(0, 24)}`;
10431
+ ${canonicalizeQualificationGpuContract(projection)}`)).slice(0, 24)}`;
10219
10432
  }
10220
10433
  function immutableBlobUri(value) {
10221
- const url = new URL(value);
10434
+ let url;
10435
+ try {
10436
+ url = new URL(value);
10437
+ } catch {
10438
+ throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
10439
+ }
10222
10440
  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 === ".."))) {
10223
10441
  throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
10224
10442
  }
@@ -10228,12 +10446,7 @@ function immutableBlobUri(value) {
10228
10446
  }
10229
10447
  async function createQualificationPreflight(input) {
10230
10448
  token3(input.qualificationId, "qualificationId");
10231
- let parsedMatrix;
10232
- try {
10233
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10234
- } catch (cause) {
10235
- throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
10236
- }
10449
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Selected matrix artifact");
10237
10450
  if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
10238
10451
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
10239
10452
  if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
@@ -10403,12 +10616,7 @@ function syntheticResult(unitId, cell, status, message, now) {
10403
10616
  async function aggregateShaderValidationEvidence(input) {
10404
10617
  const verifyArtifact = async (artifact2, label) => {
10405
10618
  if (await computeSha256(artifact2.bytes) !== artifact2.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
10406
- let parsed;
10407
- try {
10408
- parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact2.bytes));
10409
- } catch (cause) {
10410
- throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
10411
- }
10619
+ const parsed = parseQualificationJsonBytes(artifact2.bytes, `${label} bytes`);
10412
10620
  if (!canonicalEqual(parsed, artifact2.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
10413
10621
  };
10414
10622
  await verifyArtifact(input.preflight, "Qualification preflight");
@@ -10430,12 +10638,7 @@ async function aggregateShaderValidationEvidence(input) {
10430
10638
  exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
10431
10639
  const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
10432
10640
  if (!canonicalEqual(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
10433
- let parsedMatrix;
10434
- try {
10435
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10436
- } catch (cause) {
10437
- throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
10438
- }
10641
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
10439
10642
  if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10440
10643
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
10441
10644
  if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
@@ -10509,7 +10712,7 @@ async function aggregateShaderValidationEvidence(input) {
10509
10712
  if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
10510
10713
  for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
10511
10714
  const cellResults = results.slice(-units.size);
10512
- 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" });
10715
+ 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" });
10513
10716
  continue;
10514
10717
  }
10515
10718
  if (diagnostic) {
@@ -10524,7 +10727,7 @@ async function aggregateShaderValidationEvidence(input) {
10524
10727
  const status2 = value2.status === "timeout" ? "timeout" : "failed";
10525
10728
  for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
10526
10729
  const cellResults = results.slice(-units.size);
10527
- 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 });
10730
+ 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 });
10528
10731
  continue;
10529
10732
  }
10530
10733
  if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
@@ -10532,7 +10735,7 @@ async function aggregateShaderValidationEvidence(input) {
10532
10735
  if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
10533
10736
  const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
10534
10737
  results.push(...value.results);
10535
- 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" });
10738
+ 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" });
10536
10739
  }
10537
10740
  const expectedResults = units.size * cells.size;
10538
10741
  if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
@@ -10555,34 +10758,31 @@ async function aggregateShaderValidationEvidence(input) {
10555
10758
  }
10556
10759
  async function validateShaderValidationEvidence(input) {
10557
10760
  try {
10558
- const evidence = object4(input.evidence, "evidence");
10761
+ const evidence = object4(detachedQualificationContract(input.evidence), "evidence");
10762
+ const bundle = detachedQualificationContract(input.bundle);
10763
+ const matrix = detachedQualificationContract(input.matrix);
10559
10764
  exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
10560
10765
  if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
10561
10766
  const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
10562
10767
  const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
10563
10768
  const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
10564
10769
  if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
10565
- let parsedMatrix;
10566
- try {
10567
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10568
- } catch (cause) {
10569
- throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
10570
- }
10571
- if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10770
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
10771
+ if (!canonicalEqual(parsedMatrix, matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10572
10772
  const matrixSha256 = await computeSha256(input.matrixBytes);
10573
- const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
10574
- if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
10773
+ const inventorySha256 = await computeQualificationInventorySha256(bundle);
10774
+ if (inventorySha256 !== bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
10575
10775
  const subject = object4(evidence.subject, "evidence.subject");
10576
- const expectedSubjectKeys = [...Object.keys(input.bundle.subject), "dataBundleSha256"];
10776
+ const expectedSubjectKeys = [...Object.keys(bundle.subject), "dataBundleSha256"];
10577
10777
  exact3(subject, expectedSubjectKeys, "evidence.subject");
10578
10778
  const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
10579
- if (!canonicalEqual(candidateSubject, input.bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
10779
+ if (!canonicalEqual(candidateSubject, bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
10580
10780
  const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
10581
10781
  if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
10582
10782
  if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
10583
10783
  const matrixRef = object4(evidence.matrixRef, "evidence.matrixRef");
10584
10784
  exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
10585
- if (matrixRef.matrixId !== input.matrix.matrixId || matrixRef.version !== input.matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
10785
+ if (matrixRef.matrixId !== matrix.matrixId || matrixRef.version !== matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
10586
10786
  const toolchain = object4(evidence.toolchain, "evidence.toolchain");
10587
10787
  exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
10588
10788
  token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
@@ -10594,11 +10794,11 @@ async function validateShaderValidationEvidence(input) {
10594
10794
  const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
10595
10795
  const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
10596
10796
  if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
10597
- const expectedBinding = await computeQualificationSubjectBinding({ subject: input.bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
10797
+ const expectedBinding = await computeQualificationSubjectBinding({ subject: bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
10598
10798
  if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
10599
10799
  if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
10600
- const units = new Set(input.bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
10601
- const cells = new Map(input.matrix.cells.map((cell) => [cell.cellId, cell]));
10800
+ const units = new Set(bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
10801
+ const cells = new Map(matrix.cells.map((cell) => [cell.cellId, cell]));
10602
10802
  const expected = units.size * cells.size;
10603
10803
  const results = array2(evidence.results, "evidence.results");
10604
10804
  if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
@@ -10648,7 +10848,7 @@ async function validateShaderValidationEvidence(input) {
10648
10848
  sha2(automation2.sha256, `${path2}.automation.sha256`);
10649
10849
  } else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
10650
10850
  const cellResults = parsedResults.filter((result) => result.cellId === cellId);
10651
- if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
10851
+ if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeQualificationGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
10652
10852
  const resultStatuses = new Set(cellResults.map((result) => result.status));
10653
10853
  if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
10654
10854
  if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
@@ -10657,7 +10857,7 @@ async function validateShaderValidationEvidence(input) {
10657
10857
  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.`);
10658
10858
  }
10659
10859
  if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
10660
- return { ok: true, value: evidence };
10860
+ return { ok: true, value: freezeJson3(evidence) };
10661
10861
  } catch (cause) {
10662
10862
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
10663
10863
  }
@@ -10672,7 +10872,12 @@ function object5(value) {
10672
10872
  }
10673
10873
  function keys(value, expected) {
10674
10874
  const set = new Set(expected);
10675
- return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key in value);
10875
+ return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => Object.hasOwn(value, key));
10876
+ }
10877
+ function freezeJson4(value) {
10878
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
10879
+ for (const child of Object.values(value)) freezeJson4(child);
10880
+ return Object.freeze(value);
10676
10881
  }
10677
10882
  function canonicalEqual2(left, right) {
10678
10883
  try {
@@ -10722,7 +10927,13 @@ var BASELINE = /* @__PURE__ */ new Map([
10722
10927
  ["win11-nvidia-edge-d3d12", "edge|windows|x64|physical|nvidia|qualified-nvidia|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-nvidia,d3d12"]
10723
10928
  ]);
10724
10929
  function validateStableWebGpuMatrix(value) {
10725
- const matrix = object5(value);
10930
+ let snapshot;
10931
+ try {
10932
+ snapshot = snapshotGpuContract(value);
10933
+ } catch {
10934
+ return { ok: false, diagnostics: [issue3("Matrix must contain bounded detached JSON contract data.")] };
10935
+ }
10936
+ const matrix = object5(snapshot);
10726
10937
  const diagnostics = [];
10727
10938
  if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
10728
10939
  return { ok: false, diagnostics: [issue3("Matrix has unknown or missing top-level fields.")] };
@@ -10795,7 +11006,7 @@ function validateStableWebGpuMatrix(value) {
10795
11006
  }
10796
11007
  }
10797
11008
  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."));
10798
- return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
11009
+ return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson4(matrix) };
10799
11010
  }
10800
11011
 
10801
11012
  // src/testing/runner/playwright-swiftshader.ts
@@ -12104,9 +12315,6 @@ function error(code, message, path2) {
12104
12315
  function interfaceMatches(item, model) {
12105
12316
  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;
12106
12317
  }
12107
- function detachedContract(value) {
12108
- return JSON.parse(canonicalizeGpuContract(value));
12109
- }
12110
12318
  function hasValidationEvidence(value) {
12111
12319
  return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
12112
12320
  }
@@ -12154,16 +12362,25 @@ function validateModelShaderCompatibility(input) {
12154
12362
  let profile;
12155
12363
  let capabilities;
12156
12364
  try {
12157
- const modelSnapshot = detachedContract(input.model);
12158
- const shaderSnapshot = detachedContract(input.shader);
12159
- const gpuInterfaceSnapshot = detachedContract(input.gpuInterface);
12160
- const profileValue = input.profile;
12161
- const profileSnapshot = profileValue === void 0 ? void 0 : detachedContract(profileValue);
12365
+ const snapshot = snapshotGpuContract(input);
12366
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
12367
+ throw new TypeError("GPU compatibility input must be a bounded contract object.");
12368
+ }
12369
+ const envelope = snapshot;
12370
+ const keys2 = Object.keys(envelope);
12371
+ const allowed = /* @__PURE__ */ new Set(["model", "shader", "gpuInterface", "profile", "capabilities"]);
12372
+ if (keys2.some((key) => !allowed.has(key)) || !["model", "shader", "gpuInterface"].every((key) => Object.hasOwn(envelope, key))) {
12373
+ throw new TypeError("GPU compatibility input has unknown or missing fields.");
12374
+ }
12375
+ const modelSnapshot = envelope.model;
12376
+ const shaderSnapshot = envelope.shader;
12377
+ const gpuInterfaceSnapshot = envelope.gpuInterface;
12378
+ const profileSnapshot = Object.hasOwn(envelope, "profile") ? envelope.profile : void 0;
12162
12379
  model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
12163
12380
  shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
12164
12381
  gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
12165
12382
  profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
12166
- capabilities = input.capabilities;
12383
+ capabilities = Object.hasOwn(envelope, "capabilities") ? envelope.capabilities : void 0;
12167
12384
  } catch (cause) {
12168
12385
  return {
12169
12386
  ok: false,