@fantastic.dev/better-stripe 0.90.0 → 0.91.0

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 (216) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +41 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -0
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +187 -0
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -0
  7. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts +2 -23
  8. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js +1 -112
  10. package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts +8 -3
  12. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js +1 -0
  14. package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/acquisition/test-fixtures/sourcePort.d.mts +1 -1
  16. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +8 -0
  17. package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -0
  18. package/dist/client/billing/renewalAttach/internal/configure/actor.js +454 -0
  19. package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -0
  20. package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts +12 -0
  21. package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts.map +1 -0
  22. package/dist/client/billing/renewalAttach/internal/configure/capture.js +99 -0
  23. package/dist/client/billing/renewalAttach/internal/configure/capture.js.map +1 -0
  24. package/dist/client/billing/renewalAttach/internal/configure/output.d.ts +16 -0
  25. package/dist/client/billing/renewalAttach/internal/configure/output.d.ts.map +1 -0
  26. package/dist/client/billing/renewalAttach/internal/configure/output.js +274 -0
  27. package/dist/client/billing/renewalAttach/internal/configure/output.js.map +1 -0
  28. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts +3 -0
  29. package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts.map +1 -0
  30. package/dist/client/billing/renewalAttach/internal/configure/replay.js +9 -0
  31. package/dist/client/billing/renewalAttach/internal/configure/replay.js.map +1 -0
  32. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts +39 -0
  33. package/dist/client/billing/renewalAttach/internal/configure/request.d.ts.map +1 -0
  34. package/dist/client/billing/renewalAttach/internal/configure/request.js +245 -0
  35. package/dist/client/billing/renewalAttach/internal/configure/request.js.map +1 -0
  36. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +88 -0
  37. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -0
  38. package/dist/client/billing/renewalAttach/internal/configure/transport.js +289 -0
  39. package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -0
  40. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts +16 -0
  41. package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -0
  42. package/dist/client/billing/renewalAttach/internal/observation/actor.js +362 -0
  43. package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -0
  44. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts +9 -0
  45. package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -0
  46. package/dist/client/billing/renewalAttach/internal/observation/capture.js +215 -0
  47. package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -0
  48. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +7 -0
  49. package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -0
  50. package/dist/client/billing/renewalAttach/internal/observation/profile.js +190 -0
  51. package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -0
  52. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts +5 -0
  53. package/dist/client/billing/renewalAttach/internal/observation/record.d.ts.map +1 -0
  54. package/dist/client/billing/renewalAttach/internal/observation/record.js +317 -0
  55. package/dist/client/billing/renewalAttach/internal/observation/record.js.map +1 -0
  56. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +79 -0
  57. package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -0
  58. package/dist/client/billing/renewalAttach/internal/observation/types.js +27 -0
  59. package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -0
  60. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +18 -0
  61. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -0
  62. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +229 -0
  63. package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -0
  64. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +163 -0
  65. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -0
  66. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +443 -0
  67. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -0
  68. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +8 -0
  69. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -0
  70. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +467 -0
  71. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -0
  72. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +6 -0
  73. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -0
  74. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +59 -0
  75. package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -0
  76. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts +10 -0
  77. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts.map +1 -0
  78. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js +48 -0
  79. package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js.map +1 -0
  80. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +20 -0
  81. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -0
  82. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +44 -0
  83. package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -0
  84. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts +42 -0
  85. package/dist/client/billing/renewalAttach/internal/operations/types.d.ts.map +1 -0
  86. package/dist/client/billing/renewalAttach/internal/operations/types.js +158 -0
  87. package/dist/client/billing/renewalAttach/internal/operations/types.js.map +1 -0
  88. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts +5 -0
  89. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts.map +1 -0
  90. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js +214 -0
  91. package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js.map +1 -0
  92. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts +33 -0
  93. package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts.map +1 -0
  94. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js +208 -0
  95. package/dist/client/billing/renewalAttach/internal/preflight/grammar.js.map +1 -0
  96. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +4 -0
  97. package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -0
  98. package/dist/client/billing/renewalAttach/internal/preflight/output.js +25 -0
  99. package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -0
  100. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +16 -0
  101. package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -0
  102. package/dist/client/billing/renewalAttach/internal/preflight/record.js +93 -0
  103. package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -0
  104. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +7 -0
  105. package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -0
  106. package/dist/client/billing/renewalAttach/internal/preflight/relations.js +153 -0
  107. package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -0
  108. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts +22 -0
  109. package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts.map +1 -0
  110. package/dist/client/billing/renewalAttach/internal/recovery/material.js +221 -0
  111. package/dist/client/billing/renewalAttach/internal/recovery/material.js.map +1 -0
  112. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +8 -0
  113. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -0
  114. package/dist/client/billing/renewalAttach/internal/recovery/output.js +101 -0
  115. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -0
  116. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +12 -0
  117. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -0
  118. package/dist/client/billing/renewalAttach/internal/recovery/record.js +186 -0
  119. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -0
  120. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +5 -0
  121. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -0
  122. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +498 -0
  123. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -0
  124. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +21 -0
  125. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -0
  126. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +119 -0
  127. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -0
  128. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  129. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  130. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  131. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  132. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  133. package/dist/component/payoutRelease/queries.d.ts +2 -2
  134. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  135. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  136. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  137. package/docs/renewal-context-reads.md +26 -8
  138. package/docs/renewal-material-observation.md +37 -0
  139. package/docs/renewal-phase-assembly.md +68 -0
  140. package/docs/renewal-raw-acquisition.md +19 -5
  141. package/package.json +1 -1
  142. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +304 -0
  143. package/src/client/billing/renewalAttach/internal/acquisition/rawAcquisition.ts +2 -160
  144. package/src/client/billing/renewalAttach/internal/acquisition/rawWireSource.ts +15 -3
  145. package/src/client/billing/renewalAttach/internal/configure/actor.ts +575 -0
  146. package/src/client/billing/renewalAttach/internal/configure/capture.ts +117 -0
  147. package/src/client/billing/renewalAttach/internal/configure/dispatch.integration.test.ts +32 -0
  148. package/src/client/billing/renewalAttach/internal/configure/limits.test.ts +510 -0
  149. package/src/client/billing/renewalAttach/internal/configure/order.integration.test.ts +207 -0
  150. package/src/client/billing/renewalAttach/internal/configure/output.ts +372 -0
  151. package/src/client/billing/renewalAttach/internal/configure/ownership.integration.test.ts +148 -0
  152. package/src/client/billing/renewalAttach/internal/configure/replay.integration.test.ts +173 -0
  153. package/src/client/billing/renewalAttach/internal/configure/replay.ts +13 -0
  154. package/src/client/billing/renewalAttach/internal/configure/request.ts +312 -0
  155. package/src/client/billing/renewalAttach/internal/configure/transport.integration.test.ts +507 -0
  156. package/src/client/billing/renewalAttach/internal/configure/transport.ts +348 -0
  157. package/src/client/billing/renewalAttach/internal/observation/actor.ts +444 -0
  158. package/src/client/billing/renewalAttach/internal/observation/capture.ts +250 -0
  159. package/src/client/billing/renewalAttach/internal/observation/observation.integration.test.ts +220 -0
  160. package/src/client/billing/renewalAttach/internal/observation/observationRetirement.integration.test.ts +60 -0
  161. package/src/client/billing/renewalAttach/internal/observation/profile.ts +264 -0
  162. package/src/client/billing/renewalAttach/internal/observation/record.ts +408 -0
  163. package/src/client/billing/renewalAttach/internal/observation/types.ts +102 -0
  164. package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +285 -0
  165. package/src/client/billing/renewalAttach/internal/operations/defaultBindings.test.ts +69 -0
  166. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +574 -0
  167. package/src/client/billing/renewalAttach/internal/operations/initialAttach.integration.test.ts +34 -0
  168. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +535 -0
  169. package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +63 -0
  170. package/src/client/billing/renewalAttach/internal/operations/providerFailure.integration.test.ts +61 -0
  171. package/src/client/billing/renewalAttach/internal/operations/providerFailure.ts +66 -0
  172. package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +50 -0
  173. package/src/client/billing/renewalAttach/internal/operations/transport.integration.test.ts +116 -0
  174. package/src/client/billing/renewalAttach/internal/operations/types.ts +223 -0
  175. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.integration.test.ts +285 -0
  176. package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.ts +258 -0
  177. package/src/client/billing/renewalAttach/internal/preflight/configureReads.integration.test.ts +139 -0
  178. package/src/client/billing/renewalAttach/internal/preflight/grammar.ts +257 -0
  179. package/src/client/billing/renewalAttach/internal/preflight/output.ts +42 -0
  180. package/src/client/billing/renewalAttach/internal/preflight/owner.integration.test.ts +82 -0
  181. package/src/client/billing/renewalAttach/internal/preflight/preflight.integration.test.ts +354 -0
  182. package/src/client/billing/renewalAttach/internal/preflight/record.ts +127 -0
  183. package/src/client/billing/renewalAttach/internal/preflight/relations.ts +209 -0
  184. package/src/client/billing/renewalAttach/internal/recovery/material.ts +311 -0
  185. package/src/client/billing/renewalAttach/internal/recovery/output.ts +136 -0
  186. package/src/client/billing/renewalAttach/internal/recovery/record.ts +230 -0
  187. package/src/client/billing/renewalAttach/internal/recovery/recovery.integration.test.ts +463 -0
  188. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +599 -0
  189. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +175 -0
  190. package/src/client/billing/renewalAttach/internal/test-fixtures/attachEntries.ts +217 -0
  191. package/src/client/billing/renewalAttach/internal/test-fixtures/attachObservations.ts +226 -0
  192. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenario.ts +556 -0
  193. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioAssertions.ts +180 -0
  194. package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioBarriers.ts +144 -0
  195. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightAssertions.ts +122 -0
  196. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightBarriers.ts +330 -0
  197. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightControls.ts +139 -0
  198. package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightOperation.ts +513 -0
  199. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadNativeBaseline.ts +344 -0
  200. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadOperation.ts +278 -0
  201. package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadPort.ts +17 -0
  202. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +533 -0
  203. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteBarriers.ts +125 -0
  204. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +314 -0
  205. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +463 -0
  206. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteObservations.ts +515 -0
  207. package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +600 -0
  208. package/src/client/billing/renewalAttach/internal/test-fixtures/observationAssertions.ts +211 -0
  209. package/src/client/billing/renewalAttach/internal/test-fixtures/observationDeclarations.ts +192 -0
  210. package/src/client/billing/renewalAttach/internal/test-fixtures/observationHTTP.ts +197 -0
  211. package/src/client/billing/renewalAttach/internal/test-fixtures/observationObservations.ts +269 -0
  212. package/src/client/billing/renewalAttach/internal/test-fixtures/observationOperation.ts +262 -0
  213. package/src/client/billing/renewalAttach/internal/test-fixtures/observationProbe.ts +319 -0
  214. package/src/client/billing/renewalAttach/internal/test-fixtures/ownedOperations.ts +94 -0
  215. package/src/client/billing/renewalAttach/internal/test-fixtures/sourceOperationPort.ts +16 -0
  216. package/src/client/billing/renewalAttach/internal/test-fixtures/stockHttp.ts +21 -0
