@@ -52,12 +52,14 @@ import Text.Read (readMaybe)
5252
5353import Booster.JsonRpc (rpcJsonConfig )
5454import Booster.JsonRpc.Utils (
55+ DiffResult (DifferentType ),
5556 KoreRpcJson (RpcRequest ),
5657 decodeKoreRpc ,
5758 diffJson ,
5859 isIdentical ,
5960 methodOfRpcCall ,
6061 renderResult ,
62+ rpcTypeOf ,
6163 )
6264import Booster.Prettyprinter (renderDefault )
6365import Booster.Syntax.Json qualified as Syntax
@@ -85,8 +87,8 @@ handleRunOptions common@CommonOptions{dryRun} s = \case
8587 [] -> case s of
8688 Just sock -> shutdown sock ShutdownReceive
8789 Nothing -> pure ()
88- (RunTarball tarFile keepGoing runOnly : xs) -> do
89- runTarball common s tarFile keepGoing runOnly
90+ (RunTarball tarFile keepGoing runOnly noDetails : xs) -> do
91+ runTarball common s tarFile keepGoing runOnly ( not noDetails)
9092 handleRunOptions common s xs
9193 (RunSingle mode optionFile options processingOptions : xs) -> do
9294 let ProcessingOptions {postProcessing, prettify, time} = processingOptions
@@ -246,7 +248,8 @@ data RunOptions
246248 RunTarball
247249 FilePath -- tar file
248250 Bool -- do not stop on first diff if set to true
249- [Kore.JsonRpc.Types. APIMethod ] -- only run specified types of requests. run all if empty
251+ [Kore.JsonRpc.Types. APIMethod ] -- only run specified types of requests. Run all if empty.
252+ Bool -- omit detailed comparison with expected output
250253 deriving stock (Show )
251254
252255data ProcessingOptions = ProcessingOptions
@@ -448,6 +451,10 @@ parseMode =
448451 ( long " run-only"
449452 <> help " Only run the specified request(s), e.g. --run-only \" add-module implies\" "
450453 )
454+ <*> switch
455+ ( long " omit-details"
456+ <> help " only compare response types, not contents"
457+ )
451458 <**> helper
452459 )
453460 (progDesc " Run all requests and compare responses from a bug report tarball" )
@@ -479,9 +486,15 @@ parseMode =
479486-- Running all requests contained in the `rpc_*` directory of a tarball
480487
481488runTarball ::
482- CommonOptions -> Maybe Socket -> FilePath -> Bool -> [Kore.JsonRpc.Types. APIMethod ] -> IO ()
483- runTarball _ Nothing _ _ _ = pure ()
484- runTarball common (Just sock) tarFile keepGoing runOnly = do
489+ CommonOptions ->
490+ Maybe Socket ->
491+ FilePath ->
492+ Bool ->
493+ [Kore.JsonRpc.Types. APIMethod ] ->
494+ Bool ->
495+ IO ()
496+ runTarball _ Nothing _ _ _ _ = pure ()
497+ runTarball common (Just sock) tarFile keepGoing runOnly compareDetails = do
485498 -- unpack tar files, determining type from extension(s)
486499 let unpackTar
487500 | " .tar" == takeExtension tarFile = Tar. read
@@ -509,6 +522,7 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
509522 -- we should not rely on the requests being returned in a sorted order and
510523 -- should therefore sort them explicitly
511524 let requests = sort $ mapMaybe (stripSuffix " _request.json" ) jsonFiles
525+ successMsg = if compareDetails then " matches expected" else " has expected type"
512526 results <-
513527 forM requests $ \ r -> do
514528 mbError <- runRequest skt tmp jsonFiles r
@@ -519,7 +533,7 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
519533 liftIO $
520534 shutdown skt ShutdownReceive >> exitWith (ExitFailure 2 )
521535 Nothing ->
522- logInfo_ $ " Response to " <> r <> " matched with expected "
536+ logInfo_ $ unwords [ " Response to" , r, successMsg]
523537 pure mbError
524538 liftIO $ shutdown skt ShutdownReceive
525539 liftIO $ exitWith (if all isNothing results then ExitSuccess else ExitFailure 2 )
@@ -569,13 +583,22 @@ runTarball common (Just sock) tarFile keepGoing runOnly = do
569583 request <- liftIO . BS. readFile $ tmpDir </> basename <> " _request.json"
570584 expected <- liftIO . BS. readFile $ tmpDir </> basename <> " _response.json"
571585
586+ let showResult =
587+ renderResult " expected response" " actual response"
572588 makeRequest False basename (Just skt) request pure runOnly >>= \ case
573589 Nothing -> pure Nothing -- should not be reachable
574- Just actual -> do
575- let diff = diffJson expected actual
576- if isIdentical diff
577- then pure Nothing
578- else pure . Just $ renderResult " expected response" " actual response" diff
590+ Just actual
591+ | compareDetails -> do
592+ let diff = diffJson expected actual
593+ if isIdentical diff
594+ then pure Nothing
595+ else pure . Just $ showResult diff
596+ | otherwise -> do
597+ let expectedType = rpcTypeOf (decodeKoreRpc expected)
598+ actualType = rpcTypeOf (decodeKoreRpc actual)
599+ if expectedType == actualType
600+ then pure Nothing
601+ else pure . Just $ showResult (DifferentType expectedType actualType)
579602
580603noServerError :: MonadLoggerIO m => CommonOptions -> IOException -> m ()
581604noServerError common e@ IOError {ioe_type = NoSuchThing } = do
0 commit comments