@fantastic.dev/better-stripe 0.99.0 → 0.101.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/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/payoutAdoptionTestHelpers.d.ts +18 -18
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +9 -9
- package/dist/client/connect/payoutLargeAdoptionTestHelpers.d.ts +50 -50
- package/dist/client/connect/payoutSyncTestHelpers.d.ts +25 -25
- 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 +22 -22
- 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/renewalOperations/attachValidation.d.ts +19 -0
- package/dist/component/renewalOperations/attachValidation.d.ts.map +1 -0
- package/dist/component/renewalOperations/attachValidation.js +167 -0
- package/dist/component/renewalOperations/attachValidation.js.map +1 -0
- package/dist/component/renewalOperations/configureAcknowledgement.d.ts +13 -0
- package/dist/component/renewalOperations/configureAcknowledgement.d.ts.map +1 -0
- package/dist/component/renewalOperations/configureAcknowledgement.js +108 -0
- package/dist/component/renewalOperations/configureAcknowledgement.js.map +1 -0
- package/dist/component/renewalOperations/configureParent.d.ts +10 -0
- package/dist/component/renewalOperations/configureParent.d.ts.map +1 -0
- package/dist/component/renewalOperations/configureParent.js +62 -0
- package/dist/component/renewalOperations/configureParent.js.map +1 -0
- package/dist/component/renewalOperations/configureValidation.d.ts +12 -0
- package/dist/component/renewalOperations/configureValidation.d.ts.map +1 -0
- package/dist/component/renewalOperations/configureValidation.js +64 -0
- package/dist/component/renewalOperations/configureValidation.js.map +1 -0
- package/dist/component/renewalOperations/helpers.d.ts +16 -21
- package/dist/component/renewalOperations/helpers.d.ts.map +1 -1
- package/dist/component/renewalOperations/helpers.js +13 -169
- package/dist/component/renewalOperations/helpers.js.map +1 -1
- package/dist/component/renewalOperations/mutations.d.ts +6 -6
- package/dist/component/renewalOperations/mutations.d.ts.map +1 -1
- package/dist/component/renewalOperations/mutations.js +14 -7
- package/dist/component/renewalOperations/mutations.js.map +1 -1
- package/dist/component/renewalOperations/operationContext.d.ts +12 -0
- package/dist/component/renewalOperations/operationContext.d.ts.map +1 -0
- package/dist/component/renewalOperations/operationContext.js +14 -0
- package/dist/component/renewalOperations/operationContext.js.map +1 -0
- package/dist/component/renewalOperations/queries.d.ts +4 -4
- package/dist/component/renewalOperations/queries.js +2 -1
- package/dist/component/renewalOperations/queries.js.map +1 -1
- package/dist/component/renewalOperations/schema.d.ts +59 -59
- package/dist/component/renewalOperations/schema.js +3 -3
- package/dist/component/renewalOperations/schema.js.map +1 -1
- package/dist/component/renewalOperations/stageAcknowledgement.d.ts +15 -0
- package/dist/component/renewalOperations/stageAcknowledgement.d.ts.map +1 -0
- package/dist/component/renewalOperations/stageAcknowledgement.js +20 -0
- package/dist/component/renewalOperations/stageAcknowledgement.js.map +1 -0
- package/dist/component/renewalOperations/validationTypes.d.ts +9 -0
- package/dist/component/renewalOperations/validationTypes.d.ts.map +1 -0
- package/dist/component/renewalOperations/validationTypes.js +2 -0
- package/dist/component/renewalOperations/validationTypes.js.map +1 -0
- package/dist/component/schema.d.ts +9 -9
- package/dist/component/usage/allowance.fixtures.d.ts +9 -9
- package/dist/component/usageCredits/accounting.fixtures.d.ts +9 -9
- package/dist/shared/renewalOperationJournal.d.ts +1 -1
- package/dist/shared/renewalOperationJournal.d.ts.map +1 -1
- package/dist/shared/renewalOperationJournal.js +41 -9
- package/dist/shared/renewalOperationJournal.js.map +1 -1
- package/docs/renewal-context-reads.md +59 -8
- 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
- package/src/component/renewalOperations/attachValidation.ts +203 -0
- package/src/component/renewalOperations/configureAcknowledgement.test.ts +30 -0
- package/src/component/renewalOperations/configureAcknowledgement.ts +182 -0
- package/src/component/renewalOperations/configureAcknowledgementControls.test.ts +96 -0
- package/src/component/renewalOperations/configureBasis.test.ts +77 -0
- package/src/component/renewalOperations/configureCreation.test.ts +75 -0
- package/src/component/renewalOperations/configureJournal.fixtures.ts +385 -0
- package/src/component/renewalOperations/configureParent.ts +71 -0
- package/src/component/renewalOperations/configurePolicy.test.ts +105 -0
- package/src/component/renewalOperations/configurePublication.test.ts +85 -0
- package/src/component/renewalOperations/configureReceiptBounds.test.ts +39 -0
- package/src/component/renewalOperations/configureSourceControls.test.ts +65 -0
- package/src/component/renewalOperations/configureValidation.ts +70 -0
- package/src/component/renewalOperations/helpers.ts +21 -204
- package/src/component/renewalOperations/mutations.ts +16 -7
- package/src/component/renewalOperations/operationContext.ts +21 -0
- package/src/component/renewalOperations/queries.ts +1 -1
- package/src/component/renewalOperations/schema.ts +3 -3
- package/src/component/renewalOperations/stageAcknowledgement.ts +45 -0
- package/src/component/renewalOperations/validationTypes.ts +9 -0
- package/src/shared/renewalOperationJournal.ts +49 -8
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { types } from "node:util";
|
|
2
|
+
import { readInitialLineage } from "./lineageAuthority.js";
|
|
3
|
+
import { ownerForInitialLineage } from "./ownerFactory.js";
|
|
4
|
+
import { readInitialAttachAcknowledgement } from "../operations/initialAttach.js";
|
|
5
|
+
import { readReplayAttachAcknowledgement } from "../recovery/recoveryActor.js";
|
|
6
|
+
import { readResumedAttachAcknowledgement } from "./recoveryEntry.js";
|
|
7
|
+
import { COMPILED_INITIAL_ENTRIES } from "../operations/sourceOperations.js";
|
|
8
|
+
import { sourceMethod } from "../operations/initialActorData.js";
|
|
9
|
+
|
|
10
|
+
const views = new WeakMap<
|
|
11
|
+
object,
|
|
12
|
+
Readonly<{
|
|
13
|
+
originalEntry: unknown;
|
|
14
|
+
retainedPredicate: unknown;
|
|
15
|
+
freshPredicate: unknown;
|
|
16
|
+
output: unknown;
|
|
17
|
+
receipt: unknown;
|
|
18
|
+
operationalAuthority: false;
|
|
19
|
+
}>
|
|
20
|
+
>();
|
|
21
|
+
function need(value: unknown): asserts value {
|
|
22
|
+
if (!value) throw Error("ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE");
|
|
23
|
+
}
|
|
24
|
+
/** Read actual completion identity only; no receipt registration or Owner revival. */
|
|
25
|
+
export function readAttachAcknowledgementForLineage(token: object) {
|
|
26
|
+
need(arguments.length === 1);
|
|
27
|
+
readInitialLineage(token);
|
|
28
|
+
need(
|
|
29
|
+
!types.isProxy(COMPILED_INITIAL_ENTRIES) &&
|
|
30
|
+
Array.isArray(COMPILED_INITIAL_ENTRIES) &&
|
|
31
|
+
COMPILED_INITIAL_ENTRIES.length > 0,
|
|
32
|
+
);
|
|
33
|
+
const candidates = [
|
|
34
|
+
readInitialAttachAcknowledgement(token),
|
|
35
|
+
readReplayAttachAcknowledgement(token),
|
|
36
|
+
readResumedAttachAcknowledgement(token),
|
|
37
|
+
].filter((value) => value !== null);
|
|
38
|
+
need(candidates.length === 1);
|
|
39
|
+
const owner = ownerForInitialLineage(token);
|
|
40
|
+
owner.check();
|
|
41
|
+
const actual = candidates[0];
|
|
42
|
+
need(COMPILED_INITIAL_ENTRIES.includes(actual.originalEntry));
|
|
43
|
+
need(
|
|
44
|
+
sourceMethod(actual.originalEntry, "coversRetained") ===
|
|
45
|
+
actual.retainedPredicate,
|
|
46
|
+
);
|
|
47
|
+
need(
|
|
48
|
+
sourceMethod(actual.originalEntry, "coversFresh") === actual.freshPredicate,
|
|
49
|
+
);
|
|
50
|
+
let view = views.get(token);
|
|
51
|
+
if (view) {
|
|
52
|
+
need(
|
|
53
|
+
view.output === actual.output &&
|
|
54
|
+
view.receipt === actual.receipt &&
|
|
55
|
+
view.originalEntry === actual.originalEntry &&
|
|
56
|
+
view.retainedPredicate === actual.retainedPredicate &&
|
|
57
|
+
view.freshPredicate === actual.freshPredicate,
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
view = Object.freeze({ ...actual, operationalAuthority: false });
|
|
61
|
+
views.set(token, view);
|
|
62
|
+
}
|
|
63
|
+
owner.check();
|
|
64
|
+
return view;
|
|
65
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mintInitialLineage, readInitialLineage } from "./lineageAuthority.js";
|
|
2
2
|
import { captureLiveAttachRecovery } from "./recoveryEntry.js";
|
|
3
|
+
import { readAttachAcknowledgementForLineage } from "./attachAcknowledgement.js";
|
|
3
4
|
import { ownerForInitialLineage, type InitialOwner } from "./ownerFactory.js";
|
|
4
5
|
import { ownedAwaitForInitialLineage } from "./ownedAwaitFactory.js";
|
|
5
6
|
import { stockDelegateForInitialLineage } from "./stockDelegateFactory.js";
|
|
@@ -24,6 +25,9 @@ export type InitialInvocationCore = Readonly<{
|
|
|
24
25
|
acquire(): Promise<RawAcquisitionResult>;
|
|
25
26
|
initialAttach(): ReturnType<typeof captureInitialAttachForLineage>;
|
|
26
27
|
recoverAttach(): ReturnType<typeof captureLiveAttachRecovery>;
|
|
28
|
+
attachAcknowledgement(): ReturnType<
|
|
29
|
+
typeof readAttachAcknowledgementForLineage
|
|
30
|
+
>;
|
|
27
31
|
operationalAuthority: false;
|
|
28
32
|
}>;
|
|
29
33
|
|
|
@@ -90,6 +94,10 @@ export async function captureInitialInvocationCore(
|
|
|
90
94
|
if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
|
|
91
95
|
return captureLiveAttachRecovery(token);
|
|
92
96
|
},
|
|
97
|
+
attachAcknowledgement() {
|
|
98
|
+
if (arguments.length !== 0) throw Error("INITIAL_OPERATION_UNBOUND");
|
|
99
|
+
return readAttachAcknowledgementForLineage(token);
|
|
100
|
+
},
|
|
93
101
|
operationalAuthority: false,
|
|
94
102
|
});
|
|
95
103
|
} catch (error) {
|
|
@@ -0,0 +1,320 @@
|
|
|
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
|
+
function acknowledgement(core: object) {
|
|
195
|
+
const read = Reflect.get(core, "attachAcknowledgement");
|
|
196
|
+
expect(typeof read).toBe("function");
|
|
197
|
+
return Reflect.apply(read, core, []) as Readonly<{
|
|
198
|
+
output: unknown;
|
|
199
|
+
receipt: unknown;
|
|
200
|
+
operationalAuthority: false;
|
|
201
|
+
}>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
it.each(["initial", "replay", "resume"])(
|
|
205
|
+
"retains the exact actual %s output and receipt identities without replacement inputs",
|
|
206
|
+
async (path) => {
|
|
207
|
+
const declared = declaration();
|
|
208
|
+
let appended = 0;
|
|
209
|
+
await initialOperations(
|
|
210
|
+
async ({ fresh, journal }) => {
|
|
211
|
+
let posts = 0;
|
|
212
|
+
const wire = wireFor([declared], async () => {
|
|
213
|
+
posts++;
|
|
214
|
+
if (path === "replay" && posts === 1)
|
|
215
|
+
throw Error("CONTROLLED_LOST_RESPONSE");
|
|
216
|
+
});
|
|
217
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
218
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
219
|
+
try {
|
|
220
|
+
let output: unknown;
|
|
221
|
+
if (path === "initial") output = await core.initialAttach().invoke();
|
|
222
|
+
else {
|
|
223
|
+
if (path === "replay")
|
|
224
|
+
await expect(core.initialAttach().invoke()).rejects.toThrow(
|
|
225
|
+
"INITIAL_PROVIDER_REJECTED",
|
|
226
|
+
);
|
|
227
|
+
else
|
|
228
|
+
expect(data(await core.initialAttach().invoke()).status).toBe(
|
|
229
|
+
"fulfilled_unverified",
|
|
230
|
+
);
|
|
231
|
+
output = await recover(core).invoke();
|
|
232
|
+
}
|
|
233
|
+
expect(data(output).status).toBe("attach_acknowledged");
|
|
234
|
+
const view = acknowledgement(core);
|
|
235
|
+
expect(view.output).toBe(output);
|
|
236
|
+
expect(view.receipt).toBe(data(output).receipt);
|
|
237
|
+
expect(view.operationalAuthority).toBe(false);
|
|
238
|
+
expect(acknowledgement(core)).toBe(view);
|
|
239
|
+
const copy = JSON.parse(JSON.stringify(output));
|
|
240
|
+
expect(copy).toEqual(output);
|
|
241
|
+
expect(copy.receipt).not.toBe(view.receipt);
|
|
242
|
+
const calls = wire.calls.length;
|
|
243
|
+
expect(() =>
|
|
244
|
+
Reflect.apply(core.attachAcknowledgement, undefined, [
|
|
245
|
+
copy.receipt,
|
|
246
|
+
]),
|
|
247
|
+
).toThrow("INITIAL_OPERATION_UNBOUND");
|
|
248
|
+
expect(wire.calls).toHaveLength(calls);
|
|
249
|
+
expect(posts).toBe(path === "replay" ? 2 : 1);
|
|
250
|
+
expect(controls.legacy).toBe(0);
|
|
251
|
+
} finally {
|
|
252
|
+
core.owner.retire();
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
1,
|
|
256
|
+
{
|
|
257
|
+
source: declared.source,
|
|
258
|
+
...windowFor(declared.source),
|
|
259
|
+
afterAppend: async () => {
|
|
260
|
+
appended++;
|
|
261
|
+
if (path === "resume" && appended === 2)
|
|
262
|
+
throw Error("CONTROLLED_APPEND_REPLY_REJECTION");
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
);
|
|
266
|
+
},
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
it("committed receipt DATA does not become returned ACK custody while retention reply is pending, and absence is not cached", async () => {
|
|
270
|
+
const declared = declaration();
|
|
271
|
+
let release!: () => void, entered!: () => void;
|
|
272
|
+
const pending = new Promise<void>((resolve) => {
|
|
273
|
+
release = resolve;
|
|
274
|
+
});
|
|
275
|
+
const committed = new Promise<void>((resolve) => {
|
|
276
|
+
entered = resolve;
|
|
277
|
+
});
|
|
278
|
+
await initialOperations(
|
|
279
|
+
async ({ fresh, journal }) => {
|
|
280
|
+
const wire = wireFor([declared]);
|
|
281
|
+
vi.stubGlobal("fetch", wire.fetch);
|
|
282
|
+
const core = await captureInitialInvocationCore(fresh.call, journal);
|
|
283
|
+
try {
|
|
284
|
+
expect(typeof Reflect.get(core, "attachAcknowledgement")).toBe(
|
|
285
|
+
"function",
|
|
286
|
+
);
|
|
287
|
+
expect(() => acknowledgement(core)).toThrow(
|
|
288
|
+
"ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE",
|
|
289
|
+
);
|
|
290
|
+
const initial = core.initialAttach().invoke();
|
|
291
|
+
await committed;
|
|
292
|
+
expect(await journal.readProviderAcknowledgement()).not.toBeNull();
|
|
293
|
+
expect(() => acknowledgement(core)).toThrow(
|
|
294
|
+
"ATTACH_ACKNOWLEDGEMENT_UNAVAILABLE",
|
|
295
|
+
);
|
|
296
|
+
release();
|
|
297
|
+
const output = await initial;
|
|
298
|
+
const view = acknowledgement(core);
|
|
299
|
+
expect(view.output).toBe(output);
|
|
300
|
+
expect(view.receipt).toBe(data(output).receipt);
|
|
301
|
+
expect(wire.calls.filter((row) => row.method === "POST")).toHaveLength(
|
|
302
|
+
1,
|
|
303
|
+
);
|
|
304
|
+
expect(controls.legacy).toBe(0);
|
|
305
|
+
} finally {
|
|
306
|
+
release();
|
|
307
|
+
core.owner.retire();
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
1,
|
|
311
|
+
{
|
|
312
|
+
source: declared.source,
|
|
313
|
+
...windowFor(declared.source),
|
|
314
|
+
afterRetain: async () => {
|
|
315
|
+
entered();
|
|
316
|
+
await pending;
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
);
|
|
320
|
+
});
|