@fantastic.dev/better-stripe 0.98.0 → 0.99.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 +6 -0
- package/README.md +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js +13 -5
- package/dist/client/billing/renewalAttach/internal/c10/attachEvents.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts +17 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js +140 -0
- package/dist/client/billing/renewalAttach/internal/operations/actorFailureControl.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +9 -11
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +3 -380
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +138 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +64 -139
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts +63 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.js +380 -0
- package/dist/client/billing/renewalAttach/internal/operations/transportKernel.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 +6 -0
- package/dist/client/billing/renewalAttach/internal/producer/invocationProducer.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts +56 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js +49 -0
- package/dist/client/billing/renewalAttach/internal/producer/journalWorkFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js +3 -2
- package/dist/client/billing/renewalAttach/internal/producer/operationFactory.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +87 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts +368 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js +106 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryFactory.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/output.js +22 -8
- package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/record.js +10 -2
- package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +69 -156
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +18 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js +15 -1
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -1
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +16 -16
- 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/usage/allowance.fixtures.d.ts +16 -16
- package/docs/renewal-context-reads.md +44 -3
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +3 -3
- package/src/client/billing/renewalAttach/internal/c10/attachEvents.ts +17 -5
- package/src/client/billing/renewalAttach/internal/operations/actorFailureControl.ts +165 -0
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +4 -498
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +83 -160
- package/src/client/billing/renewalAttach/internal/operations/transportKernel.ts +500 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +6 -0
- package/src/client/billing/renewalAttach/internal/producer/journalWorkFactory.ts +54 -0
- package/src/client/billing/renewalAttach/internal/producer/operationFactory.ts +3 -2
- package/src/client/billing/renewalAttach/internal/producer/producerRecovery.integration.test.ts +394 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecoveryControls.integration.test.ts +437 -0
- package/src/client/billing/renewalAttach/internal/producer/producerRecoveryIsolation.integration.test.ts +332 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +109 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryFactory.ts +135 -0
- package/src/client/billing/renewalAttach/internal/recovery/output.ts +34 -8
- package/src/client/billing/renewalAttach/internal/recovery/record.ts +16 -2
- package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +107 -188
- package/src/client/billing/renewalAttach/internal/recovery/relation.ts +17 -1
- package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +14 -1
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
3
|
+
import { initialOperations } from "../test-fixtures/producerInitialOperation.js";
|
|
4
|
+
import { declaredInputs } from "../test-fixtures/attachEntries.js";
|
|
5
|
+
import {
|
|
6
|
+
captureRetainedInput,
|
|
7
|
+
type RetainedInput,
|
|
8
|
+
} from "../material/capture.js";
|
|
9
|
+
import { INITIAL_NS } from "../test-fixtures/producerInitialDeclarations.js";
|
|
10
|
+
import { captureInitialInvocationCore } from "./invocationProducer.js";
|
|
11
|
+
import { data } from "../test-fixtures/attachScenarioBarriers.js";
|
|
12
|
+
|
|
13
|
+
const controls = vi.hoisted(() => {
|
|
14
|
+
const entries: { coversRetained(): boolean; coversFresh(): boolean }[] = [];
|
|
15
|
+
const recovery: { originalEntry: unknown; coversReplay(): boolean }[] = [];
|
|
16
|
+
return { entries, recovery, legacy: 0 };
|
|
17
|
+
});
|
|
18
|
+
// Synthetic TEST coverage only. Production compiled profile arrays stay EMPTY.
|
|
19
|
+
vi.mock("../operations/sourceOperations.js", () => {
|
|
20
|
+
const poisoned = () => {
|
|
21
|
+
controls.legacy++;
|
|
22
|
+
throw Error("LEGACY_SOURCE_POISON");
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
COMPILED_INITIAL_ENTRIES: controls.entries,
|
|
26
|
+
COMPILED_RECOVERY_ENTRIES: controls.recovery,
|
|
27
|
+
loadFixedExplicitRecoveryOperation: poisoned,
|
|
28
|
+
ORIGINAL_ORIGIN_ASSOCIATION: null,
|
|
29
|
+
loadFixedInitialOperation: poisoned,
|
|
30
|
+
loadOwnedTransportSource: poisoned,
|
|
31
|
+
loadInitialOwnedTransportSource: poisoned,
|
|
32
|
+
loadRecoveryOwnedTransportSource: poisoned,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
vi.mock("../originalOwner.js", () => ({
|
|
36
|
+
OWNER: Object.freeze({
|
|
37
|
+
get basis() {
|
|
38
|
+
controls.legacy++;
|
|
39
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
40
|
+
},
|
|
41
|
+
check() {
|
|
42
|
+
controls.legacy++;
|
|
43
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
44
|
+
},
|
|
45
|
+
sample() {
|
|
46
|
+
controls.legacy++;
|
|
47
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
48
|
+
},
|
|
49
|
+
subscribe() {
|
|
50
|
+
controls.legacy++;
|
|
51
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
52
|
+
},
|
|
53
|
+
retire() {
|
|
54
|
+
controls.legacy++;
|
|
55
|
+
throw Error("LEGACY_OWNER_POISON");
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
}));
|
|
59
|
+
type Declaration = {
|
|
60
|
+
source: RetainedInput;
|
|
61
|
+
post: Record<string, unknown>;
|
|
62
|
+
key: string;
|
|
63
|
+
};
|
|
64
|
+
function declaration(suffix?: string): Declaration {
|
|
65
|
+
const original = declaredInputs("INITIAL-ACK");
|
|
66
|
+
const replace = (_key: string, value: unknown) =>
|
|
67
|
+
suffix && value === "sub_original" ? "sub_original_" + suffix : value;
|
|
68
|
+
const raw = JSON.parse(JSON.stringify(original.original), replace);
|
|
69
|
+
if (suffix) raw.attachRequest.attachKey += ":" + suffix;
|
|
70
|
+
const post: Record<string, unknown> = JSON.parse(
|
|
71
|
+
JSON.stringify(original.aPost),
|
|
72
|
+
replace,
|
|
73
|
+
);
|
|
74
|
+
if (suffix) post.id += "_" + suffix;
|
|
75
|
+
return {
|
|
76
|
+
source: captureRetainedInput(raw),
|
|
77
|
+
post,
|
|
78
|
+
key: suffix
|
|
79
|
+
? "sk_test_invalid_actor_" + suffix
|
|
80
|
+
: "sk_test_invalid_owner_core",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function windowFor(source: RetainedInput) {
|
|
84
|
+
return {
|
|
85
|
+
workEndWallMs: (source.attachRequest.firstDispatchedAt + 4) * 1000,
|
|
86
|
+
endWallMs: (source.attachRequest.firstDispatchedAt + 5) * 1000,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function wireFor(
|
|
90
|
+
declared: Declaration[],
|
|
91
|
+
beforePost = async (_index: number) => {},
|
|
92
|
+
) {
|
|
93
|
+
const calls: { method: string; path: string; index: number }[] = [];
|
|
94
|
+
const routes = new Map<string, { body: unknown; auth: Set<string> }>();
|
|
95
|
+
for (const item of declared) {
|
|
96
|
+
const b = item.source.originalBundle;
|
|
97
|
+
const rows: [string, unknown][] = [
|
|
98
|
+
[
|
|
99
|
+
"/v1/subscriptions/" +
|
|
100
|
+
item.source.attachRequest.preparation.expected.subscriptionId,
|
|
101
|
+
b.wireSubscription,
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"/v1/prices/" +
|
|
105
|
+
item.source.attachRequest.preparation.expected.targetPriceId,
|
|
106
|
+
b.wireTargetPrice,
|
|
107
|
+
],
|
|
108
|
+
["/v1/customers/" + b.wireBillingCustomer.id, b.wireBillingCustomer],
|
|
109
|
+
];
|
|
110
|
+
for (const row of b.couponReads) {
|
|
111
|
+
assert(typeof row.couponId === "string");
|
|
112
|
+
rows.push([
|
|
113
|
+
"/v1/coupons/" + encodeURIComponent(row.couponId),
|
|
114
|
+
row.wireCoupon,
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
for (const [path, body] of rows) {
|
|
118
|
+
const route = routes.get(path) ?? { body, auth: new Set<string>() };
|
|
119
|
+
route.auth.add("Bearer " + item.key);
|
|
120
|
+
routes.set(path, route);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
calls,
|
|
125
|
+
fetch: async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
126
|
+
const url = new URL(String(input));
|
|
127
|
+
assert.equal(url.origin, "https://api.stripe.com");
|
|
128
|
+
assert.equal(init?.redirect, "error");
|
|
129
|
+
const headers = new Headers(init?.headers);
|
|
130
|
+
const auth = headers.get("authorization");
|
|
131
|
+
let body: unknown,
|
|
132
|
+
index = -1;
|
|
133
|
+
if (init?.method === "GET") {
|
|
134
|
+
const row = routes.get(url.pathname);
|
|
135
|
+
assert(row && auth && row.auth.has(auth));
|
|
136
|
+
body = row.body;
|
|
137
|
+
} else {
|
|
138
|
+
assert.equal(init?.method, "POST");
|
|
139
|
+
assert.equal(url.pathname, "/v1/subscription_schedules");
|
|
140
|
+
index = declared.findIndex(
|
|
141
|
+
(item) =>
|
|
142
|
+
item.source.attachRequest.attachKey ===
|
|
143
|
+
headers.get("idempotency-key"),
|
|
144
|
+
);
|
|
145
|
+
assert(index >= 0);
|
|
146
|
+
assert.equal(auth, "Bearer " + declared[index].key);
|
|
147
|
+
assert.equal(
|
|
148
|
+
new URLSearchParams(String(init?.body)).get("from_subscription"),
|
|
149
|
+
declared[index].source.attachRequest.preparation.expected
|
|
150
|
+
.subscriptionId,
|
|
151
|
+
);
|
|
152
|
+
await beforePost(index);
|
|
153
|
+
body = declared[index].post;
|
|
154
|
+
}
|
|
155
|
+
calls.push({ method: init?.method ?? "", path: url.pathname, index });
|
|
156
|
+
return new Response(JSON.stringify(body), {
|
|
157
|
+
status: 200,
|
|
158
|
+
headers: {
|
|
159
|
+
"content-type": "application/json",
|
|
160
|
+
"request-id": "req_initial_actor_" + calls.length,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
beforeEach(() => {
|
|
167
|
+
controls.legacy = 0;
|
|
168
|
+
controls.entries.splice(0, controls.entries.length, {
|
|
169
|
+
coversRetained: () => true,
|
|
170
|
+
coversFresh: () => true,
|
|
171
|
+
});
|
|
172
|
+
controls.recovery.splice(0, controls.recovery.length, {
|
|
173
|
+
originalEntry: controls.entries[0],
|
|
174
|
+
coversReplay: () => true,
|
|
175
|
+
});
|
|
176
|
+
vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
|
|
177
|
+
vi.setSystemTime(
|
|
178
|
+
(declaration().source.attachRequest.firstDispatchedAt + 1) * 1000,
|
|
179
|
+
);
|
|
180
|
+
vi.spyOn(process.hrtime, "bigint").mockReturnValue(INITIAL_NS);
|
|
181
|
+
});
|
|
182
|
+
afterEach(() => {
|
|
183
|
+
vi.useRealTimers();
|
|
184
|
+
vi.unstubAllGlobals();
|
|
185
|
+
vi.restoreAllMocks();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
function recover(core: object) {
|
|
189
|
+
const capture = Reflect.get(core, "recoverAttach");
|
|
190
|
+
expect(typeof capture).toBe("function");
|
|
191
|
+
return Reflect.apply(capture, core, []) as { invoke(): Promise<unknown> };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
it("retiring one recovery during a pending SDK read cannot retire another SDK root or return its receipt", async () => {
|
|
195
|
+
const declared = [declaration("alpha"), declaration("bravo")];
|
|
196
|
+
const posts = [0, 0];
|
|
197
|
+
let ready = 0,
|
|
198
|
+
allReady!: () => void,
|
|
199
|
+
readEntered!: () => void,
|
|
200
|
+
release!: () => void;
|
|
201
|
+
const readyBarrier = new Promise<void>((resolve) => {
|
|
202
|
+
allReady = resolve;
|
|
203
|
+
});
|
|
204
|
+
const entered = new Promise<void>((resolve) => {
|
|
205
|
+
readEntered = resolve;
|
|
206
|
+
});
|
|
207
|
+
const pendingRead = new Promise<void>((resolve) => {
|
|
208
|
+
release = resolve;
|
|
209
|
+
});
|
|
210
|
+
const cores: ({ owner: { retire(): void } } | undefined)[] = [];
|
|
211
|
+
const wire = wireFor(declared, async (index) => {
|
|
212
|
+
posts[index]++;
|
|
213
|
+
if (posts[index] === 1) throw Error("CONTROLLED_LOST_RESPONSE");
|
|
214
|
+
});
|
|
215
|
+
const controlledFetch = async (
|
|
216
|
+
input: RequestInfo | URL,
|
|
217
|
+
init?: RequestInit,
|
|
218
|
+
) => {
|
|
219
|
+
const path = new URL(String(input)).pathname;
|
|
220
|
+
if (
|
|
221
|
+
posts[0] === 1 &&
|
|
222
|
+
init?.method === "GET" &&
|
|
223
|
+
path ===
|
|
224
|
+
"/v1/subscriptions/" +
|
|
225
|
+
declared[0].source.attachRequest.preparation.expected.subscriptionId
|
|
226
|
+
) {
|
|
227
|
+
readEntered();
|
|
228
|
+
await pendingRead;
|
|
229
|
+
}
|
|
230
|
+
return wire.fetch(input, init);
|
|
231
|
+
};
|
|
232
|
+
try {
|
|
233
|
+
await initialOperations(
|
|
234
|
+
async ({ fresh, journal, index }) => {
|
|
235
|
+
vi.stubGlobal("fetch", controlledFetch);
|
|
236
|
+
assert(fresh.result.disposition === "acquired");
|
|
237
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
238
|
+
cores[index] = core;
|
|
239
|
+
try {
|
|
240
|
+
await expect(core.initialAttach().invoke()).rejects.toThrow(
|
|
241
|
+
"INITIAL_PROVIDER_REJECTED",
|
|
242
|
+
);
|
|
243
|
+
expect(posts[index]).toBe(1);
|
|
244
|
+
ready++;
|
|
245
|
+
if (ready === 2) allReady();
|
|
246
|
+
await readyBarrier;
|
|
247
|
+
if (index === 0) {
|
|
248
|
+
const result = recover(core).invoke();
|
|
249
|
+
const observed = result.catch((error) => error);
|
|
250
|
+
await entered;
|
|
251
|
+
expect(await observed).toMatchObject({
|
|
252
|
+
message: "INITIAL_ACTOR_STOP",
|
|
253
|
+
});
|
|
254
|
+
expect(await journal.readProviderAcknowledgement()).toBeNull();
|
|
255
|
+
expect(
|
|
256
|
+
await journal.readStageEvent({
|
|
257
|
+
attemptId: fresh.result.reservation.attemptId,
|
|
258
|
+
sequence: 2,
|
|
259
|
+
}),
|
|
260
|
+
).toBeNull();
|
|
261
|
+
} else {
|
|
262
|
+
await entered;
|
|
263
|
+
cores[0]!.owner.retire();
|
|
264
|
+
const result = data(await recover(core).invoke());
|
|
265
|
+
expect(result.status).toBe("attach_acknowledged");
|
|
266
|
+
expect(data(result.receipt).providerSnapshot).toEqual(
|
|
267
|
+
declared[1].post,
|
|
268
|
+
);
|
|
269
|
+
const retained = await journal.readProviderAcknowledgement();
|
|
270
|
+
assert(retained);
|
|
271
|
+
expect(JSON.parse(retained.receiptJSON)).toEqual(result.receipt);
|
|
272
|
+
expect(
|
|
273
|
+
await journal.readStageEvent({
|
|
274
|
+
attemptId: fresh.result.reservation.attemptId,
|
|
275
|
+
sequence: 3,
|
|
276
|
+
}),
|
|
277
|
+
).not.toBeNull();
|
|
278
|
+
}
|
|
279
|
+
expect(controls.legacy).toBe(0);
|
|
280
|
+
} finally {
|
|
281
|
+
core.owner.retire();
|
|
282
|
+
if (index === 0) release();
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
2,
|
|
286
|
+
{
|
|
287
|
+
sources: declared.map((item) => item.source),
|
|
288
|
+
keys: declared.map((item) => item.key),
|
|
289
|
+
...windowFor(declared[0].source),
|
|
290
|
+
},
|
|
291
|
+
);
|
|
292
|
+
expect(posts).toEqual([1, 2]);
|
|
293
|
+
} finally {
|
|
294
|
+
release();
|
|
295
|
+
for (const core of cores) core?.owner.retire();
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("an explicit recovery cannot renew the original absolute deadline after an unknown POST", async () => {
|
|
300
|
+
const declared = declaration();
|
|
301
|
+
await initialOperations(
|
|
302
|
+
async ({ fresh, journal }) => {
|
|
303
|
+
let posts = 0;
|
|
304
|
+
const wire = wireFor([declared], async () => {
|
|
305
|
+
posts++;
|
|
306
|
+
throw Error("CONTROLLED_LOST_RESPONSE");
|
|
307
|
+
});
|
|
308
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
309
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
310
|
+
const basis = core.basisJSON;
|
|
311
|
+
try {
|
|
312
|
+
await expect(core.initialAttach().invoke()).rejects.toThrow(
|
|
313
|
+
"INITIAL_PROVIDER_REJECTED",
|
|
314
|
+
);
|
|
315
|
+
const requests = wire.calls.length;
|
|
316
|
+
vi.setSystemTime(windowFor(declared.source).workEndWallMs);
|
|
317
|
+
await expect(recover(core).invoke()).rejects.toThrow(
|
|
318
|
+
"INITIAL_OWNER_STOP",
|
|
319
|
+
);
|
|
320
|
+
expect(core.basisJSON).toBe(basis);
|
|
321
|
+
expect(wire.calls).toHaveLength(requests);
|
|
322
|
+
expect(posts).toBe(1);
|
|
323
|
+
expect(await journal.readProviderAcknowledgement()).toBeNull();
|
|
324
|
+
expect(controls.legacy).toBe(0);
|
|
325
|
+
} finally {
|
|
326
|
+
core.owner.retire();
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
1,
|
|
330
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
331
|
+
);
|
|
332
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { readInitialLineage } from "./lineageAuthority.js";
|
|
3
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { recoveryOperationForLineage } from "./recoveryFactory.js";
|
|
6
|
+
import { captureExplicitAttachRecoveryForLineage } from "../recovery/recoveryActor.js";
|
|
7
|
+
import { COMPILED_RECOVERY_ENTRIES } from "../operations/sourceOperations.js";
|
|
8
|
+
import {
|
|
9
|
+
need,
|
|
10
|
+
refuse,
|
|
11
|
+
seven,
|
|
12
|
+
sourceMethod,
|
|
13
|
+
} from "../operations/initialActorData.js";
|
|
14
|
+
import { closed } from "../operations/types.js";
|
|
15
|
+
import { createRecoveryAttachEventCompiler } from "../c10/attachEvents.js";
|
|
16
|
+
import { constructRenewalScheduleAttachmentReceiptV2 as c3 } from "../../../renewalV2/index.js";
|
|
17
|
+
import { retainInitialReceiptForLineage } from "./operationFactory.js";
|
|
18
|
+
import { admitInitialOutput } from "../recovery/material.js";
|
|
19
|
+
|
|
20
|
+
const actors = new WeakMap<object, ReturnType<typeof construct>>();
|
|
21
|
+
export function captureLiveAttachRecovery(token: object) {
|
|
22
|
+
need(arguments.length === 1);
|
|
23
|
+
readInitialLineage(token);
|
|
24
|
+
let actor = actors.get(token);
|
|
25
|
+
if (!actor) {
|
|
26
|
+
actor = construct(token);
|
|
27
|
+
actors.set(token, actor);
|
|
28
|
+
}
|
|
29
|
+
return actor;
|
|
30
|
+
}
|
|
31
|
+
function construct(token: object) {
|
|
32
|
+
let consumed = false;
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
async invoke() {
|
|
35
|
+
need(arguments.length === 0);
|
|
36
|
+
if (consumed) return refuse("invocation_consumed");
|
|
37
|
+
consumed = true;
|
|
38
|
+
need(
|
|
39
|
+
Array.isArray(COMPILED_RECOVERY_ENTRIES) &&
|
|
40
|
+
!types.isProxy(COMPILED_RECOVERY_ENTRIES),
|
|
41
|
+
);
|
|
42
|
+
if (COMPILED_RECOVERY_ENTRIES.length === 0)
|
|
43
|
+
return refuse("no_qualified_recovery_class");
|
|
44
|
+
const owner = ownerForInitialLineage(token);
|
|
45
|
+
owner.check();
|
|
46
|
+
// This consumes actual attempt custody synchronously, before any await.
|
|
47
|
+
const frame = await recoveryOperationForLineage(token);
|
|
48
|
+
const snapshot = frame.snapshot;
|
|
49
|
+
need(
|
|
50
|
+
sourceMethod(snapshot.entry, "coversRetained") ===
|
|
51
|
+
snapshot.retainedPredicate,
|
|
52
|
+
);
|
|
53
|
+
need(
|
|
54
|
+
sourceMethod(snapshot.entry, "coversFresh") === snapshot.freshPredicate,
|
|
55
|
+
);
|
|
56
|
+
const relations = COMPILED_RECOVERY_ENTRIES.filter((value) => {
|
|
57
|
+
const relation = closed(value, ["originalEntry", "coversReplay"]);
|
|
58
|
+
sourceMethod(value, "coversReplay");
|
|
59
|
+
return relation.originalEntry === snapshot.entry;
|
|
60
|
+
});
|
|
61
|
+
need(relations.length === 1);
|
|
62
|
+
if (snapshot.response === null)
|
|
63
|
+
return captureExplicitAttachRecoveryForLineage(token).invoke();
|
|
64
|
+
const response = snapshot.response;
|
|
65
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
66
|
+
const compiler = createRecoveryAttachEventCompiler(token);
|
|
67
|
+
owner.check();
|
|
68
|
+
await owned(() =>
|
|
69
|
+
compiler.dispatch({
|
|
70
|
+
event: "dispatch",
|
|
71
|
+
stage: "attach",
|
|
72
|
+
request: snapshot.request,
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
await owned(() =>
|
|
76
|
+
compiler.response({
|
|
77
|
+
event: "response",
|
|
78
|
+
stage: "attach",
|
|
79
|
+
request: snapshot.request,
|
|
80
|
+
body: response.body,
|
|
81
|
+
status: response.status,
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
const receipt = await owned(() =>
|
|
85
|
+
c3({
|
|
86
|
+
attachRequest: snapshot.raw,
|
|
87
|
+
actualDispatch: seven(snapshot.request),
|
|
88
|
+
providerSnapshot: response.body as Record<string, unknown>,
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
await owned(() => retainInitialReceiptForLineage(token, receipt));
|
|
92
|
+
await owned(() =>
|
|
93
|
+
compiler.receipt({
|
|
94
|
+
event: "receipt",
|
|
95
|
+
stage: "attach",
|
|
96
|
+
request: snapshot.request,
|
|
97
|
+
receipt,
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
const admitted = admitInitialOutput(
|
|
101
|
+
receipt,
|
|
102
|
+
snapshot.prepared,
|
|
103
|
+
snapshot.request,
|
|
104
|
+
);
|
|
105
|
+
owner.check();
|
|
106
|
+
return admitted;
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { takeInitialRecoveryRecord } from "../operations/initialAttach.js";
|
|
2
|
+
import { readInitialLineage } from "./lineageAuthority.js";
|
|
3
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
|
+
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
|
+
import { operationForInitialLineage } from "./operationFactory.js";
|
|
6
|
+
import { journalWorkForInitialLineage } from "./journalWorkFactory.js";
|
|
7
|
+
import { build } from "../operations/transportKernel.js";
|
|
8
|
+
import { createSelectedRawAcquisition } from "../acquisition/ownedAcquisition.js";
|
|
9
|
+
import { need, sourceMethod } from "../operations/initialActorData.js";
|
|
10
|
+
import { closed } from "../operations/types.js";
|
|
11
|
+
import { COMPILED_RECOVERY_ENTRIES } from "../operations/sourceOperations.js";
|
|
12
|
+
|
|
13
|
+
const frames = new WeakMap<object, ReturnType<typeof construct>>();
|
|
14
|
+
/** One reservation of actual initial custody, synchronously before construction awaits. */
|
|
15
|
+
export function recoveryOperationForLineage(token: object) {
|
|
16
|
+
need(arguments.length === 1);
|
|
17
|
+
const owner = ownerForInitialLineage(token);
|
|
18
|
+
owner.check();
|
|
19
|
+
let pending = frames.get(token);
|
|
20
|
+
if (!pending) {
|
|
21
|
+
const snapshot = takeInitialRecoveryRecord(token);
|
|
22
|
+
need(
|
|
23
|
+
sourceMethod(snapshot.entry, "coversRetained") ===
|
|
24
|
+
snapshot.retainedPredicate,
|
|
25
|
+
);
|
|
26
|
+
need(
|
|
27
|
+
sourceMethod(snapshot.entry, "coversFresh") === snapshot.freshPredicate,
|
|
28
|
+
);
|
|
29
|
+
const relations = COMPILED_RECOVERY_ENTRIES.filter((value) => {
|
|
30
|
+
const relation = closed(value, ["originalEntry", "coversReplay"]);
|
|
31
|
+
sourceMethod(value, "coversReplay");
|
|
32
|
+
return relation.originalEntry === snapshot.entry;
|
|
33
|
+
});
|
|
34
|
+
need(relations.length === 1);
|
|
35
|
+
pending = construct(token, snapshot);
|
|
36
|
+
frames.set(token, pending);
|
|
37
|
+
}
|
|
38
|
+
return pending;
|
|
39
|
+
}
|
|
40
|
+
async function construct(
|
|
41
|
+
token: object,
|
|
42
|
+
snapshot: ReturnType<typeof takeInitialRecoveryRecord>,
|
|
43
|
+
) {
|
|
44
|
+
const owner = ownerForInitialLineage(token);
|
|
45
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
46
|
+
const lineage = readInitialLineage(token);
|
|
47
|
+
const original = await owned(() => operationForInitialLineage(token));
|
|
48
|
+
owner.check();
|
|
49
|
+
if (snapshot.response !== null)
|
|
50
|
+
return Object.freeze({
|
|
51
|
+
snapshot,
|
|
52
|
+
operation: null,
|
|
53
|
+
pair: null,
|
|
54
|
+
reader: null,
|
|
55
|
+
});
|
|
56
|
+
const manifest = await owned(() =>
|
|
57
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
58
|
+
);
|
|
59
|
+
need(
|
|
60
|
+
manifest &&
|
|
61
|
+
manifest.events.length === 1 &&
|
|
62
|
+
manifest.events[0].sequence === 1,
|
|
63
|
+
);
|
|
64
|
+
need(
|
|
65
|
+
(await owned(() => lineage.journal.readProviderAcknowledgement())) === null,
|
|
66
|
+
);
|
|
67
|
+
need(journalWorkForInitialLineage(token).idle());
|
|
68
|
+
let reserved = false;
|
|
69
|
+
const operation = Object.freeze({
|
|
70
|
+
owner,
|
|
71
|
+
originAssociation: lineage.originAssociation,
|
|
72
|
+
originalEntry: snapshot.entry,
|
|
73
|
+
originalRecord: snapshot.originalRecord,
|
|
74
|
+
readPlan: original.operation.readPlan,
|
|
75
|
+
delegate: original.operation.delegate,
|
|
76
|
+
sink: original.operation.sink,
|
|
77
|
+
reserve(claimedOwner: unknown, origin: unknown, entry: unknown) {
|
|
78
|
+
need(
|
|
79
|
+
arguments.length === 3 &&
|
|
80
|
+
!reserved &&
|
|
81
|
+
claimedOwner === owner &&
|
|
82
|
+
origin === lineage.originAssociation &&
|
|
83
|
+
entry === snapshot.entry,
|
|
84
|
+
);
|
|
85
|
+
reserved = true;
|
|
86
|
+
owner.check();
|
|
87
|
+
return Object.freeze({});
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const pair = build(
|
|
91
|
+
{
|
|
92
|
+
owner,
|
|
93
|
+
request: original.request,
|
|
94
|
+
readPlan: operation.readPlan,
|
|
95
|
+
delegate: operation.delegate,
|
|
96
|
+
},
|
|
97
|
+
{ operation, readPlan: operation.readPlan, delegate: operation.delegate },
|
|
98
|
+
token,
|
|
99
|
+
);
|
|
100
|
+
const acquisition = createSelectedRawAcquisition(
|
|
101
|
+
owner,
|
|
102
|
+
pair.transport.readTransport,
|
|
103
|
+
);
|
|
104
|
+
const reader = Object.freeze({
|
|
105
|
+
acquire() {
|
|
106
|
+
need(arguments.length === 0);
|
|
107
|
+
return owned(() => acquisition.acquire(original.expected));
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
owner.check();
|
|
111
|
+
return Object.freeze({ snapshot, operation, pair, reader });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Best-effort final read fence; this is not an atomic journal/provider lock. */
|
|
115
|
+
export async function assertReplayFrontierForLineage(token: object) {
|
|
116
|
+
need(arguments.length === 1 && frames.has(token));
|
|
117
|
+
const owner = ownerForInitialLineage(token);
|
|
118
|
+
const owned = ownedAwaitForInitialLineage(token);
|
|
119
|
+
const lineage = readInitialLineage(token);
|
|
120
|
+
owner.check();
|
|
121
|
+
need(journalWorkForInitialLineage(token).idle());
|
|
122
|
+
need(
|
|
123
|
+
(await owned(() => lineage.journal.readProviderAcknowledgement())) === null,
|
|
124
|
+
);
|
|
125
|
+
const manifest = await owned(() =>
|
|
126
|
+
lineage.journal.readAttempt({ attemptId: lineage.reservation.attemptId }),
|
|
127
|
+
);
|
|
128
|
+
need(
|
|
129
|
+
manifest &&
|
|
130
|
+
manifest.events.length === 1 &&
|
|
131
|
+
manifest.events[0].sequence === 1,
|
|
132
|
+
);
|
|
133
|
+
need(journalWorkForInitialLineage(token).idle());
|
|
134
|
+
owner.check();
|
|
135
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { types } from "node:util";
|
|
2
|
+
import { ownerForInitialLineage } from "../producer/ownerFactory.js";
|
|
2
3
|
import { requiredJSONSnapshot } from "../material/requiredJson.js";
|
|
3
4
|
import {
|
|
4
5
|
objectNode,
|
|
@@ -25,16 +26,41 @@ export function admitRecoveryOutput(
|
|
|
25
26
|
observed: unknown,
|
|
26
27
|
prepared: Prepared,
|
|
27
28
|
request: AttachRequest,
|
|
29
|
+
) {
|
|
30
|
+
return admitOutput(receipt, observed, prepared, request, false);
|
|
31
|
+
}
|
|
32
|
+
export function admitRecoveryOutputForLineage(
|
|
33
|
+
token: object,
|
|
34
|
+
receipt: Receipt,
|
|
35
|
+
observed: unknown,
|
|
36
|
+
prepared: Prepared,
|
|
37
|
+
request: AttachRequest,
|
|
38
|
+
) {
|
|
39
|
+
need(arguments.length === 5);
|
|
40
|
+
const owner = ownerForInitialLineage(token);
|
|
41
|
+
owner.check();
|
|
42
|
+
const result = admitOutput(receipt, observed, prepared, request, true);
|
|
43
|
+
owner.check();
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function admitOutput(
|
|
47
|
+
receipt: Receipt,
|
|
48
|
+
observed: unknown,
|
|
49
|
+
prepared: Prepared,
|
|
50
|
+
request: AttachRequest,
|
|
51
|
+
allowNull: boolean,
|
|
28
52
|
) {
|
|
29
53
|
need(!types.isProxy(observed));
|
|
30
54
|
const observedID =
|
|
31
|
-
|
|
32
|
-
?
|
|
33
|
-
:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
allowNull && observed === null
|
|
56
|
+
? null
|
|
57
|
+
: typeof observed === "string"
|
|
58
|
+
? observed
|
|
59
|
+
: (() => {
|
|
60
|
+
need(observed !== null && typeof observed === "object");
|
|
61
|
+
return Object.getOwnPropertyDescriptor(observed, "id")
|
|
62
|
+
?.value as unknown;
|
|
63
|
+
})();
|
|
38
64
|
const output = {
|
|
39
65
|
kind: "EXPLICIT_ATTACH_RECOVERY_V2_DATA_ONLY",
|
|
40
66
|
status: "attach_acknowledged",
|
|
@@ -42,7 +68,7 @@ export function admitRecoveryOutput(
|
|
|
42
68
|
receipt,
|
|
43
69
|
observation: {
|
|
44
70
|
schedule: observed,
|
|
45
|
-
conflict: observedID !== receipt.scheduleId,
|
|
71
|
+
conflict: observedID !== null && observedID !== receipt.scheduleId,
|
|
46
72
|
authority: "unowned_prepost_observation_only",
|
|
47
73
|
},
|
|
48
74
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { types } from "node:util";
|
|
2
2
|
import { OWNER } from "../originalOwner.js";
|
|
3
|
+
import { ownerForInitialLineage } from "../producer/ownerFactory.js";
|
|
3
4
|
import { requiredJSONSnapshot } from "../material/requiredJson.js";
|
|
4
5
|
import {
|
|
5
6
|
closed,
|
|
@@ -78,7 +79,20 @@ export type CapturedRecord = Readonly<{
|
|
|
78
79
|
|
|
79
80
|
/** Detached unverified data only. The actor retains and proves its own record. */
|
|
80
81
|
export function captureRecoveryRecord(live: unknown): CapturedRecord {
|
|
81
|
-
OWNER
|
|
82
|
+
return captureRecord(live, OWNER);
|
|
83
|
+
}
|
|
84
|
+
export function captureRecoveryRecordForLineage(
|
|
85
|
+
token: object,
|
|
86
|
+
live: unknown,
|
|
87
|
+
): CapturedRecord {
|
|
88
|
+
need(arguments.length === 2);
|
|
89
|
+
return captureRecord(live, ownerForInitialLineage(token));
|
|
90
|
+
}
|
|
91
|
+
function captureRecord(
|
|
92
|
+
live: unknown,
|
|
93
|
+
owner: { check(): unknown },
|
|
94
|
+
): CapturedRecord {
|
|
95
|
+
owner.check();
|
|
82
96
|
const slots = new Map<string, string>(),
|
|
83
97
|
active = new Set<object>();
|
|
84
98
|
let nodes = 0,
|
|
@@ -189,7 +203,7 @@ export function captureRecoveryRecord(live: unknown): CapturedRecord {
|
|
|
189
203
|
const node = walk(live, "", 0);
|
|
190
204
|
need(slots.size === 6 && rawNode);
|
|
191
205
|
encode(node);
|
|
192
|
-
|
|
206
|
+
owner.check();
|
|
193
207
|
return Object.freeze({
|
|
194
208
|
node,
|
|
195
209
|
slots,
|