@fantastic.dev/better-stripe 0.95.0 → 0.96.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -1
  3. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.d.ts.map +1 -1
  4. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js +2 -5
  5. package/dist/client/billing/renewalAttach/internal/producer/lineageAuthority.js.map +1 -1
  6. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.d.ts.map +1 -1
  7. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js +15 -4
  8. package/dist/client/billing/renewalAttach/internal/producer/ownerFactory.js.map +1 -1
  9. package/dist/client/billing/renewalObservation/evidence-invoice-lines.d.ts +27 -0
  10. package/dist/client/billing/renewalObservation/evidence-invoice-lines.d.ts.map +1 -0
  11. package/dist/client/billing/renewalObservation/evidence-invoice-lines.js +164 -0
  12. package/dist/client/billing/renewalObservation/evidence-invoice-lines.js.map +1 -0
  13. package/dist/client/billing/renewalObservation/evidence-invoice.d.ts +4 -0
  14. package/dist/client/billing/renewalObservation/evidence-invoice.d.ts.map +1 -0
  15. package/dist/client/billing/renewalObservation/evidence-invoice.js +190 -0
  16. package/dist/client/billing/renewalObservation/evidence-invoice.js.map +1 -0
  17. package/dist/client/billing/renewalObservation/evidence-material.d.ts +26 -0
  18. package/dist/client/billing/renewalObservation/evidence-material.d.ts.map +1 -0
  19. package/dist/client/billing/renewalObservation/evidence-material.js +253 -0
  20. package/dist/client/billing/renewalObservation/evidence-material.js.map +1 -0
  21. package/dist/client/billing/renewalObservation/evidence-v1-types.d.ts +156 -0
  22. package/dist/client/billing/renewalObservation/evidence-v1-types.d.ts.map +1 -0
  23. package/dist/client/billing/renewalObservation/evidence-v1-types.js +2 -0
  24. package/dist/client/billing/renewalObservation/evidence-v1-types.js.map +1 -0
  25. package/dist/client/billing/renewalObservation/evidence-v1.d.ts +4 -0
  26. package/dist/client/billing/renewalObservation/evidence-v1.d.ts.map +1 -0
  27. package/dist/client/billing/renewalObservation/evidence-v1.js +263 -0
  28. package/dist/client/billing/renewalObservation/evidence-v1.js.map +1 -0
  29. package/dist/client/billing/renewalObservation/terminal-evidence.d.ts +17 -0
  30. package/dist/client/billing/renewalObservation/terminal-evidence.d.ts.map +1 -0
  31. package/dist/client/billing/renewalObservation/terminal-evidence.js +289 -0
  32. package/dist/client/billing/renewalObservation/terminal-evidence.js.map +1 -0
  33. package/dist/client/connect/payoutExecutionTestHelpers.d.ts +16 -16
  34. package/dist/client/connect/payoutSyncTestHelpers.d.ts +16 -16
  35. package/dist/component/balanceFunding/internal/actions.d.ts +11 -11
  36. package/dist/component/balanceFunding/mutations.d.ts +43 -43
  37. package/dist/component/balanceFunding/stateHandlers.d.ts +8 -8
  38. package/dist/component/earnings/triggers.d.ts +16 -16
  39. package/dist/component/financialObservations/settlementHelpers.d.ts +3 -3
  40. package/dist/component/payoutRelease/queries.d.ts +2 -2
  41. package/dist/component/payoutRelease/queries.d.ts.map +1 -1
  42. package/dist/component/processingCostReconciliation/rollback.d.ts +1 -1
  43. package/dist/component/usageCredits/accounting.fixtures.d.ts +16 -16
  44. package/docs/renewal-context-reads.md +9 -5
  45. package/docs/renewal-material-observation.md +50 -0
  46. package/package.json +1 -1
  47. package/src/client/billing/renewalAttach/internal/producer/lineageAuthority.ts +2 -5
  48. package/src/client/billing/renewalAttach/internal/producer/ownerFactory.ts +17 -5
  49. package/src/client/billing/renewalAttach/internal/producer/producerClock.integration.test.ts +175 -0
  50. package/src/client/billing/renewalAttach/internal/producer/producerOwner.integration.test.ts +15 -23
  51. package/src/client/billing/renewalAttach/internal/test-fixtures/producerInitialOperation.ts +62 -0
  52. package/src/client/billing/renewalObservation/evidence-admission.test.ts +219 -0
  53. package/src/client/billing/renewalObservation/evidence-history.test.ts +187 -0
  54. package/src/client/billing/renewalObservation/evidence-invoice-controls.test.ts +293 -0
  55. package/src/client/billing/renewalObservation/evidence-invoice-lines.ts +238 -0
  56. package/src/client/billing/renewalObservation/evidence-invoice.test.ts +177 -0
  57. package/src/client/billing/renewalObservation/evidence-invoice.ts +271 -0
  58. package/src/client/billing/renewalObservation/evidence-material.test.ts +289 -0
  59. package/src/client/billing/renewalObservation/evidence-material.ts +313 -0
  60. package/src/client/billing/renewalObservation/evidence-v1-types.ts +186 -0
  61. package/src/client/billing/renewalObservation/evidence-v1.test.ts +371 -0
  62. package/src/client/billing/renewalObservation/evidence-v1.ts +286 -0
  63. package/src/client/billing/renewalObservation/terminal-evidence.ts +379 -0
