Skip to content

Commit 935fa96

Browse files
committed
feat: use new Duration
1 parent ecf0597 commit 935fa96

File tree

27 files changed

+246
-197
lines changed

27 files changed

+246
-197
lines changed

justfile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ integration match="":
4646
echo "Please set MOOG_GITHUB_PAT environment variable, this is a valid GitHub personal access token with access to the public github API"
4747
exit 1
4848
fi
49-
if [ -z "${MOOG_SSH_PASSWORD:-}" ]; then
50-
echo "Please set MOOG_SSH_PASSWORD environment variable, this is the passphrase for the cfhal encrypted SSH private key"
51-
exit 1
52-
fi
5349
if ! test -f tmp/test.json; then
5450
echo "E2E tests expect wallet definition in tmp/test.json file"
5551
exit 1
@@ -119,10 +115,6 @@ E2E match="":
119115
echo "Please set MOOG_GITHUB_PAT environment variable, this is a valid GitHub personal access token with access to the public github API"
120116
exit 1
121117
fi
122-
if [ -z "${MOOG_SSH_PASSWORD:-}" ]; then
123-
echo "Please set MOOG_SSH_PASSWORD environment variable, this is the passphrase for the cfhal encrypted SSH private key"
124-
exit 1
125-
fi
126118
if ! test -f tmp/test.json; then
127119
echo "E2E tests expect wallet definition in tmp/test.json file"
128120
exit 1

src/Core/Options.hs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Control.Arrow (left)
2323
import Core.Types.Basic
2424
( Commit (..)
2525
, Directory (..)
26-
, Duration (..)
2726
, FaultsEnabled (FaultsEnabled)
2827
, GithubRepository (..)
2928
, GithubUsername (..)
@@ -32,6 +31,7 @@ import Core.Types.Basic
3231
, TokenId (..)
3332
, Try (..)
3433
)
34+
import Core.Types.Duration (Duration (..))
3535
import Core.Types.Mnemonics.Options (mnemonicsParser)
3636
import Core.Types.Wallet
3737
( Wallet
@@ -57,6 +57,7 @@ import OptEnvConf
5757
, strOption
5858
, switch
5959
, value
60+
, (<|>)
6061
)
6162
import OptEnvConf.Reader (Reader (..))
6263
import Submitting (readWallet)
@@ -192,15 +193,24 @@ parseOutputReference = Reader $ \s -> do
192193

