@plasius/gpu-shader 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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);
96
+ }
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);
17
106
  }
18
- function assertUnicodeScalarString(value, path2) {
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(
@@ -583,6 +766,7 @@ ${canonicalizeGpuContract(core)}`
583
766
  // src/contracts.ts
584
767
  var GPU_INTERFACE_MANIFEST_VERSION = "1.0.0";
585
768
  var SHADER_VERSION_MANIFEST_VERSION = "1.0.0";
769
+ var SHADER_STYLE_PROFILE_MANIFEST_VERSION = "1.0.0";
586
770
  var SHADER_COMPILE_UNIT_VERSION = "1.0.0";
587
771
  var SHADER_VALIDATION_EVIDENCE_VERSION = "1.0.0";
588
772
  var STABLE_WEBGPU_MATRIX_VERSION = "1.0.0";
@@ -598,6 +782,29 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
598
782
  Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
599
783
  var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
600
784
 
785
+ // src/asset-version.ts
786
+ var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
787
+ var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
788
+ "latest",
789
+ "current",
790
+ "stable",
791
+ "preview",
792
+ "default",
793
+ "production",
794
+ "canary",
795
+ "next",
796
+ "head",
797
+ "main"
798
+ ]);
799
+ var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
800
+ var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
801
+ function assertImmutableAssetVersion(value) {
802
+ if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
803
+ throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
804
+ }
805
+ return value;
806
+ }
807
+
601
808
  // src/requirements-validation.ts
602
809
  var ENABLED_FEATURES = Object.freeze({
603
810
  f16: "shader-f16",
@@ -925,6 +1132,14 @@ function validateShaderDerivedRequirements(input) {
925
1132
  // src/manifest-validation.ts
926
1133
  var stages = ["vertex", "fragment", "compute"];
927
1134
  var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
1135
+ function detachedJson(value, path2) {
1136
+ try {
1137
+ return snapshotGpuContract(value);
1138
+ } catch (cause) {
1139
+ const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
1140
+ throw new TypeError(`${path2} must contain bounded detached JSON contract data.${detail}`);
1141
+ }
1142
+ }
928
1143
  function object(value, path2) {
929
1144
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
930
1145
  return value;
@@ -932,7 +1147,7 @@ function object(value, path2) {
932
1147
  function exact(value, keys2, path2) {
933
1148
  const allowed = new Set(keys2);
934
1149
  for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path2}.${key} is not part of this contract version.`);
935
- 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.`);
936
1151
  }
937
1152
  function text(value, path2, maximum = 512) {
938
1153
  if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
@@ -945,6 +1160,13 @@ function token(value, path2) {
945
1160
  if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
946
1161
  return result;
947
1162
  }
1163
+ function immutableVersion(value, path2) {
1164
+ try {
1165
+ return assertImmutableAssetVersion(value);
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.`);
1168
+ }
1169
+ }
948
1170
  function enumeration(value, values, path2) {
949
1171
  if (!values.includes(value)) throw new TypeError(`${path2} is invalid.`);
950
1172
  return value;
@@ -972,8 +1194,8 @@ function nullableToken(value, path2) {
972
1194
  function digest(value, path2) {
973
1195
  try {
974
1196
  return asSha256Hex(text(value, path2, 64));
975
- } catch (cause) {
976
- 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.`);
977
1199
  }
978
1200
  }
979
1201
  function uri(value, path2) {
@@ -981,8 +1203,8 @@ function uri(value, path2) {
981
1203
  let parsed;
982
1204
  try {
983
1205
  parsed = new URL(result);
984
- } catch (cause) {
985
- 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.`);
986
1208
  }
987
1209
  if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash) throw new TypeError(`${path2} must be credential-free HTTPS without a fragment.`);
988
1210
  const keys2 = [...parsed.searchParams.keys()].map((key) => key.toLowerCase());
@@ -1218,7 +1440,7 @@ function interfaceRef(value, path2) {
1218
1440
  const input = object(value, path2);
1219
1441
  exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
1220
1442
  token(input.interfaceId, `${path2}.interfaceId`);
1221
- token(input.interfaceVersion, `${path2}.interfaceVersion`);
1443
+ immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
1222
1444
  uri(input.manifestUri, `${path2}.manifestUri`);
1223
1445
  digest(input.manifestSha256, `${path2}.manifestSha256`);
1224
1446
  digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
@@ -1356,7 +1578,7 @@ function pipeline(value, path2, moduleIds) {
1356
1578
  return input;
1357
1579
  }
1358
1580
  function parseSerializableGpuPipelineDescriptors(value, moduleIds, path2 = "pipelines") {
1359
- const parsed = array(value, path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
1581
+ const parsed = array(detachedJson(value, path2), path2).map((item, index) => pipeline(item, `${path2}[${index}]`, new Set(moduleIds)));
1360
1582
  unique(parsed, (item) => item.pipelineId, path2);
1361
1583
  return freeze(parsed);
1362
1584
  }
@@ -1364,7 +1586,7 @@ function compatibleModel(value, path2) {
1364
1586
  const input = object(value, path2);
1365
1587
  exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path2);
1366
1588
  token(input.interfaceId, `${path2}.interfaceId`);
1367
- token(input.interfaceVersion, `${path2}.interfaceVersion`);
1589
+ immutableVersion(input.interfaceVersion, `${path2}.interfaceVersion`);
1368
1590
  digest(input.manifestSha256, `${path2}.manifestSha256`);
1369
1591
  digest(input.interfaceAbiHash, `${path2}.interfaceAbiHash`);
1370
1592
  digest(input.modelAbiHash, `${path2}.modelAbiHash`);
@@ -1377,7 +1599,7 @@ function validationEvidenceRef(value, path2) {
1377
1599
  uri(evidence.uri, `${path2}.uri`);
1378
1600
  digest(evidence.sha256, `${path2}.sha256`);
1379
1601
  token(evidence.matrixId, `${path2}.matrixId`);
1380
- token(evidence.matrixVersion, `${path2}.matrixVersion`);
1602
+ immutableVersion(evidence.matrixVersion, `${path2}.matrixVersion`);
1381
1603
  digest(evidence.matrixSha256, `${path2}.matrixSha256`);
1382
1604
  const attestation = object(evidence.attestationRef, `${path2}.attestationRef`);
1383
1605
  exact(attestation, ["uri", "sha256"], `${path2}.attestationRef`);
@@ -1404,11 +1626,11 @@ function reflectedRecordBindingSize(record) {
1404
1626
  return Math.ceil(unrounded / record.alignment) * record.alignment;
1405
1627
  }
1406
1628
  function parseGpuInterfaceManifest(value) {
1407
- const input = object(value, "GpuInterfaceManifest");
1629
+ const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
1408
1630
  exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
1409
1631
  if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
1410
1632
  token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
1411
- token(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1633
+ immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1412
1634
  const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
1413
1635
  if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
1414
1636
  const moduleIds = moduleValues.map((value2, index) => {
@@ -1590,11 +1812,11 @@ function parseGpuInterfaceManifest(value) {
1590
1812
  return freeze(input);
1591
1813
  }
1592
1814
  function parseShaderVersionManifest(value) {
1593
- const input = object(value, "ShaderVersionManifest");
1815
+ const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
1594
1816
  exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
1595
1817
  if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
1596
1818
  token(input.shaderId, "ShaderVersionManifest.shaderId");
1597
- token(input.version, "ShaderVersionManifest.version");
1819
+ immutableVersion(input.version, "ShaderVersionManifest.version");
1598
1820
  const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
1599
1821
  if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
1600
1822
  const moduleIds = moduleValues.map((item, index) => {
@@ -1707,7 +1929,7 @@ function parseShaderVersionManifest(value) {
1707
1929
  return freeze(input);
1708
1930
  }
1709
1931
  function parseShaderVersionManifestCore(value) {
1710
- const input = object(value, "ShaderVersionManifestCore");
1932
+ const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
1711
1933
  if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
1712
1934
  throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
1713
1935
  }
@@ -1732,11 +1954,59 @@ function parseShaderVersionManifestCore(value) {
1732
1954
  void additionalValidationEvidence;
1733
1955
  return freeze(core);
1734
1956
  }
1957
+ function parseShaderStyleProfileManifest(value) {
1958
+ const input = object(detachedJson(value, "ShaderStyleProfileManifest"), "ShaderStyleProfileManifest");
1959
+ exact(input, ["contractVersion", "profileId", "version", "style", "roles", "compatibleModelInterfaces", "requiredSemantics", "requiredValidationScopes"], "ShaderStyleProfileManifest");
1960
+ if (input.contractVersion !== SHADER_STYLE_PROFILE_MANIFEST_VERSION) throw new TypeError("Unsupported style-profile contract version.");
1961
+ token(input.profileId, "ShaderStyleProfileManifest.profileId");
1962
+ immutableVersion(input.version, "ShaderStyleProfileManifest.version");
1963
+ token(input.style, "ShaderStyleProfileManifest.style");
1964
+ const roleValues = array(input.roles, "ShaderStyleProfileManifest.roles", 5);
1965
+ if (roleValues.length === 0) throw new TypeError("ShaderStyleProfileManifest.roles must not be empty.");
1966
+ const roleNames = [];
1967
+ roleValues.forEach((item, index) => {
1968
+ const path2 = `ShaderStyleProfileManifest.roles[${index}]`;
1969
+ const role = object(item, path2);
1970
+ exact(role, ["role", "shader"], path2);
1971
+ roleNames.push(enumeration(role.role, roles, `${path2}.role`));
1972
+ const shader = object(role.shader, `${path2}.shader`);
1973
+ exact(shader, ["shaderId", "version", "manifestUri", "manifestSha256"], `${path2}.shader`);
1974
+ token(shader.shaderId, `${path2}.shader.shaderId`);
1975
+ immutableVersion(shader.version, `${path2}.shader.version`);
1976
+ uri(shader.manifestUri, `${path2}.shader.manifestUri`);
1977
+ digest(shader.manifestSha256, `${path2}.shader.manifestSha256`);
1978
+ });
1979
+ unique(roleNames, String, "ShaderStyleProfileManifest.roles");
1980
+ const compatible = array(input.compatibleModelInterfaces, "ShaderStyleProfileManifest.compatibleModelInterfaces").map((item, index) => compatibleModel(item, `ShaderStyleProfileManifest.compatibleModelInterfaces[${index}]`));
1981
+ if (compatible.length === 0) throw new TypeError("ShaderStyleProfileManifest.compatibleModelInterfaces must not be empty.");
1982
+ unique(compatible, (item) => `${item.interfaceId}:${item.interfaceVersion}:${item.manifestSha256}:${item.interfaceAbiHash}:${item.modelAbiHash}`, "ShaderStyleProfileManifest.compatibleModelInterfaces");
1983
+ tokenArray(input.requiredSemantics, "ShaderStyleProfileManifest.requiredSemantics");
1984
+ const requiredValidationScopes = array(input.requiredValidationScopes, "ShaderStyleProfileManifest.requiredValidationScopes").map((item, index) => {
1985
+ const path2 = `ShaderStyleProfileManifest.requiredValidationScopes[${index}]`;
1986
+ const requirement = object(item, path2);
1987
+ exact(requirement, ["scope", "matrixId", "matrixVersion", "matrixSha256"], path2);
1988
+ const scope = token(requirement.scope, `${path2}.scope`);
1989
+ if (scope === "universal") throw new TypeError(`${path2}.scope must not use the reserved universal scope.`);
1990
+ token(requirement.matrixId, `${path2}.matrixId`);
1991
+ immutableVersion(requirement.matrixVersion, `${path2}.matrixVersion`);
1992
+ const matrixSha256 = digest(requirement.matrixSha256, `${path2}.matrixSha256`);
1993
+ if (SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES.some((policy) => policy.matrixSha256 === matrixSha256)) {
1994
+ throw new TypeError(`${path2} must require an additive matrix policy, not the universal matrix policy.`);
1995
+ }
1996
+ if (!SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES.some((policy) => scope === policy.scope && requirement.matrixId === policy.matrixId && requirement.matrixVersion === policy.matrixVersion && matrixSha256 === policy.matrixSha256)) {
1997
+ throw new TypeError(`${path2} is not a supported additive WebGPU matrix policy.`);
1998
+ }
1999
+ return requirement;
2000
+ });
2001
+ unique(requiredValidationScopes, (item) => String(item.scope), "ShaderStyleProfileManifest.requiredValidationScopes scopes");
2002
+ unique(requiredValidationScopes, (item) => String(item.matrixSha256), "ShaderStyleProfileManifest.requiredValidationScopes matrix policies");
2003
+ return freeze(input);
2004
+ }
1735
2005
  function parseModelGpuCompatibilityDescriptor(value) {
1736
- const input = object(value, "ModelGpuCompatibilityDescriptor");
2006
+ const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
1737
2007
  exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
1738
2008
  token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
1739
- token(input.version, "ModelGpuCompatibilityDescriptor.version");
2009
+ immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
1740
2010
  const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
1741
2011
  const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
1742
2012
  if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
@@ -1745,14 +2015,17 @@ function parseModelGpuCompatibilityDescriptor(value) {
1745
2015
  const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1746
2016
  exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1747
2017
  token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
1748
- token(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
2018
+ immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1749
2019
  uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
1750
2020
  digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
1751
2021
  }
1752
2022
  return freeze(input);
1753
2023
  }
1754
2024
  function parseShaderQualificationModelCompatibilityFixture(value) {
1755
- const input = object(value, "ShaderQualificationModelCompatibilityFixture");
2025
+ const input = object(
2026
+ detachedJson(value, "ShaderQualificationModelCompatibilityFixture"),
2027
+ "ShaderQualificationModelCompatibilityFixture"
2028
+ );
1756
2029
  exact(input, ["contractVersion", "fixtureId", "model"], "ShaderQualificationModelCompatibilityFixture");
1757
2030
  if (input.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported model compatibility fixture version.");
1758
2031
  token(input.fixtureId, "ShaderQualificationModelCompatibilityFixture.fixtureId");
@@ -1768,13 +2041,26 @@ function issue(code, message, path2) {
1768
2041
  function object2(value) {
1769
2042
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
1770
2043
  }
2044
+ function freezeJson(value) {
2045
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
2046
+ for (const child of Object.values(value)) freezeJson(child);
2047
+ return Object.freeze(value);
2048
+ }
1771
2049
  function exactKeys(value, keys2) {
1772
2050
  const expected = new Set(keys2);
1773
- 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));
1774
2052
  }
1775
2053
  function safeToken(value) {
1776
2054
  return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,159}$/u.test(value) && !value.includes("..");
1777
2055
  }
2056
+ function immutableVersion2(value) {
2057
+ try {
2058
+ assertImmutableAssetVersion(value);
2059
+ return true;
2060
+ } catch {
2061
+ return false;
2062
+ }
2063
+ }
1778
2064
  function validSha(value) {
1779
2065
  try {
1780
2066
  asSha256Hex(String(value));
@@ -1784,8 +2070,20 @@ function validSha(value) {
1784
2070
  }
1785
2071
  }
1786
2072
  function validateCompileUnitInventory(value) {
1787
- const envelope = object2(value);
1788
- const candidate = envelope && "inventory" in envelope ? object2(value.inventory) : envelope;
2073
+ let snapshot;
2074
+ try {
2075
+ snapshot = snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
2076
+ } catch {
2077
+ return {
2078
+ ok: false,
2079
+ diagnostics: [issue(
2080
+ "invalid-contract",
2081
+ "Compile-unit inventory must contain bounded detached JSON contract data."
2082
+ )]
2083
+ };
2084
+ }
2085
+ const envelope = object2(snapshot);
2086
+ const candidate = envelope && Object.hasOwn(envelope, "inventory") ? object2(snapshot.inventory) : envelope;
1789
2087
  const diagnostics = [];
1790
2088
  if (!candidate || !exactKeys(candidate, ["contractVersion", "fragments", "compileUnits"])) {
1791
2089
  return { ok: false, diagnostics: [issue("invalid-contract", "Compile-unit inventory has unknown or missing fields.")] };
@@ -1916,7 +2214,7 @@ function validateCompileUnitInventory(value) {
1916
2214
  diagnostics.push(issue("invalid-contract", cause instanceof Error ? cause.message : "Compile-unit pipelines are invalid.", `${path2}.pipelines`));
1917
2215
  }
1918
2216
  const interfaceRef2 = object2(unit.interfaceRef);
1919
- if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !safeToken(interfaceRef2.interfaceVersion) || typeof interfaceRef2.manifestUri !== "string" || !interfaceRef2.manifestUri.startsWith("https://") || !validSha(interfaceRef2.manifestSha256) || !validSha(interfaceRef2.interfaceAbiHash) || !validSha(interfaceRef2.modelAbiHash)) {
2217
+ if (!interfaceRef2 || !exactKeys(interfaceRef2, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"]) || !safeToken(interfaceRef2.interfaceId) || !immutableVersion2(interfaceRef2.interfaceVersion) || typeof interfaceRef2.manifestUri !== "string" || !interfaceRef2.manifestUri.startsWith("https://") || !validSha(interfaceRef2.manifestSha256) || !validSha(interfaceRef2.interfaceAbiHash) || !validSha(interfaceRef2.modelAbiHash)) {
1920
2218
  diagnostics.push(issue("invalid-contract", "Compile-unit interfaceRef is invalid.", `${path2}.interfaceRef`));
1921
2219
  }
1922
2220
  const fixture = object2(unit.qualificationFixture);
@@ -1927,7 +2225,7 @@ function validateCompileUnitInventory(value) {
1927
2225
  for (const fragmentId of fragmentIds) {
1928
2226
  if (!covered.has(fragmentId)) diagnostics.push(issue("uncovered-fragment", `WGSL fragment ${fragmentId} has no compile unit.`));
1929
2227
  }
1930
- return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: candidate };
2228
+ return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson(candidate) };
1931
2229
  }
1932
2230
 
1933
2231
  // src/testing/qualification-bundle.ts
@@ -2019,14 +2317,33 @@ function object3(value, path2) {
2019
2317
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path2} must be an object.`);
2020
2318
  return value;
2021
2319
  }
2320
+ function detachedJson2(value, label) {
2321
+ try {
2322
+ return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
2323
+ } catch {
2324
+ throw new TypeError(`${label} must contain bounded detached JSON contract data.`);
2325
+ }
2326
+ }
2327
+ function freezeJson2(value) {
2328
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
2329
+ for (const child of Object.values(value)) freezeJson2(child);
2330
+ return Object.freeze(value);
2331
+ }
2022
2332
  function exact2(value, keys2, path2) {
2023
2333
  const expected = new Set(keys2);
2024
- 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.`);
2025
2335
  }
2026
2336
  function token2(value, path2) {
2027
2337
  if (typeof value !== "string" || !TOKEN.test(value) || value.includes("..")) throw new TypeError(`${path2} must be a safe token.`);
2028
2338
  return value;
2029
2339
  }
2340
+ function immutableVersion3(value, path2) {
2341
+ try {
2342
+ return assertImmutableAssetVersion(value);
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.`);
2345
+ }
2346
+ }
2030
2347
  function path(value, label, extensions) {
2031
2348
  if (typeof value !== "string" || !SAFE_PATH2.test(value) || !extensions.some((extension) => value.endsWith(extension))) {
2032
2349
  throw new TypeError(`${label} must be a safe data-only bundle path (${extensions.join(", ")}).`);
@@ -2036,8 +2353,8 @@ function path(value, label, extensions) {
2036
2353
  function sha(value, label) {
2037
2354
  try {
2038
2355
  return asSha256Hex(String(value));
2039
- } catch (cause) {
2040
- 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.`);
2041
2358
  }
2042
2359
  }
2043
2360
  function integer4(value, label, minimum = 0, maximum = 4294967295) {
@@ -2161,7 +2478,8 @@ function jsonValue(value, label, depth = 0) {
2161
2478
  }
2162
2479
  function validateQualificationFixture(value, unit) {
2163
2480
  try {
2164
- const fixture = object3(value, "fixture");
2481
+ const compileUnit = unit === void 0 ? void 0 : detachedJson2(unit, "compile unit");
2482
+ const fixture = object3(detachedJson2(value, "fixture"), "fixture");
2165
2483
  exact2(fixture, ["contractVersion", "fixtureId", "resources", "bindGroups", "commands", "layoutProbes", "readbacks", "bounds"], "fixture");
2166
2484
  if (fixture.contractVersion !== SHADER_QUALIFICATION_FIXTURE_VERSION) throw new TypeError("Unsupported qualification fixture version.");
2167
2485
  token2(fixture.fixtureId, "fixture.fixtureId");
@@ -2291,14 +2609,14 @@ function validateQualificationFixture(value, unit) {
2291
2609
  unique2(bindingIds, `${label}.entries`);
2292
2610
  bindGroups.set(id, { group: groupIndex, entries: parsedEntries });
2293
2611
  }
2294
- const pipelines = new Map(unit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
2612
+ const pipelines = new Map(compileUnit?.pipelines.map((pipeline2) => [pipeline2.pipelineId, pipeline2]) ?? []);
2295
2613
  const pipelineIds = new Set(pipelines.keys());
2296
2614
  const commandBindGroups = (value2, pipelineId, label) => {
2297
2615
  const ids = boundedArray(value2, label, 32).map((item, index) => token2(item, `${label}[${index}]`));
2298
2616
  unique2(ids, label);
2299
2617
  const pipeline2 = pipelines.get(pipelineId);
2300
2618
  if (!pipeline2) {
2301
- if (unit) throw new TypeError(`${label} pipeline is missing.`);
2619
+ if (compileUnit) throw new TypeError(`${label} pipeline is missing.`);
2302
2620
  return;
2303
2621
  }
2304
2622
  const expectedGroups = [...pipeline2.layout.bindGroups].sort((left, right) => left.group - right.group);
@@ -2323,7 +2641,7 @@ function validateQualificationFixture(value, unit) {
2323
2641
  executionCommands += 1;
2324
2642
  exact2(command, ["kind", "pipelineId", "bindGroupIds", "workgroups"], label);
2325
2643
  const id = token2(command.pipelineId, `${label}.pipelineId`);
2326
- 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.`);
2327
2645
  commandBindGroups(command.bindGroupIds, id, `${label}.bindGroupIds`);
2328
2646
  const workgroups = tuple(command.workgroups, `${label}.workgroups`, 3, 1);
2329
2647
  if (workgroups[0] * workgroups[1] * workgroups[2] > 1048576) throw new TypeError(`${label}.workgroups exceeds the hard dispatch bound.`);
@@ -2497,14 +2815,14 @@ function validateQualificationFixture(value, unit) {
2497
2815
  }
2498
2816
  unique2(probeIds, "fixture.layoutProbes probe IDs");
2499
2817
  unique2(probeSources, "fixture.layoutProbes model sources");
2500
- return { ok: true, value: fixture };
2818
+ return { ok: true, value: freezeJson2(fixture) };
2501
2819
  } catch (cause) {
2502
2820
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification fixture." }] };
2503
2821
  }
2504
2822
  }
2505
2823
  function validateQualificationBundleManifest(value) {
2506
2824
  try {
2507
- const bundle = object3(value, "qualification");
2825
+ const bundle = object3(detachedJson2(value, "qualification"), "qualification");
2508
2826
  exact2(bundle, ["contractVersion", "inventory", "subject", "shaderManifestCorePath", "gpuInterfaceManifest", "modelCompatibilityFixtures", "modules", "fixtures"], "qualification");
2509
2827
  if (bundle.contractVersion !== SHADER_QUALIFICATION_BUNDLE_VERSION) throw new TypeError("Unsupported qualification bundle version.");
2510
2828
  const inventory = validateCompileUnitInventory(bundle.inventory);
@@ -2514,7 +2832,7 @@ function validateQualificationBundleManifest(value) {
2514
2832
  const candidate = object3(subject.shaderManifestCore, "qualification.subject.shaderManifestCore");
2515
2833
  exact2(candidate, ["shaderId", "version", "sha256"], "qualification.subject.shaderManifestCore");
2516
2834
  token2(candidate.shaderId, "qualification.subject.shaderManifestCore.shaderId");
2517
- token2(candidate.version, "qualification.subject.shaderManifestCore.version");
2835
+ immutableVersion3(candidate.version, "qualification.subject.shaderManifestCore.version");
2518
2836
  sha(candidate.sha256, "qualification.subject.shaderManifestCore.sha256");
2519
2837
  path(bundle.shaderManifestCorePath, "qualification.shaderManifestCorePath", [".json"]);
2520
2838
  const interfaceManifest = object3(bundle.gpuInterfaceManifest, "qualification.gpuInterfaceManifest");
@@ -2574,7 +2892,7 @@ function validateQualificationBundleManifest(value) {
2574
2892
  const expectedUnits = [...inventory.value.compileUnits.map((unit) => unit.compileUnitId)].sort();
2575
2893
  if (unitIds.join("\n") !== expectedUnits.join("\n")) throw new TypeError("Subject compile-unit IDs differ from inventory.");
2576
2894
  orderedUniqueTokens(subject.requiredCellIds, "qualification.subject.requiredCellIds");
2577
- return { ok: true, value: bundle };
2895
+ return { ok: true, value: freezeJson2(bundle) };
2578
2896
  } catch (cause) {
2579
2897
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid qualification bundle." }] };
2580
2898
  }
@@ -8703,7 +9021,7 @@ function validatePipelineInterfaces(input) {
8703
9021
  // package.json
8704
9022
  var package_default = {
8705
9023
  name: "@plasius/gpu-shader",
8706
- version: "0.1.1",
9024
+ version: "0.1.3",
8707
9025
  description: "Reflection-first WebGPU WGSL interfaces, CPU codecs, compatibility validation, style profiles, and qualification tooling",
8708
9026
  type: "module",
8709
9027
  sideEffects: false,
@@ -8795,6 +9113,7 @@ var package_default = {
8795
9113
  access: "public"
8796
9114
  },
8797
9115
  overrides: {
9116
+ esbuild: "^0.28.1",
8798
9117
  minimatch: "^10.2.1"
8799
9118
  },
8800
9119
  engines: {
@@ -9966,7 +10285,37 @@ function object4(value, path2) {
9966
10285
  }
9967
10286
  function exact3(value, keys2, path2) {
9968
10287
  const expected = new Set(keys2);
9969
- if (!Object.keys(value).every((key) => expected.has(key)) || !keys2.every((key) => key in value)) throw new TypeError(`${path2} has unknown or missing fields.`);
10288
+ 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.`);
10289
+ }
10290
+ function detachedQualificationContract(value) {
10291
+ try {
10292
+ return snapshotGpuContract(value, QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS);
10293
+ } catch {
10294
+ throw new TypeError("Qualification data must contain bounded detached JSON contract data.");
10295
+ }
10296
+ }
10297
+ function parseQualificationJsonBytes(bytes2, label) {
10298
+ let snapshot;
10299
+ try {
10300
+ snapshot = snapshotUint8Array(
10301
+ bytes2,
10302
+ QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
10303
+ );
10304
+ } catch {
10305
+ throw new TypeError(`${label} is not bounded UTF-8 JSON.`);
10306
+ }
10307
+ let parsed;
10308
+ try {
10309
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
10310
+ } catch {
10311
+ throw new TypeError(`${label} is not valid UTF-8 JSON.`);
10312
+ }
10313
+ return detachedQualificationContract(parsed);
10314
+ }
10315
+ function freezeJson3(value) {
10316
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
10317
+ for (const child of Object.values(value)) freezeJson3(child);
10318
+ return Object.freeze(value);
9970
10319
  }
9971
10320
  function token3(value, path2, maximum = 512) {
9972
10321
  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.`);
@@ -9975,8 +10324,8 @@ function token3(value, path2, maximum = 512) {
9975
10324
  function sha2(value, path2) {
9976
10325
  try {
9977
10326
  return asSha256Hex(token3(value, path2, 64));
9978
- } catch (cause) {
9979
- throw new TypeError(`${path2} is not a SHA-256 digest.`, { cause });
10327
+ } catch {
10328
+ throw new TypeError(`${path2} is not a SHA-256 digest.`);
9980
10329
  }
9981
10330
  }
9982
10331
  function integer5(value, path2, minimum = 0) {
@@ -10009,7 +10358,7 @@ function trustedWorkflowRef(value, path2) {
10009
10358
  return result;
10010
10359
  }
10011
10360
  function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
10012
- const input = object4(value, path2);
10361
+ const input = object4(detachedQualificationContract(value), path2);
10013
10362
  exact3(input, ["repository", "commit", "ref", "workflowRef", "workflowSha", "runId", "runAttempt", "job", "eventName", "oidcAttestation"], path2);
10014
10363
  const repository = token3(input.repository, `${path2}.repository`);
10015
10364
  if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
@@ -10028,10 +10377,10 @@ function parseTrustedWorkflowProvenance(value, path2 = "provenance") {
10028
10377
  token3(oidc.audience, `${path2}.oidcAttestation.audience`, 2048);
10029
10378
  sha2(oidc.verifiedClaimsSha256, `${path2}.oidcAttestation.verifiedClaimsSha256`);
10030
10379
  timestamp(oidc.verifiedAt, `${path2}.oidcAttestation.verifiedAt`);
10031
- return input;
10380
+ return freezeJson3(input);
10032
10381
  }
10033
10382
  function parseQualificationExecutionProducer(value, path2 = "producer") {
10034
- const input = object4(value, path2);
10383
+ const input = object4(detachedQualificationContract(value), path2);
10035
10384
  exact3(input, ["repository", "commit", "ref", "runId", "runAttempt", "job", "trustedWorkflowRepository", "trustedWorkflowRef", "trustedWorkflowSha", "runner"], path2);
10036
10385
  const repository = token3(input.repository, `${path2}.repository`);
10037
10386
  if (!repository.startsWith("Plasius-LTD/")) throw new TypeError(`${path2}.repository is outside Plasius-LTD.`);
@@ -10049,7 +10398,7 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
10049
10398
  if (!["github-hosted", "self-hosted", "device-farm"].includes(String(runner.environment))) throw new TypeError(`${path2}.runner.environment is invalid.`);
10050
10399
  token3(runner.os, `${path2}.runner.os`);
10051
10400
  token3(runner.architecture, `${path2}.runner.architecture`);
10052
- return input;
10401
+ return freezeJson3(input);
10053
10402
  }
10054
10403
  function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
10055
10404
  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.`);
@@ -10058,26 +10407,32 @@ function assertProducerMatchesPreflight(producer, provenance, cell, path2, expec
10058
10407
  if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
10059
10408
  }
10060
10409
  function canonicalEqual(left, right) {
10061
- return canonicalizeGpuContract(left) === canonicalizeGpuContract(right);
10410
+ return canonicalizeQualificationGpuContract(left) === canonicalizeQualificationGpuContract(right);
10062
10411
  }
10063
10412
  function foldRunnerLabel(value) {
10064
10413
  return value.replace(/[A-Z]/gu, (character) => character.toLowerCase());
10065
10414
  }
10066
10415
  async function computeQualificationInventorySha256(bundle) {
10067
- return computeSha256(canonicalizeGpuContract(bundle.inventory));
10416
+ const snapshot = detachedQualificationContract(bundle);
10417
+ return computeSha256(canonicalizeQualificationGpuContract(snapshot.inventory));
10068
10418
  }
10069
10419
  async function computeQualificationSubjectBinding(input) {
10070
10420
  return computeSha256(`plasius.gpu.qualification-subject/v1
10071
- ${canonicalizeGpuContract(input)}`);
10421
+ ${canonicalizeQualificationGpuContract(input)}`);
10072
10422
  }
10073
10423
  async function computeValidationEvidenceId(value) {
10074
10424
  const input = object4(value, "evidence identity input");
10075
10425
  const projection = Object.fromEntries(Object.entries(input).filter(([key]) => key !== "evidenceId"));
10076
10426
  return `qualification-${(await computeSha256(`plasius.gpu.validation-evidence/v1
10077
- ${canonicalizeGpuContract(projection)}`)).slice(0, 24)}`;
10427
+ ${canonicalizeQualificationGpuContract(projection)}`)).slice(0, 24)}`;
10078
10428
  }
10079
10429
  function immutableBlobUri(value) {
10080
- const url = new URL(value);
10430
+ let url;
10431
+ try {
10432
+ url = new URL(value);
10433
+ } catch {
10434
+ throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
10435
+ }
10081
10436
  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 === ".."))) {
10082
10437
  throw new TypeError("Source URI must be a normalized immutable Azure Blob .tar URL.");
10083
10438
  }
@@ -10087,12 +10442,7 @@ function immutableBlobUri(value) {
10087
10442
  }
10088
10443
  async function createQualificationPreflight(input) {
10089
10444
  token3(input.qualificationId, "qualificationId");
10090
- let parsedMatrix;
10091
- try {
10092
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10093
- } catch (cause) {
10094
- throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
10095
- }
10445
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Selected matrix artifact");
10096
10446
  if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
10097
10447
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
10098
10448
  if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
@@ -10262,12 +10612,7 @@ function syntheticResult(unitId, cell, status, message, now) {
10262
10612
  async function aggregateShaderValidationEvidence(input) {
10263
10613
  const verifyArtifact = async (artifact2, label) => {
10264
10614
  if (await computeSha256(artifact2.bytes) !== artifact2.sha256) throw new TypeError(`${label} artifact digest is not derived from its exact bytes.`);
10265
- let parsed;
10266
- try {
10267
- parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(artifact2.bytes));
10268
- } catch (cause) {
10269
- throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
10270
- }
10615
+ const parsed = parseQualificationJsonBytes(artifact2.bytes, `${label} bytes`);
10271
10616
  if (!canonicalEqual(parsed, artifact2.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
10272
10617
  };
10273
10618
  await verifyArtifact(input.preflight, "Qualification preflight");
@@ -10289,12 +10634,7 @@ async function aggregateShaderValidationEvidence(input) {
10289
10634
  exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
10290
10635
  const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
10291
10636
  if (!canonicalEqual(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
10292
- let parsedMatrix;
10293
- try {
10294
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10295
- } catch (cause) {
10296
- throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
10297
- }
10637
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
10298
10638
  if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10299
10639
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
10300
10640
  if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
@@ -10368,7 +10708,7 @@ async function aggregateShaderValidationEvidence(input) {
10368
10708
  if (cellArtifact || diagnostic) throw new TypeError(`Unavailable cell ${cell.cellId} has conflicting evidence.`);
10369
10709
  for (const unit of units) results.push(syntheticResult(unit, cell, "runner-unavailable", "Required physical runner was unavailable.", now));
10370
10710
  const cellResults = results.slice(-units.size);
10371
- 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" });
10711
+ 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" });
10372
10712
  continue;
10373
10713
  }
10374
10714
  if (diagnostic) {
@@ -10383,7 +10723,7 @@ async function aggregateShaderValidationEvidence(input) {
10383
10723
  const status2 = value2.status === "timeout" ? "timeout" : "failed";
10384
10724
  for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
10385
10725
  const cellResults = results.slice(-units.size);
10386
- 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 });
10726
+ 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 });
10387
10727
  continue;
10388
10728
  }
10389
10729
  if (!cellArtifact) throw new TypeError(`Cell ${cell.cellId} has no qualification evidence.`);
@@ -10391,7 +10731,7 @@ async function aggregateShaderValidationEvidence(input) {
10391
10731
  if (!matchedRunner) throw new TypeError(`Cell evidence ${cell.cellId} producer was not matched by runner preflight.`);
10392
10732
  const value = assertCellEvidence(cellArtifact.value, cell, input.matrix, preflight, input.harness, runner.value.adapterHarness, matchedRunner, units, now);
10393
10733
  results.push(...value.results);
10394
- 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" });
10734
+ 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" });
10395
10735
  }
10396
10736
  const expectedResults = units.size * cells.size;
10397
10737
  if (results.length !== expectedResults) throw new TypeError("Aggregate result product is incomplete.");
@@ -10414,34 +10754,31 @@ async function aggregateShaderValidationEvidence(input) {
10414
10754
  }
10415
10755
  async function validateShaderValidationEvidence(input) {
10416
10756
  try {
10417
- const evidence = object4(input.evidence, "evidence");
10757
+ const evidence = object4(detachedQualificationContract(input.evidence), "evidence");
10758
+ const bundle = detachedQualificationContract(input.bundle);
10759
+ const matrix = detachedQualificationContract(input.matrix);
10418
10760
  exact3(evidence, ["contractVersion", "evidenceId", "status", "generatedAt", "subjectBindingSha256", "subject", "matrixRef", "toolchain", "qualificationPreflightProvenance", "counts", "cellRuns", "results"], "evidence");
10419
10761
  if (evidence.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION) throw new TypeError("Unsupported evidence contract version.");
10420
10762
  const evidenceId = token3(evidence.evidenceId, "evidence.evidenceId");
10421
10763
  const generatedAt = timestamp(evidence.generatedAt, "evidence.generatedAt");
10422
10764
  const subjectBindingSha256 = sha2(evidence.subjectBindingSha256, "evidence.subjectBindingSha256");
10423
10765
  if (evidence.status !== "passed" && evidence.status !== "failed") throw new TypeError("Evidence status is invalid.");
10424
- let parsedMatrix;
10425
- try {
10426
- parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
10427
- } catch (cause) {
10428
- throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
10429
- }
10430
- if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10766
+ const parsedMatrix = parseQualificationJsonBytes(input.matrixBytes, "Matrix artifact");
10767
+ if (!canonicalEqual(parsedMatrix, matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
10431
10768
  const matrixSha256 = await computeSha256(input.matrixBytes);
10432
- const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
10433
- if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
10769
+ const inventorySha256 = await computeQualificationInventorySha256(bundle);
10770
+ if (inventorySha256 !== bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
10434
10771
  const subject = object4(evidence.subject, "evidence.subject");
10435
- const expectedSubjectKeys = [...Object.keys(input.bundle.subject), "dataBundleSha256"];
10772
+ const expectedSubjectKeys = [...Object.keys(bundle.subject), "dataBundleSha256"];
10436
10773
  exact3(subject, expectedSubjectKeys, "evidence.subject");
10437
10774
  const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
10438
- if (!canonicalEqual(candidateSubject, input.bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
10775
+ if (!canonicalEqual(candidateSubject, bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
10439
10776
  const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
10440
10777
  if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
10441
10778
  if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
10442
10779
  const matrixRef = object4(evidence.matrixRef, "evidence.matrixRef");
10443
10780
  exact3(matrixRef, ["matrixId", "version", "sha256"], "evidence.matrixRef");
10444
- if (matrixRef.matrixId !== input.matrix.matrixId || matrixRef.version !== input.matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
10781
+ if (matrixRef.matrixId !== matrix.matrixId || matrixRef.version !== matrix.version || matrixRef.sha256 !== matrixSha256) throw new TypeError("Evidence matrix artifact identity differs.");
10445
10782
  const toolchain = object4(evidence.toolchain, "evidence.toolchain");
10446
10783
  exact3(toolchain, ["packageVersion", "reflectorVersion", "harness"], "evidence.toolchain");
10447
10784
  token3(toolchain.packageVersion, "evidence.toolchain.packageVersion");
@@ -10453,11 +10790,11 @@ async function validateShaderValidationEvidence(input) {
10453
10790
  const harnessSha256 = sha2(harness.sha256, "evidence.toolchain.harness.sha256");
10454
10791
  const preflightProvenance = parseTrustedWorkflowProvenance(evidence.qualificationPreflightProvenance, "evidence.qualificationPreflightProvenance");
10455
10792
  if (Date.parse(generatedAt) < Date.parse(preflightProvenance.oidcAttestation.verifiedAt)) throw new TypeError("Evidence predates trusted preflight verification.");
10456
- const expectedBinding = await computeQualificationSubjectBinding({ subject: input.bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
10793
+ const expectedBinding = await computeQualificationSubjectBinding({ subject: bundle.subject, dataBundleSha256, compileUnitInventorySha256: inventorySha256, matrixSha256, harnessSha256 });
10457
10794
  if (subjectBindingSha256 !== expectedBinding) throw new TypeError("Evidence subject binding is stale.");
10458
10795
  if (evidenceId !== await computeValidationEvidenceId(evidence)) throw new TypeError("Evidence identity is stale.");
10459
- const units = new Set(input.bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
10460
- const cells = new Map(input.matrix.cells.map((cell) => [cell.cellId, cell]));
10796
+ const units = new Set(bundle.inventory.compileUnits.map((unit) => unit.compileUnitId));
10797
+ const cells = new Map(matrix.cells.map((cell) => [cell.cellId, cell]));
10461
10798
  const expected = units.size * cells.size;
10462
10799
  const results = array2(evidence.results, "evidence.results");
10463
10800
  if (results.length !== expected) throw new TypeError("Evidence result product is incomplete.");
@@ -10507,7 +10844,7 @@ async function validateShaderValidationEvidence(input) {
10507
10844
  sha2(automation2.sha256, `${path2}.automation.sha256`);
10508
10845
  } else if (run.automation !== null) throw new TypeError(`${path2}.automation must be null when no adapter completed a cell run.`);
10509
10846
  const cellResults = parsedResults.filter((result) => result.cellId === cellId);
10510
- if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
10847
+ if (run.resultCount !== units.size || cellResults.length !== units.size || await computeSha256(canonicalizeQualificationGpuContract(cellResults)) !== resultsSha256) throw new TypeError(`${path2} result count/digest is stale.`);
10511
10848
  const resultStatuses = new Set(cellResults.map((result) => result.status));
10512
10849
  if (resultStatuses.size !== 1 || !resultStatuses.has(String(run.status))) throw new TypeError(`${path2}.status differs from its results.`);
10513
10850
  if (run.source === "cell-evidence" && run.status !== "passed") throw new TypeError(`${path2} cell evidence must contain passing results.`);
@@ -10516,7 +10853,7 @@ async function validateShaderValidationEvidence(input) {
10516
10853
  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.`);
10517
10854
  }
10518
10855
  if (evidence.status === "passed" !== (passed === expected) || input.requirePassed !== false && evidence.status !== "passed") throw new TypeError("Evidence does not satisfy the required passed gate.");
10519
- return { ok: true, value: evidence };
10856
+ return { ok: true, value: freezeJson3(evidence) };
10520
10857
  } catch (cause) {
10521
10858
  return { ok: false, diagnostics: [{ code: "invalid-contract", severity: "error", message: cause instanceof Error ? cause.message : "Invalid shader validation evidence." }] };
10522
10859
  }
@@ -10531,7 +10868,12 @@ function object5(value) {
10531
10868
  }
10532
10869
  function keys(value, expected) {
10533
10870
  const set = new Set(expected);
10534
- return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key in value);
10871
+ return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => Object.hasOwn(value, key));
10872
+ }
10873
+ function freezeJson4(value) {
10874
+ if (typeof value !== "object" || value === null || Object.isFrozen(value)) return value;
10875
+ for (const child of Object.values(value)) freezeJson4(child);
10876
+ return Object.freeze(value);
10535
10877
  }
10536
10878
  function canonicalEqual2(left, right) {
10537
10879
  try {
@@ -10581,7 +10923,13 @@ var BASELINE = /* @__PURE__ */ new Map([
10581
10923
  ["win11-nvidia-edge-d3d12", "edge|windows|x64|physical|nvidia|qualified-nvidia|d3d12|playwright|self-hosted,Windows,X64,shader-validation,physical-gpu,gpu-nvidia,d3d12"]
10582
10924
  ]);
10583
10925
  function validateStableWebGpuMatrix(value) {
10584
- const matrix = object5(value);
10926
+ let snapshot;
10927
+ try {
10928
+ snapshot = snapshotGpuContract(value);
10929
+ } catch {
10930
+ return { ok: false, diagnostics: [issue3("Matrix must contain bounded detached JSON contract data.")] };
10931
+ }
10932
+ const matrix = object5(snapshot);
10585
10933
  const diagnostics = [];
10586
10934
  if (!matrix || !keys(matrix, ["contractVersion", "matrixId", "version", "policy", "cells"])) {
10587
10935
  return { ok: false, diagnostics: [issue3("Matrix has unknown or missing top-level fields.")] };
@@ -10654,7 +11002,7 @@ function validateStableWebGpuMatrix(value) {
10654
11002
  }
10655
11003
  }
10656
11004
  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."));
10657
- return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: matrix };
11005
+ return diagnostics.length > 0 ? { ok: false, diagnostics } : { ok: true, value: freezeJson4(matrix) };
10658
11006
  }
10659
11007
 
10660
11008
  // src/testing/runner/playwright-swiftshader.ts
@@ -11954,11 +12302,18 @@ function verifyReflectedLayoutProbeOutputs(input) {
11954
12302
 
11955
12303
  // src/compatibility.ts
11956
12304
  function error(code, message, path2) {
11957
- return { code, severity: "error", message, ...path2 ? { path: path2 } : {} };
12305
+ const bounded = [...message].map((character) => {
12306
+ const codePoint = character.codePointAt(0);
12307
+ return codePoint <= 31 || codePoint === 127 ? " " : character;
12308
+ }).slice(0, 512).join("");
12309
+ return { code, severity: "error", message: bounded, ...path2 ? { path: path2 } : {} };
11958
12310
  }
11959
12311
  function interfaceMatches(item, model) {
11960
12312
  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;
11961
12313
  }
12314
+ function hasValidationEvidence(value) {
12315
+ return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
12316
+ }
11962
12317
  function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
11963
12318
  const semantics = new Set(model.providedSemantics);
11964
12319
  const requiredSemantics = /* @__PURE__ */ new Set([
@@ -11997,7 +12352,40 @@ function validateRequirements(shader, gpuInterface, model, capabilities, diagnos
11997
12352
  }
11998
12353
  function validateModelShaderCompatibility(input) {
11999
12354
  const diagnostics = [];
12000
- const { model, shader, gpuInterface, profile, capabilities } = input;
12355
+ let model;
12356
+ let shader;
12357
+ let gpuInterface;
12358
+ let profile;
12359
+ let capabilities;
12360
+ try {
12361
+ const snapshot = snapshotGpuContract(input);
12362
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
12363
+ throw new TypeError("GPU compatibility input must be a bounded contract object.");
12364
+ }
12365
+ const envelope = snapshot;
12366
+ const keys2 = Object.keys(envelope);
12367
+ const allowed = /* @__PURE__ */ new Set(["model", "shader", "gpuInterface", "profile", "capabilities"]);
12368
+ if (keys2.some((key) => !allowed.has(key)) || !["model", "shader", "gpuInterface"].every((key) => Object.hasOwn(envelope, key))) {
12369
+ throw new TypeError("GPU compatibility input has unknown or missing fields.");
12370
+ }
12371
+ const modelSnapshot = envelope.model;
12372
+ const shaderSnapshot = envelope.shader;
12373
+ const gpuInterfaceSnapshot = envelope.gpuInterface;
12374
+ const profileSnapshot = Object.hasOwn(envelope, "profile") ? envelope.profile : void 0;
12375
+ model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
12376
+ shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
12377
+ gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
12378
+ profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
12379
+ capabilities = Object.hasOwn(envelope, "capabilities") ? envelope.capabilities : void 0;
12380
+ } catch (cause) {
12381
+ return {
12382
+ ok: false,
12383
+ diagnostics: [error(
12384
+ "invalid-contract",
12385
+ cause instanceof Error ? cause.message : "GPU compatibility contract snapshot failed."
12386
+ )]
12387
+ };
12388
+ }
12001
12389
  try {
12002
12390
  validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
12003
12391
  } catch (cause) {
@@ -12027,7 +12415,15 @@ function validateModelShaderCompatibility(input) {
12027
12415
  }
12028
12416
  }
12029
12417
  }
12030
- validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
12418
+ try {
12419
+ validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
12420
+ } catch (cause) {
12421
+ diagnostics.push(error(
12422
+ "invalid-contract",
12423
+ cause instanceof Error ? cause.message : "GPU capability snapshot validation failed.",
12424
+ "capabilities"
12425
+ ));
12426
+ }
12031
12427
  if (diagnostics.length > 0) return { ok: false, diagnostics };
12032
12428
  return {
12033
12429
  ok: true,