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.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/",
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.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/",
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.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"
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.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": {
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 @@ -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 `/<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.
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

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 @@ -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. */
Expand Down
11 changes: 11 additions & 0 deletions server/frontend/src/pages/ProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -555,6 +556,16 @@ function Settings({
</strong>
</span>
</label>
<label className="check">
<input
type="checkbox"
checked={draft.comment_when_unchanged}
onChange={(e) => set('comment_when_unchanged', e.target.checked)}
/>
<span>
<strong>Comment on pull requests when nothing changed</strong>
</span>
</label>
</fieldset>

<fieldset className="settings-group" disabled={!canEdit}>
Expand Down
2 changes: 2 additions & 0 deletions server/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
]
}
Expand Down
29 changes: 29 additions & 0 deletions server/migration/src/m20261203_000049_comment_when_unchanged.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
2 changes: 2 additions & 0 deletions server/src/models/_entities/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
10 changes: 10 additions & 0 deletions server/src/models/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -214,6 +218,9 @@ pub struct SettingsChange {
pub gallery_enabled: Option<bool>,
/// `false`: project tokens can't approve changes (people do); `true` lets CI's agents approve again.
pub tokens_can_approve: Option<bool>,
/// `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<bool>,
/// `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.
Expand Down Expand Up @@ -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);
}
Expand Down
58 changes: 56 additions & 2 deletions server/src/workers/pr_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Suite>> {
use crate::models::_entities::builds::Column as B;
let db = &ctx.db;
Expand Down Expand Up @@ -258,13 +279,20 @@ impl BackgroundWorker<PrCommentWorkerArgs> 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(());
}
Expand Down Expand Up @@ -313,6 +341,32 @@ impl BackgroundWorker<PrCommentWorkerArgs> 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 {
Expand Down
21 changes: 21 additions & 0 deletions server/tests/requests/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<App, _, _>(|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]
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 @@ -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 `/<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.
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

Expand Down
Loading