@plasius/gpu-shader 0.1.0 → 0.1.1

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/testing.cjs CHANGED
@@ -46,7 +46,7 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
46
46
  Object.freeze({
47
47
  matrixId: "stable-webgpu",
48
48
  matrixVersion: "2026-07-13",
49
- matrixSha256: "9b47ff8162b055d49e38c4fe90b9074992ab8c9e1125926e936f8122e6119fd8"
49
+ matrixSha256: "4620eca44fd03004ee7650cfe9fcf42934493611a5097da5525f71578980b016"
50
50
  })
51
51
  ];
52
52
  Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
@@ -540,6 +540,13 @@ function keys(value, expected) {
540
540
  const set = new Set(expected);
541
541
  return Object.keys(value).every((key) => set.has(key)) && expected.every((key) => key in value);
542
542
  }
543
+ function canonicalEqual(left, right) {
544
+ try {
545
+ return canonicalizeGpuContract(left) === canonicalizeGpuContract(right);
546
+ } catch {
547
+ return false;
548
+ }
549
+ }
543
550
  var browserNames = /* @__PURE__ */ new Set(["chromium", "chrome", "edge", "firefox", "safari"]);
544
551
  var osNames = /* @__PURE__ */ new Set(["ubuntu", "windows", "macos", "chromeos", "android", "ios", "ipados", "visionos"]);
545
552
  var backends = /* @__PURE__ */ new Set(["swiftshader", "d3d12", "metal", "vulkan"]);
@@ -633,7 +640,9 @@ function validateStableWebGpuMatrix(value) {
633
640
  const kind = String(requirement?.kind);
634
641
  const validRequirement = requirement && (kind === "exact" ? keys(requirement, ["kind", "value"]) && typeof requirement.value === "string" && /^\d+(?:\.\d+)*$/u.test(requirement.value) : kind === "major" || kind === "minimum-major" ? keys(requirement, ["kind", "value"]) && Number.isSafeInteger(requirement.value) && Number(requirement.value) > 0 : kind === "stable-channel" && keys(requirement, ["kind", "channel"]) && requirement.channel === "stable");
635
642
  if (!validRequirement) diagnostics.push(issue2("OS version requirement is invalid.", `${path2}.os.versionRequirement`));
636
- if (typeof cell.cellId === "string" && JSON.stringify(requirement) !== JSON.stringify(VERSION_REQUIREMENTS.get(cell.cellId))) diagnostics.push(issue2("OS version requirement differs from the stable baseline.", `${path2}.os.versionRequirement`));
643
+ if (typeof cell.cellId === "string" && !canonicalEqual(requirement, VERSION_REQUIREMENTS.get(cell.cellId))) {
644
+ diagnostics.push(issue2("OS version requirement differs from the stable baseline.", `${path2}.os.versionRequirement`));
645
+ }
637
646
  }
638
647
  if (!adapter || !keys(adapter, ["kind", "vendor", "family", "backend"]) || !["software", "physical"].includes(String(adapter.kind)) || !backends.has(String(adapter.backend))) diagnostics.push(issue2("Adapter descriptor is invalid.", `${path2}.adapter`));
639
648
  if (!adapterAutomation || !keys(adapterAutomation, ["kind"]) || !automation.has(String(adapterAutomation.kind))) diagnostics.push(issue2("Automation descriptor is invalid.", `${path2}.automation`));
@@ -1398,12 +1407,12 @@ function parseQualificationExecutionProducer(value, path2 = "producer") {
1398
1407
  return input;
1399
1408
  }
1400
1409
  function assertProducerMatchesPreflight(producer, provenance, cell, path2, expectedJob) {
1401
- 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.`);
1410
+ if (producer.repository !== provenance.repository || !canonicalEqual2(producer.commit, provenance.commit) || producer.ref !== provenance.ref || producer.runId !== provenance.runId || producer.runAttempt !== provenance.runAttempt || producer.trustedWorkflowRepository !== "Plasius-LTD/gpu-shader" || producer.trustedWorkflowRef !== provenance.workflowRef || !canonicalEqual2(producer.trustedWorkflowSha, provenance.workflowSha) || producer.job !== expectedJob) throw new TypeError(`${path2} does not match the exact qualification workflow run or subject.`);
1402
1411
  if (expectedJob === "swiftshader" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify the hosted SwiftShader job.`);
