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 @@ -8,7 +8,7 @@
"plugins": [
{
"name": "visualci",
"version": "0.1.71",
"version": "0.1.72",
"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
10 changes: 2 additions & 8 deletions app/src/domain/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,13 @@ pub async fn finalize_shard(build: Build, shard: Option<i32>, allow_empty: bool)
)
.update()
.await?;
let finalized = db::query!(
db::query!(
"UPDATE builds SET state = 'processing', finalized_at = now(), updated_at = now() \
WHERE id = {id} AND state = 'receiving' AND jsonb_array_length(shards_finalized) >= shard_total"
)
.update()
.await?;
let build = Build::find_or_fail(id).await?;
// An empty rerun whose suite's earlier build was never finalized finalizes and follows that build.
if finalized > 0 {
super::reruns::adopt(&build).await?;
return Build::find_or_fail(id).await;
}
Ok(build)
Build::find_or_fail(id).await
}
.await;
result.or_else(server)
Expand Down
98 changes: 76 additions & 22 deletions app/src/domain/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ pub async fn run(build_id: i64, store: &BlobStore, renderer_version: &str) -> la
drop_unneeded_renders(id).await?;
return finished(id, build.project_id).await;
}
// A subset build whose branch's previous build of the suite went quiet while this one waited finalizes it now
// (sc-9763), outside the build's lock: that build's processing may run at once, and its result reaches this one.
if let Some(adopted) = Box::pin(super::reruns::adopt_on_branch(&build)).await? {
Box::pin(super::reruns::start(id, adopted)).await?;
}
let work = move || async move {
let build = Build::find_or_fail(id).await?;
if build.state != "processing" {
Expand Down Expand Up @@ -549,6 +554,11 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->
if let Some(done) = Box::pin(super::reruns::follow(&build)).await? {
return Ok(done);
}
// A subset build waits for the branch's previous build of its suite to conclude: its rows say which snapshots this
// build didn't send still carry an unreviewed change (sc-9763).
if super::reruns::waits_for_previous(&build).await? {
return Ok(false);
}
let mut snapshots: Vec<Snapshot> = Snapshot::query()
.filter(Snapshot::build_id.eq(id))
.order_by(Snapshot::name.asc())
Expand Down Expand Up @@ -688,11 +698,31 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->
removed.push(key.clone());
}
}
// A subset build's skipped snapshots that the branch's previous build changed or added without an approval carry
// that version, compared with the baseline, rather than the baseline itself: it still needs a review (sc-9763).
let unreviewed = super::reruns::unreviewed_carry(&build, &seen, &carry).await?;
let from_branch = unreviewed.as_ref().map(|u| &u.rows);
for (key, row) in from_branch.into_iter().flatten() {
if row.state == "removed" {
// Removed there without an approval: removed here too, not carried.
for keys in carried.values_mut() {
keys.retain(|k| k != key);
}
if base_snapshots.contains_key(key) && !removed.contains(key) {
removed.push(key.clone());
}
} else if !base_snapshots.contains_key(key) {
carried.entry(grouping.key(&key.0)).or_default().push(key.clone());
}
}
carried.retain(|_, keys| !keys.is_empty());
let branch_groups: HashSet<String> =
from_branch.into_iter().flat_map(HashMap::keys).map(|k| grouping.key(&k.0)).collect();
// A carried group the build sent nothing of, whose baselines one earlier build holds exactly, is read from that
// build: no rows are written for it (docs/design-storage.md).
let mut candidates = BTreeMap::new();
for (group, keys) in &carried {
if sent_keys.contains(group) || build.mode != "ci" {
if sent_keys.contains(group) || build.mode != "ci" || branch_groups.contains(group) {
continue;
}
let bases: Vec<&Snapshot> = keys.iter().filter_map(|k| base_snapshots.get(k)).collect();
Expand All @@ -712,8 +742,10 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->
continue;
}
for key in keys {
let Some(base) = base_snapshots.get(key) else { continue };
Box::pin(carry_forward(&build, &settings, store, base)).await?;
let base = base_snapshots.get(key);
let theirs = from_branch.and_then(|rows| rows.get(key)).filter(|s| s.state != "removed");
let Some(source) = theirs.or(base) else { continue };
Box::pin(carry_forward(&build, &settings, store, source, base)).await?;
}
}
for (name, platform) in &removed {
Expand All @@ -734,9 +766,21 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->
.await?;
}

// A change the branch's previous build had rejected stays rejected, carried or removed.
if let Some(unreviewed) = &unreviewed {
super::reruns::keep_rejections(id, unreviewed).await?;
}

