@fantastic.dev/better-stripe 0.103.0 → 0.105.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/transport.d.ts +100 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +17 -2
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +105 -3
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/output.js +6 -2
- package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +3 -1
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/record.js +8 -3
- package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +2 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js +12 -5
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +19 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +71 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts +25 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js +62 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalData.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts +14 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js +17 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureJournalWork.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js +117 -0
- package/dist/client/billing/renewalAttach/internal/producer/configurePreflight.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts +30 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +224 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts +61 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js +73 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWriteFactory.js.map +1 -0
- package/docs/renewal-context-reads.md +79 -4
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +31 -2
- package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +148 -3
- package/src/client/billing/renewalAttach/internal/preflight/output.ts +20 -3
- package/src/client/billing/renewalAttach/internal/preflight/record.ts +11 -3
- package/src/client/billing/renewalAttach/internal/preflight/relations.ts +20 -5
- package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +132 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalData.ts +84 -0
- package/src/client/billing/renewalAttach/internal/producer/configureJournalWork.ts +16 -0
- package/src/client/billing/renewalAttach/internal/producer/configurePreflight.ts +170 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +317 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWriteFactory.ts +88 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflight.integration.test.ts +67 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigurePreflightControls.integration.test.ts +475 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureWrite.integration.test.ts +158 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureWriteControls.integration.test.ts +537 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerConfigureAdmission.ts +136 -6
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import {
|
|
2
|
+
configureAdmissionFixture,
|
|
3
|
+
admissionControls,
|
|
4
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
5
|
+
import { webcrypto } from "node:crypto";
|
|
6
|
+
import { expect, it, vi } from "vitest";
|
|
7
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
8
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
9
|
+
import {
|
|
10
|
+
captureAdmittedConfigurePreflight,
|
|
11
|
+
readAdmittedConfigurePreflight,
|
|
12
|
+
} from "./configurePreflight.js";
|
|
13
|
+
|
|
14
|
+
it("an invalid invoke argument spends the readonly actor without reading or reminting", async () => {
|
|
15
|
+
await configureAdmissionFixture(async (h) => {
|
|
16
|
+
await h.complete();
|
|
17
|
+
const child = await h.child();
|
|
18
|
+
const token = await h.core.admitConfigure(child.fresh.call, child.journal);
|
|
19
|
+
h.configureReads(child);
|
|
20
|
+
admissionControls.preflight.push({
|
|
21
|
+
originalEntry: admissionControls.entries[0],
|
|
22
|
+
coversPreflight: () => true,
|
|
23
|
+
});
|
|
24
|
+
const actor = captureAdmittedConfigurePreflight(token),
|
|
25
|
+
before = h.calls.length;
|
|
26
|
+
let traps = 0;
|
|
27
|
+
const input = new Proxy(
|
|
28
|
+
{},
|
|
29
|
+
{
|
|
30
|
+
get() {
|
|
31
|
+
traps++;
|
|
32
|
+
throw Error("REPLACEMENT_INVOKED");
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
await expect(Reflect.apply(actor.invoke, actor, [input])).rejects.toThrow();
|
|
37
|
+
expect(h.calls).toHaveLength(before);
|
|
38
|
+
expect(traps).toBe(0);
|
|
39
|
+
let refused = false;
|
|
40
|
+
try {
|
|
41
|
+
await actor.invoke();
|
|
42
|
+
} catch {
|
|
43
|
+
refused = true;
|
|
44
|
+
}
|
|
45
|
+
expect(refused).toBe(true);
|
|
46
|
+
expect(h.calls).toHaveLength(before);
|
|
47
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it.each([
|
|
52
|
+
"empty",
|
|
53
|
+
"foreign-entry",
|
|
54
|
+
"ambiguous",
|
|
55
|
+
"copy",
|
|
56
|
+
"proxy",
|
|
57
|
+
"extra-capture",
|
|
58
|
+
])(
|
|
59
|
+
"refuses %s preflight capture without another selector or provider read",
|
|
60
|
+
async (scenario) => {
|
|
61
|
+
await configureAdmissionFixture(async (h) => {
|
|
62
|
+
await h.complete();
|
|
63
|
+
const child = await h.child();
|
|
64
|
+
const token = await h.core.admitConfigure(
|
|
65
|
+
child.fresh.call,
|
|
66
|
+
child.journal,
|
|
67
|
+
);
|
|
68
|
+
h.configureReads(child);
|
|
69
|
+
if (scenario !== "empty")
|
|
70
|
+
admissionControls.preflight.push({
|
|
71
|
+
originalEntry:
|
|
72
|
+
scenario === "foreign-entry" ? {} : admissionControls.entries[0],
|
|
73
|
+
coversPreflight: () => true,
|
|
74
|
+
});
|
|
75
|
+
if (scenario === "ambiguous")
|
|
76
|
+
admissionControls.preflight.push({ ...admissionControls.preflight[0] });
|
|
77
|
+
let traps = 0;
|
|
78
|
+
const value =
|
|
79
|
+
scenario === "copy"
|
|
80
|
+
? { ...token }
|
|
81
|
+
: scenario === "proxy"
|
|
82
|
+
? new Proxy(token, {
|
|
83
|
+
getPrototypeOf() {
|
|
84
|
+
traps++;
|
|
85
|
+
throw Error("PROXY_INVOKED");
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
: token;
|
|
89
|
+
const calls = h.calls.length,
|
|
90
|
+
selectors = admissionControls.selectors;
|
|
91
|
+
let refused = false;
|
|
92
|
+
try {
|
|
93
|
+
Reflect.apply(
|
|
94
|
+
captureAdmittedConfigurePreflight,
|
|
95
|
+
undefined,
|
|
96
|
+
scenario === "extra-capture" ? [value, {}] : [value],
|
|
97
|
+
);
|
|
98
|
+
} catch {
|
|
99
|
+
refused = true;
|
|
100
|
+
}
|
|
101
|
+
expect(refused).toBe(true);
|
|
102
|
+
expect(traps).toBe(0);
|
|
103
|
+
expect(h.calls).toHaveLength(calls);
|
|
104
|
+
expect(admissionControls.selectors).toBe(selectors);
|
|
105
|
+
if (scenario === "copy" || scenario === "proxy")
|
|
106
|
+
await captureAdmittedConfigurePreflight(token).invoke();
|
|
107
|
+
else expect(() => captureAdmittedConfigurePreflight(token)).toThrow();
|
|
108
|
+
});
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
it("a pending raw read cannot become actual returned preflight custody", async () => {
|
|
112
|
+
let armed = false,
|
|
113
|
+
release!: () => void,
|
|
114
|
+
entered!: () => void;
|
|
115
|
+
const barrier = new Promise<void>((resolve) => {
|
|
116
|
+
release = resolve;
|
|
117
|
+
});
|
|
118
|
+
const reached = new Promise<void>((resolve) => {
|
|
119
|
+
entered = resolve;
|
|
120
|
+
});
|
|
121
|
+
await configureAdmissionFixture(
|
|
122
|
+
async (h) => {
|
|
123
|
+
await h.complete();
|
|
124
|
+
const child = await h.child();
|
|
125
|
+
const token = await h.core.admitConfigure(
|
|
126
|
+
child.fresh.call,
|
|
127
|
+
child.journal,
|
|
128
|
+
);
|
|
129
|
+
h.configureReads(child);
|
|
130
|
+
admissionControls.preflight.push({
|
|
131
|
+
originalEntry: admissionControls.entries[0],
|
|
132
|
+
coversPreflight: () => true,
|
|
133
|
+
});
|
|
134
|
+
const actor = captureAdmittedConfigurePreflight(token);
|
|
135
|
+
armed = true;
|
|
136
|
+
let completed = false;
|
|
137
|
+
const pending = actor.invoke().then((value) => {
|
|
138
|
+
completed = true;
|
|
139
|
+
return value;
|
|
140
|
+
});
|
|
141
|
+
try {
|
|
142
|
+
expect(
|
|
143
|
+
await Promise.race([
|
|
144
|
+
reached.then(() => "reached"),
|
|
145
|
+
pending.then(
|
|
146
|
+
() => "resolved",
|
|
147
|
+
(error: unknown) => String(error),
|
|
148
|
+
),
|
|
149
|
+
]),
|
|
150
|
+
).toBe("reached");
|
|
151
|
+
expect(completed).toBe(false);
|
|
152
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
153
|
+
} finally {
|
|
154
|
+
release();
|
|
155
|
+
}
|
|
156
|
+
const output = await pending;
|
|
157
|
+
expect(readAdmittedConfigurePreflight(token).output === output).toBe(
|
|
158
|
+
true,
|
|
159
|
+
);
|
|
160
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
beforeFetch: async (_path, method) => {
|
|
164
|
+
if (armed && method === "GET") {
|
|
165
|
+
armed = false;
|
|
166
|
+
entered();
|
|
167
|
+
await barrier;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
);
|
|
172
|
+
});
|
|
173
|
+
it("parent retirement rejects a pending read without returning or registering output", async () => {
|
|
174
|
+
let armed = false,
|
|
175
|
+
release!: () => void,
|
|
176
|
+
entered!: () => void;
|
|
177
|
+
const barrier = new Promise<void>((resolve) => {
|
|
178
|
+
release = resolve;
|
|
179
|
+
});
|
|
180
|
+
const reached = new Promise<void>((resolve) => {
|
|
181
|
+
entered = resolve;
|
|
182
|
+
});
|
|
183
|
+
await configureAdmissionFixture(
|
|
184
|
+
async (h) => {
|
|
185
|
+
await h.complete();
|
|
186
|
+
const child = await h.child();
|
|
187
|
+
const token = await h.core.admitConfigure(
|
|
188
|
+
child.fresh.call,
|
|
189
|
+
child.journal,
|
|
190
|
+
);
|
|
191
|
+
h.configureReads(child);
|
|
192
|
+
admissionControls.preflight.push({
|
|
193
|
+
originalEntry: admissionControls.entries[0],
|
|
194
|
+
coversPreflight: () => true,
|
|
195
|
+
});
|
|
196
|
+
const actor = captureAdmittedConfigurePreflight(token);
|
|
197
|
+
armed = true;
|
|
198
|
+
const pending = actor.invoke();
|
|
199
|
+
const refused = expect(pending).rejects.toThrow();
|
|
200
|
+
try {
|
|
201
|
+
expect(
|
|
202
|
+
await Promise.race([
|
|
203
|
+
reached.then(() => "reached"),
|
|
204
|
+
pending.then(
|
|
205
|
+
() => "resolved",
|
|
206
|
+
(error: unknown) => String(error),
|
|
207
|
+
),
|
|
208
|
+
]),
|
|
209
|
+
).toBe("reached");
|
|
210
|
+
h.core.owner.retire();
|
|
211
|
+
await refused;
|
|
212
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
213
|
+
} finally {
|
|
214
|
+
release();
|
|
215
|
+
}
|
|
216
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
217
|
+
expect(() => captureAdmittedConfigurePreflight(token)).toThrow();
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
beforeFetch: async (_path, method) => {
|
|
221
|
+
if (armed && method === "GET") {
|
|
222
|
+
armed = false;
|
|
223
|
+
entered();
|
|
224
|
+
await barrier;
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
});
|
|
230
|
+
it.each(["schedule", "coupon", "privacy", "predicate"])(
|
|
231
|
+
"changed %s material refuses without returned output or POST",
|
|
232
|
+
async (scenario) => {
|
|
233
|
+
await configureAdmissionFixture(async (h) => {
|
|
234
|
+
await h.complete();
|
|
235
|
+
const child = await h.child();
|
|
236
|
+
const token = await h.core.admitConfigure(
|
|
237
|
+
child.fresh.call,
|
|
238
|
+
child.journal,
|
|
239
|
+
);
|
|
240
|
+
const current = h.configureReads(child);
|
|
241
|
+
admissionControls.preflight.push({
|
|
242
|
+
originalEntry: admissionControls.entries[0],
|
|
243
|
+
coversPreflight: () => scenario !== "predicate",
|
|
244
|
+
});
|
|
245
|
+
if (scenario === "schedule")
|
|
246
|
+
current.schedule.metadata = { changed: true };
|
|
247
|
+
if (scenario === "coupon")
|
|
248
|
+
current.coupons[0].wireCoupon.times_redeemed = 99;
|
|
249
|
+
if (scenario === "privacy")
|
|
250
|
+
Reflect.set(
|
|
251
|
+
current.subscription,
|
|
252
|
+
"future",
|
|
253
|
+
"Bearer synthetic-preflight-private-control",
|
|
254
|
+
);
|
|
255
|
+
const before = h.calls.length,
|
|
256
|
+
actor = captureAdmittedConfigurePreflight(token);
|
|
257
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
258
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
259
|
+
expect(h.calls.slice(before).every((row) => row.method === "GET")).toBe(
|
|
260
|
+
true,
|
|
261
|
+
);
|
|
262
|
+
expect(admissionControls.legacy).toBe(0);
|
|
263
|
+
});
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
it("copied outputs cannot register custody and changed eligibility cannot revive a cached view", async () => {
|
|
267
|
+
await configureAdmissionFixture(async (h) => {
|
|
268
|
+
await h.complete();
|
|
269
|
+
const child = await h.child();
|
|
270
|
+
const token = await h.core.admitConfigure(child.fresh.call, child.journal);
|
|
271
|
+
h.configureReads(child);
|
|
272
|
+
const entry = {
|
|
273
|
+
originalEntry: admissionControls.entries[0],
|
|
274
|
+
coversPreflight: () => true,
|
|
275
|
+
};
|
|
276
|
+
admissionControls.preflight.push(entry);
|
|
277
|
+
const output = await captureAdmittedConfigurePreflight(token).invoke();
|
|
278
|
+
const view = readAdmittedConfigurePreflight(token);
|
|
279
|
+
expect(readAdmittedConfigurePreflight(token) === view).toBe(true);
|
|
280
|
+
const copy = JSON.parse(JSON.stringify(output));
|
|
281
|
+
expect(copy).toEqual(output);
|
|
282
|
+
expect(() =>
|
|
283
|
+
Reflect.apply(readAdmittedConfigurePreflight, undefined, [token, copy]),
|
|
284
|
+
).toThrow();
|
|
285
|
+
expect(() => readAdmittedConfigurePreflight({ ...token })).toThrow();
|
|
286
|
+
const original = entry.coversPreflight;
|
|
287
|
+
entry.coversPreflight = () => true;
|
|
288
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
289
|
+
entry.coversPreflight = original;
|
|
290
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("a child intent committed during original reconstruction refuses before any provider reads", async () => {
|
|
295
|
+
let invoking = false,
|
|
296
|
+
armed = false;
|
|
297
|
+
await configureAdmissionFixture(
|
|
298
|
+
async (h) => {
|
|
299
|
+
await h.complete();
|
|
300
|
+
const child = await h.child();
|
|
301
|
+
const token = await h.core.admitConfigure(
|
|
302
|
+
child.fresh.call,
|
|
303
|
+
child.journal,
|
|
304
|
+
);
|
|
305
|
+
h.configureReads(child);
|
|
306
|
+
admissionControls.preflight.push({
|
|
307
|
+
originalEntry: admissionControls.entries[0],
|
|
308
|
+
coversPreflight: () => true,
|
|
309
|
+
});
|
|
310
|
+
const actor = captureAdmittedConfigurePreflight(token);
|
|
311
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
312
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
313
|
+
const reservation = child.fresh.result.reservation;
|
|
314
|
+
const event = await canonicalJournalEvent(
|
|
315
|
+
1,
|
|
316
|
+
JSON.stringify(
|
|
317
|
+
renewalSnapshot({
|
|
318
|
+
event: "dispatch",
|
|
319
|
+
stage: "configure",
|
|
320
|
+
request: child.record.configureRecord.request,
|
|
321
|
+
}),
|
|
322
|
+
),
|
|
323
|
+
);
|
|
324
|
+
let release!: () => void,
|
|
325
|
+
entered!: () => void,
|
|
326
|
+
first = true;
|
|
327
|
+
const barrier = new Promise<void>((resolve) => {
|
|
328
|
+
release = resolve;
|
|
329
|
+
}),
|
|
330
|
+
reached = new Promise<void>((resolve) => {
|
|
331
|
+
entered = resolve;
|
|
332
|
+
});
|
|
333
|
+
vi.stubGlobal("crypto", {
|
|
334
|
+
subtle: {
|
|
335
|
+
async digest(
|
|
336
|
+
algorithm: Parameters<typeof webcrypto.subtle.digest>[0],
|
|
337
|
+
input: Parameters<typeof webcrypto.subtle.digest>[1],
|
|
338
|
+
) {
|
|
339
|
+
const result = await webcrypto.subtle.digest(algorithm, input);
|
|
340
|
+
if (
|
|
341
|
+
armed &&
|
|
342
|
+
first &&
|
|
343
|
+
ArrayBuffer.isView(input) &&
|
|
344
|
+
JSON.parse(
|
|
345
|
+
new TextDecoder().decode(
|
|
346
|
+
new Uint8Array(
|
|
347
|
+
input.buffer,
|
|
348
|
+
input.byteOffset,
|
|
349
|
+
input.byteLength,
|
|
350
|
+
),
|
|
351
|
+
),
|
|
352
|
+
)[2] === "renewal-configure"
|
|
353
|
+
) {
|
|
354
|
+
first = false;
|
|
355
|
+
entered();
|
|
356
|
+
await barrier;
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
invoking = true;
|
|
363
|
+
const before = h.calls.length;
|
|
364
|
+
const pending = actor.invoke(),
|
|
365
|
+
refused = expect(pending).rejects.toThrow();
|
|
366
|
+
try {
|
|
367
|
+
expect(
|
|
368
|
+
await Promise.race([
|
|
369
|
+
reached.then(() => "reached"),
|
|
370
|
+
pending.then(
|
|
371
|
+
() => "resolved",
|
|
372
|
+
(error: unknown) => String(error),
|
|
373
|
+
),
|
|
374
|
+
]),
|
|
375
|
+
).toBe("reached");
|
|
376
|
+
await child.journal.appendStageEvent({
|
|
377
|
+
reservation,
|
|
378
|
+
expectedSequence: 0,
|
|
379
|
+
event: { sequence: 1, binding: event.binding, dataJSON: event.json },
|
|
380
|
+
});
|
|
381
|
+
} finally {
|
|
382
|
+
release();
|
|
383
|
+
}
|
|
384
|
+
await refused;
|
|
385
|
+
expect(h.calls).toHaveLength(before);
|
|
386
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
afterQuery: async (_reply, reference) => {
|
|
390
|
+
if (invoking && reference.endsWith("/readAttempt")) armed = true;
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("an intent committed during HTTP prevents output custody", async () => {
|
|
397
|
+
let append: (() => Promise<void>) | undefined;
|
|
398
|
+
await configureAdmissionFixture(
|
|
399
|
+
async (h) => {
|
|
400
|
+
await h.complete();
|
|
401
|
+
const child = await h.child();
|
|
402
|
+
const token = await h.core.admitConfigure(
|
|
403
|
+
child.fresh.call,
|
|
404
|
+
child.journal,
|
|
405
|
+
);
|
|
406
|
+
h.configureReads(child);
|
|
407
|
+
admissionControls.preflight.push({
|
|
408
|
+
originalEntry: admissionControls.entries[0],
|
|
409
|
+
coversPreflight: () => true,
|
|
410
|
+
});
|
|
411
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
412
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
413
|
+
const reservation = child.fresh.result.reservation;
|
|
414
|
+
const event = await canonicalJournalEvent(
|
|
415
|
+
1,
|
|
416
|
+
JSON.stringify(
|
|
417
|
+
renewalSnapshot({
|
|
418
|
+
event: "dispatch",
|
|
419
|
+
stage: "configure",
|
|
420
|
+
request: child.record.configureRecord.request,
|
|
421
|
+
}),
|
|
422
|
+
),
|
|
423
|
+
);
|
|
424
|
+
append = async () => {
|
|
425
|
+
await child.journal.appendStageEvent({
|
|
426
|
+
reservation,
|
|
427
|
+
expectedSequence: 0,
|
|
428
|
+
event: { sequence: 1, binding: event.binding, dataJSON: event.json },
|
|
429
|
+
});
|
|
430
|
+
};
|
|
431
|
+
const before = h.calls.length;
|
|
432
|
+
await expect(
|
|
433
|
+
captureAdmittedConfigurePreflight(token).invoke(),
|
|
434
|
+
).rejects.toThrow();
|
|
435
|
+
expect(h.calls.slice(before).every((call) => call.method === "GET")).toBe(
|
|
436
|
+
true,
|
|
437
|
+
);
|
|
438
|
+
expect(() => readAdmittedConfigurePreflight(token)).toThrow();
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
beforeFetch: async (_path, method) => {
|
|
442
|
+
if (append && method === "GET") {
|
|
443
|
+
const run = append;
|
|
444
|
+
append = undefined;
|
|
445
|
+
await run();
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
);
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("preflight keeps original custody across a second genuine Action context", async () => {
|
|
453
|
+
await configureAdmissionFixture(async (h) => {
|
|
454
|
+
await h.complete();
|
|
455
|
+
const child = await h.child();
|
|
456
|
+
const token = await h.core.admitConfigure(child.fresh.call, child.journal);
|
|
457
|
+
h.configureReads(child);
|
|
458
|
+
admissionControls.preflight.push({
|
|
459
|
+
originalEntry: admissionControls.entries[0],
|
|
460
|
+
coversPreflight: () => true,
|
|
461
|
+
});
|
|
462
|
+
const actor = captureAdmittedConfigurePreflight(token);
|
|
463
|
+
await h.inAnotherAction(async () => {
|
|
464
|
+
const output = await actor.invoke();
|
|
465
|
+
expect(readAdmittedConfigurePreflight(token).output === output).toBe(
|
|
466
|
+
true,
|
|
467
|
+
);
|
|
468
|
+
expect(
|
|
469
|
+
readAdmittedConfigurePreflight(token).acknowledgement ===
|
|
470
|
+
h.core.attachAcknowledgement(),
|
|
471
|
+
).toBe(true);
|
|
472
|
+
});
|
|
473
|
+
expect(admissionControls.legacy).toBe(0);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { object } from "./configureJournalData.js";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
configureAdmissionFixture,
|
|
5
|
+
admissionControls,
|
|
6
|
+
configureAdmissionCase,
|
|
7
|
+
prepareAdmittedConfigure,
|
|
8
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
9
|
+
import { captureAdmittedConfigurePreflight } from "./configurePreflight.js";
|
|
10
|
+
import {
|
|
11
|
+
captureAdmittedConfigureWrite,
|
|
12
|
+
readAdmittedConfigureAcknowledgement,
|
|
13
|
+
readAdmittedConfigureWriteAttempt,
|
|
14
|
+
} from "./configureWrite.js";
|
|
15
|
+
|
|
16
|
+
configureAdmissionCase(
|
|
17
|
+
"commits dispatch, one exact configure POST, retained C9 and receipt publication before returning ACK custody",
|
|
18
|
+
prepareAdmittedConfigure,
|
|
19
|
+
async (h, { child, token }) => {
|
|
20
|
+
const before = h.calls.length;
|
|
21
|
+
const actor = captureAdmittedConfigureWrite(token);
|
|
22
|
+
expect(actor).not.toBeNull();
|
|
23
|
+
const output = await actor!.invoke();
|
|
24
|
+
expect(object(output).status).toBe("configure_acknowledged");
|
|
25
|
+
const view = readAdmittedConfigureAcknowledgement(token);
|
|
26
|
+
expect(view!.output === output).toBe(true);
|
|
27
|
+
expect(view!.receipt === object(output).receipt).toBe(true);
|
|
28
|
+
expect(view!.rawReceipt === object(output).rawReceipt).toBe(true);
|
|
29
|
+
expect(view!.acknowledgement === h.core.attachAcknowledgement()).toBe(true);
|
|
30
|
+
const calls = h.calls.slice(before);
|
|
31
|
+
expect(calls.filter((call) => call.method === "GET")).toHaveLength(6);
|
|
32
|
+
expect(calls.filter((call) => call.method === "POST")).toEqual([
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
path: child.record.configureRecord.request.path,
|
|
35
|
+
idempotencyKey: child.record.configureRecord.request.key,
|
|
36
|
+
apiVersion: "2026-09-30.endive",
|
|
37
|
+
}),
|
|
38
|
+
]);
|
|
39
|
+
if (child.fresh.result.disposition !== "acquired")
|
|
40
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
41
|
+
const history = await child.journal.readAttempt({
|
|
42
|
+
attemptId: child.fresh.result.reservation.attemptId,
|
|
43
|
+
});
|
|
44
|
+
expect(history!.events.map((event) => event.sequence)).toEqual([1, 2, 3]);
|
|
45
|
+
const retained = await child.journal.readProviderAcknowledgement();
|
|
46
|
+
expect(retained).not.toBeNull();
|
|
47
|
+
expect(JSON.parse(retained!.receiptJSON)).toEqual(object(output).receipt);
|
|
48
|
+
expect(admissionControls.legacy).toBe(0);
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
function deferred() {
|
|
53
|
+
let resolve!: () => void;
|
|
54
|
+
const promise = new Promise<void>((done) => {
|
|
55
|
+
resolve = done;
|
|
56
|
+
});
|
|
57
|
+
return { promise, resolve };
|
|
58
|
+
}
|
|
59
|
+
describe("known C9 with oversized whole output", () => {
|
|
60
|
+
let pending: Promise<void>,
|
|
61
|
+
start: ReturnType<typeof deferred>,
|
|
62
|
+
postReady: ReturnType<typeof deferred>,
|
|
63
|
+
releasePost: ReturnType<typeof deferred>,
|
|
64
|
+
run = false,
|
|
65
|
+
armed = false;
|
|
66
|
+
beforeEach(async () => {
|
|
67
|
+
run = false;
|
|
68
|
+
armed = false;
|
|
69
|
+
start = deferred();
|
|
70
|
+
postReady = deferred();
|
|
71
|
+
releasePost = deferred();
|
|
72
|
+
let ready!: () => void, failed!: (error: unknown) => void;
|
|
73
|
+
const prepared = new Promise<void>((resolve, reject) => {
|
|
74
|
+
ready = resolve;
|
|
75
|
+
failed = reject;
|
|
76
|
+
});
|
|
77
|
+
pending = configureAdmissionFixture(
|
|
78
|
+
async (h) => {
|
|
79
|
+
await h.complete();
|
|
80
|
+
const child = await h.child();
|
|
81
|
+
const token = await h.core.admitConfigure(
|
|
82
|
+
child.fresh.call,
|
|
83
|
+
child.journal,
|
|
84
|
+
);
|
|
85
|
+
h.configureReads(child);
|
|
86
|
+
admissionControls.preflight.push({
|
|
87
|
+
originalEntry: admissionControls.entries[0],
|
|
88
|
+
coversPreflight: () => true,
|
|
89
|
+
});
|
|
90
|
+
admissionControls.write.push({
|
|
91
|
+
originalEntry: admissionControls.entries[0],
|
|
92
|
+
coversConfigure: () => true,
|
|
93
|
+
});
|
|
94
|
+
await captureAdmittedConfigurePreflight(token).invoke();
|
|
95
|
+
Reflect.set(h.baseline.schedule, "padding", "x".repeat(300000));
|
|
96
|
+
ready();
|
|
97
|
+
await start.promise;
|
|
98
|
+
if (!run) return;
|
|
99
|
+
armed = true;
|
|
100
|
+
const actor = captureAdmittedConfigureWrite(token);
|
|
101
|
+
expect(object(await actor.invoke()).status).toBe("configure_unknown");
|
|
102
|
+
expect(
|
|
103
|
+
await child.journal.readProviderAcknowledgement(),
|
|
104
|
+
).not.toBeNull();
|
|
105
|
+
const attempt = readAdmittedConfigureWriteAttempt(token);
|
|
106
|
+
expect(attempt).not.toBeNull();
|
|
107
|
+
expect(attempt!.receiptKnown).toBe(true);
|
|
108
|
+
expect(Object.isFrozen(attempt!.receipt)).toBe(true);
|
|
109
|
+
expect(Object.isFrozen(attempt!.rawReceipt)).toBe(true);
|
|
110
|
+
expect(attempt!.receipt).not.toBeNull();
|
|
111
|
+
expect(attempt!.rawReceipt).not.toBeNull();
|
|
112
|
+
expect(attempt!.returned).toBe(false);
|
|
113
|
+
expect(() => readAdmittedConfigureAcknowledgement(token)).toThrow();
|
|
114
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
115
|
+
expect(
|
|
116
|
+
h.calls.filter(
|
|
117
|
+
(call) =>
|
|
118
|
+
call.method === "POST" &&
|
|
119
|
+
call.path === child.record.configureRecord.request.path,
|
|
120
|
+
),
|
|
121
|
+
).toHaveLength(1);
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
beforeFetch: async (path, method) => {
|
|
125
|
+
if (
|
|
126
|
+
armed &&
|
|
127
|
+
method === "POST" &&
|
|
128
|
+
path.startsWith("/v1/subscription_schedules/")
|
|
129
|
+
) {
|
|
130
|
+
postReady.resolve();
|
|
131
|
+
await releasePost.promise;
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
void pending.catch(failed);
|
|
137
|
+
await prepared;
|
|
138
|
+
});
|
|
139
|
+
beforeEach(async () => {
|
|
140
|
+
run = true;
|
|
141
|
+
start.resolve();
|
|
142
|
+
await Promise.race([
|
|
143
|
+
postReady.promise,
|
|
144
|
+
pending.then(() => {
|
|
145
|
+
throw Error("FIXTURE_SETTLED_BEFORE_POST");
|
|
146
|
+
}),
|
|
147
|
+
]);
|
|
148
|
+
});
|
|
149
|
+
afterEach(async () => {
|
|
150
|
+
start?.resolve();
|
|
151
|
+
releasePost?.resolve();
|
|
152
|
+
await pending?.catch(() => {});
|
|
153
|
+
});
|
|
154
|
+
it("durably retains actual C9 even when whole-output admission fails", async () => {
|
|
155
|
+
releasePost.resolve();
|
|
156
|
+
await pending;
|
|
157
|
+
});
|
|
158
|
+
});
|