@@ -0,0 +1,175 @@
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 {
5
+ INITIAL_NS,
6
+ INITIAL_WALL,
7
+ WORK_WALL,
8
+ } from "../test-fixtures/producerInitialDeclarations.js";
9
+ import { captureInitialInvocationCore } from "./invocationProducer.js";
10
+
11
+ const timerLimit = 2147483647;
12
+ let monotonic = INITIAL_NS;
13
+ beforeEach(() => {
14
+ vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] });
15
+ vi.setSystemTime(INITIAL_WALL);
16
+ monotonic = INITIAL_NS;
17
+ vi.spyOn(process.hrtime, "bigint").mockImplementation(() => monotonic);
18
+ });
19
+ afterEach(() => {
20
+ vi.useRealTimers();
21
+ vi.unstubAllGlobals();
22
+ vi.restoreAllMocks();
23
+ });
24
+
25
+ it("accepts a capture aperture above 1 ms inside the original cutoffs", async () => {
26
+ await initialOperations(async ({ fresh, journal }) => {
27
+ monotonic = INITIAL_NS + 2000000n;
28
+ vi.mocked(process.hrtime.bigint).mockReturnValueOnce(INITIAL_NS);
29
+ const core = await captureInitialInvocationCore(fresh.call, journal);
30
+ try {
31
+ expect(core.owner.basis.startNs).toBe(INITIAL_NS);
32
+ expect(core.owner.basis.workEndNs).toBe(INITIAL_NS + 3000000000n);
33
+ expect(core.owner.check().ns).toBe(monotonic);
34
+ } finally {
35
+ core.owner.retire();
36
+ }
37
+ });
38
+ });
39
+
40
+ it("refuses a capture reaching the projected work cutoff before binding", async () => {
41
+ await initialOperations(async ({ fresh, journal }) => {
42
+ monotonic = INITIAL_NS + 3000000000n;
43
+ vi.mocked(process.hrtime.bigint).mockReturnValueOnce(INITIAL_NS);
44
+ await expect(
45
+ captureInitialInvocationCore(fresh.call, journal),
46
+ ).rejects.toThrow();
47
+ const stored = await journal.loadAuthorizedOperation();
48
+ assert(stored && "initialBasis" in stored);
49
+ expect(stored.initialBasis).toBeNull();
50
+ monotonic = INITIAL_NS;
51
+ await expect(
52
+ captureInitialInvocationCore(fresh.call, journal),
53
+ ).rejects.toThrow();
54
+ });
55
+ });
56
+
57
+ it("accepts a short work timer with a final deadline beyond Node's timer range", async () => {
58
+ await initialOperations(
59
+ async ({ fresh, journal }) => {
60
+ const core = await captureInitialInvocationCore(fresh.call, journal);
61
+ expect(core.owner.basis.endWallMs).toBe(INITIAL_WALL + timerLimit + 1000);
62
+ vi.advanceTimersByTime(WORK_WALL - INITIAL_WALL);
63
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
64
+ },
65
+ 1,
66
+ { endWallMs: INITIAL_WALL + timerLimit + 1000 },
67
+ );
68
+ });
69
+
70
+ it("chunks long work timers and rechecks unchanged cutoffs on each callback", async () => {
71
+ const timers = vi.spyOn(globalThis, "setTimeout");
72
+ vi.spyOn(Date, "now").mockReturnValue(INITIAL_WALL);
73
+ await initialOperations(
74
+ async ({ fresh, journal }) => {
75
+ const core = await captureInitialInvocationCore(fresh.call, journal);
76
+ try {
77
+ const basis = core.owner.basis;
78
+ expect(timers.mock.calls[timers.mock.calls.length - 1]?.[1]).toBe(
79
+ timerLimit,
80
+ );
81
+ // Deliver a chunk while the two independent clocks still have work left.
82
+ vi.advanceTimersByTime(timerLimit);
83
+ expect(core.owner.basis).toBe(basis);
84
+ expect(timers.mock.calls[timers.mock.calls.length - 1]?.[1]).toBe(
85
+ timerLimit,
86
+ );
87
+ expect(core.owner.check().retired).toBe(false);
88
+ monotonic = basis.workEndNs;
89
+ vi.advanceTimersByTime(timerLimit);
90
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
91
+ expect(vi.getTimerCount()).toBe(0);
92
+ } finally {
93
+ core.owner.retire();
94
+ }
95
+ },
96
+ 1,
97
+ {
98
+ workEndWallMs: INITIAL_WALL + timerLimit + 1000,
99
+ endWallMs: INITIAL_WALL + timerLimit + 2000,
100
+ },
101
+ );
102
+ });
103
+
104
+ it("schedules the earlier monotonic cutoff after a wide capture", async () => {
105
+ const timers = vi.spyOn(globalThis, "setTimeout");
106
+ await initialOperations(async ({ fresh, journal }) => {
107
+ monotonic = INITIAL_NS + 2000000000n;
108
+ vi.mocked(process.hrtime.bigint).mockReturnValueOnce(INITIAL_NS);
109
+ const core = await captureInitialInvocationCore(fresh.call, journal);
110
+ expect(timers.mock.calls[timers.mock.calls.length - 1]?.[1]).toBe(1000);
111
+ monotonic = core.owner.basis.workEndNs;
112
+ vi.advanceTimersByTime(1000);
113
+ expect(() => core.owner.check()).toThrow("INITIAL_OWNER_STOP");
114
+ });
115
+ });
116
+
117
+ it("checks the original cutoff after an actual basis mutation is delayed", async () => {
118
+ let reached = () => {};
119
+ let release = () => {};
120
+ const binding = new Promise<void>((resolve) => {
121
+ reached = resolve;
122
+ });
123
+ const delayed = new Promise<void>((resolve) => {
124
+ release = resolve;
125
+ });
126
+ await initialOperations(
127
+ async ({ fresh, journal }) => {
128
+ const pending = captureInitialInvocationCore(fresh.call, journal);
129
+ const refused = expect(pending).rejects.toThrow("INITIAL_OWNER_STOP");
130
+ await binding;
131
+ const stored = await journal.loadAuthorizedOperation();
132
+ assert(stored && "initialBasis" in stored && stored.initialBasis);
133
+ const original = stored.initialBasis.basisJSON;
134
+ vi.setSystemTime(WORK_WALL);
135
+ monotonic = INITIAL_NS + 3000000000n;
136
+ release();
137
+ await refused;
138
+ const after = await journal.loadAuthorizedOperation();
139
+ assert(after && "initialBasis" in after);
140
+ expect(after.initialBasis?.basisJSON).toBe(original);
141
+ await expect(
142
+ captureInitialInvocationCore(fresh.call, journal),
143
+ ).rejects.toThrow();
144
+ },
145
+ 1,
146
+ {
147
+ afterBind: async () => {
148
+ reached();
149
+ await delayed;
150
+ },
151
+ },
152
+ );
153
+ });
154
+
155
+ it("constructs and binds using real Node wall and monotonic clocks", async () => {
156
+ vi.restoreAllMocks();
157
+ vi.useRealTimers();
158
+ const epochMs = Date.now();
159
+ await initialOperations(
160
+ async ({ fresh, journal }) => {
161
+ const core = await captureInitialInvocationCore(fresh.call, journal);
162
+ try {
163
+ expect(core.owner.basis.startWallMs).toBeGreaterThanOrEqual(epochMs);
164
+ expect(core.owner.check().retired).toBe(false);
165
+ const stored = await journal.loadAuthorizedOperation();
166
+ assert(stored && "initialBasis" in stored);
167
+ expect(stored.initialBasis?.basisJSON).toBe(core.basisJSON);
168
+ } finally {
169
+ core.owner.retire();
170
+ }
171
+ },
172
+ 1,
173
+ { epochMs },
174
+ );
175
+ });
@@ -71,29 +71,21 @@ it("rejects an extra replacement-client argument before clocks and spends custod
71
71
  });
