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
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"plugins": [
{
"name": "visualci",
"version": "0.1.46",
"version": "0.1.47",
"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.",
"author": { "name": "DocSpring", "url": "https://visualci.com" },
"homepage": "https://visualci.com/docs/skills/",
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "visualci",
"version": "0.1.46",
"version": "0.1.47",
"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.",
"author": { "name": "DocSpring", "url": "https://visualci.com" },
"homepage": "https://visualci.com/docs/skills/",
Expand Down
2 changes: 1 addition & 1 deletion .cursor-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "visualci",
"displayName": "VisualCI",
"version": "0.1.46",
"version": "0.1.47",
"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.",
"author": {
"name": "DocSpring"
Expand Down
47 changes: 3 additions & 44 deletions app/src/domain/baselines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
//! build, commit, branch, environment and mode it came from. Rows newer than the anchor are laid on top: CI
//! approvals on the build's ancestry, and any approval on the build's own branch. A local approval counts on its
//! own branch only, never through ancestry.
//! 3. **Merges**: a pull request's approvals reach its base branch only when it merges ([`record_merge`] copies them
//! to the merge commit), and count through that commit's place in a build's history. Nothing is taken from an
//! unrelated branch, and only the default branch's first build is approved without review.
//!
//! Documents and text are the same everywhere and keep one shared set (environment `""`). Screenshots keep a set per
//! environment: CI's comes from the anchor and CI approvals; a laptop's from its own approvals on the branch (or CI
Expand Down Expand Up @@ -269,50 +272,6 @@ pub async fn resolve(
}
}

// Last: a snapshot this build sent that has no baseline on its history takes the suite's latest current CI
// approval of it from any branch. That's a squash-merged pull request's approval: its commits aren't ancestors of
// the default branch's, but what it approved is what the default branch now has.
let sent: Vec<(String, String, String)> = Snapshot::query()
.filter(Snapshot::build_id.eq(build.id) & Snapshot::carried_forward.eq(false))
.get()
.await?
.into_iter()
.filter(|s| !is_config_item(s))
.map(|s| (s.name, s.platform, s.environment))
.collect();
let missing: Vec<&(String, String, String)> =
sent.iter().filter(|(n, p, _)| !chosen.contains_key(&(n.clone(), p.clone()))).collect();
if !missing.is_empty() {
let mut names: Vec<String> = missing.iter().map(|(n, _, _)| n.clone()).collect();
names.sort();
names.dedup();
let mut rows: Vec<Baseline> = Vec::new();
for chunk in names.chunks(10_000) {
let chunk = chunk.to_vec();
let found: Vec<Baseline> = db::query!(
"SELECT DISTINCT ON (name, platform, environment) * FROM baselines bl \
WHERE project_id = {project_id} AND build_name = {build_name} AND build_id <> {id} AND mode = 'ci' \
AND name IN ({...chunk}) \
AND NOT EXISTS (SELECT 1 FROM baselines b2 WHERE b2.project_id = bl.project_id \
AND b2.build_name = bl.build_name AND b2.name = bl.name AND b2.platform = bl.platform \
AND b2.environment = bl.environment AND b2.branch = bl.branch AND b2.id > bl.id) \
ORDER BY name, platform, environment, id DESC"
)
.select_as()
.await?;
rows.extend(found);
}
for (name, platform, environment) in missing {
let order = search_order(environment);
let row = order.iter().find_map(|env| {
rows.iter().find(|r| &r.name == name && &r.platform == platform && &r.environment == env)
});
if let Some(r) = row.filter(|r| r.snapshot_id.is_some()) {
chosen.insert((name.clone(), platform.clone()), (Some(r.clone()), r.snapshot_id));
}
}
}

let ids: Vec<i64> = chosen.values().filter_map(|(_, id)| *id).collect();
let mut snapshots = load(&ids).await?;
let resolved = chosen
Expand Down
23 changes: 13 additions & 10 deletions app/src/domain/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::models::{Blob, IgnoredChange, Project, Snapshot, Variant};
use crate::storage::BlobStore;

/// The exact-match passes below take a baseline row `bl` only when it's current for the snapshot's build: the same
/// suite, a CI approval or one from the build's own branch (local approvals count on their own branch only), and not
/// superseded by a later approval of the same snapshot on the same branch and environment. (Rejected approvals are
/// deleted.)
/// suite, a CI approval on the default branch or one from the build's own branch (local approvals count on their own
/// branch only, and another branch's never count), and not superseded by a later approval of the same snapshot on the
/// same branch and environment. (Rejected approvals are deleted.)
/// The snapshot's pages: a document's rendered pages, or an image or a text as a single page.
///
/// # Errors
Expand Down Expand Up @@ -216,14 +216,15 @@ async fn page_state(
if base.text == head.text {
return Ok(("unchanged", None, None));
}
// Exactly this text was approved for this snapshot elsewhere in the project (a squash-merged pull request's
// branch): it passes, as an image would.
// Exactly this text was approved for this snapshot on the build's own branch or the default branch (in
// another environment, or before a change since): it passes, as an image would.
let fingerprint = snapshot.source_fingerprint.as_str();
let approved: Option<i32> = db::query!(
"SELECT 1 FROM baselines bl JOIN snapshots s ON s.id = bl.snapshot_id \
WHERE bl.project_id = {project_id} AND bl.name = {name} AND bl.platform = {platform} \
AND s.source_fingerprint = {fingerprint} AND bl.build_name = (SELECT name FROM builds WHERE id = {build_id}) \
AND (bl.mode = 'ci' OR bl.branch = (SELECT branch FROM builds WHERE id = {build_id})) \
AND (bl.branch = (SELECT branch FROM builds WHERE id = {build_id}) \
OR (bl.mode = 'ci' AND bl.branch = (SELECT default_branch FROM projects WHERE id = {project_id}))) \
AND NOT EXISTS (SELECT 1 FROM baselines b2 WHERE b2.project_id = bl.project_id \
AND b2.build_name = bl.build_name AND b2.name = bl.name AND b2.platform = bl.platform \
AND b2.environment = bl.environment AND b2.branch = bl.branch AND b2.id > bl.id) LIMIT 1"
Expand Down Expand Up @@ -251,17 +252,19 @@ async fn page_state(
if is_variant {
return Ok(("variant", None, None));
}
// Approved before: a current baseline, in any environment, branch or commit of the suite, with exactly this image
// for this snapshot: its own environment's first, then CI's. Covers squash merges and other environments (a Linux
// agent's screenshot that matches the approved Mac one passes).
// Approved before: a current baseline, in any environment, on the build's own branch or the default branch, with
// exactly this image for this snapshot: its own environment's first, then CI's. Covers other environments (a Linux
// agent's screenshot that matches the approved Mac one passes). Another branch's approvals never count: a pull
// request's reach the default branch only at its merge (`baselines::record_merge`).
let image = head.image.as_str();
let environment = snapshot.environment.as_str();
let approved: Option<String> = db::query!(
"SELECT s.environment FROM baselines bl \
JOIN snapshots s ON s.id = bl.snapshot_id JOIN snapshot_pages p ON p.snapshot_id = s.id \
WHERE bl.project_id = {project_id} AND bl.name = {name} AND bl.platform = {platform} AND p.head_image = {image} \
AND bl.build_name = (SELECT name FROM builds WHERE id = {build_id}) \
AND (bl.mode = 'ci' OR bl.branch = (SELECT branch FROM builds WHERE id = {build_id})) \
AND (bl.branch = (SELECT branch FROM builds WHERE id = {build_id}) \
OR (bl.mode = 'ci' AND bl.branch = (SELECT default_branch FROM projects WHERE id = {project_id}))) \
AND NOT EXISTS (SELECT 1 FROM baselines b2 WHERE b2.project_id = bl.project_id \
AND b2.build_name = bl.build_name AND b2.name = bl.name AND b2.platform = bl.platform \
AND b2.environment = bl.environment AND b2.branch = bl.branch AND b2.id > bl.id) \
Expand Down
26 changes: 18 additions & 8 deletions app/src/domain/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,9 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->

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

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