@fantastic.dev/better-stripe 0.90.0 → 0.91.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 +41 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js +187 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts +2 -23
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js +1 -112
- package/dist/client/billing/renewalAttach/internal/acquisition/rawAcquisition.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts +8 -3
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.d.ts.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js +1 -0
- package/dist/client/billing/renewalAttach/internal/acquisition/rawWireSource.js.map +1 -1
- package/dist/client/billing/renewalAttach/internal/acquisition/test-fixtures/sourcePort.d.mts +1 -1
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.js +454 -0
- package/dist/client/billing/renewalAttach/internal/configure/actor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts +12 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.js +99 -0
- package/dist/client/billing/renewalAttach/internal/configure/capture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.js +274 -0
- package/dist/client/billing/renewalAttach/internal/configure/output.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts +3 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.js +9 -0
- package/dist/client/billing/renewalAttach/internal/configure/replay.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.d.ts +39 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.js +245 -0
- package/dist/client/billing/renewalAttach/internal/configure/request.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts +88 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.js +289 -0
- package/dist/client/billing/renewalAttach/internal/configure/transport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.js +362 -0
- package/dist/client/billing/renewalAttach/internal/observation/actor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts +9 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.js +215 -0
- package/dist/client/billing/renewalAttach/internal/observation/capture.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.js +190 -0
- package/dist/client/billing/renewalAttach/internal/observation/profile.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.js +317 -0
- package/dist/client/billing/renewalAttach/internal/observation/record.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts +79 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.js +27 -0
- package/dist/client/billing/renewalAttach/internal/observation/types.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts +18 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js +229 -0
- package/dist/client/billing/renewalAttach/internal/operations/configureReadTransport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts +163 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js +443 -0
- package/dist/client/billing/renewalAttach/internal/operations/fixedTransport.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js +467 -0
- package/dist/client/billing/renewalAttach/internal/operations/initialAttach.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts +6 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js +59 -0
- package/dist/client/billing/renewalAttach/internal/operations/ownedAwait.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts +10 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js +48 -0
- package/dist/client/billing/renewalAttach/internal/operations/providerFailure.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts +20 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js +44 -0
- package/dist/client/billing/renewalAttach/internal/operations/sourceOperations.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.d.ts +42 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.js +158 -0
- package/dist/client/billing/renewalAttach/internal/operations/types.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js +214 -0
- package/dist/client/billing/renewalAttach/internal/preflight/configurePreflight.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts +33 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.js +208 -0
- package/dist/client/billing/renewalAttach/internal/preflight/grammar.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts +4 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.js +25 -0
- package/dist/client/billing/renewalAttach/internal/preflight/output.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts +16 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.js +93 -0
- package/dist/client/billing/renewalAttach/internal/preflight/record.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts +7 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js +153 -0
- package/dist/client/billing/renewalAttach/internal/preflight/relations.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts +22 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.js +221 -0
- package/dist/client/billing/renewalAttach/internal/recovery/material.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts +8 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.js +101 -0
- package/dist/client/billing/renewalAttach/internal/recovery/output.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts +12 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.js +186 -0
- package/dist/client/billing/renewalAttach/internal/recovery/record.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts +5 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js +498 -0
- package/dist/client/billing/renewalAttach/internal/recovery/recoveryActor.js.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts +21 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.d.ts.map +1 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js +119 -0
- package/dist/client/billing/renewalAttach/internal/recovery/relation.js.map +1 -0
- package/dist/client/connect/payoutAdoptionTestHelpers.d.ts +32 -32
- package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
- package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
- package/dist/component/balanceFunding/mutations.d.ts +16 -16
- package/dist/component/balanceFunding/preparationHandlers.d.ts +8 -8
- 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 +26 -8
- package/docs/renewal-material-observation.md +37 -0
- package/docs/renewal-phase-assembly.md +68 -0
- package/docs/renewal-raw-acquisition.md +19 -5
- package/package.json +1 -1
- package/src/client/billing/renewalAttach/internal/acquisition/ownedAcquisition.ts +304 -0
- package/src/client/billing/renewalAttach/internal/acquisition/rawAcquisition.ts +2 -160
- package/src/client/billing/renewalAttach/internal/acquisition/rawWireSource.ts +15 -3
- package/src/client/billing/renewalAttach/internal/configure/actor.ts +575 -0
- package/src/client/billing/renewalAttach/internal/configure/capture.ts +117 -0
- package/src/client/billing/renewalAttach/internal/configure/dispatch.integration.test.ts +32 -0
- package/src/client/billing/renewalAttach/internal/configure/limits.test.ts +510 -0
- package/src/client/billing/renewalAttach/internal/configure/order.integration.test.ts +207 -0
- package/src/client/billing/renewalAttach/internal/configure/output.ts +372 -0
- package/src/client/billing/renewalAttach/internal/configure/ownership.integration.test.ts +148 -0
- package/src/client/billing/renewalAttach/internal/configure/replay.integration.test.ts +173 -0
- package/src/client/billing/renewalAttach/internal/configure/replay.ts +13 -0
- package/src/client/billing/renewalAttach/internal/configure/request.ts +312 -0
- package/src/client/billing/renewalAttach/internal/configure/transport.integration.test.ts +507 -0
- package/src/client/billing/renewalAttach/internal/configure/transport.ts +348 -0
- package/src/client/billing/renewalAttach/internal/observation/actor.ts +444 -0
- package/src/client/billing/renewalAttach/internal/observation/capture.ts +250 -0
- package/src/client/billing/renewalAttach/internal/observation/observation.integration.test.ts +220 -0
- package/src/client/billing/renewalAttach/internal/observation/observationRetirement.integration.test.ts +60 -0
- package/src/client/billing/renewalAttach/internal/observation/profile.ts +264 -0
- package/src/client/billing/renewalAttach/internal/observation/record.ts +408 -0
- package/src/client/billing/renewalAttach/internal/observation/types.ts +102 -0
- package/src/client/billing/renewalAttach/internal/operations/configureReadTransport.ts +285 -0
- package/src/client/billing/renewalAttach/internal/operations/defaultBindings.test.ts +69 -0
- package/src/client/billing/renewalAttach/internal/operations/fixedTransport.ts +574 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.integration.test.ts +34 -0
- package/src/client/billing/renewalAttach/internal/operations/initialAttach.ts +535 -0
- package/src/client/billing/renewalAttach/internal/operations/ownedAwait.ts +63 -0
- package/src/client/billing/renewalAttach/internal/operations/providerFailure.integration.test.ts +61 -0
- package/src/client/billing/renewalAttach/internal/operations/providerFailure.ts +66 -0
- package/src/client/billing/renewalAttach/internal/operations/sourceOperations.ts +50 -0
- package/src/client/billing/renewalAttach/internal/operations/transport.integration.test.ts +116 -0
- package/src/client/billing/renewalAttach/internal/operations/types.ts +223 -0
- package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.integration.test.ts +285 -0
- package/src/client/billing/renewalAttach/internal/preflight/configurePreflight.ts +258 -0
- package/src/client/billing/renewalAttach/internal/preflight/configureReads.integration.test.ts +139 -0
- package/src/client/billing/renewalAttach/internal/preflight/grammar.ts +257 -0
- package/src/client/billing/renewalAttach/internal/preflight/output.ts +42 -0
- package/src/client/billing/renewalAttach/internal/preflight/owner.integration.test.ts +82 -0
- package/src/client/billing/renewalAttach/internal/preflight/preflight.integration.test.ts +354 -0
- package/src/client/billing/renewalAttach/internal/preflight/record.ts +127 -0
- package/src/client/billing/renewalAttach/internal/preflight/relations.ts +209 -0
- package/src/client/billing/renewalAttach/internal/recovery/material.ts +311 -0
- package/src/client/billing/renewalAttach/internal/recovery/output.ts +136 -0
- package/src/client/billing/renewalAttach/internal/recovery/record.ts +230 -0
- package/src/client/billing/renewalAttach/internal/recovery/recovery.integration.test.ts +463 -0
- package/src/client/billing/renewalAttach/internal/recovery/recoveryActor.ts +599 -0
- package/src/client/billing/renewalAttach/internal/recovery/relation.ts +175 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachEntries.ts +217 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachObservations.ts +226 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenario.ts +556 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioAssertions.ts +180 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/attachScenarioBarriers.ts +144 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightAssertions.ts +122 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightBarriers.ts +330 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightControls.ts +139 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configurePreflightOperation.ts +513 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadNativeBaseline.ts +344 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadOperation.ts +278 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureReadPort.ts +17 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteAssertions.ts +533 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteBarriers.ts +125 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteDeclarations.ts +314 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteHistory.ts +463 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteObservations.ts +515 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/configureWriteOperation.ts +600 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationAssertions.ts +211 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationDeclarations.ts +192 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationHTTP.ts +197 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationObservations.ts +269 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationOperation.ts +262 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/observationProbe.ts +319 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/ownedOperations.ts +94 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/sourceOperationPort.ts +16 -0
- package/src/client/billing/renewalAttach/internal/test-fixtures/stockHttp.ts +21 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { webcrypto } from "node:crypto";
|
|
3
|
+
import { vi } from "vitest";
|
|
4
|
+
import { data, type PreflightCase } from "./configurePreflightControls.js";
|
|
5
|
+
|
|
6
|
+
export function deferred() {
|
|
7
|
+
let resolve!: () => void;
|
|
8
|
+
const promise = new Promise<void>((done) => {
|
|
9
|
+
resolve = done;
|
|
10
|
+
});
|
|
11
|
+
return { promise, resolve };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function preflightBarriers(name: PreflightCase) {
|
|
15
|
+
const entered = deferred(),
|
|
16
|
+
released = deferred();
|
|
17
|
+
const pending: Promise<unknown>[] = [];
|
|
18
|
+
let held = false;
|
|
19
|
+
return {
|
|
20
|
+
pending,
|
|
21
|
+
entered: entered.promise,
|
|
22
|
+
release: released.resolve,
|
|
23
|
+
async hold(kind: string) {
|
|
24
|
+
if (held || name !== "hold-" + kind) return;
|
|
25
|
+
held = true;
|
|
26
|
+
entered.resolve();
|
|
27
|
+
await released.promise;
|
|
28
|
+
},
|
|
29
|
+
async enterOrSettled(operation: Promise<unknown>) {
|
|
30
|
+
const observed = operation.then(
|
|
31
|
+
() => false,
|
|
32
|
+
() => false,
|
|
33
|
+
);
|
|
34
|
+
assert.equal(
|
|
35
|
+
await Promise.race([entered.promise.then(() => true), observed]),
|
|
36
|
+
true,
|
|
37
|
+
"TEST_PREREQUISITE_SETTLED_BEFORE_BARRIER",
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
async cleanup() {
|
|
41
|
+
released.resolve();
|
|
42
|
+
await Promise.allSettled(pending);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function installPreflightDigestBarrier(
|
|
48
|
+
barriers: ReturnType<typeof preflightBarriers>,
|
|
49
|
+
phase: () => string,
|
|
50
|
+
) {
|
|
51
|
+
vi.stubGlobal("crypto", {
|
|
52
|
+
subtle: {
|
|
53
|
+
digest(
|
|
54
|
+
algorithm: Parameters<typeof webcrypto.subtle.digest>[0],
|
|
55
|
+
input: Parameters<typeof webcrypto.subtle.digest>[1],
|
|
56
|
+
) {
|
|
57
|
+
const actual = webcrypto.subtle.digest(algorithm, input);
|
|
58
|
+
const observed = actual.then(async (result) => {
|
|
59
|
+
if (ArrayBuffer.isView(input)) {
|
|
60
|
+
const tuple: unknown = JSON.parse(
|
|
61
|
+
new TextDecoder().decode(
|
|
62
|
+
new Uint8Array(
|
|
63
|
+
input.buffer,
|
|
64
|
+
input.byteOffset,
|
|
65
|
+
input.byteLength,
|
|
66
|
+
),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
if (Array.isArray(tuple) && tuple[2] === "renewal-configure")
|
|
70
|
+
await barriers.hold(phase());
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
});
|
|
74
|
+
barriers.pending.push(observed.catch(() => {}));
|
|
75
|
+
return observed;
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function cleanPreflightMocks() {
|
|
82
|
+
for (const path of [
|
|
83
|
+
"../sourceBindings.js",
|
|
84
|
+
"../operations/sourceOperations.js",
|
|
85
|
+
"../../../renewalV2/index.js",
|
|
86
|
+
"../preflight/output.js",
|
|
87
|
+
"../acquisition/readLifetime.js",
|
|
88
|
+
"../acquisition/ownedAcquisition.js",
|
|
89
|
+
"../operations/configureReadTransport.js",
|
|
90
|
+
"../originalOwner.js",
|
|
91
|
+
"../preflight/record.js",
|
|
92
|
+
])
|
|
93
|
+
vi.doUnmock(path);
|
|
94
|
+
vi.unstubAllGlobals();
|
|
95
|
+
vi.restoreAllMocks();
|
|
96
|
+
vi.resetModules();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function preflightObservationState() {
|
|
100
|
+
return {
|
|
101
|
+
phase: "setup",
|
|
102
|
+
c6: 0,
|
|
103
|
+
c3: 0,
|
|
104
|
+
releaseEntries: 0,
|
|
105
|
+
coverage: 0,
|
|
106
|
+
pairLoads: 0,
|
|
107
|
+
operationLoads: 0,
|
|
108
|
+
samples: 0,
|
|
109
|
+
tupleTraps: 0,
|
|
110
|
+
readonlyCalls: 0,
|
|
111
|
+
methodRetargets: 0,
|
|
112
|
+
initialFinished: false,
|
|
113
|
+
pair: null as unknown,
|
|
114
|
+
pairCreations: 0,
|
|
115
|
+
readerBindings: 0,
|
|
116
|
+
children: 0,
|
|
117
|
+
finishes: 0,
|
|
118
|
+
finishAt: null as number | null,
|
|
119
|
+
scheduleReplies: 0,
|
|
120
|
+
c6Results: [] as unknown[],
|
|
121
|
+
records: [] as Record<string, unknown>[],
|
|
122
|
+
calls: [] as { method: string; path: string }[],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type PreflightObservationState = ReturnType<
|
|
127
|
+
typeof preflightObservationState
|
|
128
|
+
>;
|
|
129
|
+
|
|
130
|
+
export async function installPreflightObservers(
|
|
131
|
+
state: PreflightObservationState,
|
|
132
|
+
OWNER: typeof import("../originalOwner.js").OWNER,
|
|
133
|
+
name: PreflightCase,
|
|
134
|
+
gates: ReturnType<typeof preflightBarriers>,
|
|
135
|
+
advanceLater: () => void,
|
|
136
|
+
retargetReadMethod: () => void,
|
|
137
|
+
) {
|
|
138
|
+
const actual = await vi.importActual<
|
|
139
|
+
typeof import("../../../renewalV2/index.js")
|
|
140
|
+
>("../../../renewalV2/index.js");
|
|
141
|
+
vi.doMock("../../../renewalV2/index.js", () => ({
|
|
142
|
+
...actual,
|
|
143
|
+
projectRenewalConfigurationV2(
|
|
144
|
+
...args: Parameters<typeof actual.projectRenewalConfigurationV2>
|
|
145
|
+
) {
|
|
146
|
+
if (state.initialFinished) {
|
|
147
|
+
state.phase = state.c6++ === 0 ? "original" : "fresh";
|
|
148
|
+
if (state.phase === "fresh" && name === "later-sample") advanceLater();
|
|
149
|
+
}
|
|
150
|
+
const promise = actual.projectRenewalConfigurationV2(...args);
|
|
151
|
+
gates.pending.push(
|
|
152
|
+
promise.then(
|
|
153
|
+
(value) => {
|
|
154
|
+
state.c6Results.push(value);
|
|
155
|
+
if (state.phase === "original" && name === "method-retarget")
|
|
156
|
+
retargetReadMethod();
|
|
157
|
+
},
|
|
158
|
+
() => {},
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
return promise;
|
|
162
|
+
},
|
|
163
|
+
constructRenewalScheduleAttachmentReceiptV2(
|
|
164
|
+
...args: Parameters<
|
|
165
|
+
typeof actual.constructRenewalScheduleAttachmentReceiptV2
|
|
166
|
+
>
|
|
167
|
+
) {
|
|
168
|
+
if (state.initialFinished) state.c3++;
|
|
169
|
+
return actual.constructRenewalScheduleAttachmentReceiptV2(...args);
|
|
170
|
+
},
|
|
171
|
+
}));
|
|
172
|
+
vi.doMock("../preflight/output.js", async () => {
|
|
173
|
+
const real = await vi.importActual<typeof import("../preflight/output.js")>(
|
|
174
|
+
"../preflight/output.js",
|
|
175
|
+
);
|
|
176
|
+
return {
|
|
177
|
+
...real,
|
|
178
|
+
releasePreflight(...args: Parameters<typeof real.releasePreflight>) {
|
|
179
|
+
state.releaseEntries++;
|
|
180
|
+
return real.releasePreflight(...args);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
vi.doMock("../operations/configureReadTransport.js", async () => {
|
|
185
|
+
const real = await vi.importActual<
|
|
186
|
+
typeof import("../operations/configureReadTransport.js")
|
|
187
|
+
>("../operations/configureReadTransport.js");
|
|
188
|
+
return {
|
|
189
|
+
...real,
|
|
190
|
+
createConfigureOwnedReadTransport(
|
|
191
|
+
...args: Parameters<typeof real.createConfigureOwnedReadTransport>
|
|
192
|
+
) {
|
|
193
|
+
const pair = real.createConfigureOwnedReadTransport(...args);
|
|
194
|
+
state.pair = pair;
|
|
195
|
+
state.pairCreations++;
|
|
196
|
+
return pair;
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
vi.doMock("../acquisition/ownedAcquisition.js", async () => {
|
|
201
|
+
const real = await vi.importActual<
|
|
202
|
+
typeof import("../acquisition/ownedAcquisition.js")
|
|
203
|
+
>("../acquisition/ownedAcquisition.js");
|
|
204
|
+
return {
|
|
205
|
+
...real,
|
|
206
|
+
bindConfigureReadAcquisitionFromSource(
|
|
207
|
+
...args: Parameters<typeof real.bindConfigureReadAcquisitionFromSource>
|
|
208
|
+
) {
|
|
209
|
+
state.readerBindings++;
|
|
210
|
+
assert.equal(args[0], OWNER);
|
|
211
|
+
assert.equal(args[1], data(data(state.pair).transport).readTransport);
|
|
212
|
+
return real.bindConfigureReadAcquisitionFromSource(...args);
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
vi.doMock("../acquisition/readLifetime.js", async () => {
|
|
217
|
+
const real = await vi.importActual<
|
|
218
|
+
typeof import("../acquisition/readLifetime.js")
|
|
219
|
+
>("../acquisition/readLifetime.js");
|
|
220
|
+
return {
|
|
221
|
+
...real,
|
|
222
|
+
createReadLifetime(...args: Parameters<typeof real.createReadLifetime>) {
|
|
223
|
+
const child = real.createReadLifetime(...args);
|
|
224
|
+
if (!state.initialFinished) return child;
|
|
225
|
+
assert.equal(args[0], OWNER);
|
|
226
|
+
state.children++;
|
|
227
|
+
return Object.freeze({
|
|
228
|
+
begin: (...xs: Parameters<typeof child.begin>) =>
|
|
229
|
+
Reflect.apply(child.begin, child, xs) as ReturnType<
|
|
230
|
+
typeof child.begin
|
|
231
|
+
>,
|
|
232
|
+
check: (...xs: Parameters<typeof child.check>) =>
|
|
233
|
+
Reflect.apply(child.check, child, xs) as ReturnType<
|
|
234
|
+
typeof child.check
|
|
235
|
+
>,
|
|
236
|
+
fail: (...xs: Parameters<typeof child.fail>) =>
|
|
237
|
+
Reflect.apply(child.fail, child, xs) as ReturnType<
|
|
238
|
+
typeof child.fail
|
|
239
|
+
>,
|
|
240
|
+
finish(...xs: Parameters<typeof child.finish>) {
|
|
241
|
+
const value = Reflect.apply(child.finish, child, xs) as ReturnType<
|
|
242
|
+
typeof child.finish
|
|
243
|
+
>;
|
|
244
|
+
assert.equal(state.scheduleReplies, 1);
|
|
245
|
+
state.finishes++;
|
|
246
|
+
state.finishAt = value.wallMs;
|
|
247
|
+
return value;
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
return actual;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** EMPTY-only counter aliases; this fake Owner supplies no canonical/custody proof. */
|
|
257
|
+
export function installEmptyPreflightSpies() {
|
|
258
|
+
const counts = {
|
|
259
|
+
Source: 0,
|
|
260
|
+
Owner: 0,
|
|
261
|
+
check: 0,
|
|
262
|
+
sample: 0,
|
|
263
|
+
client: 0,
|
|
264
|
+
capture: 0,
|
|
265
|
+
api: 0,
|
|
266
|
+
read: 0,
|
|
267
|
+
};
|
|
268
|
+
const effect = (key: keyof typeof counts): never => {
|
|
269
|
+
counts[key]++;
|
|
270
|
+
throw Error("EMPTY_EFFECT_" + key);
|
|
271
|
+
};
|
|
272
|
+
const owner = Object.freeze({
|
|
273
|
+
check: () => effect("check"),
|
|
274
|
+
sample: () => effect("sample"),
|
|
275
|
+
});
|
|
276
|
+
const counterOwner = new Proxy(owner, {
|
|
277
|
+
get(target, key, receiver) {
|
|
278
|
+
counts.Owner++;
|
|
279
|
+
return Reflect.get(target, key, receiver);
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
vi.doMock("../originalOwner.js", () => ({ OWNER: counterOwner }));
|
|
283
|
+
vi.doMock("../sourceBindings.js", () => ({
|
|
284
|
+
loadOwnedOriginalSource: () => effect("Source"),
|
|
285
|
+
loadFixedStockClient: () => effect("client"),
|
|
286
|
+
}));
|
|
287
|
+
vi.doMock("../operations/sourceOperations.js", async () => {
|
|
288
|
+
const real = await vi.importActual<
|
|
289
|
+
typeof import("../operations/sourceOperations.js")
|
|
290
|
+
>("../operations/sourceOperations.js");
|
|
291
|
+
assert.deepEqual(real.COMPILED_PREFLIGHT_ENTRIES, []);
|
|
292
|
+
return {
|
|
293
|
+
...real,
|
|
294
|
+
loadOwnedConfigureOperation: () => effect("Source"),
|
|
295
|
+
loadConfigureOwnedReadTransportSource: () => effect("Source"),
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
vi.doMock("../../../renewalV2/index.js", async () => {
|
|
299
|
+
const real = await vi.importActual<
|
|
300
|
+
typeof import("../../../renewalV2/index.js")
|
|
301
|
+
>("../../../renewalV2/index.js");
|
|
302
|
+
return {
|
|
303
|
+
...real,
|
|
304
|
+
projectRenewalConfigurationV2: () => effect("api"),
|
|
305
|
+
constructRenewalScheduleAttachmentReceiptV2: () => effect("api"),
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
vi.doMock("../preflight/record.js", async () => {
|
|
309
|
+
const real = await vi.importActual<typeof import("../preflight/record.js")>(
|
|
310
|
+
"../preflight/record.js",
|
|
311
|
+
);
|
|
312
|
+
return { ...real, capturePreflightRecord: () => effect("capture") };
|
|
313
|
+
});
|
|
314
|
+
vi.doMock("../operations/configureReadTransport.js", async () => {
|
|
315
|
+
const real = await vi.importActual<
|
|
316
|
+
typeof import("../operations/configureReadTransport.js")
|
|
317
|
+
>("../operations/configureReadTransport.js");
|
|
318
|
+
return { ...real, createConfigureOwnedReadTransport: () => effect("read") };
|
|
319
|
+
});
|
|
320
|
+
vi.doMock("../acquisition/ownedAcquisition.js", async () => {
|
|
321
|
+
const real = await vi.importActual<
|
|
322
|
+
typeof import("../acquisition/ownedAcquisition.js")
|
|
323
|
+
>("../acquisition/ownedAcquisition.js");
|
|
324
|
+
return {
|
|
325
|
+
...real,
|
|
326
|
+
bindConfigureReadAcquisitionFromSource: () => effect("read"),
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
return counts;
|
|
330
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { makeConfigureReadNativeBaseline } from "./configureReadNativeBaseline.js";
|
|
2
|
+
|
|
3
|
+
export type PreflightCase =
|
|
4
|
+
| "positive"
|
|
5
|
+
| "foreign-owner"
|
|
6
|
+
| "foreign-origin"
|
|
7
|
+
| "foreign-entry"
|
|
8
|
+
| "foreign-preflight-entry"
|
|
9
|
+
| "foreign-delegate"
|
|
10
|
+
| "method-retarget"
|
|
11
|
+
| "foreign-ack"
|
|
12
|
+
| "foreign-pair"
|
|
13
|
+
| "retired-capture"
|
|
14
|
+
| "retired-proxy"
|
|
15
|
+
| "original-failure"
|
|
16
|
+
| "record-token"
|
|
17
|
+
| "subscription-drift"
|
|
18
|
+
| "price-drift"
|
|
19
|
+
| "customer-drift"
|
|
20
|
+
| "coupon-drift"
|
|
21
|
+
| "reference-drift"
|
|
22
|
+
| "schedule-opaque"
|
|
23
|
+
| "schedule-default"
|
|
24
|
+
| "schedule-phase"
|
|
25
|
+
| "hold-schedule"
|
|
26
|
+
| "hold-original"
|
|
27
|
+
| "hold-fresh"
|
|
28
|
+
| "later-sample"
|
|
29
|
+
| "output-overflow";
|
|
30
|
+
|
|
31
|
+
export function data(value: unknown): Record<string, unknown> {
|
|
32
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
33
|
+
throw Error("TEST_DATA_PREREQUISITE");
|
|
34
|
+
return value as Record<string, unknown>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function deepFreeze<T>(value: T): T {
|
|
38
|
+
if (value && typeof value === "object") {
|
|
39
|
+
for (const descriptor of Object.values(
|
|
40
|
+
Object.getOwnPropertyDescriptors(value),
|
|
41
|
+
))
|
|
42
|
+
if ("value" in descriptor) deepFreeze(descriptor.value);
|
|
43
|
+
Object.freeze(value);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Every raw counterexample and sample cue is declared before any constructor. */
|
|
49
|
+
export function declarePreflightCase(name: PreflightCase) {
|
|
50
|
+
const baseline = makeConfigureReadNativeBaseline();
|
|
51
|
+
const original = structuredClone(baseline.original);
|
|
52
|
+
const schedule = structuredClone(baseline.schedule);
|
|
53
|
+
if (name === "output-overflow")
|
|
54
|
+
Object.assign(schedule.metadata, { opaque: "x".repeat(135000) });
|
|
55
|
+
const baselineBundle = {
|
|
56
|
+
...structuredClone(original.originalBundle),
|
|
57
|
+
wireSubscription: {
|
|
58
|
+
...structuredClone(original.originalBundle.wireSubscription),
|
|
59
|
+
schedule: schedule.id,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
const currentBundle = structuredClone(baselineBundle);
|
|
63
|
+
const currentSchedule = structuredClone(schedule);
|
|
64
|
+
if (name === "subscription-drift")
|
|
65
|
+
Object.assign(currentBundle.wireSubscription.metadata, { drift: "Sub" });
|
|
66
|
+
if (name === "price-drift")
|
|
67
|
+
Object.assign(currentBundle.wireTargetPrice.metadata, { drift: "Price" });
|
|
68
|
+
if (name === "customer-drift")
|
|
69
|
+
Object.assign(currentBundle.wireBillingCustomer.metadata, {
|
|
70
|
+
drift: "Customer",
|
|
71
|
+
});
|
|
72
|
+
if (name === "coupon-drift")
|
|
73
|
+
currentBundle.couponReads[0]!.wireCoupon.times_redeemed++;
|
|
74
|
+
if (name === "reference-drift") {
|
|
75
|
+
const source = currentBundle.wireSubscription.discounts[0]!.source;
|
|
76
|
+
Object.defineProperty(source, "coupon", {
|
|
77
|
+
value: source.coupon.id,
|
|
78
|
+
enumerable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (name === "schedule-opaque")
|
|
84
|
+
Object.assign(currentSchedule.metadata, { drift: "Schedule" });
|
|
85
|
+
if (name === "schedule-default")
|
|
86
|
+
Object.assign(currentSchedule.default_settings, {
|
|
87
|
+
description: "different",
|
|
88
|
+
});
|
|
89
|
+
if (name === "schedule-phase")
|
|
90
|
+
currentSchedule.phases[0]!.metadata = { drift: "phase" };
|
|
91
|
+
return deepFreeze({
|
|
92
|
+
name,
|
|
93
|
+
original,
|
|
94
|
+
schedule,
|
|
95
|
+
baselineBundle,
|
|
96
|
+
currentBundle,
|
|
97
|
+
currentSchedule,
|
|
98
|
+
apiVersion: baseline.apiVersion,
|
|
99
|
+
configureKey: baseline.configureKey,
|
|
100
|
+
configureAt: baseline.configurationTime,
|
|
101
|
+
originalAPI:
|
|
102
|
+
name === "original-failure"
|
|
103
|
+
? "unsupported-preflight-api"
|
|
104
|
+
: baseline.apiVersion,
|
|
105
|
+
badRecordBinding: "renewal:v2:sha256:" + "a".repeat(64),
|
|
106
|
+
firstAt: baseline.clockPlan.attachSeconds * 1000 + 1,
|
|
107
|
+
baseAt: baseline.clockPlan.observationSeconds * 1000 + 1001,
|
|
108
|
+
scheduleAt: baseline.clockPlan.observationSeconds * 1000 + 2001,
|
|
109
|
+
laterAt: baseline.clockPlan.observationSeconds * 1000 + 3001,
|
|
110
|
+
workSeconds: baseline.clockPlan.workSeconds,
|
|
111
|
+
endSeconds: baseline.clockPlan.endSeconds,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export const preflightRecordTokenPaths = [
|
|
116
|
+
["request", "logicalBinding"],
|
|
117
|
+
["request", "attachReceiptBinding"],
|
|
118
|
+
["request", "baselineBinding"],
|
|
119
|
+
["request", "defaultSettingsBinding"],
|
|
120
|
+
["request", "requestIdentity", "binding"],
|
|
121
|
+
["attachReceipt", "logicalBinding"],
|
|
122
|
+
["attachReceipt", "request", "logicalBinding"],
|
|
123
|
+
["attachReceipt", "request", "requestIdentity", "binding"],
|
|
124
|
+
["attachReceipt", "binding"],
|
|
125
|
+
] as const;
|
|
126
|
+
|
|
127
|
+
/** Fixed TEST mutation recipe, never a production path/family selector. */
|
|
128
|
+
export function replaceRecordToken(record: unknown, index: number) {
|
|
129
|
+
const path = preflightRecordTokenPaths[index];
|
|
130
|
+
if (!path) throw Error("TEST_TOKEN_INDEX");
|
|
131
|
+
const copy = structuredClone(record);
|
|
132
|
+
let node = data(copy);
|
|
133
|
+
for (const key of path.slice(0, -1)) node = data(node[key]);
|
|
134
|
+
const key = path[path.length - 1]!;
|
|
135
|
+
const old = node[key];
|
|
136
|
+
if (typeof old !== "string") throw Error("TEST_TOKEN_PREREQUISITE");
|
|
137
|
+
node[key] = old.slice(0, old.length - 64) + "b".repeat(64);
|
|
138
|
+
return copy;
|
|
139
|
+
}
|