@fantastic.dev/better-stripe 0.93.0 → 0.95.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 +12 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts +47 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js +388 -0
- package/dist/client/billing/renewalAttach/internal/operationJournal.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +24 -5
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +182 -4
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +13 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +43 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +32 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +105 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js +59 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts +11 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +121 -0
- package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/stockDelegateFactory.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +57 -5
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/operationJournal.acknowledgement.integration.test.ts +500 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.c10.integration.test.ts +560 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.controls.integration.test.ts +356 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +181 -1
- package/src/client/billing/renewalAttach/internal/operationJournal.methods.integration.test.ts +534 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.ts +573 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +246 -8
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +58 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +161 -0
- package/src/client/billing/renewalAttach/internal/producer/ownedAwaitFactory.ts +54 -0
- package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +124 -0
- package/src/client/billing/renewalAttach/internal/producer/producerGuards.integration.test.ts +323 -0
- package/src/client/billing/renewalAttach/internal/producer/producerInitial.integration.test.ts +301 -0
- package/src/client/billing/renewalAttach/internal/producer/producerIsolation.integration.test.ts +531 -0
- package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +457 -0
- package/src/client/billing/renewalAttach/internal/producer/stockDelegateFactory.ts +23 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialDeclarations.ts +5 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +80 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { components } from "../../../../../example/convex/_generated/api.js";
|
|
3
|
+
import { createActionOperationJournal } from "./operationJournal.js";
|
|
4
|
+
import { convexTest } from "convex-test";
|
|
5
|
+
import {
|
|
6
|
+
actionGeneric,
|
|
7
|
+
componentsGeneric,
|
|
8
|
+
defineSchema,
|
|
9
|
+
makeFunctionReference,
|
|
10
|
+
} from "convex/server";
|
|
11
|
+
import { getConvexSize, getDocumentSize, v } from "convex/values";
|
|
12
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
13
|
+
import { modules, schema } from "../../../../test.js";
|
|
14
|
+
import { query } from "../../../../component/_generated/server.js";
|
|
15
|
+
import type { Doc } from "../../../../component/_generated/dataModel.js";
|
|
16
|
+
import {
|
|
17
|
+
canonical,
|
|
18
|
+
codecFixture,
|
|
19
|
+
VALUE_LIMIT,
|
|
20
|
+
} from "../../../../component/renewalOperations/timingPolicy.fixtures.js";
|
|
21
|
+
import { canonicalJournalEvent } from "../../../../shared/renewalOperationJournal.js";
|
|
22
|
+
|
|
23
|
+
const refs = components.betterStripe.renewalOperations;
|
|
24
|
+
const inspectionRefs = componentsGeneric();
|
|
25
|
+
const call = makeFunctionReference<"action", { operationId: string }, null>(
|
|
26
|
+
"adapterC10:run",
|
|
27
|
+
);
|
|
28
|
+
const parentStop = "ADAPTER_C10_PARENT_STOP_AFTER_ACK";
|
|
29
|
+
const cases = [
|
|
30
|
+
{
|
|
31
|
+
name: "C10SEND01 ACK readback and committed event survive parent Action failure",
|
|
32
|
+
sequence: 1,
|
|
33
|
+
pending: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "C10SEND02 real append rejection never ACKs",
|
|
37
|
+
sequence: 2,
|
|
38
|
+
pending: false,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "C10SEND03 real pending append cannot ACK",
|
|
42
|
+
sequence: 1,
|
|
43
|
+
pending: true,
|
|
44
|
+
},
|
|
45
|
+
] as const;
|
|
46
|
+
const basis = {
|
|
47
|
+
startWallMs: 1700000001000,
|
|
48
|
+
startNsDecimal: "1000000000",
|
|
49
|
+
workEndWallMs: 1700000005000,
|
|
50
|
+
workEndNsDecimal: "5000000000",
|
|
51
|
+
endWallMs: 1700000006000,
|
|
52
|
+
endNsDecimal: "6000000000",
|
|
53
|
+
};
|
|
54
|
+
type Physical = {
|
|
55
|
+
operations: Doc<"renewalOperations">[];
|
|
56
|
+
attempts: Doc<"renewalOperationAttempts">[];
|
|
57
|
+
events: Doc<"renewalOperationEvents">[];
|
|
58
|
+
payloads: Doc<"renewalOperationPayloads">[];
|
|
59
|
+
};
|
|
60
|
+
const inspection = {
|
|
61
|
+
physical: query({
|
|
62
|
+
args: {},
|
|
63
|
+
handler: async (ctx): Promise<Physical> => ({
|
|
64
|
+
operations: await ctx.db.query("renewalOperations").take(3),
|
|
65
|
+
attempts: await ctx.db.query("renewalOperationAttempts").take(3),
|
|
66
|
+
events: await ctx.db.query("renewalOperationEvents").take(4),
|
|
67
|
+
payloads: await ctx.db.query("renewalOperationPayloads").take(5),
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
function measure(state: Physical) {
|
|
72
|
+
expect(getConvexSize(state)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
73
|
+
for (const rows of Object.values(state))
|
|
74
|
+
for (const row of rows)
|
|
75
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
76
|
+
}
|
|
77
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
78
|
+
|
|
79
|
+
it.each(cases)("$name", async (scenario) => {
|
|
80
|
+
// Finite unsigned DATA, not an Owner-qualified typed C10 producer capture.
|
|
81
|
+
// All event/basis choices precede real constructors and transactions.
|
|
82
|
+
const data = Object.freeze({
|
|
83
|
+
future: Object.freeze([null, "retained", 1.25]),
|
|
84
|
+
});
|
|
85
|
+
const event = await canonicalJournalEvent(scenario.sequence, canonical(data));
|
|
86
|
+
const record = Object.freeze({
|
|
87
|
+
sequence: scenario.sequence,
|
|
88
|
+
binding: event.binding,
|
|
89
|
+
data,
|
|
90
|
+
});
|
|
91
|
+
const expectedHashBytes = new TextEncoder().encode(
|
|
92
|
+
JSON.stringify([
|
|
93
|
+
"betterstripe-renewal-binding",
|
|
94
|
+
2,
|
|
95
|
+
"unbound-qualification-event",
|
|
96
|
+
{ data: { future: [null, "retained", 1.25] }, sequence: 1 },
|
|
97
|
+
]),
|
|
98
|
+
);
|
|
99
|
+
let markEntered!: () => void;
|
|
100
|
+
let releaseLatch!: () => void;
|
|
101
|
+
const entered = new Promise<void>((resolve) => {
|
|
102
|
+
markEntered = resolve;
|
|
103
|
+
});
|
|
104
|
+
const releaseGate = new Promise<void>((resolve) => {
|
|
105
|
+
releaseLatch = resolve;
|
|
106
|
+
});
|
|
107
|
+
const nativeCalls: Promise<ArrayBuffer>[] = [];
|
|
108
|
+
const forwardedCalls: Promise<ArrayBuffer>[] = [];
|
|
109
|
+
const sendObservers: Promise<void>[] = [];
|
|
110
|
+
const pending = {
|
|
111
|
+
matches: 0,
|
|
112
|
+
nativeFulfilled: false,
|
|
113
|
+
released: false,
|
|
114
|
+
sendSettled: false,
|
|
115
|
+
};
|
|
116
|
+
const release = () => {
|
|
117
|
+
pending.released = true;
|
|
118
|
+
releaseLatch();
|
|
119
|
+
};
|
|
120
|
+
let restoreDigest: () => void = () => undefined;
|
|
121
|
+
const h = await codecFixture();
|
|
122
|
+
const acks: unknown[] = [];
|
|
123
|
+
const ackReads: Promise<Physical>[] = [];
|
|
124
|
+
const progress = { prepared: 0, reserved: 0, bound: 0, target: 0, sent: 0 };
|
|
125
|
+
let beforeTarget: Physical | null = null;
|
|
126
|
+
let checkedCommitted: Physical | null = null;
|
|
127
|
+
const host = {
|
|
128
|
+
run: actionGeneric({
|
|
129
|
+
args: { operationId: v.string() },
|
|
130
|
+
handler: async (ctx, args) => {
|
|
131
|
+
expect(await ctx.meta.getFunctionMetadata()).toEqual({
|
|
132
|
+
name: "adapterC10:run",
|
|
133
|
+
componentPath: "",
|
|
134
|
+
type: "action",
|
|
135
|
+
visibility: "public",
|
|
136
|
+
});
|
|
137
|
+
const prepared = await ctx.runQuery(
|
|
138
|
+
refs.queries.loadAuthorizedOperation,
|
|
139
|
+
args,
|
|
140
|
+
);
|
|
141
|
+
expect(prepared).toEqual({
|
|
142
|
+
recordVersion: 2,
|
|
143
|
+
...args,
|
|
144
|
+
recordJSON: h.recordJSON,
|
|
145
|
+
revision: 0,
|
|
146
|
+
activeAttempt: null,
|
|
147
|
+
initialBasis: null,
|
|
148
|
+
});
|
|
149
|
+
progress.prepared++;
|
|
150
|
+
const journal = await createActionOperationJournal(
|
|
151
|
+
ctx,
|
|
152
|
+
components.betterStripe,
|
|
153
|
+
args.operationId,
|
|
154
|
+
);
|
|
155
|
+
const reserveInput = {
|
|
156
|
+
expectedRevision: 0,
|
|
157
|
+
stage: "attach" as const,
|
|
158
|
+
expectedRequestBinding: h.record.requestBinding,
|
|
159
|
+
recordJSON: h.recordJSON,
|
|
160
|
+
};
|
|
161
|
+
expect(getConvexSize({ ...args, ...reserveInput })).toBeLessThanOrEqual(
|
|
162
|
+
VALUE_LIMIT,
|
|
163
|
+
);
|
|
164
|
+
const acquired = await journal.reserveAttempt(reserveInput);
|
|
165
|
+
assert(acquired && acquired.disposition === "acquired");
|
|
166
|
+
const reservation = acquired.reservation;
|
|
167
|
+
assert(
|
|
168
|
+
"recordVersion" in reservation && reservation.recordVersion === 2,
|
|
169
|
+
);
|
|
170
|
+
const reserved = await ctx.runQuery(
|
|
171
|
+
inspectionRefs.betterStripe.adapterC10Inspection.physical,
|
|
172
|
+
{},
|
|
173
|
+
);
|
|
174
|
+
expect(reserved.operations).toHaveLength(1);
|
|
175
|
+
expect(reserved.attempts).toHaveLength(1);
|
|
176
|
+
expect(reserved.events).toHaveLength(0);
|
|
177
|
+
expect(reserved.payloads).toHaveLength(1);
|
|
178
|
+
expect(reservation).toEqual({
|
|
179
|
+
operationId: args.operationId,
|
|
180
|
+
attemptId: reserved.attempts[0]._id,
|
|
181
|
+
payloadId: reserved.payloads[0]._id,
|
|
182
|
+
authorizationScope: h.record.authorization.scope,
|
|
183
|
+
authorizationId: h.record.authorization.id,
|
|
184
|
+
authorizationRevision: h.record.authorization.revision,
|
|
185
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
186
|
+
requestBinding: h.record.requestBinding,
|
|
187
|
+
key: h.request.key,
|
|
188
|
+
apiVersion: h.record.apiVersion,
|
|
189
|
+
accountJSON: canonical(h.record.account),
|
|
190
|
+
firstDispatchedAt: h.request.firstDispatchedAt,
|
|
191
|
+
ordinal: 1,
|
|
192
|
+
preparedRevision: 0,
|
|
193
|
+
committedRevision: 1,
|
|
194
|
+
recordJSON: h.recordJSON,
|
|
195
|
+
recordVersion: 2,
|
|
196
|
+
stage: "attach",
|
|
197
|
+
timingPolicyJSON: canonical(h.record.timingPolicy),
|
|
198
|
+
});
|
|
199
|
+
expect(acquired).toEqual({
|
|
200
|
+
disposition: "acquired",
|
|
201
|
+
previousRevision: 0,
|
|
202
|
+
committedRevision: 1,
|
|
203
|
+
reservation,
|
|
204
|
+
});
|
|
205
|
+
expect(reserved.payloads[0].json).toBe(h.recordJSON);
|
|
206
|
+
expect(reserved.payloads[0].owner).toEqual({
|
|
207
|
+
kind: "operation",
|
|
208
|
+
...args,
|
|
209
|
+
});
|
|
210
|
+
expect(reserved.operations[0].activeAttemptId).toBe(
|
|
211
|
+
reservation.attemptId,
|
|
212
|
+
);
|
|
213
|
+
expect(reserved.attempts[0].lastSequence).toBe(0);
|
|
214
|
+
measure(reserved);
|
|
215
|
+
progress.reserved++;
|
|
216
|
+
const bindInput = {
|
|
217
|
+
attemptId: reservation.attemptId,
|
|
218
|
+
policyJSON: canonical(h.record.timingPolicy),
|
|
219
|
+
basisJSON: canonical(basis),
|
|
220
|
+
};
|
|
221
|
+
expect(getConvexSize({ ...args, ...bindInput })).toBeLessThanOrEqual(
|
|
222
|
+
VALUE_LIMIT,
|
|
223
|
+
);
|
|
224
|
+
const bound = await journal.bindInitialBasis(bindInput);
|
|
225
|
+
expect(bound).toEqual({
|
|
226
|
+
status: "bound",
|
|
227
|
+
...args,
|
|
228
|
+
initialBasis: {
|
|
229
|
+
version: 1,
|
|
230
|
+
attemptId: reservation.attemptId,
|
|
231
|
+
sourcePayloadId: reservation.payloadId,
|
|
232
|
+
stage: "attach",
|
|
233
|
+
policyJSON: bindInput.policyJSON,
|
|
234
|
+
basisJSON: bindInput.basisJSON,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
const targetSnapshot: Physical = await ctx.runQuery(
|
|
238
|
+
inspectionRefs.betterStripe.adapterC10Inspection.physical,
|
|
239
|
+
{},
|
|
240
|
+
);
|
|
241
|
+
beforeTarget = targetSnapshot;
|
|
242
|
+
measure(targetSnapshot);
|
|
243
|
+
expect(targetSnapshot.operations[0].initialBasis).toEqual(
|
|
244
|
+
bound?.initialBasis,
|
|
245
|
+
);
|
|
246
|
+
expect(targetSnapshot.attempts).toEqual(reserved.attempts);
|
|
247
|
+
expect(targetSnapshot.payloads).toEqual(reserved.payloads);
|
|
248
|
+
expect(targetSnapshot.events).toEqual([]);
|
|
249
|
+
const { recordJSON: _recordJSON, ...summary } = reservation;
|
|
250
|
+
const boundLoad = {
|
|
251
|
+
recordVersion: 2,
|
|
252
|
+
...args,
|
|
253
|
+
recordJSON: h.recordJSON,
|
|
254
|
+
revision: 1,
|
|
255
|
+
activeAttempt: summary,
|
|
256
|
+
initialBasis: bound?.initialBasis,
|
|
257
|
+
};
|
|
258
|
+
expect(await journal.loadAuthorizedOperation()).toEqual(boundLoad);
|
|
259
|
+
progress.bound++;
|
|
260
|
+
const sender = journal.createC10Send(reservation);
|
|
261
|
+
expect(typeof sender).toBe("function");
|
|
262
|
+
const expectedArgs = {
|
|
263
|
+
reservation,
|
|
264
|
+
expectedSequence: record.sequence - 1,
|
|
265
|
+
event: {
|
|
266
|
+
sequence: record.sequence,
|
|
267
|
+
binding: record.binding,
|
|
268
|
+
dataJSON: event.json,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
expect(getConvexSize(expectedArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
272
|
+
if (scenario.pending) {
|
|
273
|
+
const subtle = globalThis.crypto.subtle;
|
|
274
|
+
const original = subtle.digest;
|
|
275
|
+
const ownDescriptor = Object.getOwnPropertyDescriptor(
|
|
276
|
+
subtle,
|
|
277
|
+
"digest",
|
|
278
|
+
);
|
|
279
|
+
const proof = await original.call(
|
|
280
|
+
subtle,
|
|
281
|
+
"SHA-256",
|
|
282
|
+
expectedHashBytes,
|
|
283
|
+
);
|
|
284
|
+
expect(
|
|
285
|
+
"unbound-qualification-event:v2:sha256:" +
|
|
286
|
+
Array.from(new Uint8Array(proof), (n) =>
|
|
287
|
+
n.toString(16).padStart(2, "0"),
|
|
288
|
+
).join(""),
|
|
289
|
+
).toBe(event.binding);
|
|
290
|
+
// This actual shared native object's OWN method is instrumented;
|
|
291
|
+
// nested handlers do not inherit an Action crypto-global override.
|
|
292
|
+
const spy = vi
|
|
293
|
+
.spyOn(subtle, "digest")
|
|
294
|
+
.mockImplementation((algorithm, input) => {
|
|
295
|
+
const bytes = ArrayBuffer.isView(input)
|
|
296
|
+
? new Uint8Array(
|
|
297
|
+
input.buffer,
|
|
298
|
+
input.byteOffset,
|
|
299
|
+
input.byteLength,
|
|
300
|
+
).slice()
|
|
301
|
+
: new Uint8Array(input).slice();
|
|
302
|
+
const match =
|
|
303
|
+
algorithm === "SHA-256" &&
|
|
304
|
+
bytes.length === expectedHashBytes.length &&
|
|
305
|
+
bytes.every(
|
|
306
|
+
(value, index) => value === expectedHashBytes[index],
|
|
307
|
+
);
|
|
308
|
+
if (match) pending.matches++;
|
|
309
|
+
const selected = match && pending.matches === 2;
|
|
310
|
+
const native = original.call(subtle, algorithm, input);
|
|
311
|
+
nativeCalls.push(native);
|
|
312
|
+
const forwarded = native.then(async (result) => {
|
|
313
|
+
if (selected) {
|
|
314
|
+
pending.nativeFulfilled = true;
|
|
315
|
+
markEntered();
|
|
316
|
+
await releaseGate;
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
});
|
|
320
|
+
forwardedCalls.push(forwarded);
|
|
321
|
+
return forwarded;
|
|
322
|
+
});
|
|
323
|
+
restoreDigest = () => {
|
|
324
|
+
spy.mockRestore();
|
|
325
|
+
if (ownDescriptor)
|
|
326
|
+
Object.defineProperty(subtle, "digest", ownDescriptor);
|
|
327
|
+
else expect(Reflect.deleteProperty(subtle, "digest")).toBe(true);
|
|
328
|
+
expect(Object.getOwnPropertyDescriptor(subtle, "digest")).toEqual(
|
|
329
|
+
ownDescriptor,
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
progress.target++;
|
|
334
|
+
const ack = (value: unknown) => {
|
|
335
|
+
acks.push(value);
|
|
336
|
+
// This real query begins from ACK, but may queue behind an already
|
|
337
|
+
// started append. Readback alone does not discriminate an early ACK;
|
|
338
|
+
// C10SEND03 checks the actual pending handler directly.
|
|
339
|
+
ackReads.push(
|
|
340
|
+
ctx.runQuery(
|
|
341
|
+
inspectionRefs.betterStripe.adapterC10Inspection.physical,
|
|
342
|
+
{},
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
};
|
|
346
|
+
try {
|
|
347
|
+
const send = sender(record, ack);
|
|
348
|
+
sendObservers.push(
|
|
349
|
+
send.then(
|
|
350
|
+
() => {
|
|
351
|
+
pending.sendSettled = true;
|
|
352
|
+
},
|
|
353
|
+
() => {
|
|
354
|
+
pending.sendSettled = true;
|
|
355
|
+
},
|
|
356
|
+
),
|
|
357
|
+
);
|
|
358
|
+
if (scenario.sequence === 2) {
|
|
359
|
+
await expect(send).rejects.toThrow(/^RENEWAL_JOURNAL_CONFLICT$/);
|
|
360
|
+
expect(acks).toEqual([]);
|
|
361
|
+
expect(ackReads).toEqual([]);
|
|
362
|
+
expect(
|
|
363
|
+
await ctx.runQuery(
|
|
364
|
+
inspectionRefs.betterStripe.adapterC10Inspection.physical,
|
|
365
|
+
{},
|
|
366
|
+
),
|
|
367
|
+
).toEqual(targetSnapshot);
|
|
368
|
+
return null;
|
|
369
|
+
}
|
|
370
|
+
await send;
|
|
371
|
+
progress.sent++;
|
|
372
|
+
expect(acks).toEqual([{ sequence: 1, binding: event.binding }]);
|
|
373
|
+
const reads = await Promise.all(ackReads);
|
|
374
|
+
expect(reads).toHaveLength(1);
|
|
375
|
+
const committed = reads[0];
|
|
376
|
+
measure(committed);
|
|
377
|
+
expect(committed.operations).toEqual(targetSnapshot.operations);
|
|
378
|
+
expect(committed.attempts).toEqual([
|
|
379
|
+
{ ...targetSnapshot.attempts[0], lastSequence: 1 },
|
|
380
|
+
]);
|
|
381
|
+
expect(committed.events).toHaveLength(1);
|
|
382
|
+
expect(committed.payloads).toHaveLength(2);
|
|
383
|
+
const row = committed.events[0];
|
|
384
|
+
expect(row).toEqual({
|
|
385
|
+
_id: row._id,
|
|
386
|
+
_creationTime: row._creationTime,
|
|
387
|
+
operationId: reservation.operationId,
|
|
388
|
+
attemptId: reservation.attemptId,
|
|
389
|
+
stage: "attach",
|
|
390
|
+
sourcePayloadId: reservation.payloadId,
|
|
391
|
+
sequence: 1,
|
|
392
|
+
binding: event.binding,
|
|
393
|
+
payloadId: row.payloadId,
|
|
394
|
+
});
|
|
395
|
+
expect(
|
|
396
|
+
committed.payloads.find((p) => p._id === reservation.payloadId),
|
|
397
|
+
).toEqual(targetSnapshot.payloads[0]);
|
|
398
|
+
const payload = committed.payloads.find(
|
|
399
|
+
(p) => p._id === row.payloadId,
|
|
400
|
+
);
|
|
401
|
+
assert(payload && payload._id !== reservation.payloadId);
|
|
402
|
+
expect(payload).toEqual({
|
|
403
|
+
_id: row.payloadId,
|
|
404
|
+
_creationTime: payload._creationTime,
|
|
405
|
+
codecVersion: 1,
|
|
406
|
+
json: event.json,
|
|
407
|
+
owner: {
|
|
408
|
+
kind: "event",
|
|
409
|
+
operationId: reservation.operationId,
|
|
410
|
+
attemptId: reservation.attemptId,
|
|
411
|
+
stage: "attach",
|
|
412
|
+
sequence: 1,
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
expect(
|
|
416
|
+
await ctx.runQuery(refs.queries.readStageEvent, {
|
|
417
|
+
...args,
|
|
418
|
+
attemptId: reservation.attemptId,
|
|
419
|
+
sequence: 1,
|
|
420
|
+
}),
|
|
421
|
+
).toEqual({
|
|
422
|
+
eventId: row._id,
|
|
423
|
+
operationId: row.operationId,
|
|
424
|
+
attemptId: row.attemptId,
|
|
425
|
+
stage: row.stage,
|
|
426
|
+
sourcePayloadId: row.sourcePayloadId,
|
|
427
|
+
sequence: 1,
|
|
428
|
+
binding: event.binding,
|
|
429
|
+
payloadId: row.payloadId,
|
|
430
|
+
dataJSON: event.json,
|
|
431
|
+
});
|
|
432
|
+
expect(await journal.loadAuthorizedOperation()).toEqual(boundLoad);
|
|
433
|
+
checkedCommitted = committed;
|
|
434
|
+
throw Error(parentStop);
|
|
435
|
+
} finally {
|
|
436
|
+
// Every query launched by an ACK is drained even if send/assertion
|
|
437
|
+
// fails. No real RPC/query Promise is abandoned during inspection.
|
|
438
|
+
await Promise.allSettled(ackReads);
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
}),
|
|
442
|
+
};
|
|
443
|
+
const t = convexTest(defineSchema({}), {
|
|
444
|
+
"./_generated/api.ts": async () => ({}),
|
|
445
|
+
"./adapterC10.ts": async () => host,
|
|
446
|
+
});
|
|
447
|
+
expect(
|
|
448
|
+
Object.prototype.hasOwnProperty.call(
|
|
449
|
+
modules,
|
|
450
|
+
"./component/adapterC10Inspection.ts",
|
|
451
|
+
),
|
|
452
|
+
).toBe(false);
|
|
453
|
+
t.registerComponent("betterStripe", schema, {
|
|
454
|
+
...modules,
|
|
455
|
+
"./component/adapterC10Inspection.ts": async () => inspection,
|
|
456
|
+
});
|
|
457
|
+
const physical = (): Promise<Physical> =>
|
|
458
|
+
t.query(inspectionRefs.betterStripe.adapterC10Inspection.physical, {});
|
|
459
|
+
expect(await physical()).toEqual({
|
|
460
|
+
operations: [],
|
|
461
|
+
attempts: [],
|
|
462
|
+
events: [],
|
|
463
|
+
payloads: [],
|
|
464
|
+
});
|
|
465
|
+
const created = await t.mutation(refs.mutations.createAuthorizedOperation, {
|
|
466
|
+
authorizationScope: h.record.authorization.scope,
|
|
467
|
+
authorizationRevision: h.record.authorization.revision,
|
|
468
|
+
logicalOperationId: h.record.logicalOperationId,
|
|
469
|
+
recordJSON: h.recordJSON,
|
|
470
|
+
});
|
|
471
|
+
assert(created.status === "created");
|
|
472
|
+
let failed = false;
|
|
473
|
+
const action = t.action(call, { operationId: created.operationId });
|
|
474
|
+
try {
|
|
475
|
+
if (scenario.pending) {
|
|
476
|
+
await Promise.race([
|
|
477
|
+
entered,
|
|
478
|
+
action.then(() => {
|
|
479
|
+
throw Error("C10_PENDING_GATE_NOT_REACHED");
|
|
480
|
+
}),
|
|
481
|
+
]);
|
|
482
|
+
// The actual append handler is held before writes. Never query the DB
|
|
483
|
+
// while it owns the transaction lock; inspect only causal local facts.
|
|
484
|
+
expect(pending).toEqual({
|
|
485
|
+
matches: 2,
|
|
486
|
+
nativeFulfilled: true,
|
|
487
|
+
released: false,
|
|
488
|
+
sendSettled: false,
|
|
489
|
+
});
|
|
490
|
+
expect(acks).toEqual([]);
|
|
491
|
+
expect(ackReads).toEqual([]);
|
|
492
|
+
release();
|
|
493
|
+
}
|
|
494
|
+
if (scenario.sequence === 1) {
|
|
495
|
+
let stopped = false;
|
|
496
|
+
try {
|
|
497
|
+
await action;
|
|
498
|
+
} catch (error) {
|
|
499
|
+
if (!(error instanceof Error) || error.message !== parentStop)
|
|
500
|
+
throw error;
|
|
501
|
+
stopped = true;
|
|
502
|
+
}
|
|
503
|
+
expect(stopped).toBe(true);
|
|
504
|
+
expect(progress).toEqual({
|
|
505
|
+
prepared: 1,
|
|
506
|
+
reserved: 1,
|
|
507
|
+
bound: 1,
|
|
508
|
+
target: 1,
|
|
509
|
+
sent: 1,
|
|
510
|
+
});
|
|
511
|
+
expect(checkedCommitted).not.toBeNull();
|
|
512
|
+
} else {
|
|
513
|
+
await action;
|
|
514
|
+
expect(progress).toEqual({
|
|
515
|
+
prepared: 1,
|
|
516
|
+
reserved: 1,
|
|
517
|
+
bound: 1,
|
|
518
|
+
target: 1,
|
|
519
|
+
sent: 0,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
} catch (error) {
|
|
523
|
+
failed = true;
|
|
524
|
+
throw error;
|
|
525
|
+
} finally {
|
|
526
|
+
release();
|
|
527
|
+
await Promise.allSettled([action]);
|
|
528
|
+
await Promise.allSettled([
|
|
529
|
+
...nativeCalls,
|
|
530
|
+
...forwardedCalls,
|
|
531
|
+
...sendObservers,
|
|
532
|
+
...ackReads,
|
|
533
|
+
]);
|
|
534
|
+
try {
|
|
535
|
+
restoreDigest();
|
|
536
|
+
const after = await physical();
|
|
537
|
+
measure(after);
|
|
538
|
+
if (beforeTarget !== null)
|
|
539
|
+
expect(after).toEqual(checkedCommitted ?? beforeTarget);
|
|
540
|
+
expect(h.fetchCalls()).toBe(0);
|
|
541
|
+
console.info(
|
|
542
|
+
"ADAPTER_C10_SETTLEMENT",
|
|
543
|
+
JSON.stringify({
|
|
544
|
+
sequence: scenario.sequence,
|
|
545
|
+
...progress,
|
|
546
|
+
ackCount: acks.length,
|
|
547
|
+
eventCount: after.events.length,
|
|
548
|
+
payloadCount: after.payloads.length,
|
|
549
|
+
committedSurvivedParentFailure: checkedCommitted !== null,
|
|
550
|
+
fetchCalls: 0,
|
|
551
|
+
pendingCase: scenario.pending,
|
|
552
|
+
matchingHashes: pending.matches,
|
|
553
|
+
}),
|
|
554
|
+
);
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (!failed) throw error;
|
|
557
|
+
console.info("ADAPTER_C10_INSPECTION_FAILED");
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|