Skip to content

Commit 71cf4ef

Browse files
committed
app/: nothing becomes a baseline unreviewed: no cross-branch fallback; only the default branch's first build is auto-approved
A pull request branch's first CI build with no base now waits for review (it was auto-approved on any branch and its snapshots recorded as baselines). baselines::resolve no longer takes any branch's latest CI approval for a snapshot with no baseline on its history, and the exact-match passes in compare.rs count only the build's own branch's approvals and the default branch's CI ones. A pull request's approvals reach its base branch only through record_merge, at the merge commit.
1 parent 261b989 commit 71cf4ef

23 files changed

Lines changed: 268 additions & 85 deletions

File tree

‎.claude-plugin/marketplace.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"plugins": [
66
{
77
"name": "visualci",
8-
"version": "0.1.46",
8+
"version": "0.1.47",
99
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
1010
"author": { "name": "DocSpring", "url": "https://visualci.com" },
1111
"homepage": "https://visualci.com/docs/skills/",

‎.claude-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "visualci",
3-
"version": "0.1.46",
3+
"version": "0.1.47",
44
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
55
"author": { "name": "DocSpring", "url": "https://visualci.com" },
66
"homepage": "https://visualci.com/docs/skills/",

‎.cursor-plugin/plugin.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "visualci",
33
"displayName": "VisualCI",
4-
"version": "0.1.46",
4+
"version": "0.1.47",
55
"description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.",
66
"author": {
77
"name": "DocSpring"

‎app/src/domain/baselines.rs‎

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
//! build, commit, branch, environment and mode it came from. Rows newer than the anchor are laid on top: CI
1111
//! approvals on the build's ancestry, and any approval on the build's own branch. A local approval counts on its
1212
//! own branch only, never through ancestry.
13+
//! 3. **Merges**: a pull request's approvals reach its base branch only when it merges ([`record_merge`] copies them
14+
//! to the merge commit), and count through that commit's place in a build's history. Nothing is taken from an
15+
//! unrelated branch, and only the default branch's first build is approved without review.
1316
//!
1417
//! Documents and text are the same everywhere and keep one shared set (environment `""`). Screenshots keep a set per
1518
//! environment: CI's comes from the anchor and CI approvals; a laptop's from its own approvals on the branch (or CI
@@ -269,50 +272,6 @@ pub async fn resolve(
269272
}
270273
}
271274

272-
// Last: a snapshot this build sent that has no baseline on its history takes the suite's latest current CI
273-
// approval of it from any branch. That's a squash-merged pull request's approval: its commits aren't ancestors of
274-
// the default branch's, but what it approved is what the default branch now has.
275-
let sent: Vec<(String, String, String)> = Snapshot::query()
276-
.filter(Snapshot::build_id.eq(build.id) & Snapshot::carried_forward.eq(false))
277-
.get()
278-
.await?
279-
.into_iter()
280-
.filter(|s| !is_config_item(s))
281-
.map(|s| (s.name, s.platform, s.environment))
282-
.collect();
283-
let missing: Vec<&(String, String, String)> =
284-
sent.iter().filter(|(n, p, _)| !chosen.contains_key(&(n.clone(), p.clone()))).collect();
285-
if !missing.is_empty() {
286-
let mut names: Vec<String> = missing.iter().map(|(n, _, _)| n.clone()).collect();
287-
names.sort();
288-
names.dedup();
289-
let mut rows: Vec<Baseline> = Vec::new();
290-
for chunk in names.chunks(10_000) {
291-
let chunk = chunk.to_vec();
292-
let found: Vec<Baseline> = db::query!(
293-
"SELECT DISTINCT ON (name, platform, environment) * FROM baselines bl \
294-
WHERE project_id = {project_id} AND build_name = {build_name} AND build_id <> {id} AND mode = 'ci' \
295-
AND name IN ({...chunk}) \
296-
AND NOT EXISTS (SELECT 1 FROM baselines b2 WHERE b2.project_id = bl.project_id \
297-
AND b2.build_name = bl.build_name AND b2.name = bl.name AND b2.platform = bl.platform \
298-
AND b2.environment = bl.environment AND b2.branch = bl.branch AND b2.id > bl.id) \
299-
ORDER BY name, platform, environment, id DESC"
300-
)
301-
.select_as()
302-
.await?;
303-
rows.extend(found);
304-
}
305-
for (name, platform, environment) in missing {
306-
let order = search_order(environment);
307-
let row = order.iter().find_map(|env| {
308-
rows.iter().find(|r| &r.name == name && &r.platform == platform && &r.environment == env)
309-
});
310-
if let Some(r) = row.filter(|r| r.snapshot_id.is_some()) {
311-
chosen.insert((name.clone(), platform.clone()), (Some(r.clone()), r.snapshot_id));
312-
}
313-
}
314-
}
315-
316275
let ids: Vec<i64> = chosen.values().filter_map(|(_, id)| *id).collect();
317276
let mut snapshots = load(&ids).await?;
318277
let resolved = chosen

‎app/src/domain/compare.rs‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use crate::models::{Blob, IgnoredChange, Project, Snapshot, Variant};
1313
use crate::storage::BlobStore;
1414

1515
/// The exact-match passes below take a baseline row `bl` only when it's current for the snapshot's build: the same
16-
/// suite, a CI approval or one from the build's own branch (local approvals count on their own branch only), and not
17-
/// superseded by a later approval of the same snapshot on the same branch and environment. (Rejected approvals are
18-
/// deleted.)
16+
/// suite, a CI approval on the default branch or one from the build's own branch (local approvals count on their own
17+
/// branch only, and another branch's never count), and not superseded by a later approval of the same snapshot on the
18+
/// same branch and environment. (Rejected approvals are deleted.)
1919
/// The snapshot's pages: a document's rendered pages, or an image or a text as a single page.
2020
///
2121
/// # Errors
@@ -216,14 +216,15 @@ async fn page_state(
216216
if base.text == head.text {
217217
return Ok(("unchanged", None, None));
218218
}
219-
// Exactly this text was approved for this snapshot elsewhere in the project (a squash-merged pull request's
220-
// branch): it passes, as an image would.
219+
// Exactly this text was approved for this snapshot on the build's own branch or the default branch (in
220+
// another environment, or before a change since): it passes, as an image would.
221221
let fingerprint = snapshot.source_fingerprint.as_str();
222222
let approved: Option<i32> = db::query!(
223223
"SELECT 1 FROM baselines bl JOIN snapshots s ON s.id = bl.snapshot_id \
224224
WHERE bl.project_id = {project_id} AND bl.name = {name} AND bl.platform = {platform} \
225225
AND s.source_fingerprint = {fingerprint} AND bl.build_name = (SELECT name FROM builds WHERE id = {build_id}) \
226-
AND (bl.mode = 'ci' OR bl.branch = (SELECT branch FROM builds WHERE id = {build_id})) \
226+
AND (bl.branch = (SELECT branch FROM builds WHERE id = {build_id}) \
227+
OR (bl.mode = 'ci' AND bl.branch = (SELECT default_branch FROM projects WHERE id = {project_id}))) \
227228
AND NOT EXISTS (SELECT 1 FROM baselines b2 WHERE b2.project_id = bl.project_id \
228229
AND b2.build_name = bl.build_name AND b2.name = bl.name AND b2.platform = bl.platform \
229230
AND b2.environment = bl.environment AND b2.branch = bl.branch AND b2.id > bl.id) LIMIT 1"
@@ -251,17 +252,19 @@ async fn page_state(
251252
if is_variant {
252253
return Ok(("variant", None, None));
253254
}
254-
// Approved before: a current baseline, in any environment, branch or commit of the suite, with exactly this image
255-
// for this snapshot: its own environment's first, then CI's. Covers squash merges and other environments (a Linux
256-
// agent's screenshot that matches the approved Mac one passes).
255+
// Approved before: a current baseline, in any environment, on the build's own branch or the default branch, with
256+
// exactly this image for this snapshot: its own environment's first, then CI's. Covers other environments (a Linux
257+
// agent's screenshot that matches the approved Mac one passes). Another branch's approvals never count: a pull
258+
// request's reach the default branch only at its merge (`baselines::record_merge`).
257259
let image = head.image.as_str();
258260
let environment = snapshot.environment.as_str();
259261
let approved: Option<String> = db::query!(
260262
"SELECT s.environment FROM baselines bl \
261263
JOIN snapshots s ON s.id = bl.snapshot_id JOIN snapshot_pages p ON p.snapshot_id = s.id \
262264
WHERE bl.project_id = {project_id} AND bl.name = {name} AND bl.platform = {platform} AND p.head_image = {image} \
263265
AND bl.build_name = (SELECT name FROM builds WHERE id = {build_id}) \
264-
AND (bl.mode = 'ci' OR bl.branch = (SELECT branch FROM builds WHERE id = {build_id})) \
266+
AND (bl.branch = (SELECT branch FROM builds WHERE id = {build_id}) \
267+
OR (bl.mode = 'ci' AND bl.branch = (SELECT default_branch FROM projects WHERE id = {project_id}))) \
265268
AND NOT EXISTS (SELECT 1 FROM baselines b2 WHERE b2.project_id = bl.project_id \
266269
AND b2.build_name = bl.build_name AND b2.name = bl.name AND b2.platform = bl.platform \
267270
AND b2.environment = bl.environment AND b2.branch = bl.branch AND b2.id > bl.id) \

‎app/src/domain/processing.rs‎

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->
500500

501501
let warnings = warnings.clone();
502502
update!(build { warnings }).await?;
503-
let build = conclude(build, base_build_id, has_base, sent).await?;
503+
let build = conclude(build, &project.default_branch, base_build_id, has_base, sent).await?;
504504
if build.review_state == "auto_approved" {
505-
// Nothing to review (or the project's first build): its changes are the baselines now.
505+
// Nothing to review (or the default branch's first build): its changes are the baselines now.
506506
let all = super::snapshots::of_build(build.id).await?;
507507
let changes: Vec<&Snapshot> = all.iter().filter(|s| !is_config_item(s)).collect();
508508
baselines::record(&build, &changes, None, None, "auto").await?;
@@ -588,7 +588,13 @@ pub fn stats_of(snapshots: &[Snapshot]) -> Stats {
588588

589589
/// Count snapshot states, set the conclusion and review state, and mark the build completed. `sent` is how many
590590
/// snapshots the build was sent itself: none means the upload found nothing, which mustn't pass as "unchanged".
591-
async fn conclude(mut build: Build, base_build_id: Option<i64>, has_base: bool, sent: i64) -> laravel::Result<Build> {
591+
async fn conclude(
592+
mut build: Build,
593+
default_branch: &str,
594+
base_build_id: Option<i64>,
595+
has_base: bool,
596+
sent: i64,
597+
) -> laravel::Result<Build> {
592598
let all = super::snapshots::of_build(build.id).await?;
593599
let stats = stats_of(&all);
594600
let empty = sent == 0 && !build.allow_empty;
@@ -599,11 +605,15 @@ async fn conclude(mut build: Build, base_build_id: Option<i64>, has_base: bool,
599605
} else {
600606
"unchanged"
601607
};
602-
// A local run's changes always wait for review, even in a project's first build: approving one sets the baseline
603-
// for its branch and environment.
604-
let review_state = match (build.mode.as_str(), conclusion, has_base) {
605-
(_, "failed", _) => "none",
606-
(_, "unchanged", _) | ("ci", _, false) => "auto_approved",
608+
// Nothing becomes a baseline unreviewed. Only a CI build on the default branch with nothing to compare against
609+
// (the project's first) is approved as it is. Another branch's first build waits for review: its approvals reach
610+
// the default branch only when its pull request merges (`baselines::record_merge`). A local run's changes always
611+
// wait for review: approving one sets the baseline for its branch and environment.
612+
let first_on_default = build.mode == "ci" && !has_base && build.branch == default_branch;
613+
let review_state = match conclusion {
614+
"failed" => "none",
615+
"unchanged" => "auto_approved",
616+
_ if first_on_default => "auto_approved",
607617
_ => "pending",
608618
};
609619
let stats = serde_json::to_value(&stats).unwrap_or_default();

0 commit comments

Comments
 (0)