72
72
  });
73
73
 
74
- it.each(["wide aperture", "u64 overflow"] as const)(
75
- "rejects %s without binding a replacement basis",
76
- async (reason) => {
77
- await initialOperations(async ({ fresh, journal }) => {
78
- const read = vi.mocked(process.hrtime.bigint);
79
- if (reason === "wide aperture") {
80
- read
81
- .mockReturnValueOnce(INITIAL_NS)
82
- .mockReturnValueOnce(INITIAL_NS + 1000001n);
83
- } else monotonic = 18446744073709551615n - 1n;
84
- await expect(
85
- captureInitialInvocationCore(fresh.call, journal),
86
- ).rejects.toThrow();
87
- const stored = await journal.loadAuthorizedOperation();
88
- assert(stored && "initialBasis" in stored);
89
- expect(stored.initialBasis).toBeNull();
90
- monotonic = INITIAL_NS;
91
- await expect(
92
- captureInitialInvocationCore(fresh.call, journal),
93
- ).rejects.toThrow();
94
- });
95
- },
96
- );
74
+ it("rejects u64 overflow without binding a replacement basis", async () => {
75
+ await initialOperations(async ({ fresh, journal }) => {
76
+ monotonic = 18446744073709551615n - 1n;
77
+ await expect(
78
+ captureInitialInvocationCore(fresh.call, journal),
79
+ ).rejects.toThrow();
80
+ const stored = await journal.loadAuthorizedOperation();
81
+ assert(stored && "initialBasis" in stored);
82
+ expect(stored.initialBasis).toBeNull();
83
+ monotonic = INITIAL_NS;
84
+ await expect(
85
+ captureInitialInvocationCore(fresh.call, journal),
86
+ ).rejects.toThrow();
87
+ });
88
+ });
97
89
 
