@fantastic.dev/better-stripe 0.99.0 → 0.100.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/operations/initialAttach.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +27 -1
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.d.ts +10 -0
- package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.js +49 -0
- package/dist/client/billing/renewalAttach/internal/producer/attachAcknowledgement.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/recoveryEntry.d.ts +9 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js +22 -0
- package/dist/client/billing/renewalAttach/internal/producer/recoveryEntry.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +9 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +27 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -1
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/mutations.d.ts +43 -43
- package/dist/component/balanceFunding/queries.d.ts +1 -1
- package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
- package/dist/component/earnings/triggers.d.ts +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/docs/renewal-context-reads.md +23 -0
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +28 -1
- package/src/client/billing/renewalAttach/internal/producer/attachAcknowledgement.ts +65 -0
- package/src/client/billing/renewalAttach/internal/producer/invocationProducer.ts +8 -0
- package/src/client/billing/renewalAttach/internal/producer/producerAcknowledgement.integration.test.ts +320 -0
- package/src/client/billing/renewalAttach/internal/producer/producerAcknowledgementControls.integration.test.ts +411 -0
- package/src/client/billing/renewalAttach/internal/producer/recoveryEntry.ts +35 -1
- package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +39 -0
|
@@ -0,0 +1,411 @@
|
|
|
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 acknowledgement(core: object) {
|
|
189
|
+
const read = Reflect.get(core, "attachAcknowledgement");
|
|
190
|
+
expect(typeof read).toBe("function");
|
|
191
|
+
return Reflect.apply(read, core, []) as Readonly<{
|
|
192
|
+
output: unknown;
|
|
193
|
+
receipt: unknown;
|
|
194
|
+
operationalAuthority: false;
|
|
195
|
+
}>;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
it.each(["retained", "fresh", "registry"])(
|
|
199
|
+
"a cached ACK refuses changed %s eligibility instead of returning stale custody",
|
|
200
|
+
async (change) => {
|
|
201
|
+
const declared = declaration();
|
|
202
|
+
await initialOperations(
|
|
203
|
+
async ({ fresh, journal }) => {
|
|
204
|
+
const wire = wireFor([declared]);
|
|
205
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
206
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
207
|
+
try {
|
|
208
|
+
const output = await core.initialAttach().invoke();
|
|
209
|
+
expect(acknowledgement(core).output).toBe(output);
|
|
210
|
+
if (change === "retained")
|
|
211
|
+
controls.entries[0].coversRetained = () => true;
|
|
212
|
+
if (change === "fresh") controls.entries[0].coversFresh = () => true;
|
|
213
|
+
if (change === "registry") controls.entries.length = 0;
|
|
214
|
+
const requests = wire.calls.length;
|
|
215
|
+
expect(() => acknowledgement(core)).toThrow(
|
|
216
|
+
"ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE",
|
|
217
|
+
);
|
|
218
|
+
expect(wire.calls).toHaveLength(requests);
|
|
219
|
+
expect(controls.legacy).toBe(0);
|
|
220
|
+
} finally {
|
|
221
|
+
core.owner.retire();
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
1,
|
|
225
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
226
|
+
);
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
it("copied receipt DATA, unknown tokens and extra arguments cannot register custody or sample clocks", async () => {
|
|
231
|
+
const declared = declaration();
|
|
232
|
+
const { readAttachAcknowledgementForLineage: read } =
|
|
233
|
+
await import("./attachAcknowledgement.js");
|
|
234
|
+
await initialOperations(
|
|
235
|
+
async ({ fresh, journal }) => {
|
|
236
|
+
const wire = wireFor([declared]);
|
|
237
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
238
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
239
|
+
try {
|
|
240
|
+
const output = await core.initialAttach().invoke();
|
|
241
|
+
const view = acknowledgement(core);
|
|
242
|
+
const copy = JSON.parse(JSON.stringify(output));
|
|
243
|
+
let foreign = 0;
|
|
244
|
+
const fake = {
|
|
245
|
+
get receipt() {
|
|
246
|
+
foreign++;
|
|
247
|
+
throw Error("FOREIGN_RECEIPT");
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
const wall = vi.spyOn(Date, "now");
|
|
251
|
+
const mono = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
252
|
+
expect(() => read(copy.receipt)).toThrow("INITIAL_LINEAGE_UNBOUND");
|
|
253
|
+
expect(() => read(fake)).toThrow("INITIAL_LINEAGE_UNBOUND");
|
|
254
|
+
expect(() =>
|
|
255
|
+
Reflect.apply(read, undefined, [fake, copy.receipt]),
|
|
256
|
+
).toThrow("ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE");
|
|
257
|
+
expect(() =>
|
|
258
|
+
Reflect.apply(core.attachAcknowledgement, undefined, [fake]),
|
|
259
|
+
).toThrow("INITIAL_OPERATION_UNBOUND");
|
|
260
|
+
expect(foreign).toBe(0);
|
|
261
|
+
expect(wall).not.toHaveBeenCalled();
|
|
262
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(mono);
|
|
263
|
+
expect(view.receipt).not.toBe(copy.receipt);
|
|
264
|
+
expect(acknowledgement(core)).toBe(view);
|
|
265
|
+
expect(controls.legacy).toBe(0);
|
|
266
|
+
} finally {
|
|
267
|
+
core.owner.retire();
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
1,
|
|
271
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("a committed receipt3 event with a pending reply is DATA until the real actor returns", async () => {
|
|
276
|
+
const declared = declaration();
|
|
277
|
+
let count = 0,
|
|
278
|
+
entered!: () => void,
|
|
279
|
+
release!: () => void;
|
|
280
|
+
const committed = new Promise<void>((resolve) => {
|
|
281
|
+
entered = resolve;
|
|
282
|
+
});
|
|
283
|
+
const pending = new Promise<void>((resolve) => {
|
|
284
|
+
release = resolve;
|
|
285
|
+
});
|
|
286
|
+
await initialOperations(
|
|
287
|
+
async ({ fresh, journal }) => {
|
|
288
|
+
assert(fresh.result.disposition === "acquired");
|
|
289
|
+
const wire = wireFor([declared]);
|
|
290
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
291
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
292
|
+
try {
|
|
293
|
+
const initial = core.initialAttach().invoke();
|
|
294
|
+
await committed;
|
|
295
|
+
expect(await journal.readProviderAcknowledgement()).not.toBeNull();
|
|
296
|
+
expect(
|
|
297
|
+
await journal.readStageEvent({
|
|
298
|
+
attemptId: fresh.result.reservation.attemptId,
|
|
299
|
+
sequence: 3,
|
|
300
|
+
}),
|
|
301
|
+
).not.toBeNull();
|
|
302
|
+
expect(() => acknowledgement(core)).toThrow(
|
|
303
|
+
"ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE",
|
|
304
|
+
);
|
|
305
|
+
release();
|
|
306
|
+
const output = await initial;
|
|
307
|
+
expect(acknowledgement(core).output).toBe(output);
|
|
308
|
+
expect(acknowledgement(core).receipt).toBe(data(output).receipt);
|
|
309
|
+
expect(controls.legacy).toBe(0);
|
|
310
|
+
} finally {
|
|
311
|
+
release();
|
|
312
|
+
core.owner.retire();
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
1,
|
|
316
|
+
{
|
|
317
|
+
source: declared.source,
|
|
318
|
+
...windowFor(declared.source),
|
|
319
|
+
afterAppend: async () => {
|
|
320
|
+
count++;
|
|
321
|
+
if (count === 3) {
|
|
322
|
+
entered();
|
|
323
|
+
await pending;
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("two real SDK roots retain distinct ACK identities and retirement invalidates only the original cached view", async () => {
|
|
331
|
+
const declared = [declaration("alpha"), declaration("bravo")];
|
|
332
|
+
const wire = wireFor(declared);
|
|
333
|
+
const cores: Awaited<ReturnType<typeof captureInitialInvocationCore>>[] = [];
|
|
334
|
+
const outputs: unknown[] = [];
|
|
335
|
+
let ready = 0,
|
|
336
|
+
allReady!: () => void,
|
|
337
|
+
retired!: () => void;
|
|
338
|
+
const complete = new Promise<void>((resolve) => {
|
|
339
|
+
allReady = resolve;
|
|
340
|
+
});
|
|
341
|
+
const retirement = new Promise<void>((resolve) => {
|
|
342
|
+
retired = resolve;
|
|
343
|
+
});
|
|
344
|
+
await initialOperations(
|
|
345
|
+
async ({ fresh, journal, index }) => {
|
|
346
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
347
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
348
|
+
cores[index] = core;
|
|
349
|
+
try {
|
|
350
|
+
outputs[index] = await core.initialAttach().invoke();
|
|
351
|
+
const view = acknowledgement(core);
|
|
352
|
+
ready++;
|
|
353
|
+
if (ready === 2) allReady();
|
|
354
|
+
await complete;
|
|
355
|
+
expect(view.output).toBe(outputs[index]);
|
|
356
|
+
expect(view.receipt).toBe(data(outputs[index]).receipt);
|
|
357
|
+
expect(view.receipt).not.toBe(data(outputs[1 - index]).receipt);
|
|
358
|
+
if (index === 0) {
|
|
359
|
+
await retirement;
|
|
360
|
+
expect(() => acknowledgement(core)).toThrow("INITIAL_OWNER_STOP");
|
|
361
|
+
} else {
|
|
362
|
+
cores[0].owner.retire();
|
|
363
|
+
retired();
|
|
364
|
+
expect(acknowledgement(core)).toBe(view);
|
|
365
|
+
expect(data(view.receipt).providerSnapshot).toEqual(declared[1].post);
|
|
366
|
+
}
|
|
367
|
+
expect(controls.legacy).toBe(0);
|
|
368
|
+
} finally {
|
|
369
|
+
core.owner.retire();
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
2,
|
|
373
|
+
{
|
|
374
|
+
sources: declared.map((value) => value.source),
|
|
375
|
+
keys: declared.map((value) => value.key),
|
|
376
|
+
...windowFor(declared[0].source),
|
|
377
|
+
},
|
|
378
|
+
);
|
|
379
|
+
expect(wire.calls.filter((row) => row.method === "POST")).toHaveLength(2);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("reading absent ACK custody from a genuine bare lineage cannot construct an Owner or sample clocks", async () => {
|
|
383
|
+
const declared = declaration();
|
|
384
|
+
const { mintInitialLineage } = await import("./lineageAuthority.js");
|
|
385
|
+
const { readAttachAcknowledgementForLineage: read } =
|
|
386
|
+
await import("./attachAcknowledgement.js");
|
|
387
|
+
await initialOperations(
|
|
388
|
+
async ({ fresh, journal }) => {
|
|
389
|
+
const token = mintInitialLineage(fresh.call, journal, 2);
|
|
390
|
+
const mono = vi.mocked(process.hrtime.bigint).mock.calls.length;
|
|
391
|
+
const wall = vi.spyOn(Date, "now");
|
|
392
|
+
const timers = vi.spyOn(globalThis, "setTimeout");
|
|
393
|
+
try {
|
|
394
|
+
expect(() => read(token)).toThrow("ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE");
|
|
395
|
+
expect(wall).not.toHaveBeenCalled();
|
|
396
|
+
expect(vi.mocked(process.hrtime.bigint).mock.calls.length).toBe(mono);
|
|
397
|
+
expect(timers).not.toHaveBeenCalled();
|
|
398
|
+
const stored = await journal.loadAuthorizedOperation();
|
|
399
|
+
assert(
|
|
400
|
+
stored && "recordVersion" in stored && stored.recordVersion === 2,
|
|
401
|
+
);
|
|
402
|
+
expect(stored.initialBasis).toBeNull();
|
|
403
|
+
expect(controls.legacy).toBe(0);
|
|
404
|
+
} finally {
|
|
405
|
+
vi.clearAllTimers();
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
1,
|
|
409
|
+
{ source: declared.source, ...windowFor(declared.source) },
|
|
410
|
+
);
|
|
411
|
+
});
|
|
@@ -11,12 +11,32 @@ import {
|
|
|
11
11
|
seven,
|
|
12
12
|
sourceMethod,
|
|
13
13
|
} from "../operations/initialActorData.js";
|
|
14
|
-
import { closed } from "../operations/types.js";
|
|
14
|
+
import { closed, type SourceMethod } from "../operations/types.js";
|
|
15
15
|
import { createRecoveryAttachEventCompiler } from "../c10/attachEvents.js";
|
|
16
16
|
import { constructRenewalScheduleAttachmentReceiptV2 as c3 } from "../../../renewalV2/index.js";
|
|
17
17
|
import { retainInitialReceiptForLineage } from "./operationFactory.js";
|
|
18
18
|
import { admitInitialOutput } from "../recovery/material.js";
|
|
19
19
|
|
|
20
|
+
const returnedAcknowledgements = new WeakMap<
|
|
21
|
+
object,
|
|
22
|
+
Readonly<{
|
|
23
|
+
originalEntry: unknown;
|
|
24
|
+
retainedPredicate: SourceMethod;
|
|
25
|
+
freshPredicate: SourceMethod;
|
|
26
|
+
output: unknown;
|
|
27
|
+
receipt: unknown;
|
|
28
|
+
}>
|
|
29
|
+
>();
|
|
30
|
+
/** Actual no-POST acknowledgement completion only, not a retained receipt lookup. */
|
|
31
|
+
export function readResumedAttachAcknowledgement(token: object) {
|
|
32
|
+
need(arguments.length === 1);
|
|
33
|
+
readInitialLineage(token);
|
|
34
|
+
const actual = returnedAcknowledgements.get(token);
|
|
35
|
+
if (!actual) return null;
|
|
36
|
+
ownerForInitialLineage(token).check();
|
|
37
|
+
return actual;
|
|
38
|
+
}
|
|
39
|
+
|
|
20
40
|
const actors = new WeakMap<object, ReturnType<typeof construct>>();
|
|
21
41
|
export function captureLiveAttachRecovery(token: object) {
|
|
22
42
|
need(arguments.length === 1);
|
|
@@ -103,6 +123,20 @@ function construct(token: object) {
|
|
|
103
123
|
snapshot.request,
|
|
104
124
|
);
|
|
105
125
|
owner.check();
|
|
126
|
+
returnedAcknowledgements.set(
|
|
127
|
+
token,
|
|
128
|
+
Object.freeze({
|
|
129
|
+
originalEntry: snapshot.entry,
|
|
130
|
+
retainedPredicate: snapshot.retainedPredicate,
|
|
131
|
+
freshPredicate: snapshot.freshPredicate,
|
|
132
|
+
output: admitted,
|
|
133
|
+
receipt: closed(admitted, [
|
|
134
|
+
"status",
|
|
135
|
+
"operationalAuthority",
|
|
136
|
+
"receipt",
|
|
137
|
+
]).receipt,
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
106
140
|
return admitted;
|
|
107
141
|
},
|
|
108
142
|
});
|
|
@@ -53,6 +53,26 @@ import {
|
|
|
53
53
|
} from "./output.js";
|
|
54
54
|
import { admitReplayMaterial, assertReplayMaterial } from "./material.js";
|
|
55
55
|
|
|
56
|
+
const returnedAcknowledgements = new WeakMap<
|
|
57
|
+
object,
|
|
58
|
+
Readonly<{
|
|
59
|
+
originalEntry: unknown;
|
|
60
|
+
retainedPredicate: SourceMethod;
|
|
61
|
+
freshPredicate: SourceMethod;
|
|
62
|
+
output: unknown;
|
|
63
|
+
receipt: unknown;
|
|
64
|
+
}>
|
|
65
|
+
>();
|
|
66
|
+
/** Actual replay completion identity, independent of stored C3 receipt DATA. */
|
|
67
|
+
export function readReplayAttachAcknowledgement(token: object) {
|
|
68
|
+
need(arguments.length === 1);
|
|
69
|
+
readInitialLineage(token);
|
|
70
|
+
const actual = returnedAcknowledgements.get(token);
|
|
71
|
+
if (!actual) return null;
|
|
72
|
+
ownerForInitialLineage(token).check();
|
|
73
|
+
return actual;
|
|
74
|
+
}
|
|
75
|
+
|
|
56
76
|
type Pair = ReturnType<typeof createPair>;
|
|
57
77
|
|
|
58
78
|
function sourceMethod(object: unknown, name: string): SourceMethod {
|
|
@@ -485,6 +505,25 @@ function recoveryKernel(token: object | null) {
|
|
|
485
505
|
);
|
|
486
506
|
OWNER.check();
|
|
487
507
|
control.takePostQuarantine();
|
|
508
|
+
if (token !== null) {
|
|
509
|
+
need(frame);
|
|
510
|
+
returnedAcknowledgements.set(
|
|
511
|
+
token,
|
|
512
|
+
Object.freeze({
|
|
513
|
+
originalEntry: op.originalEntry,
|
|
514
|
+
retainedPredicate,
|
|
515
|
+
freshPredicate: frame.snapshot.freshPredicate,
|
|
516
|
+
output: result,
|
|
517
|
+
receipt: closed(result, [
|
|
518
|
+
"kind",
|
|
519
|
+
"status",
|
|
520
|
+
"operationalAuthority",
|
|
521
|
+
"receipt",
|
|
522
|
+
"observation",
|
|
523
|
+
]).receipt,
|
|
524
|
+
}),
|
|
525
|
+
);
|
|
526
|
+
}
|
|
488
527
|
return result;
|
|
489
528
|
} catch (error) {
|
|
490
529
|
let live = false;
|