@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,493 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { makeFunctionReference } from "convex/server";
|
|
3
|
+
import { getConvexSize, getDocumentSize, type Infer } from "convex/values";
|
|
4
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
+
import type {
|
|
6
|
+
providerAcknowledgementReadResult,
|
|
7
|
+
retentionReceipt,
|
|
8
|
+
} from "./schema.js";
|
|
9
|
+
import {
|
|
10
|
+
prepareV2AcknowledgementScenario,
|
|
11
|
+
append,
|
|
12
|
+
retain,
|
|
13
|
+
canonical,
|
|
14
|
+
VALUE_LIMIT,
|
|
15
|
+
} from "./acknowledgement.fixtures.js";
|
|
16
|
+
|
|
17
|
+
const readAcknowledgement = makeFunctionReference<
|
|
18
|
+
"query",
|
|
19
|
+
{ operationId: Infer<typeof retentionReceipt>["operationId"] },
|
|
20
|
+
Infer<typeof providerAcknowledgementReadResult>
|
|
21
|
+
>("renewalOperations/queries:readProviderAcknowledgement");
|
|
22
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
23
|
+
|
|
24
|
+
it("ACKV201 retains full V2 attach DATA after actual basis and events1/2", async () => {
|
|
25
|
+
// Independent predeclared DATA expectations; no sampled runtime eligibility.
|
|
26
|
+
const policy = {
|
|
27
|
+
version: 1,
|
|
28
|
+
firstDispatchedAt: 1700000001,
|
|
29
|
+
periodStart: 1700000000,
|
|
30
|
+
periodEnd: 1702592000,
|
|
31
|
+
workEndWallMs: 1700000005000,
|
|
32
|
+
endWallMs: 1700000006000,
|
|
33
|
+
};
|
|
34
|
+
const basis = {
|
|
35
|
+
startWallMs: 1700000001000,
|
|
36
|
+
startNsDecimal: "1000000000",
|
|
37
|
+
workEndWallMs: 1700000005000,
|
|
38
|
+
workEndNsDecimal: "5000000000",
|
|
39
|
+
endWallMs: 1700000006000,
|
|
40
|
+
endNsDecimal: "6000000000",
|
|
41
|
+
};
|
|
42
|
+
const h = await prepareV2AcknowledgementScenario();
|
|
43
|
+
expect(h.scenario).toBe("clean");
|
|
44
|
+
expect(h.shouldRetain).toBe(true);
|
|
45
|
+
const operation = h.before.operations[0];
|
|
46
|
+
const initialBasis = {
|
|
47
|
+
version: 1,
|
|
48
|
+
attemptId: h.acquired.reservation.attemptId,
|
|
49
|
+
sourcePayloadId: h.acquired.reservation.payloadId,
|
|
50
|
+
stage: "attach",
|
|
51
|
+
policyJSON: canonical(policy),
|
|
52
|
+
basisJSON: canonical(basis),
|
|
53
|
+
};
|
|
54
|
+
expect(operation.recordVersion).toBe(2);
|
|
55
|
+
expect(operation.initialBasis).toEqual(initialBasis);
|
|
56
|
+
const source = h.before.payloads.find(
|
|
57
|
+
(row) => row._id === h.acquired.reservation.payloadId,
|
|
58
|
+
);
|
|
59
|
+
assert(source);
|
|
60
|
+
const record = JSON.parse(source.json);
|
|
61
|
+
expect(record.schemaVersion).toBe(2);
|
|
62
|
+
expect(record.timingPolicy).toEqual(policy);
|
|
63
|
+
expect(Object.prototype.hasOwnProperty.call(record, "basis")).toBe(false);
|
|
64
|
+
expect(record.attachRequest).toEqual(h.raw.attachRequest);
|
|
65
|
+
// Whole source equality includes its opaque bundle, without a layout gate.
|
|
66
|
+
expect(source.json).toBe(h.acquired.reservation.recordJSON);
|
|
67
|
+
expect(h.commits.map((event) => event.sequence)).toEqual([1, 2]);
|
|
68
|
+
expect(h.before.attempts[0].lastSequence).toBe(2);
|
|
69
|
+
expect(h.before.events.map((event) => event.sequence)).toEqual([1, 2]);
|
|
70
|
+
expect(Object.values(h.before).map((rows) => rows.length)).toEqual([
|
|
71
|
+
1, 1, 2, 3,
|
|
72
|
+
]);
|
|
73
|
+
expect(operation.knownAcknowledgement).toBeUndefined();
|
|
74
|
+
expect(getConvexSize(h.args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
75
|
+
let stable = h.before;
|
|
76
|
+
let targetFailed = false;
|
|
77
|
+
try {
|
|
78
|
+
// Real retention route after every owned/basis/history prerequisite above.
|
|
79
|
+
const retained = await h.t.mutation(retain, h.args);
|
|
80
|
+
assert(retained !== null);
|
|
81
|
+
const known = {
|
|
82
|
+
schemaVersion: 1,
|
|
83
|
+
stage: "attach",
|
|
84
|
+
attemptId: h.acquired.reservation.attemptId,
|
|
85
|
+
sourcePayloadId: h.acquired.reservation.payloadId,
|
|
86
|
+
dispatchEventId: h.commits[0].eventId,
|
|
87
|
+
dispatchPayloadId: h.commits[0].payloadId,
|
|
88
|
+
responseEventId: h.commits[1].eventId,
|
|
89
|
+
responsePayloadId: h.commits[1].payloadId,
|
|
90
|
+
receiptPayloadId: retained.receiptPayloadId,
|
|
91
|
+
receiptBinding: h.receipt.binding,
|
|
92
|
+
};
|
|
93
|
+
expect(retained).toEqual({
|
|
94
|
+
status: "retained",
|
|
95
|
+
...h.queryArgs,
|
|
96
|
+
...known,
|
|
97
|
+
});
|
|
98
|
+
expect(getConvexSize(retained)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
99
|
+
const after = await h.physical();
|
|
100
|
+
stable = after;
|
|
101
|
+
expect(Object.values(after).map((rows) => rows.length)).toEqual([
|
|
102
|
+
1, 1, 2, 4,
|
|
103
|
+
]);
|
|
104
|
+
expect(after.operations).toEqual([
|
|
105
|
+
{ ...operation, knownAcknowledgement: known },
|
|
106
|
+
]);
|
|
107
|
+
expect(after.operations[0].initialBasis).toEqual(initialBasis);
|
|
108
|
+
expect(after.attempts).toEqual(h.before.attempts);
|
|
109
|
+
expect(after.events).toEqual(h.before.events);
|
|
110
|
+
for (const original of h.before.payloads)
|
|
111
|
+
expect(after.payloads.find((row) => row._id === original._id)).toEqual(
|
|
112
|
+
original,
|
|
113
|
+
);
|
|
114
|
+
const added = after.payloads.filter(
|
|
115
|
+
(row) => !h.before.payloads.some((original) => original._id === row._id),
|
|
116
|
+
);
|
|
117
|
+
expect(added).toHaveLength(1);
|
|
118
|
+
const receiptPayload = added[0];
|
|
119
|
+
expect(Number.isFinite(receiptPayload._creationTime)).toBe(true);
|
|
120
|
+
expect(receiptPayload).toEqual({
|
|
121
|
+
_id: retained.receiptPayloadId,
|
|
122
|
+
_creationTime: receiptPayload._creationTime,
|
|
123
|
+
codecVersion: 1,
|
|
124
|
+
json: h.receiptJSON,
|
|
125
|
+
owner: { kind: "receipt", ...h.ownerScope },
|
|
126
|
+
});
|
|
127
|
+
expect(JSON.parse(receiptPayload.json)).toEqual(h.receipt);
|
|
128
|
+
expect(after.events.some((event) => event.sequence === 3)).toBe(false);
|
|
129
|
+
for (const rows of Object.values(after))
|
|
130
|
+
for (const row of rows)
|
|
131
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
132
|
+
const queryArgs = { operationId: retained.operationId };
|
|
133
|
+
expect(getConvexSize(queryArgs)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
134
|
+
const loaded = await h.t.query(readAcknowledgement, queryArgs);
|
|
135
|
+
expect(getConvexSize(loaded)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
136
|
+
expect(loaded).toEqual({ retention: retained, receiptJSON: h.receiptJSON });
|
|
137
|
+
expect(await h.physical()).toEqual(after);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
targetFailed = true;
|
|
140
|
+
throw error;
|
|
141
|
+
} finally {
|
|
142
|
+
try {
|
|
143
|
+
const after = await h.physical();
|
|
144
|
+
console.info(
|
|
145
|
+
"ACKV201_SETTLEMENT",
|
|
146
|
+
JSON.stringify({
|
|
147
|
+
physicalEqual: JSON.stringify(after) === JSON.stringify(stable),
|
|
148
|
+
counts: Object.values(after).map((rows) => rows.length),
|
|
149
|
+
lastSequence: after.attempts[0]?.lastSequence,
|
|
150
|
+
fetchCalls: h.fetchCalls(),
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
expect(after).toEqual(stable);
|
|
154
|
+
expect(h.fetchCalls()).toBe(0);
|
|
155
|
+
} catch (inspectionError) {
|
|
156
|
+
if (!targetFailed) throw inspectionError;
|
|
157
|
+
console.info("ACKV201_READONLY_INSPECTION_FAILED");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const bind = makeFunctionReference<"mutation">(
|
|
163
|
+
"renewalOperations/mutations:bindInitialBasis",
|
|
164
|
+
);
|
|
165
|
+
const load = makeFunctionReference<"query">(
|
|
166
|
+
"renewalOperations/queries:loadAuthorizedOperation",
|
|
167
|
+
);
|
|
168
|
+
const manifest = makeFunctionReference<"query">(
|
|
169
|
+
"renewalOperations/queries:readAttempt",
|
|
170
|
+
);
|
|
171
|
+
const readEvent = makeFunctionReference<"query">(
|
|
172
|
+
"renewalOperations/queries:readStageEvent",
|
|
173
|
+
);
|
|
174
|
+
const reserve = makeFunctionReference<"mutation">(
|
|
175
|
+
"renewalOperations/mutations:reserveAttempt",
|
|
176
|
+
);
|
|
177
|
+
const create = makeFunctionReference<"mutation">(
|
|
178
|
+
"renewalOperations/mutations:createAuthorizedOperation",
|
|
179
|
+
);
|
|
180
|
+
const contradictoryValue = "different-retained-full-body";
|
|
181
|
+
const corruptions = [
|
|
182
|
+
"known-ref",
|
|
183
|
+
"receipt-owner",
|
|
184
|
+
"receipt-body",
|
|
185
|
+
"missing-payload",
|
|
186
|
+
] as const;
|
|
187
|
+
|
|
188
|
+
async function retainedScenario() {
|
|
189
|
+
const h = await prepareV2AcknowledgementScenario();
|
|
190
|
+
expect(h.scenario).toBe("clean");
|
|
191
|
+
expect(h.shouldRetain).toBe(true);
|
|
192
|
+
expect(h.before.operations[0].recordVersion).toBe(2);
|
|
193
|
+
const initialBasis = h.before.operations[0].initialBasis;
|
|
194
|
+
assert(initialBasis);
|
|
195
|
+
expect(h.before.attempts[0].lastSequence).toBe(2);
|
|
196
|
+
expect(h.commits.map((row) => row.sequence)).toEqual([1, 2]);
|
|
197
|
+
const retained = await h.t.mutation(retain, h.args);
|
|
198
|
+
assert(retained !== null);
|
|
199
|
+
const known = {
|
|
200
|
+
schemaVersion: 1 as const,
|
|
201
|
+
stage: "attach" as const,
|
|
202
|
+
attemptId: h.acquired.reservation.attemptId,
|
|
203
|
+
sourcePayloadId: h.acquired.reservation.payloadId,
|
|
204
|
+
dispatchEventId: h.commits[0].eventId,
|
|
205
|
+
dispatchPayloadId: h.commits[0].payloadId,
|
|
206
|
+
responseEventId: h.commits[1].eventId,
|
|
207
|
+
responsePayloadId: h.commits[1].payloadId,
|
|
208
|
+
receiptPayloadId: retained.receiptPayloadId,
|
|
209
|
+
receiptBinding: h.receipt.binding,
|
|
210
|
+
};
|
|
211
|
+
expect(retained).toEqual({ status: "retained", ...h.queryArgs, ...known });
|
|
212
|
+
expect(getConvexSize(retained)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
213
|
+
const after = await h.physical();
|
|
214
|
+
expect(Object.values(after).map((rows) => rows.length)).toEqual([1, 1, 2, 4]);
|
|
215
|
+
expect(after.operations).toEqual([
|
|
216
|
+
{ ...h.before.operations[0], knownAcknowledgement: known },
|
|
217
|
+
]);
|
|
218
|
+
expect(after.attempts).toEqual(h.before.attempts);
|
|
219
|
+
expect(after.events).toEqual(h.before.events);
|
|
220
|
+
for (const old of h.before.payloads)
|
|
221
|
+
expect(after.payloads.find((row) => row._id === old._id)).toEqual(old);
|
|
222
|
+
const payload = after.payloads.find(
|
|
223
|
+
(row) => row._id === retained.receiptPayloadId,
|
|
224
|
+
);
|
|
225
|
+
assert(payload);
|
|
226
|
+
expect(payload).toEqual({
|
|
227
|
+
_id: retained.receiptPayloadId,
|
|
228
|
+
_creationTime: payload._creationTime,
|
|
229
|
+
codecVersion: 1,
|
|
230
|
+
json: h.receiptJSON,
|
|
231
|
+
owner: { kind: "receipt", ...h.ownerScope },
|
|
232
|
+
});
|
|
233
|
+
for (const group of Object.values(after))
|
|
234
|
+
for (const row of group)
|
|
235
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
236
|
+
const expectedRead = { retention: retained, receiptJSON: h.receiptJSON };
|
|
237
|
+
expect(await h.t.query(readAcknowledgement, h.queryArgs)).toEqual(
|
|
238
|
+
expectedRead,
|
|
239
|
+
);
|
|
240
|
+
const { recordJSON, ...summary } = h.acquired.reservation;
|
|
241
|
+
const loaded = await h.t.query(load, h.queryArgs);
|
|
242
|
+
expect(loaded).toEqual({
|
|
243
|
+
recordVersion: 2,
|
|
244
|
+
...h.queryArgs,
|
|
245
|
+
recordJSON,
|
|
246
|
+
revision: 1,
|
|
247
|
+
activeAttempt: summary,
|
|
248
|
+
initialBasis,
|
|
249
|
+
});
|
|
250
|
+
const bindArgs = {
|
|
251
|
+
...h.queryArgs,
|
|
252
|
+
attemptId: known.attemptId,
|
|
253
|
+
policyJSON: initialBasis.policyJSON,
|
|
254
|
+
basisJSON: initialBasis.basisJSON,
|
|
255
|
+
};
|
|
256
|
+
const historyArgs = { ...h.queryArgs, attemptId: known.attemptId };
|
|
257
|
+
const reserveArgs = {
|
|
258
|
+
...h.queryArgs,
|
|
259
|
+
expectedRevision: 0,
|
|
260
|
+
stage: "attach" as const,
|
|
261
|
+
expectedRequestBinding: h.acquired.reservation.requestBinding,
|
|
262
|
+
recordJSON,
|
|
263
|
+
};
|
|
264
|
+
const createArgs = {
|
|
265
|
+
authorizationScope: h.acquired.reservation.authorizationScope,
|
|
266
|
+
logicalOperationId: h.acquired.reservation.logicalOperationId,
|
|
267
|
+
authorizationRevision: h.acquired.reservation.authorizationRevision,
|
|
268
|
+
recordJSON,
|
|
269
|
+
};
|
|
270
|
+
const first = h.before.payloads.find(
|
|
271
|
+
(row) => row._id === known.dispatchPayloadId,
|
|
272
|
+
);
|
|
273
|
+
assert(first);
|
|
274
|
+
const duplicateArgs = {
|
|
275
|
+
reservation: h.acquired.reservation,
|
|
276
|
+
expectedSequence: 0,
|
|
277
|
+
event: {
|
|
278
|
+
sequence: 1 as const,
|
|
279
|
+
binding: h.commits[0].binding,
|
|
280
|
+
dataJSON: first.json,
|
|
281
|
+
},
|
|
282
|
+
};
|
|
283
|
+
for (const args of [
|
|
284
|
+
bindArgs,
|
|
285
|
+
historyArgs,
|
|
286
|
+
reserveArgs,
|
|
287
|
+
createArgs,
|
|
288
|
+
duplicateArgs,
|
|
289
|
+
{ ...historyArgs, sequence: 3 },
|
|
290
|
+
])
|
|
291
|
+
expect(getConvexSize(args)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
292
|
+
expect(getConvexSize(loaded)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
293
|
+
expect(getConvexSize(expectedRead)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
294
|
+
expect(await h.physical()).toEqual(after);
|
|
295
|
+
expect(h.fetchCalls()).toBe(0);
|
|
296
|
+
return {
|
|
297
|
+
...h,
|
|
298
|
+
retained,
|
|
299
|
+
known,
|
|
300
|
+
after,
|
|
301
|
+
expectedRead,
|
|
302
|
+
loaded,
|
|
303
|
+
bindArgs,
|
|
304
|
+
historyArgs,
|
|
305
|
+
reserveArgs,
|
|
306
|
+
createArgs,
|
|
307
|
+
duplicateArgs,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
type Retained = Awaited<ReturnType<typeof retainedScenario>>;
|
|
312
|
+
function contradictoryReceipt(h: Retained) {
|
|
313
|
+
const metadata = h.receipt.providerSnapshot.metadata;
|
|
314
|
+
assert(metadata && typeof metadata === "object" && !Array.isArray(metadata));
|
|
315
|
+
return {
|
|
316
|
+
...h.receipt,
|
|
317
|
+
providerSnapshot: {
|
|
318
|
+
...h.receipt.providerSnapshot,
|
|
319
|
+
metadata: { ...metadata, opaque: contradictoryValue },
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
async function inspectStable(
|
|
324
|
+
h: Retained,
|
|
325
|
+
rows: Retained["after"],
|
|
326
|
+
failed: boolean,
|
|
327
|
+
label: string,
|
|
328
|
+
) {
|
|
329
|
+
try {
|
|
330
|
+
expect(await h.physical()).toEqual(rows);
|
|
331
|
+
expect(h.fetchCalls()).toBe(0);
|
|
332
|
+
} catch (error) {
|
|
333
|
+
if (!failed) throw error;
|
|
334
|
+
console.info(label);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
async function checkStableKnown(h: Retained) {
|
|
338
|
+
const events = h.commits.map(({ reservation, ...event }) => {
|
|
339
|
+
expect(reservation).toEqual(h.acquired.reservation);
|
|
340
|
+
return event;
|
|
341
|
+
});
|
|
342
|
+
const settled = await Promise.allSettled([
|
|
343
|
+
h.t.mutation(retain, h.args),
|
|
344
|
+
h.t.mutation(bind, h.bindArgs),
|
|
345
|
+
h.t.query(readAcknowledgement, h.queryArgs),
|
|
346
|
+
h.t.query(load, h.queryArgs),
|
|
347
|
+
h.t.query(manifest, h.historyArgs),
|
|
348
|
+
h.t.query(readEvent, { ...h.historyArgs, sequence: 3 }),
|
|
349
|
+
h.t.mutation(reserve, h.reserveArgs),
|
|
350
|
+
h.t.mutation(create, h.createArgs),
|
|
351
|
+
h.t.mutation(append, h.duplicateArgs),
|
|
352
|
+
]);
|
|
353
|
+
const values = settled.map((item) => {
|
|
354
|
+
if (item.status !== "fulfilled") throw item.reason;
|
|
355
|
+
expect(getConvexSize(item.value)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
356
|
+
return item.value;
|
|
357
|
+
});
|
|
358
|
+
expect(values).toEqual([
|
|
359
|
+
h.retained,
|
|
360
|
+
{ status: "bound", ...h.queryArgs, initialBasis: h.loaded.initialBasis },
|
|
361
|
+
h.expectedRead,
|
|
362
|
+
h.loaded,
|
|
363
|
+
{ reservation: h.acquired.reservation, events },
|
|
364
|
+
null,
|
|
365
|
+
{
|
|
366
|
+
disposition: "existing",
|
|
367
|
+
committedRevision: 1,
|
|
368
|
+
reservation: h.acquired.reservation,
|
|
369
|
+
},
|
|
370
|
+
{ status: "existing", ...h.queryArgs },
|
|
371
|
+
h.commits[0],
|
|
372
|
+
]);
|
|
373
|
+
expect(await h.physical()).toEqual(h.after);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
it("ACKV202 keeps head2 retain, basis and full reads stable before event3", async () => {
|
|
377
|
+
const h = await retainedScenario();
|
|
378
|
+
let targetFailed = false;
|
|
379
|
+
try {
|
|
380
|
+
await checkStableKnown(h);
|
|
381
|
+
} catch (error) {
|
|
382
|
+
targetFailed = true;
|
|
383
|
+
throw error;
|
|
384
|
+
} finally {
|
|
385
|
+
await inspectStable(h, h.after, targetFailed, "ACKV202_INSPECTION_FAILED");
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it.each(corruptions)(
|
|
390
|
+
"ACKV205 refuses %s known corruption through all eight APIs",
|
|
391
|
+
async (kind) => {
|
|
392
|
+
const h = await retainedScenario();
|
|
393
|
+
await checkStableKnown(h);
|
|
394
|
+
let expected = h.after;
|
|
395
|
+
if (kind === "known-ref") {
|
|
396
|
+
const knownAcknowledgement = {
|
|
397
|
+
...h.known,
|
|
398
|
+
dispatchEventId: h.known.responseEventId,
|
|
399
|
+
};
|
|
400
|
+
await h.t.run((ctx) =>
|
|
401
|
+
ctx.db.patch("renewalOperations", h.retained.operationId, {
|
|
402
|
+
knownAcknowledgement,
|
|
403
|
+
}),
|
|
404
|
+
);
|
|
405
|
+
expected = {
|
|
406
|
+
...expected,
|
|
407
|
+
operations: [{ ...expected.operations[0], knownAcknowledgement }],
|
|
408
|
+
};
|
|
409
|
+
} else if (kind === "receipt-owner") {
|
|
410
|
+
const owner = {
|
|
411
|
+
kind: "receipt" as const,
|
|
412
|
+
...h.ownerScope,
|
|
413
|
+
stage: "configure" as const,
|
|
414
|
+
};
|
|
415
|
+
await h.t.run((ctx) =>
|
|
416
|
+
ctx.db.patch("renewalOperationPayloads", h.retained.receiptPayloadId, {
|
|
417
|
+
owner,
|
|
418
|
+
}),
|
|
419
|
+
);
|
|
420
|
+
expected = {
|
|
421
|
+
...expected,
|
|
422
|
+
payloads: expected.payloads.map((row) =>
|
|
423
|
+
row._id === h.retained.receiptPayloadId ? { ...row, owner } : row,
|
|
424
|
+
),
|
|
425
|
+
};
|
|
426
|
+
} else if (kind === "receipt-body") {
|
|
427
|
+
const json = canonical(contradictoryReceipt(h));
|
|
428
|
+
expect(json).not.toBe(h.receiptJSON);
|
|
429
|
+
await h.t.run((ctx) =>
|
|
430
|
+
ctx.db.patch("renewalOperationPayloads", h.retained.receiptPayloadId, {
|
|
431
|
+
json,
|
|
432
|
+
}),
|
|
433
|
+
);
|
|
434
|
+
expected = {
|
|
435
|
+
...expected,
|
|
436
|
+
payloads: expected.payloads.map((row) =>
|
|
437
|
+
row._id === h.retained.receiptPayloadId ? { ...row, json } : row,
|
|
438
|
+
),
|
|
439
|
+
};
|
|
440
|
+
} else if (kind === "missing-payload") {
|
|
441
|
+
await h.t.run((ctx) =>
|
|
442
|
+
ctx.db.delete("renewalOperationPayloads", h.retained.receiptPayloadId),
|
|
443
|
+
);
|
|
444
|
+
expected = {
|
|
445
|
+
...expected,
|
|
446
|
+
payloads: expected.payloads.filter(
|
|
447
|
+
(row) => row._id !== h.retained.receiptPayloadId,
|
|
448
|
+
),
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
const damaged = await h.physical();
|
|
452
|
+
expect(damaged).toEqual(expected);
|
|
453
|
+
for (const group of Object.values(damaged)) {
|
|
454
|
+
for (const row of group)
|
|
455
|
+
expect(getDocumentSize(row)).toBeLessThanOrEqual(VALUE_LIMIT);
|
|
456
|
+
}
|
|
457
|
+
let targetFailed = false;
|
|
458
|
+
try {
|
|
459
|
+
const settled = await Promise.allSettled([
|
|
460
|
+
h.t.query(load, h.queryArgs),
|
|
461
|
+
h.t.query(manifest, h.historyArgs),
|
|
462
|
+
h.t.query(readEvent, { ...h.historyArgs, sequence: 3 }),
|
|
463
|
+
h.t.query(readAcknowledgement, h.queryArgs),
|
|
464
|
+
h.t.mutation(reserve, h.reserveArgs),
|
|
465
|
+
h.t.mutation(bind, h.bindArgs),
|
|
466
|
+
h.t.mutation(create, h.createArgs),
|
|
467
|
+
h.t.mutation(append, h.duplicateArgs),
|
|
468
|
+
]);
|
|
469
|
+
console.info(
|
|
470
|
+
"ACKV205_SETTLEMENT",
|
|
471
|
+
JSON.stringify({ kind, statuses: settled.map((item) => item.status) }),
|
|
472
|
+
);
|
|
473
|
+
expect(settled).toEqual(
|
|
474
|
+
Array.from({ length: 8 }, () => ({
|
|
475
|
+
status: "rejected",
|
|
476
|
+
reason: expect.objectContaining({
|
|
477
|
+
message: "RENEWAL_JOURNAL_CONFLICT",
|
|
478
|
+
}),
|
|
479
|
+
})),
|
|
480
|
+
);
|
|
481
|
+
} catch (error) {
|
|
482
|
+
targetFailed = true;
|
|
483
|
+
throw error;
|
|
484
|
+
} finally {
|
|
485
|
+
await inspectStable(
|
|
486
|
+
h,
|
|
487
|
+
damaged,
|
|
488
|
+
targetFailed,
|
|
489
|
+
"ACKV205_INSPECTION_FAILED",
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
);
|