Skip to content

Commit a3e8b04

Browse files
committed
improve reporting of UnacceptableTryIndex
1 parent 923b327 commit a3e8b04

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

cli/src/Oracle/Validate/Requests/TestRun/Create.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Oracle.Validate.Requests.TestRun.Create
99

1010
import Control.Monad (when)
1111
import Control.Monad.Trans.Class (lift)
12-
import Core.Types.Basic (Commit, Directory (..), Duration (..), Repository, Try (..))
12+
import Core.Types.Basic (Commit(..), Directory (..), Duration (..), Repository(..), Try (..))
1313
import Core.Types.Change (Change (..), Key (..))
1414
import Core.Types.Fact (Fact (..))
1515
import Core.Types.Operation (Op (..), Operation (..))
@@ -106,7 +106,7 @@ validateCreateTestRun
106106
data TestRunRejection
107107
= UnacceptableDuration Int Int
108108
| UnacceptableCommit Repository Commit
109-
| UnacceptableTryIndex
109+
| UnacceptableTryIndex Try
110110
| UnacceptableRole
111111
| NoRegisteredKeyVerifiesTheSignature
112112
| UserHasNoRegisteredSSHKeys
@@ -119,10 +119,10 @@ data TestRunRejection
119119
instance Monad m => ToJSON m TestRunRejection where
120120
toJSON (UnacceptableDuration minDuration maxDuration) =
121121
stringJSON $ "unacceptable duration. Expecting duration to be between "<> show minDuration <> " and "<>show maxDuration
122-
toJSON (UnacceptableCommit repo commit)=
123-
stringJSON $ "unacceptable commit. The specified commit "<> show commit<>" cannot be found in the repository "<>show repo
124-
toJSON UnacceptableTryIndex =
125-
stringJSON "unacceptable try index"
122+
toJSON (UnacceptableCommit (Repository org repo) (Commit commit))=
123+
stringJSON $ "unacceptable commit. The specified commit "<> show commit<>" cannot be found in the repository "<>show org<>"/"<>show repo
124+
toJSON (UnacceptableTryIndex (Try maxIx))=
125+
stringJSON $ "unacceptable try index. Expecting at most "<>show maxIx<>" run attempts for a given commit"
126126
toJSON UnacceptableRole =
127127
stringJSON "unacceptable role"
128128
toJSON NoRegisteredKeyVerifiesTheSignature =
@@ -194,7 +194,7 @@ checkTryIndex
194194

195195
if tryIndex testRun == succ latest
196196
then return Nothing
197-
else return $ Just UnacceptableTryIndex
197+
else return $ Just (UnacceptableTryIndex latest)
198198

199199
checkCommit
200200
:: Monad m

cli/test/Oracle/Validate/Requests/TestRun/CreateSpec.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ spec = do
352352
validation
353353
testRun
354354
testRunState
355-
onConditionHaveReason mresult UnacceptableTryIndex
355+
let maxTry = testRunDB.tryIndex
356+
onConditionHaveReason mresult (UnacceptableTryIndex maxTry)
356357
$ testRun.tryIndex /= testRunDB.tryIndex + 1
357358

358359
it "reports unacceptable directory" $ egenProperty $ do

0 commit comments

Comments
 (0)