@@ -115,28 +115,68 @@ async fn real_analysis_finds_a_win_without_mutating_history_and_reports_uncalibr
115115}
116116
117117#[ tokio:: test]
118- async fn sudoku_reference_solver_plays_only_through_generic_analysis_and_moves ( ) -> Result < ( ) , ServerError > {
118+ async fn sudoku_reference_solver_plays_only_through_generic_analysis_and_moves (
119+ ) -> Result < ( ) , ServerError > {
119120 let directory = tempfile:: tempdir ( ) ?;
120121 let app = fixture ( & config ( & directory) ) . await ?;
121- let ( _, catalog) = call ( & app. router , "GET" , "/v1/games/sudoku/opponents" , Value :: Null , None ) . await ?;
122- assert ! ( catalog. as_array( ) . ok_or( "catalog" ) ?. iter( ) . any( |item| item[ "id" ] == "reference" ) ) ;
123- let ( _, mut state) = call ( & app. router , "POST" , "/v1/matches" , json ! ( {
124- "game_id" : "sudoku" , "config" : { "size" : 4 } , "seed" : 42 ,
125- "assists" : { "allow_analysis" : true }
126- } ) , None ) . await ?;
122+ let ( _, catalog) = call (
123+ & app. router ,
124+ "GET" ,
125+ "/v1/games/sudoku/opponents" ,
126+ Value :: Null ,
127+ None ,
128+ )
129+ . await ?;
130+ assert ! ( catalog
131+ . as_array( )
132+ . ok_or( "catalog" ) ?
133+ . iter( )
134+ . any( |item| item[ "id" ] == "reference" ) ) ;
135+ let ( _, mut state) = call (
136+ & app. router ,
137+ "POST" ,
138+ "/v1/matches" ,
139+ json ! ( {
140+ "game_id" : "sudoku" , "config" : { "size" : 4 } , "seed" : 42 ,
141+ "assists" : { "allow_analysis" : true }
142+ } ) ,
143+ None ,
144+ )
145+ . await ?;
127146 let id = state[ "match_id" ] . as_str ( ) . ok_or ( "id" ) ?. to_owned ( ) ;
128147 for _ in 0 ..16 {
129- if state[ "terminated" ] == true { break ; }
130- let ( status, result) = call ( & app. router , "POST" , "/v1/analysis" , json ! ( {
131- "game_id" : "sudoku" , "from" : { "match_id" : id, "seat" : 0 } ,
132- "opponent" : { "id" : "reference" } , "seed" : 7
133- } ) , None ) . await ?;
148+ if state[ "terminated" ] == true {
149+ break ;
150+ }
151+ let ( status, result) = call (
152+ & app. router ,
153+ "POST" ,
154+ "/v1/analysis" ,
155+ json ! ( {
156+ "game_id" : "sudoku" , "from" : { "match_id" : id, "seat" : 0 } ,
157+ "opponent" : { "id" : "reference" } , "seed" : 7
158+ } ) ,
159+ None ,
160+ )
161+ . await ?;
134162 assert_eq ! ( status, StatusCode :: OK , "{result}" ) ;
135- assert ! ( result[ "advice" ] [ "summary" ] . as_str( ) . is_some_and( |s| !s. is_empty( ) ) ) ;
136- assert ! ( state[ "legal_actions" ] . as_array( ) . ok_or( "legal" ) ?. contains( & result[ "best_moves" ] [ 0 ] ) ) ;
137- let ( status, moved) = call ( & app. router , "POST" , & format ! ( "/v1/matches/{id}/actions" ) , json ! ( {
138- "seat" : 0 , "turn" : state[ "turn" ] , "action" : result[ "best_moves" ] [ 0 ] [ "json" ]
139- } ) , None ) . await ?;
163+ assert ! ( result[ "advice" ] [ "summary" ]
164+ . as_str( )
165+ . is_some_and( |s| !s. is_empty( ) ) ) ;
166+ assert ! ( state[ "legal_actions" ]
167+ . as_array( )
168+ . ok_or( "legal" ) ?
169+ . contains( & result[ "best_moves" ] [ 0 ] ) ) ;
170+ let ( status, moved) = call (
171+ & app. router ,
172+ "POST" ,
173+ & format ! ( "/v1/matches/{id}/actions" ) ,
174+ json ! ( {
175+ "seat" : 0 , "turn" : state[ "turn" ] , "action" : result[ "best_moves" ] [ 0 ] [ "json" ]
176+ } ) ,
177+ None ,
178+ )
179+ . await ?;
140180 assert_eq ! ( status, StatusCode :: OK ) ;
141181 state = moved[ "state" ] . clone ( ) ;
142182 }
0 commit comments