Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions server/src/models/baselines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,17 @@ pub async fn resolve(
};
let after = anchor.as_ref().map_or(0, |a| a.id);

// Approvals newer than the anchor: CI ones on the ancestry, and any on this branch. For local environments also
// Approvals newer than the anchor: CI ones on the ancestry, and any on this branch. A merged pull request's
// approvals (`record_merge`) count only through their merge commit's place in this build's history: on the base
// branch they'd otherwise reach builds of commits from before the merge, which then show the merge's new snapshots
// as removed (sc-8806: main's #122, built late, showed PR 25's slider screenshots removed). For local environments also
// older ones, since the anchor (a CI build) doesn't carry their screenshots. Local approvals apply only to their
// own branch; on the default branch only CI approvals count for other branches.
let rows = Entity::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
"SELECT * FROM baselines WHERE project_id = $1 AND build_name = $2 AND build_id <> $3 AND ( \
(build_id > $4 AND ((mode = 'ci' AND commit_sha = ANY($5)) OR branch = $6)) \
(build_id > $4 AND approval <> 'merged' AND ((mode = 'ci' AND commit_sha = ANY($5)) OR branch = $6)) \
OR (approval = 'merged' AND commit_sha = ANY($5)) \
OR (environment NOT IN ('', 'ci') AND (branch = $6 OR (branch = $7 AND mode = 'ci'))) \
) ORDER BY id",
Expand Down
39 changes: 39 additions & 0 deletions server/tests/requests/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,45 @@ async fn a_pr_build_says_which_changes_are_mains_unreviewed_ones() {
.await;
}

/// A merged pull request's approvals count only for builds whose history has the merge. A main build of an older
/// commit, built after the merge (main's CI runs late), and a pull request built on top of it, don't show the merge's
/// new snapshot as removed; the merge commit's own build finds it approved (sc-8806: main's #122 and PR 27's #123
/// showed PR 25's slider screenshots removed).
#[tokio::test]
#[serial]
async fn a_merge_does_not_leak_into_older_builds_of_its_base_branch() {
request::<App, _, _>(|_request, ctx| async move {
let Some(w) = world(&ctx).await else { return };
let a = w.build("A", "main", None, &[], &[("x", png(RED))]).await;
a.review(w.db, None, &builds::Via::default(), "approve", None, None).await.unwrap();
// PR 1 adds y; it's approved and merged at M1.
let p1 = w.build("P1", "one", Some(1), &["A"], &[("x", png(RED)), ("y", png(BLUE))]).await;
p1.review(w.db, None, &builds::Via::default(), "approve", None, None).await.unwrap();
visualci_server::models::baselines::record_merge(w.db, w.project.id, "one", "main", "M1").await.unwrap();

let states = |b: builds::Model| async move {
snapshots::Model::for_build(w.db, b.id)
.await
.unwrap()
.into_iter()
.map(|s| (s.name, s.state))
.collect::<Vec<_>>()
};
// Main's build of an older commit, B (before the merge), processed after it.
let b = w.build("B", "main", None, &["A"], &[("x", png(RED))]).await;
assert_eq!(states(b).await, vec![("x".to_string(), "unchanged".to_string())], "y isn't B's to remove");
// A pull request on top of B.
let q = w.build("Q", "two", Some(2), &["B", "A"], &[("x", png(RED))]).await;
assert_eq!(states(q).await, vec![("x".to_string(), "unchanged".to_string())]);
// The merge commit's own build: y as PR 1 approved it.
let m = w.build("M1", "main", None, &["B", "A"], &[("x", png(RED)), ("y", png(BLUE))]).await;
let mut got = states(m).await;
got.sort();
assert_eq!(got, vec![("x".to_string(), "unchanged".to_string()), ("y".to_string(), "unchanged".to_string())]);
})
.await;
}

fn png_color(v: u8) -> [u8; 3] {
[v, v, v]
}
Loading