@@ -0,0 +1,463 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { vi } from "vitest";
3
+ import { createWriteHTTPAndSink } from "./configureWriteAssertions.js";
4
+ import {
5
+ declareConfigureWriteCase,
6
+ declareConfigureWriteFamily,
7
+ } from "./configureWriteDeclarations.js";
8
+ import { writeObservationState } from "./configureWriteObservations.js";
9
+ import type { configureWriteBarriers } from "./configureWriteBarriers.js";
10
+ import type { ProjectedRenewalConfigurationV2 } from "../../../renewalV2/index.js";
11
+ import assert from "node:assert/strict";
12
+ import type { WriteCase } from "./configureWriteDeclarations.js";
13
+ import type { WriteObservations } from "./configureWriteObservations.js";
14
+
15
+ /** TEST declaration of expected later replay facts, not a registry granting authority. */
16
+ export function declareExpectedReplay(originalRequest: unknown) {
17
+ return Object.freeze({
18
+ originalRequest,
19
+ persistentCustody: false,
20
+ requiresActualUnknownPOST: true,
21
+ requiresOriginalOwner: true,
22
+ permitsJSONRehydration: false,
23
+ permitsAutomaticRetry: false,
24
+ });
25
+ }
26
+
27
+ /** TEST-only closed Source construction; no production module imports this fixture. */
28
+ export function declareWriteSources(args: {
29
+ mode: WriteCase;
30
+ owner: object;
31
+ origin: object;
32
+ entry: object;
33
+ coverage: object;
34
+ record: object;
35
+ configuration: object;
36
+ preflightOutput: unknown;
37
+ acknowledgement: unknown;
38
+ plan: readonly unknown[];
39
+ delegate: object;
40
+ sink: object;
41
+ request: unknown;
42
+ state: WriteObservations;
43
+ }) {
44
+ const {
45
+ mode,
46
+ owner: OWNER,
47
+ origin,
48
+ entry,
49
+ coverage,
50
+ record: expectedRecord,
51
+ configuration: goodConfiguration,
52
+ preflightOutput,
53
+ acknowledgement,
54
+ plan: configurePlan,
55
+ delegate: writeDelegate,
56
+ sink: writeSink,
57
+ request: projected,
58
+ state: writeState,
59
+ } = args;
60
+ let reserved = false;
61
+ const writerRecord =
62
+ mode === "original-failure"
63
+ ? {
64
+ ...expectedRecord,
65
+ configuration: {
66
+ ...goodConfiguration,
67
+ apiVersion: "unsupported-configure-write-api",
68
+ },
69
+ }
70
+ : mode === "structural-failure"
71
+ ? {
72
+ ...expectedRecord,
73
+ configuration: { ...goodConfiguration, unexpected: true },
74
+ }
75
+ : mode === "forged-preflight"
76
+ ? preflightOutput
77
+ : expectedRecord;
78
+ const writerFields = {
79
+ owner: mode === "foreign-owner" ? Object.freeze({}) : OWNER,
80
+ originAssociation: mode === "foreign-origin" ? Object.freeze({}) : origin,
81
+ originalEntry: mode === "foreign-entry" ? Object.freeze({}) : entry,
82
+ configureEntry:
83
+ mode === "foreign-class" ? Object.freeze({ ...coverage }) : coverage,
84
+ originalRecord: writerRecord,
85
+ actualAttachAcknowledgement:
86
+ mode === "cloned-ack"
87
+ ? structuredClone(acknowledgement)
88
+ : acknowledgement,
89
+ readPlan:
90
+ mode === "foreign-plan"
91
+ ? Object.freeze([...configurePlan])
92
+ : configurePlan,
93
+ delegate: writeDelegate,
94
+ sink: writeSink,
95
+ reserve() {
96
+ assert.equal(reserved, false);
97
+ reserved = true;
98
+ writeState.reserves++;
99
+ return true;
100
+ },
101
+ };
102
+ const writerOperation = Object.freeze(writerFields);
103
+ const writerFrame = Object.freeze({
104
+ owner: OWNER,
105
+ operation:
106
+ mode === "foreign-operation" ? Object.freeze({}) : writerOperation,
107
+ request: projected,
108
+ readPlan: configurePlan,
109
+ delegate:
110
+ mode === "foreign-delegate"
111
+ ? Object.freeze({
112
+ rawRequest() {
113
+ throw Error("FOREIGN_WRITE_DELEGATE_CALLED");
114
+ },
115
+ })
116
+ : writeDelegate,
117
+ });
118
+ return { operation: writerOperation, frame: writerFrame };
119
+ }
120
+
121
+ /** Immutable TEST-only replay operation; the actor must find actual private history itself. */
122
+ export function declareReplaySources(args: {
123
+ owner: object;
124
+ origin: object;
125
+ entry: object;
126
+ coverage: object;
127
+ previous: object;
128
+ plan: readonly unknown[];
129
+ delegate: object;
130
+ sink: object;
131
+ request: unknown;
132
+ state: WriteObservations;
133
+ }) {
134
+ let reserved = false;
135
+ const operation = Object.freeze({
136
+ owner: args.owner,
137
+ originAssociation: args.origin,
138
+ originalEntry: args.entry,
139
+ configureEntry: args.coverage,
140
+ previousOperation: args.previous,
141
+ readPlan: args.plan,
142
+ delegate: args.delegate,
143
+ sink: args.sink,
144
+ reserve() {
145
+ assert.equal(reserved, false);
146
+ reserved = true;
147
+ args.state.reserves++;
148
+ return true;
149
+ },
150
+ });
151
+ return Object.freeze({
152
+ operation,
153
+ frame: Object.freeze({
154
+ owner: args.owner,
155
+ operation,
156
+ request: args.request,
157
+ readPlan: args.plan,
158
+ delegate: args.delegate,
159
+ }),
160
+ });
161
+ }
162
+
163
+ /** Finite closed TEST producer. The asynchronous binding never escapes to the SUT or caller. */
164
+ export async function configureWriteTestFamily(args: {
165
+ declared: ReturnType<typeof declareConfigureWriteCase>;
166
+ declarations: ReturnType<typeof declareConfigureWriteFamily>;
167
+ owner: typeof import("../originalOwner.js").OWNER;
168
+ origin: object;
169
+ entry: object;
170
+ coverage: object;
171
+ record: object;
172
+ configuration: object;
173
+ preflightOutput: unknown;
174
+ acknowledgement: unknown;
175
+ plan: readonly unknown[];
176
+ delegate: { rawRequest(...args: unknown[]): Promise<unknown> };
177
+ request: ProjectedRenewalConfigurationV2;
178
+ firstState: WriteObservations;
179
+ gates: ReturnType<typeof configureWriteBarriers>;
180
+ advance: (next: number) => void;
181
+ }) {
182
+ const states = {
183
+ A: args.firstState,
184
+ B: writeObservationState(),
185
+ C: writeObservationState(),
186
+ };
187
+ const declarations = args.declarations.stages;
188
+ const times = {
189
+ A: args.declared.writeAt,
190
+ B: args.declared.replay.BAt,
191
+ C: args.declared.replay.CAt,
192
+ };
193
+ const routes = {
194
+ A: createWriteHTTPAndSink(
195
+ declarations.A,
196
+ states.A,
197
+ args.gates,
198
+ args.request,
199
+ args.owner,
200
+ () => args.advance(times.A),
201
+ ),
202
+ B: createWriteHTTPAndSink(
203
+ declarations.B,
204
+ states.B,
205
+ args.gates,
206
+ args.request,
207
+ args.owner,
208
+ () => args.advance(times.B),
209
+ ),
210
+ C: createWriteHTTPAndSink(
211
+ declarations.C,
212
+ states.C,
213
+ args.gates,
214
+ args.request,
215
+ args.owner,
216
+ () => args.advance(times.C),
217
+ ),
218
+ };
219
+ const delegates = {
220
+ A:
221
+ args.declared.name === "source-post-sync-throw" ||
222
+ args.declared.name === "source-post-nonpromise" ||
223
+ args.declared.name === "source-post-hostile-late-reject"
224
+ ? Object.freeze({
225
+ rawRequest(...values: unknown[]) {
226
+ if (values[0] === "POST" && values[1] === args.request.path) {
227
+ states.A.trace.push(args.declared.name);
228
+ if (args.declared.name === "source-post-hostile-late-reject") {
229
+ const trap = (): never => {
230
+ states.A.traps++;
231
+ throw Error("TEST_LATE_SOURCE_REFLECTION");
232
+ };
233
+ const hostile = new Proxy(Object.freeze({}), {
234
+ get: trap,
235
+ ownKeys: trap,
236
+ getPrototypeOf: trap,
237
+ getOwnPropertyDescriptor: trap,
238
+ });
239
+ const promise = args.gates
240
+ .hold("source-rejection")
241
+ .then(() => {
242
+ throw hostile;
243
+ });
244
+ args.gates.pending.push(
245
+ promise.then(
246
+ () => {},
247
+ () => {},
248
+ ),
249
+ );
250
+ return promise;
251
+ }
252
+ if (args.declared.name === "source-post-sync-throw")
253
+ throw Error("TEST_SOURCE_DELEGATE_SYNCHRONOUS_FAILURE");
254
+ return Object.freeze({ notAnSDKPromise: true });
255
+ }
256
+ return Reflect.apply(
257
+ args.delegate.rawRequest,
258
+ args.delegate,
259
+ values,
260
+ ) as ReturnType<typeof args.delegate.rawRequest>;
261
+ },
262
+ })
263
+ : args.delegate,
264
+ B: Object.freeze({
265
+ rawRequest(...xs: unknown[]) {
266
+ return Reflect.apply(
267
+ args.delegate.rawRequest,
268
+ args.delegate,
269
+ xs,
270
+ ) as Promise<unknown>;
271
+ },
272
+ }),
273
+ C: Object.freeze({
274
+ rawRequest(...xs: unknown[]) {
275
+ return Reflect.apply(
276
+ args.delegate.rawRequest,
277
+ args.delegate,
278
+ xs,
279
+ ) as Promise<unknown>;
280
+ },
281
+ }),
282
+ };
283
+ const A = declareWriteSources({
284
+ mode: args.declared.name,
285
+ owner: args.owner,
286
+ origin: args.origin,
287
+ entry: args.entry,
288
+ coverage: args.coverage,
289
+ record: args.record,
290
+ configuration: args.configuration,
291
+ preflightOutput: args.preflightOutput,
292
+ acknowledgement: args.acknowledgement,
293
+ plan: args.plan,
294
+ delegate: delegates.A,
295
+ sink: routes.A.sink,
296
+ request: args.request,
297
+ state: states.A,
298
+ });
299
+ const previousB =
300
+ args.declared.name === "foreign-prior"
301
+ ? Object.freeze({})
302
+ : args.declared.name === "cloned-prior"
303
+ ? Object.freeze({ ...A.operation })
304
+ : A.operation;
305
+ const B = declareReplaySources({
306
+ owner: args.owner,
307
+ origin: args.origin,
308
+ entry: args.entry,
309
+ coverage: args.coverage,
310
+ previous: previousB,
311
+ plan: args.plan,
312
+ delegate: delegates.B,
313
+ sink: routes.B.sink,
314
+ request: args.request,
315
+ state: states.B,
316
+ });
317
+ const C = declareReplaySources({
318
+ owner: args.owner,
319
+ origin: args.origin,
320
+ entry: args.entry,
321
+ coverage: args.coverage,
322
+ previous:
323
+ args.declared.replay.previousC === "A" ? A.operation : B.operation,
324
+ plan: args.plan,
325
+ delegate: delegates.C,
326
+ sink: routes.C.sink,
327
+ request: args.request,
328
+ state: states.C,
329
+ });
330
+ for (const state of Object.values(states)) state.phase = "writer";
331
+ const bindings = Object.freeze({
332
+ A: Object.freeze({
333
+ ...A,
334
+ state: states.A,
335
+ route: routes.A,
336
+ time: times.A,
337
+ stage: "A",
338
+ }),
339
+ B: Object.freeze({
340
+ ...B,
341
+ state: states.B,
342
+ route: routes.B,
343
+ time: times.B,
344
+ stage: "B",
345
+ }),
346
+ C: Object.freeze({
347
+ ...C,
348
+ state: states.C,
349
+ route: routes.C,
350
+ time: times.C,
351
+ stage: "C",
352
+ }),
353
+ });
354
+ type Binding = (typeof bindings)[keyof typeof bindings];
355
+ const scope = new AsyncLocalStorage<Binding>();
356
+ const bound = () => {
357
+ const value = scope.getStore();
358
+ assert(value, "MISSING_TEST_ASYNC_BINDING");
359
+ return value;
360
+ };
361
+ vi.stubGlobal("fetch", (input: unknown, init: RequestInit) =>
362
+ bound().route.fetch(input, init),
363
+ );
364
+ // Lazy import follows actual initial ACK/preflight and TEST Source mock installation.
365
+ const actualActor = await import("../configure/actor.js");
366
+ function observedHandle(
367
+ binding: Binding,
368
+ handle: ReturnType<typeof actualActor.captureOwnedConfigureV2>,
369
+ ) {
370
+ return Object.freeze({
371
+ invoke(...values: unknown[]) {
372
+ binding.state.targetCalls++;
373
+ const promise = scope.run(binding, () =>
374
+ Reflect.apply(handle.invoke, handle, values),
375
+ ) as ReturnType<typeof handle.invoke>;
376
+ args.gates.pending.push(
377
+ promise.then(
378
+ () => {},
379
+ () => {},
380
+ ),
381
+ );
382
+ return promise;
383
+ },
384
+ });
385
+ }
386
+ function captureA(...values: unknown[]) {
387
+ const handle = scope.run(bindings.A, () =>
388
+ Reflect.apply(actualActor.captureOwnedConfigureV2, actualActor, values),
389
+ ) as ReturnType<typeof actualActor.captureOwnedConfigureV2>;
390
+ return observedHandle(bindings.A, handle);
391
+ }
392
+ function captureB(...values: unknown[]) {
393
+ const handle = scope.run(bindings.B, () =>
394
+ Reflect.apply(
395
+ actualActor.captureOwnedConfigureReplayV2,
396
+ actualActor,
397
+ values,
398
+ ),
399
+ ) as ReturnType<typeof actualActor.captureOwnedConfigureReplayV2>;
400
+ return observedHandle(bindings.B, handle);
401
+ }
402
+ function captureC(...values: unknown[]) {
403
+ const handle = scope.run(bindings.C, () =>
404
+ Reflect.apply(
405
+ actualActor.captureOwnedConfigureReplayV2,
406
+ actualActor,
407
+ values,
408
+ ),
409
+ ) as ReturnType<typeof actualActor.captureOwnedConfigureReplayV2>;
410
+ return observedHandle(bindings.C, handle);
411
+ }
412
+ return Object.freeze({
413
+ captureA,
414
+ captureB,
415
+ captureC,
416
+ states,
417
+ currentObservations: () => scope.getStore()?.state ?? states.A,
418
+ covers(
419
+ record: unknown,
420
+ evidence: unknown,
421
+ request: unknown,
422
+ expectedEvidence: object,
423
+ ) {
424
+ const b = bound();
425
+ b.state.coverage++;
426
+ assert.deepEqual(record, args.record);
427
+ assert.deepEqual(request, args.request);
428
+ assert.deepEqual(evidence, {
429
+ ...expectedEvidence,
430
+ observedAt: Math.floor(b.time / 1000),
431
+ });
432
+ return true;
433
+ },
434
+ initialOperation() {
435
+ const b = bound();
436
+ assert.equal(b.stage, "A");
437
+ b.state.sourceLoads++;
438
+ return b.operation;
439
+ },
440
+ initialFrame() {
441
+ const b = bound();
442
+ assert.equal(b.stage, "A");
443
+ b.state.pairLoads++;
444
+ return b.frame;
445
+ },
446
+ replayOperation() {
447
+ const b = bound();
448
+ assert.notEqual(b.stage, "A");
449
+ b.state.sourceLoads++;
450
+ return b.operation;
451
+ },
452
+ replayFrame() {
453
+ const b = bound();
454
+ assert.notEqual(b.stage, "A");
455
+ b.state.pairLoads++;
456
+ return b.frame;
457
+ },
458
+ });
459
+ }
460
+
461
+ export type ConfiguredWriteTestFamily = Awaited<
462
+ ReturnType<typeof configureWriteTestFamily>
463
+ >;