@@ -61,7 +61,7 @@ fn judge(endpoint: String) -> JudgeConfig {
6161 thresholds : vec ! [ ] ,
6262 timeout_ms : 1000 ,
6363 origins : vec ! [ Origin :: Operator ] ,
64- max_requests : 2 ,
64+ max_requests : 3 ,
6565 budget_window_ms : 60_000 ,
6666 cache_entries : 10 ,
6767 cache_ttl_ms : 1000 ,
@@ -120,6 +120,7 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
120120 verify_fallback ( & proxy, & stub, & store) . await ?;
121121 let mut invalid = configuration. clone ( ) ;
122122 invalid. judge . as_mut ( ) . ok_or ( "judge" ) ?. endpoint = "http://not-loopback.invalid/jev" . into ( ) ;
123+ invalid. judge . as_mut ( ) . ok_or ( "judge" ) ?. credential = Secret ( "invalid-candidate-key" . into ( ) ) ;
123124 assert ! (
124125 lifecycle
125126 . reinitialize( & loaded. name, serde_json:: to_value( invalid) ?)
@@ -128,10 +129,11 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
128129 ) ;
129130 let info: PolicyInfo = proxy. call ( names:: methods:: POLICY_INFO , ( ) ) . await ?;
130131 assert_eq ! ( info. generation, 2 ) ;
132+ verify_retained_scoring ( & proxy, & stub) . await ?;
131133 prompt_failure. store ( true , Ordering :: SeqCst ) ;
132134 assert ! (
133135 proxy
134- . call:: <EvaluateApprovalResponse2 >( names:: methods:: EVALUATE_APPROVAL2 , ( begin( 7 , 8 ) , ) )
136+ . call:: <EvaluateApprovalResponse2 >( names:: methods:: EVALUATE_APPROVAL2 , ( begin( 7 , 10 ) , ) )
135137 . await
136138 . is_err( )
137139 ) ;
@@ -161,6 +163,64 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
161163 Ok ( ( ) )
162164}
163165
166+ async fn verify_retained_scoring (
167+ proxy : & tinybus:: Proxy ,
168+ stub : & stub:: Stub ,
169+ ) -> std:: result:: Result < ( ) , Box < dyn std:: error:: Error > > {
170+ * stub. response . lock ( ) . map_err ( |_| "stub" ) ? = ( 200 , stub:: response ( [ 1.0 , 1.0 , 0.0 ] ) ) ;
171+ let retained: EvaluateApprovalResponse2 = proxy
172+ . call ( names:: methods:: EVALUATE_APPROVAL2 , ( begin ( 9 , 7 ) , ) )
173+ . await ?;
174+ assert_eq ! ( retained. decision. verdict, Verdict :: Allow ) ;
175+ assert_eq ! ( retained. record. attribution. as_deref( ) , Some ( "auto:jev" ) ) ;
176+ assert ! ( retained. record. decision_ticket_sha256. is_none( ) ) ;
177+ let evidence = retained
178+ . record
179+ . judge
180+ . as_ref ( )
181+ . ok_or ( "retained scorer evidence" ) ?;
182+ assert_eq ! ( evidence. outcome, JudgeOutcome2 :: Qualified ) ;
183+ assert_eq ! ( evidence. scores_millionths, Some ( [ 1_000_000 , 1_000_000 , 0 ] ) ) ;
184+ {
185+ let captured = stub. requests . lock ( ) . map_err ( |_| "stub" ) ?;
186+ assert_eq ! (
187+ captured. len( ) ,
188+ 3 ,
189+ "fresh identity must use retained SDK endpoint and credential"
190+ ) ;
191+ assert_eq ! (
192+ captured. last( ) . ok_or( "retained SDK request" ) ?[ "model" ] ,
193+ "jev-latest"
194+ ) ;
195+ }
196+ let consumed: ApprovalRow2 = proxy
197+ . call (
198+ names:: methods:: CONSUME_APPROVAL2 ,
199+ ( ApprovalActionRequest2 {
200+ scope_id : "a" . repeat ( 32 ) ,
201+ request_id : retained. record . request_id ,
202+ request : begin ( 9 , 8 ) . request ,
203+ audit : audit ( 8 ) ,
204+ } , ) ,
205+ )
206+ . await ?;
207+ assert_eq ! ( consumed. state, ApprovalLifecycle2 :: Reserved ) ;
208+ let budget: EvaluateApprovalResponse2 = proxy
209+ . call ( names:: methods:: EVALUATE_APPROVAL2 , ( begin ( 6 , 9 ) , ) )
210+ . await ?;
211+ assert_eq ! (
212+ budget
213+ . record
214+ . judge
215+ . as_ref( )
216+ . ok_or( "budget evidence" ) ?
217+ . outcome,
218+ JudgeOutcome2 :: Budget
219+ ) ;
220+ assert_eq ! ( stub. requests. lock( ) . map_err( |_| "stub" ) ?. len( ) , 3 ) ;
221+ Ok ( ( ) )
222+ }
223+
164224fn configuration (
165225 host : & Connection ,
166226 root : & std:: path:: Path ,
@@ -297,18 +357,6 @@ async fn verify_fallback(
297357 . await ?;
298358 assert_eq ! ( human. state, ApprovalLifecycle2 :: Approved ) ;
299359 assert ! ( human. decision_ticket_sha256. is_some( ) ) ;
300- let budget: EvaluateApprovalResponse2 = proxy
301- . call ( names:: methods:: EVALUATE_APPROVAL2 , ( begin ( 6 , 7 ) , ) )
302- . await ?;
303- assert_eq ! (
304- budget
305- . record
306- . judge
307- . as_ref( )
308- . ok_or( "budget evidence" ) ?
309- . outcome,
310- JudgeOutcome2 :: Budget
311- ) ;
312360 Ok ( ( ) )
313361}
314362
0 commit comments