@fantastic.dev/better-stripe 0.100.0 → 0.102.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/producer/classOwnedActionRoot.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.js +117 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAdmission.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +53 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +198 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts +959 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.js +115 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureLineage.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +18 -18
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +9 -9
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +50 -50
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +25 -25
- package/dist/component/balanceFunding/mutations.d.ts +27 -27
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +22 -22
- 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/attachValidation.d.ts +19 -0
- package/dist/component/renewalOperations/attachValidation.d.ts.map +1 -0
- package/dist/component/renewalOperations/attachValidation.js +167 -0
- package/dist/component/renewalOperations/attachValidation.js.map +1 -0
- package/dist/component/renewalOperations/configureAcknowledgement.d.ts +13 -0
- package/dist/component/renewalOperations/configureAcknowledgement.d.ts.map +1 -0
- package/dist/component/renewalOperations/configureAcknowledgement.js +108 -0
- package/dist/component/renewalOperations/configureAcknowledgement.js.map +1 -0
- package/dist/component/renewalOperations/configureParent.d.ts +10 -0
- package/dist/component/renewalOperations/configureParent.d.ts.map +1 -0
- package/dist/component/renewalOperations/configureParent.js +62 -0
- package/dist/component/renewalOperations/configureParent.js.map +1 -0
- package/dist/component/renewalOperations/configureValidation.d.ts +12 -0
- package/dist/component/renewalOperations/configureValidation.d.ts.map +1 -0
- package/dist/component/renewalOperations/configureValidation.js +64 -0
- package/dist/component/renewalOperations/configureValidation.js.map +1 -0
- package/dist/component/renewalOperations/helpers.d.ts +16 -21
- package/dist/component/renewalOperations/helpers.d.ts.map +1 -1
- package/dist/component/renewalOperations/helpers.js +13 -169
- package/dist/component/renewalOperations/helpers.js.map +1 -1
- package/dist/component/renewalOperations/mutations.d.ts +6 -6
- package/dist/component/renewalOperations/mutations.d.ts.map +1 -1
- package/dist/component/renewalOperations/mutations.js +14 -7
- package/dist/component/renewalOperations/mutations.js.map +1 -1
- package/dist/component/renewalOperations/operationContext.d.ts +12 -0
- package/dist/component/renewalOperations/operationContext.d.ts.map +1 -0
- package/dist/component/renewalOperations/operationContext.js +14 -0
- package/dist/component/renewalOperations/operationContext.js.map +1 -0
- package/dist/component/renewalOperations/queries.d.ts +4 -4
- package/dist/component/renewalOperations/queries.js +2 -1
- package/dist/component/renewalOperations/queries.js.map +1 -1
- package/dist/component/renewalOperations/schema.d.ts +59 -59
- package/dist/component/renewalOperations/schema.js +3 -3
- package/dist/component/renewalOperations/schema.js.map +1 -1
- package/dist/component/renewalOperations/stageAcknowledgement.d.ts +15 -0
- package/dist/component/renewalOperations/stageAcknowledgement.d.ts.map +1 -0
- package/dist/component/renewalOperations/stageAcknowledgement.js +20 -0
- package/dist/component/renewalOperations/stageAcknowledgement.js.map +1 -0
- package/dist/component/renewalOperations/validationTypes.d.ts +9 -0
- package/dist/component/renewalOperations/validationTypes.d.ts.map +1 -0
- package/dist/component/renewalOperations/validationTypes.js +2 -0
- package/dist/component/renewalOperations/validationTypes.js.map +1 -0
- package/dist/component/schema.d.ts +9 -9
- package/dist/component/usage/allowance.fixtures.d.ts +25 -25
- package/dist/component/usageCredits/accounting.fixtures.d.ts +9 -9
- package/dist/shared/renewalOperationJournal.d.ts +1 -1
- package/dist/shared/renewalOperationJournal.d.ts.map +1 -1
- package/dist/shared/renewalOperationJournal.js +41 -9
- package/dist/shared/renewalOperationJournal.js.map +1 -1
- package/docs/renewal-context-reads.md +81 -11
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/producer/classOwnedActionRoot.ts +21 -0
- package/src/client/billing/renewalAttach/internal/producer/configureAdmission.ts +179 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +248 -0
- package/src/client/billing/renewalAttach/internal/producer/configureLineage.ts +166 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +13 -0
- package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +2 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureAdmission.integration.test.ts +203 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureControls.integration.test.ts +566 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +316 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +61 -3
- package/src/component/renewalOperations/attachValidation.ts +203 -0
- package/src/component/renewalOperations/configureAcknowledgement.test.ts +30 -0
- package/src/component/renewalOperations/configureAcknowledgement.ts +182 -0
- package/src/component/renewalOperations/configureAcknowledgementControls.test.ts +96 -0
- package/src/component/renewalOperations/configureBasis.test.ts +77 -0
- package/src/component/renewalOperations/configureCreation.test.ts +75 -0
- package/src/component/renewalOperations/configureJournal.fixtures.ts +385 -0
- package/src/component/renewalOperations/configureParent.ts +71 -0
- package/src/component/renewalOperations/configurePolicy.test.ts +105 -0
- package/src/component/renewalOperations/configurePublication.test.ts +85 -0
- package/src/component/renewalOperations/configureReceiptBounds.test.ts +39 -0
- package/src/component/renewalOperations/configureSourceControls.test.ts +65 -0
- package/src/component/renewalOperations/configureValidation.ts +70 -0
- package/src/component/renewalOperations/helpers.ts +21 -204
- package/src/component/renewalOperations/mutations.ts +16 -7
- package/src/component/renewalOperations/operationContext.ts +21 -0
- package/src/component/renewalOperations/queries.ts +1 -1
- package/src/component/renewalOperations/schema.ts +3 -3
- package/src/component/renewalOperations/stageAcknowledgement.ts +45 -0
- package/src/component/renewalOperations/validationTypes.ts +9 -0
- package/src/shared/renewalOperationJournal.ts +49 -8
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { constructRenewalConfigurationReceiptV2 } from "../../client/billing/renewalV2/index.js";
|
|
2
|
+
import {
|
|
3
|
+
captureConfigureDispatch,
|
|
4
|
+
captureConfigureResponse,
|
|
5
|
+
captureConfigureReceipt,
|
|
6
|
+
} from "../../client/billing/renewalAttach/internal/c10/eventCapture.js";
|
|
7
|
+
import { requiredJSONSnapshot } from "../../client/billing/renewalAttach/internal/material/requiredJson.js";
|
|
8
|
+
import { renewalSnapshot } from "../../client/billing/renewalReplacementSnapshot.js";
|
|
9
|
+
import { equal } from "../../client/billing/renewalAggregate/shared.js";
|
|
10
|
+
import type { canonicalJournalRecord } from "../../shared/renewalOperationJournal.js";
|
|
11
|
+
import type { Reservation, CheckedEvents } from "./validationTypes.js";
|
|
12
|
+
import {
|
|
13
|
+
validateOperationalConfigureSource,
|
|
14
|
+
configureConflict,
|
|
15
|
+
jsonObject,
|
|
16
|
+
} from "./configureValidation.js";
|
|
17
|
+
|
|
18
|
+
type Receipt = Awaited<
|
|
19
|
+
ReturnType<typeof constructRenewalConfigurationReceiptV2>
|
|
20
|
+
>;
|
|
21
|
+
function admitReceipt(receiptJSON: string, rebuilt: Receipt) {
|
|
22
|
+
if (
|
|
23
|
+
receiptJSON.length > 500000 ||
|
|
24
|
+
new TextEncoder().encode(receiptJSON).length > 500000
|
|
25
|
+
)
|
|
26
|
+
configureConflict();
|
|
27
|
+
const parsed: unknown = JSON.parse(receiptJSON);
|
|
28
|
+
if (!equal(parsed, rebuilt)) configureConflict();
|
|
29
|
+
const output = renewalSnapshot({
|
|
30
|
+
status: "configure_acknowledged",
|
|
31
|
+
operationalAuthority: false,
|
|
32
|
+
receipt: parsed,
|
|
33
|
+
});
|
|
34
|
+
const slots = new Map<string, { expected: string; family: string }>();
|
|
35
|
+
const add = (path: string[], expected: string, family: string) =>
|
|
36
|
+
slots.set(JSON.stringify(["receipt", ...path]), { expected, family });
|
|
37
|
+
add(["logicalBinding"], rebuilt.logicalBinding, "renewal");
|
|
38
|
+
add(
|
|
39
|
+
["attachReceiptBinding"],
|
|
40
|
+
rebuilt.attachReceiptBinding,
|
|
41
|
+
"renewal-attach-receipt",
|
|
42
|
+
);
|
|
43
|
+
add(
|
|
44
|
+
["providerSnapshotBinding"],
|
|
45
|
+
rebuilt.providerSnapshotBinding,
|
|
46
|
+
"renewal-configured-baseline",
|
|
47
|
+
);
|
|
48
|
+
add(["binding"], rebuilt.binding, "renewal-configure-receipt");
|
|
49
|
+
if (rebuilt.defaultSettingsBinding !== undefined)
|
|
50
|
+
add(
|
|
51
|
+
["defaultSettingsBinding"],
|
|
52
|
+
rebuilt.defaultSettingsBinding,
|
|
53
|
+
"renewal-configured-defaults",
|
|
54
|
+
);
|
|
55
|
+
add(["request", "logicalBinding"], rebuilt.request.logicalBinding, "renewal");
|
|
56
|
+
add(
|
|
57
|
+
["request", "attachReceiptBinding"],
|
|
58
|
+
rebuilt.request.attachReceiptBinding,
|
|
59
|
+
"renewal-attach-receipt",
|
|
60
|
+
);
|
|
61
|
+
add(
|
|
62
|
+
["request", "baselineBinding"],
|
|
63
|
+
rebuilt.request.baselineBinding,
|
|
64
|
+
"renewal-baseline",
|
|
65
|
+
);
|
|
66
|
+
add(
|
|
67
|
+
["request", "defaultSettingsBinding"],
|
|
68
|
+
rebuilt.request.defaultSettingsBinding,
|
|
69
|
+
"renewal-defaults",
|
|
70
|
+
);
|
|
71
|
+
add(
|
|
72
|
+
["request", "requestIdentity", "binding"],
|
|
73
|
+
rebuilt.request.requestIdentity.binding,
|
|
74
|
+
"renewal-configure",
|
|
75
|
+
);
|
|
76
|
+
const found = new Set<string>();
|
|
77
|
+
function walk(value: unknown, path: string[]) {
|
|
78
|
+
const key = JSON.stringify(path),
|
|
79
|
+
slot = slots.get(key);
|
|
80
|
+
if (slot) {
|
|
81
|
+
if (
|
|
82
|
+
value !== slot.expected ||
|
|
83
|
+
typeof value !== "string" ||
|
|
84
|
+
!new RegExp("^" + slot.family + ":v2:sha256:[0-9a-f]{64}$").test(value)
|
|
85
|
+
)
|
|
86
|
+
configureConflict();
|
|
87
|
+
found.add(key);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (value === null || typeof value !== "object") {
|
|
91
|
+
requiredJSONSnapshot(value);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (const [name, child] of Object.entries(value)) {
|
|
95
|
+
requiredJSONSnapshot(name);
|
|
96
|
+
requiredJSONSnapshot({ [name]: child === null ? null : true });
|
|
97
|
+
walk(child, [...path, name]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
walk(output, []);
|
|
101
|
+
if (
|
|
102
|
+
found.size !== slots.size ||
|
|
103
|
+
new TextEncoder().encode(JSON.stringify(output)).length > 500000
|
|
104
|
+
)
|
|
105
|
+
configureConflict();
|
|
106
|
+
return JSON.stringify(output.receipt);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Complete C9 DATA against checked C3/C6/C7 source and actual stored events. */
|
|
110
|
+
export async function validateConfigureAcknowledgement(
|
|
111
|
+
full: ReturnType<typeof canonicalJournalRecord>,
|
|
112
|
+
reservation: Reservation,
|
|
113
|
+
events: CheckedEvents,
|
|
114
|
+
receiptJSON: string,
|
|
115
|
+
) {
|
|
116
|
+
if (
|
|
117
|
+
!("recordVersion" in reservation) ||
|
|
118
|
+
reservation.stage !== "configure" ||
|
|
119
|
+
(events.length !== 2 && events.length !== 3) ||
|
|
120
|
+
events[0].sequence !== 1 ||
|
|
121
|
+
events[1].sequence !== 2
|
|
122
|
+
)
|
|
123
|
+
configureConflict();
|
|
124
|
+
const checked = await validateOperationalConfigureSource(full);
|
|
125
|
+
const dispatch: unknown = JSON.parse(events[0].dataJSON),
|
|
126
|
+
response: unknown = JSON.parse(events[1].dataJSON);
|
|
127
|
+
captureConfigureDispatch(dispatch);
|
|
128
|
+
captureConfigureResponse(response);
|
|
129
|
+
const sent = jsonObject(dispatch),
|
|
130
|
+
received = jsonObject(response);
|
|
131
|
+
if (
|
|
132
|
+
!equal(sent.request, checked.request) ||
|
|
133
|
+
!equal(received.request, checked.request) ||
|
|
134
|
+
reservation.requestBinding !== checked.request.requestIdentity.binding ||
|
|
135
|
+
reservation.key !== checked.request.key ||
|
|
136
|
+
reservation.apiVersion !== checked.request.apiVersion ||
|
|
137
|
+
reservation.firstDispatchedAt !== checked.request.firstDispatchedAt ||
|
|
138
|
+
!equal(JSON.parse(reservation.accountJSON), checked.original.account) ||
|
|
139
|
+
!equal(
|
|
140
|
+
JSON.parse(reservation.timingPolicyJSON),
|
|
141
|
+
checked.original.timingPolicy,
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
configureConflict();
|
|
145
|
+
const rebuilt = await constructRenewalConfigurationReceiptV2({
|
|
146
|
+
configuration: checked.configuration as Parameters<
|
|
147
|
+
typeof constructRenewalConfigurationReceiptV2
|
|
148
|
+
>[0]["configuration"],
|
|
149
|
+
actualDispatch: checked.original.dispatch as Parameters<
|
|
150
|
+
typeof constructRenewalConfigurationReceiptV2
|
|
151
|
+
>[0]["actualDispatch"],
|
|
152
|
+
providerSnapshot: received.body as Record<string, unknown>,
|
|
153
|
+
transport: received.transport as Parameters<
|
|
154
|
+
typeof constructRenewalConfigurationReceiptV2
|
|
155
|
+
>[0]["transport"],
|
|
156
|
+
});
|
|
157
|
+
const admittedJSON = admitReceipt(receiptJSON, rebuilt);
|
|
158
|
+
// Retention at head2 never models a prospective, potentially larger event3.
|
|
159
|
+
if (events.length === 3)
|
|
160
|
+
validateConfigureReceiptEventDATA(events[2].dataJSON, rebuilt);
|
|
161
|
+
return {
|
|
162
|
+
receiptJSON: admittedJSON,
|
|
163
|
+
receiptBinding: rebuilt.binding,
|
|
164
|
+
receipt: rebuilt,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export function validateConfigureReceiptEventDATA(
|
|
168
|
+
raw: string,
|
|
169
|
+
receipt: Receipt,
|
|
170
|
+
) {
|
|
171
|
+
const parsed: unknown = JSON.parse(raw);
|
|
172
|
+
captureConfigureReceipt(parsed);
|
|
173
|
+
if (
|
|
174
|
+
!equal(parsed, {
|
|
175
|
+
event: "receipt",
|
|
176
|
+
stage: "configure",
|
|
177
|
+
request: receipt.request,
|
|
178
|
+
receipt,
|
|
179
|
+
})
|
|
180
|
+
)
|
|
181
|
+
configureConflict();
|
|
182
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
canonicalConfigure,
|
|
4
|
+
configureAcknowledgementFixture,
|
|
5
|
+
} from "./configureJournal.fixtures.js";
|
|
6
|
+
|
|
7
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
8
|
+
it.each([
|
|
9
|
+
"body",
|
|
10
|
+
"binding",
|
|
11
|
+
"transport",
|
|
12
|
+
"request",
|
|
13
|
+
"foreign-C3",
|
|
14
|
+
"extra-field",
|
|
15
|
+
])("refuses changed %s receipt DATA before first retention", async (change) => {
|
|
16
|
+
const h = await configureAcknowledgementFixture();
|
|
17
|
+
const receipt = JSON.parse(h.retainArgs.receiptJSON);
|
|
18
|
+
if (change === "body")
|
|
19
|
+
receipt.providerSnapshot.futureResponse = { changed: true };
|
|
20
|
+
if (change === "binding")
|
|
21
|
+
receipt.binding = "renewal-configure-receipt:v2:sha256:" + "0".repeat(64);
|
|
22
|
+
if (change === "transport") receipt.transport.requestId = "req_foreign";
|
|
23
|
+
if (change === "request") receipt.request.key += ":foreign";
|
|
24
|
+
if (change === "extra-field") receipt.future = "unowned";
|
|
25
|
+
const receiptJSON =
|
|
26
|
+
change === "foreign-C3"
|
|
27
|
+
? canonicalConfigure(h.record.configureRecord.attachReceipt)
|
|
28
|
+
: canonicalConfigure(receipt);
|
|
29
|
+
await expect(
|
|
30
|
+
h.t.mutation(h.retain, { ...h.retainArgs, receiptJSON }),
|
|
31
|
+
).rejects.toThrow("RENEWAL_JOURNAL_CONFLICT");
|
|
32
|
+
expect(
|
|
33
|
+
await h.t.query(h.readAcknowledgement, {
|
|
34
|
+
operationId: h.created.operationId,
|
|
35
|
+
}),
|
|
36
|
+
).toBeNull();
|
|
37
|
+
expect(
|
|
38
|
+
(
|
|
39
|
+
await h.t.query(h.readAttempt, {
|
|
40
|
+
operationId: h.created.operationId,
|
|
41
|
+
attemptId: h.acquired.reservation.attemptId,
|
|
42
|
+
})
|
|
43
|
+
).events,
|
|
44
|
+
).toHaveLength(2);
|
|
45
|
+
expect(h.fetches()).toBe(0);
|
|
46
|
+
});
|
|
47
|
+
it.each(["receipt-payload", "basis-origin", "parent-reference"])(
|
|
48
|
+
"corrupt %s makes bounded configure reads refuse without repair",
|
|
49
|
+
async (change) => {
|
|
50
|
+
const h = await configureAcknowledgementFixture();
|
|
51
|
+
const retained = await h.t.mutation(h.retain, h.retainArgs);
|
|
52
|
+
await h.t.run(async (ctx) => {
|
|
53
|
+
if (change === "receipt-payload")
|
|
54
|
+
await ctx.db.patch(
|
|
55
|
+
"renewalOperationPayloads",
|
|
56
|
+
retained.receiptPayloadId,
|
|
57
|
+
{ json: "{}" },
|
|
58
|
+
);
|
|
59
|
+
if (change === "basis-origin") {
|
|
60
|
+
const row = await ctx.db.get(
|
|
61
|
+
"renewalOperations",
|
|
62
|
+
h.created.operationId,
|
|
63
|
+
);
|
|
64
|
+
if (!row?.initialBasis) throw Error("MISSING_FIXTURE_BASIS");
|
|
65
|
+
const basis = JSON.parse(row.initialBasis.basisJSON);
|
|
66
|
+
basis.startWallMs++;
|
|
67
|
+
basis.startNsDecimal = String(BigInt(basis.startNsDecimal) + 1000000n);
|
|
68
|
+
await ctx.db.patch("renewalOperations", row._id, {
|
|
69
|
+
initialBasis: {
|
|
70
|
+
...row.initialBasis,
|
|
71
|
+
basisJSON: canonicalConfigure(basis),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (change === "parent-reference")
|
|
76
|
+
await ctx.db.patch("renewalOperations", h.parentCreated.operationId, {
|
|
77
|
+
activeAttemptId: h.acquired.reservation.attemptId,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
const before = await h.t.run((ctx) =>
|
|
81
|
+
ctx.db.query("renewalOperations").take(3),
|
|
82
|
+
);
|
|
83
|
+
await expect(
|
|
84
|
+
h.t.query(h.load, { operationId: h.created.operationId }),
|
|
85
|
+
).rejects.toThrow();
|
|
86
|
+
await expect(
|
|
87
|
+
h.t.query(h.readAcknowledgement, { operationId: h.created.operationId }),
|
|
88
|
+
).rejects.toThrow("RENEWAL_JOURNAL_CONFLICT");
|
|
89
|
+
await expect(h.t.mutation(h.retain, h.retainArgs)).rejects.toThrow(
|
|
90
|
+
"RENEWAL_JOURNAL_CONFLICT",
|
|
91
|
+
);
|
|
92
|
+
expect(
|
|
93
|
+
await h.t.run((ctx) => ctx.db.query("renewalOperations").take(3)),
|
|
94
|
+
).toEqual(before);
|
|
95
|
+
},
|
|
96
|
+
);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
canonicalConfigure,
|
|
4
|
+
configureComponentFixture,
|
|
5
|
+
} from "./configureJournal.fixtures.js";
|
|
6
|
+
|
|
7
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
8
|
+
async function reserveConfigure() {
|
|
9
|
+
const h = await configureComponentFixture();
|
|
10
|
+
const created = await h.t.mutation(h.create, h.createArgs);
|
|
11
|
+
expect(created.status).toBe("created");
|
|
12
|
+
const reserveArgs = {
|
|
13
|
+
operationId: created.operationId,
|
|
14
|
+
expectedRevision: 0,
|
|
15
|
+
stage: "configure",
|
|
16
|
+
expectedRequestBinding: h.request.requestIdentity.binding,
|
|
17
|
+
recordJSON: h.createArgs.recordJSON,
|
|
18
|
+
};
|
|
19
|
+
const acquired = await h.t.mutation(h.reserve, reserveArgs);
|
|
20
|
+
expect(acquired.disposition).toBe("acquired");
|
|
21
|
+
return {
|
|
22
|
+
...h,
|
|
23
|
+
created,
|
|
24
|
+
acquired,
|
|
25
|
+
reserveArgs,
|
|
26
|
+
bindArgs: {
|
|
27
|
+
operationId: created.operationId,
|
|
28
|
+
attemptId: acquired.reservation.attemptId,
|
|
29
|
+
policyJSON: canonicalConfigure(h.record.timingPolicy),
|
|
30
|
+
basisJSON: canonicalConfigure(h.basis),
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
it("reserves a distinct configure attempt and binds exactly the parent basis with configure stage", async () => {
|
|
35
|
+
const h = await reserveConfigure();
|
|
36
|
+
expect(h.acquired.reservation.stage).toBe("configure");
|
|
37
|
+
expect(h.acquired.reservation.attemptId).not.toBe(
|
|
38
|
+
h.record.parentAttachment.attemptId,
|
|
39
|
+
);
|
|
40
|
+
expect((await h.t.mutation(h.reserve, h.reserveArgs)).disposition).toBe(
|
|
41
|
+
"existing",
|
|
42
|
+
);
|
|
43
|
+
const bound = await h.t.mutation(h.bind, h.bindArgs);
|
|
44
|
+
expect(bound.initialBasis).toEqual({
|
|
45
|
+
version: 1,
|
|
46
|
+
stage: "configure",
|
|
47
|
+
attemptId: h.acquired.reservation.attemptId,
|
|
48
|
+
sourcePayloadId: h.acquired.reservation.payloadId,
|
|
49
|
+
policyJSON: h.bindArgs.policyJSON,
|
|
50
|
+
basisJSON: h.bindArgs.basisJSON,
|
|
51
|
+
});
|
|
52
|
+
expect(await h.t.mutation(h.bind, h.bindArgs)).toEqual(bound);
|
|
53
|
+
expect(
|
|
54
|
+
(await h.t.query(h.load, { operationId: h.created.operationId }))
|
|
55
|
+
.initialBasis,
|
|
56
|
+
).toEqual(bound.initialBasis);
|
|
57
|
+
expect(h.fetches()).toBe(0);
|
|
58
|
+
});
|
|
59
|
+
it("refuses a mathematically valid shifted basis instead of renewing the parent origin", async () => {
|
|
60
|
+
const h = await reserveConfigure();
|
|
61
|
+
const shifted = {
|
|
62
|
+
...h.basis,
|
|
63
|
+
startWallMs: h.basis.startWallMs + 1,
|
|
64
|
+
startNsDecimal: String(BigInt(h.basis.startNsDecimal) + 1000000n),
|
|
65
|
+
};
|
|
66
|
+
await expect(
|
|
67
|
+
h.t.mutation(h.bind, {
|
|
68
|
+
...h.bindArgs,
|
|
69
|
+
basisJSON: canonicalConfigure(shifted),
|
|
70
|
+
}),
|
|
71
|
+
).rejects.toThrow("RENEWAL_JOURNAL_CONFLICT");
|
|
72
|
+
expect(
|
|
73
|
+
(await h.t.query(h.load, { operationId: h.created.operationId }))
|
|
74
|
+
.initialBasis,
|
|
75
|
+
).toBeNull();
|
|
76
|
+
expect(h.fetches()).toBe(0);
|
|
77
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
canonicalConfigure,
|
|
4
|
+
configureComponentFixture,
|
|
5
|
+
} from "./configureJournal.fixtures.js";
|
|
6
|
+
|
|
7
|
+
afterEach(() => vi.unstubAllGlobals());
|
|
8
|
+
it("creates a separately authorized V2 configure operation only after its complete parent attachment DATA", async () => {
|
|
9
|
+
const h = await configureComponentFixture();
|
|
10
|
+
const created = await h.t.mutation(h.create, h.createArgs);
|
|
11
|
+
expect(created.status).toBe("created");
|
|
12
|
+
expect(created.operationId).not.toBe(h.parentCreated.operationId);
|
|
13
|
+
expect(await h.t.query(h.load, { operationId: created.operationId })).toEqual(
|
|
14
|
+
{
|
|
15
|
+
recordVersion: 2,
|
|
16
|
+
operationId: created.operationId,
|
|
17
|
+
recordJSON: h.createArgs.recordJSON,
|
|
18
|
+
revision: 0,
|
|
19
|
+
activeAttempt: null,
|
|
20
|
+
initialBasis: null,
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
expect(h.fetches()).toBe(0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it.each([
|
|
27
|
+
"missing-parent",
|
|
28
|
+
"wrong-attempt",
|
|
29
|
+
"wrong-source",
|
|
30
|
+
"changed-bundle",
|
|
31
|
+
"extended-cutoff",
|
|
32
|
+
"shortened-cutoff",
|
|
33
|
+
"unpublished-parent",
|
|
34
|
+
])(
|
|
35
|
+
"rejects configure parent-link %s before inserting child DATA",
|
|
36
|
+
async (scenario) => {
|
|
37
|
+
const h = await configureComponentFixture(
|
|
38
|
+
scenario !== "unpublished-parent",
|
|
39
|
+
);
|
|
40
|
+
const raw = JSON.parse(h.createArgs.recordJSON);
|
|
41
|
+
switch (scenario) {
|
|
42
|
+
case "missing-parent":
|
|
43
|
+
raw.parentAttachment.operationId = "missing-parent-operation";
|
|
44
|
+
break;
|
|
45
|
+
case "wrong-attempt":
|
|
46
|
+
raw.parentAttachment.attemptId = h.parentCreated.operationId;
|
|
47
|
+
break;
|
|
48
|
+
case "wrong-source":
|
|
49
|
+
raw.parentAttachment.sourcePayloadId = h.parentCreated.operationId;
|
|
50
|
+
break;
|
|
51
|
+
case "changed-bundle":
|
|
52
|
+
raw.configureRecord.originalBundle.future = ["changed"];
|
|
53
|
+
break;
|
|
54
|
+
case "extended-cutoff":
|
|
55
|
+
raw.timingPolicy.workEndWallMs++;
|
|
56
|
+
break;
|
|
57
|
+
case "shortened-cutoff":
|
|
58
|
+
raw.timingPolicy.workEndWallMs--;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
const before = await h.t.run((ctx) =>
|
|
62
|
+
ctx.db.query("renewalOperations").take(3),
|
|
63
|
+
);
|
|
64
|
+
await expect(
|
|
65
|
+
h.t.mutation(h.create, {
|
|
66
|
+
...h.createArgs,
|
|
67
|
+
recordJSON: canonicalConfigure(raw),
|
|
68
|
+
}),
|
|
69
|
+
).rejects.toThrow("RENEWAL_JOURNAL_CONFLICT");
|
|
70
|
+
expect(
|
|
71
|
+
await h.t.run((ctx) => ctx.db.query("renewalOperations").take(3)),
|
|
72
|
+
).toEqual(before);
|
|
73
|
+
expect(h.fetches()).toBe(0);
|
|
74
|
+
},
|
|
75
|
+
);
|