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