98
90
  it("does not mint from an existing component result or a copied handle", async () => {
99
91
  await initialOperations(async ({ fresh, journal }) => {
@@ -4,6 +4,7 @@ import {
4
4
  actionGeneric,
5
5
  defineSchema,
6
6
  makeFunctionReference,
7
+ getFunctionAddress,
7
8
  } from "convex/server";
8
9
  import { BetterStripe } from "../../../../index.js";
9
10
  import { components } from "../../../../../../example/convex/_generated/api.js";
@@ -13,6 +14,10 @@ import {
13
14
  codecFixture,
14
15
  } from "../../../../../component/renewalOperations/timingPolicy.fixtures.js";
15
16
  import { createClassActionOperationJournal } from "../operationJournal.js";
17
+ import {
18
+ prepareRenewalPriceReplacementV2,
19
+ prepareRenewalScheduleAttachmentV2,
20
+ } from "../../../renewalV2/index.js";
16
21
 
17
22
  type Journal = Awaited<ReturnType<typeof createClassActionOperationJournal>>;
18
23
  type Fresh = Awaited<ReturnType<Journal["reserveFreshAttempt"]>>;
@@ -24,8 +29,52 @@ export async function initialOperations(
24
29
  index: number;
25
30
  }) => Promise<void>,
26
31
  count = 1,
32
+ options: {
33
+ epochMs?: number;
34
+ workEndWallMs?: number;
35
+ endWallMs?: number;
36
+ afterBind?: () => Promise<void>;
37
+ } = {},
27
38
  ) {
28
39
  const h = await codecFixture();
40
+ if (options.epochMs !== undefined) {
41
+ const seconds = Math.floor(options.epochMs / 1000);
42
+ const source = h.record.attachRequest;
43
+ source.preparation.expected.periodStart = seconds - 1;
44
+ source.preparation.expected.periodEnd = seconds + 2592000;
45
+ const item = source.preparation.subscription.items.data[0];
46
+ item.current_period_start = seconds - 1;
47
+ item.current_period_end = seconds + 2592000;
48
+ source.firstDispatchedAt = seconds;
49
+ const prepared = await prepareRenewalPriceReplacementV2(source.preparation);
50
+ const request = await prepareRenewalScheduleAttachmentV2({
51
+ prepared,
52
+ apiVersion: source.apiVersion,
53
+ attachKey: source.attachKey,
54
+ firstDispatchedAt: seconds,
55
+ });
56
+ h.record.requestBinding = request.requestIdentity.binding;
57
+ h.record.dispatch = {
58
+ scope: request.scope,
59
+ apiVersion: request.apiVersion,
60
+ method: request.method,
61
+ path: request.path,
62
+ payload: request.payload,
63
+ key: request.key,
64
+ firstDispatchedAt: seconds,
65
+ };
66
+ Object.assign(h.record.timingPolicy, {
67
+ firstDispatchedAt: seconds,
68
+ periodStart: seconds - 1,
69
+ periodEnd: seconds + 2592000,
70
+ workEndWallMs: options.epochMs + 10000,
71
+ endWallMs: options.epochMs + 11000,
72
+ });
73
+ }
74
+ if (options.workEndWallMs !== undefined)
75
+ h.record.timingPolicy.workEndWallMs = options.workEndWallMs;
76
+ if (options.endWallMs !== undefined)
77
+ h.record.timingPolicy.endWallMs = options.endWallMs;
29
78
  const sdk = new BetterStripe(components.betterStripe, {
30
79
  STRIPE_SECRET_KEY: "sk_test_invalid_owner_core",
31
80
  });
@@ -34,6 +83,19 @@ export async function initialOperations(
34
83
  run: actionGeneric({
35
84
  args: {},
36
85
  handler: async (ctx): Promise<null> => {
86
+ const runMutation = ctx.runMutation;
87
+ if (options.afterBind)
88
+ ctx.runMutation = async (ref, ...args) => {
89
+ const result = await runMutation(ref, ...args);
90
+ if (
91
+ getFunctionAddress(ref).reference?.endsWith(
92
+ "/bindInitialBasis",
93
+ ) &&
94
+ options.afterBind
95
+ )
96
+ await options.afterBind();
97
+ return result;
98
+ };
37
99
  await Promise.all(
38
100
  Array.from({ length: count }, async (_, index) => {
39
101
  const logicalOperationId =
@@ -0,0 +1,219 @@
1
+ import { afterEach, expect, it, vi } from "vitest";
2
+ import { inspectRenewalEvidenceV1 } from "./evidence-v1.js";
3
+ import { object } from "./common.js";
4
+ import {
5
+ recipe,
6
+ set,
7
+ model,
8
+ unknownResult,
9
+ } from "../../../../tests/renewalObservation/evidenceFixtures.js";
10
+
11
+ afterEach(() => vi.unstubAllGlobals());
12
+ /** Reflection only: do not invoke getters or serialize malformed/cyclic DATA. */
13
+ function descriptors(input: unknown) {
14
+ const seen = new Set<object>();
15
+ const rows: {
16
+ object: object;
17
+ key: PropertyKey;
18
+ descriptor: PropertyDescriptor;
19
+ }[] = [];
20
+ function walk(value: unknown) {
21
+ if (!value || typeof value !== "object" || seen.has(value)) return;
22
+ seen.add(value);
23
+ for (const key of Reflect.ownKeys(value)) {
24
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
25
+ if (!descriptor) throw Error("MISSING_TEST_DESCRIPTOR");
26
+ rows.push({ object: value, key, descriptor });
27
+ if ("value" in descriptor) walk(descriptor.value);
28
+ }
29
+ }
30
+ walk(input);
31
+ return rows;
32
+ }
33
+ const malformed = [
34
+ "missing-root",
35
+ "extra-root",
36
+ "undefined",
37
+ "symbol",
38
+ "hidden",
39
+ "getter",
40
+ "cycle",
41
+ "nonfinite",
42
+ "sparse",
43
+ "prototype",
44
+ ] as const;
45
+ it.each(malformed)(
46
+ "evidence admission rejects %s without reading getters",
47
+ async (control) => {
48
+ const input = recipe().input;
49
+ const schedule = object(input.reads.schedule);
50
+ let getterCalls = 0,
51
+ fetchCalls = 0;
52
+ if (control === "missing-root") Reflect.deleteProperty(input, "reads");
53
+ if (control === "extra-root") set(input, "extra", null);
54
+ if (control === "undefined") set(schedule, "unknown", undefined);
55
+ if (control === "symbol")
56
+ set(schedule, "unknown", { [Symbol("TEST")]: true });
57
+ if (control === "hidden")
58
+ Object.defineProperty(schedule, "unknown", { value: null });
59
+ if (control === "getter")
60
+ Object.defineProperty(schedule, "unknown", {
61
+ enumerable: true,
62
+ get() {
63
+ getterCalls++;
64
+ return null;
65
+ },
66
+ });
67
+ if (control === "cycle") set(schedule, "unknown", schedule);
68
+ if (control === "nonfinite") set(schedule, "unknown", Number.NaN);
69
+ if (control === "sparse") set(schedule, "unknown", new Array(1));
70
+ if (control === "prototype") set(schedule, "unknown", new Date(0));
71
+ const before = descriptors(input);
72
+ vi.stubGlobal("fetch", () => {
73
+ fetchCalls++;
74
+ throw Error("UNEXPECTED_FETCH");
75
+ });
76
+ let targetFailed = false;
77
+ try {
78
+ await expect(inspectRenewalEvidenceV1(input)).rejects.toThrow(
79
+ /^Invalid raw renewal evidence\.$/,
80
+ );
81
+ } catch (error) {
82
+ targetFailed = true;
83
+ throw error;
84
+ } finally {
85
+ try {
86
+ expect(descriptors(input)).toEqual(before);
87
+ expect(getterCalls).toBe(0);
88
+ expect(fetchCalls).toBe(0);
89
+ } catch (error) {
90
+ if (!targetFailed) throw error;
91
+ console.info("EVIDENCE_ADMISSION_INSPECTION_FAILED");
92
+ }
93
+ }
94
+ },
95
+ );
96
+ it.each(["version", "api"] as const)(
97
+ "evidence unsupported %s returns the entire closed DTO",
98
+ async (control) => {
99
+ const input = recipe().input;
100
+ set(
101
+ input,
102
+ control === "version" ? "version" : "apiVersion",
103
+ control === "version" ? 2 : "2026-01-28.clover",
104
+ );
105
+ const before = structuredClone(input);
106
+ const expected = unknownResult(
107
+ control === "version" ? "unsupported_profile" : "unsupported_api_version",
108
+ );
109
+ let fetchCalls = 0;
110
+ vi.stubGlobal("fetch", () => {
111
+ fetchCalls++;
112
+ throw Error("UNEXPECTED_FETCH");
113
+ });
114
+ let targetFailed = false;
115
+ try {
116
+ const actual = await inspectRenewalEvidenceV1(input);
117
+ expect(actual).toEqual(expected);
118
+ expect(Reflect.ownKeys(actual)).toHaveLength(12);
119
+ } catch (error) {
120
+ targetFailed = true;
121
+ throw error;
122
+ } finally {
123
+ try {
124
+ expect(input).toEqual(before);
125
+ expect(fetchCalls).toBe(0);
126
+ } catch (error) {
127
+ if (!targetFailed) throw error;
128
+ console.info("EVIDENCE_ADMISSION_INSPECTION_FAILED");
129
+ }
130
+ }
131
+ },
132
+ );
133
+ const boundaries = [
134
+ "characters-under",
135
+ "characters-over",
136
+ "utf8-over",
137
+ "nodes-under",
138
+ "nodes-over",
139
+ "depth-under",
140
+ "depth-over",
141
+ ] as const;
142
+ it.each(boundaries)("evidence whole-model boundary %s", async (control) => {
143
+ const input = recipe().input;
144
+ // Unsupported version isolates whole-input admission from material predicates.
145
+ set(input, "version", 2);
146
+ const schedule = object(input.reads.schedule);
147
+ set(schedule, "unknown", "");
148
+ if (control.startsWith("characters")) {
149
+ const remaining = 500000 - model(input).characters;
150
+ expect(remaining).toBeGreaterThan(0);
151
+ set(
152
+ schedule,
153
+ "unknown",
154
+ "x".repeat(remaining + (control.endsWith("over") ? 1 : 0)),
155
+ );
156
+ } else if (control === "utf8-over") {
157
+ set(schedule, "unknown", "é".repeat(260000));
158
+ } else if (control.startsWith("nodes")) {
159
+ set(schedule, "unknown", []);
160
+ const remaining = 10000 - model(input).nodes;
161
+ expect(remaining).toBeGreaterThan(0);
162
+ set(
163
+ schedule,
164
+ "unknown",
165
+ Array.from(
166
+ { length: remaining + (control.endsWith("over") ? 1 : 0) },
167
+ () => null,
168
+ ),
169
+ );
170
+ } else {
171
+ let nested: unknown = null;
172
+ for (let i = 0; i < (control.endsWith("over") ? 38 : 37); i++)
173
+ nested = { next: nested };
174
+ set(schedule, "unknown", nested);
175
+ }
176
+ const metrics = model(input);
177
+ const over = control.endsWith("over");
178
+ if (control.startsWith("characters"))
179
+ expect(metrics.characters).toBe(over ? 500001 : 500000);
180
+ if (control === "utf8-over") {
181
+ expect(metrics.characters).toBeLessThan(500000);
182
+ expect(metrics.bytes).toBeGreaterThan(500000);
183
+ }
184
+ if (control.startsWith("nodes"))
185
+ expect(metrics.nodes).toBe(over ? 10001 : 10000);
186
+ if (control.startsWith("depth")) expect(metrics.depth).toBe(over ? 41 : 40);
187
+ const before = descriptors(input);
188
+ let fetchCalls = 0;
189
+ vi.stubGlobal("fetch", () => {
190
+ fetchCalls++;
191
+ throw Error("UNEXPECTED_FETCH");
192
+ });
193
+ let targetFailed = false;
194
+ try {
195
+ if (over)
196
+ await expect(inspectRenewalEvidenceV1(input)).rejects.toThrow(
197
+ /^Invalid raw renewal evidence\.$/,
198
+ );
199
+ else
200
+ expect(await inspectRenewalEvidenceV1(input)).toEqual(
201
+ unknownResult("unsupported_profile"),
202
+ );
203
+ } catch (error) {
204
+ targetFailed = true;
205
+ throw error;
206
+ } finally {
207
+ try {
208
+ expect(descriptors(input)).toEqual(before);
209
+ expect(fetchCalls).toBe(0);
210
+ console.info(
211
+ "EVIDENCE_ADMISSION_BOUNDARY",
212
+ JSON.stringify({ control, ...metrics, fetchCalls }),
213
+ );
214
+ } catch (error) {
215
+ if (!targetFailed) throw error;
216
+ console.info("EVIDENCE_ADMISSION_INSPECTION_FAILED");
217
+ }
218
+ }
219
+ });