@fantastic.dev/better-stripe 0.101.0 → 0.103.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/c10/appendAck.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/c10/appendAck.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/appendAck.js +13 -1
- package/dist/client/billing/renewalAttach/internal/c10/appendAck.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts +23 -0
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js +34 -2
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js.map +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/configureJournalWork.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +49 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.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/docs/renewal-context-reads.md +81 -3
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/c10/appendAck.ts +17 -0
- package/src/client/billing/renewalAttach/internal/c10/configureEvents.ts +45 -2
- 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/configureJournalWork.ts +53 -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/producerConfigureChannelControls.integration.test.ts +542 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureChannels.integration.test.ts +321 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureControls.integration.test.ts +566 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +353 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +61 -3
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configureAdmissionFixture,
|
|
3
|
+
admissionControls,
|
|
4
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
5
|
+
import { expect, it, vi } from "vitest";
|
|
6
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
7
|
+
import { getFunctionAddress } from "convex/server";
|
|
8
|
+
import { components } from "../../../../../../example/convex/_generated/api.js";
|
|
9
|
+
import { readConfigureLineage } from "./configureLineage.js";
|
|
10
|
+
import { createGuardedInitialStageChannel } from "../c10/appendAck.js";
|
|
11
|
+
import { createAdmittedConfigureEventCompiler } from "../c10/configureEvents.js";
|
|
12
|
+
import { journalWorkForConfigureLineage } from "./configureJournalWork.js";
|
|
13
|
+
|
|
14
|
+
it.each(["before", "after"])(
|
|
15
|
+
"does not acknowledge a child append while the %s-commit RPC barrier is pending",
|
|
16
|
+
async (phase) => {
|
|
17
|
+
let release!: () => void,
|
|
18
|
+
entered!: () => void,
|
|
19
|
+
armed = false;
|
|
20
|
+
const barrier = new Promise<void>((resolve) => {
|
|
21
|
+
release = resolve;
|
|
22
|
+
});
|
|
23
|
+
const reached = new Promise<void>((resolve) => {
|
|
24
|
+
entered = resolve;
|
|
25
|
+
});
|
|
26
|
+
const block = async () => {
|
|
27
|
+
if (armed) {
|
|
28
|
+
entered();
|
|
29
|
+
await barrier;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
await configureAdmissionFixture(
|
|
33
|
+
async (h) => {
|
|
34
|
+
await h.complete();
|
|
35
|
+
const child = await h.child();
|
|
36
|
+
const token = await h.core.admitConfigure(
|
|
37
|
+
child.fresh.call,
|
|
38
|
+
child.journal,
|
|
39
|
+
);
|
|
40
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
41
|
+
values = await h.eventsFor(child);
|
|
42
|
+
const work = journalWorkForConfigureLineage(token);
|
|
43
|
+
armed = true;
|
|
44
|
+
let completed = false;
|
|
45
|
+
const dispatched = compiler.dispatch(values.dispatch).then((value) => {
|
|
46
|
+
completed = true;
|
|
47
|
+
return value;
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
await reached;
|
|
51
|
+
expect(work.idle()).toBe(false);
|
|
52
|
+
expect(completed).toBe(false);
|
|
53
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
54
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
55
|
+
const stored = await child.journal.readAttempt({
|
|
56
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
57
|
+
});
|
|
58
|
+
expect(stored?.events).toHaveLength(phase === "before" ? 0 : 1);
|
|
59
|
+
} finally {
|
|
60
|
+
release();
|
|
61
|
+
}
|
|
62
|
+
const result = await dispatched;
|
|
63
|
+
expect(result.actualFulfillmentEstablished).toBe(false);
|
|
64
|
+
expect(completed).toBe(true);
|
|
65
|
+
expect(work.idle()).toBe(true);
|
|
66
|
+
expect(admissionControls.legacy).toBe(0);
|
|
67
|
+
},
|
|
68
|
+
phase === "before" ? { beforeAppend: block } : { afterAppend: block },
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
it.each(["before", "after"])(
|
|
73
|
+
"a rejected %s-commit append closes the child channel without another capture",
|
|
74
|
+
async (phase) => {
|
|
75
|
+
let armed = false;
|
|
76
|
+
const reject = async () => {
|
|
77
|
+
if (armed) throw Error("CONTROLLED_APPEND_REJECTION");
|
|
78
|
+
};
|
|
79
|
+
await configureAdmissionFixture(
|
|
80
|
+
async (h) => {
|
|
81
|
+
await h.complete();
|
|
82
|
+
const child = await h.child();
|
|
83
|
+
const token = await h.core.admitConfigure(
|
|
84
|
+
child.fresh.call,
|
|
85
|
+
child.journal,
|
|
86
|
+
);
|
|
87
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
88
|
+
values = await h.eventsFor(child);
|
|
89
|
+
armed = true;
|
|
90
|
+
await expect(compiler.dispatch(values.dispatch)).rejects.toThrow(
|
|
91
|
+
"C10_SOURCE_STOP",
|
|
92
|
+
);
|
|
93
|
+
expect(journalWorkForConfigureLineage(token).idle()).toBe(true);
|
|
94
|
+
expect(() => createAdmittedConfigureEventCompiler(token)).toThrow(
|
|
95
|
+
"CONFIGURE_CHANNEL_CONSUMED",
|
|
96
|
+
);
|
|
97
|
+
await expect(compiler.dispatch(values.dispatch)).rejects.toThrow(
|
|
98
|
+
"C10_SOURCE_STOP",
|
|
99
|
+
);
|
|
100
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
101
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
102
|
+
expect(
|
|
103
|
+
(
|
|
104
|
+
await child.journal.readAttempt({
|
|
105
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
106
|
+
})
|
|
107
|
+
)?.events,
|
|
108
|
+
).toHaveLength(phase === "before" ? 0 : 1);
|
|
109
|
+
},
|
|
110
|
+
phase === "before" ? { beforeAppend: reject } : { afterAppend: reject },
|
|
111
|
+
);
|
|
112
|
+
},
|
|
113
|
+
);
|
|
114
|
+
it("a channel timeout cannot hide the actual pending RPC or accept its late reply", async () => {
|
|
115
|
+
let release!: () => void,
|
|
116
|
+
entered!: () => void,
|
|
117
|
+
armed = false;
|
|
118
|
+
const barrier = new Promise<void>((resolve) => {
|
|
119
|
+
release = resolve;
|
|
120
|
+
});
|
|
121
|
+
const reached = new Promise<void>((resolve) => {
|
|
122
|
+
entered = resolve;
|
|
123
|
+
});
|
|
124
|
+
await configureAdmissionFixture(
|
|
125
|
+
async (h) => {
|
|
126
|
+
await h.complete();
|
|
127
|
+
const child = await h.child();
|
|
128
|
+
const token = await h.core.admitConfigure(
|
|
129
|
+
child.fresh.call,
|
|
130
|
+
child.journal,
|
|
131
|
+
);
|
|
132
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
133
|
+
values = await h.eventsFor(child);
|
|
134
|
+
const work = journalWorkForConfigureLineage(token);
|
|
135
|
+
armed = true;
|
|
136
|
+
const dispatched = compiler.dispatch(values.dispatch);
|
|
137
|
+
const refused = expect(dispatched).rejects.toThrow("C10_SOURCE_STOP");
|
|
138
|
+
try {
|
|
139
|
+
await reached;
|
|
140
|
+
expect(work.idle()).toBe(false);
|
|
141
|
+
await vi.advanceTimersByTimeAsync(5000);
|
|
142
|
+
await refused;
|
|
143
|
+
expect(() => h.core.owner.check()).not.toThrow();
|
|
144
|
+
expect(work.idle()).toBe(false);
|
|
145
|
+
expect(() => createAdmittedConfigureEventCompiler(token)).toThrow(
|
|
146
|
+
"CONFIGURE_CHANNEL_CONSUMED",
|
|
147
|
+
);
|
|
148
|
+
} finally {
|
|
149
|
+
release();
|
|
150
|
+
}
|
|
151
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
152
|
+
expect(work.idle()).toBe(true);
|
|
153
|
+
await expect(compiler.response(values.response)).rejects.toThrow(
|
|
154
|
+
"C10_SOURCE_STOP",
|
|
155
|
+
);
|
|
156
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
157
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
158
|
+
expect(
|
|
159
|
+
(
|
|
160
|
+
await child.journal.readAttempt({
|
|
161
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
162
|
+
})
|
|
163
|
+
)?.events,
|
|
164
|
+
).toHaveLength(1);
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
afterAppend: async () => {
|
|
168
|
+
if (armed) {
|
|
169
|
+
entered();
|
|
170
|
+
await barrier;
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
it("canonical parent retirement refuses an append while its actual committed reply is pending", async () => {
|
|
177
|
+
let release!: () => void,
|
|
178
|
+
entered!: () => void,
|
|
179
|
+
armed = false;
|
|
180
|
+
const barrier = new Promise<void>((resolve) => {
|
|
181
|
+
release = resolve;
|
|
182
|
+
});
|
|
183
|
+
const reached = new Promise<void>((resolve) => {
|
|
184
|
+
entered = resolve;
|
|
185
|
+
});
|
|
186
|
+
await configureAdmissionFixture(
|
|
187
|
+
async (h) => {
|
|
188
|
+
await h.complete();
|
|
189
|
+
const child = await h.child();
|
|
190
|
+
const token = await h.core.admitConfigure(
|
|
191
|
+
child.fresh.call,
|
|
192
|
+
child.journal,
|
|
193
|
+
);
|
|
194
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
195
|
+
values = await h.eventsFor(child);
|
|
196
|
+
armed = true;
|
|
197
|
+
const dispatched = compiler.dispatch(values.dispatch);
|
|
198
|
+
const refused = expect(dispatched).rejects.toThrow("C10_SOURCE_STOP");
|
|
199
|
+
try {
|
|
200
|
+
await reached;
|
|
201
|
+
h.core.owner.retire();
|
|
202
|
+
await refused;
|
|
203
|
+
} finally {
|
|
204
|
+
release();
|
|
205
|
+
}
|
|
206
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
207
|
+
expect(() => createAdmittedConfigureEventCompiler(token)).toThrow(
|
|
208
|
+
"CONFIGURE_CHANNEL_CONSUMED",
|
|
209
|
+
);
|
|
210
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
211
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
212
|
+
expect(
|
|
213
|
+
(
|
|
214
|
+
await child.journal.readAttempt({
|
|
215
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
216
|
+
})
|
|
217
|
+
)?.events,
|
|
218
|
+
).toHaveLength(1);
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
afterAppend: async () => {
|
|
222
|
+
if (armed) {
|
|
223
|
+
entered();
|
|
224
|
+
await barrier;
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it.each(["copy", "proxy", "extra-options", "duplicate", "failed-capture"])(
|
|
232
|
+
"%s cannot replace or remint a private child channel",
|
|
233
|
+
async (scenario) => {
|
|
234
|
+
await configureAdmissionFixture(async (h) => {
|
|
235
|
+
await h.complete();
|
|
236
|
+
const child = await h.child();
|
|
237
|
+
const token = await h.core.admitConfigure(
|
|
238
|
+
child.fresh.call,
|
|
239
|
+
child.journal,
|
|
240
|
+
);
|
|
241
|
+
let traps = 0;
|
|
242
|
+
const input =
|
|
243
|
+
scenario === "copy"
|
|
244
|
+
? { ...token }
|
|
245
|
+
: scenario === "proxy"
|
|
246
|
+
? new Proxy(token, {
|
|
247
|
+
getPrototypeOf() {
|
|
248
|
+
traps++;
|
|
249
|
+
throw Error("PROXY_INVOKED");
|
|
250
|
+
},
|
|
251
|
+
})
|
|
252
|
+
: token;
|
|
253
|
+
const extra = new Proxy(
|
|
254
|
+
{},
|
|
255
|
+
{
|
|
256
|
+
ownKeys() {
|
|
257
|
+
traps++;
|
|
258
|
+
throw Error("REPLACEMENT_INVOKED");
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
);
|
|
262
|
+
if (scenario === "duplicate") createAdmittedConfigureEventCompiler(token);
|
|
263
|
+
const query = h.ctx.runQuery;
|
|
264
|
+
if (scenario === "failed-capture")
|
|
265
|
+
h.ctx.runQuery = async () => {
|
|
266
|
+
throw Error("REPLACED_QUERY");
|
|
267
|
+
};
|
|
268
|
+
const before = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
269
|
+
let refused = false;
|
|
270
|
+
try {
|
|
271
|
+
Reflect.apply(
|
|
272
|
+
createAdmittedConfigureEventCompiler,
|
|
273
|
+
undefined,
|
|
274
|
+
scenario === "extra-options" ? [input, extra] : [input],
|
|
275
|
+
);
|
|
276
|
+
} catch {
|
|
277
|
+
refused = true;
|
|
278
|
+
} finally {
|
|
279
|
+
h.ctx.runQuery = query;
|
|
280
|
+
}
|
|
281
|
+
const after = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
282
|
+
expect(refused).toBe(true);
|
|
283
|
+
expect(traps).toBe(0);
|
|
284
|
+
if (scenario !== "failed-capture") expect(after - before).toBe(0);
|
|
285
|
+
if (scenario === "copy" || scenario === "proxy")
|
|
286
|
+
expect(createAdmittedConfigureEventCompiler(token).stageChannel).toBe(
|
|
287
|
+
"configure",
|
|
288
|
+
);
|
|
289
|
+
else
|
|
290
|
+
expect(() => createAdmittedConfigureEventCompiler(token)).toThrow(
|
|
291
|
+
"CONFIGURE_CHANNEL_CONSUMED",
|
|
292
|
+
);
|
|
293
|
+
});
|
|
294
|
+
},
|
|
295
|
+
);
|
|
296
|
+
it("a child-only RPC pointer change refuses before event reflection and permanently closes the channel", async () => {
|
|
297
|
+
await configureAdmissionFixture(async (h) => {
|
|
298
|
+
await h.complete();
|
|
299
|
+
await h.inAnotherAction(async (ctx) => {
|
|
300
|
+
const child = await h.child({ ctx });
|
|
301
|
+
const token = await h.core.admitConfigure(
|
|
302
|
+
child.fresh.call,
|
|
303
|
+
child.journal,
|
|
304
|
+
);
|
|
305
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
306
|
+
values = await h.eventsFor(child);
|
|
307
|
+
const query = ctx.runQuery;
|
|
308
|
+
ctx.runQuery = async () => {
|
|
309
|
+
throw Error("REPLACED_CHILD_QUERY");
|
|
310
|
+
};
|
|
311
|
+
let traps = 0;
|
|
312
|
+
const hostile = new Proxy(values.dispatch, {
|
|
313
|
+
getPrototypeOf() {
|
|
314
|
+
traps++;
|
|
315
|
+
throw Error("EVENT_REFLECTED");
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
try {
|
|
319
|
+
expect(() => h.core.owner.check()).not.toThrow();
|
|
320
|
+
await expect(compiler.dispatch(hostile)).rejects.toThrow(
|
|
321
|
+
"C10_SOURCE_STOP",
|
|
322
|
+
);
|
|
323
|
+
expect(traps).toBe(0);
|
|
324
|
+
} finally {
|
|
325
|
+
ctx.runQuery = query;
|
|
326
|
+
}
|
|
327
|
+
await expect(compiler.dispatch(values.dispatch)).rejects.toThrow(
|
|
328
|
+
"C10_SOURCE_STOP",
|
|
329
|
+
);
|
|
330
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
331
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
332
|
+
await expect(
|
|
333
|
+
child.journal.readAttempt({
|
|
334
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
335
|
+
}),
|
|
336
|
+
).rejects.toThrow("CLASS_ACTION_JOURNAL_UNBOUND");
|
|
337
|
+
expect(
|
|
338
|
+
(
|
|
339
|
+
await ctx.runQuery(
|
|
340
|
+
components.betterStripe.renewalOperations.queries.readAttempt,
|
|
341
|
+
{
|
|
342
|
+
operationId: child.created.operationId,
|
|
343
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
344
|
+
},
|
|
345
|
+
)
|
|
346
|
+
)?.events,
|
|
347
|
+
).toHaveLength(0);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
it.each(["true", "promise", "then-getter", "proxy-guard"])(
|
|
352
|
+
"the guarded kernel rejects %s without replacing its canonical Owner",
|
|
353
|
+
async (scenario) => {
|
|
354
|
+
await configureAdmissionFixture(async (h) => {
|
|
355
|
+
await h.complete();
|
|
356
|
+
const child = await h.child();
|
|
357
|
+
const token = await h.core.admitConfigure(
|
|
358
|
+
child.fresh.call,
|
|
359
|
+
child.journal,
|
|
360
|
+
);
|
|
361
|
+
const lineage = readConfigureLineage(token);
|
|
362
|
+
let traps = 0;
|
|
363
|
+
const result =
|
|
364
|
+
scenario === "promise"
|
|
365
|
+
? Promise.resolve(undefined)
|
|
366
|
+
: scenario === "then-getter"
|
|
367
|
+
? Object.defineProperty({}, "then", {
|
|
368
|
+
get() {
|
|
369
|
+
traps++;
|
|
370
|
+
throw Error("THEN_INVOKED");
|
|
371
|
+
},
|
|
372
|
+
})
|
|
373
|
+
: true;
|
|
374
|
+
const guard =
|
|
375
|
+
scenario === "proxy-guard"
|
|
376
|
+
? new Proxy(() => undefined, {
|
|
377
|
+
apply() {
|
|
378
|
+
traps++;
|
|
379
|
+
throw Error("GUARD_INVOKED");
|
|
380
|
+
},
|
|
381
|
+
})
|
|
382
|
+
: () => result;
|
|
383
|
+
expect(() =>
|
|
384
|
+
createGuardedInitialStageChannel(
|
|
385
|
+
lineage.parentToken,
|
|
386
|
+
{ timeoutMs: 100, send: () => Promise.resolve() },
|
|
387
|
+
guard,
|
|
388
|
+
),
|
|
389
|
+
).toThrow("C10_SOURCE_STOP");
|
|
390
|
+
expect(traps).toBe(0);
|
|
391
|
+
expect(() => h.core.owner.check()).not.toThrow();
|
|
392
|
+
expect(admissionControls.legacy).toBe(0);
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
);
|
|
396
|
+
it("a child-only binding change during an actual committed append cannot receive a channel ACK", async () => {
|
|
397
|
+
await configureAdmissionFixture(async (h) => {
|
|
398
|
+
await h.complete();
|
|
399
|
+
await h.inAnotherAction(async (ctx) => {
|
|
400
|
+
let release!: () => void,
|
|
401
|
+
entered!: () => void,
|
|
402
|
+
armed = false;
|
|
403
|
+
const barrier = new Promise<void>((resolve) => {
|
|
404
|
+
release = resolve;
|
|
405
|
+
});
|
|
406
|
+
const reached = new Promise<void>((resolve) => {
|
|
407
|
+
entered = resolve;
|
|
408
|
+
});
|
|
409
|
+
const mutate = ctx.runMutation;
|
|
410
|
+
ctx.runMutation = async (ref, ...args) => {
|
|
411
|
+
const result = await mutate(ref, ...args);
|
|
412
|
+
if (
|
|
413
|
+
armed &&
|
|
414
|
+
getFunctionAddress(ref).reference?.endsWith("/appendStageEvent")
|
|
415
|
+
) {
|
|
416
|
+
entered();
|
|
417
|
+
await barrier;
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
};
|
|
421
|
+
const child = await h.child({ ctx });
|
|
422
|
+
const token = await h.core.admitConfigure(
|
|
423
|
+
child.fresh.call,
|
|
424
|
+
child.journal,
|
|
425
|
+
);
|
|
426
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
427
|
+
values = await h.eventsFor(child);
|
|
428
|
+
armed = true;
|
|
429
|
+
const pending = compiler.dispatch(values.dispatch);
|
|
430
|
+
const refused = expect(pending).rejects.toThrow("C10_SOURCE_STOP");
|
|
431
|
+
const query = ctx.runQuery;
|
|
432
|
+
try {
|
|
433
|
+
await reached;
|
|
434
|
+
ctx.runQuery = async () => {
|
|
435
|
+
throw Error("CHANGED_CHILD_QUERY");
|
|
436
|
+
};
|
|
437
|
+
expect(() => h.core.owner.check()).not.toThrow();
|
|
438
|
+
} finally {
|
|
439
|
+
release();
|
|
440
|
+
}
|
|
441
|
+
await refused;
|
|
442
|
+
ctx.runQuery = query;
|
|
443
|
+
await expect(compiler.response(values.response)).rejects.toThrow(
|
|
444
|
+
"C10_SOURCE_STOP",
|
|
445
|
+
);
|
|
446
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
447
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
448
|
+
await expect(
|
|
449
|
+
child.journal.readAttempt({
|
|
450
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
451
|
+
}),
|
|
452
|
+
).rejects.toThrow("CLASS_ACTION_JOURNAL_UNBOUND");
|
|
453
|
+
expect(
|
|
454
|
+
(
|
|
455
|
+
await ctx.runQuery(
|
|
456
|
+
components.betterStripe.renewalOperations.queries.readAttempt,
|
|
457
|
+
{
|
|
458
|
+
operationId: child.created.operationId,
|
|
459
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
460
|
+
},
|
|
461
|
+
)
|
|
462
|
+
)?.events,
|
|
463
|
+
).toHaveLength(1);
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it("another child's valid dispatch cannot replace the captured configure source", async () => {
|
|
469
|
+
await configureAdmissionFixture(async (h) => {
|
|
470
|
+
await h.complete();
|
|
471
|
+
const one = await h.child(),
|
|
472
|
+
two = await h.child();
|
|
473
|
+
const a = await h.core.admitConfigure(one.fresh.call, one.journal),
|
|
474
|
+
b = await h.core.admitConfigure(two.fresh.call, two.journal);
|
|
475
|
+
const first = createAdmittedConfigureEventCompiler(a),
|
|
476
|
+
second = createAdmittedConfigureEventCompiler(b);
|
|
477
|
+
const av = await h.eventsFor(one),
|
|
478
|
+
bv = await h.eventsFor(two);
|
|
479
|
+
await expect(first.dispatch(bv.dispatch)).rejects.toThrow(
|
|
480
|
+
"C10_SOURCE_STOP",
|
|
481
|
+
);
|
|
482
|
+
await expect(first.dispatch(av.dispatch)).rejects.toThrow(
|
|
483
|
+
"C10_SOURCE_STOP",
|
|
484
|
+
);
|
|
485
|
+
await second.dispatch(bv.dispatch);
|
|
486
|
+
if (
|
|
487
|
+
one.fresh.result.disposition !== "acquired" ||
|
|
488
|
+
two.fresh.result.disposition !== "acquired"
|
|
489
|
+
)
|
|
490
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
491
|
+
expect(
|
|
492
|
+
(
|
|
493
|
+
await one.journal.readAttempt({
|
|
494
|
+
attemptId: one.fresh.result.reservation.attemptId,
|
|
495
|
+
})
|
|
496
|
+
)?.events,
|
|
497
|
+
).toHaveLength(0);
|
|
498
|
+
expect(
|
|
499
|
+
(
|
|
500
|
+
await two.journal.readAttempt({
|
|
501
|
+
attemptId: two.fresh.result.reservation.attemptId,
|
|
502
|
+
})
|
|
503
|
+
)?.events,
|
|
504
|
+
).toHaveLength(1);
|
|
505
|
+
expect(() => h.core.owner.check()).not.toThrow();
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
it("another child's complete C9 cannot become receipt3 or alter retained acknowledgement DATA", async () => {
|
|
509
|
+
await configureAdmissionFixture(async (h) => {
|
|
510
|
+
await h.complete();
|
|
511
|
+
const one = await h.child(),
|
|
512
|
+
two = await h.child();
|
|
513
|
+
const token = await h.core.admitConfigure(two.fresh.call, two.journal);
|
|
514
|
+
const compiler = createAdmittedConfigureEventCompiler(token),
|
|
515
|
+
av = await h.eventsFor(one),
|
|
516
|
+
bv = await h.eventsFor(two);
|
|
517
|
+
await compiler.dispatch(bv.dispatch);
|
|
518
|
+
await compiler.response(bv.response);
|
|
519
|
+
if (two.fresh.result.disposition !== "acquired")
|
|
520
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
521
|
+
const retained = await two.journal.retainProviderAcknowledgement({
|
|
522
|
+
attemptId: two.fresh.result.reservation.attemptId,
|
|
523
|
+
expectedSequence: 2,
|
|
524
|
+
receiptJSON: JSON.stringify(renewalSnapshot(bv.receipt)),
|
|
525
|
+
});
|
|
526
|
+
await expect(
|
|
527
|
+
compiler.receipt({ ...bv.receiptEvent, receipt: av.receipt }),
|
|
528
|
+
).rejects.toThrow("C10_SOURCE_STOP");
|
|
529
|
+
const known = await two.journal.readProviderAcknowledgement();
|
|
530
|
+
expect(known?.retention).toEqual(retained);
|
|
531
|
+
expect(known?.receiptJSON).toBe(
|
|
532
|
+
JSON.stringify(renewalSnapshot(bv.receipt)),
|
|
533
|
+
);
|
|
534
|
+
expect(
|
|
535
|
+
(
|
|
536
|
+
await two.journal.readAttempt({
|
|
537
|
+
attemptId: two.fresh.result.reservation.attemptId,
|
|
538
|
+
})
|
|
539
|
+
)?.events,
|
|
540
|
+
).toHaveLength(2);
|
|
541
|
+
});
|
|
542
|
+
});
|