peachsim 0.1.1667 → 0.1.1673

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 (178) hide show
  1. package/README.md +1 -1
  2. package/cli/bridge-flow-runner.ts +4 -1
  3. package/cli/commands/coverage-swift.ts +291 -0
  4. package/cli/commands/coverage.ts +168 -24
  5. package/cli/commands/diagnose.ts +1 -19
  6. package/cli/commands/react.ts +3 -18
  7. package/cli/commands/screenshot.ts +1 -1
  8. package/cli/commands/screenshots-capture.ts +1 -1
  9. package/cli/drivers/playwright-provisioning.ts +1 -4
  10. package/cli/drivers/playwright.ts +15 -1
  11. package/cli/scene-video.ts +1 -1
  12. package/cli/ui.ts +20 -0
  13. package/cli/ws-bridge.ts +7 -36
  14. package/detox/frame-identity.cjs +21 -0
  15. package/detox/frame-identity.d.cts +6 -0
  16. package/detox/index.ts +39 -33
  17. package/detox/jest-environment.cjs +4 -1
  18. package/detox/jest-setup-after-env.cjs +0 -4
  19. package/detox/navigation-lifecycle.ts +2 -2
  20. package/detox/proof-observer.ts +126 -0
  21. package/dist-lib/agent-daemon-client.cjs +29 -1
  22. package/dist-lib/agent-events.cjs +1 -1
  23. package/dist-lib/attached-projects.cjs +10 -1
  24. package/dist-lib/auth/shared-session.cjs +1 -1
  25. package/dist-lib/backend-origin.cjs +1 -1
  26. package/dist-lib/beta.cjs +1 -1
  27. package/dist-lib/beta.mjs +1 -1
  28. package/dist-lib/bridge-constants.cjs +1 -1
  29. package/dist-lib/bridge-contract-input.cjs +1 -1
  30. package/dist-lib/bridge-contract-input.mjs +1 -1
  31. package/dist-lib/bridge-contract.cjs +1 -1
  32. package/dist-lib/bridge-contract.mjs +1 -1
  33. package/dist-lib/bundle-channel.cjs +530 -154
  34. package/dist-lib/capture-contract.cjs +1 -1
  35. package/dist-lib/capture-contract.mjs +1 -1
  36. package/dist-lib/cloud-contract.cjs +1 -1
  37. package/dist-lib/cloud-contract.mjs +1 -1
  38. package/dist-lib/cloud-test-args.cjs +1 -1
  39. package/dist-lib/cloud-test-args.mjs +1 -1
  40. package/dist-lib/cloud.cjs +1 -1
  41. package/dist-lib/cloud.mjs +1 -1
  42. package/dist-lib/config.cjs +1 -1
  43. package/dist-lib/config.mjs +1 -1
  44. package/dist-lib/detox/index.cjs +5074 -7353
  45. package/dist-lib/detox/jest-environment.cjs +4 -1
  46. package/dist-lib/dev-bundle-resolution.cjs +1 -1
  47. package/dist-lib/expo-swift-bundle.cjs +578 -151
  48. package/dist-lib/expo-swift-metadata.cjs +1 -1
  49. package/dist-lib/expo-swift-metadata.mjs +1 -1
  50. package/dist-lib/home-paths.cjs +1 -1
  51. package/dist-lib/host/bridge-host.cjs +660 -192
  52. package/dist-lib/host/fetch-proxy-handler.cjs +2 -2
  53. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  54. package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
  55. package/dist-lib/host/replacement-module-handler.cjs +1 -1
  56. package/dist-lib/host/websocket-proxy.cjs +1 -1
  57. package/dist-lib/index.cjs +206 -6
  58. package/dist-lib/jump-to-source-babel.cjs +1 -1
  59. package/dist-lib/jump-to-source-native.cjs +1 -1
  60. package/dist-lib/kotlin-host.cjs +1 -1
  61. package/dist-lib/menu.cjs +1 -1
  62. package/dist-lib/menu.mjs +1 -1
  63. package/dist-lib/metro-fingerprint-registry.cjs +1 -1
  64. package/dist-lib/metro-fingerprint-registry.mjs +1 -1
  65. package/dist-lib/metro-production-bundle.cjs +10 -1
  66. package/dist-lib/metro-production-bundle.mjs +12 -1
  67. package/dist-lib/metro.cjs +155 -5
  68. package/dist-lib/native-app-identity-project.cjs +43 -5
  69. package/dist-lib/native-app-identity-project.mjs +43 -5
  70. package/dist-lib/native-app-identity.cjs +1 -1
  71. package/dist-lib/native-app-identity.mjs +1 -1
  72. package/dist-lib/native-firebase-metadata.cjs +1 -1
  73. package/dist-lib/native-firebase-metadata.mjs +1 -1
  74. package/dist-lib/plist.cjs +1 -1
  75. package/dist-lib/plist.mjs +1 -1
  76. package/dist-lib/profiles.cjs +21 -1
  77. package/dist-lib/public-brand.cjs +1 -1
  78. package/dist-lib/public-origins-lib-esm.json +73 -27
  79. package/dist-lib/public-origins-lib-static.json +1 -1
  80. package/dist-lib/public-origins-lib.json +563 -183
  81. package/dist-lib/react-native-host-modules.cjs +1 -1
  82. package/dist-lib/react-native-host-modules.mjs +1 -1
  83. package/dist-lib/reap-browser.cjs +964 -0
  84. package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
  85. package/dist-lib/sdk.cjs +1 -1
  86. package/dist-lib/sdk.mjs +1 -1
  87. package/dist-lib/skills.cjs +963 -521
  88. package/dist-lib/swift-compile.cjs +276 -86
  89. package/dist-lib/swift-compile.mjs +276 -86
  90. package/dist-lib/swift-package.cjs +34 -4
  91. package/dist-lib/swift-package.mjs +33 -4
  92. package/dist-lib/swift-submit.cjs +2 -2
  93. package/dist-lib/swift-submit.mjs +2 -2
  94. package/dist-lib/swift-toolchain.cjs +25 -44
  95. package/dist-lib/swift.cjs +1 -1
  96. package/dist-lib/vite-swift.cjs +579 -113
  97. package/dist-lib/vite.cjs +61 -2
  98. package/dist-lib/worklet-executable.cjs +1 -1
  99. package/dist-lib/worklet-executable.mjs +1 -1
  100. package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +7 -0
  101. package/dist-types/packages/peach-engine/src/engine/glass-material.d.ts +1 -1
  102. package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +2 -0
  103. package/dist-types/packages/peach-engine/src/engine/inspect-outline.d.ts +2 -1
  104. package/dist-types/packages/peach-engine/src/engine/liquid-glass.d.ts +1 -0
  105. package/dist-types/packages/peach-engine/src/engine/paint-boundary.d.ts +3 -1
  106. package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +7 -0
  107. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime-kind.d.ts +24 -0
  108. package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +4 -2
  109. package/dist-types/packages/peach-engine/src/settings/devices.d.ts +1 -0
  110. package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +18 -0
  111. package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
  112. package/dist-types/packages/peach-globals/src/nodeContract.d.ts +1 -0
  113. package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
  114. package/package.json +1 -1
  115. package/runtime-companion.json +1 -1
  116. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +2 -0
  117. package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +36 -0
  118. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStore.h +439 -0
  119. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h +216 -0
  120. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreKey.h +267 -0
  121. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetwork.h +204 -0
  122. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h +1393 -0
  123. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkConnection.h +568 -0
  124. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCNetworkReachability.h +369 -0
  125. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferences.h +473 -0
  126. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesPath.h +179 -0
  127. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCPreferencesSetSpecific.h +95 -0
  128. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h +2395 -0
  129. package/sdk/ios/System/Library/Frameworks/SystemConfiguration.framework/Headers/SystemConfiguration.h +184 -0
  130. package/sdk/ios/usr/include/libkern/OSByteOrder.h +315 -0
  131. package/sdk/ios/usr/include/libkern/machine/OSByteOrder.h +147 -0
  132. package/src/bridge-contract.ts +42 -0
  133. package/src/chromium-admission.ts +196 -0
  134. package/src/host/bridge-host.ts +6 -43
  135. package/src/launch-deadline.ts +74 -0
  136. package/src/nitro-adapter.lock.json +3 -3
  137. package/src/profiles.ts +21 -0
  138. package/src/react-native-coverage/capability-reference-resolution.ts +402 -0
  139. package/src/react-native-coverage/capability-source-references.ts +1296 -0
  140. package/src/react-native-coverage/native-typescript-parser.ts +74 -0
  141. package/src/react-native-coverage/project-aliases.ts +207 -0
  142. package/src/react-native-coverage/verified-reach.ts +47 -0
  143. package/src/reap-browser.ts +1019 -0
  144. package/src/skills/builtin/a11y-review.ts +1 -1
  145. package/src/skills/builtin/perf-profile.ts +1 -1
  146. package/src/skills/builtin/screenshot-all.ts +1 -1
  147. package/src/skills/builtin/visual-diff.ts +1 -1
  148. package/src/swift-compile.ts +107 -56
  149. package/src/swift-coverage/indexdump.ts +80 -0
  150. package/src/swift-coverage/indexing.ts +147 -0
  151. package/src/swift-coverage/package.ts +230 -0
  152. package/src/swift-coverage/provenance.ts +47 -0
  153. package/src/swift-coverage/reader.ts +81 -0
  154. package/src/swift-coverage/source.ts +252 -0
  155. package/src/swift-coverage/types.ts +58 -0
  156. package/src/swift-coverage/xcode-assets.ts +175 -0
  157. package/src/swift-coverage/xcode-bridging.ts +160 -0
  158. package/src/swift-coverage/xcode-packages.ts +251 -0
  159. package/src/swift-coverage/xcode-strings.ts +78 -0
  160. package/src/swift-coverage/xcode.ts +656 -0
  161. package/src/swift-distribution.lock.json +8 -8
  162. package/src/swift-host.ts +21 -1
  163. package/src/swift-objc-import.ts +191 -27
  164. package/src/swift-objc-standin.ts +4 -2
  165. package/src/swift-package-manifest.ts +134 -13
  166. package/src/swift-package.ts +46 -4
  167. package/src/swift-submit.ts +2 -1
  168. package/src/swift-toolchain.ts +36 -61
  169. package/src/worker-system-chunks.ts +3 -10
  170. package/src/xcode-project.ts +5 -5
  171. package/detox/attempt-events.cjs +0 -914
  172. package/detox/attempt-events.d.cts +0 -113
  173. package/detox/motion-change.cjs +0 -524
  174. package/detox/motion-change.d.cts +0 -140
  175. package/detox/motion-leg-starts.cjs +0 -20
  176. package/detox/motion-leg-starts.d.cts +0 -8
  177. package/detox/proof-frame.cjs +0 -190
  178. package/detox/record-block-execution.cjs +0 -78
