@@ -247,17 +247,78 @@ fn human_output_exposes_unknown_reasons_and_live_counts() {
247247}
248248
249249#[ test]
250- fn filtered_empty_page_retains_unfiltered_unknown_counts ( ) {
250+ fn later_filtered_empty_page_retains_unfiltered_unknown_counts ( ) {
251251 let mut body = page ( ) ;
252252 body[ "state" ] = json ! ( "legacy" ) ;
253253 body[ "runs" ] = json ! ( [ ] ) ;
254254 body[ "returned_count" ] = json ! ( 0 ) ;
255255 let server = Server :: new ( info ( ) , Reply :: Json ( 200 , body. clone ( ) ) ) ;
256256 let mut query = args ( ) ;
257- query. extend ( [ "--state=legacy" , "--output=jsonl" ] ) ;
257+ query. extend ( [ "--state=legacy" , "--cursor=after-legacy" , "-- output=jsonl"] ) ;
258258 assert_eq ! ( success( & Scratch :: new( ) . run( & server, & query) ) , body) ;
259259}
260260
261+ #[ test]
262+ fn first_filtered_empty_page_requires_zero_selected_count ( ) {
263+ let scratch = Scratch :: new ( ) ;
264+ for legacy in [ 0 , 1 ] {
265+ let mut body = page ( ) ;
266+ body[ "state" ] = json ! ( "legacy" ) ;
267+ body[ "runs" ] = json ! ( [ ] ) ;
268+ body[ "returned_count" ] = json ! ( 0 ) ;
269+ body[ "counts" ] = json ! ( { "total" : 5 , "legacy" : legacy, "current" : 2 -legacy, "unknown" : 3 } ) ;
270+ let server = Server :: new ( info ( ) , Reply :: Json ( 200 , body. clone ( ) ) ) ;
271+ let mut query = args ( ) ;
272+ query. extend ( [ "--state=legacy" , "--output=json" ] ) ;
273+ let output = scratch. run ( & server, & query) ;
274+ if legacy == 0 {
275+ assert_eq ! ( success( & output) , body) ;
276+ } else {
277+ assert_failed ( & output) ;
278+ }
279+ }
280+ }
281+
282+ #[ test]
283+ fn truncated_first_terminal_pages_cannot_report_success ( ) {
284+ let scratch = Scratch :: new ( ) ;
285+ for mode in [ "--output=json" , "--output=jsonl" ] {
286+ let mut body = page ( ) ;
287+ body[ "runs" ] . as_array_mut ( ) . unwrap ( ) . pop ( ) ;
288+ body[ "returned_count" ] = json ! ( 4 ) ;
289+ let server = Server :: new ( info ( ) , Reply :: Json ( 200 , body. clone ( ) ) ) ;
290+ let mut query = args ( ) ;
291+ query. push ( mode) ;
292+ assert_failed ( & scratch. run ( & server, & query) ) ;
293+ // Later terminal pages cannot infer preceding cardinality from an
294+ // opaque cursor. Keep that valid live-page behavior available.
295+ query. push ( "--cursor=prior-opaque" ) ;
296+ assert_eq ! ( success( & scratch. run( & server, & query) ) , body) ;
297+ }
298+ }
299+
300+ #[ test]
301+ fn continuation_pages_must_fill_the_requested_limit ( ) {
302+ let scratch = Scratch :: new ( ) ;
303+ for limit in [ 5 , 50 ] {
304+ let mut body = page ( ) ;
305+ body[ "counts" ] = json ! ( { "total" : 100 , "legacy" : 1 , "current" : 1 , "unknown" : 98 } ) ;
306+ body[ "limit" ] = json ! ( limit) ;
307+ body[ "has_more" ] = json ! ( true ) ;
308+ body[ "next_cursor" ] = json ! ( "next-opaque" ) ;
309+ let server = Server :: new ( info ( ) , Reply :: Json ( 200 , body. clone ( ) ) ) ;
310+ let limit_arg = format ! ( "--limit={limit}" ) ;
311+ let mut query = args ( ) ;
312+ query. extend ( [ & limit_arg, "--output=json" ] ) ;
313+ let output = scratch. run ( & server, & query) ;
314+ if limit == 5 {
315+ assert_eq ! ( success( & output) , body) ;
316+ } else {
317+ assert_failed ( & output) ;
318+ }
319+ }
320+ }
321+
261322#[ test]
262323fn encodes_exact_query_values_and_namespace_without_following_cursor ( ) {
263324 let workflow_type = "Commande/é?&" ;
0 commit comments