@@ -8,7 +8,6 @@ module User.Agent.Cli
8
8
, TestRunId (.. )
9
9
, IsReady (.. )
10
10
, agentCmd
11
- , agentCmdCore
12
11
)
13
12
where
14
13
@@ -60,7 +59,7 @@ import Oracle.Validate.Requests.TestRun.Update
60
59
, validateToRunningUpdate
61
60
)
62
61
import Oracle.Validate.Types
63
- ( AValidationResult
62
+ ( AValidationResult ( .. )
64
63
, Validate
65
64
, Validated
66
65
, liftMaybe
@@ -87,16 +86,6 @@ import User.Types
87
86
)
88
87
import Validation (Validation )
89
88
90
- agentCmd
91
- :: MonadIO m
92
- => AgentCommand NotReady a
93
- -> WithContext m a
94
- agentCmd cmdNotReady = do
95
- mCmdReady <- resolveOldState cmdNotReady
96
- case mCmdReady of
97
- Nothing -> error " No previous state found for the command"
98
- Just cmdReady -> agentCmdCore cmdReady
99
-
100
89
withExpectedState
101
90
:: (FromJSON Maybe (TestRunState phase ), Monad m )
102
91
=> TokenId
@@ -139,30 +128,42 @@ withResolvedTestRun tk (TestRunId testRunId) cont = do
139
128
Nothing -> pure Nothing
140
129
Just testRun -> cont testRun
141
130
142
- resolveOldState
143
- :: Monad m
144
- => AgentCommand NotReady result
145
- -> WithContext m (Maybe (AgentCommand Ready result ))
146
- resolveOldState cmd = case cmd of
147
- Accept tokenId wallet key () ->
148
- withResolvedTestRun tokenId key $ \ testRun ->
149
- withExpectedState tokenId testRun
150
- $ pure . Accept tokenId wallet testRun
151
- Reject tokenId wallet key () reason ->
152
- withResolvedTestRun tokenId key $ \ testRun ->
153
- withExpectedState tokenId testRun
154
- $ \ pending -> pure $ Reject tokenId wallet testRun pending reason
155
- Report tokenId wallet key () duration url ->
156
- withResolvedTestRun tokenId key $ \ testRun ->
157
- withExpectedState tokenId testRun $ \ runningState ->
158
- pure $ Report tokenId wallet testRun runningState duration url
159
- Query tokenId -> pure $ Just $ Query tokenId
160
- WhiteList tokenId m platform repo ->
161
- pure $ Just $ WhiteList tokenId m platform repo
131
+ updateTestRunState
132
+ :: (Monad m , FromJSON Maybe (TestRunState phase ))
133
+ => TokenId
134
+ -> TestRunId
135
+ -> ( TestRun
136
+ -> TestRunState phase
137
+ -> WithContext m (AValidationResult UpdateTestRunFailure a )
138
+ )
139
+ -> WithContext m (AValidationResult UpdateTestRunFailure a )
140
+ updateTestRunState tokenId key f = do
141
+ mResult <- withResolvedTestRun tokenId key $ \ testRun ->
142
+ withExpectedState tokenId testRun $ f testRun
143
+ pure $ case mResult of
144
+ Nothing -> ValidationFailure UpdateTestRunWrongPreviousState
145
+ Just result -> result
146
+
147
+ agentCmd
148
+ :: MonadIO m
149
+ => AgentCommand NotReady a
150
+ -> WithContext m a
151
+ agentCmd = \ case
152
+ Query tokenId -> queryCommand tokenId
153
+ WhiteList tokenId wallet platform repo ->
154
+ whiteList tokenId wallet platform repo
162
155
BlackList tokenId wallet platform repo ->
163
- pure $ Just $ BlackList tokenId wallet platform repo
164
- DownloadAssets tokenId key dir ->
165
- pure $ Just $ DownloadAssets tokenId key dir
156
+ blackList tokenId wallet platform repo
157
+ DownloadAssets tokenId key dir -> downloadAssets tokenId key dir
158
+ Accept tokenId wallet key () -> do
159
+ updateTestRunState tokenId key $ \ testRun testRunState ->
160
+ acceptCommand tokenId wallet testRun testRunState
161
+ Reject tokenId wallet key () reason -> do
162
+ updateTestRunState tokenId key $ \ testRun testRunState ->
163
+ rejectCommand tokenId wallet testRun testRunState reason
164
+ Report tokenId wallet key () duration url -> do
165
+ updateTestRunState tokenId key $ \ testRun testRunState ->
166
+ reportCommand tokenId wallet testRun testRunState duration url
166
167
167
168
data IsReady = NotReady | Ready
168
169
deriving (Show , Eq )
@@ -245,22 +246,6 @@ deriving instance Eq (AgentCommand NotReady result)
245
246
deriving instance Show (AgentCommand Ready result )
246
247
deriving instance Eq (AgentCommand Ready result )
247
248
248
- agentCmdCore
249
- :: MonadIO m
250
- => AgentCommand Ready result
251
- -> WithContext m result
252
- agentCmdCore cmd = case cmd of
253
- Accept tokenId wallet key pending ->
254
- acceptCommand tokenId wallet key pending
255
- Reject tokenId wallet key pending reason ->
256
- rejectCommand tokenId wallet key pending reason
257
- Report tokenId wallet key running duration url ->
258
- reportCommand tokenId wallet key running duration url
259
- Query tokenId -> queryCommand tokenId
260
- WhiteList tokenId wallet platform repo -> whiteList tokenId wallet platform repo
261
- BlackList tokenId wallet platform repo -> blackList tokenId wallet platform repo
262
- DownloadAssets tokenId key dir -> downloadAssets tokenId key dir
263
-
264
249
whiteList
265
250
:: Monad m
266
251
=> TokenId
0 commit comments