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