@fantastic.dev/better-stripe 0.104.0 → 0.105.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 (43) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +100 -0
  4. package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
  5. package/dist/client/billing/renewalAttach/internal/configure/transport.js +17 -2
  6. package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +16 -0
  8. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -1
  9. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +46 -0
  10. package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -1
  11. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +25 -0
  12. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -1
  13. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +62 -0
  14. package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -1
  15. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +14 -0
  16. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -1
  17. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +17 -0
  18. package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -1
  19. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts +30 -0
  20. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -0
  21. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +224 -0
  22. package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -0
  23. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts +61 -0
  24. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts.map +1 -0
  25. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js +73 -0
  26. package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js.map +1 -0
  27. package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
  28. package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
  29. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  30. package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
  31. package/dist/component/balanceFunding/queries.d.ts +1 -1
  32. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  33. package/docs/renewal-context-reads.md +47 -4
  34. package/package.json +1 -1
  35. package/src/client/billing/renewalAttach/internal/configure/transport.ts +31 -2
  36. package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +92 -0
  37. package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +84 -0
  38. package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +16 -0
  39. package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +317 -0
  40. package/src/client/billing/renewalAttach/internal/producer/configureWriteFactory.ts +88 -0
  41. package/src/client/billing/renewalAttach/internal/producer/producerConfigureWrite.integration.test.ts +158 -0
  42. package/src/client/billing/renewalAttach/internal/producer/producerConfigureWriteControls.integration.test.ts +537 -0
  43. package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +85 -2
