Skip to content

Commit

Permalink
207 consume pyk rpc bug reports (#241)
Browse files Browse the repository at this point in the history
Extend `rpc-client` to run all requests from a tarball (from the
directory `rpc_*` inside it)

Also refactored program option data type(s) to accommodate the new run
mode.

---------

Co-authored-by: Georgy Lukyanov <[email protected]>
  • Loading branch information
jberthold and geo2a authored Jul 26, 2023
1 parent a7678ce commit 8735476
Show file tree
Hide file tree
Showing 31 changed files with 402 additions and 110 deletions.
5 changes: 5 additions & 0 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
active-repositories: hackage.haskell.org:merge
constraints: any.Cabal ==3.6.3.0,
any.Diff ==0.4.1,
any.Glob ==0.10.2,
any.HUnit ==1.6.2.0,
any.OneTuple ==0.3.1,
Expand Down Expand Up @@ -45,6 +46,10 @@ constraints: any.Cabal ==3.6.3.0,
byteslice +avoid-rawmemchr,
any.bytesmith ==0.3.9.1,
any.bytestring ==0.11.4.0,
any.bz2 ==1.0.1.0,
bz2 -cross +with-bzlib,
any.c2hs ==0.28.8,
c2hs +base3 -regression,
any.cabal-doctest ==1.0.9,
any.call-stack ==0.4.0,
any.case-insensitive ==1.2.1.0,
Expand Down
44 changes: 21 additions & 23 deletions library/Booster/JsonRpc/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,10 @@ import Network.JSONRPC
import Kore.JsonRpc.Types
import Kore.Syntax.Json.Types hiding (Left, Right)

diffJson :: FilePath -> FilePath -> IO DiffResult
diffJson korefile1 korefile2 = do
contents1 <-
decodeKoreRpc <$> BS.readFile korefile1
contents2 <-
decodeKoreRpc <$> BS.readFile korefile2

pure $ case (contents1, contents2) of
(_, _)
diffJson :: BS.ByteString -> BS.ByteString -> DiffResult
diffJson file1 file2 =
case (decodeKoreRpc file1, decodeKoreRpc file2) of
(contents1, contents2)
| contents1 == contents2 ->
Identical $ rpcTypeOf contents1
(NotRpcJson lines1, NotRpcJson lines2) -> do
Expand Down Expand Up @@ -96,22 +91,25 @@ decodeKoreRpc input =
req <- Json.decode @Request input
parser <- parseParams req.getReqMethod
parseMaybe parser req.getReqParams
rpcResponse = fmap RpcResponse $ do
rpcResponse = do
resp <- Json.decode @Response input
foldl1
(<|>)
[ Execute <$> parseMaybe (Json.parseJSON @ExecuteResult) resp.getResult
, Implies <$> parseMaybe (Json.parseJSON @ImpliesResult) resp.getResult
, Simplify <$> parseMaybe (Json.parseJSON @SimplifyResult) resp.getResult
, AddModule <$> parseMaybe (Json.parseJSON @()) resp.getResult
, GetModel <$> parseMaybe (Json.parseJSON @GetModelResult) resp.getResult
]
case resp of
ResponseError{} -> extractError resp.getError
OrphanError{} -> extractError resp.getError
Response{} ->
fmap RpcResponse . try $
[ Execute <$> parseMaybe (Json.parseJSON @ExecuteResult) resp.getResult
, Implies <$> parseMaybe (Json.parseJSON @ImpliesResult) resp.getResult
, Simplify <$> parseMaybe (Json.parseJSON @SimplifyResult) resp.getResult
, AddModule <$> parseMaybe (Json.parseJSON @()) resp.getResult
, GetModel <$> parseMaybe (Json.parseJSON @GetModelResult) resp.getResult
]
rpcError =
Json.decode @ErrorObj input
>>= \case
ErrorObj msg code mbData ->
pure $ RpcError msg code mbData
ErrorVal{} -> fail "arbitrary json can be an ErrorVal"
Json.decode @ErrorObj input >>= extractError
extractError = \case
ErrorObj msg code mbData ->
pure $ RpcError msg code mbData
ErrorVal{} -> fail "arbitrary json can be an ErrorVal"
koreJson =
RpcKoreJson <$> Json.decode @KoreJson input
unknown =
Expand Down
4 changes: 4 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,20 @@ executables:
- aeson-pretty
- base
- bytestring
- bz2
- clock
- directory
- extra
- filepath
- hs-backend-booster
- network
- network-run
- optparse-applicative
- process
- tar
- text
- vector
- zlib
ghc-options:
- -rtsopts
parsetest:
Expand Down
1 change: 1 addition & 0 deletions test/jsonrpc-examples/add-module.error.response
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","id":4,"error":{"code":2,"data":{"context":null,"error":"FOUNDRY-MAIN-DEPENDS-MODULE: Duplicate module"},"message":"Could not verify pattern"}}
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/depth-limit.execute.response: ExecuteM response
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/depth-limit.spaghetti-formatted.execute.response: ExecuteM response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/foundry-proof.implies.request: ImpliesM request
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/foundry-proof.simplify.request: SimplifyM request
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/foundry-proof2.simplify.request: SimplifyM request
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/not-json.error: non-JSON file
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/params.random.json: unknown object
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/state-a.kore.json: Kore term
3 changes: 3 additions & 0 deletions ...jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/state-a.spaghetti-formatted.kore.json: Kore term
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/state-a.unformatted.execute.request: ExecuteM request
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/terminal.execute.response: ExecuteM response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/add-module.error.response: error response
* File test/jsonrpc-examples/with-logging.simplify.response: SimplifyM response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/depth-limit.execute.response: ExecuteM response
* File test/jsonrpc-examples/add-module.error.response: error response
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/depth-limit.spaghetti-formatted.execute.response: ExecuteM response
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/foundry-proof.implies.request: ImpliesM request
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/foundry-proof.simplify.request: SimplifyM request
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/foundry-proof2.simplify.request: SimplifyM request
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/not-json.error: non-JSON file
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/params.random.json: unknown object
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/state-a.kore.json: Kore term
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions ...jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/state-a.spaghetti-formatted.kore.json: Kore term
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/state-a.unformatted.execute.request: ExecuteM request
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/terminal.execute.response: ExecuteM response
* File test/jsonrpc-examples/add-module.error.response: error response
3 changes: 3 additions & 0 deletions test/jsonrpc-examples/expected/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Json data in files is of different type
* File test/jsonrpc-examples/with-logging.simplify.response: SimplifyM response
* File test/jsonrpc-examples/add-module.error.response: error response
8 changes: 5 additions & 3 deletions tools/kore-json-differ/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ main = do
_
| "--help" `elem` args ->
putStrLn usage
[x, y] -> do
result <- diffJson x y
BS.putStrLn $ renderResult x y result
[file1, file2] -> do
x <- BS.readFile file1
y <- BS.readFile file2
let result = diffJson x y
BS.putStrLn $ renderResult file1 file2 result
exitWith $ if isIdentical result then ExitSuccess else ExitFailure 1
_other -> do
putStrLn $ "ERROR: program requires exactly two arguments.\n\n" <> usage
Expand Down
Loading

0 comments on commit 8735476

Please sign in to comment.