@systemfsoftware/vitest 0.1.0 → 0.3.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.
@@ -0,0 +1,1293 @@
1
+
2
+ import { d as isUserFrame, f as siteOfFrame, i as checksFor, o as makeLedger, p as withRaisingFrame, r as Asserted, s as callFrame, t as VitestTestContext, u as framesOf$1 } from "./test-context-D_-acRSc.mjs";
3
+ import * as V from "vitest";
4
+ import { TestRunner, inject } from "vitest";
5
+ import * as Cause from "effect/Cause";
6
+ import * as Effect$1 from "effect/Effect";
7
+ import * as Equal from "effect/Equal";
8
+ import * as Exit from "effect/Exit";
9
+ import * as Function from "effect/Function";
10
+ import * as Schema$1 from "effect/Schema";
11
+ import * as Option$1 from "effect/Option";
12
+ import * as Match from "effect/Match";
13
+ import * as Tracer from "effect/Tracer";
14
+ import { Effect, Option, Schema, SchemaGetter, SchemaIssue } from "effect";
15
+ import * as Arbitrary from "effect/unstable/arbitrary/Arbitrary";
16
+ import * as Data from "effect/Data";
17
+ //#region src/internal/property/defaults.ts
18
+ /** @internal The `test.provide` key the shared config fills with this run's tier's check options. */
19
+ const checkDefaultsKey = "@systemfsoftware/vitest:property-check";
20
+ /** @internal The configured property-check defaults, or `undefined` when the run provided none. */
21
+ const providedCheckDefaults = () => inject(checkDefaultsKey);
22
+ //#endregion
23
+ //#region src/replay.schema.ts
24
+ /**
25
+ * The one replay grammar (KTD10, R6): the `CONFORMANCE_REPLAY` text a failure record's rerun line carries and
26
+ * the spec runtime reads back to re-run the same schedule. The text names the seed a generator chose and the
27
+ * decisions it took, in order — `seed=7;path=1,2,3` — and the path is empty when the run took no decision
28
+ * (`seed=1;path=`). A text that names neither is not a replay.
29
+ *
30
+ * The seed and every decision are branded whole numbers (CONST-D3), and the text is a codec rooted at
31
+ * `Schema.String`, so one declaration serves both the writer and the reader instead of a pattern each.
32
+ *
33
+ * @since 4.0.0
34
+ */
35
+ /** The seed a replay names: the whole number a generator chose, never negative (CONST-D3). */
36
+ const ReplaySeed = Schema.Int.pipe(Schema.check(Schema.isGreaterThanOrEqualTo(0)), Schema.brand("ReplaySeed"));
37
+ /** One decision along a replay path: the index the scheduler picked at that step (CONST-D3). */
38
+ const ReplayStep = Schema.Int.pipe(Schema.check(Schema.isGreaterThanOrEqualTo(0)), Schema.brand("ReplayStep"));
39
+ /** The replay a generator chose: its seed and the decisions it took, in order (R6). */
40
+ const Replay = Schema.Struct({
41
+ seed: ReplaySeed,
42
+ path: Schema.Array(ReplayStep)
43
+ });
44
+ const SEED_PREFIX = "seed=";
45
+ const PATH_PREFIX = "path=";
46
+ const PAIR_SEPARATOR = ";";
47
+ const ENTRY_SEPARATOR = ",";
48
+ const WHOLE_NUMBER = /^\d+$/u;
49
+ const NOT_A_REPLAY = "a replay reads \"seed=<whole number>;path=<comma-separated whole numbers>\"";
50
+ const wholeNumberOf = (text) => WHOLE_NUMBER.test(text) ? Number(text) : void 0;
51
+ const seedDigitsOf = (text) => text.startsWith(SEED_PREFIX) ? text.slice(5) : void 0;
52
+ const pathDigitsOf = (text) => text.startsWith(PATH_PREFIX) ? text.slice(5) : void 0;
53
+ const entriesOf$1 = (text) => text.length === 0 ? [] : text.split(ENTRY_SEPARATOR);
54
+ const wholeNumbersOf = (entries) => {
55
+ const numbers = entries.map(wholeNumberOf);
56
+ return numbers.every((value) => value !== void 0) ? numbers : void 0;
57
+ };
58
+ const seedIn = (part) => Option.flatMap(Option.fromUndefinedOr(seedDigitsOf(part)), (digits) => Option.fromUndefinedOr(wholeNumberOf(digits)));
59
+ const decisionsIn = (part) => Option.flatMap(Option.fromUndefinedOr(pathDigitsOf(part)), (entries) => Option.fromUndefinedOr(wholeNumbersOf(entriesOf$1(entries))));
60
+ const pairPartsOf = (text) => {
61
+ const [seedPart, pathPart, ...rest] = text.split(PAIR_SEPARATOR);
62
+ return rest.length === 0 ? Option.all([Option.fromUndefinedOr(seedPart), Option.fromUndefinedOr(pathPart)]) : Option.none();
63
+ };
64
+ /** The seed and decisions a pair names, or nothing when the pair is not `seed=…;path=…`. */
65
+ const namedPairOf = (text) => Option.flatMap(pairPartsOf(text), ([seedPart, pathPart]) => Option.all([seedIn(seedPart), decisionsIn(pathPart)]));
66
+ /** The replay a seed and decision path name, or nothing when either is outside the grammar's domain. */
67
+ const replayOfParts = (parts) => Schema.decodeOption(Replay)(parts);
68
+ const replayOfName = (text) => Option.flatMap(namedPairOf(text), ([seed, path]) => replayOfParts({
69
+ seed,
70
+ path
71
+ }));
72
+ const textOfEncodedReplay = (replay) => `${SEED_PREFIX}${replay.seed}${PAIR_SEPARATOR}${PATH_PREFIX}${replay.path.join(ENTRY_SEPARATOR)}`;
73
+ const replayRefusal = (text) => /* @__PURE__ */ new Error(`CONFORMANCE_REPLAY names neither a seed nor a decision path: ${text}`);
74
+ /**
75
+ * The `CONFORMANCE_REPLAY` text as the replay it names. A text a seed and a path cannot be read out of is refused
76
+ * with the same prose the spec runtime has always thrown, so the grammar and its refusal share one home.
77
+ *
78
+ * @since 4.0.0
79
+ */
80
+ const replayOfText = (text) => Option.match(replayOfName(text), {
81
+ onNone: () => {
82
+ throw replayRefusal(text);
83
+ },
84
+ onSome: (replay) => replay
85
+ });
86
+ /** The text a replay is written as: the `CONFORMANCE_REPLAY` value a rerun line carries (R6).
87
+ *
88
+ * @since 4.0.0
89
+ */
90
+ const replayTextOf = (replay) => textOfEncodedReplay(replay);
91
+ /**
92
+ * The replay codec: `Schema.String` in, a replay out. A text that names no seed and path fails the decode, and
93
+ * every replay encodes back to the text it was read from.
94
+ *
95
+ * @since 4.0.0
96
+ */
97
+ const ReplayFromText = Schema.String.pipe(Schema.decodeTo(Replay, {
98
+ decode: SchemaGetter.transformEffect((text, options) => Effect.fromOption(replayOfName(text), () => new SchemaIssue.InvalidValue({ message: NOT_A_REPLAY }, text, options))),
99
+ encode: SchemaGetter.transform(textOfEncodedReplay)
100
+ }));
101
+ //#endregion
102
+ //#region src/internal/errors.schema.ts
103
+ /**
104
+ * The contract rules a rendered failure record can break (R10, KTD7).
105
+ *
106
+ * @internal
107
+ */
108
+ const Breach = Schema.Literals([
109
+ "R1",
110
+ "R2",
111
+ "R6"
112
+ ]);
113
+ /** A record's breaches, in the order the renderer found them.
114
+ *
115
+ * @internal
116
+ */
117
+ const Breaches = Schema.Array(Breach);
118
+ /** The fixed prose each breach is refused with; nothing ever reads a refusal back, so it cannot recurse. */
119
+ const REFUSED_BREACH_TEXT = {
120
+ R1: "the headline is empty",
121
+ R2: "the record names no source location",
122
+ R6: "a replay value names a run no generator chose, or the rerun line is missing"
123
+ };
124
+ /**
125
+ * The one detail a record refusal carries: every breach the renderer found, in the prose above (R10, KTD7). The
126
+ * breach letter is not printed: a reader acts on what is missing, not on which requirement numbered it.
127
+ *
128
+ * @internal
129
+ */
130
+ const refusedRecordDetail = (breaches) => `✗ refused a failure record: ${breaches.map((breach) => REFUSED_BREACH_TEXT[breach]).join(", and ")}`;
131
+ /** @internal */
132
+ var NonBooleanVerdict = class extends Schema.TaggedError()("NonBooleanVerdict", { detail: Schema.String }) {
133
+ get message() {
134
+ return this.detail;
135
+ }
136
+ };
137
+ /** @internal */
138
+ var LeakedState = class extends Schema.TaggedError()("LeakedState", { detail: Schema.String }) {
139
+ get message() {
140
+ return this.detail;
141
+ }
142
+ };
143
+ /** @internal */
144
+ var Slop = class extends Schema.TaggedError()("Slop", { detail: Schema.String }) {
145
+ get message() {
146
+ return this.detail;
147
+ }
148
+ };
149
+ /** @internal */
150
+ var InvalidBudget = class extends Schema.TaggedError()("InvalidBudget", { detail: Schema.String }) {
151
+ get message() {
152
+ return this.detail;
153
+ }
154
+ };
155
+ /** @internal */
156
+ var FailureRecordRefused = class extends Schema.TaggedError()("FailureRecordRefused", {
157
+ breaches: Breaches,
158
+ cause: Schema.optional(Schema.Unknown)
159
+ }) {
160
+ get message() {
161
+ return refusedRecordDetail(this.breaches);
162
+ }
163
+ };
164
+ //#endregion
165
+ //#region src/internal/provided.schema.ts
166
+ /**
167
+ * The npm name of the package under test, as its own `package.json` spells it.
168
+ *
169
+ * @internal
170
+ */
171
+ const PackageName = Schema.NonEmptyString.pipe(Schema.brand("PackageName"));
172
+ /**
173
+ * The workspace root every rendered path is relativized against.
174
+ *
175
+ * @internal
176
+ */
177
+ const WorkspaceRoot = Schema.NonEmptyString.pipe(Schema.brand("WorkspaceRoot"));
178
+ //#endregion
179
+ //#region src/internal/provided.ts
180
+ /**
181
+ * The values the shared vitest config provides for the fork: the package under test's npm name and the workspace
182
+ * root every rendered path is relativized against. Both are read out of the run's provided context (Vitest's
183
+ * `inject`), so no production source reads a Node built-in, and an absent value is simply `undefined` — a rerun
184
+ * line then drops its package filter, and paths print absolute (R6, KTD5).
185
+ *
186
+ * The values are branded (`provided.schema.ts`): a package name and a workspace root are not interchangeable
187
+ * text (CONST-D3).
188
+ *
189
+ * @since 4.0.0
190
+ */
191
+ /** @internal */
192
+ const packageKey = "@systemfsoftware/vitest:package";
193
+ /** @internal */
194
+ const workspaceRootKey = "@systemfsoftware/vitest:workspace-root";
195
+ const isText$1 = (value) => typeof value === "string";
196
+ const nonEmpty = (value) => value.length === 0 ? void 0 : value;
197
+ const nonEmptyText$1 = (value) => isText$1(value) ? nonEmpty(value) : void 0;
198
+ const read = (key) => {
199
+ try {
200
+ return nonEmptyText$1(inject(key));
201
+ } catch {
202
+ return;
203
+ }
204
+ };
205
+ const readNamed = (key, schema) => Option.getOrUndefined(Option.flatMap(Option.fromUndefinedOr(read(key)), (text) => Schema.decodeOption(schema)(text)));
206
+ /** @internal */
207
+ const providedPackage = () => readNamed(packageKey, PackageName);
208
+ /** @internal */
209
+ const providedRoot = () => readNamed(workspaceRootKey, WorkspaceRoot);
210
+ //#endregion
211
+ //#region src/internal/failure-record.ts
212
+ /**
213
+ * The one renderer for a spec failure: the failure and the spans its run recorded become the record Vitest
214
+ * prints, together with the contract rules that record breaks (KTD1, KTD7).
215
+ *
216
+ * The record is ordered by R2-R6: the raising frame leads, the failing step and its spec line follow, then every
217
+ * cause layer, then the step trail with the cell decisions each step caused, then the rerun command. The
218
+ * renderer is pure and never throws: a value it cannot read renders as text, never as an exception.
219
+ *
220
+ * @since 4.0.0
221
+ */
222
+ const STEP_SPAN = "gherkin.step";
223
+ const STEP_KEYWORD = "gherkin.keyword";
224
+ const STEP_TEXT = "gherkin.text";
225
+ const CODE_SITE = "code.site";
226
+ const CELL_NAME = "cell.name";
227
+ const CELL_STACKTRACE = "cell.stacktrace";
228
+ const CELL_DECIDE_STACKTRACE = "cell.decide_stacktrace";
229
+ const CELL_COMMAND_TAG = "cell.command_tag";
230
+ const CELL_MEMBER_TAGS = "cell.member_tags";
231
+ const CELL_DECLARED = "cell.declared";
232
+ const CELL_OUTCOME = "cell.outcome";
233
+ const TAG_FIELD = "_tag";
234
+ const MESSAGE_FIELD = "message";
235
+ const NAME_FIELD = "name";
236
+ const STACK_FIELD = "stack";
237
+ const CAUSE_FIELD = "cause";
238
+ const FILE_PROTOCOL = "file://";
239
+ const UNKNOWN_SITE = "?";
240
+ const DEFAULT_FAILURE_NAME = "Error";
241
+ const NEVER_FINISHED = " (never finished)";
242
+ const CAUSE_DEPTH = 6;
243
+ /** The fields a layer's own values exclude: the chain renders the cause, and the raise site names the stack. */
244
+ const SKIPPED_FIELDS = {
245
+ [TAG_FIELD]: true,
246
+ [MESSAGE_FIELD]: true,
247
+ [NAME_FIELD]: true,
248
+ [STACK_FIELD]: true,
249
+ [CAUSE_FIELD]: true
250
+ };
251
+ /** The contract's "first location": any `<path>:<line>` the record names. */
252
+ const LOCATION = /(?:[\w.@-]+\/)*[\w.@-]+\.[cm]?[jt]sx?:\d+/u;
253
+ const COLUMN_SUFFIX = /:\d+$/u;
254
+ const MARK = {
255
+ passed: "✓",
256
+ failed: "✗",
257
+ unfinished: "✗"
258
+ };
259
+ const not = (value) => !value;
260
+ const and = (left, right) => left && right;
261
+ const or = (left, right) => left || right;
262
+ const firstPresent = (values) => values.find((value) => value !== void 0);
263
+ const isObject = (value) => typeof value === "object" && value !== null;
264
+ const isText = (value) => typeof value === "string";
265
+ const isArray = (value) => Array.isArray(value);
266
+ const isNumber = (value) => typeof value === "number";
267
+ const isBoolean = (value) => typeof value === "boolean";
268
+ const isBigInt = (value) => typeof value === "bigint";
269
+ const isNull = (value) => value === null;
270
+ const isPrimitive = (value) => or(or(isNumber(value), isBoolean(value)), isBigInt(value));
271
+ const objectOrUndefined = (value) => isObject(value) ? value : void 0;
272
+ const isFieldName = (name) => SKIPPED_FIELDS[name] !== true;
273
+ const presentOrUndefined = (text) => text.length === 0 ? void 0 : text;
274
+ const nonEmptyText = (text) => text === void 0 ? void 0 : presentOrUndefined(text);
275
+ const fieldOf = (value, key) => Reflect.get(value, key);
276
+ const textFieldOf = (value, key) => {
277
+ const field = fieldOf(value, key);
278
+ return isText(field) ? field : void 0;
279
+ };
280
+ const nonEmptyFieldOf = (value, key) => nonEmptyText(textFieldOf(value, key));
281
+ const tagFieldOf = (value) => nonEmptyFieldOf(value, TAG_FIELD);
282
+ const messageFieldOf = (value) => nonEmptyFieldOf(value, MESSAGE_FIELD);
283
+ const pairOf = (name, text) => ({
284
+ name,
285
+ text
286
+ });
287
+ const pairTextOf = (pair) => `${JSON.stringify(pair.name)}:${pair.text}`;
288
+ const pairTextsOf = (pairs) => pairs.map(pairTextOf);
289
+ const hasPair = (pairs, name) => pairs.some((pair) => pair.name === name);
290
+ const pairsOf = (value) => isObject(value) ? Object.keys(value).map((key) => pairOf(key, renderValue(fieldOf(value, key)))) : [];
291
+ const fieldsOf = (value) => pairsOf(value).filter((pair) => isFieldName(pair.name));
292
+ const renderValue = (value) => isObject(value) ? renderObject(value) : renderScalar(value);
293
+ const renderScalar = (value) => isText(value) ? JSON.stringify(value) : renderPrimitive(value);
294
+ const renderPrimitive = (value) => isBigInt(value) ? `${value}n` : renderPlain(value);
295
+ const renderPlain = (value) => isPrimitive(value) ? `${value}` : renderOther(value);
296
+ const renderOther = (value) => isNull(value) ? "null" : renderUndefined(value);
297
+ const renderUndefined = (value) => value === void 0 ? "undefined" : renderContainer(value);
298
+ const renderContainer = (value) => isArray(value) ? renderList(value) : typeof value;
299
+ const renderList = (value) => `[${value.map(renderValue).join(",")}]`;
300
+ const renderObject = (value) => tagFieldOf(value) ?? renderRecord$1(value);
301
+ const renderRecord$1 = (value) => `{${pairTextsOf(pairsOf(value)).join(",")}}`;
302
+ const bracesOf = (pairs) => ` {${pairTextsOf(pairs).join(",")}}`;
303
+ const renderFields = (value) => bracesOf(fieldsOf(value));
304
+ const textSummaryOf = (text) => text.length === 0 ? text : JSON.stringify(text);
305
+ const scalarSummaryOf = (value) => isText(value) ? textSummaryOf(value) : renderScalar(value);
306
+ /** @internal */
307
+ const summaryOf = (value) => isObject(value) ? objectSummaryOf(value) : scalarSummaryOf(value);
308
+ const objectSummaryOf = (value) => {
309
+ const tag = tagFieldOf(value);
310
+ return tag === void 0 ? untaggedSummaryOf(value) : taggedSummaryOf(tag, value);
311
+ };
312
+ const untaggedSummaryOf = (value) => isErrorValue(value) ? errorSummaryOf(value) : valueRecordSummaryOf(value);
313
+ const valueRecordSummaryOf = (value) => isArray(value) ? renderList(value) : renderRecord$1(value);
314
+ const isErrorValue = (value) => value instanceof Error;
315
+ const firstLine = (text) => text.split("\n")[0] ?? text;
316
+ const restLines = (text) => text.split("\n").slice(1);
317
+ const taggedSummaryOf = (tag, value) => {
318
+ const message = messageFieldOf(value);
319
+ return message === void 0 ? `${tag}${renderFields(value)}` : `${tag}: ${firstLine(message)}`;
320
+ };
321
+ const errorSummaryOf = (value) => {
322
+ const name = objectNameOf(value);
323
+ const message = messageFieldOf(value);
324
+ return message === void 0 ? `${name}${renderFields(value)}` : `${name}: ${firstLine(message)}`;
325
+ };
326
+ const objectNameOf = (value) => firstPresent([tagFieldOf(value), nonEmptyFieldOf(value, NAME_FIELD)]) ?? DEFAULT_FAILURE_NAME;
327
+ const headlineOf = (layers) => layers.length === 0 ? "" : summaryOf(layers[0]);
328
+ const nameOf = (layers) => {
329
+ const entry = layers[0];
330
+ return isObject(entry) ? objectNameOf(entry) : DEFAULT_FAILURE_NAME;
331
+ };
332
+ const stripProtocol = (path) => path.startsWith(FILE_PROTOCOL) ? path.slice(7) : path;
333
+ const stripColumn = (site) => site.replace(COLUMN_SUFFIX, "");
334
+ const knownSiteOf = (site) => isText(site) ? stripColumn(stripProtocol(site)) : void 0;
335
+ const siteTextOf = (site) => knownSiteOf(site) ?? UNKNOWN_SITE;
336
+ const siteOfFrames = (frames) => Option$1.getOrUndefined(Option$1.map(Option$1.fromUndefinedOr(frames.find(isUserFrame)), siteOfFrame));
337
+ /** The author's site in a raw captured stack, the form a cell span records instead of a pre-resolved site. */
338
+ const cellStackSiteOf = (stack) => isText(stack) ? siteOfFrames(framesOf$1(stack)) : void 0;
339
+ const stackSiteTextOf = (stack) => knownSiteOf(cellStackSiteOf(stack)) ?? UNKNOWN_SITE;
340
+ const stackIn = (value) => textFieldOf(value, STACK_FIELD) ?? "";
341
+ const stackOf = (value) => isObject(value) ? stackIn(value) : "";
342
+ const framesOf = (value) => framesOf$1(stackOf(value));
343
+ const isFrame = (frame) => frame !== void 0;
344
+ const usableFrameOf = (value) => framesOf(value).find(isUserFrame);
345
+ const frameTextOf = (frame) => `${frame.path}:${frame.line}${frameNameSuffix(frame.fn)}`;
346
+ const isAuthorName = (fn) => fn !== void 0 && !fn.includes("~effect/");
347
+ const frameNameSuffix = (fn) => isAuthorName(fn) ? ` (${fn})` : "";
348
+ const isSameSite = (frame, other) => and(frame.path === other.path, frame.line === other.line);
349
+ const isSameFrame = (frame, other) => other === void 0 ? false : isSameSite(frame, other);
350
+ const chosenFrameOf = (layers) => {
351
+ const inner = layers.slice(1).map(usableFrameOf).filter(isFrame).at(-1);
352
+ return inner === void 0 ? usableFrameOf(layers[0]) : inner;
353
+ };
354
+ const attrOf = (span, key) => span.attributes.get(key);
355
+ const textAttrOf = (span, key) => {
356
+ const value = attrOf(span, key);
357
+ return isText(value) ? value : void 0;
358
+ };
359
+ const ancestorsIn = (span) => span instanceof Tracer.NativeSpan ? [span, ...ancestorsOf(span.parent)] : [];
360
+ const ancestorsOf = (parent) => Option$1.isNone(parent) ? [] : ancestorsIn(parent.value);
361
+ const stepAncestorOf = (span) => ancestorsOf(span.parent).find((ancestor) => ancestor.name === STEP_SPAN);
362
+ const stateOf = (span) => Match.value(span.status).pipe(Match.when({ _tag: "Started" }, () => "unfinished"), Match.when({ _tag: "Ended" }, (ended) => endedStateOf(ended.exit)), Match.exhaustive);
363
+ const endedStateOf = (exit) => Exit.isSuccess(exit) ? "passed" : "failed";
364
+ const stepSpansOf = (spans) => spans.filter(isTopStepSpan);
365
+ const isTopStepSpan = (span) => and(span.name === STEP_SPAN, stepAncestorOf(span) === void 0);
366
+ const isCellSpan = (span) => isText(attrOf(span, CELL_STACKTRACE));
367
+ const cellSpansOf = (spans) => spans.filter(isCellSpan);
368
+ const cellNameOf = (cell) => textAttrOf(cell, CELL_NAME) ?? cell.name;
369
+ const causeFieldOf = (value) => isObject(value) ? objectOrUndefined(fieldOf(value, CAUSE_FIELD)) : void 0;
370
+ /** One layer with whatever its own `cause` adds, depth-limited. */
371
+ const layerWithCauseOf = (value, depth) => [value, ...nestedCauseOf(value, depth - 1)];
372
+ /** The layers the reasons of an Effect `Cause` add, each rendered as any other layer. */
373
+ const reasonLayersOf = (cause, depth) => cause.reasons.flatMap((reason) => layerWithCauseOf(reasonPayloadOf(reason), depth));
374
+ const layersOfCause = (cause, depth) => Cause.isCause(cause) ? reasonLayersOf(cause, depth) : layerWithCauseOf(cause, depth);
375
+ const nestedOf = (cause, depth) => cause === void 0 ? [] : layersOfCause(cause, depth);
376
+ const nestedCauseOf = (value, depth) => depth === 0 ? [] : nestedOf(causeFieldOf(value), depth);
377
+ const causeChainOf = (value) => [value, ...nestedCauseOf(value, CAUSE_DEPTH)];
378
+ const interruptTextOf = (reason) => reason.fiberId === void 0 ? "interrupted" : `interrupted by fiber #${reason.fiberId}`;
379
+ const reasonPayloadOf = (reason) => Match.value(reason).pipe(Match.when({ _tag: "Fail" }, (fail) => fail.error), Match.when({ _tag: "Die" }, (die) => die.defect), Match.when({ _tag: "Interrupt" }, (interrupt) => interruptTextOf(interrupt)), Match.exhaustive);
380
+ const reasonsOf = (cause) => cause.reasons.flatMap((reason) => causeChainOf(reasonPayloadOf(reason)));
381
+ const layersOf = (failure) => Cause.isCause(failure) ? reasonsOf(failure) : causeChainOf(failure);
382
+ const declineOf = (span) => stateOf(span) === "unfinished" ? NEVER_FINISHED : "";
383
+ const capitalize = (text) => text.length === 0 ? text : `${text.slice(0, 1).toUpperCase()}${text.slice(1)}`;
384
+ const keywordOf = (step) => capitalize(textAttrOf(step, STEP_KEYWORD) ?? "");
385
+ const stepTextOf = (step) => textAttrOf(step, STEP_TEXT) ?? "";
386
+ const stepSiteOf = (step) => siteTextOf(attrOf(step, CODE_SITE));
387
+ const stepLineOf = (step) => ` ${MARK[stateOf(step)]} ${keywordOf(step)} ${stepTextOf(step)} ${stepSiteOf(step)}${declineOf(step)}`;
388
+ const commandOf = (cell) => textAttrOf(cell, CELL_COMMAND_TAG) ?? "";
389
+ const cellPairsOf = (cell) => {
390
+ const members = pairsOf(attrOf(cell, CELL_MEMBER_TAGS));
391
+ const declared = pairsOf(attrOf(cell, CELL_DECLARED)).filter((pair) => !hasPair(members, pair.name));
392
+ return [...members, ...declared];
393
+ };
394
+ const pairsBracesOf = (cell) => bracesOf(cellPairsOf(cell));
395
+ const outcomeOf$1 = (cell) => {
396
+ const outcome = textAttrOf(cell, CELL_OUTCOME);
397
+ return outcome === void 0 ? "" : ` → ${outcome}`;
398
+ };
399
+ const blockOf = (cell) => ({
400
+ head: ` cell ${cellNameOf(cell)}: ${commandOf(cell)}${pairsBracesOf(cell)}${outcomeOf$1(cell)}`,
401
+ tail: ` decide ${stackSiteTextOf(attrOf(cell, CELL_DECIDE_STACKTRACE))} cell ${stackSiteTextOf(attrOf(cell, CELL_STACKTRACE))}`
402
+ });
403
+ const groupOf = (block, count) => ({
404
+ block,
405
+ count
406
+ });
407
+ const isSameBlock = (block, other) => and(block.head === other.head, block.tail === other.tail);
408
+ const appendBeside = (groups, block, last) => isSameBlock(last.block, block) ? [...groups.slice(0, -1), groupOf(block, last.count + 1)] : [...groups, groupOf(block, 1)];
409
+ const appendAfter = (groups, block, last) => last === void 0 ? [groupOf(block, 1)] : appendBeside(groups, block, last);
410
+ const appendGroup = (groups, block) => appendAfter(groups, block, groups.at(-1));
411
+ const groupsOf = (blocks) => blocks.reduce(appendGroup, []);
412
+ const groupLinesOf = (group) => [group.count > 1 ? `${group.block.head} (×${group.count})` : group.block.head, group.block.tail];
413
+ const cellsUnder = (spans, step) => cellSpansOf(spans).filter((cell) => stepAncestorOf(cell) === step);
414
+ const decisionLinesOf = (spans, step) => groupsOf(cellsUnder(spans, step).map(blockOf)).flatMap(groupLinesOf);
415
+ const trailStepsOf = (spans) => {
416
+ const steps = stepSpansOf(spans);
417
+ const failing = steps.find((step) => stateOf(step) !== "passed");
418
+ return failing === void 0 ? steps : steps.slice(0, steps.indexOf(failing) + 1);
419
+ };
420
+ const trailLinesOf = (spans) => trailStepsOf(spans).flatMap((step) => [stepLineOf(step), ...decisionLinesOf(spans, step)]);
421
+ const layerHintOf = (spans) => {
422
+ const cell = cellSpansOf(spans).at(0);
423
+ return cell === void 0 ? "" : ` (cell ${cellNameOf(cell)})`;
424
+ };
425
+ const failingStepTextOf = (step) => `Failing step: ${keywordOf(step)} ${stepTextOf(step)} ${stepSiteOf(step)}`;
426
+ const noFailingStepLineOf = (steps, spans) => steps.length === 0 ? `Failing step: no step ran${layerHintOf(spans)}` : "Failing step: none of the steps failed";
427
+ const failingStepLineOf = (spans) => {
428
+ const steps = stepSpansOf(spans);
429
+ const failing = steps.find((step) => stateOf(step) !== "passed");
430
+ return failing === void 0 ? noFailingStepLineOf(steps, spans) : failingStepTextOf(failing);
431
+ };
432
+ const isFailedSpan = (span) => stateOf(span) === "failed";
433
+ const isUnfinishedCell = (span) => and(isCellSpan(span), stateOf(span) === "unfinished");
434
+ const spanSiteOf = (span) => knownSiteOf(attrOf(span, CODE_SITE)) ?? knownSiteOf(cellStackSiteOf(attrOf(span, CELL_STACKTRACE)));
435
+ const cellSiteOf = (spans) => {
436
+ const cell = spans.toReversed().find(isCellSpan);
437
+ return cell === void 0 ? void 0 : spanSiteOf(cell);
438
+ };
439
+ const unfinishedDecideSiteOf = (spans) => {
440
+ const unfinished = spans.toReversed().find(isUnfinishedCell);
441
+ return unfinished === void 0 ? void 0 : knownSiteOf(cellStackSiteOf(attrOf(unfinished, CELL_DECIDE_STACKTRACE)));
442
+ };
443
+ const decideSiteOf = (spans) => unfinishedDecideSiteOf(spans) ?? cellSiteOf(spans);
444
+ const failedSiteOf = (spans) => {
445
+ const failed = spans.toReversed().find(isFailedSpan);
446
+ return failed === void 0 ? void 0 : spanSiteOf(failed);
447
+ };
448
+ const fallbackSiteOf = (spans) => failedSiteOf(spans) ?? decideSiteOf(spans);
449
+ const fallbackRaisedAtLineOf = (spans) => {
450
+ const site = fallbackSiteOf(spans);
451
+ return site === void 0 ? void 0 : ` raised at ${site}`;
452
+ };
453
+ const raisedAtLineOf = (frame, spans) => frame === void 0 ? fallbackRaisedAtLineOf(spans) : ` raised at ${frameTextOf(frame)}`;
454
+ const chainNamedFrame = (frame, chosen) => isSameFrame(frame, chosen) ? "" : ` raised at ${frameTextOf(frame)}`;
455
+ const chainFrameTextOf = (frame, chosen) => frame === void 0 ? "" : chainNamedFrame(frame, chosen);
456
+ const chainLineOf = (layer, chosen) => ` ${summaryOf(layer)}${chainFrameTextOf(usableFrameOf(layer), chosen)}`;
457
+ const chainContinuation = (line) => ` ${line}`;
458
+ const isMessageBearing = (layer) => or(tagFieldOf(layer) !== void 0, isErrorValue(layer));
459
+ const messageOf = (layer) => messageFieldOf(layer) ?? "";
460
+ const messageTailLines = (layer) => isMessageBearing(layer) ? restLines(messageOf(layer)).map(chainContinuation) : [];
461
+ const chainDetailLines = (layer) => isObject(layer) ? messageTailLines(layer) : [];
462
+ const chainLayerLines = (layer, chosen) => [chainLineOf(layer, chosen), ...chainDetailLines(layer)];
463
+ const chainLinesOf = (layers, chosen) => layers.slice(1).flatMap((layer) => chainLayerLines(layer, chosen));
464
+ const quoted = (text) => `"${text.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"`;
465
+ const rerunReplayTextOf = (replay) => Option$1.getOrUndefined(Option$1.flatMap(Option$1.fromUndefinedOr(replay.seed), (seed) => Option$1.map(replayOfParts({
466
+ seed,
467
+ path: replay.path
468
+ }), replayTextOf)));
469
+ const replayPrefixText = (text) => text === void 0 ? "" : `CONFORMANCE_REPLAY="${text}" `;
470
+ const replayPrefixOf = (replay) => replayPrefixText(replay === void 0 ? void 0 : rerunReplayTextOf(replay));
471
+ const isCompleteIdentity = (identity) => and(identity.file.length > 0, identity.name.length > 0);
472
+ const filterPrefixOf = (identity) => identity.package.length === 0 ? "" : `pnpm --filter ${identity.package} exec `;
473
+ const rerunLineOf = (identity, replay) => isCompleteIdentity(identity) ? ` ${replayPrefixOf(replay)}${filterPrefixOf(identity)}vitest run ${identity.file} -t ` + quoted(identity.name) : void 0;
474
+ const rerunLinesOf = (identity, replay) => {
475
+ const line = rerunLineOf(identity, replay);
476
+ return line === void 0 ? [] : ["Rerun only this scenario:", line];
477
+ };
478
+ const baselineReplay = (replay) => and(replay.seed === void 0, replay.path.length > 0);
479
+ const replayOnBaseline = (replay) => replay === void 0 ? false : baselineReplay(replay);
480
+ const headMessageOf = (layers) => {
481
+ const entry = layers[0];
482
+ return isObject(entry) ? messageFieldOf(entry) : void 0;
483
+ };
484
+ const detailOf = (layers) => {
485
+ const message = headMessageOf(layers);
486
+ return message === void 0 ? [] : restLines(message);
487
+ };
488
+ const detailLinesOf = (lines) => lines.length === 0 ? [] : [...lines.map((line) => ` ${line}`), ""];
489
+ const scheduleLinesOf = (schedule) => schedule === void 0 ? [] : [
490
+ "",
491
+ `schedule: seed ${schedule.seed}`,
492
+ ""
493
+ ];
494
+ const recordPartsOf = (input, layers) => {
495
+ const chosen = chosenFrameOf(layers);
496
+ return {
497
+ headline: headlineOf(layers),
498
+ raisedAt: raisedAtLineOf(chosen, input.spans),
499
+ failingStep: failingStepLineOf(input.spans),
500
+ detail: detailOf(layers),
501
+ chain: chainLinesOf(layers, chosen),
502
+ trail: trailLinesOf(input.spans),
503
+ schedule: scheduleLinesOf(input.schedule),
504
+ rerun: rerunLinesOf(input.identity, input.replay)
505
+ };
506
+ };
507
+ const maybeLine = (line) => line === void 0 ? [] : [line];
508
+ const sectionLines = (header, lines) => lines.length === 0 ? [] : [
509
+ header,
510
+ ...lines,
511
+ ""
512
+ ];
513
+ const linesOf = (parts) => [
514
+ parts.headline,
515
+ ...maybeLine(parts.raisedAt),
516
+ parts.failingStep,
517
+ ...detailLinesOf(parts.detail),
518
+ "",
519
+ ...sectionLines("Cause chain:", parts.chain),
520
+ ...sectionLines("Steps and the decisions each caused:", parts.trail),
521
+ ...parts.schedule,
522
+ ...parts.rerun
523
+ ];
524
+ const breachIf = (holds, breach) => holds ? [breach] : [];
525
+ const r6Broken = (parts, input) => or(parts.rerun.length === 0, replayOnBaseline(input.replay));
526
+ const breachesOf = (parts, input, record) => [
527
+ ...breachIf(parts.headline.length === 0, "R1"),
528
+ ...breachIf(not(LOCATION.test(record)), "R2"),
529
+ ...breachIf(r6Broken(parts, input), "R6")
530
+ ];
531
+ const hasRoot = (root) => root !== void 0 && root.length > 0;
532
+ const relativize = (record, root) => hasRoot(root) ? record.replaceAll(`${root}/`, "") : record;
533
+ /**
534
+ * Renders the record Vitest prints for one spec failure, and the contract rules it breaks.
535
+ *
536
+ * Never throws: a `Cause` renders layer by layer, a thrown `Error` renders as one layer, and any other value
537
+ * renders as itself. The first location the record names is the raising frame — the first stack frame outside
538
+ * `node_modules` and outside the spec libraries' own `src/` and `dist/` — and when no layer has one, the
539
+ * innermost failed span's site stands in, or the innermost unfinished cell's decide site for a deadlock (KTD6).
540
+ *
541
+ * @internal
542
+ */
543
+ const renderFailureRecord = (input) => {
544
+ const layers = layersOf(input.failure);
545
+ const parts = recordPartsOf(input, layers);
546
+ const record = relativize(linesOf(parts).join("\n").trimEnd(), input.root);
547
+ return {
548
+ name: nameOf(layers),
549
+ record,
550
+ breaches: breachesOf(parts, input, record)
551
+ };
552
+ };
553
+ const RECORD = Symbol.for("@systemfsoftware/vitest/FailureRecord");
554
+ const DIFF_FIELDS = [
555
+ "actual",
556
+ "expected",
557
+ "showDiff",
558
+ "operator",
559
+ "diff"
560
+ ];
561
+ const ERROR_CAUSE_DEPTH = 8;
562
+ const isDiffLayer = (value) => fieldOf(value, "actual") !== void 0;
563
+ const marked = (error) => {
564
+ Object.defineProperty(error, RECORD, { value: true });
565
+ return error;
566
+ };
567
+ const recordSiteOf = (text) => LOCATION.exec(text)?.[0];
568
+ const withoutTag = (record) => {
569
+ const prefix = `${record.name}: `;
570
+ return record.record.startsWith(prefix) ? record.record.slice(prefix.length) : record.record;
571
+ };
572
+ const recordStackOf = (record, message) => {
573
+ const head = `${record.name}: ${message}`;
574
+ const site = recordSiteOf(record.record);
575
+ return site === void 0 ? head : `${head}\n at ${site}`;
576
+ };
577
+ const withStack = (error, record, message) => {
578
+ error.stack = recordStackOf(record, message);
579
+ return error;
580
+ };
581
+ const withName = (error, name) => {
582
+ error.name = name;
583
+ return error;
584
+ };
585
+ const reasonFieldOf = (reason) => fieldOf(reason, "error") ?? fieldOf(reason, "defect");
586
+ const firstReasonOf = (cause) => {
587
+ const reason = cause.reasons[0];
588
+ return reason === void 0 ? cause : reasonFieldOf(reason);
589
+ };
590
+ const payloadOf = (failure) => Cause.isCause(failure) ? firstReasonOf(failure) : failure;
591
+ const errorCauseChainOf = (value, depth) => depth <= 0 ? [] : [value, ...chainedCausesOf(value, depth)];
592
+ const chainedCausesOf = (value, depth) => {
593
+ const cause = causeFieldOf(value);
594
+ return cause === void 0 ? [] : errorCauseChainOf(cause, depth - 1);
595
+ };
596
+ const layerChainOf = (failure) => {
597
+ const first = payloadOf(failure);
598
+ return [first, ...chainedCausesOf(first, ERROR_CAUSE_DEPTH)];
599
+ };
600
+ const diffCarrierOf = (failure) => layerChainOf(failure).map(objectOrUndefined).filter(isObject).find(isDiffLayer);
601
+ const copyField = (error, carrier, field) => {
602
+ const value = fieldOf(carrier, field);
603
+ if (value === void 0) return;
604
+ Object.defineProperty(error, field, {
605
+ value,
606
+ enumerable: true,
607
+ configurable: true,
608
+ writable: true
609
+ });
610
+ };
611
+ const copyFields = (error, carrier) => {
612
+ for (const field of DIFF_FIELDS) copyField(error, carrier, field);
613
+ return error;
614
+ };
615
+ const copyDiffFields = (error, failure) => {
616
+ const carrier = diffCarrierOf(failure);
617
+ return carrier === void 0 ? error : copyFields(error, carrier);
618
+ };
619
+ /**
620
+ * The `Error` Vitest prints for one record (R2, R7, R8): its `name` is the record's failure tag, its `message` is
621
+ * the record, and its `stack` leads with that message — Vitest's JSON reporter hands a consumer `stack || message`,
622
+ * so the record has to ride there too — followed by the record's first location, so no `effect` or library frame
623
+ * stays. The tag is left out of the message because Vitest prints `name: message`: it would otherwise lead twice.
624
+ *
625
+ * A failure that carries a diff — Chai's `actual`, `expected`, `showDiff`, `operator` and Vitest's `diff` — has
626
+ * those fields copied from the innermost layer that holds them, because Vitest renders its Expected/Received
627
+ * block from the thrown error, not from the record text.
628
+ *
629
+ * @internal
630
+ */
631
+ const failureRecordError = (record) => {
632
+ const message = withoutTag(record);
633
+ return marked(withStack(withName(new Error(message), record.name), record, message));
634
+ };
635
+ const isRefusalFailure = (value) => Schema$1.is(FailureRecordRefused)(value);
636
+ /**
637
+ * The refusal thrown in a record's place (R10, KTD7): fixed prose naming each breach, the original failure as its
638
+ * `cause`, and the record that failure would have printed beneath it. The record rides in the stack because
639
+ * Vitest's JSON reporter hands a consumer `stack || message`, where a cause is invisible; the prose never carries
640
+ * record text and is never read back, so a refusal cannot recurse.
641
+ */
642
+ const refusalError = (failure, record) => {
643
+ const refusal = new FailureRecordRefused({
644
+ breaches: record.breaches,
645
+ cause: failure
646
+ });
647
+ refusal.stack = `${refusal.name}: ${refusal.message}\n${failureRecordError(record).stack ?? ""}`;
648
+ return refusal;
649
+ };
650
+ const printedError = (failure, record) => record.breaches.length > 0 ? refusalError(failure, record) : failureRecordError(record);
651
+ /** @internal */
652
+ const isFailureRecordError = (value) => isObject(value) && fieldOf(value, RECORD) === true;
653
+ /** @internal */
654
+ const throwFailureRecord = (input) => {
655
+ if (isRefusalFailure(input.failure)) throw input.failure;
656
+ const record = renderFailureRecord(input);
657
+ throw copyDiffFields(printedError(input.failure, record), input.failure);
658
+ };
659
+ const LEVEL_SEPARATOR = " > ";
660
+ const EMPTY_TEXT = "";
661
+ const textOrEmpty = (value) => isText(value) ? value : EMPTY_TEXT;
662
+ const firstNonEmptyText = (values) => textOrEmpty(values.find(isText));
663
+ const fileOf = (fullName) => textOrEmpty(fullName).split(LEVEL_SEPARATOR).at(0) ?? EMPTY_TEXT;
664
+ const identityOf = (task) => ({
665
+ package: providedPackage() ?? EMPTY_TEXT,
666
+ file: fileOf(task.fullName),
667
+ name: firstNonEmptyText([task.fullTestName, task.name])
668
+ });
669
+ const currentTask = () => TestRunner.getCurrentTest() ?? {};
670
+ /** @internal */
671
+ const testIdentityOf = (task) => identityOf(task ?? currentTask());
672
+ //#endregion
673
+ //#region src/internal/property/coverage.ts
674
+ /**
675
+ * @internal The R14 coverage classes: labelled input predicates, each with a minimum share of runs.
676
+ *
677
+ * A class fails only when QuickCheck's sequential test (`stdConfidence`) is confident its share is below
678
+ * the minimum, and is satisfied once the test is confident the share is at least 0.9 of the minimum
679
+ * (`TOLERANCE` at a certainty of 10^9). The tolerance is what makes the test terminate: a class sitting
680
+ * exactly at its minimum would otherwise draw forever.
681
+ */
682
+ const CERTAINTY = 10 ** 9;
683
+ const TOLERANCE = .9;
684
+ const FIRST_BATCH = 64;
685
+ const BATCH_CAP = 4096;
686
+ const DRAW_CAP = 1e5;
687
+ const FAILURE_HEAD = "coverage";
688
+ /** The certainty's two-sided tail probability: `alpha / 2` for `alpha = 1 / CERTAINTY`. */
689
+ const TAIL_PROBABILITY = 1 / (2 * CERTAINTY);
690
+ const C1 = -.007784894002430293;
691
+ const C2 = -.3223964580411365;
692
+ const C3 = -2.400758277161838;
693
+ const C4 = -2.549732539343734;
694
+ const C5 = 4.374664141464968;
695
+ const C6 = 2.938163982698783;
696
+ const D1 = .007784695709041462;
697
+ const D2 = .3224671290700398;
698
+ const D3 = 2.445134137142996;
699
+ const D4 = 3.754408661907416;
700
+ const TAIL_NUMERATOR = [
701
+ C1,
702
+ C2,
703
+ C3,
704
+ C4,
705
+ C5,
706
+ C6
707
+ ];
708
+ const TAIL_DENOMINATOR = [
709
+ D1,
710
+ D2,
711
+ D3,
712
+ D4
713
+ ];
714
+ /** Horner's rule over a coefficient list, highest power first. */
715
+ const poly = (coefficients, x) => coefficients.reduceRight((total, coefficient) => total * x + coefficient, 0);
716
+ const tailSpread = (p) => Math.sqrt(-2 * Math.log(p));
717
+ const tailInverse = (spread) => poly(TAIL_NUMERATOR, spread) / poly(TAIL_DENOMINATOR, spread);
718
+ /** The inverse standard-normal CDF at the tail probability the certainty asks for. */
719
+ const TAIL_Z = tailInverse(tailSpread(TAIL_PROBABILITY));
720
+ const wilson = (hits, runs, z) => {
721
+ const share = hits / runs;
722
+ const zz = z * z;
723
+ return (share + zz / (2 * runs) + z * Math.sqrt(share * (1 - share) / runs + zz / (4 * runs * runs))) / (1 + zz / runs);
724
+ };
725
+ /**
726
+ * Thrown when a coverage class is confidently below its minimum share of runs.
727
+ *
728
+ * @internal
729
+ */
730
+ var CoverageBelowMinimum = class extends Data.Error {};
731
+ const wilsonLower = (entry, runs) => wilson(entry.hits, runs, -TAIL_Z);
732
+ const wilsonUpper = (entry, runs) => wilson(entry.hits, runs, TAIL_Z);
733
+ const covered = (entry, runs) => wilsonLower(entry, runs) >= TOLERANCE * entry.minimum;
734
+ const uncovered = (entry, runs) => wilsonUpper(entry, runs) < entry.minimum;
735
+ const decided = (entry, runs) => covered(entry, runs) || uncovered(entry, runs);
736
+ const settled = (entry, runs) => runs === 0 ? false : decided(entry, runs);
737
+ const entriesOf = (classes) => Object.keys(classes).map((label) => entryAt(classes, label));
738
+ const entryAt = (classes, label) => [label, classOf(classes, label)];
739
+ const classOf = (classes, label) => classes[label] ?? {
740
+ hits: 0,
741
+ minimum: 0
742
+ };
743
+ const judgeOf = (classes, runs) => ({
744
+ classes: new Map(entriesOf(classes)),
745
+ runs
746
+ });
747
+ const openLabels = (judge) => [...judge.classes].filter(([, entry]) => !settled(entry, judge.runs)).map(([label]) => label);
748
+ const failedEntries = (judge) => [...judge.classes].filter(([, entry]) => uncovered(entry, judge.runs));
749
+ const describeShare = (hits, runs) => `${String(hits)}/${String(runs)}`;
750
+ const describeFailure = (label, entry, runs) => `${FAILURE_HEAD} ${label}: ${describeShare(entry.hits, runs)} of runs, below the required ${String(entry.minimum)}`;
751
+ const reportFailures = (judge) => failedEntries(judge).map(([label, entry]) => describeFailure(label, entry, judge.runs)).join("\n");
752
+ /** @internal */
753
+ const countHit = Function.dual(2, (classes, label) => {
754
+ const prior = classes.get(label);
755
+ if (prior !== void 0) classes.set(label, {
756
+ hits: prior.hits + 1,
757
+ minimum: prior.minimum
758
+ });
759
+ });
760
+ const countLabels = (classes, labels) => {
761
+ for (const label of labels) countHit(classes, label);
762
+ return classes;
763
+ };
764
+ const countDraws = (classes, drawn) => drawn.reduce(countLabels, new Map(classes));
765
+ const withDraws = (judge, drawn) => ({
766
+ classes: countDraws(judge.classes, drawn),
767
+ runs: judge.runs + drawn.length
768
+ });
769
+ const drawBatch = (judge, draw, batch) => withDraws(judge, draw.more(sizeOf(judge, batch)));
770
+ const sizeOf = (judge, batch) => Math.min(batch, DRAW_CAP - judge.runs);
771
+ const grown = (batch) => Math.min(batch * 2, BATCH_CAP);
772
+ const keepDrawing = (judge) => openLabels(judge).length > 0 && judge.runs < DRAW_CAP;
773
+ const toppedUp = (judge, draw, batch) => keepDrawing(judge) ? toppedUp(drawBatch(judge, draw, batch), draw, grown(batch)) : judge;
774
+ const reportOf$1 = (judge) => failedEntries(judge).length === 0 ? void 0 : reportFailures(judge);
775
+ /**
776
+ * Runs R14's sequential draw: tops up the undecided classes until every class is decided or the draw cap
777
+ * is reached, then reports the confidently under-covered classes, naming each label and its observed share.
778
+ *
779
+ * @internal
780
+ */
781
+ const judgeCoverage = (options) => reportOf$1(toppedUp(judgeOf(options.classes, options.runs), options.draw, FIRST_BATCH));
782
+ //#endregion
783
+ //#region src/internal/property/error.schema.ts
784
+ /**
785
+ * The generator's choice that refuted a property, as data: the seed and the shrink path fast-check recorded. The
786
+ * renderer reads it off the failure value instead of parsing the message (KTD5).
787
+ *
788
+ * @internal
789
+ */
790
+ const PropertyReplay = Schema$1.Struct({
791
+ seed: Schema$1.Finite,
792
+ path: Schema$1.Array(Schema$1.Finite)
793
+ });
794
+ /**
795
+ * A falsified property: the message the failure carries, and the generator's choice when the check result recorded
796
+ * one, so the rerun line can replay it (KTD5).
797
+ *
798
+ * @internal
799
+ */
800
+ var PropertyRefuted = class extends Schema$1.TaggedError()("PropertyRefuted", {
801
+ detail: Schema$1.String,
802
+ replay: Schema$1.optional(PropertyReplay)
803
+ }) {
804
+ get message() {
805
+ return this.detail;
806
+ }
807
+ };
808
+ /**
809
+ * Thrown at file end when no property in the file refuted a subject's constant impostor (R12).
810
+ *
811
+ * @internal
812
+ */
813
+ var VacuousProperty = class extends Schema$1.TaggedError()("VacuousProperty", { detail: Schema$1.String }) {
814
+ get message() {
815
+ return this.detail;
816
+ }
817
+ };
818
+ /**
819
+ * Thrown when a law kind is given a record `of`, which cannot be spread into its subject.
820
+ *
821
+ * @internal
822
+ */
823
+ var NonTupleOf = class extends Schema$1.TaggedError()("NonTupleOf", { detail: Schema$1.String }) {
824
+ get message() {
825
+ return this.detail;
826
+ }
827
+ };
828
+ //#endregion
829
+ //#region src/internal/property/impostor.ts
830
+ const SUBJECT_KEY = "the subject";
831
+ const NO_VALUE = "";
832
+ const isCallable = (value) => typeof value === "function";
833
+ const isCallableSubject = (target) => typeof target === "function";
834
+ const describeValue = (value) => isCallable(value) ? "a function" : String(value);
835
+ const describeEntry = (key, value) => `${key} always returned ${describeValue(value)}`;
836
+ const emptyState = () => ({ outputs: /* @__PURE__ */ new Map() });
837
+ const frozenAt = (state, key, compute) => state.outputs.has(key) ? state.outputs.get(key) : remember(state, key, compute());
838
+ const remember = (state, key, value) => {
839
+ state.outputs.set(key, value);
840
+ return value;
841
+ };
842
+ const callOutput = (state, fn, thisArg, args) => frozenAt(state, SUBJECT_KEY, () => Reflect.apply(fn, thisArg, args));
843
+ const memberWrapper = (state, key, fn) => (...values) => frozenAt(state, key, () => Reflect.apply(fn, void 0, values));
844
+ const memberWrapperOf = (state, fn, key) => fn === void 0 ? void 0 : memberWrapper(state, key, fn);
845
+ const appliedImpostor = (state, target, thisArg, args) => isCallableSubject(target) ? callOutput(state, target, thisArg, args) : void 0;
846
+ const memberImpostor = (state, target, key) => memberWrapperOf(state, target[key], key);
847
+ const readImpostor = (state, target, property) => isCallableSubject(target) ? Reflect.get(target, property, target) : memberRead(state, target, property);
848
+ const memberRead = (state, target, property) => typeof property === "string" ? memberImpostor(state, target, property) : void 0;
849
+ const impostorHandler = (state) => ({
850
+ apply: (target, thisArg, args) => appliedImpostor(state, target, thisArg, args),
851
+ get: (target, property) => readImpostor(state, target, property)
852
+ });
853
+ const describeFrozen = (state) => [...state.outputs].map(([key, value]) => describeEntry(key, value)).join("; ");
854
+ /**
855
+ * A constant impostor of `subject`: a function returns its first output forever, and so does each member
856
+ * of a record.
857
+ *
858
+ * @internal
859
+ */
860
+ const impostorOf = (subject) => {
861
+ const state = emptyState();
862
+ return {
863
+ impostor: new Proxy(subject, impostorHandler(state)),
864
+ frozen: () => describeFrozen(state)
865
+ };
866
+ };
867
+ /** @internal */
868
+ const subjectLabel = (subject) => isCallableSubject(subject) ? `a function of ${String(subject.length)} argument(s)` : `a record of ${Object.keys(subject).sort().join(", ")}`;
869
+ const judgeFor = (subject) => ({
870
+ label: subjectLabel(subject),
871
+ properties: [],
872
+ refuters: [],
873
+ frozen: NO_VALUE,
874
+ runs: 0
875
+ });
876
+ const trackProperty = (judge, property) => judge.properties.includes(property) ? judge : {
877
+ ...judge,
878
+ properties: [...judge.properties, property]
879
+ };
880
+ const trackRefuter = (judge, property) => judge.refuters.includes(property) ? judge : {
881
+ ...judge,
882
+ refuters: [...judge.refuters, property]
883
+ };
884
+ const trackVerdict = (judge, property, verdict) => {
885
+ const named = trackProperty(judge, property);
886
+ return verdict.refuted ? trackRefuter(named, property) : {
887
+ ...named,
888
+ frozen: verdict.frozen,
889
+ runs: verdict.runs
890
+ };
891
+ };
892
+ const recordJudge = (state, subject, property, verdict) => {
893
+ const prior = state.judges.get(subject) ?? judgeFor(subject);
894
+ state.judges.set(subject, trackVerdict(prior, property, verdict));
895
+ };
896
+ const isVacuous = (judge) => judge.refuters.length === 0;
897
+ const describeVacuous = (judge) => `${judge.properties.join(", ")}: no property in this file refuted the constant impostor of this subject (${judge.label}), so nothing here pins it down. It held for ${judge.runs} run(s) against a fake that ${judge.frozen === NO_VALUE ? "was never called" : judge.frozen}, whatever the input. Laws that only relate outputs to each other (additivity, idempotence, commutativity, round trips through the subject) hold for such constants. Pin the output to the input: compare against an independent model (\`subject(x)\` equals a straightforward reimplementation), or conjoin a base case (\`subject([one])\` equals its known value). Also check that the body calls the \`subject\` it was given, not the imported implementation.`;
898
+ const finaliseJudges = (state, onProblems) => {
899
+ const vacuous = [...state.judges.values()].filter(isVacuous).map(describeVacuous);
900
+ if (vacuous.length === 0) return;
901
+ throw onProblems(vacuous.join("\n\n"));
902
+ };
903
+ const ledgerOf = (state, onProblems) => ({
904
+ record: (subject, property, verdict) => recordJudge(state, subject, property, verdict),
905
+ finalise: () => finaliseJudges(state, onProblems)
906
+ });
907
+ /**
908
+ * Collects the impostor verdicts of every property in the file and decides, at file end, which subjects
909
+ * nothing refuted.
910
+ *
911
+ * @internal
912
+ */
913
+ const makeFileLedger = (onProblems) => ledgerOf({ judges: /* @__PURE__ */ new Map() }, onProblems);
914
+ //#endregion
915
+ //#region src/internal/property/kinds.ts
916
+ /**
917
+ * @internal The R13 law kinds: `model`, `metamorphic`, `roundTrip` and `invariant` are sugar over the
918
+ * gated property (R11/R12); `idempotent` and `deterministic` are declared exempt — they skip the impostor
919
+ * gate, are reported as exempt, and are the only exemptions.
920
+ *
921
+ * Each kind owns the comparison, so there is nowhere to write `return true`: the author hands over
922
+ * functions, and the kind relates their outputs with Effect's structural `Equal`.
923
+ */
924
+ /**
925
+ * The generated values as the argument list a law subject is called with.
926
+ *
927
+ * @internal
928
+ */
929
+ const spreadValues = (values) => Array.isArray(values) ? values : refuseRecordOf();
930
+ const refuseRecordOf = () => {
931
+ throw new NonTupleOf({ detail: "a law kind spreads the generated values into its subject, so `of` must be a tuple; a record `of` holds functions of the record, which only it.prop reaches" });
932
+ };
933
+ const call = (subject, values) => subject(...spreadValues(values));
934
+ const equalOutputs = (original, transformed) => Equal.equals(original, transformed);
935
+ /** @internal */
936
+ const modelHolds = (oracle) => (subject, values) => Equal.equals(call(subject, values), call(oracle, values));
937
+ /** @internal */
938
+ const metamorphicHolds = (relation) => (subject, values) => (relation.relate ?? equalOutputs)(call(subject, values), call(subject, relation.transform(...spreadValues(values))));
939
+ /** @internal */
940
+ const roundTripHolds = (decode) => (subject, values) => Equal.equals(decode(call(subject, values)), values);
941
+ /** @internal */
942
+ const invariantHolds = (holds) => (subject, values) => holds(call(subject, values), ...spreadValues(values));
943
+ const firstOf = (values) => values[0];
944
+ const sameTwice = (subject, value) => value === void 0 ? false : Equal.equals(subject(subject(value)), subject(value));
945
+ /** @internal */
946
+ const idempotentHolds = () => (subject, values) => sameTwice(subject, firstOf(spreadValues(values)));
947
+ /** @internal */
948
+ const deterministicHolds = () => (subject, values) => Equal.equals(call(subject, values), call(subject, values));
949
+ //#endregion
950
+ //#region src/internal/property/replay.schema.ts
951
+ /**
952
+ * The token effect's falsification runner records, as the Schema that decodes it (KTD5). One falsification's
953
+ * coordinates ride in a JSON array: a leading `0` naming a numeric seed, the seed text, the attempt, the size,
954
+ * the shrink path, and the failure tag.
955
+ *
956
+ * @since 4.0.0
957
+ */
958
+ /** @internal */
959
+ const ReplayToken = Schema$1.fromJsonString(Schema$1.Tuple([
960
+ Schema$1.Finite,
961
+ Schema$1.Union([Schema$1.Finite, Schema$1.String]),
962
+ Schema$1.Finite,
963
+ Schema$1.Finite,
964
+ Schema$1.Array(Schema$1.Finite),
965
+ Schema$1.String
966
+ ]));
967
+ //#endregion
968
+ //#region src/internal/property/replay.ts
969
+ /**
970
+ * The replay value a property counterexample carries (KTD5): the seed and the shrink path the generator recorded,
971
+ * read off the failure value and out of the check result as data. Nothing here reads a failure message.
972
+ *
973
+ * The token `effect`'s falsification runner writes is decoded here — never hand-parsed — into the seed and path R6
974
+ * prints.
975
+ *
976
+ * @since 4.0.0
977
+ */
978
+ /** The token's leading kind that names a numeric seed. */
979
+ const NUMERIC_SEED = 0;
980
+ const numericSeedOf = (token) => token[0] === NUMERIC_SEED ? Number(token[1]) : void 0;
981
+ const replayOf = (token) => Option$1.map(Option$1.fromNullishOr(numericSeedOf(token)), (seed) => ({
982
+ seed,
983
+ path: token[4]
984
+ }));
985
+ /** @internal */
986
+ const replayOfToken = (replay) => Option$1.getOrUndefined(Option$1.flatMap(Schema$1.decodeOption(ReplayToken)(replay), replayOf));
987
+ const refutationOf = (value) => Schema$1.is(PropertyRefuted)(value) ? value : void 0;
988
+ /** @internal */
989
+ const replayOfFailure = (value) => Option$1.getOrUndefined(Option$1.flatMap(Option$1.fromNullishOr(refutationOf(value)), (failure) => Option$1.fromNullishOr(failure.replay)));
990
+ //#endregion
991
+ //#region src/internal/property/engine.ts
992
+ /**
993
+ * @internal The lawful property engine (R11-R15): a property names the function under test, takes a budget
994
+ * that merges its own fields over the configured default over `runs: 100`, accepts only a literal boolean
995
+ * verdict (or an `Effect` of one), judges coverage classes with QuickCheck's sequential test, and defers the
996
+ * constant-impostor verdict to the end of the file.
997
+ *
998
+ * `of` accepts what upstream accepts — a tuple or record of Schemas or Arbitraries (KTD10) — and `holds`
999
+ * receives the generated values exactly as drawn, typed by the gens that produced them.
1000
+ */
1001
+ const REWRITE = "it.prop(name, { of, subject, runs }, holds)";
1002
+ const DEFAULT_RUNS = 100;
1003
+ const isPositiveInteger = (runs) => Number.isInteger(runs) && runs > 0;
1004
+ const describeRuns = (runs) => Number.isInteger(runs) ? `${String(runs)}` : "a non-integer";
1005
+ const invalidPropertyBudget = (name, runs) => `${name}: pass a positive integer \`runs\`; received ${describeRuns(runs)}. Write ${REWRITE}.`;
1006
+ const invalidProvidedBudget = (runs) => `the configured property budget (${checkDefaultsKey}) supplies \`runs\`: ${describeRuns(runs)}; it must be a positive integer.`;
1007
+ const requirePositiveRuns = (message, runs) => {
1008
+ if (isInvalidRuns(runs)) throw new InvalidBudget({ detail: message(runs) });
1009
+ };
1010
+ const isInvalidRuns = (runs) => runs !== void 0 && isPositiveInteger(runs) === false;
1011
+ /** The property's own explicit fields, a property-level `runs` outranking the same field in `arbitrary`. */
1012
+ const explicitOptions = (spec) => spec.runs === void 0 ? { ...spec.arbitrary } : {
1013
+ ...spec.arbitrary,
1014
+ runs: spec.runs
1015
+ };
1016
+ const mergedOptions = (provided, explicit) => ({
1017
+ runs: DEFAULT_RUNS,
1018
+ ...provided,
1019
+ ...explicit
1020
+ });
1021
+ const resolvedRuns = (options) => options.runs ?? DEFAULT_RUNS;
1022
+ /**
1023
+ * The effective check options: the property's own fields over the configured default over `runs: 100`,
1024
+ * merged field by field so a property that sets only `runs` still inherits the configured size and caps.
1025
+ */
1026
+ const resolveBudget = (name, spec, provided) => {
1027
+ const explicit = explicitOptions(spec);
1028
+ requirePositiveRuns((runs) => invalidPropertyBudget(name, runs), explicit.runs);
1029
+ requirePositiveRuns(invalidProvidedBudget, provided?.runs);
1030
+ const options = mergedOptions(provided, explicit);
1031
+ return {
1032
+ runs: resolvedRuns(options),
1033
+ options
1034
+ };
1035
+ };
1036
+ const toArbitrary = (input) => Schema$1.isSchema(input) ? Arbitrary.schema(input) : input;
1037
+ const assignArbitrary = (built, of, key) => {
1038
+ const input = of[key];
1039
+ if (input !== void 0) built[key] = toArbitrary(input);
1040
+ };
1041
+ const recordArbitraries = (of) => {
1042
+ const built = {};
1043
+ for (const key of Object.keys(of)) assignArbitrary(built, of, key);
1044
+ return built;
1045
+ };
1046
+ const isTupleOf = (of) => Array.isArray(of);
1047
+ function arbitraryOf(of) {
1048
+ return isTupleOf(of) ? Arbitrary.all(of.map(toArbitrary)) : Arbitrary.all(recordArbitraries(of));
1049
+ }
1050
+ const minimumOf = (entry) => entry[1];
1051
+ const seedClasses = (entries) => {
1052
+ const classes = /* @__PURE__ */ new Map();
1053
+ for (const [label, entry] of entries) classes.set(label, {
1054
+ hits: 0,
1055
+ minimum: minimumOf(entry)
1056
+ });
1057
+ return classes;
1058
+ };
1059
+ const satisfiedLabels = (entries, values) => entries.filter(([, entry]) => entry[0](...spreadValues(values))).map(([label]) => label);
1060
+ const observeRun = (classes, counter, entries, values) => {
1061
+ counter.runs = counter.runs + 1;
1062
+ for (const label of satisfiedLabels(entries, values)) countHit(classes, label);
1063
+ };
1064
+ const drawFor = (entries, arbitrary) => ({ more: (count) => Effect$1.runSync(Arbitrary.sampleEffect(arbitrary, { count }).pipe(Effect$1.orDie)).map((values) => satisfiedLabels(entries, values)) });
1065
+ const noCoverage = () => ({
1066
+ observe: () => void 0,
1067
+ judge: () => void 0
1068
+ });
1069
+ const liveCoverage = (cover, arbitrary) => {
1070
+ const entries = Object.entries(cover);
1071
+ const classes = seedClasses(entries);
1072
+ const counter = { runs: 0 };
1073
+ return {
1074
+ observe: (values) => observeRun(classes, counter, entries, values),
1075
+ judge: () => judgeCoverage({
1076
+ classes: Object.fromEntries(classes),
1077
+ runs: counter.runs,
1078
+ draw: drawFor(entries, arbitrary)
1079
+ })
1080
+ };
1081
+ };
1082
+ const makeCoverage = (cover, arbitrary) => cover === void 0 ? noCoverage() : liveCoverage(cover, arbitrary);
1083
+ const describeVerdict = (verdict) => Effect$1.isEffect(verdict) ? "an Effect, which this lane never runs" : `a ${typeof verdict}`;
1084
+ const nonBoolean = (verdict, violations) => {
1085
+ violations.add(describeVerdict(verdict));
1086
+ return true;
1087
+ };
1088
+ const literalVerdict = (verdict, violations) => typeof verdict === "boolean" ? verdict : nonBoolean(verdict, violations);
1089
+ const effectVerdict = (lane, verdict, violations) => lane === "sync" ? Effect$1.succeed(nonBoolean(verdict, violations)) : Effect$1.map(verdict, (value) => literalVerdict(value, violations));
1090
+ const verdictFor = (run, values, violations) => {
1091
+ run.observe(values);
1092
+ const verdict = run.holds(run.subject, values);
1093
+ return Effect$1.isEffect(verdict) ? effectVerdict(run.lane, verdict, violations) : Effect$1.succeed(literalVerdict(verdict, violations));
1094
+ };
1095
+ const tolerateInterruption = (cause) => Cause.hasInterrupts(cause) ? Effect$1.interrupt : Effect$1.fail(cause);
1096
+ const guardedVerdict = (run, violations) => (values) => Effect$1.catchCause(Effect$1.suspend(() => verdictFor(run, values, violations)), tolerateInterruption);
1097
+ const violationMessage = (name, violations) => `${name}: the property returned no boolean; it returned ${violations.join(", ")}. A property must return a literal boolean verdict — asserting with expect(), or returning an Option, Result or object, is not a verdict; write ${REWRITE}.`;
1098
+ const runCheck = (run) => {
1099
+ const violations = /* @__PURE__ */ new Set();
1100
+ return Arbitrary.checkEffect(run.arbitrary, guardedVerdict(run, violations), run.options).pipe(Effect$1.map((result) => ({
1101
+ violations,
1102
+ result
1103
+ })));
1104
+ };
1105
+ const reportOf = (checked) => Arbitrary.formatCheckFailure(checked.result);
1106
+ const violationOf = (name, checked) => checked.violations.size === 0 ? void 0 : violationMessage(name, [...checked.violations]);
1107
+ const isRefuted = (checked) => checked.violations.size > 0 || reportOf(checked) !== void 0;
1108
+ const dieWithSite = (error, site) => Effect$1.die(withRaisingFrame(error, site));
1109
+ const dieViolation = (detail, site) => dieWithSite(new NonBooleanVerdict({ detail }), site);
1110
+ const dieReported = (name, report, replay, site) => {
1111
+ const detail = `${name}: the property was falsified. ${report}`;
1112
+ return dieWithSite(new PropertyRefuted(replay === void 0 ? { detail } : {
1113
+ detail,
1114
+ replay
1115
+ }), site);
1116
+ };
1117
+ const dieUncovered = (failure, site) => dieWithSite(new CoverageBelowMinimum({ message: failure }), site);
1118
+ const impostorHolds = (holds, impostor) => (_subject, values) => holds(impostor.impostor, values);
1119
+ const recordImpostor = (run, budget, impostor, checked) => {
1120
+ const verdict = {
1121
+ refuted: isRefuted(checked),
1122
+ frozen: impostor.frozen(),
1123
+ runs: budget.runs
1124
+ };
1125
+ gatedLedger.record(run.subject, run.name, verdict);
1126
+ };
1127
+ const impostorRun = (run, budget) => {
1128
+ const impostor = impostorOf(run.subject);
1129
+ const retry = {
1130
+ ...run,
1131
+ holds: impostorHolds(run.holds, impostor),
1132
+ observe: noObserve
1133
+ };
1134
+ return runCheck(retry).pipe(Effect$1.map((checked) => recordImpostor(retry, budget, impostor, checked)));
1135
+ };
1136
+ const noObserve = () => void 0;
1137
+ const gateRun = (run, budget, gate) => gate ? impostorRun(run, budget) : Effect$1.void;
1138
+ const finishPassed = (run, budget, coverage, gate) => {
1139
+ const failure = coverage.judge();
1140
+ return failure === void 0 ? gateRun(run, budget, gate) : dieUncovered(`${run.name}: ${failure}`, run.site);
1141
+ };
1142
+ const falsifiedOf = (result) => "replay" in result ? result : void 0;
1143
+ const replayOfChecked = (checked) => Option$1.getOrUndefined(Option$1.flatMap(Option$1.fromNullishOr(falsifiedOf(checked.result)), (falsified) => Option$1.fromNullishOr(replayOfToken(falsified.replay))));
1144
+ const settleReport = (run, budget, coverage, gate, report, replay) => report === void 0 ? finishPassed(run, budget, coverage, gate) : dieReported(run.name, report, replay, run.site);
1145
+ const settle = (registration, run, budget, coverage, checked) => {
1146
+ const violation = violationOf(registration.name, checked);
1147
+ return violation === void 0 ? settleReport(run, budget, coverage, registration.gate, reportOf(checked), replayOfChecked(checked)) : dieViolation(violation, registration.site);
1148
+ };
1149
+ const checkOf = (registration, arbitrary, budget, observe) => ({
1150
+ name: registration.name,
1151
+ lane: registration.lane,
1152
+ subject: registration.spec.subject,
1153
+ holds: registration.holds,
1154
+ arbitrary,
1155
+ observe,
1156
+ options: budget.options,
1157
+ site: registration.site
1158
+ });
1159
+ const program = (registration) => Effect$1.gen(function* () {
1160
+ const budget = resolveBudget(registration.name, registration.spec, providedCheckDefaults());
1161
+ const arbitrary = arbitraryOf(registration.spec.of);
1162
+ const coverage = makeCoverage(registration.spec.cover, arbitrary);
1163
+ const run = checkOf(registration, arbitrary, budget, coverage.observe);
1164
+ const checked = yield* runCheck(run);
1165
+ yield* settle(registration, run, budget, coverage, checked);
1166
+ });
1167
+ const programOf = (registration) => () => registration.runtime.provide(program(registration));
1168
+ const selfModelMessage = (name) => `${name}: the model is the subject itself; a model law must compare against an independent oracle.`;
1169
+ const gatedLedger = makeFileLedger((message) => new VacuousProperty({ detail: message }));
1170
+ V.afterAll(() => {
1171
+ gatedLedger.finalise();
1172
+ });
1173
+ const registeredName = (name, kind, exempt) => exempt ? `${name} [exempt: ${kind}]` : name;
1174
+ const isSelfModel = (subject, oracle) => Object.is(subject, oracle);
1175
+ /**
1176
+ * The property surface over one runtime: `prop`, `effectProp`, and the R13 law kinds routed through the gate.
1177
+ *
1178
+ * @internal
1179
+ */
1180
+ const makeProperty = (runtime) => {
1181
+ const body = (name, spec, holds, lane, gate) => {
1182
+ const registration = {
1183
+ runtime,
1184
+ name,
1185
+ spec,
1186
+ holds,
1187
+ lane,
1188
+ gate,
1189
+ site: callFrame()
1190
+ };
1191
+ runtime.register(name, programOf(registration));
1192
+ };
1193
+ const refuseSelfModel = (name) => {
1194
+ const site = callFrame();
1195
+ runtime.register(name, () => dieWithSite(new VacuousProperty({ detail: selfModelMessage(name) }), site));
1196
+ };
1197
+ const gated = (name, spec, holds, kind, exempt) => body(registeredName(name, kind, exempt), spec, holds, "sync", exempt === false);
1198
+ const model = (name, spec, oracle) => isSelfModel(spec.subject, oracle) ? refuseSelfModel(name) : gated(name, spec, modelHolds(oracle), "model", false);
1199
+ const idempotent = (name, spec) => gated(name, spec, idempotentHolds(), "idempotent", true);
1200
+ const deterministic = (name, spec) => gated(name, spec, deterministicHolds(), "deterministic", true);
1201
+ return {
1202
+ prop: (name, spec, holds) => body(name, spec, holds, "sync", true),
1203
+ effectProp: (name, spec, holds) => body(name, spec, holds, "effect", true),
1204
+ law: {
1205
+ model,
1206
+ metamorphic: (name, spec, relation) => gated(name, spec, metamorphicHolds(relation), "metamorphic", false),
1207
+ roundTrip: (name, spec, decode) => gated(name, spec, roundTripHolds(decode), "roundTrip", false),
1208
+ invariant: (name, spec, holds) => gated(name, spec, invariantHolds(holds), "invariant", false),
1209
+ idempotent,
1210
+ deterministic
1211
+ }
1212
+ };
1213
+ };
1214
+ //#endregion
1215
+ //#region src/internal/span-recorder.ts
1216
+ /**
1217
+ * The run recorder: an in-memory {@link Tracer.Tracer} that keeps every span one run opened (KTD2). Nothing is
1218
+ * exported from a recorder — its spans are read in process by the failure renderer and dropped with the run.
1219
+ *
1220
+ * A recorder is per run: the kernel's baseline, each seeded run and each replay each get their own, and so does
1221
+ * every program the runner drives. Installing it is the caller's job, through `Effect.withTracer`.
1222
+ *
1223
+ * @since 4.0.0
1224
+ */
1225
+ /** @internal */
1226
+ const createSpanRecorder = () => {
1227
+ const spans = [];
1228
+ return {
1229
+ tracer: Tracer.make({ span(options) {
1230
+ const span = new Tracer.NativeSpan(options);
1231
+ spans.push(span);
1232
+ return span;
1233
+ } }),
1234
+ spans
1235
+ };
1236
+ };
1237
+ //#endregion
1238
+ //#region src/internal/recorded-run.ts
1239
+ /**
1240
+ * The in-process way to run a program the way the runner runs a lane and read back the record its failure rendered
1241
+ * (R11, KTD10): a corpus drives a fixture through this instead of spawning Vitest, and without importing `src/`.
1242
+ *
1243
+ * The run gets its own check ledger — its own `expect` — so a corpus fixture's `Then` asserts on the check it
1244
+ * answered with, not on the check the corpus test itself already spent, and its own recorder, so the record is
1245
+ * rendered from exactly the spans the run opened.
1246
+ *
1247
+ * @since 4.0.0
1248
+ */
1249
+ const renderRecord = (failure, spans, identity) => renderFailureRecord({
1250
+ failure,
1251
+ spans,
1252
+ identity,
1253
+ replay: replayOfFailure(failure),
1254
+ root: providedRoot()
1255
+ });
1256
+ const outcomeOf = (exit, recorder, identity) => Exit.isSuccess(exit) ? void 0 : renderRecord(Cause.squash(exit.cause), recorder.spans, identity);
1257
+ const provideRun = (effect, ledger, ctx) => effect.pipe(Effect$1.provideService(Asserted, ledger.asserted), Effect$1.provideService(VitestTestContext, ctx));
1258
+ const runRecorded = (ctx, program) => {
1259
+ const ledger = makeLedger(ctx);
1260
+ const recorder = createSpanRecorder();
1261
+ return Effect$1.runPromiseExit(provideRun(program(checksFor(ledger)), ledger, ctx).pipe(Effect$1.withTracer(recorder.tracer))).then((exit) => outcomeOf(exit, recorder, testIdentityOf()));
1262
+ };
1263
+ /**
1264
+ * Runs one program as the runner runs a lane, with a fresh ledger and its own recorder, and resolves with the
1265
+ * record its failure rendered — or `undefined` when it passed.
1266
+ *
1267
+ * @internal
1268
+ */
1269
+ const recordOfRun = (program) => {
1270
+ const task = TestRunner.getCurrentTest();
1271
+ if (task === void 0) return Promise.resolve(void 0);
1272
+ return runRecorded(task.context, program);
1273
+ };
1274
+ const capturingRuntime = (programs) => ({
1275
+ register: (_name, program) => {
1276
+ programs.push(program);
1277
+ },
1278
+ provide: (effect) => effect
1279
+ });
1280
+ const capturedProgram = (programs) => Option$1.getOrThrow(Option$1.fromNullishOr(programs[0]));
1281
+ /**
1282
+ * Runs one property the way the runner runs `it.prop`, with a fresh ledger and its own recorder, and resolves with
1283
+ * the record its falsification rendered — or `undefined` when it held.
1284
+ *
1285
+ * @internal
1286
+ */
1287
+ const recordOfProperty = (input) => {
1288
+ const programs = [];
1289
+ makeProperty(capturingRuntime(programs)).prop(input.name, input.spec, input.holds);
1290
+ return recordOfRun(capturedProgram(programs));
1291
+ };
1292
+ //#endregion
1293
+ export { ReplayFromText as _, replayOfFailure as a, summaryOf as c, providedRoot as d, InvalidBudget as f, Replay as g, Slop as h, makeProperty as i, testIdentityOf as l, NonBooleanVerdict as m, recordOfRun as n, isFailureRecordError as o, LeakedState as p, createSpanRecorder as r, renderFailureRecord as s, recordOfProperty as t, throwFailureRecord as u, replayOfText as v };