@fantastic.dev/better-stripe 0.98.0 → 0.99.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 (93) 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 +6 -0
  4. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +1 -1
  6. package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
  8. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
  10. package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
  12. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
  13. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
  14. package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
  15. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +9 -11
  16. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +3 -380
  18. package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +138 -0
  20. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
  21. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +64 -139
  22. package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
  23. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts +63 -0
  24. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
  26. package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js.map +1 -0
  27. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +2 -0
  28. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
  29. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +6 -0
  30. package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
  31. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
  32. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
  33. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
  34. package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
  35. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
  36. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -1
  37. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +3 -2
  38. package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -1
  39. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
  40. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
  41. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
  42. package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
  43. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
  44. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
  45. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
  46. package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
  47. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
  48. package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
  49. package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
  50. package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
  51. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
  52. package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
  53. package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
  54. package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
  55. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
  56. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
  57. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
  58. package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
  59. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
  60. package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
  61. package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
  62. package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
  63. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  64. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  65. package/dist/component/balanceFunding/mutations.d.ts +16 -16
  66. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  67. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  68. package/dist/component/earnings/triggers.d.ts +16 -16
  69. package/dist/component/payoutRelease/queries.d.ts +2 -2
  70. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  71. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  72. package/dist/component/usage/allowance.fixtures.d.ts +16 -16
  73. package/docs/renewal-context-reads.md +44 -3
  74. package/package.json +1 -1
  75. package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +3 -3
  76. package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
  77. package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
  78. package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +4 -498
  79. package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +83 -160
  80. package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
  81. package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +6 -0
  82. package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
  83. package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +3 -2
  84. package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
  85. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
  86. package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
  87. package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
  88. package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
  89. package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
  90. package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
  91. package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
  92. package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
  93. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +14 -1
