From 070f7b9443b19885d3e7c38b8d56744dfd640e91 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 17:38:55 +0000 Subject: [PATCH] Retention: keep the current baselines of a branch pull requests target, however old (release branches) --- app/src/domain/retention.rs | 8 ++++++-- app/tests/retention.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/src/domain/retention.rs b/app/src/domain/retention.rs index 3e9b5c65..661fe5ba 100644 --- a/app/src/domain/retention.rs +++ b/app/src/domain/retention.rs @@ -8,8 +8,10 @@ //! - the newest completed CI build of each project and build name on the default branch, //! - every build a kept build reads groups from (`build_groups.source_build_id`): their rows are the kept build's //! unchanged snapshots, -//! - every current baseline: the newest baseline row per snapshot name on the default branch, and on each branch with -//! a build in the window, +//! - every current baseline: the newest baseline row per snapshot name on the default branch, on each branch with a +//! build in the window, and on each branch a pull request has targeted (a build's `base_branch`, such as a release +//! branch), however long ago: the next pull request into it compares with those, not an older build or the +//! default branch's. A feature branch's baselines go 90 days after its last build, //! - the snapshots those builds compared against (`base_snapshot_id`), //! - renders those snapshots use, and any render made in the window or not finished, //! - variants' images, and any blob created in the window (an upload a build hasn't claimed yet), @@ -111,6 +113,8 @@ async fn keep_sets(days: i32) -> laravel::Result<()> { WHERE bl.branch = p.default_branch OR EXISTS ( \ SELECT 1 FROM builds b WHERE b.project_id = bl.project_id AND b.branch = bl.branch \ AND b.created_at > now() - make_interval(days => {days})) \ + OR (bl.project_id, bl.branch) IN (SELECT DISTINCT project_id, base_branch FROM builds \ + WHERE base_branch IS NOT NULL) \ ORDER BY bl.project_id, bl.build_name, bl.name, bl.platform, bl.environment, bl.branch, bl.id DESC \ ) current WHERE snapshot_id IS NOT NULL \ ON CONFLICT DO NOTHING" diff --git a/app/tests/retention.rs b/app/tests/retention.rs index df9f962b..494cbc75 100644 --- a/app/tests/retention.rs +++ b/app/tests/retention.rs @@ -343,3 +343,36 @@ async fn no_mark_outlives(app: Application) -> laravel::Result<()> { assert!(Blob::query().filter(Blob::sha256.eq(registered)).first().await?.is_some(), "registered just now: kept"); Ok(()) } + +/// A release branch with no builds in the window keeps its current baselines while a pull request has ever targeted it: +/// the next pull request into it compares with them, not an older build or the default branch's. A feature branch's go. +#[laravel::test] +async fn retention_keeps_the_baselines_of_a_branch_pull_requests_target(app: Application) -> laravel::Result<()> { + fixtures::blob_store().await?; + let token = project_token().await?; + let release = build(&app, &token, "release-1", [255, 0, 0]).await; + let feature = build(&app, &token, "old-feature", [0, 0, 255]).await; + let pull = build(&app, &token, "fix-for-release", [0, 255, 0]).await; + for b in [&release, &feature, &pull] { + age(b).await?; + } + // Each branch's approved snapshot is its current baseline; the old pull request targeted release-1. + for b in [&release, &feature] { + let (project_id, build_id, branch, sha) = (b.project_id, b.id, b.branch.clone(), b.commit_sha.clone()); + db::query!( + "INSERT INTO baselines (project_id, build_name, name, platform, environment, branch, commit_sha, build_id, \ + snapshot_id, approval, created_at) \ + SELECT {project_id}, 'default', name, platform, environment, {branch}, {sha}, {build_id}, id, 'approved', \ + now() - interval '200 days' FROM snapshots WHERE build_id = {build_id}" + ) + .insert() + .await?; + } + let pull_id = pull.id; + db::query!("UPDATE builds SET base_branch = 'release-1', pr_number = 3 WHERE id = {pull_id}").update().await?; + + retention::prune(None, retention::RETENTION_DAYS, false).await?; + assert!(blob_of(&release).await.is_some(), "the release branch's baseline stays"); + assert!(blob_of(&feature).await.is_none(), "a feature branch's baseline goes with its last build"); + Ok(()) +}