@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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +100 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +17 -2
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +46 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +25 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +62 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +14 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +17 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts +30 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +224 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts +61 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js +73 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +47 -4
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +31 -2
- package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +92 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +84 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +16 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +317 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWriteFactory.ts +88 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureWrite.integration.test.ts +158 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureWriteControls.integration.test.ts +537 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +85 -2
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { freeze } from "../material/nodeKernel.js";
|
|
2
|
+
import { closed as closedFields } from "../operations/types.js";
|
|
3
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { createAdmittedConfigureWriteTransport } from "../configure/transport.js";
|
|
6
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
7
|
+
import { createAdmittedConfigureEventCompiler } from "../c10/configureEvents.js";
|
|
8
|
+
import {
|
|
9
|
+
assertConfigurePreflightFrontier,
|
|
10
|
+
assertConfigureWriteFrontier,
|
|
11
|
+
} from "./configureFrontier.js";
|
|
12
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
13
|
+
import { checkConfigureRetention } from "./configureJournalData.js";
|
|
14
|
+
import {
|
|
15
|
+
projectRenewalConfigurationV2,
|
|
16
|
+
constructRenewalScheduleAttachmentReceiptV2,
|
|
17
|
+
constructRenewalConfigurationReceiptV2,
|
|
18
|
+
} from "../../../renewalV2/index.js";
|
|
19
|
+
import {
|
|
20
|
+
verifyPreflightRecordDATA,
|
|
21
|
+
verifyCurrentPreflightDATA,
|
|
22
|
+
} from "../preflight/relations.js";
|
|
23
|
+
import { releasePreflightDATA } from "../preflight/output.js";
|
|
24
|
+
import {
|
|
25
|
+
admitConfigureACK,
|
|
26
|
+
admitConfigureFailure,
|
|
27
|
+
configureControl,
|
|
28
|
+
} from "../configure/output.js";
|
|
29
|
+
import { need, seven, stop } from "../configure/request.js";
|
|
30
|
+
import { equal } from "../../../renewalAggregate/shared.js";
|
|
31
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
32
|
+
import type { Bundle } from "../material/capture.js";
|
|
33
|
+
import type { PreflightRecord } from "../preflight/grammar.js";
|
|
34
|
+
|
|
35
|
+
function matchesCurrentBundle(
|
|
36
|
+
value: unknown,
|
|
37
|
+
record: PreflightRecord,
|
|
38
|
+
): value is Bundle {
|
|
39
|
+
return equal(value, {
|
|
40
|
+
...record.originalBundle,
|
|
41
|
+
wireSubscription: record.configuration.freshSubscription,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
type Pair = ReturnType<typeof createAdmittedConfigureWriteTransport>;
|
|
45
|
+
type ACK = ReturnType<typeof admitConfigureACK>;
|
|
46
|
+
type Completion = Readonly<{
|
|
47
|
+
output: ACK;
|
|
48
|
+
receipt: unknown;
|
|
49
|
+
rawReceipt: unknown;
|
|
50
|
+
acknowledgement: Pair["preflight"]["acknowledgement"];
|
|
51
|
+
originalEntry: unknown;
|
|
52
|
+
configureEntry: unknown;
|
|
53
|
+
coversConfigure: unknown;
|
|
54
|
+
operationalAuthority: false;
|
|
55
|
+
}>;
|
|
56
|
+
type Attempt = { pair: Pair; receipt: unknown; rawReceipt: unknown };
|
|
57
|
+
const attempts = new WeakMap<object, Attempt>();
|
|
58
|
+
const completions = new WeakMap<
|
|
59
|
+
object,
|
|
60
|
+
{ view: Completion; guard: () => void }
|
|
61
|
+
>();
|
|
62
|
+
/** One fixed initial configure attempt. No replay, caller frame or output registration. */
|
|
63
|
+
export function captureAdmittedConfigureWrite(token: object) {
|
|
64
|
+
const pair = createAdmittedConfigureWriteTransport(token);
|
|
65
|
+
need(arguments.length === 1);
|
|
66
|
+
const attempt: Attempt = { pair, receipt: null, rawReceipt: null };
|
|
67
|
+
attempts.set(token, attempt);
|
|
68
|
+
const lineage = readConfigureLineage(token),
|
|
69
|
+
owned = ownedAwaitForInitialLineage(lineage.parentToken);
|
|
70
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
71
|
+
work = journalWorkForConfigureLineage(token);
|
|
72
|
+
let used = false,
|
|
73
|
+
closed = false,
|
|
74
|
+
receiptKnown = false;
|
|
75
|
+
function guard() {
|
|
76
|
+
need(!closed);
|
|
77
|
+
pair.guard();
|
|
78
|
+
}
|
|
79
|
+
async function checked<T>(call: () => T | PromiseLike<T>) {
|
|
80
|
+
guard();
|
|
81
|
+
const result = await owned(call);
|
|
82
|
+
guard();
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
function providerFailure(
|
|
86
|
+
fact: NonNullable<ReturnType<Pair["capability"]["consumeReadCatch"]>>,
|
|
87
|
+
) {
|
|
88
|
+
const failure = admitConfigureFailure(
|
|
89
|
+
fact.phase,
|
|
90
|
+
fact.resource,
|
|
91
|
+
fact.ordinal,
|
|
92
|
+
pair.record.request,
|
|
93
|
+
fact.diagnostics,
|
|
94
|
+
);
|
|
95
|
+
const error = Error("OWNED_CONFIGURE_PROVIDER_REJECTED");
|
|
96
|
+
Object.defineProperty(error, "failure", { value: failure });
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
return Object.freeze({
|
|
100
|
+
async invoke() {
|
|
101
|
+
need(!used);
|
|
102
|
+
used = true;
|
|
103
|
+
need(arguments.length === 0);
|
|
104
|
+
let actualError: Error | null = null;
|
|
105
|
+
try {
|
|
106
|
+
guard();
|
|
107
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
108
|
+
const original = await checked(() =>
|
|
109
|
+
projectRenewalConfigurationV2(pair.record.configuration),
|
|
110
|
+
);
|
|
111
|
+
need(original.status === "projected_configure_request");
|
|
112
|
+
const attachment = await checked(() =>
|
|
113
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
114
|
+
pair.record.configuration.attachReceipt,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
const record = verifyPreflightRecordDATA(
|
|
118
|
+
pair.retained,
|
|
119
|
+
original,
|
|
120
|
+
attachment,
|
|
121
|
+
);
|
|
122
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
123
|
+
const reader = createSelectedRawAcquisition(
|
|
124
|
+
pair.owner,
|
|
125
|
+
pair.transport.readTransport,
|
|
126
|
+
attachment.scheduleId,
|
|
127
|
+
);
|
|
128
|
+
const acquired = await checked(() =>
|
|
129
|
+
reader.acquire(record.configuration.preparation.expected),
|
|
130
|
+
);
|
|
131
|
+
if (!acquired.ok) {
|
|
132
|
+
const fact = pair.capability.consumeReadCatch();
|
|
133
|
+
if (fact) {
|
|
134
|
+
actualError = providerFailure(fact);
|
|
135
|
+
throw actualError;
|
|
136
|
+
}
|
|
137
|
+
return stop();
|
|
138
|
+
}
|
|
139
|
+
if (!matchesCurrentBundle(acquired.bundle, record))
|
|
140
|
+
return configureControl(
|
|
141
|
+
"not_dispatched",
|
|
142
|
+
"preconfigure_baseline_changed",
|
|
143
|
+
);
|
|
144
|
+
const evidence = Object.freeze({
|
|
145
|
+
bundle: acquired.bundle,
|
|
146
|
+
schedule: acquired.schedule,
|
|
147
|
+
observedAt: acquired.observedAt,
|
|
148
|
+
});
|
|
149
|
+
verifyCurrentPreflightDATA(record, evidence);
|
|
150
|
+
const fresh = await checked(() =>
|
|
151
|
+
projectRenewalConfigurationV2({
|
|
152
|
+
...record.configuration,
|
|
153
|
+
freshSubscription: evidence.bundle.wireSubscription,
|
|
154
|
+
targetPrice: evidence.bundle.wireTargetPrice,
|
|
155
|
+
...(Object.prototype.hasOwnProperty.call(
|
|
156
|
+
record.configuration,
|
|
157
|
+
"billingCustomer",
|
|
158
|
+
)
|
|
159
|
+
? { billingCustomer: evidence.bundle.wireBillingCustomer }
|
|
160
|
+
: {}),
|
|
161
|
+
schedule: evidence.schedule,
|
|
162
|
+
observedAt: evidence.observedAt,
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
need(
|
|
166
|
+
fresh.status === "projected_configure_request" &&
|
|
167
|
+
equal(fresh, original) &&
|
|
168
|
+
equal(fresh, record.request),
|
|
169
|
+
);
|
|
170
|
+
need(
|
|
171
|
+
Reflect.apply(pair.covers, pair.entry, [record, evidence, fresh]) ===
|
|
172
|
+
true,
|
|
173
|
+
);
|
|
174
|
+
guard();
|
|
175
|
+
releasePreflightDATA(record, evidence, fresh, original, attachment);
|
|
176
|
+
await checked(() => assertConfigurePreflightFrontier(token));
|
|
177
|
+
const dispatch = {
|
|
178
|
+
event: "dispatch",
|
|
179
|
+
stage: "configure",
|
|
180
|
+
request: original,
|
|
181
|
+
};
|
|
182
|
+
await checked(() => compiler.dispatch(dispatch));
|
|
183
|
+
await checked(() => assertConfigureWriteFrontier(token, [dispatch]));
|
|
184
|
+
const reply = await checked(() => pair.transport.postConfigure());
|
|
185
|
+
if (pair.capability.consumeNotStarted(reply))
|
|
186
|
+
return configureControl("not_dispatched", "post_not_started");
|
|
187
|
+
const fact = pair.capability.consumePostCatch(reply);
|
|
188
|
+
if (fact) {
|
|
189
|
+
actualError = providerFailure(fact);
|
|
190
|
+
throw actualError;
|
|
191
|
+
}
|
|
192
|
+
if (reply.outcome !== "fulfilled_safe")
|
|
193
|
+
return configureControl("configure_unknown", "post_unverified");
|
|
194
|
+
const response = {
|
|
195
|
+
event: "response",
|
|
196
|
+
stage: "configure",
|
|
197
|
+
request: original,
|
|
198
|
+
body: reply.body,
|
|
199
|
+
transport: reply.transport,
|
|
200
|
+
};
|
|
201
|
+
await checked(() => compiler.response(response));
|
|
202
|
+
const rawReceipt = Object.freeze({
|
|
203
|
+
configuration: record.configuration,
|
|
204
|
+
actualDispatch: seven(original),
|
|
205
|
+
providerSnapshot: reply.body,
|
|
206
|
+
transport: reply.transport,
|
|
207
|
+
});
|
|
208
|
+
const receipt = await checked(() =>
|
|
209
|
+
constructRenewalConfigurationReceiptV2(rawReceipt),
|
|
210
|
+
);
|
|
211
|
+
// Known receipt closes this once-only attempt before output admission or persistence.
|
|
212
|
+
receiptKnown = true;
|
|
213
|
+
attempt.receipt = freeze(receipt);
|
|
214
|
+
attempt.rawReceipt = freeze(rawReceipt);
|
|
215
|
+
guard();
|
|
216
|
+
const events = await checked(() =>
|
|
217
|
+
assertConfigureWriteFrontier(token, [dispatch, response]),
|
|
218
|
+
);
|
|
219
|
+
const receiptJSON = JSON.stringify(renewalSnapshot(receipt));
|
|
220
|
+
const retained: unknown = await checked(() => work.retain(receiptJSON));
|
|
221
|
+
const retention = checkConfigureRetention(
|
|
222
|
+
retained,
|
|
223
|
+
lineage.reservation,
|
|
224
|
+
events,
|
|
225
|
+
receipt.binding,
|
|
226
|
+
);
|
|
227
|
+
const known = {
|
|
228
|
+
receiptJSON,
|
|
229
|
+
receiptBinding: receipt.binding,
|
|
230
|
+
retention,
|
|
231
|
+
};
|
|
232
|
+
await checked(() =>
|
|
233
|
+
assertConfigureWriteFrontier(token, [dispatch, response], known),
|
|
234
|
+
);
|
|
235
|
+
const output = admitConfigureACK(record, rawReceipt, receipt);
|
|
236
|
+
const returned = closedFields(output, [
|
|
237
|
+
"status",
|
|
238
|
+
"originalRecord",
|
|
239
|
+
"rawReceipt",
|
|
240
|
+
"receipt",
|
|
241
|
+
"operationalAuthority",
|
|
242
|
+
]);
|
|
243
|
+
const published = {
|
|
244
|
+
event: "receipt",
|
|
245
|
+
stage: "configure",
|
|
246
|
+
request: original,
|
|
247
|
+
receipt,
|
|
248
|
+
};
|
|
249
|
+
await checked(() => compiler.receipt(published));
|
|
250
|
+
await checked(() =>
|
|
251
|
+
assertConfigureWriteFrontier(
|
|
252
|
+
token,
|
|
253
|
+
[dispatch, response, published],
|
|
254
|
+
known,
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
const view: Completion = Object.freeze({
|
|
258
|
+
output,
|
|
259
|
+
receipt: returned.receipt,
|
|
260
|
+
rawReceipt: returned.rawReceipt,
|
|
261
|
+
acknowledgement: pair.preflight.acknowledgement,
|
|
262
|
+
originalEntry: pair.preflight.originalEntry,
|
|
263
|
+
configureEntry: pair.entry,
|
|
264
|
+
coversConfigure: pair.covers,
|
|
265
|
+
operationalAuthority: false,
|
|
266
|
+
});
|
|
267
|
+
guard();
|
|
268
|
+
// No callback, reflection or Owner sample follows the final gate before discard.
|
|
269
|
+
pair.capability.discardFulfilledQuarantine();
|
|
270
|
+
completions.set(token, { view, guard });
|
|
271
|
+
return output;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
let live = false;
|
|
274
|
+
try {
|
|
275
|
+
guard();
|
|
276
|
+
live = true;
|
|
277
|
+
} catch {
|
|
278
|
+
/* No reflection on provider data after closure. */
|
|
279
|
+
}
|
|
280
|
+
closed = true;
|
|
281
|
+
if (live && actualError === error) throw error;
|
|
282
|
+
if (pair.transport.postDisposition() !== "NOT_STARTED" || receiptKnown)
|
|
283
|
+
return configureControl(
|
|
284
|
+
"configure_unknown",
|
|
285
|
+
live ? "post_unverified" : "owner_closed_after_post",
|
|
286
|
+
);
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/** Actual returned ACK custody only, without accepting any copied receipt or output. */
|
|
293
|
+
export function readAdmittedConfigureAcknowledgement(token: object) {
|
|
294
|
+
need(arguments.length === 1);
|
|
295
|
+
const completed = completions.get(token);
|
|
296
|
+
need(completed);
|
|
297
|
+
completed.guard();
|
|
298
|
+
return completed.view;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Private live attempt DATA, never an ACK registration or replay grant. */
|
|
302
|
+
export function readAdmittedConfigureWriteAttempt(token: object) {
|
|
303
|
+
need(arguments.length === 1);
|
|
304
|
+
const attempt = attempts.get(token);
|
|
305
|
+
need(attempt);
|
|
306
|
+
attempt.pair.guard();
|
|
307
|
+
const view = Object.freeze({
|
|
308
|
+
postDisposition: attempt.pair.transport.postDisposition(),
|
|
309
|
+
receiptKnown: attempt.receipt !== null,
|
|
310
|
+
receipt: attempt.receipt,
|
|
311
|
+
rawReceipt: attempt.rawReceipt,
|
|
312
|
+
returned: completions.has(token),
|
|
313
|
+
operationalAuthority: false as const,
|
|
314
|
+
});
|
|
315
|
+
attempt.pair.guard();
|
|
316
|
+
return view;
|
|
317
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { COMPILED_CONFIGURE_WRITE_ENTRIES } from "../operations/sourceOperations.js";
|
|
3
|
+
import { closed } from "../operations/types.js";
|
|
4
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
5
|
+
import { readAdmittedConfigurePreflight } from "./configurePreflight.js";
|
|
6
|
+
import { captureInitialStockRawDelegate } from "./stockDelegateFactory.js";
|
|
7
|
+
import { capturePreflightRecordDATA } from "../preflight/record.js";
|
|
8
|
+
import { expectedPlan, need, ownMethod } from "../configure/request.js";
|
|
9
|
+
|
|
10
|
+
const captures = new WeakSet<object>();
|
|
11
|
+
/** Derive a fixed write frame from actual completed readonly custody. */
|
|
12
|
+
export function captureAdmittedConfigureWriteFrame(
|
|
13
|
+
token: object,
|
|
14
|
+
arity: number,
|
|
15
|
+
) {
|
|
16
|
+
need(typeof token === "object" && token !== null && !captures.has(token));
|
|
17
|
+
captures.add(token);
|
|
18
|
+
need(arity === 1);
|
|
19
|
+
const lineage = readConfigureLineage(token);
|
|
20
|
+
const preflight = readAdmittedConfigurePreflight(token);
|
|
21
|
+
need(
|
|
22
|
+
!types.isProxy(COMPILED_CONFIGURE_WRITE_ENTRIES) &&
|
|
23
|
+
Array.isArray(COMPILED_CONFIGURE_WRITE_ENTRIES),
|
|
24
|
+
);
|
|
25
|
+
const candidates = COMPILED_CONFIGURE_WRITE_ENTRIES.filter((entry) => {
|
|
26
|
+
const fields = closed(entry, ["originalEntry", "coversConfigure"]);
|
|
27
|
+
ownMethod(entry, "coversConfigure");
|
|
28
|
+
return fields.originalEntry === preflight.originalEntry;
|
|
29
|
+
});
|
|
30
|
+
need(candidates.length === 1);
|
|
31
|
+
const entry = candidates[0],
|
|
32
|
+
covers = ownMethod(entry, "coversConfigure");
|
|
33
|
+
const record = preflight.output.originalRecord;
|
|
34
|
+
const retained = capturePreflightRecordDATA(record);
|
|
35
|
+
let closedFrame = false;
|
|
36
|
+
function guard() {
|
|
37
|
+
need(!closedFrame);
|
|
38
|
+
try {
|
|
39
|
+
const current = readConfigureLineage(token);
|
|
40
|
+
need(
|
|
41
|
+
current.owner === lineage.owner &&
|
|
42
|
+
current.originalReservation === lineage.originalReservation &&
|
|
43
|
+
current.journal === lineage.journal,
|
|
44
|
+
);
|
|
45
|
+
need(readAdmittedConfigurePreflight(token) === preflight);
|
|
46
|
+
need(
|
|
47
|
+
!types.isProxy(COMPILED_CONFIGURE_WRITE_ENTRIES) &&
|
|
48
|
+
Array.isArray(COMPILED_CONFIGURE_WRITE_ENTRIES) &&
|
|
49
|
+
COMPILED_CONFIGURE_WRITE_ENTRIES.includes(entry),
|
|
50
|
+
);
|
|
51
|
+
const fields = closed(entry, ["originalEntry", "coversConfigure"]);
|
|
52
|
+
need(
|
|
53
|
+
fields.originalEntry === preflight.originalEntry &&
|
|
54
|
+
fields.coversConfigure === covers &&
|
|
55
|
+
!types.isProxy(covers),
|
|
56
|
+
);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
closedFrame = true;
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
guard();
|
|
63
|
+
const delegate = captureInitialStockRawDelegate(lineage.parentToken);
|
|
64
|
+
const expected = expectedPlan(record);
|
|
65
|
+
const readPlan = Object.freeze(
|
|
66
|
+
expected.map(({ resource, ordinal, method, path, body, options }) =>
|
|
67
|
+
Object.freeze({ resource, ordinal, method, path, body, options }),
|
|
68
|
+
),
|
|
69
|
+
);
|
|
70
|
+
const frame = Object.freeze({
|
|
71
|
+
owner: lineage.owner,
|
|
72
|
+
operation: token,
|
|
73
|
+
request: record.request,
|
|
74
|
+
readPlan,
|
|
75
|
+
delegate,
|
|
76
|
+
});
|
|
77
|
+
return Object.freeze({
|
|
78
|
+
frame,
|
|
79
|
+
expected,
|
|
80
|
+
owner: lineage.owner,
|
|
81
|
+
guard,
|
|
82
|
+
record,
|
|
83
|
+
retained,
|
|
84
|
+
preflight,
|
|
85
|
+
entry,
|
|
86
|
+
covers,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { object } from "./configureJournalData.js";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
configureAdmissionFixture,
|
|
5
|
+
admissionControls,
|
|
6
|
+
configureAdmissionCase,
|
|
7
|
+
prepareAdmittedConfigure,
|
|
8
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
9
|
+
import { captureAdmittedConfigurePreflight } from "./configurePreflight.js";
|
|
10
|
+
import {
|
|
11
|
+
captureAdmittedConfigureWrite,
|
|
12
|
+
readAdmittedConfigureAcknowledgement,
|
|
13
|
+
readAdmittedConfigureWriteAttempt,
|
|
14
|
+
} from "./configureWrite.js";
|
|
15
|
+
|
|
16
|
+
configureAdmissionCase(
|
|
17
|
+
"commits dispatch, one exact configure POST, retained C9 and receipt publication before returning ACK custody",
|
|
18
|
+
prepareAdmittedConfigure,
|
|
19
|
+
async (h, { child, token }) => {
|
|
20
|
+
const before = h.calls.length;
|
|
21
|
+
const actor = captureAdmittedConfigureWrite(token);
|
|
22
|
+
expect(actor).not.toBeNull();
|
|
23
|
+
const output = await actor!.invoke();
|
|
24
|
+
expect(object(output).status).toBe("configure_acknowledged");
|
|
25
|
+
const view = readAdmittedConfigureAcknowledgement(token);
|
|
26
|
+
expect(view!.output === output).toBe(true);
|
|
27
|
+
expect(view!.receipt === object(output).receipt).toBe(true);
|
|
28
|
+
expect(view!.rawReceipt === object(output).rawReceipt).toBe(true);
|
|
29
|
+
expect(view!.acknowledgement === h.core.attachAcknowledgement()).toBe(true);
|
|
30
|
+
const calls = h.calls.slice(before);
|
|
31
|
+
expect(calls.filter((call) => call.method === "GET")).toHaveLength(6);
|
|
32
|
+
expect(calls.filter((call) => call.method === "POST")).toEqual([
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
path: child.record.configureRecord.request.path,
|
|
35
|
+
idempotencyKey: child.record.configureRecord.request.key,
|
|
36
|
+
apiVersion: "2026-09-30.endive",
|
|
37
|
+
}),
|
|
38
|
+
]);
|
|
39
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
40
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
41
|
+
const history = await child.journal.readAttempt({
|
|
42
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
43
|
+
});
|
|
44
|
+
expect(history!.events.map((event) => event.sequence)).toEqual([1, 2, 3]);
|
|
45
|
+
const retained = await child.journal.readProviderAcknowledgement();
|
|
46
|
+
expect(retained).not.toBeNull();
|
|
47
|
+
expect(JSON.parse(retained!.receiptJSON)).toEqual(object(output).receipt);
|
|
48
|
+
expect(admissionControls.legacy).toBe(0);
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
function deferred() {
|
|
53
|
+
let resolve!: () => void;
|
|
54
|
+
const promise = new Promise<void>((done) => {
|
|
55
|
+
resolve = done;
|
|
56
|
+
});
|
|
57
|
+
return { promise, resolve };
|
|
58
|
+
}
|
|
59
|
+
describe("known C9 with oversized whole output", () => {
|
|
60
|
+
let pending: Promise<void>,
|
|
61
|
+
start: ReturnType<typeof deferred>,
|
|
62
|
+
postReady: ReturnType<typeof deferred>,
|
|
63
|
+
releasePost: ReturnType<typeof deferred>,
|
|
64
|
+
run = false,
|
|
65
|
+
armed = false;
|
|
66
|
+
beforeEach(async () => {
|
|
67
|
+
run = false;
|
|
68
|
+
armed = false;
|
|
69
|
+
start = deferred();
|
|
70
|
+
postReady = deferred();
|
|
71
|
+
releasePost = deferred();
|
|
72
|
+
let ready!: () => void, failed!: (error: unknown) => void;
|
|
73
|
+
const prepared = new Promise<void>((resolve, reject) => {
|
|
74
|
+
ready = resolve;
|
|
75
|
+
failed = reject;
|
|
76
|
+
});
|
|
77
|
+
pending = configureAdmissionFixture(
|
|
78
|
+
async (h) => {
|
|
79
|
+
await h.complete();
|
|
80
|
+
const child = await h.child();
|
|
81
|
+
const token = await h.core.admitConfigure(
|
|
82
|
+
child.fresh.call,
|
|
83
|
+
child.journal,
|
|
84
|
+
);
|
|
85
|
+
h.configureReads(child);
|
|
86
|
+
admissionControls.preflight.push({
|
|
87
|
+
originalEntry: admissionControls.entries[0],
|
|
88
|
+
coversPreflight: () => true,
|
|
89
|
+
});
|
|
90
|
+
admissionControls.write.push({
|
|
91
|
+
originalEntry: admissionControls.entries[0],
|
|
92
|
+
coversConfigure: () => true,
|
|
93
|
+
});
|
|
94
|
+
await captureAdmittedConfigurePreflight(token).invoke();
|
|
95
|
+
Reflect.set(h.baseline.schedule, "padding", "x".repeat(300000));
|
|
96
|
+
ready();
|
|
97
|
+
await start.promise;
|
|
98
|
+
if (!run) return;
|
|
99
|
+
armed = true;
|
|
100
|
+
const actor = captureAdmittedConfigureWrite(token);
|
|
101
|
+
expect(object(await actor.invoke()).status).toBe("configure_unknown");
|
|
102
|
+
expect(
|
|
103
|
+
await child.journal.readProviderAcknowledgement(),
|
|
104
|
+
).not.toBeNull();
|
|
105
|
+
const attempt = readAdmittedConfigureWriteAttempt(token);
|
|
106
|
+
expect(attempt).not.toBeNull();
|
|
107
|
+
expect(attempt!.receiptKnown).toBe(true);
|
|
108
|
+
expect(Object.isFrozen(attempt!.receipt)).toBe(true);
|
|
109
|
+
expect(Object.isFrozen(attempt!.rawReceipt)).toBe(true);
|
|
110
|
+
expect(attempt!.receipt).not.toBeNull();
|
|
111
|
+
expect(attempt!.rawReceipt).not.toBeNull();
|
|
112
|
+
expect(attempt!.returned).toBe(false);
|
|
113
|
+
expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
|
|
114
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
115
|
+
expect(
|
|
116
|
+
h.calls.filter(
|
|
117
|
+
(call) =>
|
|
118
|
+
call.method === "POST" &&
|
|
119
|
+
call.path === child.record.configureRecord.request.path,
|
|
120
|
+
),
|
|
121
|
+
).toHaveLength(1);
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
beforeFetch: async (path, method) => {
|
|
125
|
+
if (
|
|
126
|
+
armed &&
|
|
127
|
+
method === "POST" &&
|
|
128
|
+
path.startsWith("/v1/subscription_schedules/")
|
|
129
|
+
) {
|
|
130
|
+
postReady.resolve();
|
|
131
|
+
await releasePost.promise;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
void pending.catch(failed);
|
|
137
|
+
await prepared;
|
|
138
|
+
});
|
|
139
|
+
beforeEach(async () => {
|
|
140
|
+
run = true;
|
|
141
|
+
start.resolve();
|
|
142
|
+
await Promise.race([
|
|
143
|
+
postReady.promise,
|
|
144
|
+
pending.then(() => {
|
|
145
|
+
throw Error("FIXTURE_SETTLED_BEFORE_POST");
|
|
146
|
+
}),
|
|
147
|
+
]);
|
|
148
|
+
});
|
|
149
|
+
afterEach(async () => {
|
|
150
|
+
start?.resolve();
|
|
151
|
+
releasePost?.resolve();
|
|
152
|
+
await pending?.catch(() => {});
|
|
153
|
+
});
|
|
154
|
+
it("durably retains actual C9 even when whole-output admission fails", async () => {
|
|
155
|
+
releasePost.resolve();
|
|
156
|
+
await pending;
|
|
157
|
+
});
|
|
158
|
+
});
|