@typeonce/effect-machine 0.47.1 → 0.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +374 -22
- package/CLAUDE.md +374 -22
- package/README.md +56 -7
- package/ai-docs/src/10_modeling/01_create-a-machine.ts +3 -3
- package/ai-docs/src/10_modeling/index.md +64 -17
- package/ai-docs/src/20_root-api/index.md +2 -2
- package/ai-docs/src/35_cluster/index.md +213 -0
- package/ai-docs/src/37_new-host/index.md +90 -0
- package/dist/LocalMachine.d.ts +417 -0
- package/dist/LocalMachine.d.ts.map +1 -0
- package/dist/LocalMachine.js +193 -0
- package/dist/LocalMachine.js.map +1 -0
- package/dist/Machine.d.ts +1120 -812
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +195 -186
- package/dist/Machine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +8 -10
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +7 -6
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/capability.d.ts +101 -0
- package/dist/internal/machine/capability.d.ts.map +1 -0
- package/dist/internal/machine/capability.js +70 -0
- package/dist/internal/machine/capability.js.map +1 -0
- package/dist/internal/machine/{invocationDefinition.d.ts → capturedInvocation.d.ts} +11 -11
- package/dist/internal/machine/capturedInvocation.d.ts.map +1 -0
- package/dist/internal/machine/{invocationDefinition.js → capturedInvocation.js} +2 -2
- package/dist/internal/machine/capturedInvocation.js.map +1 -0
- package/dist/internal/machine/child.d.ts +14 -0
- package/dist/internal/machine/child.d.ts.map +1 -0
- package/dist/internal/machine/child.js +19 -0
- package/dist/internal/machine/child.js.map +1 -0
- package/dist/internal/machine/childRegistry.d.ts +0 -2
- package/dist/internal/machine/childRegistry.d.ts.map +1 -1
- package/dist/internal/machine/childRegistry.js +2 -2
- package/dist/internal/machine/childRegistry.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts +19 -4
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +263 -110
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/clusterChild.d.ts +66 -0
- package/dist/internal/machine/clusterChild.d.ts.map +1 -0
- package/dist/internal/machine/clusterChild.js +105 -0
- package/dist/internal/machine/clusterChild.js.map +1 -0
- package/dist/internal/machine/clusterFailure.d.ts +14 -0
- package/dist/internal/machine/clusterFailure.d.ts.map +1 -0
- package/dist/internal/machine/clusterFailure.js +44 -0
- package/dist/internal/machine/clusterFailure.js.map +1 -0
- package/dist/internal/machine/clusterInstance.d.ts +194 -0
- package/dist/internal/machine/clusterInstance.d.ts.map +1 -0
- package/dist/internal/machine/clusterInstance.js +1076 -0
- package/dist/internal/machine/clusterInstance.js.map +1 -0
- package/dist/internal/machine/clusterKeepAlive.d.ts +47 -0
- package/dist/internal/machine/clusterKeepAlive.d.ts.map +1 -0
- package/dist/internal/machine/clusterKeepAlive.js +72 -0
- package/dist/internal/machine/clusterKeepAlive.js.map +1 -0
- package/dist/internal/machine/clusterProgress.d.ts +73 -0
- package/dist/internal/machine/clusterProgress.d.ts.map +1 -0
- package/dist/internal/machine/clusterProgress.js +116 -0
- package/dist/internal/machine/clusterProgress.js.map +1 -0
- package/dist/internal/machine/clusterProtocol.d.ts +37 -4
- package/dist/internal/machine/clusterProtocol.d.ts.map +1 -1
- package/dist/internal/machine/clusterProtocol.js +18 -4
- package/dist/internal/machine/clusterProtocol.js.map +1 -1
- package/dist/internal/machine/clusterProxy.d.ts +46 -0
- package/dist/internal/machine/clusterProxy.d.ts.map +1 -0
- package/dist/internal/machine/clusterProxy.js +150 -0
- package/dist/internal/machine/clusterProxy.js.map +1 -0
- package/dist/internal/machine/clusterRead.d.ts +61 -0
- package/dist/internal/machine/clusterRead.d.ts.map +1 -0
- package/dist/internal/machine/clusterRead.js +108 -0
- package/dist/internal/machine/clusterRead.js.map +1 -0
- package/dist/internal/machine/clusterSqlStorage.d.ts +16 -0
- package/dist/internal/machine/clusterSqlStorage.d.ts.map +1 -0
- package/dist/internal/machine/clusterSqlStorage.js +138 -0
- package/dist/internal/machine/clusterSqlStorage.js.map +1 -0
- package/dist/internal/machine/clusterStorageCheck.d.ts +19 -0
- package/dist/internal/machine/clusterStorageCheck.d.ts.map +1 -0
- package/dist/internal/machine/clusterStorageCheck.js +186 -0
- package/dist/internal/machine/clusterStorageCheck.js.map +1 -0
- package/dist/internal/machine/clusterTarget.d.ts +74 -0
- package/dist/internal/machine/clusterTarget.d.ts.map +1 -0
- package/dist/internal/machine/clusterTarget.js +81 -0
- package/dist/internal/machine/clusterTarget.js.map +1 -0
- package/dist/internal/machine/clusterTimer.d.ts +21 -0
- package/dist/internal/machine/clusterTimer.d.ts.map +1 -0
- package/dist/internal/machine/clusterTimer.js +50 -0
- package/dist/internal/machine/clusterTimer.js.map +1 -0
- package/dist/internal/machine/clusterWake.d.ts +61 -0
- package/dist/internal/machine/clusterWake.d.ts.map +1 -0
- package/dist/internal/machine/clusterWake.js +81 -0
- package/dist/internal/machine/clusterWake.js.map +1 -0
- package/dist/internal/machine/clusterWork.d.ts +130 -0
- package/dist/internal/machine/clusterWork.d.ts.map +1 -0
- package/dist/internal/machine/clusterWork.js +191 -0
- package/dist/internal/machine/clusterWork.js.map +1 -0
- package/dist/internal/machine/command.d.ts +4 -4
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts +8 -6
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +1 -5
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +0 -13
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +0 -151
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +11 -2
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/errors.js +11 -2
- package/dist/internal/machine/errors.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +45 -3
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +328 -191
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +6 -6
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/inspectionRuntime.d.ts +1 -1
- package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -1
- package/dist/internal/machine/invocationChanges.d.ts +60 -0
- package/dist/internal/machine/invocationChanges.d.ts.map +1 -0
- package/dist/internal/machine/invocationChanges.js +54 -0
- package/dist/internal/machine/invocationChanges.js.map +1 -0
- package/dist/internal/machine/{activities.d.ts → invocationDefinitions.d.ts} +8 -8
- package/dist/internal/machine/invocationDefinitions.d.ts.map +1 -0
- package/dist/internal/machine/{activities.js → invocationDefinitions.js} +5 -5
- package/dist/internal/machine/invocationDefinitions.js.map +1 -0
- package/dist/internal/machine/invocationEvent.d.ts +16 -7
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +26 -12
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/invocationOutcome.d.ts +89 -0
- package/dist/internal/machine/invocationOutcome.d.ts.map +1 -0
- package/dist/internal/machine/invocationOutcome.js +76 -0
- package/dist/internal/machine/invocationOutcome.js.map +1 -0
- package/dist/internal/machine/invocationResolution.d.ts +137 -0
- package/dist/internal/machine/invocationResolution.d.ts.map +1 -0
- package/dist/internal/machine/invocationResolution.js +150 -0
- package/dist/internal/machine/invocationResolution.js.map +1 -0
- package/dist/internal/machine/logicScope.d.ts +24 -0
- package/dist/internal/machine/logicScope.d.ts.map +1 -0
- package/dist/internal/machine/logicScope.js +33 -0
- package/dist/internal/machine/logicScope.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +17 -23
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +24 -40
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/observation.d.ts +3 -0
- package/dist/internal/machine/observation.d.ts.map +1 -1
- package/dist/internal/machine/observation.js +56 -2
- package/dist/internal/machine/observation.js.map +1 -1
- package/dist/internal/machine/plannedSnapshot.d.ts.map +1 -1
- package/dist/internal/machine/plannedSnapshot.js +11 -20
- package/dist/internal/machine/plannedSnapshot.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +36 -23
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +15 -8
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +17 -9
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +43 -503
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +1 -1
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +48 -10
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +20 -16
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +93 -88
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -1
- package/dist/internal/machine/runtimeCompiled.js +359 -120
- package/dist/internal/machine/runtimeCompiled.js.map +1 -1
- package/dist/internal/machine/runtimeProtocol.d.ts +151 -82
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
- package/dist/internal/machine/runtimeProtocol.js +236 -219
- package/dist/internal/machine/runtimeProtocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +0 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +0 -1
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/step.d.ts +486 -0
- package/dist/internal/machine/step.d.ts.map +1 -0
- package/dist/internal/machine/step.js +957 -0
- package/dist/internal/machine/step.js.map +1 -0
- package/dist/internal/machine/stepHost.d.ts +33 -0
- package/dist/internal/machine/stepHost.d.ts.map +1 -0
- package/dist/internal/machine/stepHost.js +501 -0
- package/dist/internal/machine/stepHost.js.map +1 -0
- package/dist/internal/machine/symbols.d.ts +2 -11
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -2
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/transition.d.ts +7 -7
- package/dist/internal/machine/transition.d.ts.map +1 -1
- package/dist/internal/testing/machine/check.d.ts.map +1 -1
- package/dist/internal/testing/machine/check.js +217 -25
- package/dist/internal/testing/machine/check.js.map +1 -1
- package/dist/internal/testing/machine/exploration.d.ts +19 -2
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js +14 -3
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/format.js.map +1 -1
- package/dist/internal/testing/machine/probe.d.ts.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +2 -2
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +10 -3
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/trace.d.ts +38 -3
- package/dist/internal/testing/machine/trace.d.ts.map +1 -1
- package/dist/internal/testing/machine/trace.js +180 -33
- package/dist/internal/testing/machine/trace.js.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +9 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/internal/testing/machine/work.d.ts +47 -0
- package/dist/internal/testing/machine/work.d.ts.map +1 -0
- package/dist/internal/testing/machine/work.js +74 -0
- package/dist/internal/testing/machine/work.js.map +1 -0
- package/dist/testing/MachineTest.d.ts +253 -37
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +81 -9
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +1071 -41
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +441 -12
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachineProxy.d.ts +257 -0
- package/dist/unstable/cluster/ClusterMachineProxy.d.ts.map +1 -0
- package/dist/unstable/cluster/ClusterMachineProxy.js +73 -0
- package/dist/unstable/cluster/ClusterMachineProxy.js.map +1 -0
- package/dist/unstable/cluster/SqlMachineStorage.d.ts +125 -0
- package/dist/unstable/cluster/SqlMachineStorage.d.ts.map +1 -0
- package/dist/unstable/cluster/SqlMachineStorage.js +62 -0
- package/dist/unstable/cluster/SqlMachineStorage.js.map +1 -0
- package/dist/unstable/cluster/index.d.ts +13 -0
- package/dist/unstable/cluster/index.d.ts.map +1 -1
- package/dist/unstable/cluster/index.js +13 -0
- package/dist/unstable/cluster/index.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +21 -26
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +5 -3
- package/src/LocalMachine.ts +611 -0
- package/src/Machine.ts +1379 -1334
- package/src/index.ts +1 -0
- package/src/internal/machine/atom.ts +20 -49
- package/src/internal/machine/capability.ts +123 -0
- package/src/internal/machine/{invocationDefinition.ts → capturedInvocation.ts} +13 -13
- package/src/internal/machine/child.ts +25 -0
- package/src/internal/machine/childRegistry.ts +1 -4
- package/src/internal/machine/cluster.ts +420 -205
- package/src/internal/machine/clusterChild.ts +117 -0
- package/src/internal/machine/clusterFailure.ts +53 -0
- package/src/internal/machine/clusterInstance.ts +1779 -0
- package/src/internal/machine/clusterKeepAlive.ts +93 -0
- package/src/internal/machine/clusterProgress.ts +159 -0
- package/src/internal/machine/clusterProtocol.ts +46 -4
- package/src/internal/machine/clusterProxy.ts +233 -0
- package/src/internal/machine/clusterRead.ts +207 -0
- package/src/internal/machine/clusterSqlStorage.ts +181 -0
- package/src/internal/machine/clusterStorageCheck.ts +274 -0
- package/src/internal/machine/clusterTarget.ts +154 -0
- package/src/internal/machine/clusterTimer.ts +58 -0
- package/src/internal/machine/clusterWake.ts +100 -0
- package/src/internal/machine/clusterWork.ts +269 -0
- package/src/internal/machine/command.ts +4 -4
- package/src/internal/machine/commandRuntime.ts +12 -24
- package/src/internal/machine/configuration.ts +0 -181
- package/src/internal/machine/errors.ts +11 -2
- package/src/internal/machine/executionPlan.ts +493 -263
- package/src/internal/machine/implementation.ts +6 -6
- package/src/internal/machine/inspectionRuntime.ts +1 -1
- package/src/internal/machine/invocationChanges.ts +89 -0
- package/src/internal/machine/{activities.ts → invocationDefinitions.ts} +10 -10
- package/src/internal/machine/invocationEvent.ts +35 -12
- package/src/internal/machine/invocationOutcome.ts +145 -0
- package/src/internal/machine/invocationResolution.ts +307 -0
- package/src/internal/machine/logicScope.ts +47 -0
- package/src/internal/machine/machine.ts +35 -100
- package/src/internal/machine/observation.ts +67 -2
- package/src/internal/machine/plannedSnapshot.ts +17 -20
- package/src/internal/machine/planner.ts +75 -99
- package/src/internal/machine/process.ts +78 -722
- package/src/internal/machine/protocol.ts +70 -26
- package/src/internal/machine/runtime.ts +198 -195
- package/src/internal/machine/runtimeCompiled.ts +496 -171
- package/src/internal/machine/runtimeProtocol.ts +416 -305
- package/src/internal/machine/stateDefinition.ts +0 -5
- package/src/internal/machine/step.ts +1518 -0
- package/src/internal/machine/stepHost.ts +634 -0
- package/src/internal/machine/symbols.ts +3 -14
- package/src/internal/machine/transition.ts +11 -11
- package/src/internal/testing/machine/check.ts +240 -36
- package/src/internal/testing/machine/exploration.ts +42 -3
- package/src/internal/testing/machine/format.ts +1 -1
- package/src/internal/testing/machine/probe.ts +2 -1
- package/src/internal/testing/machine/runtime.ts +15 -5
- package/src/internal/testing/machine/trace.ts +261 -41
- package/src/internal/testing/machine/transitionCoverage.ts +1 -1
- package/src/internal/testing/machine/verification.ts +11 -5
- package/src/internal/testing/machine/work.ts +101 -0
- package/src/testing/MachineTest.ts +268 -44
- package/src/unstable/cluster/ClusterMachine.ts +1183 -59
- package/src/unstable/cluster/ClusterMachineProxy.ts +372 -0
- package/src/unstable/cluster/SqlMachineStorage.ts +136 -0
- package/src/unstable/cluster/index.ts +15 -0
- package/src/unstable/reactivity/AtomMachine.ts +27 -88
- package/dist/internal/machine/activities.d.ts.map +0 -1
- package/dist/internal/machine/activities.js.map +0 -1
- package/dist/internal/machine/invocation.d.ts +0 -33
- package/dist/internal/machine/invocation.d.ts.map +0 -1
- package/dist/internal/machine/invocation.js +0 -220
- package/dist/internal/machine/invocation.js.map +0 -1
- package/dist/internal/machine/invocationDefinition.d.ts.map +0 -1
- package/dist/internal/machine/invocationDefinition.js.map +0 -1
- package/dist/internal/machine/requirements.d.ts +0 -4
- package/dist/internal/machine/requirements.d.ts.map +0 -1
- package/dist/internal/machine/requirements.js +0 -2
- package/dist/internal/machine/requirements.js.map +0 -1
- package/dist/internal/machine/runtimeGeneric.d.ts +0 -3
- package/dist/internal/machine/runtimeGeneric.d.ts.map +0 -1
- package/dist/internal/machine/runtimeGeneric.js +0 -465
- package/dist/internal/machine/runtimeGeneric.js.map +0 -1
- package/src/internal/machine/invocation.ts +0 -376
- package/src/internal/machine/requirements.ts +0 -11
- package/src/internal/machine/runtimeGeneric.ts +0 -797
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Commands, Machine } from "../../Machine.js"
|
|
2
2
|
|
|
3
3
|
/** Captured callbacks shared by definition construction and both planners. */
|
|
4
|
-
export type TransitionHandler<States extends Machine.StateSchemas,
|
|
4
|
+
export type TransitionHandler<States extends Machine.StateSchemas, Context> = (
|
|
5
5
|
context: Context,
|
|
6
|
-
enqueue:
|
|
7
|
-
) => Machine.HandlerResult<States
|
|
6
|
+
enqueue: Commands<any, any>
|
|
7
|
+
) => Machine.HandlerResult<States> | Machine.Declined
|
|
8
8
|
|
|
9
|
-
export type TransitionEvaluator<States extends Machine.StateSchemas,
|
|
9
|
+
export type TransitionEvaluator<States extends Machine.StateSchemas, Context> = (
|
|
10
10
|
context: Context,
|
|
11
|
-
enqueue:
|
|
11
|
+
enqueue: Commands<any, any>
|
|
12
12
|
) => {
|
|
13
|
-
readonly result: Machine.HandlerResult<States
|
|
13
|
+
readonly result: Machine.HandlerResult<States> | Machine.Declined
|
|
14
14
|
readonly branchIndex: number
|
|
15
15
|
readonly branchKey: string | undefined
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export type EventTransition<States extends Machine.StateSchemas,
|
|
19
|
-
| TransitionHandler<States,
|
|
18
|
+
export type EventTransition<States extends Machine.StateSchemas, Context> =
|
|
19
|
+
| TransitionHandler<States, Context>
|
|
20
20
|
| {
|
|
21
21
|
readonly reenter?: boolean
|
|
22
22
|
readonly declinable?: boolean
|
|
23
23
|
readonly targets?: ReadonlyArray<string>
|
|
24
|
-
readonly transition: TransitionHandler<States,
|
|
25
|
-
readonly evaluate?: TransitionEvaluator<States,
|
|
24
|
+
readonly transition: TransitionHandler<States, Context>
|
|
25
|
+
readonly evaluate?: TransitionEvaluator<States, Context>
|
|
26
26
|
}
|
|
@@ -18,21 +18,27 @@ import type {
|
|
|
18
18
|
CheckOptions,
|
|
19
19
|
CheckReplay,
|
|
20
20
|
CheckReport,
|
|
21
|
-
EventPlan,
|
|
22
21
|
ExplorationEdge,
|
|
23
22
|
ExplorationNode,
|
|
23
|
+
ExplorationStateContext,
|
|
24
24
|
InitialPlan,
|
|
25
25
|
RunFailure,
|
|
26
|
+
RunningWork,
|
|
26
27
|
RunServices,
|
|
27
28
|
Trace,
|
|
28
|
-
TraceStep
|
|
29
|
+
TraceStep,
|
|
30
|
+
WorkOutcome
|
|
29
31
|
} from "../../../testing/MachineTest.js"
|
|
32
|
+
import * as CapturedInvocation from "../../machine/capturedInvocation.js"
|
|
33
|
+
import * as Configuration from "../../machine/configuration.js"
|
|
30
34
|
import * as Protocol from "../../machine/protocol.js"
|
|
31
35
|
import type { EnsureExecutable } from "../../machine/readiness.js"
|
|
32
|
-
import {
|
|
36
|
+
import { type ExploredMachineFailure, exploreWith } from "./exploration.js"
|
|
33
37
|
import { formatValue } from "./format.js"
|
|
34
38
|
import { InvariantError } from "./invariant.js"
|
|
39
|
+
import { planEntry } from "./trace.js"
|
|
35
40
|
import { VerificationError, verify } from "./verification.js"
|
|
41
|
+
import * as Work from "./work.js"
|
|
36
42
|
|
|
37
43
|
type AnyMachine = Machine.Machine.Any
|
|
38
44
|
|
|
@@ -198,6 +204,115 @@ const planEvidence = (plan: {
|
|
|
198
204
|
const statePaths = (step: { readonly afterConfiguration: ReadonlyArray<string> }): string =>
|
|
199
205
|
step.afterConfiguration.filter((path) => path !== "").join(", ")
|
|
200
206
|
|
|
207
|
+
const label = (event: unknown): string =>
|
|
208
|
+
Work.isWorkOutcome(event) ? `${event.kind} ${event.id}` : String((event as { readonly _tag: PropertyKey })._tag)
|
|
209
|
+
|
|
210
|
+
const channelKey = (path: string, id: string, outcome: string): string => JSON.stringify([path, id, outcome])
|
|
211
|
+
|
|
212
|
+
// Limits for work whose results exploration cannot take, and so for states
|
|
213
|
+
// that only those results may lead to.
|
|
214
|
+
const hidingLimits: ReadonlyArray<CheckExplorationLimit> = ["effectsWithoutOutcomes", "streams", "logic", "children"]
|
|
215
|
+
|
|
216
|
+
interface SuppliedOutcomes {
|
|
217
|
+
readonly done: ReadonlyArray<unknown>
|
|
218
|
+
readonly failure: ReadonlyArray<unknown>
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** The names of the Effect sources that some state of `machine` invokes. */
|
|
222
|
+
const effectSources = (machine: AnyMachine): ReadonlySet<string> => {
|
|
223
|
+
const names = new Set<string>()
|
|
224
|
+
for (const path of machine.stateNodes.byPath.keys()) {
|
|
225
|
+
for (const definition of CapturedInvocation.list(Configuration.getStateConfigByPath(machine, path)?.invoke)) {
|
|
226
|
+
if ("effect" in definition && definition.sourceName !== undefined) names.add(definition.sourceName)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return names
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Validates the caller's outcomes against the Effect sources the machine
|
|
234
|
+
* invokes. A name that matches none is a finding: its values would never be
|
|
235
|
+
* tried. `undefined` means no outcomes were supplied.
|
|
236
|
+
*/
|
|
237
|
+
const suppliedOutcomes = (
|
|
238
|
+
machine: AnyMachine,
|
|
239
|
+
outcomes: unknown,
|
|
240
|
+
findings: Array<CheckFinding>
|
|
241
|
+
): ReadonlyMap<string, SuppliedOutcomes> | undefined => {
|
|
242
|
+
if (outcomes === undefined) return undefined
|
|
243
|
+
const supplied = new Map<string, SuppliedOutcomes>()
|
|
244
|
+
if (typeof outcomes !== "object" || outcomes === null) {
|
|
245
|
+
findings.push({
|
|
246
|
+
law: "outcomes.invalid",
|
|
247
|
+
severity: "error",
|
|
248
|
+
source: "",
|
|
249
|
+
message: "Outcomes must be a record keyed by Effect source name."
|
|
250
|
+
})
|
|
251
|
+
return supplied
|
|
252
|
+
}
|
|
253
|
+
const invoked = effectSources(machine)
|
|
254
|
+
for (const [source, entry] of Object.entries(outcomes)) {
|
|
255
|
+
if (entry === undefined) continue
|
|
256
|
+
if (!invoked.has(source)) {
|
|
257
|
+
findings.push({
|
|
258
|
+
law: "outcomes.invalid",
|
|
259
|
+
severity: "error",
|
|
260
|
+
source,
|
|
261
|
+
message: `Outcomes are supplied for "${source}", but no state invokes an Effect source with that name. ` +
|
|
262
|
+
`Fix the name, or remove the entry.`
|
|
263
|
+
})
|
|
264
|
+
continue
|
|
265
|
+
}
|
|
266
|
+
const done: unknown = (entry as { readonly done?: unknown }).done ?? []
|
|
267
|
+
const failure: unknown = (entry as { readonly failure?: unknown }).failure ?? []
|
|
268
|
+
if (!Array.isArray(done) || !Array.isArray(failure)) {
|
|
269
|
+
findings.push({
|
|
270
|
+
law: "outcomes.invalid",
|
|
271
|
+
severity: "error",
|
|
272
|
+
source,
|
|
273
|
+
message: `Outcomes for "${source}" must list values in "done" and "failure" arrays.`
|
|
274
|
+
})
|
|
275
|
+
continue
|
|
276
|
+
}
|
|
277
|
+
supplied.set(source, { done, failure })
|
|
278
|
+
}
|
|
279
|
+
return supplied
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Reports each supplied result that failed the machine once, at the first
|
|
284
|
+
* place breadth-first exploration reached it, so its replay is the shortest.
|
|
285
|
+
*/
|
|
286
|
+
const reportMachineFailures = <M extends AnyMachine>(
|
|
287
|
+
failures: ReadonlyArray<ExploredMachineFailure<M>>,
|
|
288
|
+
findings: Array<CheckFinding>,
|
|
289
|
+
replay: (events: ReadonlyArray<unknown>) => CheckReplay
|
|
290
|
+
): void => {
|
|
291
|
+
const seen = new Set<string>()
|
|
292
|
+
for (const failure of failures) {
|
|
293
|
+
const outcome = failure.event as WorkOutcome
|
|
294
|
+
const work = Work.find(failure.trace.work, outcome)
|
|
295
|
+
const key = channelKey(outcome.path, outcome.id, outcome.kind)
|
|
296
|
+
if (seen.has(key)) continue
|
|
297
|
+
seen.add(key)
|
|
298
|
+
const state = outcome.path === "" ? "root" : outcome.path
|
|
299
|
+
const typed = failure.cause.reasons.find(Cause.isFailReason)
|
|
300
|
+
findings.push({
|
|
301
|
+
law: "outcome.failsMachine",
|
|
302
|
+
severity: "error",
|
|
303
|
+
source: work?.source,
|
|
304
|
+
replay: replay([...failure.trace.scenario.events, outcome]),
|
|
305
|
+
message: outcome.kind === "Failure"
|
|
306
|
+
? `A failure of "${outcome.id}" in "${state}" has no onFailure, so the machine fails with ${
|
|
307
|
+
causeMessage(typed === undefined ? Cause.pretty(failure.cause) : typed.error)
|
|
308
|
+
}. Handle it with onFailure.`
|
|
309
|
+
: `A result of "${outcome.id}" in "${state}" has no onDone, so the machine fails: ${
|
|
310
|
+
causeMessage(Cause.squash(failure.cause))
|
|
311
|
+
}.`
|
|
312
|
+
})
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
201
316
|
export const check = <M extends AnyMachine>(
|
|
202
317
|
machine: ReadyMachine<M>,
|
|
203
318
|
options: CheckOptions<M> = {}
|
|
@@ -243,21 +358,88 @@ export const check = <M extends AnyMachine>(
|
|
|
243
358
|
events = derived.value.events
|
|
244
359
|
}
|
|
245
360
|
if (options.stateKey !== undefined) limits.add("customStateKey")
|
|
246
|
-
if (Machine.activityDefinitions(machine).length > 0) limits.add("invocations")
|
|
247
361
|
|
|
362
|
+
const supplied = suppliedOutcomes(machine, (options as { readonly outcomes?: unknown }).outcomes, findings)
|
|
363
|
+
if (supplied !== undefined) limits.add("customOutcomes")
|
|
364
|
+
|
|
365
|
+
// Which results exploration offered, as `path`, `id`, and outcome channel.
|
|
366
|
+
const offered = new Set<string>()
|
|
367
|
+
let unofferedResults = false
|
|
368
|
+
const offers = (running: ReadonlyArray<RunningWork>): ReadonlyArray<WorkOutcome> => {
|
|
369
|
+
const results: Array<WorkOutcome> = []
|
|
370
|
+
for (const work of running) {
|
|
371
|
+
switch (work.kind) {
|
|
372
|
+
case "Timer":
|
|
373
|
+
results.push(Work.elapsed(work))
|
|
374
|
+
offered.add(channelKey(work.path, work.id, "done"))
|
|
375
|
+
break
|
|
376
|
+
case "Effect": {
|
|
377
|
+
const values = work.source === undefined ? undefined : supplied?.get(work.source)
|
|
378
|
+
if (values === undefined) {
|
|
379
|
+
limits.add("effectsWithoutOutcomes")
|
|
380
|
+
break
|
|
381
|
+
}
|
|
382
|
+
for (const output of values.done) results.push(Work.done(work, output))
|
|
383
|
+
for (const error of values.failure) results.push(Work.failure(work, error))
|
|
384
|
+
if (values.done.length > 0) offered.add(channelKey(work.path, work.id, "done"))
|
|
385
|
+
if (values.failure.length > 0) offered.add(channelKey(work.path, work.id, "failure"))
|
|
386
|
+
// A handled channel with no value supplied may hide the states it leads to.
|
|
387
|
+
const handled = Work.channels(work)
|
|
388
|
+
if ((handled.done && values.done.length === 0) || (handled.failure && values.failure.length === 0)) {
|
|
389
|
+
unofferedResults = true
|
|
390
|
+
}
|
|
391
|
+
break
|
|
392
|
+
}
|
|
393
|
+
case "Stream":
|
|
394
|
+
limits.add("streams")
|
|
395
|
+
break
|
|
396
|
+
case "Logic":
|
|
397
|
+
limits.add("logic")
|
|
398
|
+
break
|
|
399
|
+
case "Child":
|
|
400
|
+
limits.add("children")
|
|
401
|
+
break
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return results
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// A node is its logical state and the work still running in it: a state
|
|
408
|
+
// whose work has ended no longer offers that work's results.
|
|
409
|
+
const logicalKey = options.stateKey ?? (({ snapshot }: { readonly snapshot: unknown }) => formatValue(snapshot))
|
|
410
|
+
const keys = new Map<unknown, Map<string, number>>()
|
|
411
|
+
let nextKey = 0
|
|
412
|
+
const stateKey = (context: ExplorationStateContext<M>): number => {
|
|
413
|
+
const logical = logicalKey(context)
|
|
414
|
+
const running = formatValue(context.trace.work.map((work) => [work.path, work.id]))
|
|
415
|
+
let byWork = keys.get(logical)
|
|
416
|
+
if (byWork === undefined) keys.set(logical, byWork = new Map())
|
|
417
|
+
let key = byWork.get(running)
|
|
418
|
+
if (key === undefined) byWork.set(running, key = nextKey++)
|
|
419
|
+
return key
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const machineFailures: Array<ExploredMachineFailure<M>> = []
|
|
423
|
+
// The scenario being planned, which a defect in a callback reproduces.
|
|
424
|
+
let planning: ReadonlyArray<unknown> = []
|
|
248
425
|
const replay = (replayEvents: ReadonlyArray<unknown>) => replayOf(input, hasInput, replayEvents)
|
|
249
|
-
const stateKey = options.stateKey ?? (({ snapshot }: { readonly snapshot: unknown }) => formatValue(snapshot))
|
|
250
426
|
const explored = yield* Effect.exit(
|
|
251
|
-
(
|
|
427
|
+
(exploreWith as any)(machine, {
|
|
252
428
|
...(hasInput ? { input } : {}),
|
|
253
429
|
limits: { ...defaultLimits, ...options.limits },
|
|
254
430
|
invariants: options.invariants,
|
|
255
431
|
stateKey,
|
|
256
|
-
// A completed machine accepts no further events.
|
|
432
|
+
// A completed machine accepts no further events and runs no work.
|
|
257
433
|
events: ({ trace }: { readonly trace: Trace<M> }) =>
|
|
258
|
-
(trace.steps.at(-1)?.plan ?? trace.initial.plan).done ? [] : events
|
|
434
|
+
(trace.steps.at(-1)?.plan ?? trace.initial.plan).done ? [] : [...events, ...offers(trace.work)]
|
|
435
|
+
}, {
|
|
436
|
+
onMachineFailure: (failure: ExploredMachineFailure<M>) => machineFailures.push(failure),
|
|
437
|
+
onPlan: (scenario: { readonly events: ReadonlyArray<unknown> }) => {
|
|
438
|
+
planning = scenario.events
|
|
439
|
+
}
|
|
259
440
|
}) as Effect.Effect<any, RunFailure<unknown, M> | InvariantError<M>, RunServices<M>>
|
|
260
441
|
)
|
|
442
|
+
reportMachineFailures(machineFailures, findings, replay)
|
|
261
443
|
|
|
262
444
|
if (Exit.isFailure(explored)) {
|
|
263
445
|
const failure = Cause.findErrorOption(explored.cause)
|
|
@@ -284,7 +466,7 @@ export const check = <M extends AnyMachine>(
|
|
|
284
466
|
findings.push({
|
|
285
467
|
law: "planning.failed",
|
|
286
468
|
severity: "error",
|
|
287
|
-
replay: replay(
|
|
469
|
+
replay: replay(planning),
|
|
288
470
|
message: `A planning callback threw: ${Cause.pretty(explored.cause)}`
|
|
289
471
|
})
|
|
290
472
|
}
|
|
@@ -331,9 +513,7 @@ export const check = <M extends AnyMachine>(
|
|
|
331
513
|
) {
|
|
332
514
|
const source = graph.nodes.get(edge.source) as ExplorationNode<M>
|
|
333
515
|
const step: TraceStep<M> = edge.data.step
|
|
334
|
-
const location = `${statePaths({ afterConfiguration: step.beforeConfiguration })}:${
|
|
335
|
-
String((step.event as { readonly _tag: PropertyKey })._tag)
|
|
336
|
-
}`
|
|
516
|
+
const location = `${statePaths({ afterConfiguration: step.beforeConfiguration })}:${label(step.event)}`
|
|
337
517
|
const events = [...source.trace.scenario.events, step.event]
|
|
338
518
|
|
|
339
519
|
const verified = yield* Effect.exit(
|
|
@@ -360,16 +540,11 @@ export const check = <M extends AnyMachine>(
|
|
|
360
540
|
}
|
|
361
541
|
}
|
|
362
542
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
EventPlan<M>,
|
|
366
|
-
unknown,
|
|
367
|
-
RunServices<M>
|
|
368
|
-
>
|
|
369
|
-
)
|
|
543
|
+
// The same entry after the same trace, through the same step.
|
|
544
|
+
const again = yield* Effect.exit(planEntry(machine, source.trace, step.event))
|
|
370
545
|
if (
|
|
371
|
-
Exit.isSuccess(again) &&
|
|
372
|
-
planEvidence(again.value, again.value.next) !== planEvidence(step.plan, step.after) &&
|
|
546
|
+
Exit.isSuccess(again) && again.value._tag === "Planned" &&
|
|
547
|
+
planEvidence(again.value.plan, again.value.plan.next) !== planEvidence(step.plan, step.after) &&
|
|
373
548
|
!seen.has(location)
|
|
374
549
|
) {
|
|
375
550
|
seen.add(location)
|
|
@@ -378,36 +553,45 @@ export const check = <M extends AnyMachine>(
|
|
|
378
553
|
severity: "error",
|
|
379
554
|
source: location,
|
|
380
555
|
replay: replay(events),
|
|
381
|
-
message:
|
|
556
|
+
message:
|
|
557
|
+
`Planning "${location}" produced a different result from the same snapshot and ${
|
|
558
|
+
Work.isWorkOutcome(step.event) ? "result" : "event"
|
|
559
|
+
}. ` +
|
|
382
560
|
`Do not read the clock, randomness, or external state in planning callbacks.`
|
|
383
561
|
})
|
|
384
562
|
}
|
|
385
563
|
}
|
|
386
564
|
|
|
387
|
-
// Exploration
|
|
388
|
-
//
|
|
389
|
-
//
|
|
565
|
+
// Exploration takes a result of work only when it has one: a timer always,
|
|
566
|
+
// an Effect when its results were supplied. A transition for a result it
|
|
567
|
+
// never offered is not reported, and neither is one from a state that only
|
|
568
|
+
// such a result leads to: `limits` already reports that gap, and a warning
|
|
569
|
+
// for each such transition would only tell the reader to remove live code.
|
|
390
570
|
const visited = new Set<string>()
|
|
391
571
|
for (const node of exploration.nodes as ReadonlyArray<ExplorationNode<M>>) {
|
|
392
572
|
for (const path of node.configuration as ReadonlyArray<string>) visited.add(path)
|
|
393
573
|
}
|
|
394
|
-
const
|
|
574
|
+
const workHidesStates = unofferedResults || hidingLimits.some((limit) => limits.has(limit))
|
|
395
575
|
for (const miss of exploration.transitionCoverage.branches.misses) {
|
|
396
|
-
|
|
397
|
-
if (
|
|
576
|
+
const trigger = miss.trigger
|
|
577
|
+
if (trigger.type === "invoke") {
|
|
578
|
+
if (!offered.has(channelKey(miss.source, trigger.id, trigger.outcome))) continue
|
|
579
|
+
} else if (workHidesStates && !visited.has(miss.source)) continue
|
|
580
|
+
const target = miss.branch.target === undefined ? "" : ` to "${miss.branch.target}"`
|
|
398
581
|
findings.push({
|
|
399
582
|
law: "transition.notCovered",
|
|
400
583
|
severity: "warning",
|
|
401
584
|
source: miss.source,
|
|
402
|
-
trigger
|
|
585
|
+
trigger,
|
|
403
586
|
target: miss.branch.target,
|
|
404
587
|
...(miss.branchKey === undefined ? {} : { branchKey: miss.branchKey }),
|
|
405
|
-
message:
|
|
406
|
-
`Exploration never took the ${
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
`
|
|
410
|
-
|
|
588
|
+
message: trigger.type === "invoke"
|
|
589
|
+
? `Exploration never took the ${trigger.outcome === "done" ? "onDone" : "onFailure"} transition of ` +
|
|
590
|
+
`"${trigger.id}" from "${miss.source}"${target}. ` +
|
|
591
|
+
`Supply a result that takes it, or remove it if it cannot happen.`
|
|
592
|
+
: `Exploration never took the ${trigger.type === "event" ? `"${String(trigger.event)}"` : trigger.type} ` +
|
|
593
|
+
`transition from "${miss.source}"${target}. ` +
|
|
594
|
+
`Cover it with a scenario, or remove it if it cannot happen.`
|
|
411
595
|
})
|
|
412
596
|
}
|
|
413
597
|
|
|
@@ -447,9 +631,29 @@ const finish = (
|
|
|
447
631
|
findings
|
|
448
632
|
})
|
|
449
633
|
|
|
634
|
+
const formatReplayEvent = (event: unknown): string => {
|
|
635
|
+
if (!Work.isWorkOutcome(event)) return formatValue(event)
|
|
636
|
+
const work = `${event.path === "" ? "root" : event.path}#${event.id}`
|
|
637
|
+
switch (event.kind) {
|
|
638
|
+
case "Done":
|
|
639
|
+
return `done ${work} ${formatValue(event.output)}`
|
|
640
|
+
case "Failure":
|
|
641
|
+
return `failure ${work} ${formatValue(event.error)}`
|
|
642
|
+
case "Elapsed":
|
|
643
|
+
return `elapsed ${work}`
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// One step per item, in order, so a result of work reads apart from the events.
|
|
648
|
+
const formatReplay = (replay: CheckReplay): string =>
|
|
649
|
+
[
|
|
650
|
+
...("input" in replay ? [`input ${formatValue(replay.input)}`] : []),
|
|
651
|
+
...replay.events.map(formatReplayEvent)
|
|
652
|
+
].join(" -> ") || "startup"
|
|
653
|
+
|
|
450
654
|
const formatFinding = (finding: CheckFinding): string =>
|
|
451
655
|
` ${finding.severity === "error" ? "error" : "warn "} ${finding.law}: ${finding.message}` +
|
|
452
|
-
("replay" in finding ? `\n replay: ${
|
|
656
|
+
("replay" in finding ? `\n replay: ${formatReplay(finding.replay)}` : "")
|
|
453
657
|
|
|
454
658
|
export const formatReport = (report: CheckReport): string =>
|
|
455
659
|
[
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @since 0.4.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import type * as Cause from "effect/Cause"
|
|
7
8
|
import * as Data from "effect/Data"
|
|
8
9
|
import * as Effect from "effect/Effect"
|
|
9
10
|
import * as Graph from "effect/Graph"
|
|
@@ -25,11 +26,12 @@ import type {
|
|
|
25
26
|
RunFailure,
|
|
26
27
|
RunServices,
|
|
27
28
|
Scenario,
|
|
29
|
+
ScenarioEvent,
|
|
28
30
|
Trace
|
|
29
31
|
} from "../../../testing/MachineTest.js"
|
|
30
32
|
import type { EnsureExecutable } from "../../machine/readiness.js"
|
|
31
33
|
import { assertInvariants, type InvariantError } from "./invariant.js"
|
|
32
|
-
import {
|
|
34
|
+
import { failMachine, isMachineFailure, run, stepTrace } from "./trace.js"
|
|
33
35
|
import { makeTransitionCoverageCollector } from "./transitionCoverage.js"
|
|
34
36
|
|
|
35
37
|
type AnyMachine = Machine.Machine.Any
|
|
@@ -85,7 +87,7 @@ const stateContext = <M extends AnyMachine>(machine: M, trace: Trace<M>): Explor
|
|
|
85
87
|
|
|
86
88
|
const scenarioWithEvent = <M extends AnyMachine>(
|
|
87
89
|
trace: Trace<M>,
|
|
88
|
-
event:
|
|
90
|
+
event: ScenarioEvent<M>
|
|
89
91
|
): Scenario<M> => ({
|
|
90
92
|
...trace.scenario,
|
|
91
93
|
events: [...trace.scenario.events, event]
|
|
@@ -97,6 +99,23 @@ interface ExplorationEdgeDraft<M extends AnyMachine> {
|
|
|
97
99
|
readonly edge: ExplorationEdge<M>
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
/**
|
|
103
|
+
* A result of work that failed the machine during exploration. The public
|
|
104
|
+
* `explore` fails with it, and `check` reports it instead.
|
|
105
|
+
*/
|
|
106
|
+
export interface ExploredMachineFailure<M extends AnyMachine> {
|
|
107
|
+
readonly trace: Trace<M>
|
|
108
|
+
readonly event: ScenarioEvent<M>
|
|
109
|
+
readonly cause: Cause.Cause<unknown>
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Hooks that `check` passes to exploration. */
|
|
113
|
+
export interface ExplorationHooks<M extends AnyMachine> {
|
|
114
|
+
readonly onMachineFailure?: ((failure: ExploredMachineFailure<M>) => void) | undefined
|
|
115
|
+
/** Called with each scenario before its last entry is planned, so a defect can name it. */
|
|
116
|
+
readonly onPlan?: ((scenario: Scenario<M>) => void) | undefined
|
|
117
|
+
}
|
|
118
|
+
|
|
100
119
|
export const explore = <M extends AnyMachine, Key extends ExplorationKey>(
|
|
101
120
|
machine: ReadyMachine<M>,
|
|
102
121
|
options: ExploreOptions<M, Key>
|
|
@@ -104,6 +123,16 @@ export const explore = <M extends AnyMachine, Key extends ExplorationKey>(
|
|
|
104
123
|
Exploration<M, Key>,
|
|
105
124
|
RunFailure<RunError<M>, M> | InvariantError<M>,
|
|
106
125
|
RunServices<M>
|
|
126
|
+
> => exploreWith(machine, options, {})
|
|
127
|
+
|
|
128
|
+
export const exploreWith = <M extends AnyMachine, Key extends ExplorationKey>(
|
|
129
|
+
machine: ReadyMachine<M>,
|
|
130
|
+
options: ExploreOptions<M, Key>,
|
|
131
|
+
hooks: ExplorationHooks<M>
|
|
132
|
+
): Effect.Effect<
|
|
133
|
+
Exploration<M, Key>,
|
|
134
|
+
RunFailure<RunError<M>, M> | InvariantError<M>,
|
|
135
|
+
RunServices<M>
|
|
107
136
|
> => {
|
|
108
137
|
const limits = resolveLimits(options.limits)
|
|
109
138
|
const initialScenario = (machine.input === undefined || machine.input === Schema.Void
|
|
@@ -167,8 +196,18 @@ export const explore = <M extends AnyMachine, Key extends ExplorationKey>(
|
|
|
167
196
|
}
|
|
168
197
|
|
|
169
198
|
const scenario = scenarioWithEvent(source.trace, event)
|
|
170
|
-
|
|
199
|
+
hooks.onPlan?.(scenario)
|
|
200
|
+
const stepped = yield* stepTrace(machine, source.trace, event, scenario)
|
|
171
201
|
plannedTransitions += 1
|
|
202
|
+
if (isMachineFailure(stepped)) {
|
|
203
|
+
// The machine ended here, so the branch has no state to explore.
|
|
204
|
+
if (hooks.onMachineFailure === undefined) {
|
|
205
|
+
return yield* failMachine(source.trace, event, scenario, stepped)
|
|
206
|
+
}
|
|
207
|
+
hooks.onMachineFailure({ trace: source.trace, event, cause: stepped.cause })
|
|
208
|
+
continue
|
|
209
|
+
}
|
|
210
|
+
const targetTrace = stepped
|
|
172
211
|
const step = targetTrace.steps[targetTrace.steps.length - 1]!
|
|
173
212
|
for (const microstep of step.plan.microsteps) transitionCoverage.observeMicrostep(microstep)
|
|
174
213
|
if (invariants.length > 0) {
|
|
@@ -56,7 +56,7 @@ export const formatValue = (value: unknown): string => JSON.stringify(canonicali
|
|
|
56
56
|
const formatConfiguration = (paths: ReadonlyArray<string>): string =>
|
|
57
57
|
`[${paths.map((path) => path === "" ? "(root)" : path).join(", ")}]`
|
|
58
58
|
|
|
59
|
-
const formatMicrosteps = <M extends AnyMachine>(microsteps: ReadonlyArray<Microstep<M
|
|
59
|
+
const formatMicrosteps = <M extends AnyMachine>(microsteps: ReadonlyArray<Microstep<M>>): Array<string> =>
|
|
60
60
|
microsteps.map((microstep, index) => {
|
|
61
61
|
const transitions = microstep.transitions.map((transition) => ({
|
|
62
62
|
source: transition.source,
|
|
@@ -41,7 +41,8 @@ export const probe = <M extends AnyMachine, Error, Output>(
|
|
|
41
41
|
if (acknowledged === undefined) {
|
|
42
42
|
return Effect.fail(
|
|
43
43
|
new ProbeUnavailableError({
|
|
44
|
-
message:
|
|
44
|
+
message:
|
|
45
|
+
"MachineTest.probe requires a managed statechart reference created by LocalMachine.start or LocalMachine.resume"
|
|
45
46
|
})
|
|
46
47
|
)
|
|
47
48
|
}
|
|
@@ -96,7 +96,7 @@ export const checkpointCommand = <Event = never>(label?: string): RuntimeCommand
|
|
|
96
96
|
*/
|
|
97
97
|
export type RuntimeCommandResult =
|
|
98
98
|
| { readonly _tag: "SendAccepted" }
|
|
99
|
-
| { readonly _tag: "SendRejected"; readonly error: Machine.StoppedError }
|
|
99
|
+
| { readonly _tag: "SendRejected"; readonly error: Machine.StoppedError | Machine.MachineSchemaDecodeError }
|
|
100
100
|
| { readonly _tag: "ClockAdvanced" }
|
|
101
101
|
| { readonly _tag: "Stopped" }
|
|
102
102
|
| { readonly _tag: "Checkpoint" }
|
|
@@ -188,7 +188,7 @@ export interface CausalRuntimeModelStep<Model, Expected, State, Error, Output> {
|
|
|
188
188
|
*/
|
|
189
189
|
export type CausalRuntimeCommandResult<M extends AnyMachine> =
|
|
190
190
|
| { readonly _tag: "SendProcessed"; readonly step: ProbeStep<M> }
|
|
191
|
-
| { readonly _tag: "SendRejected"; readonly error: Machine.StoppedError }
|
|
191
|
+
| { readonly _tag: "SendRejected"; readonly error: Machine.StoppedError | Machine.MachineSchemaDecodeError }
|
|
192
192
|
| { readonly _tag: "ClockAdvanced" }
|
|
193
193
|
| { readonly _tag: "Stopped" }
|
|
194
194
|
| { readonly _tag: "Checkpoint" }
|
|
@@ -712,8 +712,18 @@ const executeCausalCommand = <M extends AnyMachine, Error, Output>(
|
|
|
712
712
|
switch (command._tag) {
|
|
713
713
|
case "Send":
|
|
714
714
|
return Effect.matchEffect(probe.sendAndAwait(command.event), {
|
|
715
|
-
onFailure: (error) =>
|
|
716
|
-
|
|
715
|
+
onFailure: (error): Effect.Effect<CausalRuntimeCommandResult<M>, Error> =>
|
|
716
|
+
// A refused event is rejected before it is sent, so the machine
|
|
717
|
+
// still runs; a processing failure has ended it.
|
|
718
|
+
error instanceof Machine.MachineSchemaDecodeError
|
|
719
|
+
? probe.ref.snapshot.pipe(
|
|
720
|
+
Effect.flatMap((snapshot) =>
|
|
721
|
+
snapshot.status === "active"
|
|
722
|
+
? Effect.succeed({ _tag: "SendRejected", error } as const)
|
|
723
|
+
: Effect.fail(error as Error)
|
|
724
|
+
)
|
|
725
|
+
)
|
|
726
|
+
: error instanceof Machine.StoppedError
|
|
717
727
|
? probe.ref.snapshot.pipe(
|
|
718
728
|
Effect.flatMap((snapshot) =>
|
|
719
729
|
snapshot.status === "stopped"
|
|
@@ -721,7 +731,7 @@ const executeCausalCommand = <M extends AnyMachine, Error, Output>(
|
|
|
721
731
|
: Effect.fail(error as Error)
|
|
722
732
|
)
|
|
723
733
|
)
|
|
724
|
-
: Effect.fail(error
|
|
734
|
+
: Effect.fail(error),
|
|
725
735
|
onSuccess: (step) => Effect.succeed({ _tag: "SendProcessed", step } as const)
|
|
726
736
|
})
|
|
727
737
|
case "Advance":
|