193194
durationOption :: Parser Duration
194195
durationOption =
195-
Duration
196+
Hours
196197
<$> setting
197-
[ long "duration"
198-
, short 't'
199-
, metavar "DURATION"
198+
[ long "hours-duration"
199+
, short 'h'
200+
, metavar "HOURS"
200201
, help "The duration in hours for the test-run"
201202
, reader auto
202203
, option
203204
]
205+
<|> Minutes
206+
<$> setting
207+
[ long "minutes-duration"
208+
, short 'm'
209+
, metavar "MINUTES"
210+
, help "The duration in minutes for the test-run"
211+
, reader auto
212+
, option
213+
]
204214

205215
faultsEnabledOption :: Parser FaultsEnabled
206216
faultsEnabledOption =

src/Core/Types/Basic.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module Core.Types.Basic
77
, Commit (..)
88
, Directory (..)
99
, FileName (..)
10-
, Duration (..)
1110
, Host (..)
1211
, Owner (..)
1312
, Platform (..)
@@ -197,9 +196,6 @@ instance FromHttpApiData Address where
197196
instance ToHttpApiData Address where
198197
toUrlPiece (Address addr) = addr
199198

200-
newtype Duration = Duration Int
201-
deriving (Eq, Show)
202-
203199
newtype FaultsEnabled = FaultsEnabled {getFaultsEnabled :: Bool}
204200
deriving (Eq, Show)
205201
deriving newtype (Aeson.FromJSON)

src/Oracle/Config/Options.hs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ where
99

1010
import Core.Options (tokenIdOption, walletOption)
1111
import Core.Types.Basic (Owner (..))
12+
import Core.Types.Duration (Duration (..))
1213
import Lib.Box (Box (..))
1314
import OptEnvConf
1415
( Parser
@@ -32,22 +33,24 @@ import Oracle.Validate.Requests.TestRun.Config
3233
configOption :: Parser Config
3334
configOption = do
3435
minDuration <-
35-
setting
36-
[ long "min-test-duration"
37-
, metavar "MIN_TEST_HOURS"
38-
, help "Minimum duration of the tests in hours"
39-
, option
40-
, reader auto
41-
]
36+
Minutes
37+
<$> setting
38+
[ long "min-test-duration"
39+
, metavar "MINUTES"
40+
, help "Minimum duration of the tests in minutes"
41+
, option
42+
, reader auto
43+
]
4244

4345
maxDuration <-
44-
setting
45-
[ long "max-test-duration"
46-
, metavar "MAX_TEST_HOURS"
47-
, help "Maximum duration of the tests in hours"
48-
, option
49-
, reader auto
50-
]
46+
Minutes
47+
<$> setting
48+
[ long "max-test-duration"
49+
, metavar "MINUTES"
50+
, help "Maximum duration of the tests in minutes"
51+
, option
52+
, reader auto
53+
]
5154
agent <-
5255
Owner
5356
<$> strOption

src/Oracle/Config/Types.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ module Oracle.Config.Types
66
)
77
where
88

9+
import Control.Applicative (Alternative)
910
import Core.Types.Basic (Owner)
1011
import Core.Types.Change (Change)
11-
import Core.Types.Operation
12-
import Lib.JSON.Canonical.Extra
12+
import Core.Types.Operation (Op (OpI, OpU))
13+
import Lib.JSON.Canonical.Extra (object, withObject, (.:), (.=))
1314
import Oracle.Validate.Requests.TestRun.Config
1415
( TestRunValidationConfig
1516
)
1617
import Text.JSON.Canonical
18+
( FromJSON (..)
19+
, JSValue (JSString)
20+
, ReportSchemaErrors
21+
, ToJSON (..)
22+
, expectedButGotValue
23+
, toJSString
24+
)
1725

1826
data Config = Config
1927
{ configAgent :: Owner
@@ -46,7 +54,7 @@ instance Monad m => ToJSON m Config where
4654
, "testRun" .= testRun
4755
]
4856

49-
instance ReportSchemaErrors m => FromJSON m Config where
57+
instance (Alternative m, ReportSchemaErrors m) => FromJSON m Config where
5058
fromJSON = withObject "Config" $ \o -> do
5159
Config
5260
<$> o .: "agent"

src/Oracle/Validate/Requests/Config.hs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ where
88
import Control.Monad (when)
99
import Core.Types.Basic (Owner)
1010
import Core.Types.Change (Change (..))
11+
import Core.Types.Duration (Duration)
1112
import Core.Types.Operation (Op (..), Operation (..))
1213
import Effects
1314
( Effects
@@ -29,28 +30,28 @@ import Oracle.Validate.Types
2930
, mapFailure
3031
, notValidated
3132
)
32-
import Text.JSON.Canonical (Int54, ToJSON (..))
33+
import Text.JSON.Canonical (ToJSON (..))
3334

3435
data ConfigFailure
3536
= ConfigureKeyValidationFailure KeyFailure
3637
| ConfigureNotFromOracle Owner
37-
| ConfigureMinLessThanOne Int
38-
| ConfigureMaxLessThanMin Int Int
38+
| ConfigureMinLessThanZero Duration
39+
| ConfigureMaxLessThanMin Duration Duration
3940
deriving (Show, Eq)
4041

4142
instance Monad m => ToJSON m ConfigFailure where
4243
toJSON (ConfigureKeyValidationFailure keyFailure) =
4344
object ["configureKeyValidationFailure" .= keyFailure]
4445
toJSON (ConfigureNotFromOracle owner) =
4546
object ["configureNotFromOracle" .= show owner]
46-
toJSON (ConfigureMinLessThanOne minD) =
47-
object ["configureMinLessThanOne" .= fromIntegral @_ @Int54 minD]
47+
toJSON (ConfigureMinLessThanZero minD) =
48+
object ["configureMinLessThanZero" .= minD]
4849
toJSON (ConfigureMaxLessThanMin maxD minD) =
4950
object
5051
[ (,) "configureMaxLessThanMin"
5152
$ object
52-
[ "max" .= fromIntegral @_ @Int54 maxD
53-
, "min" .= fromIntegral @_ @Int54 minD
53+
[ "max" .= maxD
54+
, "min" .= minD
5455
]
5556
]
5657

@@ -66,9 +67,9 @@ commonValidation oracleOwner submitterOwner configTestRun = do
6667
$ ConfigureNotFromOracle submitterOwner
6768
let minD = minDuration configTestRun
6869
maxD = maxDuration configTestRun
69-
when (minD < 1)
70+
when (minD <= mempty)
7071
$ notValidated
71-
$ ConfigureMinLessThanOne minD
72+
$ ConfigureMinLessThanZero minD
7273
when (maxD < minD)
7374
$ notValidated
7475
$ ConfigureMaxLessThanMin maxD minD

src/Oracle/Validate/Requests/TestRun/Config.hs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,34 @@ module Oracle.Validate.Requests.TestRun.Config
44
( TestRunValidationConfig (..)
55
) where
66

7+
import Control.Applicative (Alternative)
8+
import Core.Types.Duration (Duration)
79
import GHC.Generics (Generic)
810
import Lib.JSON.Canonical.Extra
911
import Text.JSON.Canonical
1012
( FromJSON (..)
11-
, Int54
1213
, ReportSchemaErrors
1314
, ToJSON (..)
1415
)
1516

1617
data TestRunValidationConfig = TestRunValidationConfig
17-
{ maxDuration :: Int
18-
, minDuration :: Int
18+
{ maxDuration :: Duration
19+
, minDuration :: Duration
1920
}
2021
deriving (Show, Eq, Generic)
2122

2223
instance Monad m => ToJSON m TestRunValidationConfig where
2324
toJSON (TestRunValidationConfig maxDur minDur) =
2425
object
25-
[ "maxDuration" .= fromIntegral @_ @Int54 maxDur
26-
, "minDuration" .= fromIntegral @_ @Int54 minDur
26+
[ "maxDuration" .= maxDur
27+
, "minDuration" .= minDur
2728
]
2829

29-
instance ReportSchemaErrors m => FromJSON m TestRunValidationConfig where
30+
instance
31+
(Alternative m, ReportSchemaErrors m)
32+
=> FromJSON m TestRunValidationConfig
33+
where
3034
fromJSON = withObject "TestRunValidationConfig" $ \o ->
3135
TestRunValidationConfig
32-
<$> (o .: "maxDuration" >>= pure . fromIntegral @Int54)
33-
<*> (o .: "minDuration" >>= pure . fromIntegral @Int54)
36+
<$> (o .: "maxDuration" >>= fromJSON)
37+
<*> (o .: "minDuration" >>= fromJSON)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import Control.Monad.Trans.Class (lift)
1212
import Core.Types.Basic
1313
( Commit (..)
1414
, Directory (..)
15-
, Duration (..)
1615
, GithubRepository (..)
1716
, GithubUsername (..)
1817
, Try (..)
1918
)
2019
import Core.Types.Change (Change (..), Key (..))
20+
import Core.Types.Duration (Duration)
2121
import Core.Types.Fact (Fact (..))
2222
import Core.Types.Operation (Op (..), Operation (..))
2323
import Core.Types.VKey (decodeVKey)
@@ -120,7 +120,7 @@ validateCreateTestRun
120120
testRunState
121121

122122
data TestRunRejection
123-
= UnacceptableDuration Int Int
123+
= UnacceptableDuration Duration Duration
124124
| UnacceptableCommit GithubRepository Commit
125125
| UnacceptableTryIndex Try
126126
| UnacceptableRole RegisterRoleKey
@@ -179,7 +179,7 @@ instance Monad m => ToJSON m TestRunRejection where
179179

180180
checkDuration
181181
:: TestRunValidationConfig -> Duration -> Maybe TestRunRejection
182-
checkDuration TestRunValidationConfig{maxDuration, minDuration} (Duration n)
182+
checkDuration TestRunValidationConfig{maxDuration, minDuration} n
183183
| n < minDuration || n > maxDuration =
184184
Just $ UnacceptableDuration minDuration maxDuration
185185
| otherwise = Nothing

src/User/Agent/Cli.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Core.Context
2828
)
2929
import Core.Types.Basic
3030
( Directory
31-
, Duration
3231
, GithubRepository
3332
, GithubUsername (..)
3433
, Owner
@@ -37,6 +36,7 @@ import Core.Types.Basic
3736
, TokenId
3837
)
3938
import Core.Types.Change (Change (..), Key (..))
39+
import Core.Types.Duration (Duration)
4040
import Core.Types.Fact
4141
( Fact (..)
4242
, keyHash
@@ -100,7 +100,6 @@ import User.Agent.PublishResults.Email
100100
( EmailException
101101
, EmailPassword
102102
, EmailUser
103-
, Minutes
104103
, Result (..)
105104
, readEmails
106105
)
@@ -368,12 +367,12 @@ data AgentCommand (phase :: IsReady) result where
368367
-> EmailUser
369368
-> EmailPassword
370369
-> TestRunId
371-
-> Minutes
370+
-> Duration
372371
-> AgentCommand phase (AValidationResult CheckResultsFailure Result)
373372
CheckAllResults
374373
:: EmailUser
375374
-> EmailPassword
376-
-> Minutes
375+
-> Duration
377376
-- ^ limit to last N minutes
378377
-> AgentCommand phase (AValidationResult CheckResultsFailure [Result])
379378
PushTest

src/User/Agent/Lib.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module User.Agent.Lib
77

88
import Control.Applicative (Alternative (..))
99
import Core.Context (WithContext, withMPFS)
10-
import Core.Types.Basic (Duration, FaultsEnabled, TokenId)
10+
import Core.Types.Basic (FaultsEnabled, TokenId)
11+
import Core.Types.Duration (Duration)
1112
import Core.Types.Fact (Fact (..), keyHash, parseFacts)
1213
import Data.Foldable (find)
1314
import MPFS.API (MPFS (..))

0 commit comments

Comments
 (0)