@@ -0,0 +1,437 @@
1
+ import assert from "node:assert/strict";
2
+ import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
3
+ import { afterEach, beforeEach, expect, it, vi } from "vitest";
4
+ import { initialOperations } from "../test-fixtures/producerInitialOperation.js";
5
+ import { declaredInputs } from "../test-fixtures/attachEntries.js";
6
+ import {
7
+ captureRetainedInput,
8
+ type RetainedInput,
9
+ } from "../material/capture.js";
10
+ import { INITIAL_NS } from "../test-fixtures/producerInitialDeclarations.js";
11
+ import { captureInitialInvocationCore } from "./invocationProducer.js";
12
+ import { data } from "../test-fixtures/attachScenarioBarriers.js";
13
+
14
+ const controls = vi.hoisted(() => {
15
+ const entries: { coversRetained(): boolean; coversFresh(): boolean }[] = [];
16
+ const recovery: { originalEntry: unknown; coversReplay(): boolean }[] = [];
17
+ return { entries, recovery, legacy: 0 };
18
+ });
19
+ // Synthetic TEST coverage only. Production compiled profile arrays stay EMPTY.
20
+ vi.mock("../operations/sourceOperations.js", () => {
21
+ const poisoned = () => {
22
+ controls.legacy++;
23
+ throw Error("LEGACY_SOURCE_POISON");
24
+ };
25
+ return {
26
+ COMPILED_INITIAL_ENTRIES: controls.entries,
27
+ COMPILED_RECOVERY_ENTRIES: controls.recovery,
28
+ loadFixedExplicitRecoveryOperation: poisoned,
29
+ ORIGINAL_ORIGIN_ASSOCIATION: null,
30
+ loadFixedInitialOperation: poisoned,
31
+ loadOwnedTransportSource: poisoned,
32
+ loadInitialOwnedTransportSource: poisoned,
33
+ loadRecoveryOwnedTransportSource: poisoned,
34
+ };
35
+ });
36
+ vi.mock("../originalOwner.js", () => ({
37
+ OWNER: Object.freeze({
38
+ get basis() {
39
+ controls.legacy++;
40
+ throw Error("LEGACY_OWNER_POISON");
41
+ },
42
+ check() {
43
+ controls.legacy++;
44
+ throw Error("LEGACY_OWNER_POISON");
45
+ },
46
+ sample() {
47
+ controls.legacy++;
48
+ throw Error("LEGACY_OWNER_POISON");
49
+ },
50
+ subscribe() {
51
+ controls.legacy++;
52
+ throw Error("LEGACY_OWNER_POISON");
53
+ },
54
+ retire() {
55
+ controls.legacy++;
56
+ throw Error("LEGACY_OWNER_POISON");
57
+ },
58
+ }),
59
+ }));
60
+ type Declaration = {
61
+ source: RetainedInput;
62
+ post: Record<string, unknown>;
63
+ key: string;
64
+ };
65
+ function declaration(suffix?: string): Declaration {
66
+ const original = declaredInputs("INITIAL-ACK");
67
+ const replace = (_key: string, value: unknown) =>
68
+ suffix && value === "sub_original" ? "sub_original_" + suffix : value;
69
+ const raw = JSON.parse(JSON.stringify(original.original), replace);
70
+ if (suffix) raw.attachRequest.attachKey += ":" + suffix;
71
+ const post: Record<string, unknown> = JSON.parse(
72
+ JSON.stringify(original.aPost),
73
+ replace,
74
+ );
75
+ if (suffix) post.id += "_" + suffix;
76
+ return {
77
+ source: captureRetainedInput(raw),
78
+ post,
79
+ key: suffix
80
+ ? "sk_test_invalid_actor_" + suffix
81
+ : "sk_test_invalid_owner_core",
82
+ };
83
+ }
84
+ function windowFor(source: RetainedInput) {
85
+ return {
86
+ workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
87
+ endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
88
+ };
89
+ }
90
+ function wireFor(
91
+ declared: Declaration[],
92
+ beforePost = async (_index: number) => {},
93
+ ) {
94
+ const calls: { method: string; path: string; index: number }[] = [];
95
+ const routes = new Map<string, { body: unknown; auth: Set<string> }>();
96
+ for (const item of declared) {
97
+ const b = item.source.originalBundle;
98
+ const rows: [string, unknown][] = [
99
+ [
100
+ "/v1/subscriptions/" +
101
+ item.source.attachRequest.preparation.expected.subscriptionId,
102
+ b.wireSubscription,
103
+ ],
104
+ [
105
+ "/v1/prices/" +
106
+ item.source.attachRequest.preparation.expected.targetPriceId,
107
+ b.wireTargetPrice,
108
+ ],
109
+ ["/v1/customers/" + b.wireBillingCustomer.id, b.wireBillingCustomer],
110
+ ];
111
+ for (const row of b.couponReads) {
112
+ assert(typeof row.couponId === "string");
113
+ rows.push([
114
+ "/v1/coupons/" + encodeURIComponent(row.couponId),
115
+ row.wireCoupon,
116
+ ]);
117
+ }
118
+ for (const [path, body] of rows) {
119
+ const route = routes.get(path) ?? { body, auth: new Set<string>() };
120
+ route.auth.add("Bearer " + item.key);
121
+ routes.set(path, route);
122
+ }
123
+ }
124
+ return {
125
+ calls,
126
+ fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
127
+ const url = new URL(String(input));
128
+ assert.equal(url.origin, "https://api.stripe.com");
129
+ assert.equal(init?.redirect, "error");
130
+ const headers = new Headers(init?.headers);
131
+ const auth = headers.get("authorization");
132
+ let body: unknown,
133
+ index = -1;
134
+ if (init?.method === "GET") {
135
+ const row = routes.get(url.pathname);
136
+ assert(row && auth && row.auth.has(auth));
137
+ body = row.body;
138
+ } else {
139
+ assert.equal(init?.method, "POST");
140
+ assert.equal(url.pathname, "/v1/subscription_schedules");
141
+ index = declared.findIndex(
142
+ (item) =>
143
+ item.source.attachRequest.attachKey ===
144
+ headers.get("idempotency-key"),
145
+ );
146
+ assert(index >= 0);
147
+ assert.equal(auth, "Bearer " + declared[index].key);
148
+ assert.equal(
149
+ new URLSearchParams(String(init?.body)).get("from_subscription"),
150
+ declared[index].source.attachRequest.preparation.expected
151
+ .subscriptionId,
152
+ );
153
+ await beforePost(index);
154
+ body = declared[index].post;
155
+ }
156
+ calls.push({ method: init?.method ?? "", path: url.pathname, index });
157
+ return new Response(JSON.stringify(body), {
158
+ status: 200,
159
+ headers: {
160
+ "content-type": "application/json",
161
+ "request-id": "req_initial_actor_" + calls.length,
162
+ },
163
+ });
164
+ },
165
+ };
166
+ }
167
+ beforeEach(() => {
168
+ controls.legacy = 0;
169
+ controls.entries.splice(0, controls.entries.length, {
170
+ coversRetained: () => true,
171
+ coversFresh: () => true,
172
+ });
173
+ controls.recovery.splice(0, controls.recovery.length, {
174
+ originalEntry: controls.entries[0],
175
+ coversReplay: () => true,
176
+ });
177
+ vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
178
+ vi.setSystemTime(
179
+ (declaration().source.attachRequest.firstDispatchedAt + 1) * 1000,
180
+ );
181
+ vi.spyOn(process.hrtime, "bigint").mockReturnValue(INITIAL_NS);
182
+ });
183
+ afterEach(() => {
184
+ vi.useRealTimers();
185
+ vi.unstubAllGlobals();
186
+ vi.restoreAllMocks();
187
+ });
188
+
189
+ function recover(core: object) {
190
+ const capture = Reflect.get(core, "recoverAttach");
191
+ expect(typeof capture).toBe("function");
192
+ return Reflect.apply(capture, core, []) as { invoke(): Promise<unknown> };
193
+ }
194
+
195
+ it.each(["before_attempt", "returned_ack", "retired"])(
196
+ "refuses recovery for %s without additional provider work",
197
+ async (state) => {
198
+ const declared = declaration();
199
+ await initialOperations(
200
+ async ({ fresh, journal }) => {
201
+ const wire = wireFor([declared]);
202
+ vi.stubGlobal("fetch", wire.fetch);
203
+ const core = await captureInitialInvocationCore(fresh.call, journal);
204
+ try {
205
+ if (state === "returned_ack")
206
+ expect(data(await core.initialAttach().invoke()).status).toBe(
207
+ "attach_acknowledged",
208
+ );
209
+ if (state === "retired") core.owner.retire();
210
+ const calls = wire.calls.length;
211
+ await expect(recover(core).invoke()).rejects.toThrow();
212
+ expect(wire.calls).toHaveLength(calls);
213
+ expect(controls.legacy).toBe(0);
214
+ } finally {
215
+ core.owner.retire();
216
+ }
217
+ },
218
+ 1,
219
+ { source: declared.source, ...windowFor(declared.source) },
220
+ );
221
+ },
222
+ );
223
+
224
+ it("EMPTY recovery and replacement arguments refuse before new clock or provider effects", async () => {
225
+ const declared = declaration();
226
+ controls.recovery.length = 0;
227
+ await initialOperations(
228
+ async ({ fresh, journal }) => {
229
+ const wire = wireFor([declared]);
230
+ vi.stubGlobal("fetch", wire.fetch);
231
+ const core = await captureInitialInvocationCore(fresh.call, journal);
232
+ try {
233
+ const wall = vi.spyOn(Date, "now");
234
+ const mono = vi.mocked(process.hrtime.bigint).mock.calls.length;
235
+ let foreign = 0;
236
+ const replacement = {
237
+ get client() {
238
+ foreign++;
239
+ throw Error("FOREIGN");
240
+ },
241
+ };
242
+ expect(() =>
243
+ Reflect.apply(core.recoverAttach, undefined, [replacement]),
244
+ ).toThrow("INITIAL_OPERATION_UNBOUND");
245
+ const actor = recover(core);
246
+ expect(data(await actor.invoke()).reason).toBe(
247
+ "no_qualified_recovery_class",
248
+ );
249
+ await expect(
250
+ Reflect.apply(actor.invoke, undefined, [replacement]),
251
+ ).rejects.toThrow("INITIAL_ACTOR_STOP");
252
+ expect(wall).not.toHaveBeenCalled();
253
+ expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(mono);
254
+ expect(foreign).toBe(0);
255
+ expect(wire.calls).toHaveLength(0);
256
+ expect(controls.legacy).toBe(0);
257
+ } finally {
258
+ core.owner.retire();
259
+ }
260
+ },
261
+ 1,
262
+ { source: declared.source, ...windowFor(declared.source) },
263
+ );
264
+ });
265
+
266
+ it("refuses recovery while a committed response2 mutation reply remains pending", async () => {
267
+ const declared = declaration();
268
+ let count = 0,
269
+ release!: () => void,
270
+ entered!: () => void;
271
+ const reply = new Promise<void>((resolve) => {
272
+ release = resolve;
273
+ });
274
+ const committed = new Promise<void>((resolve) => {
275
+ entered = resolve;
276
+ });
277
+ await initialOperations(
278
+ async ({ fresh, journal }) => {
279
+ assert(fresh.result.disposition === "acquired");
280
+ const wire = wireFor([declared]);
281
+ vi.stubGlobal("fetch", wire.fetch);
282
+ const core = await captureInitialInvocationCore(fresh.call, journal);
283
+ try {
284
+ const initial = core.initialAttach().invoke();
285
+ await committed;
286
+ await vi.advanceTimersByTimeAsync(5000);
287
+ expect(data(await initial).status).toBe("fulfilled_unverified");
288
+ const requests = wire.calls.length;
289
+ await expect(recover(core).invoke()).rejects.toThrow(
290
+ "INITIAL_ACTOR_STOP",
291
+ );
292
+ expect(wire.calls).toHaveLength(requests);
293
+ expect(wire.calls.filter((row) => row.method === "POST")).toHaveLength(
294
+ 1,
295
+ );
296
+ expect(
297
+ await journal.readStageEvent({
298
+ attemptId: fresh.result.reservation.attemptId,
299
+ sequence: 2,
300
+ }),
301
+ ).not.toBeNull();
302
+ expect(
303
+ await journal.readStageEvent({
304
+ attemptId: fresh.result.reservation.attemptId,
305
+ sequence: 3,
306
+ }),
307
+ ).toBeNull();
308
+ expect(await journal.readProviderAcknowledgement()).toBeNull();
309
+ expect(controls.legacy).toBe(0);
310
+ } finally {
311
+ release();
312
+ await new Promise<void>((resolve) => setImmediate(resolve));
313
+ core.owner.retire();
314
+ }
315
+ },
316
+ 1,
317
+ {
318
+ source: declared.source,
319
+ workEndWallMs:
320
+ (declared.source.attachRequest.firstDispatchedAt + 20) * 1000,
321
+ endWallMs: (declared.source.attachRequest.firstDispatchedAt + 21) * 1000,
322
+ afterAppend: async () => {
323
+ count++;
324
+ if (count === 2) {
325
+ entered();
326
+ await reply;
327
+ }
328
+ },
329
+ },
330
+ );
331
+ });
332
+
333
+ it.each(["relation", "retained_predicate", "fresh_predicate"])(
334
+ "refuses changed %s before replay reads or POST",
335
+ async (change) => {
336
+ const declared = declaration();
337
+ await initialOperations(
338
+ async ({ fresh, journal }) => {
339
+ let posts = 0;
340
+ const wire = wireFor([declared], async () => {
341
+ posts++;
342
+ throw Error("CONTROLLED_LOST_RESPONSE");
343
+ });
344
+ vi.stubGlobal("fetch", wire.fetch);
345
+ const core = await captureInitialInvocationCore(fresh.call, journal);
346
+ try {
347
+ await expect(core.initialAttach().invoke()).rejects.toThrow(
348
+ "INITIAL_PROVIDER_REJECTED",
349
+ );
350
+ if (change === "relation") controls.recovery[0].originalEntry = {};
351
+ if (change === "retained_predicate")
352
+ controls.entries[0].coversRetained = () => true;
353
+ if (change === "fresh_predicate")
354
+ controls.entries[0].coversFresh = () => true;
355
+ const requests = wire.calls.length;
356
+ await expect(recover(core).invoke()).rejects.toThrow(
357
+ "INITIAL_ACTOR_STOP",
358
+ );
359
+ expect(wire.calls).toHaveLength(requests);
360
+ expect(posts).toBe(1);
361
+ expect(controls.legacy).toBe(0);
362
+ } finally {
363
+ core.owner.retire();
364
+ }
365
+ },
366
+ 1,
367
+ { source: declared.source, ...windowFor(declared.source) },
368
+ );
369
+ },
370
+ );
371
+
372
+ it("refuses another POST when actual journal history advances during a blocked recovery read", async () => {
373
+ const declared = declaration();
374
+ await initialOperations(
375
+ async ({ fresh, journal }) => {
376
+ assert(fresh.result.disposition === "acquired");
377
+ let posts = 0,
378
+ release!: () => void,
379
+ entered!: () => void;
380
+ const blocked = new Promise<void>((resolve) => {
381
+ release = resolve;
382
+ });
383
+ const readEntered = new Promise<void>((resolve) => {
384
+ entered = resolve;
385
+ });
386
+ const wire = wireFor([declared], async () => {
387
+ posts++;
388
+ if (posts === 1) throw Error("CONTROLLED_LOST_RESPONSE");
389
+ });
390
+ vi.stubGlobal(
391
+ "fetch",
392
+ async (input: RequestInfo | URL, init?: RequestInit) => {
393
+ if (
394
+ posts === 1 &&
395
+ init?.method === "GET" &&
396
+ new URL(String(input)).pathname.startsWith("/v1/subscriptions/")
397
+ ) {
398
+ entered();
399
+ await blocked;
400
+ }
401
+ return wire.fetch(input, init);
402
+ },
403
+ );
404
+ const core = await captureInitialInvocationCore(fresh.call, journal);
405
+ try {
406
+ await expect(core.initialAttach().invoke()).rejects.toThrow(
407
+ "INITIAL_PROVIDER_REJECTED",
408
+ );
409
+ const recovery = recover(core)
410
+ .invoke()
411
+ .catch((error) => error);
412
+ await readEntered;
413
+ // Concurrent host-authorized journal DATA is not provider response custody.
414
+ const event = await canonicalJournalEvent(
415
+ 2,
416
+ JSON.stringify({ frontier: "advanced-during-recovery-read" }),
417
+ );
418
+ await journal.appendStageEvent({
419
+ reservation: fresh.result.reservation,
420
+ expectedSequence: 1,
421
+ event: { sequence: 2, binding: event.binding, dataJSON: event.json },
422
+ });
423
+ release();
424
+ const result = await recovery;
425
+ expect(posts).toBe(1);
426
+ expect(result).toMatchObject({ message: "INITIAL_ACTOR_STOP" });
427
+ expect(await journal.readProviderAcknowledgement()).toBeNull();
428
+ expect(controls.legacy).toBe(0);
429
+ } finally {
430
+ release();
431
+ core.owner.retire();
432
+ }
433
+ },
434
+ 1,
435
+ { source: declared.source, ...windowFor(declared.source) },
436
+ );
437
+ });