@typeonce/effect-machine 0.37.0 → 0.38.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 (28) hide show
  1. package/README.md +20 -0
  2. package/dist/internal/testing/machine/arbitrary.d.ts +4 -2
  3. package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -1
  4. package/dist/internal/testing/machine/arbitrary.js +5 -4
  5. package/dist/internal/testing/machine/arbitrary.js.map +1 -1
  6. package/dist/internal/testing/machine/finiteModel.d.ts +2 -2
  7. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  8. package/dist/internal/testing/machine/finiteModel.js +39 -33
  9. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  10. package/dist/internal/testing/machine/referenceModel.d.ts.map +1 -1
  11. package/dist/internal/testing/machine/referenceModel.js +6 -5
  12. package/dist/internal/testing/machine/referenceModel.js.map +1 -1
  13. package/dist/internal/testing/machine/runtime.d.ts +8 -9
  14. package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
  15. package/dist/internal/testing/machine/runtime.js +16 -14
  16. package/dist/internal/testing/machine/runtime.js.map +1 -1
  17. package/dist/internal/testing/machine/verification.js +7 -7
  18. package/dist/internal/testing/machine/verification.js.map +1 -1
  19. package/dist/testing/MachineTest.d.ts +6 -6
  20. package/dist/testing/MachineTest.d.ts.map +1 -1
  21. package/dist/testing/MachineTest.js +2 -2
  22. package/package.json +4 -4
  23. package/src/internal/testing/machine/arbitrary.ts +11 -4
  24. package/src/internal/testing/machine/finiteModel.ts +87 -59
  25. package/src/internal/testing/machine/referenceModel.ts +6 -5
  26. package/src/internal/testing/machine/runtime.ts +24 -22
  27. package/src/internal/testing/machine/verification.ts +13 -13
  28. package/src/testing/MachineTest.ts +6 -6
@@ -11,12 +11,14 @@ import * as Duration from "effect/Duration"
11
11
  import * as Effect from "effect/Effect"
12
12
  import * as Inspectable from "effect/Inspectable"
13
13
  import * as Queue from "effect/Queue"
14
+ import * as Schema from "effect/Schema"
14
15
  import * as Stream from "effect/Stream"
15
- import { FastCheck, TestClock } from "effect/testing"
16
+ import { TestClock } from "effect/testing"
17
+ import * as Arbitrary from "effect/unstable/arbitrary/Arbitrary"
16
18
  import * as Machine from "../../../Machine.js"
17
19
  import type { CausalRuntimeEvidence, Probe, ProbeStep, RuntimeInvariant } from "../../../testing/MachineTest.js"
18
20
  import * as Protocol from "../../machine/protocol.js"
19
- import { type SchemaArbitraryReport, toArbitraryWithReport } from "./arbitrary.js"
21
+ import { chooseArbitrary, type SchemaArbitraryReport, toArbitraryWithReport } from "./arbitrary.js"
20
22
  import { assertRuntimeInvariants, type RuntimeInvariantError } from "./runtimeInvariant.js"
21
23
 
22
24
  type AnyMachine = Machine.Machine.Any
@@ -1188,7 +1190,7 @@ export const runRuntimeCommands: typeof runEnqueuedCommands = runEnqueuedCommand
1188
1190
  * inspection, assertion, and the next command. Use `probe.await.until` only
1189
1191
  * for later asynchronous work such as timer, invoke, or child delivery.
1190
1192
  * Processing failures are attributed to the exact submitted command and retain
1191
- * the successfully checked prefix for FastCheck shrinking and replay.
1193
+ * the successfully checked prefix for Arbitrary shrinking and replay.
1192
1194
  *
1193
1195
  * Use `runEnqueuedCommands` instead when the behavior under test intentionally
1194
1196
  * depends on burst enqueueing or outstanding mailbox work.