@@ -0,0 +1,537 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import {
3
+ configureAdmissionFixture,
4
+ admissionControls,
5
+ configureAdmissionCase,
6
+ prepareAdmittedConfigure,
7
+ } from "../test-fixtures/producerConfigureAdmission.js";
8
+ import { captureAdmittedConfigurePreflight } from "./configurePreflight.js";
9
+ import {
10
+ captureAdmittedConfigureWrite,
11
+ readAdmittedConfigureAcknowledgement,
12
+ } from "./configureWrite.js";
13
+ import { object } from "./configureJournalData.js";
14
+
15
+ type Harness = Parameters<Parameters<typeof configureAdmissionFixture>[0]>[0];
16
+ async function prepare(h: Harness, preflight = true) {
17
+ await h.complete();
18
+ const child = await h.child();
19
+ const token = await h.core.admitConfigure(child.fresh.call, child.journal);
20
+ const current = h.configureReads(child);
21
+ if (admissionControls.preflight.length === 0)
22
+ admissionControls.preflight.push({
23
+ originalEntry: admissionControls.entries[0],
24
+ coversPreflight: () => true,
25
+ });
26
+ if (admissionControls.write.length === 0)
27
+ admissionControls.write.push({
28
+ originalEntry: admissionControls.entries[0],
29
+ coversConfigure: () => true,
30
+ });
31
+ if (preflight) await captureAdmittedConfigurePreflight(token).invoke();
32
+ return { child, token, current };
33
+ }
34
+ function deferred() {
35
+ let resolve!: () => void;
36
+ const promise = new Promise<void>((done) => {
37
+ resolve = done;
38
+ });
39
+ return { promise, resolve };
40
+ }
41
+ function posts(h: Harness) {
42
+ return h.calls.filter(
43
+ (call) =>
44
+ call.method === "POST" &&
45
+ call.path.startsWith("/v1/subscription_schedules/"),
46
+ );
47
+ }
48
+
49
+ it.each([
50
+ "no-preflight",
51
+ "empty",
52
+ "foreign",
53
+ "ambiguous",
54
+ "copy",
55
+ "proxy",
56
+ "extra",
57
+ ])("refuses %s write custody without provider reads", async (scenario) => {
58
+ await configureAdmissionFixture(async (h) => {
59
+ const { token } = await prepare(h, scenario !== "no-preflight");
60
+ if (scenario === "empty") admissionControls.write.splice(0);
61
+ if (scenario === "foreign") admissionControls.write[0].originalEntry = {};
62
+ if (scenario === "ambiguous")
63
+ admissionControls.write.push({ ...admissionControls.write[0] });
64
+ let traps = 0;
65
+ const copied =
66
+ scenario === "copy"
67
+ ? { ...token }
68
+ : scenario === "proxy"
69
+ ? new Proxy(token, {
70
+ get() {
71
+ traps++;
72
+ throw Error("PROXY_TRAP");
73
+ },
74
+ })
75
+ : token;
76
+ const before = h.calls.length;
77
+ expect(() =>
78
+ scenario === "extra"
79
+ ? Reflect.apply(captureAdmittedConfigureWrite, undefined, [token, {}])
80
+ : captureAdmittedConfigureWrite(copied),
81
+ ).toThrow();
82
+ expect(h.calls).toHaveLength(before);
83
+ expect(posts(h)).toHaveLength(0);
84
+ expect(traps).toBe(0);
85
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
86
+ });
87
+ });
88
+ it("invalid invoke arguments spend the actor without a POST or second frame", async () => {
89
+ await configureAdmissionFixture(async (h) => {
90
+ const { token } = await prepare(h),
91
+ actor = captureAdmittedConfigureWrite(token),
92
+ before = h.calls.length;
93
+ await expect(Reflect.apply(actor.invoke, actor, [{}])).rejects.toThrow();
94
+ await expect(actor.invoke()).rejects.toThrow();
95
+ expect(() => captureAdmittedConfigureWrite(token)).toThrow();
96
+ expect(h.calls).toHaveLength(before);
97
+ });
98
+ });
99
+ it.each([
100
+ "subscription",
101
+ "schedule",
102
+ "predicate",
103
+ "entry-pointer",
104
+ "preflight-pointer",
105
+ ])("changed %s refuses before POST", async (scenario) => {
106
+ await configureAdmissionFixture(async (h) => {
107
+ const { token, current } = await prepare(h),
108
+ actor = captureAdmittedConfigureWrite(token);
109
+ if (scenario === "subscription")
110
+ Reflect.set(current.subscription, "metadata", { changed: true });
111
+ if (scenario === "schedule") current.schedule.metadata = { changed: true };
112
+ if (scenario === "predicate")
113
+ admissionControls.write[0].coversConfigure = () => false;
114
+ if (scenario === "entry-pointer") admissionControls.write.splice(0);
115
+ if (scenario === "preflight-pointer")
116
+ admissionControls.preflight[0].coversPreflight = () => true;
117
+ try {
118
+ await actor.invoke();
119
+ } catch {
120
+ /* Closed source metadata may reject. */
121
+ }
122
+ expect(posts(h)).toHaveLength(0);
123
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
124
+ await expect(actor.invoke()).rejects.toThrow();
125
+ });
126
+ });
127
+ for (const phase of ["dispatch", "retention", "receipt"] as const) {
128
+ const entered = deferred(),
129
+ released = deferred();
130
+ let armed = false,
131
+ appended = 0;
132
+ configureAdmissionCase(
133
+ "pending " + phase + " reply cannot return actual configure ACK",
134
+ prepareAdmittedConfigure,
135
+ async (h, { token, child }) => {
136
+ armed = true;
137
+ const actor = captureAdmittedConfigureWrite(token),
138
+ pending = actor.invoke();
139
+ try {
140
+ expect(
141
+ await Promise.race([
142
+ entered.promise.then(() => true),
143
+ pending.then(
144
+ () => false,
145
+ () => false,
146
+ ),
147
+ ]),
148
+ ).toBe(true);
149
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
150
+ await expect(actor.invoke()).rejects.toThrow();
151
+ expect(posts(h)).toHaveLength(phase === "dispatch" ? 0 : 1);
152
+ if (phase !== "dispatch")
153
+ expect(
154
+ await child.journal.readProviderAcknowledgement(),
155
+ ).not.toBeNull();
156
+ } finally {
157
+ released.resolve();
158
+ }
159
+ const output = await pending;
160
+ expect(object(output).status).toBe("configure_acknowledged");
161
+ expect(
162
+ readAdmittedConfigureAcknowledgement(token).output === output,
163
+ ).toBe(true);
164
+ },
165
+ {
166
+ afterAppend: async () => {
167
+ if (
168
+ armed &&
169
+ ++appended === (phase === "dispatch" ? 1 : 3) &&
170
+ phase !== "retention"
171
+ ) {
172
+ entered.resolve();
173
+ await released.promise;
174
+ }
175
+ },
176
+ afterRetain: async () => {
177
+ if (armed && phase === "retention") {
178
+ entered.resolve();
179
+ await released.promise;
180
+ }
181
+ },
182
+ },
183
+ );
184
+ }
185
+ it("retention rejection after commit keeps C9 but returns no ACK or second POST", async () => {
186
+ let armed = false;
187
+ await configureAdmissionFixture(
188
+ async (h) => {
189
+ const { token, child } = await prepare(h);
190
+ armed = true;
191
+ const actor = captureAdmittedConfigureWrite(token);
192
+ expect(object(await actor.invoke()).status).toBe("configure_unknown");
193
+ expect(await child.journal.readProviderAcknowledgement()).not.toBeNull();
194
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
195
+ await expect(actor.invoke()).rejects.toThrow();
196
+ expect(posts(h)).toHaveLength(1);
197
+ },
198
+ {
199
+ afterRetain: async () => {
200
+ if (armed) throw Error("CONTROLLED_RETENTION_REPLY_REJECTION");
201
+ },
202
+ },
203
+ );
204
+ });
205
+ it("parent retirement during POST returns unknown and late fulfillment cannot publish ACK", async () => {
206
+ const entered = deferred(),
207
+ released = deferred();
208
+ let armed = false;
209
+ await configureAdmissionFixture(
210
+ async (h) => {
211
+ const { token, child } = await prepare(h);
212
+ armed = true;
213
+ const actor = captureAdmittedConfigureWrite(token),
214
+ pending = actor.invoke();
215
+ try {
216
+ expect(
217
+ await Promise.race([
218
+ entered.promise.then(() => true),
219
+ pending.then(
220
+ () => false,
221
+ () => false,
222
+ ),
223
+ ]),
224
+ ).toBe(true);
225
+ h.core.owner.retire();
226
+ expect(object(await pending).status).toBe("configure_unknown");
227
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
228
+ } finally {
229
+ released.resolve();
230
+ }
231
+ await vi.advanceTimersByTimeAsync(0);
232
+ expect(await child.journal.readProviderAcknowledgement()).toBeNull();
233
+ expect(posts(h)).toHaveLength(1);
234
+ await expect(actor.invoke()).rejects.toThrow();
235
+ },
236
+ {
237
+ beforeFetch: async (_path, method) => {
238
+ if (armed && method === "POST") {
239
+ armed = false;
240
+ entered.resolve();
241
+ await released.promise;
242
+ }
243
+ },
244
+ },
245
+ );
246
+ });
247
+ it("unsafe fulfilled POST stays unknown without response event or returned ACK", async () => {
248
+ await configureAdmissionFixture(async (h) => {
249
+ const { token, child } = await prepare(h);
250
+ Reflect.set(h.baseline.schedule, "metadata", {
251
+ unsafe: "Bearer synthetic-configure-write-control",
252
+ });
253
+ const output = await captureAdmittedConfigureWrite(token).invoke();
254
+ expect(object(output).status).toBe("configure_unknown");
255
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
256
+ expect(await child.journal.readProviderAcknowledgement()).toBeNull();
257
+ expect(posts(h)).toHaveLength(1);
258
+ });
259
+ });
260
+
261
+ it.each(["GET", "POST"])(
262
+ "an actual %s rejection carries bounded failure and never retries",
263
+ async (verb) => {
264
+ let armed = false,
265
+ attempts = 0;
266
+ await configureAdmissionFixture(
267
+ async (h) => {
268
+ const { token, child } = await prepare(h);
269
+ armed = true;
270
+ const actor = captureAdmittedConfigureWrite(token);
271
+ let actual: unknown;
272
+ try {
273
+ await actor.invoke();
274
+ } catch (error) {
275
+ actual = error;
276
+ }
277
+ expect(actual).toBeInstanceOf(Error);
278
+ expect(object(Reflect.get(actual as Error, "failure")).phase).toBe(
279
+ verb === "GET" ? "read" : "post",
280
+ );
281
+ expect(attempts).toBe(1);
282
+ expect(await child.journal.readProviderAcknowledgement()).toBeNull();
283
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
284
+ await expect(actor.invoke()).rejects.toThrow();
285
+ },
286
+ {
287
+ beforeFetch: async (_path, method) => {
288
+ if (armed && method === verb) {
289
+ attempts++;
290
+ throw Error("CONTROLLED_PROVIDER_REJECTION");
291
+ }
292
+ },
293
+ },
294
+ );
295
+ },
296
+ );
297
+ it("a returned ACK reader preserves output identity and closes after observed Source pointer drift", async () => {
298
+ await configureAdmissionFixture(async (h) => {
299
+ const { token } = await prepare(h);
300
+ const output = await captureAdmittedConfigureWrite(token).invoke();
301
+ const view = readAdmittedConfigureAcknowledgement(token);
302
+ expect(view.output === output).toBe(true);
303
+ expect(view.receipt === object(output).receipt).toBe(true);
304
+ expect(() => readAdmittedConfigureAcknowledgement({ ...token })).toThrow();
305
+ expect(() =>
306
+ Reflect.apply(readAdmittedConfigureAcknowledgement, undefined, [
307
+ token,
308
+ structuredClone(output),
309
+ ]),
310
+ ).toThrow();
311
+ const covers = admissionControls.write[0].coversConfigure;
312
+ admissionControls.write[0].coversConfigure = () => true;
313
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
314
+ admissionControls.write[0].coversConfigure = covers;
315
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
316
+ expect(posts(h)).toHaveLength(1);
317
+ });
318
+ });
319
+ it("a genuine second Action context retains the original configure attempt custody", async () => {
320
+ await configureAdmissionFixture(async (h) => {
321
+ const { token } = await prepare(h),
322
+ actor = captureAdmittedConfigureWrite(token);
323
+ await h.inAnotherAction(async () => {
324
+ const output = await actor.invoke();
325
+ expect(object(output).status).toBe("configure_acknowledged");
326
+ expect(
327
+ readAdmittedConfigureAcknowledgement(token).output === output,
328
+ ).toBe(true);
329
+ });
330
+ expect(posts(h)).toHaveLength(1);
331
+ expect(admissionControls.legacy).toBe(0);
332
+ });
333
+ });
334
+
335
+ it.each(["event-payload-alias", "changed-id", "extra-field"])(
336
+ "refuses %s in the final retention readback",
337
+ async (scenario) => {
338
+ let childId = "",
339
+ eventPayload = "",
340
+ forged = false;
341
+ await configureAdmissionFixture(
342
+ async (h) => {
343
+ const { token, child } = await prepare(h);
344
+ childId = child.created.operationId;
345
+ const output = await captureAdmittedConfigureWrite(token).invoke();
346
+ expect(forged).toBe(true);
347
+ expect(object(output).status).toBe("configure_unknown");
348
+ expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
349
+ expect(posts(h)).toHaveLength(1);
350
+ },
351
+ {
352
+ afterQuery: async (reply, reference, args) => {
353
+ if (!reply || object(args).operationId !== childId) return;
354
+ const own = object(reply);
355
+ if (
356
+ reference.endsWith("/readAttempt") &&
357
+ Array.isArray(own.events) &&
358
+ own.events.length === 3
359
+ ) {
360
+ const payload = object(own.events[2]).payloadId;
361
+ if (typeof payload === "string") eventPayload = payload;
362
+ }
363
+ if (
364
+ reference.endsWith("/readProviderAcknowledgement") &&
365
+ eventPayload &&
366
+ own.retention &&
367
+ typeof own.retention === "object"
368
+ ) {
369
+ Reflect.set(
370
+ own.retention,
371
+ scenario === "extra-field" ? "extra" : "receiptPayloadId",
372
+ scenario === "event-payload-alias"
373
+ ? eventPayload
374
+ : "controlled-changed-payload",
375
+ );
376
+ forged = true;
377
+ }
378
+ },
379
+ },
380
+ );
381
+ },
382
+ );
383
+
384
+ describe("concurrent admitted children", () => {
385
+ let pending: Promise<void>,
386
+ start: ReturnType<typeof deferred>,
387
+ postsReady: ReturnType<typeof deferred>,
388
+ releasePosts: ReturnType<typeof deferred>,
389
+ retainedReady: ReturnType<typeof deferred>,
390
+ releaseRetained: ReturnType<typeof deferred>,
391
+ run = false,
392
+ armed = false,
393
+ postCount = 0,
394
+ retainedCount = 0;
395
+ const stage = (ready: ReturnType<typeof deferred>) =>
396
+ Promise.race([
397
+ ready.promise,
398
+ pending.then(() => {
399
+ throw Error("FIXTURE_SETTLED_BEFORE_STAGE");
400
+ }),
401
+ ]);
402
+ beforeEach(async () => {
403
+ run = false;
404
+ armed = false;
405
+ postCount = 0;
406
+ retainedCount = 0;
407
+ start = deferred();
408
+ postsReady = deferred();
409
+ releasePosts = deferred();
410
+ retainedReady = deferred();
411
+ releaseRetained = deferred();
412
+ let ready!: () => void, failed!: (error: unknown) => void;
413
+ const prepared = new Promise<void>((resolve, reject) => {
414
+ ready = resolve;
415
+ failed = reject;
416
+ });
417
+ pending = configureAdmissionFixture(
418
+ async (h) => {
419
+ const first = await prepare(h);
420
+ const child = await h.child();
421
+ const token = await h.core.admitConfigure(
422
+ child.fresh.call,
423
+ child.journal,
424
+ );
425
+ h.configureReads(child);
426
+ await captureAdmittedConfigurePreflight(token).invoke();
427
+ ready();
428
+ await start.promise;
429
+ if (!run) return;
430
+ armed = true;
431
+ const actors = [
432
+ captureAdmittedConfigureWrite(first.token),
433
+ captureAdmittedConfigureWrite(token),
434
+ ];
435
+ const outputs = await Promise.all(
436
+ actors.map((actor) => actor.invoke()),
437
+ );
438
+ expect(outputs.map((output) => object(output).status)).toEqual([
439
+ "configure_acknowledged",
440
+ "configure_acknowledged",
441
+ ]);
442
+ expect(outputs[0] === outputs[1]).toBe(false);
443
+ expect(
444
+ readAdmittedConfigureAcknowledgement(first.token).output ===
445
+ outputs[0],
446
+ ).toBe(true);
447
+ expect(
448
+ readAdmittedConfigureAcknowledgement(token).output === outputs[1],
449
+ ).toBe(true);
450
+ expect(
451
+ posts(h)
452
+ .map((call) => call.idempotencyKey)
453
+ .sort(),
454
+ ).toEqual(
455
+ [
456
+ first.child.record.configureRecord.request.key,
457
+ child.record.configureRecord.request.key,
458
+ ].sort(),
459
+ );
460
+ const retained = await Promise.all([
461
+ first.child.journal.readProviderAcknowledgement(),
462
+ child.journal.readProviderAcknowledgement(),
463
+ ]);
464
+ expect(retained.every((value) => value !== null)).toBe(true);
465
+ expect(retained[0]!.receiptJSON === retained[1]!.receiptJSON).toBe(
466
+ false,
467
+ );
468
+ },
469
+ {
470
+ beforeFetch: async (path, method) => {
471
+ if (
472
+ armed &&
473
+ method === "POST" &&
474
+ path.startsWith("/v1/subscription_schedules/")
475
+ ) {
476
+ if (++postCount === 2) postsReady.resolve();
477
+ await releasePosts.promise;
478
+ }
479
+ },
480
+ afterRetain: async () => {
481
+ if (armed) {
482
+ if (++retainedCount === 2) retainedReady.resolve();
483
+ await releaseRetained.promise;
484
+ }
485
+ },
486
+ },
487
+ );
488
+ void pending.catch(failed);
489
+ await prepared;
490
+ });
491
+ beforeEach(async () => {
492
+ run = true;
493
+ start.resolve();
494
+ await stage(postsReady);
495
+ });
496
+ beforeEach(async () => {
497
+ releasePosts.resolve();
498
+ await stage(retainedReady);
499
+ });
500
+ afterEach(async () => {
501
+ start?.resolve();
502
+ releasePosts?.resolve();
503
+ releaseRetained?.resolve();
504
+ await pending?.catch(() => {});
505
+ });
506
+ it("concurrent children retain separate POST keys, journals and returned outputs", async () => {
507
+ expect(postCount).toBe(2);
508
+ expect(retainedCount).toBe(2);
509
+ releaseRetained.resolve();
510
+ await pending;
511
+ });
512
+ });
513
+
514
+ describe("independent SDK root lifetime", () => {
515
+ let prior: object;
516
+ beforeEach(async () => {
517
+ await configureAdmissionFixture(async (h) => {
518
+ const { token } = await prepare(h);
519
+ prior = token;
520
+ expect(
521
+ object(await captureAdmittedConfigureWrite(token).invoke()).status,
522
+ ).toBe("configure_acknowledged");
523
+ });
524
+ });
525
+ it("retiring one SDK root cannot close a later independent root", async () => {
526
+ await configureAdmissionFixture(async (h) => {
527
+ const { token } = await prepare(h);
528
+ expect(() => readAdmittedConfigureAcknowledgement(prior)).toThrow();
529
+ const output = await captureAdmittedConfigureWrite(token).invoke();
530
+ expect(object(output).status).toBe("configure_acknowledged");
531
+ expect(
532
+ readAdmittedConfigureAcknowledgement(token).output === output,
533
+ ).toBe(true);
534
+ expect(() => readAdmittedConfigureAcknowledgement(prior)).toThrow();
535
+ });
536
+ });
537
+ });
@@ -1,8 +1,9 @@
1
1
  import assert from "node:assert/strict";
