keiro-dsl-0.17.0.0: test/conformance-process-reactions/Generated/ProcessReactions/IncidentSaga/Harness.hs
-- @generated by keiro-dsl 0.17.0.0 (language keiro-dsl 6) from aggregate IncidentSaga; do not edit.
module Generated.ProcessReactions.IncidentSaga.Harness (harnessAssertions) where
import Generated.ProcessReactions.IncidentSaga.Domain
import Generated.ProcessReactions.IncidentSaga.Codec (encodeIncidentSagaEvent, parseIncidentSagaEvent, incidentSagaCodec)
import Generated.ProcessReactions.IncidentSaga.Transducer (incidentSagaTransducer)
import Keiki.Core (applyEventsEither, defaultValidationOptions, step, validateTransducer)
import Keiro.Codec (eventType)
import Generated.ProcessReactions.Nominals (IncidentId, parseIncidentId)
-- | (label, passed). A driver runs these and exits non-zero on any False,
-- naming the failing assertion. Filling a hole wrongly turns a specific
-- entry False; the scaffold cannot.
harnessAssertions :: [(String, Bool)]
harnessAssertions =
[ ("validateTransducer is empty", null (validateTransducer defaultValidationOptions incidentSagaTransducer))
-- clock-free: spec samples no wall clock (verified at scaffold time)
, ("golden round-trip: CriticalRecorded", roundTrips sampleEventCriticalRecorded)
, ("golden round-trip: RoutineRecorded", roundTrips sampleEventRoutineRecorded)
, ("accepts RecordCritical from IncidentSagaOpen", acceptRecordCritical)
, ("accepts RecordRoutine from IncidentSagaOpen", acceptRecordRoutine)
]
++ forwardReplayRecordCritical
++ forwardReplayRecordRoutine
roundTrips :: IncidentSagaEvent -> Bool
roundTrips e = parseIncidentSagaEvent (eventType incidentSagaCodec e) (encodeIncidentSagaEvent e) == Right e
sampleIncidentId :: IncidentId
sampleIncidentId =
case parseIncidentId "inc_01h455vb4pex5vsknk084sn02q" of
Right parsed -> parsed
Left problem -> error (show problem)
sampleEventCriticalRecorded :: IncidentSagaEvent
sampleEventCriticalRecorded = CriticalRecorded (CriticalRecordedData sampleIncidentId)
sampleEventRoutineRecorded :: IncidentSagaEvent
sampleEventRoutineRecorded = RoutineRecorded (RoutineRecordedData sampleIncidentId)
acceptRecordCritical :: Bool
acceptRecordCritical =
case step incidentSagaTransducer (IncidentSagaOpen, initialIncidentSagaRegs) (RecordCritical (RecordCriticalData sampleIncidentId)) of
Just (v, _, _) -> v == IncidentSagaOpen
Nothing -> False
acceptRecordRoutine :: Bool
acceptRecordRoutine =
case step incidentSagaTransducer (IncidentSagaOpen, initialIncidentSagaRegs) (RecordRoutine (RecordRoutineData sampleIncidentId)) of
Just (v, _, _) -> v == IncidentSagaOpen
Nothing -> False
-- forward/replay equality (plan 147): cross the persisted codec boundary,
-- replay the emitted chain, and compare the final vertex and every register.
forwardReplayRecordCritical :: [(String, Bool)]
forwardReplayRecordCritical =
case step incidentSagaTransducer (IncidentSagaOpen, initialIncidentSagaRegs) (RecordCritical (RecordCriticalData sampleIncidentId)) of
Nothing -> [(prefix <> "forward step accepted", False)]
Just (forwardVertex, _forwardRegs, emitted) ->
case mapM (\event -> parseIncidentSagaEvent (eventType incidentSagaCodec event) (encodeIncidentSagaEvent event)) emitted of
Left _ -> [(prefix <> "emitted chain decodes", False)]
Right decodedEvents ->
case applyEventsEither incidentSagaTransducer (IncidentSagaOpen, initialIncidentSagaRegs) decodedEvents of
Left _ -> [(prefix <> "replay succeeds", False)]
Right (replayVertex, _replayRegs) ->
[ (prefix <> "final vertex", replayVertex == forwardVertex)
]
where
prefix = "forward/replay equality: RecordCritical from IncidentSagaOpen -- "
-- forward/replay equality (plan 147): cross the persisted codec boundary,
-- replay the emitted chain, and compare the final vertex and every register.
forwardReplayRecordRoutine :: [(String, Bool)]
forwardReplayRecordRoutine =
case step incidentSagaTransducer (IncidentSagaOpen, initialIncidentSagaRegs) (RecordRoutine (RecordRoutineData sampleIncidentId)) of
Nothing -> [(prefix <> "forward step accepted", False)]
Just (forwardVertex, _forwardRegs, emitted) ->
case mapM (\event -> parseIncidentSagaEvent (eventType incidentSagaCodec event) (encodeIncidentSagaEvent event)) emitted of
Left _ -> [(prefix <> "emitted chain decodes", False)]
Right decodedEvents ->
case applyEventsEither incidentSagaTransducer (IncidentSagaOpen, initialIncidentSagaRegs) decodedEvents of
Left _ -> [(prefix <> "replay succeeds", False)]
Right (replayVertex, _replayRegs) ->
[ (prefix <> "final vertex", replayVertex == forwardVertex)
]
where
prefix = "forward/replay equality: RecordRoutine from IncidentSagaOpen -- "