@@ -343,3 +343,36 @@ async fn no_mark_outlives(app: Application) -> laravel::Result<()> {
343343 assert ! ( Blob :: query( ) . filter( Blob :: sha256. eq( registered) ) . first( ) . await ?. is_some( ) , "registered just now: kept" ) ;
344344 Ok ( ( ) )
345345}
346+
347+ /// A release branch with no builds in the window keeps its current baselines while a pull request has ever targeted it:
348+ /// the next pull request into it compares with them, not an older build or the default branch's. A feature branch's go.
349+ #[ laravel:: test]
350+ async fn retention_keeps_the_baselines_of_a_branch_pull_requests_target ( app : Application ) -> laravel:: Result < ( ) > {
351+ fixtures:: blob_store ( ) . await ?;
352+ let token = project_token ( ) . await ?;
353+ let release = build ( & app, & token, "release-1" , [ 255 , 0 , 0 ] ) . await ;
354+ let feature = build ( & app, & token, "old-feature" , [ 0 , 0 , 255 ] ) . await ;
355+ let pull = build ( & app, & token, "fix-for-release" , [ 0 , 255 , 0 ] ) . await ;
356+ for b in [ & release, & feature, & pull] {
357+ age ( b) . await ?;
358+ }
359+ // Each branch's approved snapshot is its current baseline; the old pull request targeted release-1.
360+ for b in [ & release, & feature] {
361+ let ( project_id, build_id, branch, sha) = ( b. project_id , b. id , b. branch . clone ( ) , b. commit_sha . clone ( ) ) ;
362+ db:: query!(
363+ "INSERT INTO baselines (project_id, build_name, name, platform, environment, branch, commit_sha, build_id, \
364+ snapshot_id, approval, created_at) \
365+ SELECT {project_id}, 'default', name, platform, environment, {branch}, {sha}, {build_id}, id, 'approved', \
366+ now() - interval '200 days' FROM snapshots WHERE build_id = {build_id}"
367+ )
368+ . insert ( )
369+ . await ?;
370+ }
371+ let pull_id = pull. id ;
372+ db:: query!( "UPDATE builds SET base_branch = 'release-1', pr_number = 3 WHERE id = {pull_id}" ) . update ( ) . await ?;
373+
374+ retention:: prune ( None , retention:: RETENTION_DAYS , false ) . await ?;
375+ assert ! ( blob_of( & release) . await . is_some( ) , "the release branch's baseline stays" ) ;
376+ assert ! ( blob_of( & feature) . await . is_none( ) , "a feature branch's baseline goes with its last build" ) ;
377+ Ok ( ( ) )
378+ }
0 commit comments