Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions webapi-test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Revision history for webapi-test

## 0.6.0.0 -- 2026-11-18 (zenbridge #2741: a recorder's sink)

* **A recorder hands what it records to a sink, as it happens**
(`newRecorderTo`, `TraceEvent`), so a run can be followed while it plays.
* `StepEnded phase step`: each step once, when it is final. That is as
soon as its checks have run (`sealStep`, which the state model calls
after a step's postcondition, or after its inconclusive mark), not when
the next step is pushed: a move's own step is handed over before its
settle step begins. A step whose checks never ran (it failed, or its
case was cut) is handed over as its case closes.
* `CaseEnded phase close`: a play closed, after its last step
(`CaseClose`: its outcome, the step it failed at or reached, why, its
moves, the labels that held). A case QuickCheck discards closes too.
* `Phase` tells a replayed regression case, a generated case and a
narrowing try apart (`{"replay": 1}`, `{"case": 2}`, `{"try": 3}`).
* The sink is called on the thread that plays the case, with asynchronous
exceptions masked, so an event is handed over whole or not at all: it
must neither block nor throw (put the event on a queue). A recorder
without a sink records as before.
* **A regression case cut while it replays is recorded** (breaking:
`ReplayOutcome` gains `ReplayCut`). `replayCasesDL` marks the replay it
is in (`beginReplay`); `closeCut` notes it among the replays as `cut`,
with the steps it had made, and `RunTrace.cut` holds it (`replay k`).
* **A regression case is replayed once.** A replay QuickCheck discarded (a
move that did not settle) was played again, up to ten times: the same
case each time.
* `reached`: where a case stopped while it was open got to (its last step,
and the move it was in).

## 0.5.0.0 -- 2026-11-17 (zenbridge #2730: a run cut, and a run's budgets)

* **A cut case is recorded** (breaking: `CaseOutcome` gains `Cut`,
Expand Down
9 changes: 7 additions & 2 deletions webapi-test/quickcheck-dynamic/Test/WebApi/DynamicLogic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Test.QuickCheck.Monadic
import Test.QuickCheck.Monadic qualified as QC
import Data.Reflection
import Data.IORef
import Test.WebApi.Trace (Recorder, ReplayOutcome (..), ReplayRecord (..), StepRecord (..), beginCaseWith, noteReplay, recordedProperty, stepsFailure, takeSteps)
import Test.WebApi.Trace (Recorder, ReplayOutcome (..), ReplayRecord (..), StepRecord (..), beginCaseWith, beginReplay, noteReplay, recordedProperty, stepsFailure, takeSteps)
import Test.WebApi.Prediction (MoveInconclusive (..))
import Control.Exception (catch)
import Data.List (find)
Expand Down Expand Up @@ -70,6 +70,8 @@ propDLTraced rec _ webapiRunner d = recordedProperty rec $
-- (zenbridge #2713), before the property draws any of its own: how it
-- fared noted in the recorder ('Test.WebApi.Trace.replays'), its moves
-- in full. A case the program no longer plays is noted as such, with why.
-- A run cut while a case replays leaves it open: 'Test.WebApi.Trace.closeCut'
-- notes it as cut.
replayCasesDL :: forall c xstate apps e s.
( DynLogicModel xstate
, RunModel xstate IO
Expand All @@ -83,7 +85,10 @@ replayCasesDL rec _ webapiRunner d kept = forM_ (zip [1 ..] kept) $ \(k, CaseRec
case replayTest webApiReplayHooks dl items of
Left why -> noteReplay rec ReplayRecord {caseNumber = k, replayOutcome = CantReplay, replayAt = Nothing, replayWhy = Just why, replaySteps = []}
Right test -> do
res <- QC.quickCheckWithResult QC.stdArgs {QC.maxSuccess = 1, QC.maxShrinks = 0, QC.chatty = False}
beginReplay rec k
-- played once: a case that is discarded (a move that did not settle)
-- is not drawn again, it is the same case
res <- QC.quickCheckWithResult QC.stdArgs {QC.maxSuccess = 1, QC.maxShrinks = 0, QC.maxDiscardRatio = 1, QC.chatty = False}
(withDLScript dl (propApiWithCase (Just rec) Nothing webapiRunner) test)
played <- takeSteps rec
let (at, why) = stepsFailure played
Expand Down
9 changes: 6 additions & 3 deletions webapi-test/quickcheck-dynamic/Test/WebApi/StateModel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ import qualified Data.Text.Encoding.Error as TE
import Test.WebApi.Trace
( StepInfo (..), stepLabel, StepKind (..), Expectation (..), RequestRecord (..), FileRecord (..)
, AnswerRecord (..), CheckRecord (..), StageRecord (..), StepRecord (..), Recorder
, pushStep, amendStep, afterStep, markInconclusive, clipText, bodyText )
, pushStep, amendStep, sealStep, afterStep, markInconclusive, clipText, bodyText )
import Test.WebApi.Prediction
import Data.ByteString (ByteString)
import Data.Text (Text)
Expand Down Expand Up @@ -961,7 +961,7 @@ instance ( Reifies s (WebApiGlobalStateModel c xstate apps)
case settled of
Right () -> pure res
Left why -> do
forM_ traceRecorder $ \rec -> liftIO (amendStep rec (markInconclusive why))
forM_ traceRecorder $ \rec -> liftIO (amendStep rec (markInconclusive why) >> sealStep rec)
liftIO (throwIO MoveInconclusive {move = name, why})
_ -> do
res <- performIt
Expand Down Expand Up @@ -1060,6 +1060,8 @@ instance ( Reifies s (WebApiGlobalStateModel c xstate apps)
m <- renderModel lkp' after
stageAfter <- stageOfGuarded lkp' after
amendStep r (afterStep cs ls m stageAfter held)
-- the step is final: its checks have run
sealStep r
pure held
where
-- a move's end: the host observes, then every thing is held against
Expand All @@ -1073,7 +1075,7 @@ instance ( Reifies s (WebApiGlobalStateModel c xstate apps)
Left why -> do
rec <- lift (asks (\WebApiSessionsCxt {traceRecorder} -> traceRecorder))
lift $ liftIO $ do
forM_ rec $ \r -> amendStep r (markInconclusive ("nothing could be observed: " <> why))
forM_ rec $ \r -> amendStep r (markInconclusive ("nothing could be observed: " <> why)) >> sealStep r
throwIO MoveInconclusive {move = name, why = "nothing could be observed: " <> why}
Right obs -> do
let
Expand Down Expand Up @@ -1116,6 +1118,7 @@ instance ( Reifies s (WebApiGlobalStateModel c xstate apps)
m <- renderModel lkp after
stageAfter <- stageOfGuarded lkp after
amendStep r (afterStep [] [] m stageAfter held)
sealStep r
pure held
where
held = case act of
Expand Down
Loading
Loading