1403
1412
  if (expectedJob === "physical" && producer.runner.environment === "github-hosted") throw new TypeError(`${path2} cannot use a hosted runner for a physical execution cell.`);
1404
1413
  if (expectedJob === "physical-runner-preflight" && producer.runner.environment !== "github-hosted") throw new TypeError(`${path2} must identify its hosted orchestration job truthfully.`);
1405
1414
  }
1406
- function canonicalEqual(left, right) {
1415
+ function canonicalEqual2(left, right) {
1407
1416
  return canonicalizeGpuContract(left) === canonicalizeGpuContract(right);
1408
1417
  }
1409
1418
  function foldRunnerLabel(value) {
@@ -1439,13 +1448,13 @@ async function createQualificationPreflight(input) {
1439
1448
  } catch (cause) {
1440
1449
  throw new TypeError("Selected matrix artifact is not UTF-8 JSON.", { cause });
1441
1450
  }
1442
- if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
1451
+ if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Selected matrix artifact bytes differ from the supplied matrix value.");
1443
1452
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
1444
1453
  if (actualMatrixSha256 !== input.matrixSha256) throw new TypeError("Selected matrix digest is not derived from the exact matrix manifest.");
1445
1454
  const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
1446
1455
  if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject contains a stale compile-unit inventory digest.");
1447
1456
  const requiredCells = input.matrix.cells.map((cell) => cell.cellId);
1448
- if (!canonicalEqual(input.bundle.subject.requiredCellIds, requiredCells)) throw new TypeError("Bundle subject cell set differs from the selected matrix.");
1457
+ if (!canonicalEqual2(input.bundle.subject.requiredCellIds, requiredCells)) throw new TypeError("Bundle subject cell set differs from the selected matrix.");
1449
1458
  const subjectBindingSha256 = await computeQualificationSubjectBinding({
1450
1459
  subject: input.bundle.subject,
1451
1460
  dataBundleSha256: input.dataBundleSha256,
@@ -1505,7 +1514,7 @@ function assertResult(value, path2, cell, passingRequired, timeBounds, expectedR
1505
1514
  const labels = array2(runner.labels, `${path2}.observed.runner.labels`).map((item, index) => token3(item, `${path2}.observed.runner.labels[${index}]`));
1506
1515
  const normalizedLabels = labels.map(foldRunnerLabel);
1507
1516
  if (new Set(normalizedLabels).size !== normalizedLabels.length || cell.runnerLabels.some((label) => !normalizedLabels.includes(foldRunnerLabel(label)))) throw new TypeError(`${path2} actual runner labels do not contain the matrix route (ASCII case-insensitive).`);
1508
- if (expectedRunner && (runnerId !== expectedRunner.name || !canonicalEqual(labels, expectedRunner.labels))) throw new TypeError(`${path2} runner identity/labels differ from the exact runner API preflight observation.`);
1517
+ if (expectedRunner && (runnerId !== expectedRunner.name || !canonicalEqual2(labels, expectedRunner.labels))) throw new TypeError(`${path2} runner identity/labels differ from the exact runner API preflight observation.`);
1509
1518
  const os = object5(observed.os, `${path2}.observed.os`);
1510
1519
  exact3(os, ["name", "version", "channel", "architecture"], `${path2}.observed.os`);
1511
1520
  const osVersion = token3(os.version, `${path2}.observed.os.version`);
@@ -1564,15 +1573,15 @@ function assertCellEvidence(value, cell, matrix, preflight, harness, adapterHarn
1564
1573
  if (input.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || input.qualificationId !== preflight.qualificationId || input.matrixId !== matrix.matrixId || input.matrixVersion !== matrix.version || input.cellId !== cell.cellId || input.matrixSha256 !== preflight.matrixSha256 || input.dataBundleSha256 !== preflight.dataBundleSha256 || input.compileUnitInventorySha256 !== preflight.compileUnitInventorySha256 || input.subjectBindingSha256 !== preflight.subjectBindingSha256) throw new TypeError(`Cell evidence ${cell.cellId} has stale subject/matrix identities.`);
1565
1574
  const actualHarness = object5(input.harness, `cellEvidence.${cell.cellId}.harness`);
1566
1575
  exact3(actualHarness, ["id", "version", "sha256"], `cellEvidence.${cell.cellId}.harness`);
1567
- if (!canonicalEqual(actualHarness, harness)) throw new TypeError(`Cell evidence ${cell.cellId} used a different harness.`);
1576
+ if (!canonicalEqual2(actualHarness, harness)) throw new TypeError(`Cell evidence ${cell.cellId} used a different harness.`);
1568
1577
  const automation2 = object5(input.automation, `cellEvidence.${cell.cellId}.automation`);
1569
1578
  exact3(automation2, ["kind", "driver", "version", "sha256"], `cellEvidence.${cell.cellId}.automation`);
1570
1579
  if (automation2.kind !== cell.automation.kind) throw new TypeError(`Cell evidence ${cell.cellId} used the wrong automation route.`);
1571
1580
  token3(automation2.driver, `cellEvidence.${cell.cellId}.automation.driver`);
1572
1581
  token3(automation2.version, `cellEvidence.${cell.cellId}.automation.version`);
1573
1582
  sha2(automation2.sha256, `cellEvidence.${cell.cellId}.automation.sha256`);
1574
- if (adapterHarness !== null && !canonicalEqual({ id: automation2.driver, version: automation2.version, sha256: automation2.sha256 }, adapterHarness)) throw new TypeError(`Cell evidence ${cell.cellId} automation differs from its independently verified preflight adapter harness.`);
1575
- if (!canonicalEqual(parseTrustedWorkflowProvenance(input.qualificationPreflightProvenance), preflight.provenance)) throw new TypeError(`Cell evidence ${cell.cellId} changed trusted prepare provenance.`);
1583
+ if (adapterHarness !== null && !canonicalEqual2({ id: automation2.driver, version: automation2.version, sha256: automation2.sha256 }, adapterHarness)) throw new TypeError(`Cell evidence ${cell.cellId} automation differs from its independently verified preflight adapter harness.`);
1584
+ if (!canonicalEqual2(parseTrustedWorkflowProvenance(input.qualificationPreflightProvenance), preflight.provenance)) throw new TypeError(`Cell evidence ${cell.cellId} changed trusted prepare provenance.`);
1576
1585
  const producer = parseQualificationExecutionProducer(input.producer, `cellEvidence.${cell.cellId}.producer`);
1577
1586
  assertProducerMatchesPreflight(producer, preflight.provenance, cell, `cellEvidence.${cell.cellId}.producer`, cell.adapter.kind === "software" ? "swiftshader" : "physical");
1578
1587
  const results = array2(input.results, `cellEvidence.${cell.cellId}.results`);
@@ -1614,7 +1623,7 @@ async function aggregateShaderValidationEvidence(input) {
1614
1623
  } catch (cause) {
1615
1624
  throw new TypeError(`${label} bytes are not UTF-8 JSON.`, { cause });
1616
1625
  }
1617
- if (!canonicalEqual(parsed, artifact.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
1626
+ if (!canonicalEqual2(parsed, artifact.value)) throw new TypeError(`${label} parsed value differs from its exact bytes.`);
1618
1627
  };
1619
1628
  await verifyArtifact(input.preflight, "Qualification preflight");
1620
1629
  for (const artifact of input.cellEvidence) await verifyArtifact(artifact, "Cell evidence");
@@ -1634,14 +1643,14 @@ async function aggregateShaderValidationEvidence(input) {
1634
1643
  const sourceBlob = object5(preflight.sourceBlob, "Qualification preflight.sourceBlob");
1635
1644
  exact3(sourceBlob, ["host", "versionId", "uri"], "Qualification preflight.sourceBlob");
1636
1645
  const normalizedSource = immutableBlobUri(token3(sourceBlob.uri, "Qualification preflight.sourceBlob.uri", 2048));
1637
- if (!canonicalEqual(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
1646
+ if (!canonicalEqual2(sourceBlob, normalizedSource)) throw new TypeError("Qualification preflight source Blob claims are stale.");
1638
1647
  let parsedMatrix;
1639
1648
  try {
1640
1649
  parsedMatrix = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(input.matrixBytes));
1641
1650
  } catch (cause) {
1642
1651
  throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
1643
1652
  }
1644
- if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
1653
+ if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
1645
1654
  const actualMatrixSha256 = await computeSha256(input.matrixBytes);
1646
1655
  if (preflight.matrixSha256 !== actualMatrixSha256) throw new TypeError("Qualification preflight matrix artifact digest is stale.");
1647
1656
  const actualInventorySha256 = await computeQualificationInventorySha256(input.bundle);
@@ -1685,7 +1694,7 @@ async function aggregateShaderValidationEvidence(input) {
1685
1694
  exact3(raw, ["contractVersion", "kind", "qualificationId", "cellId", "status", "matrixSha256", "runnerLabels", "matchedRunners", "adapterHarness", "qualificationPreflightProvenance", "producer"], `runnerPreflight.${cell.cellId}`);
1686
1695
  const producer = parseQualificationExecutionProducer(value2.producer, `runnerPreflight.${cell.cellId}.producer`);
1687
1696
  assertProducerMatchesPreflight(producer, preflight.provenance, cell, `runnerPreflight.${cell.cellId}.producer`, cell.adapter.kind === "software" ? "swiftshader" : "physical-runner-preflight");
1688
- if (value2.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || value2.kind !== "shader-runner-cell-preflight-evidence" || value2.qualificationId !== preflight.qualificationId || value2.cellId !== cell.cellId || value2.matrixSha256 !== preflight.matrixSha256 || !canonicalEqual(value2.runnerLabels, cell.runnerLabels) || !canonicalEqual(value2.qualificationPreflightProvenance, preflight.provenance)) throw new TypeError(`Runner preflight ${cell.cellId} is stale or inconsistent.`);
1697
+ if (value2.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || value2.kind !== "shader-runner-cell-preflight-evidence" || value2.qualificationId !== preflight.qualificationId || value2.cellId !== cell.cellId || value2.matrixSha256 !== preflight.matrixSha256 || !canonicalEqual2(value2.runnerLabels, cell.runnerLabels) || !canonicalEqual2(value2.qualificationPreflightProvenance, preflight.provenance)) throw new TypeError(`Runner preflight ${cell.cellId} is stale or inconsistent.`);
1689
1698
  const requestedLabels = cell.runnerLabels.map(foldRunnerLabel);
1690
1699
  const matched = array2(value2.matchedRunners, `runnerPreflight.${cell.cellId}.matchedRunners`).map((item, index) => {
1691
1700
  const label = `runnerPreflight.${cell.cellId}.matchedRunners[${index}]`;
@@ -1724,7 +1733,7 @@ async function aggregateShaderValidationEvidence(input) {
1724
1733
  const producer = parseQualificationExecutionProducer(value2.producer, `workflowDiagnostic.${cell.cellId}.producer`);
1725
1734
  assertProducerMatchesPreflight(producer, preflight.provenance, cell, `workflowDiagnostic.${cell.cellId}.producer`, cell.adapter.kind === "software" ? "swiftshader" : "physical");
1726
1735
  if (!runner.value.matchedRunners.some((item) => item.name === producer.runner.name)) throw new TypeError(`Workflow diagnostic ${cell.cellId} was not produced by a runner matched in preflight.`);
1727
- if (value2.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || value2.kind !== "non-qualifying-workflow-diagnostic" || value2.qualificationId !== preflight.qualificationId || value2.cellId !== cell.cellId || value2.matrixSha256 !== preflight.matrixSha256 || !canonicalEqual(value2.qualificationPreflightProvenance, preflight.provenance)) throw new TypeError(`Workflow diagnostic ${cell.cellId} is stale or inconsistent.`);
1736
+ if (value2.contractVersion !== SHADER_VALIDATION_EVIDENCE_VERSION || value2.kind !== "non-qualifying-workflow-diagnostic" || value2.qualificationId !== preflight.qualificationId || value2.cellId !== cell.cellId || value2.matrixSha256 !== preflight.matrixSha256 || !canonicalEqual2(value2.qualificationPreflightProvenance, preflight.provenance)) throw new TypeError(`Workflow diagnostic ${cell.cellId} is stale or inconsistent.`);
1728
1737
  token3(value2.message, `workflowDiagnostic.${cell.cellId}.message`, 4096);
1729
1738
  const status2 = value2.status === "timeout" ? "timeout" : "failed";
1730
1739
  for (const unit of units) results.push(syntheticResult(unit, cell, status2, value2.message, now));
@@ -1773,7 +1782,7 @@ async function validateShaderValidationEvidence(input) {
1773
1782
  } catch (cause) {
1774
1783
  throw new TypeError("Matrix artifact is not UTF-8 JSON.", { cause });
1775
1784
  }
1776
- if (!canonicalEqual(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
1785
+ if (!canonicalEqual2(parsedMatrix, input.matrix)) throw new TypeError("Matrix artifact bytes differ from the supplied matrix value.");
1777
1786
  const matrixSha256 = await computeSha256(input.matrixBytes);
1778
1787
  const inventorySha256 = await computeQualificationInventorySha256(input.bundle);
1779
1788
  if (inventorySha256 !== input.bundle.subject.compileUnitInventorySha256) throw new TypeError("Bundle subject inventory digest is stale.");
@@ -1781,7 +1790,7 @@ async function validateShaderValidationEvidence(input) {
1781
1790
  const expectedSubjectKeys = [...Object.keys(input.bundle.subject), "dataBundleSha256"];
1782
1791
  exact3(subject, expectedSubjectKeys, "evidence.subject");
1783
1792
  const candidateSubject = Object.fromEntries(Object.entries(subject).filter(([key]) => key !== "dataBundleSha256"));
1784
- if (!canonicalEqual(candidateSubject, input.bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
1793
+ if (!canonicalEqual2(candidateSubject, input.bundle.subject)) throw new TypeError("Evidence candidate subject differs from bundle.");
1785
1794
  const dataBundleSha256 = sha2(subject.dataBundleSha256, "evidence.subject.dataBundleSha256");
1786
1795
  if (input.dataBundleSha256 && input.dataBundleSha256 !== dataBundleSha256) throw new TypeError("Evidence data bundle digest differs from the exact archive.");
1787
1796
  if (subject.compileUnitInventorySha256 !== inventorySha256) throw new TypeError("Evidence compile-unit inventory digest is stale.");
@@ -1839,11 +1848,11 @@ async function validateShaderValidationEvidence(input) {
1839
1848
  const sourceArtifactSha256 = sha2(run.sourceArtifactSha256, `${path2}.sourceArtifactSha256`);
1840
1849
  if (/^0{64}$/u.test(sourceArtifactSha256)) throw new TypeError(`${path2}.sourceArtifactSha256 cannot be a placeholder.`);
1841
1850
  const resultsSha256 = sha2(run.resultsSha256, `${path2}.resultsSha256`);
1842
- if (!canonicalEqual(parseTrustedWorkflowProvenance(run.qualificationPreflightProvenance, `${path2}.qualificationPreflightProvenance`), preflightProvenance)) throw new TypeError(`${path2} changed qualification preflight provenance.`);
1851
+ if (!canonicalEqual2(parseTrustedWorkflowProvenance(run.qualificationPreflightProvenance, `${path2}.qualificationPreflightProvenance`), preflightProvenance)) throw new TypeError(`${path2} changed qualification preflight provenance.`);
1843
1852
  const producer = parseQualificationExecutionProducer(run.producer, `${path2}.producer`);
1844
1853
  const expectedJob = run.source === "runner-preflight" ? cell.adapter.kind === "software" ? "swiftshader" : "physical-runner-preflight" : cell.adapter.kind === "software" ? "swiftshader" : "physical";
1845
1854
  assertProducerMatchesPreflight(producer, preflightProvenance, cell, `${path2}.producer`, expectedJob);
1846
- if (!canonicalEqual(run.harness, harness)) throw new TypeError(`${path2}.harness differs.`);
1855
+ if (!canonicalEqual2(run.harness, harness)) throw new TypeError(`${path2}.harness differs.`);
1847
1856
  if (run.source === "cell-evidence") {
1848
1857
  const automation2 = object5(run.automation, `${path2}.automation`);
1849
1858
  exact3(automation2, ["kind", "driver", "version", "sha256"], `${path2}.automation`);