@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,566 @@
|
|
|
1
|
+
import { expect, it } from "vitest";
|
|
2
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
3
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
4
|
+
import { data } from "../test-fixtures/attachScenarioBarriers.js";
|
|
5
|
+
import { BetterStripe } from "../../../../index.js";
|
|
6
|
+
import { components } from "../../../../../../example/convex/_generated/api.js";
|
|
7
|
+
import {
|
|
8
|
+
configureAdmissionFixture,
|
|
9
|
+
admissionControls,
|
|
10
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
11
|
+
|
|
12
|
+
it.each([
|
|
13
|
+
"copy-call",
|
|
14
|
+
"copy-journal",
|
|
15
|
+
"foreign-journal",
|
|
16
|
+
"proxy-call",
|
|
17
|
+
"proxy-journal",
|
|
18
|
+
"extra-argument",
|
|
19
|
+
"wrong-root",
|
|
20
|
+
"spent",
|
|
21
|
+
"legacy-child",
|
|
22
|
+
"attach-child",
|
|
23
|
+
])(
|
|
24
|
+
"refuses %s custody without another selector or provider request",
|
|
25
|
+
async (scenario) => {
|
|
26
|
+
await configureAdmissionFixture(async (h) => {
|
|
27
|
+
await h.complete();
|
|
28
|
+
const parent =
|
|
29
|
+
h.fresh.result.disposition === "acquired"
|
|
30
|
+
? JSON.parse(h.fresh.result.reservation.recordJSON)
|
|
31
|
+
: null;
|
|
32
|
+
const child = await h.child(
|
|
33
|
+
scenario === "legacy-child"
|
|
34
|
+
? {
|
|
35
|
+
change: (raw) => {
|
|
36
|
+
raw.schemaVersion = 1;
|
|
37
|
+
raw.basis = JSON.parse(h.core.basisJSON);
|
|
38
|
+
delete raw.timingPolicy;
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
: scenario === "attach-child"
|
|
42
|
+
? {
|
|
43
|
+
stage: "attach",
|
|
44
|
+
change: (raw) => {
|
|
45
|
+
Object.assign(raw, {
|
|
46
|
+
stage: "attach",
|
|
47
|
+
attachRequest: h.source.attachRequest,
|
|
48
|
+
requestBinding: parent.requestBinding,
|
|
49
|
+
dispatch: parent.dispatch,
|
|
50
|
+
timingPolicy: parent.timingPolicy,
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
: scenario === "wrong-root"
|
|
55
|
+
? {
|
|
56
|
+
sdk: new BetterStripe(components.betterStripe, {
|
|
57
|
+
STRIPE_SECRET_KEY: "sk_test_invalid_owner_core",
|
|
58
|
+
}),
|
|
59
|
+
}
|
|
60
|
+
: {},
|
|
61
|
+
);
|
|
62
|
+
let traps = 0;
|
|
63
|
+
const call =
|
|
64
|
+
scenario === "copy-call"
|
|
65
|
+
? {}
|
|
66
|
+
: scenario === "proxy-call"
|
|
67
|
+
? new Proxy(child.fresh.call!, {
|
|
68
|
+
get() {
|
|
69
|
+
traps++;
|
|
70
|
+
throw Error("GET_TRAP");
|
|
71
|
+
},
|
|
72
|
+
})
|
|
73
|
+
: child.fresh.call;
|
|
74
|
+
const other = scenario === "foreign-journal" ? await h.child() : null;
|
|
75
|
+
const journal = other
|
|
76
|
+
? other.journal
|
|
77
|
+
: scenario === "copy-journal"
|
|
78
|
+
? { ...child.journal }
|
|
79
|
+
: scenario === "proxy-journal"
|
|
80
|
+
? new Proxy(child.journal, {
|
|
81
|
+
get() {
|
|
82
|
+
traps++;
|
|
83
|
+
throw Error("GET_TRAP");
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
: child.journal;
|
|
87
|
+
const args: unknown[] = [call, journal];
|
|
88
|
+
if (scenario === "extra-argument")
|
|
89
|
+
args.push(h.core.attachAcknowledgement().receipt);
|
|
90
|
+
if (scenario === "spent")
|
|
91
|
+
await h.core.admitConfigure(child.fresh.call, child.journal);
|
|
92
|
+
const selectors = admissionControls.selectors;
|
|
93
|
+
const calls = h.calls.length;
|
|
94
|
+
await expect(
|
|
95
|
+
Reflect.apply(h.core.admitConfigure, h.core, args),
|
|
96
|
+
).rejects.toThrow();
|
|
97
|
+
expect(traps).toBe(0);
|
|
98
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
99
|
+
expect(h.calls).toHaveLength(calls);
|
|
100
|
+
if (["copy-call", "proxy-call"].includes(scenario))
|
|
101
|
+
await expect(
|
|
102
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
103
|
+
).resolves.toHaveProperty("operationalAuthority", false);
|
|
104
|
+
else
|
|
105
|
+
await expect(
|
|
106
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
107
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
it("existing CAS replies supply no fresh child admission", async () => {
|
|
112
|
+
await configureAdmissionFixture(async (h) => {
|
|
113
|
+
await h.complete();
|
|
114
|
+
const child = await h.child();
|
|
115
|
+
const existing = await child.journal.reserveFreshAttempt(child.reserveArgs);
|
|
116
|
+
expect(existing.result.disposition).toBe("existing");
|
|
117
|
+
expect(existing.call).toBeNull();
|
|
118
|
+
await expect(
|
|
119
|
+
h.core.admitConfigure(existing.call, child.journal),
|
|
120
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
121
|
+
await expect(
|
|
122
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
123
|
+
).resolves.toHaveProperty("owner", h.core.owner);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
it.each(["retired", "predicate", "binding-pointers"])(
|
|
127
|
+
"refuses changed parent %s custody and spends the child handle",
|
|
128
|
+
async (scenario) => {
|
|
129
|
+
await configureAdmissionFixture(async (h) => {
|
|
130
|
+
await h.complete();
|
|
131
|
+
const child = await h.child();
|
|
132
|
+
if (scenario === "retired") h.core.owner.retire();
|
|
133
|
+
if (scenario === "predicate")
|
|
134
|
+
admissionControls.entries[0].coversFresh = () => true;
|
|
135
|
+
if (scenario === "binding-pointers")
|
|
136
|
+
h.ctx.runQuery = async () => {
|
|
137
|
+
throw Error("REPLACED_RPC");
|
|
138
|
+
};
|
|
139
|
+
await expect(
|
|
140
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
141
|
+
).rejects.toThrow();
|
|
142
|
+
await expect(
|
|
143
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
144
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
it.each(["retire", "predicate", "contradictory-reply"])(
|
|
149
|
+
"does not return admission when %s occurs during child binding",
|
|
150
|
+
async (scenario) => {
|
|
151
|
+
let afterBind: ((reply: unknown) => Promise<void>) | undefined;
|
|
152
|
+
await configureAdmissionFixture(
|
|
153
|
+
async (h) => {
|
|
154
|
+
await h.complete();
|
|
155
|
+
const child = await h.child();
|
|
156
|
+
afterBind = async (reply) => {
|
|
157
|
+
if (scenario === "retire") h.core.owner.retire();
|
|
158
|
+
if (scenario === "predicate")
|
|
159
|
+
admissionControls.entries[0].coversRetained = () => true;
|
|
160
|
+
if (scenario === "contradictory-reply")
|
|
161
|
+
Object.assign(reply as object, {
|
|
162
|
+
operationId: "foreign-operation",
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
await expect(
|
|
166
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
167
|
+
).rejects.toThrow();
|
|
168
|
+
await expect(
|
|
169
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
170
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
afterBind: async (reply) => {
|
|
174
|
+
await afterBind?.(reply);
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
it("retirement rejects promptly while the actual committed basis reply remains pending", async () => {
|
|
181
|
+
let release!: () => void, entered!: () => void;
|
|
182
|
+
const pending = new Promise<void>((resolve) => {
|
|
183
|
+
release = resolve;
|
|
184
|
+
});
|
|
185
|
+
const committed = new Promise<void>((resolve) => {
|
|
186
|
+
entered = resolve;
|
|
187
|
+
});
|
|
188
|
+
let block = false;
|
|
189
|
+
await configureAdmissionFixture(
|
|
190
|
+
async (h) => {
|
|
191
|
+
await h.complete();
|
|
192
|
+
const child = await h.child();
|
|
193
|
+
block = true;
|
|
194
|
+
const admitted = h.core.admitConfigure(child.fresh.call, child.journal);
|
|
195
|
+
const refusal = expect(admitted).rejects.toThrow("INITIAL_OWNER_STOP");
|
|
196
|
+
await committed;
|
|
197
|
+
const loaded = await child.journal.loadAuthorizedOperation();
|
|
198
|
+
expect(
|
|
199
|
+
loaded && "initialBasis" in loaded ? loaded.initialBasis : null,
|
|
200
|
+
).not.toBeNull();
|
|
201
|
+
h.core.owner.retire();
|
|
202
|
+
await refusal;
|
|
203
|
+
release();
|
|
204
|
+
await expect(
|
|
205
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
206
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
afterBind: async () => {
|
|
210
|
+
if (block) {
|
|
211
|
+
entered();
|
|
212
|
+
await pending;
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
it("published receipt DATA cannot replace actual returned parent ACK custody", async () => {
|
|
219
|
+
let release!: () => void, entered!: () => void;
|
|
220
|
+
const pending = new Promise<void>((resolve) => {
|
|
221
|
+
release = resolve;
|
|
222
|
+
});
|
|
223
|
+
const committed = new Promise<void>((resolve) => {
|
|
224
|
+
entered = resolve;
|
|
225
|
+
});
|
|
226
|
+
let appended = 0;
|
|
227
|
+
await configureAdmissionFixture(
|
|
228
|
+
async (h) => {
|
|
229
|
+
const attachment = h.complete();
|
|
230
|
+
await committed;
|
|
231
|
+
const child = await h.child();
|
|
232
|
+
expect(() => h.core.attachAcknowledgement()).toThrow(
|
|
233
|
+
"ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE",
|
|
234
|
+
);
|
|
235
|
+
await expect(
|
|
236
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
237
|
+
).rejects.toThrow("ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE");
|
|
238
|
+
release();
|
|
239
|
+
await attachment;
|
|
240
|
+
await expect(
|
|
241
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
242
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
243
|
+
const next = await h.child();
|
|
244
|
+
await expect(
|
|
245
|
+
h.core.admitConfigure(next.fresh.call, next.journal),
|
|
246
|
+
).resolves.toHaveProperty("owner", h.core.owner);
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
afterAppend: async () => {
|
|
250
|
+
if (++appended === 3) {
|
|
251
|
+
entered();
|
|
252
|
+
await pending;
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it.each([
|
|
260
|
+
"parent-load",
|
|
261
|
+
"child-load",
|
|
262
|
+
"child-load-after-bind",
|
|
263
|
+
"parent-history",
|
|
264
|
+
"child-history",
|
|
265
|
+
"parent-event",
|
|
266
|
+
"parent-ACK",
|
|
267
|
+
"parent-array-getter",
|
|
268
|
+
"parent-array-proxy",
|
|
269
|
+
])(
|
|
270
|
+
"refuses malformed %s RPC DATA without invoking caller traps or returning admission",
|
|
271
|
+
async (scenario) => {
|
|
272
|
+
let armed = false,
|
|
273
|
+
changed = false,
|
|
274
|
+
bound = false,
|
|
275
|
+
traps = 0;
|
|
276
|
+
let childId = "";
|
|
277
|
+
await configureAdmissionFixture(
|
|
278
|
+
async (h) => {
|
|
279
|
+
await h.complete();
|
|
280
|
+
const child = await h.child();
|
|
281
|
+
childId = child.created.operationId;
|
|
282
|
+
armed = true;
|
|
283
|
+
const calls = h.calls.length,
|
|
284
|
+
selectors = admissionControls.selectors;
|
|
285
|
+
await expect(
|
|
286
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
287
|
+
).rejects.toThrow();
|
|
288
|
+
expect(changed).toBe(true);
|
|
289
|
+
expect(traps).toBe(0);
|
|
290
|
+
expect(h.calls).toHaveLength(calls);
|
|
291
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
292
|
+
await expect(
|
|
293
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
294
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
afterBind: async () => {
|
|
298
|
+
if (armed) bound = true;
|
|
299
|
+
},
|
|
300
|
+
afterQuery: async (reply, reference, args) => {
|
|
301
|
+
if (!armed || changed || !reply) return;
|
|
302
|
+
const input = data(args),
|
|
303
|
+
value = data(reply);
|
|
304
|
+
const child = input.operationId === childId;
|
|
305
|
+
if (
|
|
306
|
+
reference.endsWith("/loadAuthorizedOperation") &&
|
|
307
|
+
((scenario === "parent-load" && !child) ||
|
|
308
|
+
(scenario === "child-load" && child) ||
|
|
309
|
+
(scenario === "child-load-after-bind" && child && bound))
|
|
310
|
+
) {
|
|
311
|
+
value.recordJSON = String(value.recordJSON) + " ";
|
|
312
|
+
changed = true;
|
|
313
|
+
}
|
|
314
|
+
if (
|
|
315
|
+
reference.endsWith("/readAttempt") &&
|
|
316
|
+
!child &&
|
|
317
|
+
[
|
|
318
|
+
"parent-history",
|
|
319
|
+
"parent-array-getter",
|
|
320
|
+
"parent-array-proxy",
|
|
321
|
+
].includes(scenario)
|
|
322
|
+
) {
|
|
323
|
+
if (scenario === "parent-history")
|
|
324
|
+
data(value.reservation).key = "foreign-key";
|
|
325
|
+
else {
|
|
326
|
+
const events = value.events;
|
|
327
|
+
if (!Array.isArray(events)) throw Error("INVALID_FIXTURE_EVENTS");
|
|
328
|
+
if (scenario === "parent-array-getter")
|
|
329
|
+
Object.defineProperty(events, "0", {
|
|
330
|
+
enumerable: true,
|
|
331
|
+
configurable: true,
|
|
332
|
+
get() {
|
|
333
|
+
traps++;
|
|
334
|
+
throw Error("GETTER_INVOKED");
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
else
|
|
338
|
+
value.events = new Proxy(events, {
|
|
339
|
+
get() {
|
|
340
|
+
traps++;
|
|
341
|
+
throw Error("PROXY_INVOKED");
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
changed = true;
|
|
346
|
+
}
|
|
347
|
+
if (
|
|
348
|
+
reference.endsWith("/readAttempt") &&
|
|
349
|
+
child &&
|
|
350
|
+
scenario === "child-history"
|
|
351
|
+
) {
|
|
352
|
+
value.future = true;
|
|
353
|
+
changed = true;
|
|
354
|
+
}
|
|
355
|
+
if (
|
|
356
|
+
reference.endsWith("/readStageEvent") &&
|
|
357
|
+
!child &&
|
|
358
|
+
scenario === "parent-event"
|
|
359
|
+
) {
|
|
360
|
+
value.binding = "foreign-event-binding";
|
|
361
|
+
changed = true;
|
|
362
|
+
}
|
|
363
|
+
if (
|
|
364
|
+
reference.endsWith("/readProviderAcknowledgement") &&
|
|
365
|
+
!child &&
|
|
366
|
+
scenario === "parent-ACK"
|
|
367
|
+
) {
|
|
368
|
+
data(value.retention).responsePayloadId = "foreign-payload";
|
|
369
|
+
changed = true;
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
);
|
|
374
|
+
},
|
|
375
|
+
);
|
|
376
|
+
it.each(["stage", "basis", "extra-field", "getter", "proxy"])(
|
|
377
|
+
"refuses contradictory %s binding reply after actual commit without promoting DATA",
|
|
378
|
+
async (scenario) => {
|
|
379
|
+
let armed = false,
|
|
380
|
+
traps = 0;
|
|
381
|
+
await configureAdmissionFixture(
|
|
382
|
+
async (h) => {
|
|
383
|
+
await h.complete();
|
|
384
|
+
const child = await h.child();
|
|
385
|
+
armed = true;
|
|
386
|
+
await expect(
|
|
387
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
388
|
+
).rejects.toThrow();
|
|
389
|
+
expect(traps).toBe(0);
|
|
390
|
+
const loaded = await child.journal.loadAuthorizedOperation();
|
|
391
|
+
expect(
|
|
392
|
+
loaded && "initialBasis" in loaded ? loaded.initialBasis : null,
|
|
393
|
+
).not.toBeNull();
|
|
394
|
+
await expect(
|
|
395
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
396
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
afterBind: async (reply) => {
|
|
400
|
+
if (!armed) return;
|
|
401
|
+
const value = data(reply),
|
|
402
|
+
basis = data(value.initialBasis);
|
|
403
|
+
if (scenario === "stage") basis.stage = "attach";
|
|
404
|
+
if (scenario === "basis") basis.basisJSON = "{}";
|
|
405
|
+
if (scenario === "extra-field") value.future = true;
|
|
406
|
+
if (scenario === "getter")
|
|
407
|
+
Object.defineProperty(value, "initialBasis", {
|
|
408
|
+
enumerable: true,
|
|
409
|
+
configurable: true,
|
|
410
|
+
get() {
|
|
411
|
+
traps++;
|
|
412
|
+
throw Error("GETTER_INVOKED");
|
|
413
|
+
},
|
|
414
|
+
});
|
|
415
|
+
if (scenario === "proxy")
|
|
416
|
+
value.initialBasis = new Proxy(basis, {
|
|
417
|
+
get() {
|
|
418
|
+
traps++;
|
|
419
|
+
throw Error("PROXY_INVOKED");
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
);
|
|
425
|
+
},
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
it("refuses a child event committed while the final no-ACK read is pending", async () => {
|
|
429
|
+
let armed = false,
|
|
430
|
+
bound = false,
|
|
431
|
+
advanced = false,
|
|
432
|
+
childId = "";
|
|
433
|
+
let append!: () => Promise<unknown>;
|
|
434
|
+
await configureAdmissionFixture(
|
|
435
|
+
async (h) => {
|
|
436
|
+
await h.complete();
|
|
437
|
+
const child = await h.child();
|
|
438
|
+
childId = child.created.operationId;
|
|
439
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
440
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
441
|
+
const reservation = child.fresh.result.reservation;
|
|
442
|
+
const event = await canonicalJournalEvent(
|
|
443
|
+
1,
|
|
444
|
+
JSON.stringify(
|
|
445
|
+
renewalSnapshot({
|
|
446
|
+
event: "dispatch",
|
|
447
|
+
stage: "configure",
|
|
448
|
+
request: child.record.configureRecord.request,
|
|
449
|
+
}),
|
|
450
|
+
),
|
|
451
|
+
);
|
|
452
|
+
append = () =>
|
|
453
|
+
child.journal.appendStageEvent({
|
|
454
|
+
reservation,
|
|
455
|
+
expectedSequence: 0,
|
|
456
|
+
event: { sequence: 1, binding: event.binding, dataJSON: event.json },
|
|
457
|
+
});
|
|
458
|
+
armed = true;
|
|
459
|
+
let refused = false;
|
|
460
|
+
try {
|
|
461
|
+
await h.core.admitConfigure(child.fresh.call, child.journal);
|
|
462
|
+
} catch {
|
|
463
|
+
refused = true;
|
|
464
|
+
}
|
|
465
|
+
expect(refused).toBe(true);
|
|
466
|
+
expect(advanced).toBe(true);
|
|
467
|
+
const history = await child.journal.readAttempt({
|
|
468
|
+
attemptId: reservation.attemptId,
|
|
469
|
+
});
|
|
470
|
+
expect(history?.events).toHaveLength(1);
|
|
471
|
+
await expect(
|
|
472
|
+
h.core.admitConfigure(child.fresh.call, child.journal),
|
|
473
|
+
).rejects.toThrow("CLASS_JOURNAL_CALL_UNBOUND");
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
afterBind: async () => {
|
|
477
|
+
if (armed) bound = true;
|
|
478
|
+
},
|
|
479
|
+
afterQuery: async (reply, ref, args) => {
|
|
480
|
+
if (
|
|
481
|
+
armed &&
|
|
482
|
+
bound &&
|
|
483
|
+
!advanced &&
|
|
484
|
+
ref.endsWith("/readProviderAcknowledgement") &&
|
|
485
|
+
data(args).operationId === childId &&
|
|
486
|
+
reply === null
|
|
487
|
+
) {
|
|
488
|
+
advanced = true;
|
|
489
|
+
await append();
|
|
490
|
+
}
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it.each([
|
|
497
|
+
"dispatch-request",
|
|
498
|
+
"response-request",
|
|
499
|
+
"response-body",
|
|
500
|
+
"response-status",
|
|
501
|
+
])(
|
|
502
|
+
"refuses hash-consistent but contradictory parent %s DATA",
|
|
503
|
+
async (scenario) => {
|
|
504
|
+
let armed = false,
|
|
505
|
+
childId = "",
|
|
506
|
+
changedManifest = false,
|
|
507
|
+
changedEvent = false;
|
|
508
|
+
let forged: { json: string; binding: string };
|
|
509
|
+
const sequence = scenario === "dispatch-request" ? 1 : 2;
|
|
510
|
+
await configureAdmissionFixture(
|
|
511
|
+
async (h) => {
|
|
512
|
+
await h.complete();
|
|
513
|
+
const child = await h.child();
|
|
514
|
+
childId = child.created.operationId;
|
|
515
|
+
if (h.fresh.result.disposition !== "acquired")
|
|
516
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
517
|
+
const actual = await h.journal.readStageEvent({
|
|
518
|
+
attemptId: h.fresh.result.reservation.attemptId,
|
|
519
|
+
sequence,
|
|
520
|
+
});
|
|
521
|
+
if (!actual) throw Error("INVALID_FIXTURE_EVENT");
|
|
522
|
+
const modified = JSON.parse(actual.dataJSON);
|
|
523
|
+
if (scenario.endsWith("request")) {
|
|
524
|
+
modified.request.key = "foreign-key";
|
|
525
|
+
modified.request.requestIdentity.key = "foreign-key";
|
|
526
|
+
}
|
|
527
|
+
if (scenario === "response-body")
|
|
528
|
+
modified.body.future = { changed: true };
|
|
529
|
+
if (scenario === "response-status") modified.status = 500;
|
|
530
|
+
forged = await canonicalJournalEvent(
|
|
531
|
+
sequence,
|
|
532
|
+
JSON.stringify(renewalSnapshot(modified)),
|
|
533
|
+
);
|
|
534
|
+
armed = true;
|
|
535
|
+
let refused = false;
|
|
536
|
+
try {
|
|
537
|
+
await h.core.admitConfigure(child.fresh.call, child.journal);
|
|
538
|
+
} catch {
|
|
539
|
+
refused = true;
|
|
540
|
+
}
|
|
541
|
+
expect(refused).toBe(true);
|
|
542
|
+
expect(changedManifest && changedEvent).toBe(true);
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
afterQuery: async (reply, reference, args) => {
|
|
546
|
+
if (!armed || !reply || data(args).operationId === childId) return;
|
|
547
|
+
if (reference.endsWith("/readAttempt")) {
|
|
548
|
+
const events = data(reply).events;
|
|
549
|
+
if (!Array.isArray(events)) throw Error("INVALID_FIXTURE_MANIFEST");
|
|
550
|
+
data(events[sequence - 1]).binding = forged.binding;
|
|
551
|
+
changedManifest = true;
|
|
552
|
+
}
|
|
553
|
+
if (
|
|
554
|
+
reference.endsWith("/readStageEvent") &&
|
|
555
|
+
data(args).sequence === sequence
|
|
556
|
+
) {
|
|
557
|
+
const value = data(reply);
|
|
558
|
+
value.binding = forged.binding;
|
|
559
|
+
value.dataJSON = forged.json;
|
|
560
|
+
changedEvent = true;
|
|
561
|
+
}
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
);
|
|
565
|
+
},
|
|
566
|
+
);
|