stylegallery 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.
Files changed (230) hide show
  1. package/AGENTS.md +4 -1
  2. package/DOMAINS.md +2 -6
  3. package/GOVERNANCE.md +10 -9
  4. package/README.md +23 -127
  5. package/consumer-reference/agent-native/v2/admission-policy.json +646 -0
  6. package/consumer-reference/agent-native/v2/material-registry.json +1 -0
  7. package/consumer-reference/agent-native/v2/schema/admission-policy.schema.json +50 -0
  8. package/consumer-reference/agent-native/v2/schema/material-manifest.schema.json +17 -0
  9. package/consumer-reference/agent-native/v2/schema/material-record.schema.json +20 -0
  10. package/consumer-reference/contract.md +1 -1
  11. package/consumer-reference/index.md +5 -3
  12. package/layout/index.md +124 -0
  13. package/log.md +51 -0
  14. package/package.json +181 -22
  15. package/scripts/agent-native/v2/experimental-extension-registry.mjs +143 -0
  16. package/scripts/agent-native/v2/extensions/a2a-projection.mjs +264 -0
  17. package/scripts/agent-native/v2/extensions/agui-projection.mjs +191 -0
  18. package/scripts/agent-native/v2/material-admission.mjs +295 -0
  19. package/scripts/agent-native/v2/material-cli-adapter.mjs +134 -0
  20. package/scripts/agent-native/v2/material-context.mjs +251 -0
  21. package/scripts/agent-native/v2/material-identity.mjs +71 -0
  22. package/scripts/agent-native/v2/material-mcp-adapter.mjs +253 -0
  23. package/scripts/agent-native/v2/material-operation-registry.mjs +123 -0
  24. package/scripts/agent-native/v2/material-queries.mjs +398 -0
  25. package/scripts/agent-native/v2/material-registry.mjs +319 -0
  26. package/scripts/sg-material-mcp.mjs +98 -0
  27. package/scripts/sg-material.mjs +27 -0
  28. package/consumer-reference/adapters/style-dictionary.config.mjs +0 -36
  29. package/consumer-reference/baselines/calibration.json +0 -260
  30. package/consumer-reference/baselines/manifest.json +0 -21
  31. package/consumer-reference/fixtures/consumer-conformance/e2e-fixture.mjs +0 -282
  32. package/consumer-reference/fixtures/consumer-conformance/manifest.json +0 -102
  33. package/consumer-reference/fixtures/consumer-conformance/runtime-proof.mjs +0 -32
  34. package/consumer-reference/fixtures/consumer-conformance/valid-migration-result.json +0 -18
  35. package/consumer-reference/fixtures/consumer-conformance/valid-migration.json +0 -142
  36. package/consumer-reference/fixtures/invalid-stable-ended-support.json +0 -19
  37. package/consumer-reference/fixtures/promotion/invalid-blocking-evidence.json +0 -26
  38. package/consumer-reference/fixtures/promotion/invalid-count-only.json +0 -29
  39. package/consumer-reference/fixtures/promotion/invalid-missing-owner-migration.json +0 -25
  40. package/consumer-reference/fixtures/promotion/invalid-normative-bypass-no-regression.json +0 -25
  41. package/consumer-reference/fixtures/promotion/invalid-related-counted-independent.json +0 -45
  42. package/consumer-reference/fixtures/promotion/invalid-stable-ended-support.json +0 -26
  43. package/consumer-reference/fixtures/promotion/manifest.json +0 -15
  44. package/consumer-reference/fixtures/promotion/valid-deferred-example.json +0 -67
  45. package/consumer-reference/fixtures/promotion/valid-normative-bypass.json +0 -67
  46. package/consumer-reference/fixtures/token-portability/invalid-cycle.json +0 -7
  47. package/consumer-reference/fixtures/token-portability/invalid-dangling-alias.json +0 -6
  48. package/consumer-reference/fixtures/token-portability/invalid-extends.json +0 -4
  49. package/consumer-reference/fixtures/token-portability/invalid-json-pointer.json +0 -7
  50. package/consumer-reference/fixtures/token-portability/invalid-resolver.json +0 -9
  51. package/consumer-reference/fixtures/token-portability/invalid-type-mismatch.json +0 -10
  52. package/consumer-reference/fixtures/token-portability/invalid-unknown-reserved.json +0 -6
  53. package/consumer-reference/fixtures/token-portability/invalid-untested-type.json +0 -6
  54. package/consumer-reference/fixtures/token-portability/valid-border.json +0 -14
  55. package/consumer-reference/fixtures/token-portability/valid-reference.json +0 -32
  56. package/consumer-reference/fixtures/token-portability/valid-whole-alias.json +0 -7
  57. package/consumer-reference/fixtures/valid-deprecated.json +0 -21
  58. package/consumer-reference/fixtures/valid-experimental.json +0 -19
  59. package/consumer-reference/generated/manifest.json +0 -40
  60. package/consumer-reference/generated/tokens.css +0 -12
  61. package/consumer-reference/policies/shared-experimental.json +0 -37
  62. package/consumer-reference/schema/ax-evidence.schema.json +0 -30
  63. package/consumer-reference/schema/baseline-manifest.schema.json +0 -55
  64. package/consumer-reference/schema/calibration-record.schema.json +0 -190
  65. package/consumer-reference/schema/capture-session.schema.json +0 -161
  66. package/consumer-reference/schema/component-state.schema.json +0 -150
  67. package/consumer-reference/schema/consumer-conformance-record.schema.json +0 -365
  68. package/consumer-reference/schema/dom-evidence.schema.json +0 -38
  69. package/consumer-reference/schema/evidence-record.schema.json +0 -81
  70. package/consumer-reference/schema/fixture-manifest.schema.json +0 -32
  71. package/consumer-reference/schema/item.schema.json +0 -188
  72. package/consumer-reference/schema/page-evidence-manifest.schema.json +0 -216
  73. package/consumer-reference/schema/page-evidence-session.schema.json +0 -119
  74. package/consumer-reference/schema/portable-tokens.schema.json +0 -104
  75. package/consumer-reference/schema/promotion-rfc.schema.json +0 -219
  76. package/consumer-reference/schema/runtime-evidence-manifest.schema.json +0 -33
  77. package/consumer-reference/schema/visual-evidence.schema.json +0 -31
  78. package/design-engineering/consumer-migration-readiness.md +0 -124
  79. package/design-engineering/interface-craft.md +0 -107
  80. package/design-engineering/reference-profiles/external-adaptation/index.md +0 -12
  81. package/design-engineering/reference-profiles/governed-local/editorial/components/button.component.json +0 -125
  82. package/design-engineering/reference-profiles/governed-local/editorial/evidence/button.evidence.json +0 -3504
  83. package/design-engineering/reference-profiles/governed-local/editorial/fixtures/button.fixture.json +0 -65
  84. package/design-engineering/reference-profiles/governed-local/editorial/generated/evidence-coverage.md +0 -23
  85. package/design-engineering/reference-profiles/governed-local/editorial/generated/keyboard-matrix.md +0 -19
  86. package/design-engineering/reference-profiles/governed-local/editorial/generated/state-matrix.md +0 -21
  87. package/design-engineering/reference-profiles/governed-local/editorial/local-foundations.json +0 -12
  88. package/design-engineering/reference-profiles/governed-local/editorial/states/button.states.json +0 -195
  89. package/design-engineering/reference-profiles/governed-local/editorial/tokens.dtcg.json +0 -17
  90. package/design-engineering/reference-profiles/governed-local/terminal/components/button.component.json +0 -125
  91. package/design-engineering/reference-profiles/governed-local/terminal/evidence/button.evidence.json +0 -3504
  92. package/design-engineering/reference-profiles/governed-local/terminal/fixtures/button.fixture.json +0 -65
  93. package/design-engineering/reference-profiles/governed-local/terminal/generated/evidence-coverage.md +0 -23
  94. package/design-engineering/reference-profiles/governed-local/terminal/generated/keyboard-matrix.md +0 -19
  95. package/design-engineering/reference-profiles/governed-local/terminal/generated/state-matrix.md +0 -21
  96. package/design-engineering/reference-profiles/governed-local/terminal/local-foundations.json +0 -12
  97. package/design-engineering/reference-profiles/governed-local/terminal/profile.json +0 -43
  98. package/design-engineering/reference-profiles/governed-local/terminal/states/button.states.json +0 -195
  99. package/design-engineering/reference-profiles/governed-local/terminal/tokens.dtcg.json +0 -17
  100. package/game-ui/classification.md +0 -82
  101. package/game-ui/reference-record.md +0 -62
  102. package/game-ui/screen-hierarchy.md +0 -107
  103. package/game-ui/unity/architecture.md +0 -166
  104. package/game-ui/unity/cli-loop.md +0 -84
  105. package/game-ui/unity/data/unity-technologies-public-repositories.json +0 -26654
  106. package/game-ui/unity/org-wiki.md +0 -146
  107. package/game-ui/unity/repository-map.md +0 -102
  108. package/game-ui/unity/ui-systems.md +0 -85
  109. package/motion/practice-reference.md +0 -145
  110. package/motion/review-workflow.md +0 -86
  111. package/motion/vocabulary.md +0 -82
  112. package/platform-guides/apple-interaction.md +0 -89
  113. package/scripts/agent-native/events.mjs +0 -113
  114. package/scripts/agent-native/immutable-store.mjs +0 -102
  115. package/scripts/artifact-metadata.mjs +0 -20
  116. package/scripts/audit-evidence-freshness.mjs +0 -308
  117. package/scripts/baseline-contract.mjs +0 -189
  118. package/scripts/baseline-schema-parity.mjs +0 -40
  119. package/scripts/build-reference-artifacts.mjs +0 -127
  120. package/scripts/calibration-raw-contract.mjs +0 -172
  121. package/scripts/capture-session-contract.mjs +0 -187
  122. package/scripts/component-state-artifact-fixture.mjs +0 -44
  123. package/scripts/component-state-contract.mjs +0 -99
  124. package/scripts/component-state-semantics.mjs +0 -128
  125. package/scripts/component-state-workflow-contract.mjs +0 -67
  126. package/scripts/component-state-workflow-negative-cases.mjs +0 -64
  127. package/scripts/consumer-conformance-contract.mjs +0 -198
  128. package/scripts/consumer-evidence-governance-contract.mjs +0 -210
  129. package/scripts/consumer-reference-case-runner.mjs +0 -93
  130. package/scripts/consumer-reference-schema.mjs +0 -155
  131. package/scripts/create-component-state-session.mjs +0 -100
  132. package/scripts/create-page-evidence-session.mjs +0 -139
  133. package/scripts/domain-document-boundaries.mjs +0 -40
  134. package/scripts/domain-validation-checks.mjs +0 -141
  135. package/scripts/evidence-artifact-contract.mjs +0 -191
  136. package/scripts/finalize-component-state-evidence.mjs +0 -165
  137. package/scripts/finalize-page-evidence.mjs +0 -197
  138. package/scripts/generate-consumer-reference-evidence.mjs +0 -154
  139. package/scripts/generate-patterns.mjs +0 -218
  140. package/scripts/governance-matrix-contract.mjs +0 -73
  141. package/scripts/governance-matrix-negative-cases.mjs +0 -114
  142. package/scripts/governance-policy-contract.mjs +0 -49
  143. package/scripts/governance-test-fixture.mjs +0 -321
  144. package/scripts/governance-workflow-negative-cases.mjs +0 -241
  145. package/scripts/governed-profile-registry.mjs +0 -125
  146. package/scripts/json-schema-formats.mjs +0 -31
  147. package/scripts/markdown-structure.mjs +0 -45
  148. package/scripts/page-artifact-metadata.mjs +0 -124
  149. package/scripts/page-evidence-contract.mjs +0 -297
  150. package/scripts/page-evidence-fixture.mjs +0 -271
  151. package/scripts/pattern-data.mjs +0 -325
  152. package/scripts/profile-record-contract.mjs +0 -140
  153. package/scripts/promotion-attestation-contract.mjs +0 -91
  154. package/scripts/promotion-boundary-test-contract.mjs +0 -92
  155. package/scripts/promotion-fixture-inventory.mjs +0 -109
  156. package/scripts/promotion-governance-contract.mjs +0 -28
  157. package/scripts/reference-artifact-path-contract.mjs +0 -28
  158. package/scripts/reference-profile-contract.mjs +0 -114
  159. package/scripts/reference-token-contract.mjs +0 -156
  160. package/scripts/run-consumer-page-evidence-ci.mjs +0 -170
  161. package/scripts/summarize-sentinel-calibration.mjs +0 -98
  162. package/scripts/test-agent-adapter-conformance.mjs +0 -250
  163. package/scripts/test-agent-conformance-receipt.mjs +0 -106
  164. package/scripts/test-agent-events.mjs +0 -81
  165. package/scripts/test-agent-execution-effects.mjs +0 -114
  166. package/scripts/test-agent-execution-fixtures.mjs +0 -140
  167. package/scripts/test-agent-execution-kernel.mjs +0 -39
  168. package/scripts/test-agent-execution-learning.mjs +0 -130
  169. package/scripts/test-agent-execution-lifecycle.mjs +0 -143
  170. package/scripts/test-agent-execution-safety.mjs +0 -158
  171. package/scripts/test-agent-execution-views.mjs +0 -117
  172. package/scripts/test-agent-identity-integrity-cases.mjs +0 -160
  173. package/scripts/test-agent-knowledge-kernel.mjs +0 -183
  174. package/scripts/test-agent-learning.mjs +0 -246
  175. package/scripts/test-agent-mcp.mjs +0 -246
  176. package/scripts/test-agent-native-schemas.mjs +0 -215
  177. package/scripts/test-agent-projections.mjs +0 -249
  178. package/scripts/test-agent-registry-mcp-integrity.mjs +0 -215
  179. package/scripts/test-agent-registry-mutations.mjs +0 -110
  180. package/scripts/test-audit-evidence-freshness.mjs +0 -177
  181. package/scripts/test-component-state-sentinel.mjs +0 -35
  182. package/scripts/test-component-state-source-contract.mjs +0 -83
  183. package/scripts/test-consumer-conformance-sentinel.mjs +0 -165
  184. package/scripts/test-consumer-reference-sentinel.mjs +0 -31
  185. package/scripts/test-generate-consumer-reference-evidence.mjs +0 -124
  186. package/scripts/test-json-cli-output.mjs +0 -151
  187. package/scripts/test-json-schema-formats.mjs +0 -40
  188. package/scripts/test-reference-adapters.mjs +0 -199
  189. package/scripts/test-renderer-purity.mjs +0 -34
  190. package/scripts/test-sg-cli.mjs +0 -129
  191. package/scripts/test-summarize-sentinel-calibration.mjs +0 -226
  192. package/scripts/test-validate-baseline-manifest.mjs +0 -234
  193. package/scripts/test-validate-component-state-artifacts.mjs +0 -243
  194. package/scripts/test-validate-component-state.mjs +0 -106
  195. package/scripts/test-validate-consumer-conformance.mjs +0 -427
  196. package/scripts/test-validate-consumer-reference-cli.mjs +0 -69
  197. package/scripts/test-validate-consumer-reference.mjs +0 -263
  198. package/scripts/test-validate-domains.mjs +0 -357
  199. package/scripts/test-validate-governance.mjs +0 -292
  200. package/scripts/test-validate-ia.mjs +0 -262
  201. package/scripts/test-validate-okf.mjs +0 -73
  202. package/scripts/test-validate-page-evidence.mjs +0 -302
  203. package/scripts/test-validate-patterns.mjs +0 -157
  204. package/scripts/test-validate-promotion-rfc.mjs +0 -250
  205. package/scripts/test-validate-reference-profiles.mjs +0 -170
  206. package/scripts/test-validate-unity-org-wiki.mjs +0 -57
  207. package/scripts/test-validate-unity-source-contracts.mjs +0 -67
  208. package/scripts/test-validate-vocabulary.mjs +0 -174
  209. package/scripts/test-validate-webpage-workflow.mjs +0 -293
  210. package/scripts/validate-baseline-manifest.mjs +0 -44
  211. package/scripts/validate-catalog.mjs +0 -65
  212. package/scripts/validate-component-state.mjs +0 -141
  213. package/scripts/validate-consumer-conformance.mjs +0 -477
  214. package/scripts/validate-consumer-reference.mjs +0 -288
  215. package/scripts/validate-domains.mjs +0 -237
  216. package/scripts/validate-governance.mjs +0 -248
  217. package/scripts/validate-ia.mjs +0 -136
  218. package/scripts/validate-links.mjs +0 -66
  219. package/scripts/validate-okf.mjs +0 -104
  220. package/scripts/validate-page-evidence.mjs +0 -191
  221. package/scripts/validate-patterns.mjs +0 -246
  222. package/scripts/validate-promotion-rfc.mjs +0 -224
  223. package/scripts/validate-reference-artifacts.mjs +0 -125
  224. package/scripts/validate-renderer-purity.mjs +0 -56
  225. package/scripts/validate-unity-org-wiki.mjs +0 -146
  226. package/scripts/validate-unity-source-contracts.mjs +0 -107
  227. package/scripts/validate-vocabulary.mjs +0 -115
  228. package/scripts/validate-webpage-workflow.mjs +0 -254
  229. package/scripts/visual-expectation-contract.mjs +0 -20
  230. package/scripts/workflow-action-contract.mjs +0 -163