2
- import { afterEach, beforeEach, vi } from "vitest";
2
+ import { afterEach, beforeEach, describe, it, vi } from "vitest";
3
3
  import { initialOperations } from "./producerInitialOperation.js";
4
4
  import { makeConfigureReadNativeBaseline } from "./configureReadNativeBaseline.js";
5
5
  import { captureRetainedInput } from "../material/capture.js";
6
+ import { captureAdmittedConfigurePreflight } from "../producer/configurePreflight.js";
6
7
  import { captureInitialInvocationCore } from "../producer/invocationProducer.js";
7
8
  import { createClassActionOperationJournal } from "../operationJournal.js";
8
9
  import { components } from "../../../../../../example/convex/_generated/api.js";
@@ -23,6 +24,10 @@ const controls = vi.hoisted(() => ({
23
24
  originalEntry: unknown;
24
25
  coversPreflight(...args: unknown[]): boolean;
25
26
  }[],
27
+ write: [] as {
28
+ originalEntry: unknown;
29
+ coversConfigure(...args: unknown[]): boolean;
30
+ }[],
26
31
  legacy: 0,
27
32
  selectors: 0,
28
33
  }));
@@ -35,6 +40,11 @@ vi.mock("../operations/sourceOperations.js", () => {
35
40
  COMPILED_INITIAL_ENTRIES: controls.entries,
36
41
  COMPILED_RECOVERY_ENTRIES: controls.recovery,
37
42
  COMPILED_PREFLIGHT_ENTRIES: controls.preflight,
43
+ COMPILED_CONFIGURE_WRITE_ENTRIES: controls.write,
44
+ loadConfigureWriteTransportSource: poison,
45
+ loadConfigureReplayTransportSource: poison,
46
+ loadFixedConfigureWriteOperation: poison,
47
+ loadFixedConfigureReplayOperation: poison,
38
48
  loadOwnedConfigureOperation: poison,
39
49
  loadConfigureOwnedReadTransportSource: poison,
40
50
  ORIGINAL_ORIGIN_ASSOCIATION: null,
@@ -77,6 +87,7 @@ const canonical = (value: unknown) => JSON.stringify(renewalSnapshot(value));
77
87
  beforeEach(() => {
78
88
  controls.legacy = 0;
79
89
  controls.preflight.splice(0);
90
+ controls.write.splice(0);
80
91
  controls.selectors = 0;
81
92
  controls.entries.splice(0, controls.entries.length, {
82
93
  coversRetained: () => true,
@@ -113,6 +124,8 @@ async function setup(
113
124
  path: string;
114
125
  query: string;
115
126
  hasBody: boolean;
127
+ idempotencyKey: string | null;
128
+ apiVersion: string | null;
116
129
  }[] = [];
117
130
  const routes = new Map<string, unknown>([
118
131
  ["/v1/subscriptions/sub_original", source.originalBundle.wireSubscription],
@@ -132,6 +145,8 @@ async function setup(
132
145
  path,
133
146
  query: parsed.search,
134
147
  hasBody: init?.body !== undefined,
148
+ idempotencyKey: new Headers(init?.headers).get("idempotency-key"),
149
+ apiVersion: new Headers(init?.headers).get("stripe-version"),
135
150
  });
136
151
  await hooks.beforeFetch?.(path, method);
137
152
  if (method === "POST") {
@@ -143,7 +158,9 @@ async function setup(
143
158
  assert(body);
144
159
  assert(
145
160
  method === "GET" ||
146
- (method === "POST" && path === "/v1/subscription_schedules"),
161
+ (method === "POST" &&
162
+ (path === "/v1/subscription_schedules" ||
163
+ path === "/v1/subscription_schedules/" + baseline.schedule.id)),
147
164
  );
148
165
  return new Response(JSON.stringify(body), {
149
166
  status: 200,
@@ -362,6 +379,7 @@ export async function configureAdmissionFixture(
362
379
  ) => Promise<void>;
363
380
  afterAppend?: () => Promise<void>;
364
381
  beforeAppend?: () => Promise<void>;
382
+ afterRetain?: () => Promise<void>;
365
383
  beforeFetch?: (path: string, method: string) => Promise<void>;
366
384
  } = {},
367
385
  ) {
@@ -383,6 +401,7 @@ export async function configureAdmissionFixture(
383
401
  afterBind: options.afterBind,
384
402
  afterQuery: options.afterQuery,
385
403
  beforeAppend: options.beforeAppend,
404
+ afterRetain: options.afterRetain,
386
405
  afterAppend: async () => {
387
406
  completion.appends++;
388
407
  if (completion.mode === "resume" && completion.appends === 2)
@@ -398,3 +417,67 @@ export async function configureAdmissionFixture(
398
417
  },
399
418
  );
400
419
  }
420
+
421
+ /** Stage real Action prerequisites separately while joining every test continuation. */
422
+ export function configureAdmissionCase<T>(
423
+ name: string,
424
+ prepare: (h: Awaited<ReturnType<typeof setup>>) => Promise<T>,
425
+ verify: (h: Awaited<ReturnType<typeof setup>>, state: T) => Promise<void>,
426
+ options: Parameters<typeof configureAdmissionFixture>[1] = {},
427
+ ) {
428
+ describe(name, () => {
429
+ let pending: Promise<void>,
430
+ start!: () => void,
431
+ run = false;
432
+ beforeEach(async () => {
433
+ run = false;
434
+ let ready!: () => void, failed!: (error: unknown) => void;
435
+ const prepared = new Promise<void>((resolve, reject) => {
436
+ ready = resolve;
437
+ failed = reject;
438
+ });
439
+ const entered = new Promise<void>((resolve) => {
440
+ start = resolve;
441
+ });
442
+ pending = configureAdmissionFixture(async (h) => {
443
+ const state = await prepare(h);
444
+ ready();
445
+ await entered;
446
+ if (run) await verify(h, state);
447
+ }, options);
448
+ void pending.catch(failed);
449
+ await prepared;
450
+ });
451
+ afterEach(async () => {
452
+ start?.();
453
+ await pending?.catch(() => {});
454
+ });
455
+ it(name, async () => {
456
+ run = true;
457
+ start();
458
+ await pending;
459
+ });
460
+ });
461
+ }
462
+
463
+ /** Actual initial ACK, child admission and completed readonly preflight prerequisites. */
464
+ export async function prepareAdmittedConfigure(
465
+ h: Awaited<ReturnType<typeof setup>>,
466
+ ) {
467
+ await h.complete();
468
+ const child = await h.child();
469
+ const token = await h.core.admitConfigure(child.fresh.call, child.journal);
470
+ const current = h.configureReads(child);
471
+ if (controls.preflight.length === 0)
472
+ controls.preflight.push({
473
+ originalEntry: controls.entries[0],
474
+ coversPreflight: () => true,
475
+ });
476
+ if (controls.write.length === 0)
477
+ controls.write.push({
478
+ originalEntry: controls.entries[0],
479
+ coversConfigure: () => true,
480
+ });
481
+ await captureAdmittedConfigurePreflight(token).invoke();
482
+ return { child, token, current };
483
+ }