@@ -1460,12 +1462,12 @@ export const verifyCausalCommands = <M extends AnyMachine, Error, Output>(
1460
1462
  export interface RuntimeCommandsOptions<M extends AnyMachine> {
1461
1463
  readonly minCommands?: number
1462
1464
  readonly maxCommands?: number
1463
- readonly eventArbitrary?: FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>
1464
- readonly advanceArbitrary?: FastCheck.Arbitrary<Duration.Input>
1465
+ readonly eventArbitrary?: Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>
1466
+ readonly advanceArbitrary?: Arbitrary.Arbitrary<Duration.Input>
1465
1467
  readonly includeAdvance?: boolean
1466
1468
  readonly includeStop?: boolean
1467
1469
  readonly includeCheckpoint?: boolean
1468
- readonly additionalCommands?: ReadonlyArray<FastCheck.Arbitrary<RuntimeCommand<Machine.Machine.InputEvent<M>>>>
1470
+ readonly additionalCommands?: ReadonlyArray<Arbitrary.Arbitrary<RuntimeCommand<Machine.Machine.InputEvent<M>>>>
1469
1471
  }
1470
1472
 
1471
1473
  /**
@@ -1489,7 +1491,7 @@ export interface RuntimeCommandsDiagnostics {
1489
1491
  * @since 0.4.0
1490
1492
  */
1491
1493
  export interface RuntimeCommands<M extends AnyMachine> {
1492
- readonly arbitrary: FastCheck.Arbitrary<ReadonlyArray<RuntimeCommand<Machine.Machine.InputEvent<M>>>>
1494
+ readonly arbitrary: Arbitrary.Arbitrary<ReadonlyArray<RuntimeCommand<Machine.Machine.InputEvent<M>>>>
1493
1495
  readonly diagnostics: RuntimeCommandsDiagnostics
1494
1496
  }
1495
1497
 
@@ -1503,9 +1505,8 @@ const validateCommandLength = (name: "minCommands" | "maxCommands", value: numbe
1503
1505
  * Derives a shrinkable command sequence from public event schemas and explicit
1504
1506
  * clock/stop/checkpoint command choices.
1505
1507
  *
1506
- * This deliberately returns ordinary Effect FastCheck arbitraries instead of
1507
- * adapting the runner through `asyncModelRun`: the latter requires Promise
1508
- * callbacks and would erase Effect error and service channels.
1508
+ * Returns native Arbitrary values for use with `Arbitrary.checkEffect` or
1509
+ * Effect property tests, preserving typed errors and required services.
1509
1510
  *
1510
1511
  * @category constructors
1511
1512
  * @since 0.4.0
@@ -1527,33 +1528,34 @@ export const runtimeCommands = <M extends AnyMachine>(
1527
1528
  ? Protocol.inputEventSchemas(machine).map((schema) => {
1528
1529
  const derived = toArbitraryWithReport(schema)
1529
1530
  reports.push(derived.report)
1530
- return derived.value as FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>
1531
+ return derived.value as Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>
1531
1532
  })
1532
1533
  : []
1533
1534
  const eventArbitrary = options.eventArbitrary ?? (eventArbitraries.length === 0
1534
1535
  ? undefined
1535
- : FastCheck.oneof(
1536
+ : chooseArbitrary(
1536
1537
  ...eventArbitraries as [
1537
- FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>,
1538
- ...Array<FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>>
1538
+ Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>,
1539
+ ...Array<Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>>
1539
1540
  ]
1540
1541
  ))
1541
- const commandArbitraries: Array<FastCheck.Arbitrary<RuntimeCommand<Machine.Machine.InputEvent<M>>>> = []
1542
- if (eventArbitrary !== undefined) commandArbitraries.push(eventArbitrary.map(sendCommand))
1542
+ const commandArbitraries: Array<Arbitrary.Arbitrary<RuntimeCommand<Machine.Machine.InputEvent<M>>>> = []
1543
+ if (eventArbitrary !== undefined) commandArbitraries.push(eventArbitrary.pipe(Arbitrary.map(sendCommand)))
1543
1544
 
1544
1545
  if (options.includeAdvance !== false) {
1545
- const advanceArbitrary = options.advanceArbitrary ?? FastCheck.nat({ max: 60_000 })
1546
- commandArbitraries.push(advanceArbitrary.map(advanceCommand))
1546
+ const advanceArbitrary = options.advanceArbitrary ??
1547
+ Arbitrary.schema(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 60_000 })))
1548
+ commandArbitraries.push(advanceArbitrary.pipe(Arbitrary.map(advanceCommand)))
1547
1549
  }
1548
- if (options.includeStop !== false) commandArbitraries.push(FastCheck.constant(stopCommand()))
1549
- if (options.includeCheckpoint !== false) commandArbitraries.push(FastCheck.constant(checkpointCommand()))
1550
+ if (options.includeStop !== false) commandArbitraries.push(Arbitrary.Constant(stopCommand()))
1551
+ if (options.includeCheckpoint !== false) commandArbitraries.push(Arbitrary.Constant(checkpointCommand()))
1550
1552
  commandArbitraries.push(...options.additionalCommands ?? [])
1551
1553
  if (commandArbitraries.length === 0) {
1552
1554
  if (minCommands > 0) {
1553
1555
  throw new Error("MachineTest.runtimeCommands cannot generate a non-empty command sequence without commands")
1554
1556
  }
1555
1557
  return {
1556
- arbitrary: FastCheck.constant([]),
1558
+ arbitrary: Arbitrary.Constant([]),
1557
1559
  diagnostics: {
1558
1560
  events: options.eventArbitrary !== undefined ? "override" : eventArbitraries.length === 0 ? "none" : "schema",
1559
1561
  schemaReports: reports,
@@ -1565,7 +1567,7 @@ export const runtimeCommands = <M extends AnyMachine>(
1565
1567
  }
1566
1568
 
1567
1569
  return {
1568
- arbitrary: FastCheck.array(FastCheck.oneof(...commandArbitraries), {
1570
+ arbitrary: Arbitrary.array(chooseArbitrary(commandArbitraries[0]!, ...commandArbitraries.slice(1)), {
1569
1571
  minLength: minCommands,
1570
1572
  maxLength: maxCommands
1571
1573
  }),
@@ -9,7 +9,7 @@ import * as Effect from "effect/Effect"
9
9
  import * as Graph from "effect/Graph"
10
10
  import * as Schema from "effect/Schema"
11
11
  import * as SchemaAST from "effect/SchemaAST"
12
- import { FastCheck } from "effect/testing"
12
+ import * as Arbitrary from "effect/unstable/arbitrary/Arbitrary"
13
13
  import * as Machine from "../../../Machine.js"
14
14
  import type {
15
15
  Coverage,
@@ -32,7 +32,7 @@ import type {
32
32
  VerifyOptions
33
33
  } from "../../../testing/MachineTest.js"
34
34
  import * as Protocol from "../../machine/protocol.js"
35
- import { toArbitraryWithReport } from "./arbitrary.js"
35
+ import { chooseArbitrary, toArbitraryWithReport } from "./arbitrary.js"
36
36
  import type { FiniteModel } from "./finiteModel.js"
37
37
  import * as ReferenceModel from "./referenceModel.js"
38
38
  import { rawConfigurationPaths } from "./trace.js"
@@ -82,17 +82,17 @@ export const scenarios = <M extends AnyMachine>(
82
82
  index,
83
83
  report: derived.report
84
84
  })
85
- return derived.value as FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>
85
+ return derived.value as Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>
86
86
  })
87
87
  : []
88
88
 
89
89
  const eventsArbitrary = options.eventsArbitrary ?? (eventArbitraries.length === 0
90
- ? FastCheck.constant<ReadonlyArray<Machine.Machine.InputEvent<M>>>([])
91
- : FastCheck.array(
92
- FastCheck.oneof(
90
+ ? Arbitrary.Constant<ReadonlyArray<Machine.Machine.InputEvent<M>>>([])
91
+ : Arbitrary.array(
92
+ chooseArbitrary(
93
93
  ...eventArbitraries as [
94
- FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>,
95
- ...Array<FastCheck.Arbitrary<Machine.Machine.InputEvent<M>>>
94
+ Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>,
95
+ ...Array<Arbitrary.Arbitrary<Machine.Machine.InputEvent<M>>>
96
96
  ]
97
97
  ),
98
98
  { minLength: minEvents, maxLength: maxEvents }
@@ -103,7 +103,7 @@ export const scenarios = <M extends AnyMachine>(
103
103
  throw new Error("MachineTest.scenarios cannot override input for a machine without an input schema")
104
104
  }
105
105
  return {
106
- arbitrary: eventsArbitrary.map((events) => ({ events }) as Scenario<M>),
106
+ arbitrary: eventsArbitrary.pipe(Arbitrary.map((events) => ({ events }) as Scenario<M>)),
107
107
  diagnostics: {
108
108
  input: "none",
109
109
  events: options.eventsArbitrary !== undefined ? "override" : eventArbitraries.length === 0 ? "empty" : "schema",
@@ -112,7 +112,7 @@ export const scenarios = <M extends AnyMachine>(
112
112
  }
113
113
  }
114
114
 
115
- let inputArbitrary: FastCheck.Arbitrary<InputValue<M>>
115
+ let inputArbitrary: Arbitrary.Arbitrary<InputValue<M>>
116
116
  if (options.inputArbitrary !== undefined) {
117
117
  inputArbitrary = options.inputArbitrary
118
118
  } else {
@@ -122,16 +122,16 @@ export const scenarios = <M extends AnyMachine>(
122
122
  index: undefined,
123
123
  report: derived.report
124
124
  })
125
- inputArbitrary = derived.value as FastCheck.Arbitrary<InputValue<M>>
125
+ inputArbitrary = derived.value as Arbitrary.Arbitrary<InputValue<M>>
126
126
  }
127
127
 
128
128
  return {
129
- arbitrary: FastCheck.tuple(inputArbitrary, eventsArbitrary).map(([input, events]) =>
129
+ arbitrary: Arbitrary.all([inputArbitrary, eventsArbitrary]).pipe(Arbitrary.map(([input, events]) =>
130
130
  ({
131
131
  input,
132
132
  events
133
133
  }) as Scenario<M>
134
- ),
134
+ )),
135
135
  diagnostics: {
136
136
  input: options.inputArbitrary !== undefined ? "override" : "schema",
137
137
  events: options.eventsArbitrary !== undefined ? "override" : eventArbitraries.length === 0 ? "empty" : "schema",
@@ -7,7 +7,7 @@
7
7
  import type * as Effect from "effect/Effect"
8
8
  import type * as Graph from "effect/Graph"
9
9
  import type * as Schema from "effect/Schema"
10
- import type { FastCheck } from "effect/testing"
10
+ import type * as Arbitrary from "effect/unstable/arbitrary/Arbitrary"
11
11
  import type { EnsureExecutable } from "../internal/machine/readiness.js"
12
12
  import type { SchemaArbitraryReport } from "../internal/testing/machine/arbitrary.js"
13
13
  import * as ExplorationImpl from "../internal/testing/machine/exploration.js"
@@ -179,13 +179,13 @@ export type ScenarioOptions<M extends AnyMachine> =
179
179
  & {
180
180
  readonly minEvents?: number
181
181
  readonly maxEvents?: number
182
- readonly eventsArbitrary?: FastCheck.Arbitrary<ReadonlyArray<Machine.Machine.InputEvent<M>>>
182
+ readonly eventsArbitrary?: Arbitrary.Arbitrary<ReadonlyArray<Machine.Machine.InputEvent<M>>>
183
183
  }
184
184
  & (Machine.Machine.InputSchema<M> extends typeof Schema.Void ? {
185
185
  readonly inputArbitrary?: never
186
186
  }
187
187
  : {
188
- readonly inputArbitrary?: FastCheck.Arbitrary<InputValue<M>>
188
+ readonly inputArbitrary?: Arbitrary.Arbitrary<InputValue<M>>
189
189
  })
190
190
 
191
191
  /**
@@ -219,14 +219,14 @@ export interface ScenarioDiagnostics {
219
219
  * @since 0.4.0
220
220
  */
221
221
  export interface Scenarios<M extends AnyMachine> {
222
- readonly arbitrary: FastCheck.Arbitrary<Scenario<M>>
222
+ readonly arbitrary: Arbitrary.Arbitrary<Scenario<M>>
223
223
  readonly diagnostics: ScenarioDiagnostics
224
224
  }
225
225
 
226
226
  /**
227
227
  * Derives valid machine inputs and public events from their schemas.
228
228
  *
229
- * Unsupported schema derivations fail immediately through `Schema.toArbitrary`.
229
+ * Unsupported schema derivations fail immediately through `Arbitrary.schema`.
230
230
  * Non-fatal derivation warnings are returned instead of being hidden.
231
231
  *
232
232
  * **Example**
@@ -1216,7 +1216,7 @@ export { InvariantError } from "../internal/testing/machine/invariant.js"
1216
1216
  *
1217
1217
  * Every invariant and matching observation is evaluated so one failure
1218
1218
  * contains all relevant evidence. Combine this with `scenarios` and `run` in
1219
- * an Effect property test to retain FastCheck shrinking.
1219
+ * an Effect property test to retain Arbitrary shrinking.
1220
1220
  *
1221
1221
  * @category verification
1222
1222
  * @since 0.4.0