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

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.26",
"version": "0.1.27",
"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.26",
"version": "0.1.27",
"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.26",
"version": "0.1.27",
"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
2 changes: 1 addition & 1 deletion gemini-extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "visualci",
"version": "0.1.26",
"version": "0.1.27",
"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.",
"mcpServers": {
"visualci": {
Expand Down
2 changes: 1 addition & 1 deletion server/frontend/content/docs/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \
4. The agent checks each change against the code and the task:
- **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed.
- **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline.
5. `snapshot_history` shows one snapshot across recent builds, which helps find when a page started changing.
5. `snapshot_history` shows one snapshot across recent builds, which helps find when a page started changing. `get_build` marks a change `flaky: true` when its content flipped back and forth over the branch's recent builds: often a test that isn't deterministic rather than a real change (see [Deterministic screenshots](/docs/screenshots/deterministic/)).
6. Before asking for a merge, `get_pr_changeset` (the project and the pull request's number, or a branch) lists everything the pull request adds, changes or removes across all of its builds, against the baseline it forked from, with where review stands for each. A change approved in an earlier build still shows there, so nothing slips through; nothing should be pending or unexpected. The web app shows the same at `/<org>/<project>/pulls/<number>`.

On GitHub, VisualCI keeps one comment on each pull request up to date: each suite's newest build, its counts and review state, before and after images of the changed snapshots, and what was removed. To show images in a comment of your own, use the `embed_url` links `get_snapshot` gives for each page: they work for a week.
Expand Down
4 changes: 4 additions & 0 deletions server/frontend/content/docs/screenshots/deterministic.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ diff <(cd run1 && find . -name '*.png' | sort | xargs sha256sum) \

Run it in CI's image, since that's where the baselines come from.

VisualCI points at likely suspects too: a change whose content flipped back and forth over its branch's recent builds
(A, B, A, B) is marked **flaky?** on the build page and `flaky: true` in `get_build`. It's only a hint: nothing is
ignored or approved because of it.

## Fonts

Text is most of a screenshot, and fonts are the most common difference between machines.
Expand Down
2 changes: 2 additions & 0 deletions server/frontend/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ export type SnapshotRow = {
/** The same new version was already approved on another branch. A hint: it approves nothing here. */
approved_elsewhere: ApprovedElsewhere | null
thumbnail_url: string | null
/** Its content flipped back and forth over the branch's recent builds: a hint only. */
flaky: boolean
}

export type BuildDetail = BuildSummary & {
Expand Down
5 changes: 5 additions & 0 deletions server/frontend/src/pages/BuildPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ function SnapshotItem({
</span>
</Link>
<span className="snap-side">
{s.flaky && (
<Pill tone="neutral" title="Its content flipped back and forth over this branch's recent builds. It may differ from run to run (the time, an animation, a late font) rather than have really changed: check before approving.">
flaky?
</Pill>
)}
<StatePill state={s.state} />
<ReviewPill review={s.review} />
{reviewable(build, s) && (
Expand Down
5 changes: 5 additions & 0 deletions server/src/controllers/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ struct SnapshotRow {
approved_elsewhere: Option<crate::models::baselines::ApprovedElsewhere>,
/// A thumbnail: the first changed page (else the first page).
thumbnail_url: Option<String>,
/// A change whose content flipped back and forth over the branch's recent builds (`flaky_in`): a hint only.
flaky: bool,
}

#[debug_handler]
Expand All @@ -774,6 +776,7 @@ async fn show_build(
let mut elsewhere = crate::models::baselines::approved_elsewhere(&ctx.db, build.id).await?;
let ids: Vec<i64> = list.iter().filter_map(|s| s.baseline_id).collect();
let notes = crate::models::baselines::local_notes(&ctx.db, &ids).await?;
let flaky = snapshots::Model::flaky_in(&ctx.db, &build).await?;
for s in list {
let pages = snapshot_pages::Entity::find()
.filter(snapshot_pages::Column::SnapshotId.eq(s.id))
Expand Down Expand Up @@ -801,6 +804,7 @@ async fn show_build(
(d.iter().filter(|l| l.tag == "+").count(), d.iter().filter(|l| l.tag == "-").count())
})
});
let is_flaky = s.is_change() && flaky.contains(&(s.name.clone(), s.platform.clone()));
rows.push(SnapshotRow {
format: s.text_format().map(|f| f.as_str().to_string()),
lines_added: text_stats.map(|t| t.0),
Expand All @@ -821,6 +825,7 @@ async fn show_build(
change: sizes.get(&s.id).copied(),
approved_elsewhere: elsewhere.remove(&s.id),
thumbnail_url: thumb,
flaky: is_flaky,
});
}
let mut summary = serde_json::to_value(BuildSummary::for_viewer(&build, member)).unwrap_or_default();
Expand Down
7 changes: 6 additions & 1 deletion server/src/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ impl VisualCi {
}

#[tool(
description = "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved on another branch (a hint: it approves nothing). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied).",
description = "A build's status and its snapshots that need attention, 30 at a time (offset and limit page through; longer lists also come grouped by state and name prefix) (changed, added, removed, failed), with how many pages changed in each, the largest change first (order: name to sort by name), and approved_elsewhere when the same new version was already approved on another branch (a hint: it approves nothing). Unchanged snapshots are only counted unless include_unchanged is set. `config` is the visualci.yml the build was sent (null when it had none: the project's settings applied). `flaky: true` marks a change whose content flipped back and forth over the branch's recent builds: often something that differs between runs (the time, an animation, a late font) rather than a real change, so check it before approving, and make the test deterministic.",
annotations(title = "Get build", read_only_hint = true, idempotent_hint = true, open_world_hint = false)
)]
async fn get_build(
Expand Down Expand Up @@ -1474,6 +1474,7 @@ impl VisualCi {
*groups.entry((s.state.clone(), prefix)).or_default() += 1;
}
}
let flaky = snapshots::Model::flaky_in(&self.ctx.db, &build).await.map_err(internal)?;
let mut items = Vec::new();
for s in listed.into_iter().skip(offset).take(limit) {
let attention = s.is_change() || s.state == "failed";
Expand Down Expand Up @@ -1501,6 +1502,10 @@ impl VisualCi {
"changed_pages": pages.map(|p| p.iter().filter(|p| p.state == "changed").count()),
"moved_lines": detail.as_ref().map_or(0, |d| d.moved.len()),
});
if s.is_change() && flaky.contains(&(s.name.clone(), s.platform.clone())) {
// Its content flipped back and forth over the branch's recent builds: a hint, not a verdict.
item["flaky"] = json!(true);
}
if let Some(format) = s.text_format() {
item["format"] = json!(format.as_str());
if let Some(text) = detail.as_ref().and_then(|d| d.text.as_ref()) {
Expand Down
81 changes: 81 additions & 0 deletions server/src/models/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,87 @@ impl Model {
}
Ok(ids)
}

/// The snapshots of this build that look flaky, by name and platform: over the newest builds of its suite on its
/// branch, up to this one ([`FLAKY_WINDOW`]), the snapshot's content changed at least three times and came back
/// to a version it had before (A, B, A, B). Commits on one branch rarely flip a page back and forth, so this
/// usually means something that differs from run to run: the time, an animation, a font that loads late. Only a
/// hint for whoever reviews: nothing is ignored or approved because of it.
///
/// # Errors
/// On a database error.
pub async fn flaky_in(
db: &DatabaseConnection,
build: &builds::Model,
) -> ModelResult<std::collections::HashSet<(String, String)>> {
use super::_entities::builds as b;
let recent: Vec<i64> = b::Entity::find()
.select_only()
.column(b::Column::Id)
.filter(b::Column::ProjectId.eq(build.project_id))
.filter(b::Column::Name.eq(&build.name))
.filter(b::Column::Branch.eq(&build.branch))
.filter(b::Column::Id.lte(build.id))
.order_by_desc(b::Column::Id)
.limit(FLAKY_WINDOW)
.into_tuple()
.all(db)
.await?;
// Three changes need at least four builds.
if recent.len() < 4 {
return Ok(std::collections::HashSet::new());
}
let rows: Vec<(i64, String, String, String)> = Entity::find()
.select_only()
.columns([snapshots::Column::BuildId, snapshots::Column::Name, snapshots::Column::Platform])
.column(snapshots::Column::SourceFingerprint)
.filter(snapshots::Column::BuildId.is_in(recent))
.filter(snapshots::Column::SourceFingerprint.ne(""))
.order_by_asc(snapshots::Column::BuildId)
.into_tuple()
.all(db)
.await?;
let mut history: std::collections::HashMap<(String, String), Vec<String>> = std::collections::HashMap::new();
for (_, name, platform, fingerprint) in rows {
history.entry((name, platform)).or_default().push(fingerprint);
}
Ok(history.into_iter().filter(|(_, versions)| flips(versions)).map(|(key, _)| key).collect())
}
}

/// How many of a branch's newest builds the flaky hint looks at.
pub const FLAKY_WINDOW: u64 = 8;

/// Whether a run of versions, oldest first, changed at least three times and came back to an earlier version.
fn flips(versions: &[String]) -> bool {
let changes = versions.windows(2).filter(|w| w[0] != w[1]).count();
let returned =
versions.iter().enumerate().skip(1).any(|(i, v)| versions[i - 1] != *v && versions[..i - 1].contains(v));
changes >= 3 && returned
}

#[cfg(test)]
mod flaky_tests {
use super::flips;

fn run(s: &str) -> Vec<String> {
s.chars().map(String::from).collect()
}

#[test]
fn flipping_back_and_forth_is_flaky() {
assert!(flips(&run("ABAB")));
assert!(flips(&run("AABBAAB")));
assert!(flips(&run("ABCA")));
}

#[test]
fn steady_changes_and_one_revert_are_not() {
assert!(!flips(&run("AAAA")));
assert!(!flips(&run("ABCD")), "changed every build but never came back");
assert!(!flips(&run("ABA")), "one revert is two changes");
assert!(!flips(&run("AABBA")), "a change and its revert");
}
}

/// Conditions on a baseline row `bl` for exact-match passes: the same suite as the snapshot's build ($5), a CI
Expand Down
34 changes: 33 additions & 1 deletion server/tests/requests/comments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Comment threads: an open thread blocks approving its snapshot until it's resolved (rejecting still works), and
//! threads follow the branch to its newer builds. Also reviewing only a build's added, or only its changed, snapshots.
//! threads follow the branch to its newer builds. Also reviewing only a build's added, or only its changed, snapshots,
//! and the flaky hint, for a snapshot that flips back and forth.
//!
//! These need the S3-compatible blob store (MinIO on the dev box). Where it can't be reached (CI has none), they print
//! why and pass without running.
Expand Down Expand Up @@ -333,6 +334,33 @@ async fn a_blob_is_confirmed_with_its_real_size() {
.await;
}

/// A snapshot whose image flips back and forth over a branch's builds is flagged flaky; one that changes steadily,
/// or flips on another branch, isn't.
#[tokio::test]
#[serial]
async fn a_snapshot_that_flips_back_and_forth_is_flagged_flaky() {
request::<App, _, _>(|_request, ctx| async move {
let Some(w) = world(&ctx).await else { return };
w.build("A", "main", None, &[], &[("x", png(RED)), ("y", png(RED))]).await;
let flips = [RED, BLUE, RED, BLUE];
let steady = [GREEN, BLUE, PURPLE, png_color(10)];
let mut last = None;
for (i, (f, s)) in flips.iter().zip(steady.iter()).enumerate() {
let commit = format!("F{i}");
last = Some(w.build(&commit, "feat", Some(5), &["A"], &[("x", png(*f)), ("y", png(*s))]).await);
}
let last = last.unwrap();
let flaky = snapshots::Model::flaky_in(w.db, &last).await.unwrap();
assert!(flaky.contains(&("x".to_string(), String::new())), "x went red, blue, red, blue: {flaky:?}");
assert!(!flaky.contains(&("y".to_string(), String::new())), "y changed every build but never came back");

// main has only one build: nothing to go on.
let main = w.build("B", "main", None, &["A"], &[("x", png(BLUE)), ("y", png(RED))]).await;
assert!(snapshots::Model::flaky_in(w.db, &main).await.unwrap().is_empty());
})
.await;
}

/// A build that runs its organization out of credits while it processes stops there: it fails with the
/// out-of-credits reason, and the renders it queued that nothing else needs are dropped, instead of drawing every page
/// of a large build on credit the organization doesn't have.
Expand Down Expand Up @@ -416,3 +444,7 @@ async fn a_review_can_take_only_the_added_or_only_the_changed_snapshots() {
})
.await;
}

fn png_color(v: u8) -> [u8; 3] {
[v, v, v]
}
4 changes: 4 additions & 0 deletions skills/visualci-deterministic/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ diff <(cd run1 && find . -name '*.png' | sort | xargs sha256sum) \

Run it in CI's image, since that's where the baselines come from.

VisualCI points at likely suspects too: a change whose content flipped back and forth over its branch's recent builds
(A, B, A, B) is marked **flaky?** on the build page and `flaky: true` in `get_build`. It's only a hint: nothing is
ignored or approved because of it.

## Fonts

Text is most of a screenshot, and fonts are the most common difference between machines.
Expand Down
2 changes: 1 addition & 1 deletion skills/visualci-review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \
4. The agent checks each change against the code and the task:
- **Intended:** it calls `review` with `approve`. The approved snapshots become the baseline, and the check turns green. No new commit or CI run is needed.
- **A bug:** it fixes the code and pushes again. The next build is compared with the same baseline.
5. `snapshot_history` shows one snapshot across recent builds, which helps find when a page started changing.
5. `snapshot_history` shows one snapshot across recent builds, which helps find when a page started changing. `get_build` marks a change `flaky: true` when its content flipped back and forth over the branch's recent builds: often a test that isn't deterministic rather than a real change (see [Deterministic screenshots](https://visualci.com/docs/screenshots/deterministic.md)).
6. Before asking for a merge, `get_pr_changeset` (the project and the pull request's number, or a branch) lists everything the pull request adds, changes or removes across all of its builds, against the baseline it forked from, with where review stands for each. A change approved in an earlier build still shows there, so nothing slips through; nothing should be pending or unexpected. The web app shows the same at `/<org>/<project>/pulls/<number>`.

On GitHub, VisualCI keeps one comment on each pull request up to date: each suite's newest build, its counts and review state, before and after images of the changed snapshots, and what was removed. To show images in a comment of your own, use the `embed_url` links `get_snapshot` gives for each page: they work for a week.
Expand Down
Loading