// The file's settings: a loosening ci_mode it can't use, ignore rules that matched nothing, and whether they hide
// more than the base build's (then the build gets a "visualci.yml" item to review).
let mut warnings = settings.config_warnings();
if let Some(u) = unreviewed.as_ref().filter(|u| !u.rows.is_empty()) {
warnings.push(super::reruns::unreviewed_carry_warning(u.rows.len(), u.number));
}
if let Some(number) = unreviewed.as_ref().and_then(|u| u.unfinished) {
warnings.push(super::reruns::unfinished_previous_warning(number));
}
let hold = unreviewed.as_ref().is_some_and(|u| u.unfinished.is_some());
let names: Vec<String> = super::snapshots::of_build(id).await?.into_iter().map(|s| s.name).collect();
if settings.scoped_rules().0 == Source::File {
for rule in settings.unmatched_rules(names.iter().map(String::as_str)) {
Expand Down Expand Up @@ -817,7 +861,7 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->

let warnings = warnings.clone();
update!(build { warnings }).await?;
let build = conclude(build, &project.default_branch, base_build_id, has_base, sent).await?;
let build = conclude(build, &project.default_branch, base_build_id, has_base, sent, hold).await?;
if build.review_state == "auto_approved" {
// 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?;
Expand All @@ -840,29 +884,31 @@ pub async fn process(build: Build, store: &BlobStore, renderer_version: &str) ->
concluded
}

/// Carry a base snapshot forward into a build as its own row, compared with the base (unchanged).
/// Carry a snapshot the build didn't send into it as its own row, compared with its base: the base itself (unchanged),
/// or the branch's previous build's unapproved version of it (changed, or added when there's no base).
async fn carry_forward(
build: &Build,
settings: &BuildSettings<'_>,
store: &BlobStore,
base: &Snapshot,
source: &Snapshot,
base: Option<&Snapshot>,
) -> laravel::Result<()> {
let (id, pid) = (build.id, laravel::str::uuid7());
let group_key = groups::grouping(build.group_depth).key(&base.name);
let group_key = groups::grouping(build.group_depth).key(&source.name);
let (name, platform, kind, format, fingerprint, blob, render_id, engine, rules, environment, threshold, aa, meta) = (
&base.name,
&base.platform,
&base.kind,
&base.format,
&base.source_fingerprint,
&base.source_blob,
base.render_id,
&base.engine,
&base.ignore_rules,
&base.environment,
base.threshold,
base.ignore_anti_aliasing,
&base.meta,
&source.name,
&source.platform,
&source.kind,
&source.format,
&source.source_fingerprint,
&source.source_blob,
source.render_id,
&source.engine,
&source.ignore_rules,
&source.environment,
source.threshold,
source.ignore_anti_aliasing,
&source.meta,
);
// A second run of this processing (the job retried after a run that stopped part-way) finds the row there
// already: it compares it again only when that run stopped before comparing it.
Expand All @@ -884,7 +930,7 @@ async fn carry_forward(
if inserted == 0 && !(carried.carried_forward && carried.state == "pending") {
return Ok(());
}
if let Err(e) = compare(&mut carried, store, settings, Some(base)).await {
if let Err(e) = compare(&mut carried, store, settings, base).await {
tracing::warn!(build = id, snapshot = carried.id, error = %e, "carrying a snapshot forward failed");
mark_failed(&mut carried, &format!("comparison failed: {e}")).await?;
}
Expand Down Expand Up @@ -916,19 +962,22 @@ 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".
/// `hold`: the build can't be known to be clean (the branch's previous build was still processing,
/// `reruns::unfinished_previous_warning`), so it waits for a review rather than passing or being approved on its own.
async fn conclude(
mut build: Build,
default_branch: &str,
base_build_id: Option<i64>,
has_base: bool,
sent: i64,
hold: bool,
) -> laravel::Result<Build> {
let all = super::snapshots::of_build(build.id).await?;
let stats = stats_of(&all);
let empty = sent == 0 && !build.allow_empty;
let conclusion = if stats.failed > 0 || empty {
"failed"
} else if stats.changes() > 0 {
} else if stats.changes() > 0 || hold {
"changes"
} else {
"unchanged"
Expand All @@ -938,8 +987,13 @@ async fn conclude(
// 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;
// A carried (or removed) change the branch's previous build had rejected keeps its rejection
// (`reruns::keep_rejections`): nothing else in a build being concluded has been reviewed.
let rejected = all.iter().any(|s| is_change(s) && s.review.as_deref() == Some("rejected"));
let review_state = match conclusion {
"failed" => "none",
_ if rejected => "rejected",
_ if hold => "pending",
"unchanged" => "auto_approved",
_ if first_on_default => "auto_approved",
_ => "pending",
Expand Down
Loading
Loading