@fantastic.dev/better-stripe 0.105.0 → 0.107.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/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 +28 -0
- package/dist/client/billing/renewalAttach/internal/c10/configureEvents.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +200 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +31 -4
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/observation/history.d.ts +41 -0
- package/dist/client/billing/renewalAttach/internal/observation/history.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/history.js +161 -0
- package/dist/client/billing/renewalAttach/internal/observation/history.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.d.ts +55 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.js +83 -0
- package/dist/client/billing/renewalAttach/internal/observation/historyEvents.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.d.ts +19 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.js +11 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAcknowledgement.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.d.ts +56 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.js +79 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts +31 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js +33 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureFrontier.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.js +259 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureRecovery.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts +2 -25
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js +15 -30
- package/dist/client/billing/renewalAttach/internal/producer/configureWrite.js.map +1 -1
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
- package/docs/renewal-context-reads.md +90 -3
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/c10/configureEvents.ts +37 -0
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +37 -4
- package/src/client/billing/renewalAttach/internal/observation/history.integration.test.ts +79 -0
- package/src/client/billing/renewalAttach/internal/observation/history.ts +200 -0
- package/src/client/billing/renewalAttach/internal/observation/historyControls.integration.test.ts +238 -0
- package/src/client/billing/renewalAttach/internal/observation/historyEvents.ts +114 -0
- package/src/client/billing/renewalAttach/internal/producer/configureAcknowledgement.ts +11 -0
- package/src/client/billing/renewalAttach/internal/producer/configureAttemptAuthority.ts +121 -0
- package/src/client/billing/renewalAttach/internal/producer/configureFrontier.ts +63 -0
- package/src/client/billing/renewalAttach/internal/producer/configureRecovery.ts +361 -0
- package/src/client/billing/renewalAttach/internal/producer/configureWrite.ts +18 -47
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureRecovery.integration.test.ts +99 -0
- package/src/client/billing/renewalAttach/internal/producer/producerConfigureRecoveryControls.integration.test.ts +420 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/historySnapshot.ts +47 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { expect, vi } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
configureAdmissionCase,
|
|
4
|
+
prepareAdmittedConfigure,
|
|
5
|
+
admissionControls,
|
|
6
|
+
} from "../test-fixtures/producerConfigureAdmission.js";
|
|
7
|
+
import {
|
|
8
|
+
captureAdmittedConfigureWrite,
|
|
9
|
+
readAdmittedConfigureAcknowledgement,
|
|
10
|
+
} from "./configureWrite.js";
|
|
11
|
+
import { captureAdmittedConfigureRecovery } from "./configureRecovery.js";
|
|
12
|
+
import { readOriginalConfigureAttempt } from "./configureAttemptAuthority.js";
|
|
13
|
+
import { object } from "./configureJournalData.js";
|
|
14
|
+
import * as retention from "../configure/replay.js";
|
|
15
|
+
import { canonicalJournalEvent } from "../../../../../shared/renewalOperationJournal.js";
|
|
16
|
+
import { renewalSnapshot } from "../../../renewalReplacementSnapshot.js";
|
|
17
|
+
|
|
18
|
+
type Harness = Parameters<typeof prepareAdmittedConfigure>[0];
|
|
19
|
+
type State = Awaited<ReturnType<typeof prepareAdmittedConfigure>>;
|
|
20
|
+
type Options = Parameters<typeof configureAdmissionCase>[3];
|
|
21
|
+
function unknownCase(
|
|
22
|
+
name: string,
|
|
23
|
+
verify: (h: Harness, state: State) => Promise<void>,
|
|
24
|
+
options: Options = {},
|
|
25
|
+
) {
|
|
26
|
+
let reject = false;
|
|
27
|
+
configureAdmissionCase(
|
|
28
|
+
name,
|
|
29
|
+
async (h) => {
|
|
30
|
+
const state = await prepareAdmittedConfigure(h);
|
|
31
|
+
reject = true;
|
|
32
|
+
await expect(
|
|
33
|
+
captureAdmittedConfigureWrite(state.token).invoke(),
|
|
34
|
+
).rejects.toThrow("OWNED_CONFIGURE_PROVIDER_REJECTED");
|
|
35
|
+
return state;
|
|
36
|
+
},
|
|
37
|
+
verify,
|
|
38
|
+
{
|
|
39
|
+
...options,
|
|
40
|
+
beforeFetch: async (path, method) => {
|
|
41
|
+
if (
|
|
42
|
+
reject &&
|
|
43
|
+
method === "POST" &&
|
|
44
|
+
path.startsWith("/v1/subscription_schedules/")
|
|
45
|
+
) {
|
|
46
|
+
reject = false;
|
|
47
|
+
throw Error("CONTROLLED_UNKNOWN_POST");
|
|
48
|
+
}
|
|
49
|
+
await options.beforeFetch?.(path, method);
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
function posts(h: Harness, state: State) {
|
|
55
|
+
return h.calls.filter(
|
|
56
|
+
(call) =>
|
|
57
|
+
call.method === "POST" &&
|
|
58
|
+
call.path === state.child.record.configureRecord.request.path,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
for (const scenario of [
|
|
62
|
+
"copy",
|
|
63
|
+
"proxy",
|
|
64
|
+
"extra-capture",
|
|
65
|
+
"extra-invoke",
|
|
66
|
+
"already-reserved",
|
|
67
|
+
] as const) {
|
|
68
|
+
unknownCase(
|
|
69
|
+
"refuses " + scenario + " recovery without another provider call",
|
|
70
|
+
async (h, state) => {
|
|
71
|
+
const before = h.calls.length;
|
|
72
|
+
let traps = 0;
|
|
73
|
+
if (scenario === "copy" || scenario === "proxy") {
|
|
74
|
+
const value =
|
|
75
|
+
scenario === "copy"
|
|
76
|
+
? { ...state.token }
|
|
77
|
+
: new Proxy(state.token, {
|
|
78
|
+
get() {
|
|
79
|
+
traps++;
|
|
80
|
+
throw Error("PROXY_TRAP");
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
expect(() => captureAdmittedConfigureRecovery(value)).toThrow();
|
|
84
|
+
} else if (scenario === "extra-capture") {
|
|
85
|
+
expect(() =>
|
|
86
|
+
Reflect.apply(captureAdmittedConfigureRecovery, undefined, [
|
|
87
|
+
state.token,
|
|
88
|
+
{},
|
|
89
|
+
]),
|
|
90
|
+
).toThrow();
|
|
91
|
+
expect(() => captureAdmittedConfigureRecovery(state.token)).toThrow();
|
|
92
|
+
} else {
|
|
93
|
+
const actor = captureAdmittedConfigureRecovery(state.token);
|
|
94
|
+
if (scenario === "already-reserved")
|
|
95
|
+
expect(() => captureAdmittedConfigureRecovery(state.token)).toThrow();
|
|
96
|
+
else {
|
|
97
|
+
await expect(
|
|
98
|
+
Reflect.apply(actor.invoke, actor, [{}]),
|
|
99
|
+
).rejects.toThrow();
|
|
100
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
expect(h.calls).toHaveLength(before);
|
|
104
|
+
expect(traps).toBe(0);
|
|
105
|
+
expect(() => readAdmittedConfigureAcknowledgement(state.token)).toThrow();
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
for (const scenario of [
|
|
110
|
+
"source-pointer",
|
|
111
|
+
"preflight-pointer",
|
|
112
|
+
"schedule-drift",
|
|
113
|
+
"subscription-drift",
|
|
114
|
+
"retention-expired",
|
|
115
|
+
"retention-before-post",
|
|
116
|
+
] as const) {
|
|
117
|
+
unknownCase(
|
|
118
|
+
"refuses " + scenario + " before replay POST",
|
|
119
|
+
async (h, state) => {
|
|
120
|
+
const actor = captureAdmittedConfigureRecovery(state.token);
|
|
121
|
+
if (scenario === "source-pointer")
|
|
122
|
+
admissionControls.write[0].coversConfigure = () => true;
|
|
123
|
+
if (scenario === "preflight-pointer")
|
|
124
|
+
admissionControls.preflight[0].coversPreflight = () => true;
|
|
125
|
+
if (scenario === "schedule-drift")
|
|
126
|
+
state.current.schedule.metadata = { changed: true };
|
|
127
|
+
if (scenario === "subscription-drift")
|
|
128
|
+
Reflect.set(state.current.subscription, "metadata", { changed: true });
|
|
129
|
+
if (scenario === "retention-expired")
|
|
130
|
+
vi.spyOn(retention, "withinConfigureRetention").mockReturnValue(false);
|
|
131
|
+
if (scenario === "retention-before-post")
|
|
132
|
+
vi.spyOn(retention, "withinConfigureRetention")
|
|
133
|
+
.mockReturnValueOnce(true)
|
|
134
|
+
.mockReturnValueOnce(true)
|
|
135
|
+
.mockReturnValue(false);
|
|
136
|
+
expect(object(await actor.invoke()).status).toBe(
|
|
137
|
+
scenario === "subscription-drift"
|
|
138
|
+
? "not_dispatched"
|
|
139
|
+
: "configure_unknown",
|
|
140
|
+
);
|
|
141
|
+
expect(posts(h, state)).toHaveLength(1);
|
|
142
|
+
expect(() => readAdmittedConfigureAcknowledgement(state.token)).toThrow();
|
|
143
|
+
await expect(actor.invoke()).rejects.toThrow();
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
unknownCase(
|
|
148
|
+
"journal response DATA cannot recreate missing owned response custody",
|
|
149
|
+
async (h, state) => {
|
|
150
|
+
if (state.child.fresh.result.disposition !== "acquired")
|
|
151
|
+
throw Error("INVALID_FIXTURE_CAS");
|
|
152
|
+
const event = await canonicalJournalEvent(
|
|
153
|
+
2,
|
|
154
|
+
JSON.stringify(
|
|
155
|
+
renewalSnapshot({
|
|
156
|
+
event: "response",
|
|
157
|
+
stage: "configure",
|
|
158
|
+
request: state.child.record.configureRecord.request,
|
|
159
|
+
body: h.baseline.schedule,
|
|
160
|
+
transport: { status: 200, requestId: "req_host_data_only" },
|
|
161
|
+
}),
|
|
162
|
+
),
|
|
163
|
+
);
|
|
164
|
+
await state.child.journal.appendStageEvent({
|
|
165
|
+
reservation: state.child.fresh.result.reservation,
|
|
166
|
+
expectedSequence: 1,
|
|
167
|
+
event: { sequence: 2, binding: event.binding, dataJSON: event.json },
|
|
168
|
+
});
|
|
169
|
+
const before = h.calls.length;
|
|
170
|
+
expect(
|
|
171
|
+
object(await captureAdmittedConfigureRecovery(state.token).invoke())
|
|
172
|
+
.status,
|
|
173
|
+
).toBe("configure_unknown");
|
|
174
|
+
expect(h.calls).toHaveLength(before);
|
|
175
|
+
expect(() => readAdmittedConfigureAcknowledgement(state.token)).toThrow();
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
for (const mode of [
|
|
179
|
+
"response-before",
|
|
180
|
+
"response-after",
|
|
181
|
+
"receipt-before",
|
|
182
|
+
"receipt-after",
|
|
183
|
+
"retention-after",
|
|
184
|
+
] as const) {
|
|
185
|
+
let armed = false,
|
|
186
|
+
count = 0;
|
|
187
|
+
configureAdmissionCase(
|
|
188
|
+
"no-POST completion after " + mode + " fault",
|
|
189
|
+
async (h) => {
|
|
190
|
+
const state = await prepareAdmittedConfigure(h);
|
|
191
|
+
armed = true;
|
|
192
|
+
count = 0;
|
|
193
|
+
expect(
|
|
194
|
+
object(await captureAdmittedConfigureWrite(state.token).invoke())
|
|
195
|
+
.status,
|
|
196
|
+
).toBe("configure_unknown");
|
|
197
|
+
armed = false;
|
|
198
|
+
return state;
|
|
199
|
+
},
|
|
200
|
+
async (h, state) => {
|
|
201
|
+
const before = h.calls.length;
|
|
202
|
+
const output = await captureAdmittedConfigureRecovery(
|
|
203
|
+
state.token,
|
|
204
|
+
).invoke();
|
|
205
|
+
expect(object(output).status).toBe("configure_acknowledged");
|
|
206
|
+
expect(h.calls).toHaveLength(before);
|
|
207
|
+
const view = readAdmittedConfigureAcknowledgement(state.token);
|
|
208
|
+
expect(view.output === output).toBe(true);
|
|
209
|
+
expect(view.receipt === object(output).receipt).toBe(true);
|
|
210
|
+
expect(view.rawReceipt === object(output).rawReceipt).toBe(true);
|
|
211
|
+
expect(
|
|
212
|
+
await state.child.journal.readProviderAcknowledgement(),
|
|
213
|
+
).not.toBeNull();
|
|
214
|
+
expect(posts(h, state)).toHaveLength(1);
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
beforeAppend: async () => {
|
|
218
|
+
if (
|
|
219
|
+
armed &&
|
|
220
|
+
mode.endsWith("-before") &&
|
|
221
|
+
++count === (mode.startsWith("response") ? 2 : 3)
|
|
222
|
+
)
|
|
223
|
+
throw Error("CONTROLLED_BEFORE_APPEND");
|
|
224
|
+
},
|
|
225
|
+
afterAppend: async () => {
|
|
226
|
+
if (
|
|
227
|
+
armed &&
|
|
228
|
+
mode.endsWith("-after") &&
|
|
229
|
+
mode !== "retention-after" &&
|
|
230
|
+
++count === (mode.startsWith("response") ? 2 : 3)
|
|
231
|
+
)
|
|
232
|
+
throw Error("CONTROLLED_AFTER_APPEND");
|
|
233
|
+
},
|
|
234
|
+
afterRetain: async () => {
|
|
235
|
+
if (armed && mode === "retention-after")
|
|
236
|
+
throw Error("CONTROLLED_RETAINED_REPLY_REJECTION");
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
let safeFault = false,
|
|
242
|
+
safeCount = 0;
|
|
243
|
+
configureAdmissionCase(
|
|
244
|
+
"FULFILLED_SAFE without owned response or C9 refuses replay",
|
|
245
|
+
async (h) => {
|
|
246
|
+
const state = await prepareAdmittedConfigure(h);
|
|
247
|
+
safeFault = true;
|
|
248
|
+
safeCount = 0;
|
|
249
|
+
expect(
|
|
250
|
+
object(await captureAdmittedConfigureWrite(state.token).invoke()).status,
|
|
251
|
+
).toBe("configure_unknown");
|
|
252
|
+
const attempt = readOriginalConfigureAttempt(state.token);
|
|
253
|
+
attempt.response = null;
|
|
254
|
+
attempt.receipt = null;
|
|
255
|
+
attempt.rawReceipt = null;
|
|
256
|
+
return state;
|
|
257
|
+
},
|
|
258
|
+
async (h, state) => {
|
|
259
|
+
const before = h.calls.length;
|
|
260
|
+
expect(() => captureAdmittedConfigureRecovery(state.token)).toThrow();
|
|
261
|
+
expect(h.calls).toHaveLength(before);
|
|
262
|
+
expect(posts(h, state)).toHaveLength(1);
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
beforeAppend: async () => {
|
|
266
|
+
if (safeFault && ++safeCount === 2) {
|
|
267
|
+
safeFault = false;
|
|
268
|
+
throw Error("CONTROLLED_RESPONSE_FAULT");
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
);
|
|
273
|
+
configureAdmissionCase(
|
|
274
|
+
"already returned configure ACK cannot capture recovery",
|
|
275
|
+
async (h) => {
|
|
276
|
+
const state = await prepareAdmittedConfigure(h);
|
|
277
|
+
await captureAdmittedConfigureWrite(state.token).invoke();
|
|
278
|
+
return state;
|
|
279
|
+
},
|
|
280
|
+
async (h, state) => {
|
|
281
|
+
const before = h.calls.length;
|
|
282
|
+
expect(() => captureAdmittedConfigureRecovery(state.token)).toThrow();
|
|
283
|
+
expect(h.calls).toHaveLength(before);
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
function deferred() {
|
|
288
|
+
let resolve!: () => void;
|
|
289
|
+
const promise = new Promise<void>((done) => {
|
|
290
|
+
resolve = done;
|
|
291
|
+
});
|
|
292
|
+
return { promise, resolve };
|
|
293
|
+
}
|
|
294
|
+
for (const phase of ["post", "append"] as const) {
|
|
295
|
+
const entered = deferred(),
|
|
296
|
+
released = deferred();
|
|
297
|
+
let armed = false,
|
|
298
|
+
appends = 0;
|
|
299
|
+
configureAdmissionCase(
|
|
300
|
+
"pending original " + phase + " refuses recovery even after visible commit",
|
|
301
|
+
async (h) => {
|
|
302
|
+
const state = await prepareAdmittedConfigure(h);
|
|
303
|
+
armed = true;
|
|
304
|
+
appends = 0;
|
|
305
|
+
const original = captureAdmittedConfigureWrite(state.token).invoke();
|
|
306
|
+
expect(
|
|
307
|
+
await Promise.race([
|
|
308
|
+
entered.promise.then(() => true),
|
|
309
|
+
original.then(
|
|
310
|
+
() => false,
|
|
311
|
+
() => false,
|
|
312
|
+
),
|
|
313
|
+
]),
|
|
314
|
+
).toBe(true);
|
|
315
|
+
if (phase === "append") {
|
|
316
|
+
await vi.advanceTimersByTimeAsync(5001);
|
|
317
|
+
expect(object(await original).status).toBe("configure_unknown");
|
|
318
|
+
}
|
|
319
|
+
return { ...state, original };
|
|
320
|
+
},
|
|
321
|
+
async (h, state) => {
|
|
322
|
+
const before = h.calls.length;
|
|
323
|
+
try {
|
|
324
|
+
expect(() => captureAdmittedConfigureRecovery(state.token)).toThrow();
|
|
325
|
+
expect(() =>
|
|
326
|
+
readAdmittedConfigureAcknowledgement(state.token),
|
|
327
|
+
).toThrow();
|
|
328
|
+
expect(h.calls).toHaveLength(before);
|
|
329
|
+
expect(posts(h, state)).toHaveLength(1);
|
|
330
|
+
} finally {
|
|
331
|
+
released.resolve();
|
|
332
|
+
}
|
|
333
|
+
const result = await state.original;
|
|
334
|
+
if (phase === "post")
|
|
335
|
+
expect(object(result).status).toBe("configure_acknowledged");
|
|
336
|
+
await vi.advanceTimersByTimeAsync(0);
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
beforeFetch: async (path, method) => {
|
|
340
|
+
if (
|
|
341
|
+
armed &&
|
|
342
|
+
phase === "post" &&
|
|
343
|
+
method === "POST" &&
|
|
344
|
+
path.startsWith("/v1/subscription_schedules/")
|
|
345
|
+
) {
|
|
346
|
+
armed = false;
|
|
347
|
+
entered.resolve();
|
|
348
|
+
await released.promise;
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
afterAppend: async () => {
|
|
352
|
+
if (armed && phase === "append" && ++appends === 2) {
|
|
353
|
+
armed = false;
|
|
354
|
+
entered.resolve();
|
|
355
|
+
await released.promise;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
configureAdmissionCase(
|
|
362
|
+
"actual safe response resumes without POST after C9 hashing fails",
|
|
363
|
+
async (h) => {
|
|
364
|
+
const state = await prepareAdmittedConfigure(h);
|
|
365
|
+
const native = crypto.subtle.digest.bind(crypto.subtle);
|
|
366
|
+
let fail = true;
|
|
367
|
+
const digest = vi
|
|
368
|
+
.spyOn(crypto.subtle, "digest")
|
|
369
|
+
.mockImplementation((algorithm, input) => {
|
|
370
|
+
if (ArrayBuffer.isView(input)) {
|
|
371
|
+
const tuple: unknown = JSON.parse(
|
|
372
|
+
new TextDecoder().decode(
|
|
373
|
+
new Uint8Array(input.buffer, input.byteOffset, input.byteLength),
|
|
374
|
+
),
|
|
375
|
+
);
|
|
376
|
+
if (
|
|
377
|
+
fail &&
|
|
378
|
+
Array.isArray(tuple) &&
|
|
379
|
+
tuple[2] === "renewal-configured-baseline"
|
|
380
|
+
) {
|
|
381
|
+
fail = false;
|
|
382
|
+
return Promise.reject(Error("CONTROLLED_C9_HASH_FAULT"));
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return native(algorithm, input);
|
|
386
|
+
});
|
|
387
|
+
try {
|
|
388
|
+
expect(
|
|
389
|
+
object(await captureAdmittedConfigureWrite(state.token).invoke())
|
|
390
|
+
.status,
|
|
391
|
+
).toBe("configure_unknown");
|
|
392
|
+
} finally {
|
|
393
|
+
digest.mockRestore();
|
|
394
|
+
}
|
|
395
|
+
expect(fail).toBe(false);
|
|
396
|
+
expect(readOriginalConfigureAttempt(state.token).response).not.toBeNull();
|
|
397
|
+
expect(readOriginalConfigureAttempt(state.token).receipt).toBeNull();
|
|
398
|
+
return state;
|
|
399
|
+
},
|
|
400
|
+
async (h, state) => {
|
|
401
|
+
const before = h.calls.length;
|
|
402
|
+
const output = await captureAdmittedConfigureRecovery(state.token).invoke();
|
|
403
|
+
expect(object(output).status).toBe("configure_acknowledged");
|
|
404
|
+
expect(h.calls).toHaveLength(before);
|
|
405
|
+
expect(
|
|
406
|
+
readAdmittedConfigureAcknowledgement(state.token).output === output,
|
|
407
|
+
).toBe(true);
|
|
408
|
+
},
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
unknownCase(
|
|
412
|
+
"missing original fresh evidence cannot qualify recovery from disposition alone",
|
|
413
|
+
async (h, state) => {
|
|
414
|
+
const attempt = readOriginalConfigureAttempt(state.token);
|
|
415
|
+
Reflect.set(attempt, "freshEvidence", null);
|
|
416
|
+
const before = h.calls.length;
|
|
417
|
+
expect(() => captureAdmittedConfigureRecovery(state.token)).toThrow();
|
|
418
|
+
expect(h.calls).toHaveLength(before);
|
|
419
|
+
},
|
|
420
|
+
);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { prepareAdmittedConfigure } from "./producerConfigureAdmission.js";
|
|
3
|
+
import { captureAdmittedConfigureWrite } from "../producer/configureWrite.js";
|
|
4
|
+
|
|
5
|
+
export async function historySnapshot(
|
|
6
|
+
h: Parameters<typeof prepareAdmittedConfigure>[0],
|
|
7
|
+
) {
|
|
8
|
+
const { child, token } = await prepareAdmittedConfigure(h);
|
|
9
|
+
await captureAdmittedConfigureWrite(token).invoke();
|
|
10
|
+
async function read(journal: typeof child.journal) {
|
|
11
|
+
const operation = await journal.loadAuthorizedOperation();
|
|
12
|
+
assert(operation?.activeAttempt);
|
|
13
|
+
const attempt = await journal.readAttempt({
|
|
14
|
+
attemptId: operation.activeAttempt.attemptId,
|
|
15
|
+
});
|
|
16
|
+
assert(attempt);
|
|
17
|
+
const events = await Promise.all(
|
|
18
|
+
attempt.events.map((event) =>
|
|
19
|
+
journal.readStageEvent({
|
|
20
|
+
attemptId: attempt.reservation.attemptId,
|
|
21
|
+
sequence: event.sequence,
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
);
|
|
25
|
+
const acknowledgement = await journal.readProviderAcknowledgement();
|
|
26
|
+
return { operation, attempt, events, acknowledgement };
|
|
27
|
+
}
|
|
28
|
+
const snapshot = structuredClone({
|
|
29
|
+
parent: await read(h.journal),
|
|
30
|
+
configure: await read(child.journal),
|
|
31
|
+
});
|
|
32
|
+
return snapshot;
|
|
33
|
+
}
|
|
34
|
+
export type HistorySnapshot = Awaited<ReturnType<typeof historySnapshot>>;
|
|
35
|
+
|
|
36
|
+
/** A prefix of already recorded real events, without inventing new evidence. */
|
|
37
|
+
export function historyPrefix(
|
|
38
|
+
full: HistorySnapshot,
|
|
39
|
+
head: number,
|
|
40
|
+
retained = false,
|
|
41
|
+
) {
|
|
42
|
+
const copy = structuredClone(full);
|
|
43
|
+
copy.configure.attempt.events.splice(head);
|
|
44
|
+
copy.configure.events.splice(head);
|
|
45
|
+
if (!retained) copy.configure.acknowledgement = null;
|
|
46
|
+
return copy;
|
|
47
|
+
}
|