@@ -1,141 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import {
7
- canonicalSourceManifest,
8
- canonicalIntended,
9
- readCaptureSession,
10
- sameJson,
11
- sourceManifestMatches,
12
- withinSession,
13
- } from "./capture-session-contract.mjs";
14
- import { compileSchemas, readRecord, validateEvidenceArtifacts, validateProfile } from "./component-state-contract.mjs";
15
- import { resolveProfileRecords } from "./profile-record-contract.mjs";
16
- import { visualExpectationFor } from "./visual-expectation-contract.mjs";
17
-
18
- const repositoryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
19
- const options = { artifactRoot: undefined, json: false, root: path.join(repositoryRoot, "design-engineering/reference-profiles/governed-local"), runtimeManifest: undefined };
20
- const failures = [];
21
-
22
- function validateCommittedVisualExpectations(resolved) {
23
- const evidenceRecord = resolved.records.evidence[0];
24
- const statesRecord = resolved.records.states[0];
25
- if (!evidenceRecord || !statesRecord) return;
26
- const scenarios = new Map((statesRecord.value.scenarios ?? []).map((scenario) => [scenario.id, scenario]));
27
- for (const pass of (evidenceRecord.value.passes ?? []).filter((candidate) => candidate.channel === "visual")) {
28
- const scenario = scenarios.get(pass.scenario_id);
29
- if (!scenario) continue;
30
- try {
31
- const expected = visualExpectationFor(scenario, pass.environment, statesRecord.value.visual_environments ?? []);
32
- const actual = pass.artifact ?? {};
33
- if (actual.sha256 !== expected.sha256 || actual.width !== expected.width || actual.height !== expected.height) {
34
- failures.push({ code: "evidence_visual_expectation_mismatch", message: `${pass.id} committed visual metadata differs from its canonical environment expectation`, path: evidenceRecord.path });
35
- }
36
- } catch (error) {
37
- failures.push({ code: "evidence_visual_expectation_invalid", message: error instanceof Error ? error.message : String(error), path: evidenceRecord.path });
38
- }
39
- }
40
- }
41
-
42
- for (let index = 2; index < process.argv.length; index += 1) {
43
- const argument = process.argv[index];
44
- if (argument === "--json") options.json = true;
45
- else if (["--artifact-root", "--runtime-manifest", "--root"].includes(argument)) {
46
- const value = process.argv[index + 1];
47
- if (!value) failures.push({ code: "argument_value_required", message: `${argument} requires a path`, path: "<cli>" });
48
- else {
49
- if (argument === "--artifact-root") options.artifactRoot = path.resolve(value);
50
- if (argument === "--runtime-manifest") options.runtimeManifest = path.resolve(value);
51
- if (argument === "--root") options.root = path.resolve(value);
52
- index += 1;
53
- }
54
- } else failures.push({ code: "argument_unknown", message: `unsupported argument ${argument}`, path: "<cli>" });
55
- }
56
-
57
- const schemas = compileSchemas(path.join(repositoryRoot, "consumer-reference/schema"));
58
- let runtimeManifest;
59
- let capture;
60
- let canonicalSource;
61
- if (!options.runtimeManifest) {
62
- try { canonicalSource = canonicalSourceManifest(repositoryRoot, options.root); }
63
- catch (error) { failures.push({ code: "capture_source_unreadable", message: error instanceof Error ? error.message : String(error), path: options.root }); }
64
- }
65
- if (options.runtimeManifest) {
66
- runtimeManifest = readRecord(options.runtimeManifest, failures);
67
- if (!options.artifactRoot) failures.push({ code: "runtime_manifest_artifact_root_required", message: "--runtime-manifest requires --artifact-root", path: "<cli>" });
68
- if (runtimeManifest && !schemas.runtime(runtimeManifest)) for (const error of schemas.runtime.errors ?? []) failures.push({ code: "runtime_manifest_schema_invalid", message: `${error.instancePath || "/"} ${error.message}`, path: options.runtimeManifest });
69
- if (options.artifactRoot) capture = readCaptureSession(path.join(options.artifactRoot, "capture-session.json"), schemas.capture, failures);
70
- if (capture && runtimeManifest) {
71
- const session = runtimeManifest.session;
72
- if (!session || !sameJson(session.receipt, capture.artifact) || session.receipt_sha256 !== capture.digest) failures.push({ code: "capture_session_receipt_mismatch", message: "manifest receipt metadata does not match capture-session.json", path: options.runtimeManifest });
73
- const expectedLink = capture.link;
74
- for (const key of ["session_id", "nonce", "started_at", "revision", "branch", "attempt", "environment", "source"]) if (!sameJson(session?.[key], expectedLink[key])) failures.push({ code: "capture_session_mismatch", message: `manifest ${key} differs from receipt`, path: options.runtimeManifest });
75
- for (const key of ["repository", "intended"]) if (!sameJson(session?.[key], capture.receipt[key])) failures.push({ code: "capture_session_mismatch", message: `manifest ${key} differs from receipt`, path: options.runtimeManifest });
76
- if (runtimeManifest.recorded_at !== session?.completed_at) failures.push({ code: "evidence_recorded_at_mismatch", message: "manifest recorded_at must equal session completed_at", path: options.runtimeManifest });
77
- if (!withinSession(session?.completed_at, capture.receipt.started_at, session?.completed_at)) failures.push({ code: "capture_session_time_outside", message: "completed_at precedes session start", path: options.runtimeManifest });
78
- const canonical = canonicalIntended(options.root, failures);
79
- if (!sameJson(capture.receipt.intended, canonical)) failures.push({ code: "capture_session_intent_mismatch", message: "receipt intent differs from current canonical records", path: options.runtimeManifest });
80
- if (!capture.receipt.source) failures.push({ code: "capture_source_missing", message: "capture receipt must include its canonical source manifest", path: options.runtimeManifest });
81
- else if (!sourceManifestMatches(capture.receipt.source, repositoryRoot, options.root)) failures.push({ code: "capture_source_drift", message: "current capture sources differ from the receipt source manifest", path: options.runtimeManifest });
82
- const run = runtimeManifest.run;
83
- if (run?.id !== capture.receipt.session_id || run?.repository !== capture.receipt.repository || run?.revision !== capture.receipt.revision || run?.attempt !== capture.receipt.attempt) failures.push({ code: "capture_session_mismatch", message: "manifest run differs from receipt", path: options.runtimeManifest });
84
- for (const record of runtimeManifest.records ?? []) {
85
- for (const pass of record.passes ?? []) {
86
- if (!sameJson(pass.environment, runtimeManifest.environment) || !sameJson(pass.run, run)) failures.push({ code: "runtime_manifest_identity_mismatch", message: `${pass.id} does not match the closed manifest identity`, path: options.runtimeManifest });
87
- if (!sameJson(pass.session, capture.link) || !sameJson(pass.environment, capture.receipt.environment) || !sameJson(pass.run, run)) failures.push({ code: "capture_session_mismatch", message: `${pass.id} pass identity differs from receipt`, path: options.runtimeManifest });
88
- }
89
- }
90
- }
91
- } else if (options.artifactRoot) failures.push({ code: "runtime_manifest_required", message: "artifact validation requires --runtime-manifest", path: "<cli>" });
92
-
93
- const profiles = fs.existsSync(options.root)
94
- ? fs.readdirSync(options.root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && fs.existsSync(path.join(options.root, entry.name, "profile.json"))).map((entry) => entry.name).sort()
95
- : [];
96
- if (profiles.length === 0) failures.push({ code: "profile_root_empty", message: "governed-local root must contain profiles", path: options.root });
97
- for (const profile of profiles) {
98
- const profileRoot = path.join(options.root, profile);
99
- failures.push(...validateProfile(profileRoot, schemas));
100
- if (!runtimeManifest) {
101
- const resolved = resolveProfileRecords(profileRoot, failures);
102
- if (resolved) validateCommittedVisualExpectations(resolved);
103
- const evidenceRecord = resolved?.records.evidence[0];
104
- if (canonicalSource) {
105
- for (const pass of evidenceRecord?.value.passes ?? []) {
106
- if (!pass.session?.source) failures.push({ code: "capture_source_missing", message: `${pass.id} committed evidence must include its canonical source manifest`, path: evidenceRecord.path });
107
- else if (!sameJson(pass.session.source, canonicalSource)) failures.push({ code: "capture_source_drift", message: `${pass.id} committed evidence source differs from current canonical capture sources`, path: evidenceRecord.path });
108
- }
109
- }
110
- }
111
- const profileId = JSON.parse(fs.readFileSync(path.join(profileRoot, "profile.json"), "utf8")).id;
112
- const matching = runtimeManifest?.records?.filter((record) => record.profile_id === profileId) ?? [];
113
- if (runtimeManifest && matching.length !== 1) failures.push({ code: "runtime_manifest_profile_count", message: `${profileId} requires exactly one runtime evidence record`, path: options.runtimeManifest });
114
- if (options.artifactRoot && runtimeManifest) failures.push(...validateEvidenceArtifacts(profileRoot, options.artifactRoot, matching[0], schemas, runtimeManifest.session));
115
- }
116
- if (runtimeManifest) {
117
- const known = new Set(profiles.map((profile) => JSON.parse(fs.readFileSync(path.join(options.root, profile, "profile.json"), "utf8")).id));
118
- for (const record of runtimeManifest.records ?? []) if (!known.has(record.profile_id)) failures.push({ code: "runtime_manifest_profile_unknown", message: `${record.profile_id} is not a governed profile`, path: options.runtimeManifest });
119
- }
120
- if (runtimeManifest && options.artifactRoot) {
121
- const passes = (runtimeManifest.records ?? []).flatMap((record) => record.passes ?? []);
122
- const passArtifacts = new Set(passes.map((pass) => pass.artifact?.path).filter(Boolean));
123
- if (passArtifacts.size !== 30) failures.push({ code: "runtime_channel_count_mismatch", message: `manifest requires exactly 30 unique channel artifacts, found ${passArtifacts.size}`, path: options.runtimeManifest });
124
- const expected = new Set(passArtifacts);
125
- for (const pass of passes) if (pass.channel === "visual" && pass.artifact?.path?.endsWith(".png")) expected.add(pass.artifact.path.replace(/\.png$/, ".visual.json"));
126
- if (expected.size !== 40) failures.push({ code: "runtime_artifact_count_mismatch", message: `manifest requires exactly 40 runtime files, found ${expected.size}`, path: options.runtimeManifest });
127
- const runtimeRoot = path.join(options.artifactRoot, "runtime");
128
- const actual = fs.existsSync(runtimeRoot) ? fs.readdirSync(runtimeRoot, { withFileTypes: true }) : [];
129
- for (const entry of actual) {
130
- const reference = `runtime/${entry.name}`;
131
- if (!entry.isFile() || !expected.has(reference)) failures.push({ code: "runtime_artifact_unmanifested", message: `${reference} is not a declared regular session artifact`, path: runtimeRoot });
132
- }
133
- for (const reference of expected) if (!fs.existsSync(path.join(options.artifactRoot, reference))) failures.push({ code: "runtime_artifact_missing", message: `${reference} is missing`, path: runtimeRoot });
134
- }
135
-
136
- const uniqueFailures = [...new Map(failures.map((failure) => [`${failure.code}:${failure.path}:${failure.message}`, failure])).values()];
137
- const result = { checkedProfiles: profiles.length, failures: uniqueFailures, ok: uniqueFailures.length === 0, warnings: [] };
138
- if (options.json) process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
139
- else if (result.ok) process.stdout.write(`ok: ${profiles.length} governed-local component profiles\n`);
140
- else process.stderr.write(`${result.failures.map((failure) => `${failure.code}: ${failure.path}: ${failure.message}`).join("\n")}\n`);
141
- if (!result.ok) process.exitCode = 1;
@@ -1,477 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { spawnSync } from "node:child_process";
7
- import { isDeepStrictEqual } from "node:util";
8
- import { fileURLToPath } from "node:url";
9
- import Ajv2020 from "ajv/dist/2020.js";
10
- import {
11
- MIGRATION_DIMENSIONS,
12
- consumerConformanceSchemaFindings,
13
- isNormalizedRepositoryPath,
14
- validateConsumerConformanceSemantics,
15
- validateConsumerPageEvidenceSemantics,
16
- validateConsumerPageIntentSemantics,
17
- } from "./consumer-conformance-contract.mjs";
18
- import { parseStrictJson } from "./strict-json.mjs";
19
- import { addDateTimeFormat } from "./json-schema-formats.mjs";
20
- import {
21
- addSchemaFindings,
22
- compilePageEvidenceSchemas,
23
- digest,
24
- gitIdentity,
25
- normalizeReference,
26
- PAGE_EVIDENCE_MANIFEST,
27
- readJsonFile,
28
- resolveContained,
29
- } from "./page-evidence-contract.mjs";
30
- import { MAX_ARTIFACT_FILE_BYTES } from "./page-artifact-metadata.mjs";
31
-
32
- const styleGalleryRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
33
- const schemaPath = path.join(styleGalleryRoot, "consumer-reference", "schema", "consumer-conformance-record.schema.json");
34
- const pageSchemaRoot = path.join(styleGalleryRoot, "consumer-reference", "schema");
35
- const pageValidator = path.join(styleGalleryRoot, "scripts", "validate-page-evidence.mjs");
36
- const runtimeTimeout = Math.min(120_000, Math.max(100, Number.parseInt(process.env.STYLEGALLERY_RUNTIME_TIMEOUT_MS ?? "120000", 10) || 120_000));
37
-
38
- function finding(code, message, recordPath) {
39
- return { code, message, path: recordPath };
40
- }
41
-
42
- function parseArguments(argv) {
43
- const options = { artifactRoot: undefined, json: false, priorManifest: undefined, record: undefined, root: process.cwd() };
44
- const failures = [];
45
- for (let index = 2; index < argv.length; index += 1) {
46
- const argument = argv[index];
47
- if (argument === "--json") options.json = true;
48
- else if (["--artifact-root", "--prior-manifest", "--record", "--root"].includes(argument)) {
49
- const value = argv[index + 1];
50
- if (!value || value.startsWith("--")) failures.push(finding("argument_value_required", `${argument} requires a value`, "<cli>"));
51
- else {
52
- if (argument === "--artifact-root") options.artifactRoot = value;
53
- if (argument === "--prior-manifest") options.priorManifest = value;
54
- if (argument === "--record") options.record = value;
55
- if (argument === "--root") options.root = value;
56
- index += 1;
57
- }
58
- } else failures.push(finding("argument_unknown", `unsupported argument ${argument}`, "<cli>"));
59
- }
60
- if (!options.record) failures.push(finding("argument_value_required", "--record requires a normalized JSON path", "<cli>"));
61
- return { failures, options };
62
- }
63
-
64
- function containedRecord(rootArgument, recordArgument, failures) {
65
- const root = path.resolve(process.cwd(), rootArgument);
66
- if (!fs.existsSync(root) || !fs.lstatSync(root).isDirectory() || fs.realpathSync(root) !== root) {
67
- failures.push(finding("consumer_conformance_root_invalid", "consumer root must be a real directory without filesystem redirects", rootArgument));
68
- return undefined;
69
- }
70
- if (!isNormalizedRepositoryPath(recordArgument, { jsonOnly: true })) {
71
- failures.push(finding("consumer_conformance_record_path_invalid", "--record must be a normalized repository-relative JSON path", recordArgument));
72
- return undefined;
73
- }
74
- const resolved = path.resolve(root, recordArgument);
75
- const relative = path.relative(root, resolved);
76
- if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative) || !fs.existsSync(resolved)) {
77
- failures.push(finding("consumer_conformance_record_path_invalid", "consumer conformance record must exist inside the consumer root", recordArgument));
78
- return undefined;
79
- }
80
- let current = root;
81
- for (const segment of relative.split(path.sep).filter(Boolean)) {
82
- current = path.join(current, segment);
83
- if (fs.lstatSync(current).isSymbolicLink()) {
84
- failures.push(finding("consumer_conformance_record_path_invalid", "consumer conformance record must not traverse a symlink", recordArgument));
85
- return undefined;
86
- }
87
- }
88
- if (!fs.lstatSync(resolved).isFile() || fs.realpathSync(resolved) !== resolved) {
89
- failures.push(finding("consumer_conformance_record_path_invalid", "consumer conformance record must be a contained regular file", recordArgument));
90
- return undefined;
91
- }
92
- return { recordPath: relative.split(path.sep).join("/"), resolved, root };
93
- }
94
-
95
- function readStrictJson(file, code, displayPath, failures) {
96
- try {
97
- if (fs.lstatSync(file).size > MAX_ARTIFACT_FILE_BYTES) throw new Error(`file exceeds ${MAX_ARTIFACT_FILE_BYTES} bytes`);
98
- return parseStrictJson(fs.readFileSync(file, "utf8"));
99
- } catch (error) {
100
- failures.push(finding(code, error instanceof Error ? error.message : String(error), displayPath));
101
- return undefined;
102
- }
103
- }
104
-
105
- function uniqueFindings(findings) {
106
- return [...new Map(findings.map((entry) => [`${entry.code}:${entry.path}:${entry.message}`, entry])).values()];
107
- }
108
-
109
- function runGit(root, args, encoding = "utf8") {
110
- return spawnSync("git", ["-c", `safe.directory=${path.resolve(root)}`, ...args], { cwd: root, encoding });
111
- }
112
-
113
- function firstFilesystemRedirect(root) {
114
- const pending = [root];
115
- while (pending.length > 0) {
116
- const directory = pending.pop();
117
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
118
- const target = path.join(directory, entry.name);
119
- const stat = fs.lstatSync(target);
120
- if (stat.isSymbolicLink()) return path.relative(root, target).split(path.sep).join("/");
121
- if (stat.isDirectory()) pending.push(target);
122
- }
123
- }
124
- return undefined;
125
- }
126
-
127
- function executePinnedScenario(root, revision, scenario, expectedResult, failures) {
128
- if (!Array.isArray(scenario?.argv) || scenario.argv.length === 0 || scenario.argv.some((argument) => typeof argument !== "string" || argument.length === 0)) return false;
129
- const [executable, ...args] = scenario.argv;
130
- if (executable !== "node") {
131
- failures.push(finding("runtime_command_executable_invalid", `scenario ${scenario.id ?? "<unknown>"} must use the governed Node runtime`, scenario.id ?? "<scenario>"));
132
- return undefined;
133
- }
134
- const entrypoint = args[0];
135
- if (!isNormalizedRepositoryPath(entrypoint ?? "") || entrypoint.startsWith("-") || !/\.(?:c?js|mjs)$/.test(entrypoint)) {
136
- failures.push(finding("runtime_command_argv_unsafe", `scenario ${scenario.id ?? "<unknown>"} may not override the governed Node permission boundary`, scenario.id ?? "<scenario>"));
137
- return undefined;
138
- }
139
- const temporaryRoot = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "stylegallery-consumer-command-")));
140
- const checkout = path.join(temporaryRoot, "checkout");
141
- let worktreeAdded = false;
142
- try {
143
- const add = runGit(root, ["worktree", "add", "--detach", checkout, revision]);
144
- if (add.status !== 0) {
145
- failures.push(finding("runtime_command_checkout_failed", `scenario ${scenario.id ?? "<unknown>"} could not check out the pinned revision`, scenario.id ?? "<scenario>"));
146
- return false;
147
- }
148
- worktreeAdded = true;
149
- const redirect = firstFilesystemRedirect(checkout);
150
- if (redirect) {
151
- failures.push(finding("runtime_command_checkout_symlink", `scenario ${scenario.id ?? "<unknown>"} checkout contains filesystem redirect ${redirect}`, redirect));
152
- return undefined;
153
- }
154
- const resultFile = path.resolve(checkout, scenario.result_artifact);
155
- fs.rmSync(resultFile, { force: true });
156
- const child = spawnSync(process.execPath, ["--permission", `--allow-fs-read=${checkout}`, `--allow-fs-write=${checkout}`, ...args], {
157
- cwd: checkout,
158
- env: {
159
- CI: "1",
160
- LANG: "C",
161
- LC_ALL: "C",
162
- PATH: process.env.PATH ?? "",
163
- STYLEGALLERY_RESULT_ARTIFACT: scenario.result_artifact,
164
- STYLEGALLERY_RUNTIME_CONTEXT: JSON.stringify(expectedResult),
165
- },
166
- killSignal: "SIGKILL",
167
- shell: false,
168
- stdio: "ignore",
169
- timeout: runtimeTimeout,
170
- });
171
- if (child.error || child.status !== 0) {
172
- const outcome = child.error?.code === "ETIMEDOUT" ? "timed out" : child.signal ? `received ${child.signal}` : `exited ${child.status ?? "without a status"}`;
173
- failures.push(finding("runtime_command_failed", `scenario ${scenario.id ?? "<unknown>"} ${outcome} at the pinned revision`, scenario.id ?? "<scenario>"));
174
- return undefined;
175
- }
176
- try {
177
- const stat = fs.lstatSync(resultFile);
178
- if (stat.size > MAX_ARTIFACT_FILE_BYTES) throw new Error(`result exceeds ${MAX_ARTIFACT_FILE_BYTES} bytes`);
179
- if (!stat.isFile() || stat.isSymbolicLink() || !fs.realpathSync(resultFile).startsWith(`${fs.realpathSync(checkout)}${path.sep}`)) throw new Error("result is not a contained regular file");
180
- return parseStrictJson(fs.readFileSync(resultFile, "utf8"));
181
- } catch (error) {
182
- failures.push(finding("runtime_command_result_missing", `scenario ${scenario.id ?? "<unknown>"} did not produce a valid result artifact: ${error instanceof Error ? error.message : String(error)}`, scenario.result_artifact));
183
- return undefined;
184
- }
185
- } finally {
186
- if (worktreeAdded) {
187
- const removed = runGit(root, ["worktree", "remove", "--force", "--force", checkout]);
188
- if (removed.status !== 0) {
189
- try { fs.rmSync(checkout, { force: true, recursive: true }); } catch {}
190
- runGit(root, ["worktree", "prune", "--expire", "now"]);
191
- const registered = runGit(root, ["worktree", "list", "--porcelain"]);
192
- if (registered.status !== 0 || registered.stdout.includes(checkout)) failures.push(finding("runtime_command_cleanup_failed", `scenario ${scenario.id ?? "<unknown>"} worktree cleanup failed`, scenario.id ?? "<scenario>"));
193
- }
194
- }
195
- fs.rmSync(temporaryRoot, { force: true, recursive: true });
196
- }
197
- }
198
-
199
- function remoteIdentity(remote) {
200
- const cleaned = remote.trim().replace(/\.git$/, "");
201
- const scp = cleaned.match(/^[^@]+@[^:]+:(.+)$/);
202
- if (scp) return scp[1];
203
- try { return new URL(cleaned).pathname.replace(/^\//, ""); }
204
- catch { return undefined; }
205
- }
206
-
207
- function pinnedSourceManifest(root, revision, references, failures) {
208
- if (!Array.isArray(references) || references.length === 0 || new Set(references).size !== references.length) return undefined;
209
- const revisionCheck = runGit(root, ["cat-file", "-e", `${revision}^{commit}`]);
210
- if (revisionCheck.status !== 0) {
211
- failures.push(finding("consumer_revision_unknown", "consumer revision must resolve to a commit in the repository", revision));
212
- return undefined;
213
- }
214
- const files = [];
215
- for (const reference of [...references].sort()) {
216
- if (!isNormalizedRepositoryPath(reference)) continue;
217
- const tree = runGit(root, ["ls-tree", "-z", revision, "--", reference], "buffer");
218
- const entry = tree.status === 0 ? tree.stdout.toString("utf8").split("\0").find((line) => line.endsWith(`\t${reference}`)) : undefined;
219
- if (!entry) {
220
- failures.push(finding("consumer_source_missing", "relevant source is missing from the pinned revision", reference));
221
- continue;
222
- }
223
- const [metadata] = entry.split("\t", 1);
224
- const [mode, type] = metadata.split(" ");
225
- if (mode === "120000") {
226
- failures.push(finding("consumer_source_symlink", "relevant source must not be a symbolic link", reference));
227
- continue;
228
- }
229
- if (type !== "blob") {
230
- failures.push(finding("consumer_source_type_invalid", "relevant source must be a regular file", reference));
231
- continue;
232
- }
233
- const blob = runGit(root, ["show", `${revision}:${reference}`], "buffer");
234
- if (blob.status !== 0) {
235
- failures.push(finding("consumer_source_unreadable", "relevant source could not be read from the pinned revision", reference));
236
- continue;
237
- }
238
- files.push({ byte_length: blob.stdout.length, path: reference, sha256: digest(blob.stdout) });
239
- }
240
- return files.length === references.length ? { files, sha256: digest(Buffer.from(JSON.stringify(files))) } : undefined;
241
- }
242
-
243
- function markdownAnchors(bytes) {
244
- const occurrences = new Map();
245
- return bytes.toString("utf8").split("\n").flatMap((line) => {
246
- const heading = line.match(/^\s{0,3}#{1,6}\s+(.+?)\s*#*\s*$/)?.[1];
247
- if (!heading) return [];
248
- const base = heading
249
- .replace(/`([^`]*)`/g, "$1")
250
- .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
251
- .toLowerCase()
252
- .replace(/[^a-z0-9 _-]/g, "")
253
- .trim()
254
- .replace(/\s+/g, "-");
255
- const occurrence = occurrences.get(base) ?? 0;
256
- occurrences.set(base, occurrence + 1);
257
- return [occurrence === 0 ? `#${base}` : `#${base}-${occurrence}`];
258
- });
259
- }
260
-
261
- function validateStyleGallerySources(value, recordPath, failures) {
262
- const mappings = Array.isArray(value?.adoption_mappings) ? value.adoption_mappings : [];
263
- let checked = 0;
264
- for (const [index, mapping] of mappings.entries()) {
265
- const source = mapping?.stylegallery;
266
- if (!source || !/^[a-f0-9]{40}$/.test(source.revision ?? "") || !isNormalizedRepositoryPath(source.path)) continue;
267
- const revision = runGit(styleGalleryRoot, ["cat-file", "-e", `${source.revision}^{commit}`]);
268
- if (revision.status !== 0) {
269
- failures.push(finding("adoption_stylegallery_revision_unknown", `adoption mapping ${index} revision does not resolve in StyleGallery`, recordPath));
270
- continue;
271
- }
272
- const tree = runGit(styleGalleryRoot, ["ls-tree", "-z", source.revision, "--", source.path], "buffer");
273
- const entry = tree.status === 0 ? tree.stdout.toString("utf8").split("\0").find((line) => line.endsWith(`\t${source.path}`)) : undefined;
274
- if (!entry) {
275
- failures.push(finding("adoption_stylegallery_path_missing", `adoption mapping ${index} path is missing from its pinned StyleGallery revision`, source.path));
276
- continue;
277
- }
278
- const [metadata] = entry.split("\t", 1);
279
- const [mode, type] = metadata.split(" ");
280
- if (mode === "120000" || type !== "blob") {
281
- failures.push(finding("adoption_stylegallery_path_invalid", `adoption mapping ${index} path must be a regular StyleGallery file`, source.path));
282
- continue;
283
- }
284
- const blob = runGit(styleGalleryRoot, ["show", `${source.revision}:${source.path}`], "buffer");
285
- if (blob.status !== 0) {
286
- failures.push(finding("adoption_stylegallery_path_unreadable", `adoption mapping ${index} path could not be read from StyleGallery`, source.path));
287
- continue;
288
- }
289
- if (!markdownAnchors(blob.stdout).includes(source.anchor)) {
290
- failures.push(finding("adoption_stylegallery_anchor_missing", `adoption mapping ${index} anchor is missing from its pinned StyleGallery file`, `${source.path}${source.anchor}`));
291
- continue;
292
- }
293
- checked += 1;
294
- }
295
- return checked;
296
- }
297
-
298
- function validateRuntimeEvidence({ recordPath, root, validateResult, value }, failures) {
299
- const consumer = value?.consumer;
300
- const scenarios = Array.isArray(value?.scenarios) ? value.scenarios : [];
301
- if (!consumer || typeof consumer.repository !== "string" || typeof consumer.revision !== "string" || !Array.isArray(consumer.relevant_sources)) return 0;
302
-
303
- const gitFailures = [];
304
- const identity = gitIdentity(root, gitFailures);
305
- for (const issue of gitFailures) failures.push(finding("consumer_git_invalid", issue.message, issue.path));
306
- if (identity) {
307
- const remote = runGit(root, ["config", "--get", "remote.origin.url"]);
308
- const repositories = new Set([identity.repository, remote.status === 0 ? remoteIdentity(remote.stdout) : undefined].filter(Boolean));
309
- if (repositories.size === 0) failures.push(finding("consumer_repository_unverifiable", "consumer repository requires a verifiable Git remote identity", recordPath));
310
- else if (!repositories.has(consumer.repository)) failures.push(finding("consumer_repository_mismatch", "consumer repository differs from the Git repository identity", recordPath));
311
- }
312
-
313
- const source = pinnedSourceManifest(root, consumer.revision, consumer.relevant_sources, failures);
314
- if (source) {
315
- for (const scenario of scenarios) {
316
- if (scenario?.source_digest !== source.sha256) failures.push(finding("runtime_source_digest_mismatch", `scenario ${scenario?.id ?? "<unknown>"} source digest differs from the pinned relevant sources`, recordPath));
317
- }
318
- }
319
-
320
- let checked = 0;
321
- let executed = 0;
322
- for (const scenario of scenarios) {
323
- if (!isNormalizedRepositoryPath(scenario?.result_artifact, { jsonOnly: true })) continue;
324
- const result = readJsonFile({ prefix: "runtime_result_artifact", reference: scenario.result_artifact, root }, failures);
325
- if (!result) continue;
326
- checked += 1;
327
- if (scenario.evidence_method === "browser" && value.page_evidence?.status === "applicable") continue;
328
- if (!validateResult(result.value)) {
329
- for (const error of validateResult.errors ?? []) failures.push(finding("runtime_result_artifact_schema_invalid", `${error.instancePath || "/"} ${error.message}`, scenario.result_artifact));
330
- continue;
331
- }
332
- const expected = {
333
- argv: scenario.argv,
334
- evidence_method: scenario.evidence_method,
335
- exit_code: scenario.exit_code,
336
- repository: consumer.repository,
337
- revision: consumer.revision,
338
- run_id: scenario.run_id,
339
- scenario_id: scenario.id,
340
- session_id: scenario.session_id,
341
- source_digest: scenario.source_digest,
342
- };
343
- if (Object.entries(expected).some(([key, expectedValue]) => Array.isArray(expectedValue)
344
- ? !Array.isArray(result.value[key]) || expectedValue.length !== result.value[key].length || expectedValue.some((entry, index) => result.value[key][index] !== entry)
345
- : result.value[key] !== expectedValue)) {
346
- failures.push(finding("runtime_result_artifact_mismatch", `scenario ${scenario.id ?? "<unknown>"} result artifact identity differs from the conformance record`, scenario.result_artifact));
347
- }
348
- const executedResult = identity && source ? executePinnedScenario(root, consumer.revision, scenario, expected, failures) : undefined;
349
- if (executedResult !== undefined) {
350
- executed += 1;
351
- if (!validateResult(executedResult)) {
352
- for (const error of validateResult.errors ?? []) failures.push(finding("runtime_command_result_invalid", `${error.instancePath || "/"} ${error.message}`, scenario.result_artifact));
353
- } else if (!isDeepStrictEqual(executedResult, result.value)) {
354
- failures.push(finding("runtime_result_artifact_execution_mismatch", `scenario ${scenario.id ?? "<unknown>"} stored result differs from the result produced at the pinned revision`, scenario.result_artifact));
355
- }
356
- }
357
- }
358
- return { checked, executed };
359
- }
360
-
361
- function runPageValidator({ artifactRoot, manifest, priorManifest, root }, failures) {
362
- const args = [pageValidator, "--root", root, "--artifact-root", artifactRoot, "--manifest", manifest];
363
- if (priorManifest) args.push("--prior-manifest", priorManifest);
364
- args.push("--json");
365
- const child = spawnSync(process.execPath, args, { cwd: styleGalleryRoot, encoding: "utf8" });
366
- let report;
367
- try {
368
- report = parseStrictJson(child.stdout);
369
- } catch (error) {
370
- failures.push(finding("page_evidence_validator_output_invalid", error instanceof Error ? error.message : String(error), manifest));
371
- return undefined;
372
- }
373
- if (Array.isArray(report?.failures)) failures.push(...report.failures);
374
- if (child.status !== 0 && report?.failures?.length === 0) failures.push(finding("page_evidence_validator_failed", "page evidence validator exited without a finding", manifest));
375
- return report;
376
- }
377
-
378
- function validatePageEvidence({ artifactRootArgument, priorManifestArgument, recordPath, root, value }, failures) {
379
- if (value?.page_evidence?.status !== "applicable") return undefined;
380
- const intentFindings = validateConsumerPageIntentSemantics(value, recordPath);
381
- failures.push(...intentFindings);
382
- if (intentFindings.some((entry) => entry.code === "page_evidence_runtime_scenario_required")) return undefined;
383
- if (!artifactRootArgument) {
384
- failures.push(finding("page_evidence_artifact_root_required", "applicable page evidence requires --artifact-root", value.page_evidence.manifest ?? "<page-evidence>"));
385
- return undefined;
386
- }
387
- const artifactReference = normalizeReference(root, artifactRootArgument);
388
- if (!artifactReference) {
389
- failures.push(finding("page_evidence_artifact_escape", "artifact root must be a normalized path inside the consumer root", artifactRootArgument));
390
- return undefined;
391
- }
392
- const artifact = resolveContained({ expectedType: "directory", prefix: "page_evidence_artifact", reference: artifactReference, root }, failures);
393
- const expectedManifest = `${artifactReference}/${PAGE_EVIDENCE_MANIFEST}`;
394
- if (value.page_evidence.manifest !== expectedManifest) {
395
- failures.push(finding("page_evidence_manifest_path_mismatch", `page evidence manifest must equal ${expectedManifest}`, value.page_evidence.manifest));
396
- return undefined;
397
- }
398
- const manifest = readJsonFile({ prefix: "page_evidence_manifest", reference: expectedManifest, root }, failures);
399
- if (!artifact || !manifest) return undefined;
400
- let schemas;
401
- try {
402
- schemas = compilePageEvidenceSchemas(pageSchemaRoot);
403
- } catch (error) {
404
- failures.push(finding("page_evidence_schema_invalid", error instanceof Error ? error.message : String(error), "consumer-reference/schema"));
405
- return undefined;
406
- }
407
- if (!addSchemaFindings(schemas.manifest, manifest.value, manifest.reference, "page_evidence_manifest_schema_invalid", failures)) return undefined;
408
- failures.push(...validateConsumerPageEvidenceSemantics(value, manifest.value, recordPath));
409
-
410
- let priorManifest;
411
- if (priorManifestArgument) {
412
- const reference = normalizeReference(root, priorManifestArgument);
413
- const prior = reference ? resolveContained({ expectedType: "file", prefix: "page_evidence_reuse_manifest", reference, root }, failures) : undefined;
414
- if (!reference) failures.push(finding("page_evidence_reuse_manifest_escape", "prior manifest must be a normalized path inside the consumer root", priorManifestArgument));
415
- priorManifest = prior?.file;
416
- }
417
- if (priorManifestArgument && !priorManifest) return undefined;
418
- return runPageValidator({ artifactRoot: artifact.file, manifest: manifest.file, priorManifest, root }, failures);
419
- }
420
-
421
- const { failures: argumentFailures, options } = parseArguments(process.argv);
422
- const failures = [...argumentFailures];
423
- const record = options.record ? containedRecord(options.root, options.record, failures) : undefined;
424
- const schema = readStrictJson(schemaPath, "consumer_conformance_schema_invalid", "consumer-reference/schema/consumer-conformance-record.schema.json", failures);
425
- const value = record ? readStrictJson(record.resolved, "consumer_conformance_json_invalid", record.recordPath, failures) : undefined;
426
- let checkedRuntimeArtifacts = 0;
427
- let checkedRuntimeCommands = 0;
428
- let checkedStyleGallerySources = 0;
429
- let recordSchemaValid = false;
430
-
431
- if (schema && value !== undefined) {
432
- try {
433
- const ajv = new Ajv2020({ allErrors: true, strict: true });
434
- addDateTimeFormat(ajv);
435
- ajv.addSchema(schema);
436
- const validate = ajv.getSchema(schema.$id);
437
- const validateResult = ajv.compile({ $ref: `${schema.$id}#/$defs/runtimeResult` });
438
- const schemaValid = validate(value);
439
- recordSchemaValid = schemaValid;
440
- if (!schemaValid) failures.push(...consumerConformanceSchemaFindings(validate.errors, record.recordPath));
441
- else {
442
- failures.push(...validateConsumerConformanceSemantics(value, record.recordPath));
443
- checkedStyleGallerySources = validateStyleGallerySources(value, record.recordPath, failures);
444
- const runtimeEvidence = validateRuntimeEvidence({ recordPath: record.recordPath, root: record.root, validateResult, value }, failures);
445
- checkedRuntimeArtifacts = runtimeEvidence.checked;
446
- checkedRuntimeCommands = runtimeEvidence.executed;
447
- }
448
- } catch (error) {
449
- failures.push(finding("consumer_conformance_schema_invalid", error instanceof Error ? error.message : String(error), "consumer-reference/schema/consumer-conformance-record.schema.json"));
450
- }
451
- }
452
-
453
- const pageReport = record && value !== undefined && recordSchemaValid
454
- ? validatePageEvidence({ artifactRootArgument: options.artifactRoot, priorManifestArgument: options.priorManifest, recordPath: record.recordPath, root: record.root, value }, failures)
455
- : undefined;
456
-
457
- const uniqueFailures = uniqueFindings(failures);
458
- const result = {
459
- checkedDimensions: value && typeof value.migration_dimensions === "object" && value.migration_dimensions !== null
460
- ? MIGRATION_DIMENSIONS.filter((name) => Object.hasOwn(value.migration_dimensions, name)).length
461
- : 0,
462
- checkedMappings: Array.isArray(value?.adoption_mappings) ? value.adoption_mappings.length : 0,
463
- checkedRuntimeArtifacts,
464
- checkedRuntimeCommands,
465
- checkedScenarios: Array.isArray(value?.scenarios) ? value.scenarios.length : 0,
466
- checkedStyleGallerySources,
467
- checkedPageArtifacts: pageReport?.artifactCount ?? 0,
468
- checkedPageScenarios: pageReport?.scenarioCount ?? 0,
469
- failures: uniqueFailures,
470
- ok: uniqueFailures.length === 0,
471
- pageSessionId: pageReport?.sessionId ?? null,
472
- record: record?.recordPath ?? options.record ?? null,
473
- };
474
- if (options.json) console.log(JSON.stringify(result, null, 2));
475
- else if (result.ok) console.log(`ok: ${result.checkedDimensions} migration dimensions, ${result.checkedMappings} adoption mappings`);
476
- else console.error(result.failures.map((entry) => `${entry.code}: ${entry.path}: ${entry.message}`).join("\n"));
477
- process.exitCode = result.ok ? 0 : 1;