@@ -1,914 +0,0 @@
1
- const {
2
- parseDiscreteFrameCadence,
3
- } = require('../../peach-conformance/src/cases/checkpoint-evidence.cjs')
4
- const fs = require('node:fs')
5
- const path = require('node:path')
6
-
7
- function attemptEventsPath() {
8
- const enabled =
9
- process.env.CONFORMANCE_PROOF === '1' || Boolean(process.env.CONFORMANCE_PROOF_DIR)
10
- if (!enabled) return null
11
- const root = path.resolve(
12
- process.cwd(),
13
- process.env.CONFORMANCE_PROOF_DIR || 'artifacts/conformance-proof/latest',
14
- )
15
- return path.join(root, 'events.jsonl')
16
- }
17
-
18
- function writeAttemptEvent(event) {
19
- const output = attemptEventsPath()
20
- if (output === null) return false
21
- fs.mkdirSync(path.dirname(output), { recursive: true })
22
- fs.appendFileSync(output, `${JSON.stringify(event)}\n`)
23
- return true
24
- }
25
-
26
- module.exports = { attemptEventsPath, writeAttemptEvent }
27
-
28
- const crypto = require('node:crypto')
29
- const { spawnSync } = require('node:child_process')
30
- const {
31
- classifyDiscreteFrame,
32
- evaluateDiscreteFrameTrace,
33
- } = require('./motion-change.cjs')
34
-
35
- function proofByteHash(bytes) {
36
- return crypto.createHash('sha256').update(bytes).digest('hex')
37
- }
38
-
39
- function proofBoundPath(root, relative) {
40
- if (typeof relative !== 'string' || !relative || path.isAbsolute(relative))
41
- throw new Error('cadence evidence needs a relative path')
42
- const resolved = path.resolve(root, relative)
43
- if (!resolved.startsWith(path.resolve(root) + path.sep))
44
- throw new Error('cadence evidence path escapes its root')
45
- return resolved
46
- }
47
-
48
- // lifecycle receipts bind every clock and census read to the retained bytes.
49
- function boundText(root, relative, sha256, label) {
50
- const bytes = fs.readFileSync(proofBoundPath(root, relative))
51
- if (proofByteHash(bytes) !== sha256)
52
- throw new Error(`${label} does not match its recorded hash`)
53
- return bytes.toString('utf8')
54
- }
55
- module.exports.boundText = boundText
56
-
57
- function authenticateDiscreteFrameAsset(root, declaration, calibrate = false) {
58
- const cadence = parseDiscreteFrameCadence(declaration)
59
- const fixture = fs.readFileSync(proofBoundPath(root, cadence.asset.fixturePath))
60
- const calibration = fs.readFileSync(proofBoundPath(root, cadence.asset.calibrationPath))
61
- if (
62
- (!calibrate && proofByteHash(fixture) !== cadence.asset.fixtureSha256) ||
63
- proofByteHash(calibration) !== cadence.asset.calibrationSha256
64
- )
65
- throw new Error('cadence source or calibration digest mismatch')
66
- const payloads = [
67
- ...fixture.toString().matchAll(/data:[^;\s]+;base64,([A-Za-z0-9+/=]+)/g),
68
- ]
69
- if (
70
- !payloads.some(
71
- (match) =>
72
- proofByteHash(Buffer.from(match[1], 'base64')) === cadence.asset.encodedSha256,
73
- )
74
- )
75
- throw new Error('cadence encoded asset digest mismatch')
76
- const ledger = JSON.parse(calibration.toString())
77
- if (
78
- ledger.version !== 1 ||
79
- ledger.fixtureSha256 !== cadence.asset.fixtureSha256 ||
80
- ledger.encodedSha256 !== cadence.asset.encodedSha256 ||
81
- JSON.stringify(ledger.frames) !== JSON.stringify(cadence.asset.frames) ||
82
- !/^[a-f0-9]{64}$/.test(ledger.originalEvidenceArchiveSha256) ||
83
- !Array.isArray(ledger.calibration) ||
84
- ledger.calibration.length === 0
85
- )
86
- throw new Error('cadence calibration ledger does not authenticate this asset')
87
- return cadence
88
- }
89
-
90
- function assertNormalProofAttempt(root) {
91
- const file = path.join(root, 'capture-context.json')
92
- if (
93
- fs.existsSync(file) &&
94
- JSON.parse(fs.readFileSync(file, 'utf8')).discreteFrameCalibration
95
- )
96
- throw new Error('calibration evidence cannot satisfy a normal proof gate')
97
- }
98
-
99
- function mintProofAttemptContext(root, sourceFingerprint, calibration = false) {
100
- const source = JSON.parse(
101
- fs.readFileSync(path.join(root, 'source-fingerprint.json'), 'utf8'),
102
- )
103
- if (
104
- source.sourceFingerprint !== sourceFingerprint ||
105
- !/^[a-f0-9]{64}$/.test(source.proofSourceFingerprint)
106
- )
107
- throw new Error('cadence attempt needs current source and proof-source identity')
108
- const value = {
109
- version: 1,
110
- ...(calibration ? { discreteFrameCalibration: true } : {}),
111
- attemptNonce: crypto.randomUUID(),
112
- sourceFingerprint,
113
- proofSourceFingerprint: source.proofSourceFingerprint,
114
- }
115
- fs.writeFileSync(
116
- path.join(root, 'capture-context.json'),
117
- JSON.stringify(value) + '\n',
118
- { flag: 'wx' },
119
- )
120
- return value
121
- }
122
-
123
- function beginDiscreteFrameCapture({
124
- root,
125
- sourceRoot,
126
- target,
127
- caseName,
128
- checkpoint,
129
- appearance,
130
- device,
131
- runtime,
132
- probeRect,
133
- outputRect,
134
- rootRect,
135
- cadence,
136
- }) {
137
- if (target.startsWith('android'))
138
- throw new Error('discrete frame cadence is uncalibrated on Android')
139
- if (!fs.existsSync(path.join(root, 'capture-context.json')))
140
- throw new Error(
141
- `discrete frame cadence needs an attempt minted by the paired proof capture (bun run test:conformance:proof); ${root} has no capture-context.json`,
142
- )
143
- const attempt = JSON.parse(
144
- fs.readFileSync(path.join(root, 'capture-context.json'), 'utf8'),
145
- )
146
- const source = JSON.parse(
147
- fs.readFileSync(path.join(root, 'source-fingerprint.json'), 'utf8'),
148
- )
149
- authenticateDiscreteFrameAsset(
150
- sourceRoot,
151
- cadence,
152
- attempt.discreteFrameCalibration === true,
153
- )
154
- if (
155
- attempt.version !== 1 ||
156
- !attempt.attemptNonce ||
157
- attempt.sourceFingerprint !== source.sourceFingerprint ||
158
- attempt.proofSourceFingerprint !== source.proofSourceFingerprint
159
- )
160
- throw new Error('cadence attempt has stale source context')
161
- for (const rect of [probeRect, outputRect, rootRect]) {
162
- if (
163
- !rect ||
164
- !['x', 'y', 'width', 'height'].every((key) => Number.isFinite(rect[key])) ||
165
- rect.width <= 0 ||
166
- rect.height <= 0
167
- )
168
- throw new Error('cadence capture needs measured probe, output and root rectangles')
169
- }
170
- if (!['light', 'dark'].includes(appearance) || !device || !runtime)
171
- throw new Error('cadence capture needs actual appearance/device/runtime')
172
- const context = {
173
- ...attempt,
174
- ...(attempt.discreteFrameCalibration === true
175
- ? {
176
- fixtureSha256: proofByteHash(
177
- fs.readFileSync(proofBoundPath(sourceRoot, cadence.asset.fixturePath)),
178
- ),
179
- }
180
- : {}),
181
- captureNonce: crypto.randomUUID(),
182
- createdAtMs: Date.now(),
183
- target,
184
- caseName,
185
- checkpoint,
186
- appearance,
187
- device,
188
- runtime,
189
- probeRect,
190
- outputRect,
191
- rootRect,
192
- contractSha256: proofByteHash(JSON.stringify(cadence)),
193
- encodedAssetSha256: cadence.asset.encodedSha256,
194
- clock: target.startsWith('ios') ? 'native-presentation' : 'peach-virtual',
195
- }
196
- const relative = `${target}/${caseName}/${checkpoint}/cadence-begin.json`
197
- const output = proofBoundPath(root, relative)
198
- fs.mkdirSync(path.dirname(output), { recursive: true })
199
- fs.writeFileSync(output, JSON.stringify(context) + '\n', { flag: 'wx' })
200
- return context
201
- }
202
-
203
- function decodeDiscreteNativeFrames(recording, cadence, probeRect, rootRect) {
204
- const metadata = spawnSync(
205
- 'ffprobe',
206
- [
207
- '-v',
208
- 'error',
209
- '-fflags',
210
- '+igndts',
211
- '-select_streams',
212
- 'v:0',
213
- '-show_entries',
214
- 'stream=width,height:format=duration:frame=best_effort_timestamp_time',
215
- '-show_frames',
216
- '-of',
217
- 'json',
218
- recording,
219
- ],
220
- { encoding: 'utf8', maxBuffer: 8 * 1024 * 1024, timeout: 30000 },
221
- )
222
- if (metadata.status !== 0)
223
- throw new Error(`cadence native timestamps refused: ${metadata.stderr}`)
224
- const info = JSON.parse(metadata.stdout)
225
- const stream = info.streams?.[0]
226
- if (
227
- !stream ||
228
- !Array.isArray(info.frames) ||
229
- !Number.isFinite(Number(info.format?.duration)) ||
230
- !rootRect ||
231
- rootRect.width <= 0 ||
232
- rootRect.height <= 0
233
- )
234
- throw new Error('cadence recording has no authenticated clock/geometry')
235
- const sx = stream.width / rootRect.width,
236
- sy = stream.height / rootRect.height
237
- const x = Math.round((probeRect.x - rootRect.x) * sx),
238
- y = Math.round((probeRect.y - rootRect.y) * sy)
239
- const width = Math.round(probeRect.width * sx),
240
- height = Math.round(probeRect.height * sy)
241
- if (
242
- x < 0 ||
243
- y < 0 ||
244
- width <= 0 ||
245
- height <= 0 ||
246
- x + width > stream.width ||
247
- y + height > stream.height
248
- )
249
- throw new Error('cadence recording probe escapes its original frame')
250
- // only the measured probe crosses the decoder boundary. bounded buffering
251
- // refuses oversized traces instead of streaming full device frames.
252
- const decoded = spawnSync(
253
- 'ffmpeg',
254
- [
255
- '-v',
256
- 'error',
257
- '-threads',
258
- '2',
259
- '-filter_threads',
260
- '1',
261
- '-fflags',
262
- '+igndts',
263
- '-i',
264
- recording,
265
- '-vf',
266
- `crop=${width}:${height}:${x}:${y}`,
267
- '-fps_mode',
268
- 'passthrough',
269
- '-f',
270
- 'rawvideo',
271
- '-pix_fmt',
272
- 'rgba',
273
- 'pipe:1',
274
- ],
275
- { maxBuffer: 32 * 1024 * 1024, timeout: 30000 },
276
- )
277
- if (decoded.status !== 0)
278
- throw new Error(`cadence native probe decode refused: ${decoded.stderr}`)
279
- const frameBytes = width * height * 4
280
- if (decoded.stdout.length !== info.frames.length * frameBytes)
281
- throw new Error('cadence native frame/timestamp census mismatch')
282
- const observations = info.frames.map((frame, frameIndex) => ({
283
- frameIndex,
284
- atMs: Number(frame.best_effort_timestamp_time) * 1000,
285
- ...classifyDiscreteFrame({
286
- pixels: decoded.stdout.subarray(
287
- frameIndex * frameBytes,
288
- (frameIndex + 1) * frameBytes,
289
- ),
290
- frames: cadence.asset.frames,
291
- }),
292
- }))
293
- return {
294
- observations,
295
- mediaDurationMs: Number(info.format.duration) * 1000,
296
- probeBytes: decoded.stdout.length,
297
- peakProbeBytes: decoded.stdout.length + frameBytes,
298
- }
299
- }
300
-
301
- function writeDiscreteFrameReceipt(
302
- root,
303
- context,
304
- trace,
305
- recording = null,
306
- rootRect = null,
307
- lifecycle = null,
308
- ) {
309
- const relative = `${context.target}/${context.caseName}/${context.checkpoint}/cadence.json`
310
- const receipt = { version: 1, context, trace, recording, rootRect, lifecycle }
311
- fs.writeFileSync(proofBoundPath(root, relative), JSON.stringify(receipt) + '\n', {
312
- flag: 'wx',
313
- })
314
- // write authentic failed traces too. the caller and every receiver recompute
315
- // the decision; a producer never writes an accepted scalar as evidence.
316
- return {
317
- path: relative,
318
- sha256: proofByteHash(fs.readFileSync(proofBoundPath(root, relative))),
319
- }
320
- }
321
-
322
- function authenticateNativeCadenceCensus(root, sourceRoot, life, decoded) {
323
- const {
324
- authenticateNativeRefreshSamples,
325
- } = require('../../peach-conformance/e2e/utils/native-frame-receipt.cjs')
326
- authenticateNativeRefreshSamples(root, sourceRoot, life)
327
- const native = life.nativeFramebuffer
328
- if (
329
- !native ||
330
- native.exitCode !== 0 ||
331
- native.failure ||
332
- native.sourceSha256 !==
333
- proofByteHash(
334
- fs.readFileSync(
335
- path.join(sourceRoot, 'scripts/debug/native-ios-frame-consumer.m'),
336
- ),
337
- )
338
- )
339
- throw new Error('native cadence has no source-matched framebuffer consumer')
340
- const frames = boundText(
341
- root,
342
- native.receipt,
343
- native.receiptSha256,
344
- 'native cadence source receipt',
345
- )
346
- .trim()
347
- .split('\n')
348
- .map(JSON.parse)
349
- const media = boundText(
350
- root,
351
- native.mediaFrames,
352
- native.mediaFramesSha256,
353
- 'native cadence sampled surface census',
354
- )
355
- .trim()
356
- .split('\n')
357
- .map(JSON.parse)
358
- if (frames.length !== decoded.observations.length || media.length !== frames.length)
359
- throw new Error('native cadence acquisition and sampled surface census differ')
360
- const {
361
- decodeNativeFramebuffer,
362
- requireNativeRawFrame,
363
- } = require('../../peach-conformance/e2e/utils/native-frame-receipt.cjs')
364
- const rawRoot = path.dirname(proofBoundPath(root, native.receipt))
365
- const origin = frames[0].consumerArrival
366
- // a callback whose frame a newer one overwrote mid-read keeps no bytes; its
367
- // superseded receipt fills exactly the gap it leaves in the callback order
368
- const supersededLines = boundText(
369
- root,
370
- native.superseded,
371
- native.supersededSha256,
372
- 'native cadence superseded receipt',
373
- )
374
- .split('\n')
375
- .filter(Boolean)
376
- const superseded = new Set(
377
- supersededLines.map((line) => {
378
- const row = JSON.parse(line)
379
- const uint32 = (value) =>
380
- Number.isInteger(value) && value >= 0 && value <= 0xffffffff
381
- const ticks = (value) => typeof value === 'string' && /^\d+$/.test(value)
382
- const arrival = row.consumerArrival
383
- const window = row.readWindow
384
- if (
385
- !Number.isSafeInteger(row.callbackIndex) ||
386
- row.callbackIndex < 0 ||
387
- !uint32(row.surfaceId) ||
388
- row.surfaceId < 1 ||
389
- !uint32(row.seedBeforeRead) ||
390
- !uint32(row.seedAfterRead) ||
391
- row.seedBeforeRead === row.seedAfterRead ||
392
- !Number.isFinite(row.copyMs) ||
393
- row.copyMs < 0 ||
394
- arrival?.domain !== origin.domain ||
395
- arrival.timebaseNumer !== origin.timebaseNumer ||
396
- arrival.timebaseDenom !== origin.timebaseDenom ||
397
- arrival.bootSessionUUID !== origin.bootSessionUUID ||
398
- !ticks(arrival.machTicks) ||
399
- !ticks(window?.machStart) ||
400
- !ticks(window.machEnd) ||
401
- !ticks(window.surfaceAcquired) ||
402
- !ticks(window.surfaceLocked) ||
403
- !Number.isFinite(window.copyCpuMs) ||
404
- window.copyCpuMs < 0 ||
405
- // the writer stamps arrival, acquire, lock, copy start and copy end in order
406
- BigInt(window.surfaceAcquired) < BigInt(arrival.machTicks) ||
407
- BigInt(window.surfaceLocked) < BigInt(window.surfaceAcquired) ||
408
- BigInt(window.machStart) < BigInt(window.surfaceLocked) ||
409
- BigInt(window.machEnd) < BigInt(window.machStart)
410
- )
411
- throw new Error('native superseded receipt is not an overwritten read')
412
- return row.callbackIndex
413
- }),
414
- )
415
- if (superseded.size !== supersededLines.length)
416
- throw new Error('native superseded receipt repeats a callback')
417
- const reads = boundText(
418
- root,
419
- native.reads,
420
- native.readsSha256,
421
- 'native cadence observations',
422
- )
423
- .split('\n')
424
- .filter(Boolean)
425
- .map(JSON.parse)
426
- let expectedCallback = 0
427
- for (const read of reads) {
428
- while (superseded.delete(expectedCallback)) expectedCallback++
429
- if (read.callbackIndex !== expectedCallback++)
430
- throw new Error('native cadence observations have invalid callback order')
431
- }
432
- for (const [index, frame] of frames.entries()) {
433
- const clock = frame.consumerArrival
434
- if (
435
- media[index].sourceFrameIndex !== index ||
436
- !clock ||
437
- clock.domain !== 'host-mach-absolute-time' ||
438
- clock.domain !== origin.domain ||
439
- clock.timebaseNumer !== origin.timebaseNumer ||
440
- clock.timebaseDenom !== origin.timebaseDenom ||
441
- !Number.isSafeInteger(clock.timebaseNumer) ||
442
- clock.timebaseNumer <= 0 ||
443
- !Number.isSafeInteger(clock.timebaseDenom) ||
444
- clock.timebaseDenom <= 0
445
- )
446
- throw new Error('native cadence source census has invalid clock or order')
447
- const pts =
448
- ((BigInt(clock.machTicks) - BigInt(origin.machTicks)) *
449
- BigInt(clock.timebaseNumer)) /
450
- BigInt(clock.timebaseDenom)
451
- if (
452
- pts < 0n ||
453
- pts !== BigInt(media[index].ptsNanoseconds) ||
454
- Math.abs(Number(pts) / 1000000 - decoded.observations[index].atMs) > 0.001
455
- )
456
- throw new Error('native cadence presentation lost its acquired source timestamp')
457
- requireNativeRawFrame(
458
- frame,
459
- decodeNativeFramebuffer(
460
- frame,
461
- fs.readFileSync(proofBoundPath(rawRoot, frame.rawPath)),
462
- ),
463
- )
464
- }
465
- while (superseded.delete(expectedCallback)) expectedCallback++
466
- if (superseded.size)
467
- throw new Error('native superseded receipts fall outside the callback order')
468
- }
469
-
470
- function readDiscreteFrameReceipt(root, sourceRoot, reference, expected) {
471
- if (expected.calibration !== true) assertNormalProofAttempt(root)
472
- if (!reference || !/^[a-f0-9]{64}$/.test(reference.sha256))
473
- throw new Error('missing discrete cadence receipt')
474
- const bytes = fs.readFileSync(proofBoundPath(root, reference.path))
475
- if (proofByteHash(bytes) !== reference.sha256)
476
- throw new Error('cadence receipt digest mismatch')
477
- const receipt = JSON.parse(bytes)
478
- if (receipt.version !== 1 || !receipt.context || !receipt.trace)
479
- throw new Error('cadence receipt is incomplete')
480
- const context = receipt.context
481
- const cadence = authenticateDiscreteFrameAsset(
482
- sourceRoot,
483
- expected.cadence,
484
- expected.calibration === true,
485
- )
486
- const source = JSON.parse(
487
- fs.readFileSync(path.join(root, 'source-fingerprint.json'), 'utf8'),
488
- )
489
- const attempt = JSON.parse(
490
- fs.readFileSync(path.join(root, 'capture-context.json'), 'utf8'),
491
- )
492
- if (expected.calibration === true) {
493
- if (
494
- attempt.discreteFrameCalibration !== true ||
495
- context.discreteFrameCalibration !== true ||
496
- context.fixtureSha256 !==
497
- proofByteHash(
498
- fs.readFileSync(proofBoundPath(sourceRoot, cadence.asset.fixturePath)),
499
- )
500
- )
501
- throw new Error('calibration receipt does not bind the current fixture')
502
- } else if (attempt.discreteFrameCalibration || context.discreteFrameCalibration) {
503
- throw new Error('calibration evidence cannot satisfy a normal proof gate')
504
- }
505
- const begin = JSON.parse(
506
- fs.readFileSync(
507
- proofBoundPath(
508
- root,
509
- `${expected.target}/${expected.caseName}/${expected.checkpoint}/cadence-begin.json`,
510
- ),
511
- 'utf8',
512
- ),
513
- )
514
- if (
515
- JSON.stringify(context) !== JSON.stringify(begin) ||
516
- context.attemptNonce !== attempt.attemptNonce ||
517
- context.sourceFingerprint !== source.sourceFingerprint ||
518
- context.proofSourceFingerprint !== source.proofSourceFingerprint ||
519
- attempt.sourceFingerprint !== source.sourceFingerprint ||
520
- attempt.proofSourceFingerprint !== source.proofSourceFingerprint ||
521
- context.contractSha256 !== proofByteHash(JSON.stringify(cadence)) ||
522
- context.encodedAssetSha256 !== cadence.asset.encodedSha256
523
- )
524
- throw new Error('cadence capture is stale or replayed')
525
- for (const field of ['target', 'caseName', 'checkpoint', 'appearance'])
526
- if (context[field] !== expected[field])
527
- throw new Error(`cadence capture has wrong ${field}`)
528
- if (
529
- JSON.stringify(receipt.trace.cadence) !== JSON.stringify(cadence) ||
530
- receipt.trace.clock !== context.clock ||
531
- context.clock !==
532
- (context.target.startsWith('ios') ? 'native-presentation' : 'peach-virtual') ||
533
- !context.captureNonce ||
534
- !context.device ||
535
- !context.runtime
536
- )
537
- throw new Error('cadence trace has wrong declaration or clock')
538
- for (const field of [
539
- 'attemptNonce',
540
- 'captureNonce',
541
- 'sourceFingerprint',
542
- 'proofSourceFingerprint',
543
- ])
544
- if (receipt.trace.binding?.[field] !== context[field])
545
- throw new Error('cadence observations are stale or replayed')
546
- if (
547
- ![
548
- context.createdAtMs,
549
- receipt.trace.triggerStartedAtMs,
550
- receipt.trace.triggerCompletedAtMs,
551
- receipt.trace.completedAtMs,
552
- ].every(Number.isFinite) ||
553
- receipt.trace.triggerStartedAtMs < context.createdAtMs ||
554
- receipt.trace.triggerCompletedAtMs < receipt.trace.triggerStartedAtMs ||
555
- receipt.trace.completedAtMs < receipt.trace.triggerCompletedAtMs
556
- )
557
- throw new Error('cadence observation lifetime predates its issued capture')
558
- if (context.clock === 'native-presentation') {
559
- if (JSON.stringify(receipt.rootRect) !== JSON.stringify(context.rootRect))
560
- throw new Error('native cadence root geometry differs from its issued capture')
561
- if (!receipt.recording || !receipt.lifecycle || !receipt.rootRect)
562
- throw new Error('native cadence has no original recording/lifetime')
563
- const file = proofBoundPath(root, receipt.recording.path)
564
- if (proofByteHash(fs.readFileSync(file)) !== receipt.recording.sha256)
565
- throw new Error('native cadence original recording digest mismatch')
566
- const lifeBytes = fs.readFileSync(proofBoundPath(root, receipt.lifecycle.path))
567
- if (proofByteHash(lifeBytes) !== receipt.lifecycle.sha256)
568
- throw new Error('native cadence original lifetime digest mismatch')
569
- const life = JSON.parse(lifeBytes)
570
- if (JSON.stringify(life.captureContext) !== JSON.stringify(context))
571
- throw new Error('native cadence lifetime belongs to a stale or replayed capture')
572
- if (
573
- ![
574
- life.recordingStartedAtMonotonicMs,
575
- life.triggerStartAtMonotonicMs,
576
- life.triggerCompletedAtMonotonicMs,
577
- life.stopRequestedAtMonotonicMs,
578
- life.recorderClosedAtMonotonicMs,
579
- ].every(Number.isFinite) ||
580
- life.triggerStartAtMonotonicMs < life.recordingStartedAtMonotonicMs ||
581
- life.triggerCompletedAtMonotonicMs < life.triggerStartAtMonotonicMs ||
582
- life.stopRequestedAtMonotonicMs < life.triggerCompletedAtMonotonicMs ||
583
- life.recorderClosedAtMonotonicMs < life.stopRequestedAtMonotonicMs ||
584
- receipt.trace.coverageEndMs >
585
- life.stopRequestedAtMonotonicMs - life.recordingStartedAtMonotonicMs
586
- )
587
- throw new Error('native cadence is outside its original recorder lifetime')
588
- const decoded = decodeDiscreteNativeFrames(
589
- file,
590
- cadence,
591
- context.probeRect,
592
- receipt.rootRect,
593
- )
594
- authenticateNativeCadenceCensus(root, sourceRoot, life, decoded)
595
- if (
596
- JSON.stringify(decoded.observations) !==
597
- JSON.stringify(receipt.trace.observations) ||
598
- decoded.mediaDurationMs !== receipt.trace.mediaDurationMs ||
599
- (cadence.mode === 'frozen' &&
600
- (receipt.trace.coverageEndMs !== decoded.mediaDurationMs ||
601
- receipt.trace.triggerMs !==
602
- life.triggerCompletedAtMonotonicMs - life.recordingStartedAtMonotonicMs))
603
- )
604
- throw new Error('native cadence observations disagree with original pixels')
605
- }
606
- return { receipt, decision: evaluateDiscreteFrameTrace(receipt.trace) }
607
- }
608
-
609
- module.exports.assertNormalProofAttempt = assertNormalProofAttempt
610
- module.exports.proofByteHash = proofByteHash
611
- module.exports.authenticateDiscreteFrameAsset = authenticateDiscreteFrameAsset
612
- module.exports.mintProofAttemptContext = mintProofAttemptContext
613
- module.exports.beginDiscreteFrameCapture = beginDiscreteFrameCapture
614
- module.exports.decodeDiscreteNativeFrames = decodeDiscreteNativeFrames
615
- module.exports.writeDiscreteFrameReceipt = writeDiscreteFrameReceipt
616
- module.exports.readDiscreteFrameReceipt = readDiscreteFrameReceipt
617
-
618
- function validateDiscreteFrameCaseEvidence(
619
- root,
620
- sourceRoot,
621
- cases,
622
- targets,
623
- appearance,
624
- calibration = false,
625
- ) {
626
- if (!calibration) assertNormalProofAttempt(root)
627
- const results = []
628
- for (const entry of cases) {
629
- const declarations = (entry.checkpoints || []).filter(
630
- (checkpoint) => checkpoint.motionCadence,
631
- )
632
- const holdsByAsset = new Map()
633
- for (const checkpoint of declarations) {
634
- const cadence = checkpoint.motionCadence
635
- for (const target of targets) {
636
- const relative = `${target}/${entry.caseName}/${checkpoint.id}/cadence.json`
637
- const reference = {
638
- path: relative,
639
- sha256: proofByteHash(fs.readFileSync(proofBoundPath(root, relative))),
640
- }
641
- const eventPath =
642
- cadence.mode === 'playing'
643
- ? `${target}/${entry.caseName}/${checkpoint.id}/stages.json`
644
- : `${target}/${entry.caseName}/${checkpoint.id}.json`
645
- const event = JSON.parse(fs.readFileSync(proofBoundPath(root, eventPath), 'utf8'))
646
- const metadata = event.metadata
647
- if (
648
- cadence.mode === 'playing' &&
649
- JSON.stringify(event.cadenceEvidence) !== JSON.stringify(reference)
650
- )
651
- throw new Error('cadence event references a missing or changed receipt')
652
- const image = metadata?.elementRegions?.find(
653
- (region) => region.name === cadence.probe.elementName,
654
- )?.rect
655
- const output = metadata?.elementRegions?.find(
656
- (region) => region.name === metadata.outputRegionName,
657
- )?.rect
658
- if (
659
- !image ||
660
- !output ||
661
- event.caseName !== entry.caseName ||
662
- event.checkpoint !== checkpoint.id ||
663
- event.target !== target
664
- )
665
- throw new Error('cadence capture has no authentic region/event identity')
666
- const probeRect = {
667
- x: image.x + cadence.probe.inset,
668
- y: image.y + cadence.probe.inset,
669
- width: image.width - 2 * cadence.probe.inset,
670
- height: image.height - 2 * cadence.probe.inset,
671
- }
672
- const verified = readDiscreteFrameReceipt(root, sourceRoot, reference, {
673
- cadence,
674
- calibration,
675
- target,
676
- caseName: entry.caseName,
677
- checkpoint: checkpoint.id,
678
- appearance,
679
- })
680
- if (
681
- JSON.stringify(probeRect) !==
682
- JSON.stringify(verified.receipt.context.probeRect) ||
683
- JSON.stringify(output) !==
684
- JSON.stringify(verified.receipt.context.outputRect) ||
685
- JSON.stringify(metadata.elementRegionRoot) !==
686
- JSON.stringify(verified.receipt.context.rootRect) ||
687
- (event.runtime?.udid || event.runtime?.deviceModel) !==
688
- verified.receipt.context.device ||
689
- JSON.stringify(event.runtime) !== verified.receipt.context.runtime
690
- )
691
- throw new Error(
692
- 'cadence capture geometry/runtime does not match its actual event',
693
- )
694
- if (cadence.mode === 'frozen') {
695
- for (const id of cadence.captures) {
696
- const sibling = entry.checkpoints.find((candidate) => candidate.id === id)
697
- if (
698
- !sibling ||
699
- sibling.kind === 'motion' ||
700
- sibling.evidenceKind !== 'visual'
701
- )
702
- throw new Error('frozen cadence capture has no authentic settled sibling')
703
- const captured = JSON.parse(
704
- fs.readFileSync(
705
- proofBoundPath(root, `${target}/${entry.caseName}/${id}.json`),
706
- 'utf8',
707
- ),
708
- )
709
- if (
710
- captured.caseName !== entry.caseName ||
711
- captured.checkpoint !== id ||
712
- captured.target !== target ||
713
- JSON.stringify(captured.runtime) !== verified.receipt.context.runtime ||
714
- JSON.stringify(captured.metadata?.elementRegionRoot) !==
715
- JSON.stringify(verified.receipt.context.rootRect) ||
716
- proofByteHash(fs.readFileSync(proofBoundPath(root, captured.path))) !==
717
- captured.pngSha256
718
- )
719
- throw new Error('frozen cadence has missing or changed endpoint pixels')
720
- const { PNG } = require('pngjs')
721
- const png = PNG.sync.read(
722
- fs.readFileSync(proofBoundPath(root, captured.path)),
723
- )
724
- const rootRect = captured.metadata?.elementRegionRoot
725
- if (!rootRect || rootRect.width <= 0 || rootRect.height <= 0)
726
- throw new Error('frozen endpoint has no measured root')
727
- const sx = png.width / rootRect.width,
728
- sy = png.height / rootRect.height
729
- const left = Math.round((probeRect.x - rootRect.x) * sx),
730
- top = Math.round((probeRect.y - rootRect.y) * sy),
731
- width = Math.round(probeRect.width * sx),
732
- height = Math.round(probeRect.height * sy)
733
- if (
734
- left < 0 ||
735
- top < 0 ||
736
- width <= 0 ||
737
- height <= 0 ||
738
- left + width > png.width ||
739
- top + height > png.height
740
- )
741
- throw new Error('frozen endpoint probe escapes original pixels')
742
- const pixels = Buffer.alloc(width * height * 4)
743
- for (let y = 0; y < height; y++)
744
- png.data.copy(
745
- pixels,
746
- y * width * 4,
747
- ((top + y) * png.width + left) * 4,
748
- ((top + y) * png.width + left + width) * 4,
749
- )
750
- if (
751
- classifyDiscreteFrame({ pixels, frames: cadence.asset.frames }).phase !==
752
- verified.decision.phase
753
- )
754
- throw new Error('frozen endpoint phase differs from complete observation')
755
- }
756
- } else {
757
- const key = `${target}:${cadence.asset.encodedSha256}`
758
- const observed = holdsByAsset.get(key) || new Set()
759
- for (const hold of verified.decision.holds) observed.add(hold.phase)
760
- holdsByAsset.set(key, observed)
761
- }
762
- results.push({
763
- caseName: entry.caseName,
764
- checkpoint: checkpoint.id,
765
- target,
766
- reference,
767
- context: verified.receipt.context,
768
- decision: verified.decision,
769
- })
770
- }
771
- }
772
- for (const checkpoint of declarations.filter(
773
- (checkpoint) => checkpoint.motionCadence.mode === 'playing',
774
- )) {
775
- for (const target of targets) {
776
- const cadence = checkpoint.motionCadence
777
- const holds = holdsByAsset.get(`${target}:${cadence.asset.encodedSha256}`)
778
- if (!holds || cadence.asset.frames.some((_, phase) => !holds.has(phase)))
779
- throw new Error(
780
- `discrete cadence is missing case-wide phase holds for ${entry.caseName}/${target}`,
781
- )
782
- }
783
- }
784
- }
785
- return results
786
- }
787
- module.exports.validateDiscreteFrameCaseEvidence = validateDiscreteFrameCaseEvidence
788
-
789
- function discreteFrameEvidenceFiles(root, evidence) {
790
- const paths = new Set(['source-fingerprint.json', 'capture-context.json'])
791
- for (const item of evidence) {
792
- const prefix = `${item.target}/${item.caseName}/${item.checkpoint}`
793
- paths.add(item.reference.path)
794
- paths.add(`${prefix}/cadence-begin.json`)
795
- const receipt = JSON.parse(
796
- fs.readFileSync(proofBoundPath(root, item.reference.path), 'utf8'),
797
- )
798
- if (receipt.recording) paths.add(receipt.recording.path)
799
- if (receipt.lifecycle) {
800
- paths.add(receipt.lifecycle.path)
801
- const life = JSON.parse(
802
- fs.readFileSync(proofBoundPath(root, receipt.lifecycle.path), 'utf8'),
803
- )
804
- // the app's ui frame clock and delivered input are replayed from their
805
- // own receipts, so their bytes travel bound to the hashes the lifecycle
806
- // recorded
807
- for (const [label, auxiliary] of [
808
- ['ui frame clock', life.uiFrameClock],
809
- ['delivered input', life.deliveredUIKitInput],
810
- ]) {
811
- if (!auxiliary) continue
812
- const bytes = fs.readFileSync(proofBoundPath(root, auxiliary.sourceReceipt))
813
- if (proofByteHash(bytes) !== auxiliary.sourceReceiptSha256)
814
- throw new Error(`native ${label} receipt does not match its recorded hash`)
815
- paths.add(auxiliary.sourceReceipt)
816
- }
817
- const native = life.nativeFramebuffer
818
- if (native) {
819
- paths.add(native.receipt)
820
- paths.add(native.superseded)
821
- paths.add(native.mediaFrames)
822
- paths.add(native.gradingMarkers)
823
- paths.add(native.gradingPlan)
824
- paths.add(native.windowResolution)
825
- paths.add(native.reads)
826
- for (const receipt of native.finalReads) {
827
- const text = boundText(
828
- root,
829
- receipt.path,
830
- receipt.sha256,
831
- 'native sampled end state',
832
- )
833
- paths.add(receipt.path)
834
- for (const row of text.split('\n').filter(Boolean).map(JSON.parse)) {
835
- const file = proofBoundPath(
836
- path.dirname(proofBoundPath(root, receipt.path)),
837
- row.rawPath,
838
- )
839
- paths.add(path.relative(root, file).split(path.sep).join('/'))
840
- }
841
- }
842
- const rows = fs
843
- .readFileSync(proofBoundPath(root, native.receipt), 'utf8')
844
- .trim()
845
- .split('\n')
846
- .map(JSON.parse)
847
- for (const row of rows) {
848
- const file = proofBoundPath(
849
- path.dirname(proofBoundPath(root, native.receipt)),
850
- row.rawPath,
851
- )
852
- paths.add(path.relative(root, file).split(path.sep).join('/'))
853
- }
854
- }
855
- }
856
- if (receipt.trace.cadence.mode === 'playing') paths.add(`${prefix}/stages.json`)
857
- else
858
- for (const id of receipt.trace.cadence.captures) {
859
- const eventPath = `${item.target}/${item.caseName}/${id}.json`
860
- paths.add(eventPath)
861
- paths.add(
862
- JSON.parse(fs.readFileSync(proofBoundPath(root, eventPath), 'utf8')).path,
863
- )
864
- }
865
- }
866
- return [...paths].sort().map((relative) => ({
867
- path: relative,
868
- sha256: proofByteHash(fs.readFileSync(proofBoundPath(root, relative))),
869
- }))
870
- }
871
- module.exports.discreteFrameEvidenceFiles = discreteFrameEvidenceFiles
872
-
873
- function parseDiscreteProofEvidence(value) {
874
- if (
875
- !value ||
876
- typeof value !== 'object' ||
877
- !value.context ||
878
- !value.reference ||
879
- !value.decision
880
- )
881
- throw new Error('discrete proof summary evidence is incomplete')
882
- for (const field of ['caseName', 'checkpoint', 'target'])
883
- if (typeof value[field] !== 'string' || value[field] !== value.context[field])
884
- throw new Error('discrete proof summary has wrong capture identity')
885
- for (const field of [
886
- 'sourceFingerprint',
887
- 'proofSourceFingerprint',
888
- 'contractSha256',
889
- 'encodedAssetSha256',
890
- ])
891
- if (!/^[a-f0-9]{64}$/.test(value.context[field]))
892
- throw new Error('discrete proof summary has invalid digest')
893
- if (
894
- !/^[a-f0-9]{64}$/.test(value.reference.sha256) ||
895
- typeof value.reference.path !== 'string' ||
896
- path.isAbsolute(value.reference.path) ||
897
- value.reference.path.split('/').includes('..')
898
- )
899
- throw new Error('discrete proof summary has invalid receipt')
900
- if (
901
- !['playing', 'frozen'].includes(value.decision.mode) ||
902
- !Array.isArray(value.decision.holds)
903
- )
904
- throw new Error('discrete proof summary has no phase decision')
905
- for (const hold of value.decision.holds)
906
- if (
907
- !Number.isInteger(hold.phase) ||
908
- !Number.isFinite(hold.expectedMs) ||
909
- !Number.isFinite(hold.observedMs)
910
- )
911
- throw new Error('discrete proof summary has invalid hold')
912
- return value
913
- }
914
- module.exports.parseDiscreteProofEvidence = parseDiscreteProofEvidence