From e8cdeaed2bac94c7b2acaac5fdb6f6bd3fcfb4ec Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 09:15:43 +1300 Subject: [PATCH] No pull request comment when nothing changed (Nathan): a pull request whose suites' newest builds are all unchanged (no changed, added, removed or failed snapshots) gets no VisualCI comment, only the passing check, unless the project's new comment_when_unchanged is on (off by default, for every project); a comment already there keeps being updated (GitHub doesn't email about edits), and builds with changes are commented as before; the setting in project settings (one checkbox), the REST and MCP project settings, and the agents docs (skills regenerated, plugin 0.1.46) --- .claude-plugin/marketplace.json | 2 +- .claude-plugin/plugin.json | 2 +- .cursor-plugin/plugin.json | 2 +- gemini-extension.json | 2 +- server/frontend/content/docs/agents.md | 2 +- server/frontend/src/api/types.ts | 2 + server/frontend/src/pages/ProjectPage.tsx | 11 ++++ server/migration/src/lib.rs | 2 + ...m20261203_000049_comment_when_unchanged.rs | 29 ++++++++++ server/src/models/_entities/projects.rs | 2 + server/src/models/projects.rs | 10 ++++ server/src/workers/pr_comment.rs | 58 ++++++++++++++++++- server/tests/requests/mcp.rs | 21 +++++++ skills/visualci-review/SKILL.md | 2 +- 14 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 server/migration/src/m20261203_000049_comment_when_unchanged.rs diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 2e237864..0dc521b2 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.45", + "version": "0.1.46", "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/", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 8a80ecf3..78da2802 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.45", + "version": "0.1.46", "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/", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 488d8bd6..48895fdc 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.45", + "version": "0.1.46", "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" diff --git a/gemini-extension.json b/gemini-extension.json index ae128fcb..648e042d 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.45", + "version": "0.1.46", "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": { diff --git a/server/frontend/content/docs/agents.md b/server/frontend/content/docs/agents.md index 9699afea..198ecc9c 100644 --- a/server/frontend/content/docs/agents.md +++ b/server/frontend/content/docs/agents.md @@ -46,7 +46,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \ 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 `///pulls/`. -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. +On GitHub, VisualCI keeps one comment on each pull request up to date when something changed: each suite's newest build, its counts and review state, before and after images of the changed snapshots, and what was removed. A pull request where nothing changed gets only the passing check, unless the project's `comment_when_unchanged` setting is on; a comment that's already there keeps being updated. 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. ### Comment threads diff --git a/server/frontend/src/api/types.ts b/server/frontend/src/api/types.ts index 1bc44eb7..92ceb2fd 100644 --- a/server/frontend/src/api/types.ts +++ b/server/frontend/src/api/types.ts @@ -232,6 +232,8 @@ export type ProjectSettings = { gallery_enabled: boolean /** Whether project tokens (CI's agents) may approve changes; off keeps approving with people. */ tokens_can_approve: boolean + /** Whether VisualCI comments on pull requests when nothing changed (off: only the check). */ + comment_when_unchanged: boolean /** Anyone, signed in or not, can read its builds and diffs. */ public: boolean /** GitHub says its repository is public (checked on linking and once a day). Only then can it be public. */ diff --git a/server/frontend/src/pages/ProjectPage.tsx b/server/frontend/src/pages/ProjectPage.tsx index be3209ed..742a83f6 100644 --- a/server/frontend/src/pages/ProjectPage.tsx +++ b/server/frontend/src/pages/ProjectPage.tsx @@ -256,6 +256,7 @@ const toDraft = (s: ProjectSettings): Draft => ({ ignore_anti_aliasing: s.ignore_anti_aliasing, gallery_enabled: s.gallery_enabled, tokens_can_approve: s.tokens_can_approve, + comment_when_unchanged: s.comment_when_unchanged, public: s.public, rules: s.ignore_rules.map((r) => ({ snapshots: r.snapshots, @@ -555,6 +556,16 @@ function Settings({ +
diff --git a/server/migration/src/lib.rs b/server/migration/src/lib.rs index 36679cc8..c4338cad 100644 --- a/server/migration/src/lib.rs +++ b/server/migration/src/lib.rs @@ -49,6 +49,7 @@ mod m20261202_000042_build_groups; mod m20261203_000046_waitlist; mod m20261203_000047_empty_reason; mod m20261203_000048_downloads; +mod m20261203_000049_comment_when_unchanged; pub struct Migrator; @@ -104,6 +105,7 @@ impl MigratorTrait for Migrator { Box::new(m20261203_000046_waitlist::Migration), Box::new(m20261203_000047_empty_reason::Migration), Box::new(m20261203_000048_downloads::Migration), + Box::new(m20261203_000049_comment_when_unchanged::Migration), // inject-above (do not remove this comment) ] } diff --git a/server/migration/src/m20261203_000049_comment_when_unchanged.rs b/server/migration/src/m20261203_000049_comment_when_unchanged.rs new file mode 100644 index 00000000..34e8c507 --- /dev/null +++ b/server/migration/src/m20261203_000049_comment_when_unchanged.rs @@ -0,0 +1,29 @@ +//! VisualCI's pull request comment, only when something changed: with `comment_when_unchanged` off (the default), a +//! pull request whose builds are all unchanged gets no comment (its VisualCI check still passes), so nobody's inbox +//! fills with "nothing changed". A comment already there keeps being edited. +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20261203_000049_comment_when_unchanged" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> { + m.get_connection() + .execute_unprepared( + "ALTER TABLE projects ADD COLUMN comment_when_unchanged BOOLEAN NOT NULL DEFAULT false;", + ) + .await?; + Ok(()) + } + + async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> { + m.get_connection().execute_unprepared("ALTER TABLE projects DROP COLUMN comment_when_unchanged;").await?; + Ok(()) + } +} diff --git a/server/src/models/_entities/projects.rs b/server/src/models/_entities/projects.rs index ce8a014e..604b4941 100644 --- a/server/src/models/_entities/projects.rs +++ b/server/src/models/_entities/projects.rs @@ -29,6 +29,8 @@ pub struct Model { pub gallery_enabled: bool, /// Whether project tokens may approve changes over MCP (CI's agents); off keeps approving with people. pub tokens_can_approve: bool, + /// Whether VisualCI comments on a pull request whose builds are all unchanged; off by default (the check passes). + pub comment_when_unchanged: bool, #[sea_orm(column_type = "Text")] pub default_branch: String, #[sea_orm(column_type = "Text")] diff --git a/server/src/models/projects.rs b/server/src/models/projects.rs index 80f4cf87..51a3eeaf 100644 --- a/server/src/models/projects.rs +++ b/server/src/models/projects.rs @@ -136,6 +136,9 @@ pub struct Settings { pub gallery_enabled: bool, /// Whether project tokens may approve changes over MCP; off keeps approving with people. pub tokens_can_approve: bool, + /// Whether VisualCI comments on a pull request whose builds are all unchanged. Off by default: the VisualCI check + /// still passes, and a comment already there (an earlier build had changes) keeps being updated. + pub comment_when_unchanged: bool, /// Whether anyone, signed in or not, can read the project's builds and diffs (open source). Settings, tokens and /// reviewing stay with its members. pub public: bool, @@ -171,6 +174,7 @@ impl From<&Model> for Settings { forge_webhook_at: p.forge_webhook_at.map(|d| d.to_rfc3339()), gallery_enabled: p.gallery_enabled, tokens_can_approve: p.tokens_can_approve, + comment_when_unchanged: p.comment_when_unchanged, public: p.public, repository_public: p.repository_public, open_source: p.open_source, @@ -214,6 +218,9 @@ pub struct SettingsChange { pub gallery_enabled: Option, /// `false`: project tokens can't approve changes (people do); `true` lets CI's agents approve again. pub tokens_can_approve: Option, + /// `true`: comment on pull requests even when nothing changed. `false` (the default): a pull request whose builds + /// are all unchanged gets no comment, only the passing check; a comment already there keeps being updated. + pub comment_when_unchanged: Option, /// `true` lets anyone, signed in or not, read the project's builds and diffs (for open source projects); /// settings, tokens and reviewing stay with its members. Only a project linked to a public repository can be /// public. `false` makes it private again. @@ -349,6 +356,9 @@ impl Model { if let Some(v) = p.tokens_can_approve { a.tokens_can_approve = Set(v); } + if let Some(v) = p.comment_when_unchanged { + a.comment_when_unchanged = Set(v); + } if let Some(v) = p.gallery_enabled { a.gallery_enabled = Set(v); } diff --git a/server/src/workers/pr_comment.rs b/server/src/workers/pr_comment.rs index f1e56715..8f9c6a57 100644 --- a/server/src/workers/pr_comment.rs +++ b/server/src/workers/pr_comment.rs @@ -164,6 +164,27 @@ async fn embed(db: &DatabaseConnection, store: &BlobStore, sha: Option<&String>) } /// Each suite's newest build for this pull request, ready to render. +/// Whether to post or update the pull request's comment: always when there's something to look at, or a comment to +/// update; when every suite is unchanged, only with the project's `comment_when_unchanged` on. +#[must_use] +pub fn posts(has_comment: bool, comment_when_unchanged: bool, suites: &[Suite]) -> bool { + has_comment || comment_when_unchanged || !all_unchanged(suites) +} + +/// Whether every suite's newest build has finished with nothing to look at: no changed, added, removed or failed +/// snapshots, and no error. +#[must_use] +pub fn all_unchanged(suites: &[Suite]) -> bool { + suites.iter().all(|s| { + s.state == "completed" + && s.error.is_none() + && s.stats.changed == 0 + && s.stats.added == 0 + && s.stats.removed == 0 + && s.stats.failed == 0 + }) +} + async fn suites(ctx: &AppContext, project: &projects::Model, org: &str, pr_number: i32) -> Result> { use crate::models::_entities::builds::Column as B; let db = &ctx.db; @@ -258,13 +279,20 @@ impl BackgroundWorker for PrCommentWorker { }; let org = organizations::Entity::find_by_id(project.organization_id).one(db).await?.ok_or(Error::NotFound)?; let request = if repository.forge == crate::forge::ForgeKind::Gitlab { "MR" } else { "PR" }; - let body = render(&suites(&self.ctx, &project, &org.slug, pr_number).await?, request); - let hash = hex::encode(sha2::Sha256::digest(body.as_bytes())); + let suites = suites(&self.ctx, &project, &org.slug, pr_number).await?; let existing = pr_comments::Entity::find() .filter(pr_comments::Column::ProjectId.eq(project.id)) .filter(pr_comments::Column::PrNumber.eq(pr_number)) .one(db) .await?; + // Nothing changed: the VisualCI check says so, and a comment would only fill people's inboxes. One already + // there (an earlier build had changes) is still updated, to show the pull request is clean now; GitHub + // doesn't email about edits. + if !posts(existing.is_some(), project.comment_when_unchanged, &suites) { + return Ok(()); + } + let body = render(&suites, request); + let hash = hex::encode(sha2::Sha256::digest(body.as_bytes())); if existing.as_ref().and_then(|e| e.body_sha256.as_deref()) == Some(hash.as_str()) { return Ok(()); } @@ -313,6 +341,32 @@ impl BackgroundWorker for PrCommentWorker { mod tests { use super::*; + fn suite(state: &str, stats: builds::Stats) -> Suite { + Suite { name: "default".into(), state: state.into(), stats, ..Default::default() } + } + + #[test] + fn nothing_changed_gets_no_new_comment_unless_the_project_asks() { + let clean = [suite("completed", builds::Stats { unchanged: 40, total: 40, ..Default::default() })]; + assert!(!posts(false, false, &clean), "no comment for an unchanged pull request"); + assert!(posts(false, true, &clean), "with comment_when_unchanged on"); + assert!(posts(true, false, &clean), "a comment already there is still updated"); + for stats in [ + builds::Stats { changed: 1, ..Default::default() }, + builds::Stats { added: 1, ..Default::default() }, + builds::Stats { removed: 1, ..Default::default() }, + builds::Stats { failed: 1, ..Default::default() }, + ] { + assert!(posts(false, false, &[suite("completed", stats)]), "changes are always posted"); + } + // One suite clean, another with a change; a build still processing or one that failed isn't "unchanged" + let mixed = [clean[0].clone(), suite("completed", builds::Stats { changed: 2, ..Default::default() })]; + assert!(posts(false, false, &mixed)); + assert!(posts(false, false, &[suite("processing", builds::Stats::default())])); + let errored = Suite { error: Some("out of credits".into()), ..suite("failed", builds::Stats::default()) }; + assert!(posts(false, false, &[errored])); + } + #[test] fn renders_counts_images_and_removals() { let suite = Suite { diff --git a/server/tests/requests/mcp.rs b/server/tests/requests/mcp.rs index 72575228..fe776038 100644 --- a/server/tests/requests/mcp.rs +++ b/server/tests/requests/mcp.rs @@ -1033,6 +1033,27 @@ async fn a_project_token_acts_as_a_member_not_an_admin() { .await; } +/// A pull request where nothing changed gets no comment by default; `comment_when_unchanged` turns that on. +#[tokio::test] +#[serial] +async fn comments_when_nothing_changed_are_off_until_turned_on() { + request::(|request, ctx| async move { + let f = fixture(&ctx).await; + let project = format!("{}/pdfs", f.org); + let (err, s) = call(&request, &f.user_token, "get_project", serde_json::json!({ "project": project })).await; + assert!(!err && s["settings"]["comment_when_unchanged"] == false, "off by default: {s}"); + let (err, s) = call( + &request, + &f.user_token, + "update_project", + serde_json::json!({ "project": project, "comment_when_unchanged": true }), + ) + .await; + assert!(!err && s["settings"]["comment_when_unchanged"] == true, "{s}"); + }) + .await; +} + /// With "Tokens can approve" off, a project token can't approve, accept a variant or ignore a change; it can still /// reject. A person's token can turn it off and on. #[tokio::test] diff --git a/skills/visualci-review/SKILL.md b/skills/visualci-review/SKILL.md index b0a3212f..f3013676 100644 --- a/skills/visualci-review/SKILL.md +++ b/skills/visualci-review/SKILL.md @@ -51,7 +51,7 @@ claude mcp add --transport http visualci https://mcp.visualci.com/mcp \ 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 `///pulls/`. -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. +On GitHub, VisualCI keeps one comment on each pull request up to date when something changed: each suite's newest build, its counts and review state, before and after images of the changed snapshots, and what was removed. A pull request where nothing changed gets only the passing check, unless the project's `comment_when_unchanged` setting is on; a comment that's already there keeps being updated. 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. ### Comment threads