@fantastic.dev/better-stripe 0.91.0 → 0.93.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/configure/actor.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/actor.js +46 -56
- package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js +61 -0
- package/dist/client/billing/renewalAttach/internal/configure/ownedContinuation.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/actor.js +25 -4
- package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/capture.js +3 -2
- package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js +11 -0
- package/dist/client/billing/renewalAttach/internal/observation/configureAcknowledgement.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts +30 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +113 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +562 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +562 -0
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts.map +1 -1
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +281 -0
- package/dist/client/connect/payoutSyncTestHelpers.d.ts.map +1 -1
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +16 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +6 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +406 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/balanceFunding/workflowValidators.d.ts +16 -16
- package/dist/component/earnings/triggers.d.ts +294 -0
- package/dist/component/earnings/triggers.d.ts.map +1 -1
- package/dist/component/payoutRelease/queries.d.ts +2 -2
- package/dist/component/payoutRelease/queries.d.ts.map +1 -1
- package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
- package/dist/component/renewalOperations/helpers.d.ts +236 -0
- package/dist/component/renewalOperations/helpers.d.ts.map +1 -0
- package/dist/component/renewalOperations/helpers.js +457 -0
- package/dist/component/renewalOperations/helpers.js.map +1 -0
- package/dist/component/renewalOperations/mutations.d.ts +252 -0
- package/dist/component/renewalOperations/mutations.d.ts.map +1 -0
- package/dist/component/renewalOperations/mutations.js +340 -0
- package/dist/component/renewalOperations/mutations.js.map +1 -0
- package/dist/component/renewalOperations/queries.d.ts +163 -0
- package/dist/component/renewalOperations/queries.d.ts.map +1 -0
- package/dist/component/renewalOperations/queries.js +167 -0
- package/dist/component/renewalOperations/queries.js.map +1 -0
- package/dist/component/renewalOperations/schema.d.ts +1988 -0
- package/dist/component/renewalOperations/schema.d.ts.map +1 -0
- package/dist/component/renewalOperations/schema.js +227 -0
- package/dist/component/renewalOperations/schema.js.map +1 -0
- package/dist/component/schema.d.ts +281 -0
- package/dist/component/schema.js +5 -0
- package/dist/component/schema.js.map +1 -1
- package/dist/component/usage/allowance.fixtures.d.ts +281 -0
- package/dist/component/usage/allowance.fixtures.d.ts.map +1 -1
- package/dist/component/usageCredits/accounting.fixtures.d.ts +281 -0
- package/dist/component/usageCredits/accounting.fixtures.d.ts.map +1 -1
- package/dist/shared/renewalOperationJournal.d.ts +43 -0
- package/dist/shared/renewalOperationJournal.d.ts.map +1 -0
- package/dist/shared/renewalOperationJournal.js +294 -0
- package/dist/shared/renewalOperationJournal.js.map +1 -0
- package/docs/renewal-context-reads.md +152 -0
- package/docs/renewal-material-observation.md +32 -11
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/configure/actor.ts +63 -52
- package/src/client/billing/renewalAttach/internal/configure/ownedContinuation.ts +56 -0
- package/src/client/billing/renewalAttach/internal/observation/actor.ts +46 -3
- package/src/client/billing/renewalAttach/internal/observation/capture.ts +3 -2
- package/src/client/billing/renewalAttach/internal/observation/configureAcknowledgement.ts +20 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACK.integration.test.ts +36 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKControls.integration.test.ts +48 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfigureACKLifecycle.integration.test.ts +44 -0
- package/src/client/billing/renewalAttach/internal/observation/observationConfiguredHistory.integration.test.ts +34 -0
- package/src/client/billing/renewalAttach/internal/observation/types.ts +5 -0
- package/src/client/billing/renewalAttach/internal/operationJournal.integration.test.ts +380 -0
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +155 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +5 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +12 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDelegate.ts +38 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +8 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +10 -23
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKAssertions.ts +115 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKDeclarations.ts +141 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleAssertions.ts +74 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleDeclarations.ts +79 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleInstrumentation.ts +207 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKLifecycleOperation.ts +494 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfigureACKOperation.ts +452 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryAssertions.ts +88 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryDeclarations.ts +170 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryNative.ts +99 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationConfiguredHistoryOperation.ts +411 -0
- package/src/client/index.ts +24 -3
- package/src/component/_generated/api.ts +6 -0
- package/src/component/_generated/component.ts +450 -0
- package/src/component/renewalOperations/acknowledgement.fixtures.ts +552 -0
- package/src/component/renewalOperations/acknowledgement.test.ts +573 -0
- package/src/component/renewalOperations/acknowledgementReads.test.ts +442 -0
- package/src/component/renewalOperations/acknowledgementV2.test.ts +493 -0
- package/src/component/renewalOperations/acknowledgementV2Publication.test.ts +373 -0
- package/src/component/renewalOperations/basisBinding.test.ts +567 -0
- package/src/component/renewalOperations/basisLifecycle.test.ts +569 -0
- package/src/component/renewalOperations/boundHistory.test.ts +474 -0
- package/src/component/renewalOperations/helpers.ts +592 -0
- package/src/component/renewalOperations/historyReads.test.ts +595 -0
- package/src/component/renewalOperations/initialBasis.test.ts +578 -0
- package/src/component/renewalOperations/journal.test.ts +567 -0
- package/src/component/renewalOperations/mutations.ts +456 -0
- package/src/component/renewalOperations/payload.test.ts +589 -0
- package/src/component/renewalOperations/payloadEncoding.test.ts +592 -0
- package/src/component/renewalOperations/queries.ts +204 -0
- package/src/component/renewalOperations/schema.ts +268 -0
- package/src/component/renewalOperations/timingPolicy.fixtures.ts +193 -0
- package/src/component/renewalOperations/timingPolicy.test.ts +523 -0
- package/src/component/schema.ts +11 -0
- package/src/shared/renewalOperationJournal.ts +333 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
3
|
+
import { getConvexSize, getDocumentSize, type ObjectType } from "convex/values";
|
|
4
|
+
import type { appendArgs } from "./schema.js";
|
|
5
|
+
import {
|
|
6
|
+
prepareAcknowledgementScenario,
|
|
7
|
+
retain,
|
|
8
|
+
append,
|
|
9
|
+
canonical,
|
|
10
|
+
VALUE_LIMIT,
|
|
11
|
+
negativeScenarios,
|
|
12
|
+
type Scenario,
|
|
13
|
+
type RetentionReceipt,
|
|
14
|
+
} from "./acknowledgement.fixtures.js";
|
|
15
|
+
import { constructRenewalScheduleAttachmentReceiptV2 } from "../../client/billing/renewalV2/index.js";
|
|
16
|
+
import { admitInitialOutput } from "../../client/billing/renewalAttach/internal/recovery/material.js";
|
|
17
|
+
import { captureAttachReceipt } from "../../client/billing/renewalAttach/internal/c10/eventCapture.js";
|
|
18
|
+
import {
|
|
19
|
+
eventDigest,
|
|
20
|
+
objectNode,
|
|
21
|
+
scalarNode,
|
|
22
|
+
materialize,
|
|
23
|
+
} from "../../client/billing/renewalAttach/internal/c10/eventCodec.js";
|
|
24
|
+
import { canonicalJournalEvent } from "../../shared/renewalOperationJournal.js";
|
|
25
|
+
import { receiptInput } from "../../client/billing/renewalAttach/internal/acquisition/test-fixtures/fixture.mjs";
|
|
26
|
+
import type { ConstructRenewalScheduleAttachmentReceiptV2Options } from "../../client/billing/renewalV2/index.js";
|
|
27
|
+
|
|
28
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
29
|
+
async function acknowledgementScenario(scenario: Scenario, duplicate = false) {
|
|
30
|
+
const h = await prepareAcknowledgementScenario(scenario);
|
|
31
|
+
const {
|
|
32
|
+
t,
|
|
33
|
+
physical,
|
|
34
|
+
before,
|
|
35
|
+
args,
|
|
36
|
+
receipt,
|
|
37
|
+
receiptJSON,
|
|
38
|
+
acquired,
|
|
39
|
+
commits,
|
|
40
|
+
ownerScope,
|
|
41
|
+
queryArgs,
|
|
42
|
+
shouldRetain,
|
|
43
|
+
fetchCalls,
|
|
44
|
+
} = h;
|
|
45
|
+
if (!shouldRetain) {
|
|
46
|
+
let fulfilled = false;
|
|
47
|
+
let returnedNull = false;
|
|
48
|
+
let refusal: unknown;
|
|
49
|
+
try {
|
|
50
|
+
const value = await t.mutation(retain, args);
|
|
51
|
+
fulfilled = true;
|
|
52
|
+
returnedNull = value === null;
|
|
53
|
+
expect(getConvexSize(value)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
refusal = error;
|
|
56
|
+
}
|
|
57
|
+
let after: Awaited<ReturnType<typeof physical>>;
|
|
58
|
+
try {
|
|
59
|
+
after = await physical();
|
|
60
|
+
} catch (inspectionError) {
|
|
61
|
+
if (refusal !== undefined) throw refusal;
|
|
62
|
+
throw inspectionError;
|
|
63
|
+
}
|
|
64
|
+
const physicalEqual = JSON.stringify(after) === JSON.stringify(before);
|
|
65
|
+
console.info(
|
|
66
|
+
"BTS317_ACK_NEGATIVE",
|
|
67
|
+
JSON.stringify({
|
|
68
|
+
scenario,
|
|
69
|
+
fulfilled,
|
|
70
|
+
returnedNull,
|
|
71
|
+
physicalEqual,
|
|
72
|
+
counts: Object.values(after).map((rows) => rows.length),
|
|
73
|
+
lastSequence: after.attempts[0]?.lastSequence,
|
|
74
|
+
fetchCalls: fetchCalls(),
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
// Missing route/import/framework errors must remain original STOP errors.
|
|
78
|
+
if (
|
|
79
|
+
refusal !== undefined &&
|
|
80
|
+
(!(refusal instanceof Error) ||
|
|
81
|
+
refusal.message !== "RENEWAL_JOURNAL_CONFLICT")
|
|
82
|
+
)
|
|
83
|
+
throw refusal;
|
|
84
|
+
expect(fulfilled).toBe(false);
|
|
85
|
+
expect(refusal).toBeInstanceOf(Error);
|
|
86
|
+
expect(physicalEqual).toBe(true);
|
|
87
|
+
expect(Object.values(after).map((rows) => rows.length)).toEqual([
|
|
88
|
+
1, 1, 2, 3,
|
|
89
|
+
]);
|
|
90
|
+
expect(after.attempts[0].lastSequence).toBe(2);
|
|
91
|
+
expect(fetchCalls()).toBe(0);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
let retained: RetentionReceipt | null | undefined;
|
|
95
|
+
const inspectSettlement = async () => {
|
|
96
|
+
const rows = await physical();
|
|
97
|
+
console.info(
|
|
98
|
+
"BTS317_ACK01_SETTLEMENT",
|
|
99
|
+
JSON.stringify({
|
|
100
|
+
resultNull: retained === null,
|
|
101
|
+
physicalEqual: JSON.stringify(rows) === JSON.stringify(before),
|
|
102
|
+
counts: Object.values(rows).map((docs) => docs.length),
|
|
103
|
+
lastSequence: rows.attempts[0]?.lastSequence,
|
|
104
|
+
fetchCalls: fetchCalls(),
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
return rows;
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
retained = await t.mutation(retain, args);
|
|
111
|
+
} catch (originalError) {
|
|
112
|
+
try {
|
|
113
|
+
await inspectSettlement();
|
|
114
|
+
} finally {
|
|
115
|
+
throw originalError;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const after = await inspectSettlement();
|
|
119
|
+
// The intended honest-null RED occurs HERE after every real prerequisite.
|
|
120
|
+
expect(retained).not.toBeNull();
|
|
121
|
+
assert(retained !== null && retained !== undefined);
|
|
122
|
+
expect(getConvexSize(retained)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
123
|
+
const expectedKnown = {
|
|
124
|
+
schemaVersion: 1,
|
|
125
|
+
stage: "attach",
|
|
126
|
+
attemptId: acquired.reservation.attemptId,
|
|
127
|
+
sourcePayloadId: acquired.reservation.payloadId,
|
|
128
|
+
dispatchEventId: commits[0].eventId,
|
|
129
|
+
dispatchPayloadId: commits[0].payloadId,
|
|
130
|
+
responseEventId: commits[1].eventId,
|
|
131
|
+
responsePayloadId: commits[1].payloadId,
|
|
132
|
+
receiptPayloadId: retained.receiptPayloadId,
|
|
133
|
+
receiptBinding: receipt.binding,
|
|
134
|
+
};
|
|
135
|
+
expect(retained).toEqual({
|
|
136
|
+
status: "retained",
|
|
137
|
+
...queryArgs,
|
|
138
|
+
...expectedKnown,
|
|
139
|
+
});
|
|
140
|
+
assert(after);
|
|
141
|
+
expect(Object.values(after).map((rows) => rows.length)).toEqual([1, 1, 2, 4]);
|
|
142
|
+
const known = Object.getOwnPropertyDescriptor(
|
|
143
|
+
after.operations[0],
|
|
144
|
+
"knownAcknowledgement",
|
|
145
|
+
);
|
|
146
|
+
assert(known && "value" in known);
|
|
147
|
+
expect(known.value).toEqual(expectedKnown);
|
|
148
|
+
const storedReceipt = after.payloads.find(
|
|
149
|
+
(row) => row._id === retained.receiptPayloadId,
|
|
150
|
+
);
|
|
151
|
+
assert(storedReceipt);
|
|
152
|
+
expect(storedReceipt.codecVersion).toBe(1);
|
|
153
|
+
expect(storedReceipt.owner).toEqual({ kind: "receipt", ...ownerScope });
|
|
154
|
+
expect(storedReceipt.json).toBe(receiptJSON);
|
|
155
|
+
if (scenario === "nullable-key") {
|
|
156
|
+
const savedMetadata = JSON.parse(storedReceipt.json).providerSnapshot
|
|
157
|
+
.metadata;
|
|
158
|
+
expect(
|
|
159
|
+
Object.prototype.hasOwnProperty.call(savedMetadata, "client_secret"),
|
|
160
|
+
).toBe(true);
|
|
161
|
+
expect(savedMetadata.client_secret).toBeNull();
|
|
162
|
+
}
|
|
163
|
+
for (const doc of before.payloads)
|
|
164
|
+
expect(after.payloads.find((row) => row._id === doc._id)).toEqual(doc);
|
|
165
|
+
expect(after.attempts).toEqual(before.attempts);
|
|
166
|
+
expect(after.events).toEqual(before.events);
|
|
167
|
+
expect(
|
|
168
|
+
Object.fromEntries(
|
|
169
|
+
Object.entries(after.operations[0]).filter(
|
|
170
|
+
([key]) => key !== "knownAcknowledgement",
|
|
171
|
+
),
|
|
172
|
+
),
|
|
173
|
+
).toEqual(before.operations[0]);
|
|
174
|
+
for (const rows of Object.values(after))
|
|
175
|
+
for (const doc of rows)
|
|
176
|
+
expect(getDocumentSize(doc)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
177
|
+
expect(fetchCalls()).toBe(0);
|
|
178
|
+
if (duplicate) {
|
|
179
|
+
try {
|
|
180
|
+
expect(await t.mutation(retain, args)).toEqual(retained);
|
|
181
|
+
} finally {
|
|
182
|
+
expect(await physical()).toEqual(after);
|
|
183
|
+
expect(fetchCalls()).toBe(0);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return { ...h, retained, after };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
it("ACK01 retains full known attach receipt before receipt3 publication", async () => {
|
|
190
|
+
await acknowledgementScenario("clean");
|
|
191
|
+
});
|
|
192
|
+
it("ACK-null explicit null credential field is retained without becoming absent", async () => {
|
|
193
|
+
await acknowledgementScenario("nullable-key");
|
|
194
|
+
});
|
|
195
|
+
it.each(negativeScenarios)(
|
|
196
|
+
"ACK-negative %s refuses invalid host DATA before retention writes",
|
|
197
|
+
async (scenario) => {
|
|
198
|
+
await acknowledgementScenario(scenario);
|
|
199
|
+
},
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
it("ACK02 identical retain returns the original receipt without writes", async () => {
|
|
203
|
+
await acknowledgementScenario("clean", true);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
type PreparedACK = Awaited<ReturnType<typeof prepareAcknowledgementScenario>>;
|
|
207
|
+
async function thirdEventArgs(
|
|
208
|
+
h: PreparedACK,
|
|
209
|
+
receipt: PreparedACK["receipt"],
|
|
210
|
+
): Promise<ObjectType<typeof appendArgs>> {
|
|
211
|
+
const data = {
|
|
212
|
+
event: "receipt",
|
|
213
|
+
stage: "attach",
|
|
214
|
+
request: h.request,
|
|
215
|
+
receipt,
|
|
216
|
+
};
|
|
217
|
+
const node = captureAttachReceipt(data);
|
|
218
|
+
expect(materialize(node)).toEqual(data);
|
|
219
|
+
const full = await canonicalJournalEvent(3, canonical(data));
|
|
220
|
+
expect(full.binding).toBe(
|
|
221
|
+
await eventDigest(
|
|
222
|
+
objectNode([
|
|
223
|
+
["sequence", scalarNode(3)],
|
|
224
|
+
["data", node],
|
|
225
|
+
]),
|
|
226
|
+
),
|
|
227
|
+
);
|
|
228
|
+
const args: ObjectType<typeof appendArgs> = {
|
|
229
|
+
reservation: h.acquired.reservation,
|
|
230
|
+
expectedSequence: 2,
|
|
231
|
+
event: { sequence: 3, binding: full.binding, dataJSON: full.json },
|
|
232
|
+
};
|
|
233
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
234
|
+
return args;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
it("ACK03 first retain after matching event3 is stable on identical retry", async () => {
|
|
238
|
+
const h = await prepareAcknowledgementScenario("clean");
|
|
239
|
+
const eventArgs = await thirdEventArgs(h, h.receipt);
|
|
240
|
+
const committed = await h.t.mutation(append, eventArgs);
|
|
241
|
+
expect(committed.sequence).toBe(3);
|
|
242
|
+
expect(committed.binding).toBe(eventArgs.event.binding);
|
|
243
|
+
expect(committed.reservation).toEqual(h.acquired.reservation);
|
|
244
|
+
expect(getConvexSize(committed)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
245
|
+
const before = await h.physical();
|
|
246
|
+
expect(Object.values(before).map((rows) => rows.length)).toEqual([
|
|
247
|
+
1, 1, 3, 4,
|
|
248
|
+
]);
|
|
249
|
+
expect(before.attempts[0].lastSequence).toBe(3);
|
|
250
|
+
for (const rows of Object.values(before))
|
|
251
|
+
for (const row of rows)
|
|
252
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
253
|
+
expect(
|
|
254
|
+
Object.prototype.hasOwnProperty.call(
|
|
255
|
+
before.operations[0],
|
|
256
|
+
"knownAcknowledgement",
|
|
257
|
+
),
|
|
258
|
+
).toBe(false);
|
|
259
|
+
expect(
|
|
260
|
+
before.payloads.find((row) => row._id === committed.payloadId),
|
|
261
|
+
).toMatchObject({
|
|
262
|
+
codecVersion: 1,
|
|
263
|
+
json: eventArgs.event.dataJSON,
|
|
264
|
+
owner: { kind: "event", ...h.ownerScope, sequence: 3 },
|
|
265
|
+
});
|
|
266
|
+
for (const row of h.before.payloads)
|
|
267
|
+
expect(
|
|
268
|
+
before.payloads.find((candidate) => candidate._id === row._id),
|
|
269
|
+
).toEqual(row);
|
|
270
|
+
for (const row of h.before.events)
|
|
271
|
+
expect(
|
|
272
|
+
before.events.find((candidate) => candidate._id === row._id),
|
|
273
|
+
).toEqual(row);
|
|
274
|
+
const args = { ...h.args, expectedSequence: 3 as const };
|
|
275
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
276
|
+
let retained: RetentionReceipt | null | undefined;
|
|
277
|
+
try {
|
|
278
|
+
retained = await h.t.mutation(retain, args);
|
|
279
|
+
} catch (originalError) {
|
|
280
|
+
try {
|
|
281
|
+
const rows = await h.physical();
|
|
282
|
+
const physicalEqual = JSON.stringify(rows) === JSON.stringify(before);
|
|
283
|
+
console.info(
|
|
284
|
+
"ACK03_FIRST_SETTLEMENT",
|
|
285
|
+
JSON.stringify({
|
|
286
|
+
physicalEqual,
|
|
287
|
+
counts: Object.values(rows).map((group) => group.length),
|
|
288
|
+
fetchCalls: h.fetchCalls(),
|
|
289
|
+
}),
|
|
290
|
+
);
|
|
291
|
+
expect(physicalEqual).toBe(true);
|
|
292
|
+
expect(h.fetchCalls()).toBe(0);
|
|
293
|
+
} finally {
|
|
294
|
+
throw originalError;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
assert(retained !== null && retained !== undefined);
|
|
298
|
+
expect(getConvexSize(retained)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
299
|
+
const expectedKnown = {
|
|
300
|
+
schemaVersion: 1,
|
|
301
|
+
stage: "attach",
|
|
302
|
+
attemptId: h.acquired.reservation.attemptId,
|
|
303
|
+
sourcePayloadId: h.acquired.reservation.payloadId,
|
|
304
|
+
dispatchEventId: h.commits[0].eventId,
|
|
305
|
+
dispatchPayloadId: h.commits[0].payloadId,
|
|
306
|
+
responseEventId: h.commits[1].eventId,
|
|
307
|
+
responsePayloadId: h.commits[1].payloadId,
|
|
308
|
+
receiptPayloadId: retained.receiptPayloadId,
|
|
309
|
+
receiptBinding: h.receipt.binding,
|
|
310
|
+
};
|
|
311
|
+
expect(retained).toEqual({
|
|
312
|
+
status: "retained",
|
|
313
|
+
...h.queryArgs,
|
|
314
|
+
...expectedKnown,
|
|
315
|
+
});
|
|
316
|
+
const after = await h.physical();
|
|
317
|
+
expect(Object.values(after).map((rows) => rows.length)).toEqual([1, 1, 3, 5]);
|
|
318
|
+
expect(after.operations[0].knownAcknowledgement).toEqual(expectedKnown);
|
|
319
|
+
expect(
|
|
320
|
+
after.payloads.find((row) => row._id === retained.receiptPayloadId),
|
|
321
|
+
).toMatchObject({
|
|
322
|
+
codecVersion: 1,
|
|
323
|
+
json: h.receiptJSON,
|
|
324
|
+
owner: { kind: "receipt", ...h.ownerScope },
|
|
325
|
+
});
|
|
326
|
+
for (const row of before.payloads)
|
|
327
|
+
expect(
|
|
328
|
+
after.payloads.find((candidate) => candidate._id === row._id),
|
|
329
|
+
).toEqual(row);
|
|
330
|
+
expect(after.events).toEqual(before.events);
|
|
331
|
+
expect(after.attempts).toEqual(before.attempts);
|
|
332
|
+
expect(
|
|
333
|
+
Object.fromEntries(
|
|
334
|
+
Object.entries(after.operations[0]).filter(
|
|
335
|
+
([key]) => key !== "knownAcknowledgement",
|
|
336
|
+
),
|
|
337
|
+
),
|
|
338
|
+
).toEqual(before.operations[0]);
|
|
339
|
+
for (const rows of Object.values(after))
|
|
340
|
+
for (const row of rows)
|
|
341
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
342
|
+
try {
|
|
343
|
+
expect(await h.t.mutation(retain, args)).toEqual(retained);
|
|
344
|
+
} finally {
|
|
345
|
+
expect(await h.physical()).toEqual(after);
|
|
346
|
+
expect(h.fetchCalls()).toBe(0);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
it("ACK04 matching event3 leaves known receipt and old expectedSequence2 retry stable", async () => {
|
|
350
|
+
const h = await acknowledgementScenario("clean");
|
|
351
|
+
assert(h);
|
|
352
|
+
const eventArgs = await thirdEventArgs(h, h.receipt);
|
|
353
|
+
const committed = await h.t.mutation(append, eventArgs);
|
|
354
|
+
expect(committed.sequence).toBe(3);
|
|
355
|
+
expect(committed.binding).toBe(eventArgs.event.binding);
|
|
356
|
+
expect(getConvexSize(committed)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
357
|
+
const after3 = await h.physical();
|
|
358
|
+
expect(Object.values(after3).map((rows) => rows.length)).toEqual([
|
|
359
|
+
1, 1, 3, 5,
|
|
360
|
+
]);
|
|
361
|
+
expect(after3.operations[0].knownAcknowledgement).toEqual(
|
|
362
|
+
h.after.operations[0].knownAcknowledgement,
|
|
363
|
+
);
|
|
364
|
+
expect(after3.attempts[0].lastSequence).toBe(3);
|
|
365
|
+
try {
|
|
366
|
+
for (const expectedSequence of [2, 3] as const) {
|
|
367
|
+
const args = { ...h.args, expectedSequence };
|
|
368
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
369
|
+
expect(await h.t.mutation(retain, args)).toEqual(h.retained);
|
|
370
|
+
}
|
|
371
|
+
} finally {
|
|
372
|
+
expect(await h.physical()).toEqual(after3);
|
|
373
|
+
expect(h.fetchCalls()).toBe(0);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
function alternateRawRecipe(): ConstructRenewalScheduleAttachmentReceiptV2Options {
|
|
377
|
+
const declared = receiptInput();
|
|
378
|
+
const wire = declared.actualDispatch;
|
|
379
|
+
assert(wire.scope === "platform" && wire.method === "POST");
|
|
380
|
+
assert(wire.path === "/v1/subscription_schedules");
|
|
381
|
+
return {
|
|
382
|
+
attachRequest: declared.attachRequest,
|
|
383
|
+
actualDispatch: {
|
|
384
|
+
scope: wire.scope,
|
|
385
|
+
apiVersion: wire.apiVersion,
|
|
386
|
+
method: wire.method,
|
|
387
|
+
path: wire.path,
|
|
388
|
+
payload: wire.payload,
|
|
389
|
+
key: wire.key,
|
|
390
|
+
firstDispatchedAt: wire.firstDispatchedAt,
|
|
391
|
+
},
|
|
392
|
+
providerSnapshot: {
|
|
393
|
+
...declared.providerSnapshot,
|
|
394
|
+
metadata: {
|
|
395
|
+
...declared.providerSnapshot.metadata,
|
|
396
|
+
opaque: "different-full-body",
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
it.each(["derived-other", "copied-known-binding"] as const)(
|
|
402
|
+
"ACK05 %s event3 cannot contradict the already retained whole receipt",
|
|
403
|
+
async (mode) => {
|
|
404
|
+
// The alternate raw response is declared BEFORE all C1/C2/C3 constructors.
|
|
405
|
+
const alternateRaw = alternateRawRecipe();
|
|
406
|
+
const h = await acknowledgementScenario("clean");
|
|
407
|
+
assert(h);
|
|
408
|
+
const alternate =
|
|
409
|
+
await constructRenewalScheduleAttachmentReceiptV2(alternateRaw);
|
|
410
|
+
expect(alternate.request).toEqual(h.request);
|
|
411
|
+
expect(alternate.binding).not.toBe(h.receipt.binding);
|
|
412
|
+
admitInitialOutput(alternate, h.prepared, h.request);
|
|
413
|
+
// Second mode is intentionally invalid host C3 DATA, not a constructor ACK.
|
|
414
|
+
// Its shape/hash capture alone cannot prove the complete receipt relation.
|
|
415
|
+
const candidate =
|
|
416
|
+
mode === "derived-other"
|
|
417
|
+
? alternate
|
|
418
|
+
: {
|
|
419
|
+
...alternate,
|
|
420
|
+
binding: h.receipt.binding,
|
|
421
|
+
};
|
|
422
|
+
const eventArgs = await thirdEventArgs(h, candidate);
|
|
423
|
+
const before = await h.physical();
|
|
424
|
+
let targetError: unknown;
|
|
425
|
+
try {
|
|
426
|
+
await expect(h.t.mutation(append, eventArgs)).rejects.toThrow(
|
|
427
|
+
"RENEWAL_JOURNAL_CONFLICT",
|
|
428
|
+
);
|
|
429
|
+
} catch (error) {
|
|
430
|
+
targetError = error;
|
|
431
|
+
throw error;
|
|
432
|
+
} finally {
|
|
433
|
+
try {
|
|
434
|
+
const after = await h.physical();
|
|
435
|
+
const physicalEqual = JSON.stringify(after) === JSON.stringify(before);
|
|
436
|
+
console.info(
|
|
437
|
+
"ACK05_SETTLEMENT",
|
|
438
|
+
JSON.stringify({
|
|
439
|
+
mode,
|
|
440
|
+
physicalEqual,
|
|
441
|
+
counts: Object.values(after).map((rows) => rows.length),
|
|
442
|
+
fetchCalls: h.fetchCalls(),
|
|
443
|
+
}),
|
|
444
|
+
);
|
|
445
|
+
expect(physicalEqual).toBe(true);
|
|
446
|
+
expect(h.fetchCalls()).toBe(0);
|
|
447
|
+
} catch (inspectionError) {
|
|
448
|
+
if (targetError !== undefined) throw targetError;
|
|
449
|
+
throw inspectionError;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
it("ACK06 a mismatched existing event3 cannot create known retention", async () => {
|
|
456
|
+
const raw = alternateRawRecipe();
|
|
457
|
+
const h = await prepareAcknowledgementScenario("clean");
|
|
458
|
+
const alternate = await constructRenewalScheduleAttachmentReceiptV2(raw);
|
|
459
|
+
admitInitialOutput(alternate, h.prepared, h.request);
|
|
460
|
+
const eventArgs = await thirdEventArgs(h, alternate);
|
|
461
|
+
const committed = await h.t.mutation(append, eventArgs);
|
|
462
|
+
expect(committed.sequence).toBe(3);
|
|
463
|
+
expect(committed.binding).toBe(eventArgs.event.binding);
|
|
464
|
+
expect(getConvexSize(committed)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
465
|
+
const before = await h.physical();
|
|
466
|
+
expect(Object.values(before).map((rows) => rows.length)).toEqual([
|
|
467
|
+
1, 1, 3, 4,
|
|
468
|
+
]);
|
|
469
|
+
expect(
|
|
470
|
+
Object.prototype.hasOwnProperty.call(
|
|
471
|
+
before.operations[0],
|
|
472
|
+
"knownAcknowledgement",
|
|
473
|
+
),
|
|
474
|
+
).toBe(false);
|
|
475
|
+
try {
|
|
476
|
+
await expect(
|
|
477
|
+
h.t.mutation(retain, { ...h.args, expectedSequence: 3 }),
|
|
478
|
+
).rejects.toThrow("RENEWAL_JOURNAL_CONFLICT");
|
|
479
|
+
} finally {
|
|
480
|
+
expect(await h.physical()).toEqual(before);
|
|
481
|
+
expect(h.fetchCalls()).toBe(0);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
it("ACK07 parent abort rolls back tentative receipt retention", async () => {
|
|
485
|
+
const h = await prepareAcknowledgementScenario("clean");
|
|
486
|
+
let received = false;
|
|
487
|
+
await expect(
|
|
488
|
+
h.t.mutation(async (ctx) => {
|
|
489
|
+
const retained = await ctx.runMutation(retain, h.args);
|
|
490
|
+
assert(retained);
|
|
491
|
+
expect(retained.status).toBe("retained");
|
|
492
|
+
expect(retained.operationId).toBe(h.queryArgs.operationId);
|
|
493
|
+
received = true;
|
|
494
|
+
throw Error("ACK_PARENT_ABORT_AFTER_RETAINED");
|
|
495
|
+
}),
|
|
496
|
+
).rejects.toThrow("ACK_PARENT_ABORT_AFTER_RETAINED");
|
|
497
|
+
expect(received).toBe(true);
|
|
498
|
+
expect(await h.physical()).toEqual(h.before);
|
|
499
|
+
expect(h.fetchCalls()).toBe(0);
|
|
500
|
+
});
|
|
501
|
+
it("ACK08 corrupted retained receipt owner refuses duplicate without repair", async () => {
|
|
502
|
+
const h = await acknowledgementScenario("clean");
|
|
503
|
+
assert(h);
|
|
504
|
+
await h.t.run((ctx) =>
|
|
505
|
+
ctx.db.patch("renewalOperationPayloads", h.retained.receiptPayloadId, {
|
|
506
|
+
owner: { kind: "operation", operationId: h.queryArgs.operationId },
|
|
507
|
+
}),
|
|
508
|
+
);
|
|
509
|
+
const before = await h.physical();
|
|
510
|
+
expect(
|
|
511
|
+
before.payloads.find((row) => row._id === h.retained.receiptPayloadId)
|
|
512
|
+
?.owner,
|
|
513
|
+
).toEqual({
|
|
514
|
+
kind: "operation",
|
|
515
|
+
operationId: h.queryArgs.operationId,
|
|
516
|
+
});
|
|
517
|
+
try {
|
|
518
|
+
await expect(h.t.mutation(retain, h.args)).rejects.toThrow(
|
|
519
|
+
"RENEWAL_JOURNAL_CONFLICT",
|
|
520
|
+
);
|
|
521
|
+
} finally {
|
|
522
|
+
expect(await h.physical()).toEqual(before);
|
|
523
|
+
expect(h.fetchCalls()).toBe(0);
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it.each(["fresh-stale2", "known-future3"] as const)(
|
|
528
|
+
"ACK09 %s refuses a sequence crossing the validated history head",
|
|
529
|
+
async (mode) => {
|
|
530
|
+
const h =
|
|
531
|
+
mode === "fresh-stale2"
|
|
532
|
+
? await prepareAcknowledgementScenario("clean")
|
|
533
|
+
: await acknowledgementScenario("clean");
|
|
534
|
+
assert(h);
|
|
535
|
+
if (mode === "fresh-stale2") {
|
|
536
|
+
const eventArgs = await thirdEventArgs(h, h.receipt);
|
|
537
|
+
const committed = await h.t.mutation(append, eventArgs);
|
|
538
|
+
expect(committed.sequence).toBe(3);
|
|
539
|
+
expect(committed.binding).toBe(eventArgs.event.binding);
|
|
540
|
+
expect(committed.reservation).toEqual(h.acquired.reservation);
|
|
541
|
+
expect(getConvexSize(committed)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
542
|
+
}
|
|
543
|
+
const before = await h.physical();
|
|
544
|
+
const head = mode === "fresh-stale2" ? 3 : 2;
|
|
545
|
+
expect(Object.values(before).map((rows) => rows.length)).toEqual([
|
|
546
|
+
1,
|
|
547
|
+
1,
|
|
548
|
+
head,
|
|
549
|
+
4,
|
|
550
|
+
]);
|
|
551
|
+
expect(before.attempts[0].lastSequence).toBe(head);
|
|
552
|
+
expect(
|
|
553
|
+
Object.prototype.hasOwnProperty.call(
|
|
554
|
+
before.operations[0],
|
|
555
|
+
"knownAcknowledgement",
|
|
556
|
+
),
|
|
557
|
+
).toBe(mode === "known-future3");
|
|
558
|
+
const expectedSequence: 2 | 3 = mode === "fresh-stale2" ? 2 : 3;
|
|
559
|
+
const args = { ...h.args, expectedSequence };
|
|
560
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
561
|
+
for (const rows of Object.values(before))
|
|
562
|
+
for (const row of rows)
|
|
563
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
564
|
+
try {
|
|
565
|
+
await expect(h.t.mutation(retain, args)).rejects.toThrow(
|
|
566
|
+
"RENEWAL_JOURNAL_CONFLICT",
|
|
567
|
+
);
|
|
568
|
+
} finally {
|
|
569
|
+
expect(await h.physical()).toEqual(before);
|
|
570
|
+
expect(h.fetchCalls()).toBe(0);
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
);
|