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.43",
"version": "0.1.44",
"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.43",
"version": "0.1.44",
"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.43",
"version": "0.1.44",
"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: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*", "server", "server/migration"]

[workspace.package]
version = "0.2.15"
version = "0.2.16"
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/DocSpring/visualci"
Expand Down
16 changes: 13 additions & 3 deletions crates/visualci-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,19 @@ impl Client {
}

/// Finalize a shard (or the whole build). `allow_empty`: the build may have no snapshots on purpose; otherwise
/// one that was sent none fails.
pub fn finalize(&self, id: &str, shard: Option<i32>, allow_empty: bool) -> Result<Build> {
let body = json!({ "shard": shard, "allow_empty": allow_empty });
/// one that was sent none fails. `empty_reason` says why (and implies `allow_empty`).
pub fn finalize(
&self,
id: &str,
shard: Option<i32>,
allow_empty: bool,
empty_reason: Option<&str>,
) -> Result<Build> {
let mut body = json!({ "shard": shard, "allow_empty": allow_empty });
// Only when there's one: a server from before empty_reason refuses a field it doesn't know
if let Some(reason) = empty_reason {
body["empty_reason"] = json!(reason);
}
Ok(serde_json::from_value(self.post(&format!("/api/v1/builds/{id}/finalize"), &body)?)?)
}

Expand Down
20 changes: 16 additions & 4 deletions crates/visualci-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ enum BuildCommand {
/// sent none fails.
#[arg(long)]
allow_empty: bool,
/// Why the build has no snapshots, like "inputs unchanged": implies --allow-empty, and the build's summary
/// (its check and its page) shows it with the build its baseline came from.
#[arg(long)]
empty_reason: Option<String>,
#[command(flatten)]
connection: Connection,
},
Expand Down Expand Up @@ -495,10 +499,18 @@ fn run() -> Result<()> {
}
println!("{}", build.id);
}
Command::Build(BuildCommand::Finalize { build, shard, wait, timeout, allow_empty, connection }) => {
Command::Build(BuildCommand::Finalize {
build,
shard,
wait,
timeout,
allow_empty,
empty_reason,
connection,
}) => {
let client = Client::from_env(connection.api_url, connection.token, connection.project)?;
let id = build_id(build)?;
let mut build = client.finalize(&id, shard, allow_empty)?;
let mut build = client.finalize(&id, shard, allow_empty, empty_reason.as_deref())?;
if wait {
build = client.wait(&id, Duration::from_secs(timeout))?;
}
Expand Down Expand Up @@ -696,7 +708,7 @@ fn run() -> Result<()> {
}
}
// Finalized whatever happened to the tests: a run that sent nothing (it failed before any snapshot) too.
let mut build = client.finalize(&build.id, None, true)?;
let mut build = client.finalize(&build.id, None, true, None)?;
if !no_wait {
build = client.wait(&build.id, Duration::from_secs(timeout))?;
}
Expand All @@ -714,7 +726,7 @@ fn run() -> Result<()> {
}
send_snapshots(&client, &build.id, &snapshots)?;
eprintln!("waiting for build #{}", build.number);
client.finalize(&build.id, None, false)?;
client.finalize(&build.id, None, false, None)?;
let build = client.wait(&build.id, Duration::from_secs(timeout))?;
print_build(&client, &build)?;
if build.blocked_message().is_some() {
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.43",
"version": "0.1.44",
"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: 2 additions & 0 deletions server/frontend/content/docs/ci/circleci.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ The build is compared once every shard has finalized. The [Ruby helpers](/docs/s

If some containers can be skipped (for example, tests split by changed files), add `--subset` when creating the build, so snapshots that weren't sent aren't counted as removed.

When a pipeline skips every job that sends a build's snapshots (a cached job whose inputs didn't change, or a docs-only push), the job that finalizes it still runs, and a build that was sent nothing fails. Finalize that build with `--allow-empty` instead: its snapshots are carried forward from the nearest ancestor, its check passes, and the check and the build's page read "No snapshots this run: baseline from #N". Only do this for jobs the pipeline really skipped: a job that ran and sent nothing should still fail.

Snapshot names must be unique across the build's jobs and containers. Sending the same file under a name again is fine (a job that's run again does it), but two containers sending different content under one name is refused with a 409 that names the snapshot: give each test's snapshot a name of its own.

## Orb
Expand Down
2 changes: 1 addition & 1 deletion server/frontend/content/docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ A name (with its platform) is one snapshot per build. Registering it again with

## Finalize

`POST /api/v1/builds/{id}/finalize`, with an empty body or `{"shard": 0}`. VisualCI compares the build once every shard has finalized. The response is the build. A build that was sent no snapshots fails; send `"allow_empty": true` when it's empty on purpose.
`POST /api/v1/builds/{id}/finalize`, with an empty body or `{"shard": 0}`. VisualCI compares the build once every shard has finalized. The response is the build. A build that was sent no snapshots fails; send `"allow_empty": true` when it's empty on purpose, or `"empty_reason": "inputs unchanged"`, which implies it and puts the reason in the build's summary with the build its baseline came from.

## Read a build

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 @@ -47,6 +47,7 @@ mod m20261202_000040_closed_builds;
mod m20261202_000041_build_creator;
mod m20261202_000042_build_groups;
mod m20261203_000046_waitlist;
mod m20261203_000047_empty_reason;

pub struct Migrator;

Expand Down Expand Up @@ -100,6 +101,7 @@ impl MigratorTrait for Migrator {
Box::new(m20261202_000041_build_creator::Migration),
Box::new(m20261202_000042_build_groups::Migration),
Box::new(m20261203_000046_waitlist::Migration),
Box::new(m20261203_000047_empty_reason::Migration),
// inject-above (do not remove this comment)
]
}
Expand Down
24 changes: 24 additions & 0 deletions server/migration/src/m20261203_000047_empty_reason.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Why a build was finished with no snapshots of its own on purpose (`builds.empty_reason`, "inputs unchanged" for a
//! CI run that skipped a suite's jobs), shown in its summary with the build its baseline came from.
use sea_orm_migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
fn name(&self) -> &str {
"m20261203_000047_empty_reason"
}
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.get_connection().execute_unprepared("ALTER TABLE builds ADD COLUMN empty_reason TEXT;").await?;
Ok(())
}

async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
m.get_connection().execute_unprepared("ALTER TABLE builds DROP COLUMN empty_reason;").await?;
Ok(())
}
}
10 changes: 9 additions & 1 deletion server/src/controllers/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ struct FinalizeParams {
/// The build may have no snapshots on purpose; otherwise one that was sent none fails.
#[serde(default)]
allow_empty: bool,
/// Why it has none ("inputs unchanged"): implies allow_empty, and shows in the build's summary.
#[serde(default)]
empty_reason: Option<String>,
}

#[debug_handler]
Expand All @@ -332,7 +335,12 @@ async fn finalize(
};
let shard = params.shard;
let was_receiving = build.state == "receiving";
let build = build.finalize_shard(&ctx.db, shard, params.allow_empty).await.map_err(model_error)?;
let build = match params.empty_reason.as_deref() {
Some(reason) => build.allow_empty_because(&ctx.db, reason).await.map_err(model_error)?,
None => build,
};
let allow_empty = params.allow_empty || params.empty_reason.is_some();
let build = build.finalize_shard(&ctx.db, shard, allow_empty).await.map_err(model_error)?;
let build = if was_receiving { build.stop_if_out_of_credits(&ctx).await? } else { build };
if was_receiving && build.state == "processing" {
ProcessBuildWorker::perform_later(&ctx, ProcessBuildWorkerArgs { build_id: build.id }).await?;
Expand Down
15 changes: 13 additions & 2 deletions server/src/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ pub struct FinalizeArgs {
pub shard: Option<i32>,
/// True when the build may have no snapshots on purpose. Otherwise a build that was sent none fails.
pub allow_empty: Option<bool>,
/// Why it has none, like "inputs unchanged" (the CI run skipped the tests): implies allow_empty, and shows in the
/// build's summary with the build its baseline came from.
pub empty_reason: Option<String>,
}

// Standard Support level 1 (standardsupport.dev): the schema names every field and its choices, with no field
Expand Down Expand Up @@ -2400,7 +2403,7 @@ impl VisualCi {
}

#[tool(
description = "Finish a build (or one shard of it): VisualCI renders and compares what was uploaded. Then poll `get_build` until its state is completed. A build that was sent no snapshots fails, unless allow_empty is true.",
description = "Finish a build (or one shard of it): VisualCI renders and compares what was uploaded. Then poll `get_build` until its state is completed. A build that was sent no snapshots fails, unless allow_empty is true or empty_reason says why it has none (\"inputs unchanged\").",
annotations(
title = "Finalize build",
read_only_hint = false,
Expand All @@ -2421,7 +2424,15 @@ impl VisualCi {
return Ok(tool_error(format!("no build {} in this project", args.build)));
};
let was_receiving = build.state == "receiving";
let build = match build.finalize_shard(&self.ctx.db, args.shard, args.allow_empty.unwrap_or(false)).await {
let build = match args.empty_reason.as_deref() {
Some(reason) => match build.allow_empty_because(&self.ctx.db, reason).await {
Ok(b) => b,
Err(e) => return Ok(tool_error(e.to_string())),
},
None => build,
};
let allow_empty = args.allow_empty.unwrap_or(false) || args.empty_reason.is_some();
let build = match build.finalize_shard(&self.ctx.db, args.shard, allow_empty).await {
Ok(b) => b,
Err(e) => return Ok(tool_error(e.to_string())),
};
Expand Down
1 change: 1 addition & 0 deletions server/src/models/_entities/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct Model {
pub manifest_same_as_build_id: Option<i64>,
/// The person whose token made the build, if one did (not a project token).
pub created_by_user_id: Option<i64>,
pub empty_reason: Option<String>,
pub finalized_at: Option<DateTimeWithTimeZone>,
pub completed_at: Option<DateTimeWithTimeZone>,
pub created_at: DateTimeWithTimeZone,
Expand Down
24 changes: 24 additions & 0 deletions server/src/models/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ impl Default for Via {
}
}

/// The longest reason a build may give for having no snapshots on purpose.
pub const EMPTY_REASON_MAX: usize = 200;

/// Why a build that was sent no snapshots failed.
pub const EMPTY_BUILD: &str = "No snapshots were sent, so nothing was compared. Check the paths the upload was given \
(or visualci.yml's uploads), or finalize with --allow-empty when an empty build is on \
Expand Down Expand Up @@ -387,6 +390,27 @@ impl Model {
Ok(out)
}

/// Let the build finish with no snapshots of its own, and say why ("inputs unchanged": the CI run skipped the
/// suite's jobs). Its summary shows the reason and the build its baseline came from. Only while it's receiving.
///
/// # Errors
/// `Message` for a reason that's empty or longer than [`EMPTY_REASON_MAX`] characters.
pub async fn allow_empty_because(self, db: &DatabaseConnection, reason: &str) -> ModelResult<Self> {
let reason = reason.trim();
if reason.is_empty() || reason.chars().count() > EMPTY_REASON_MAX {
return Err(ModelError::Message(format!(
"empty_reason must be 1 to {EMPTY_REASON_MAX} characters, like \"inputs unchanged\""
)));
}
if self.state != "receiving" {
return Ok(self);
}
let mut active = self.into_active_model();
active.allow_empty = Set(true);
active.empty_reason = Set(Some(reason.to_string()));
Ok(active.update(db).await?)
}

/// Mark a shard finished. Returns the build, now `processing` when every shard has finished.
///
/// # Errors
Expand Down
17 changes: 17 additions & 0 deletions server/src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub async fn summary_line(db: &DatabaseConnection, build: &builds::Model) -> Res
}
let all = snapshots::Model::for_build(db, build.id).await?;
let mut parts = Vec::new();
// Finished with nothing of its own on purpose (a CI run that skipped the suite's jobs): say so, and where its
// baseline came from, rather than leave "0 unchanged" to read like something broke
let sent = all.iter().any(|s| !s.carried_forward && s.state != "removed" && s.platform != CONFIG_PLATFORM);
if build.allow_empty && !sent && build.conclusion.as_deref() != Some("failed") {
parts.push(nothing_sent(db, build).await?);
}
if all.iter().any(|s| s.platform == CONFIG_PLATFORM && s.is_change()) {
parts.push("visualci.yml could hide changes".to_string());
}
Expand All @@ -44,6 +50,17 @@ pub async fn summary_line(db: &DatabaseConnection, build: &builds::Model) -> Res
Ok((!parts.is_empty()).then(|| parts.join("; ")))
}

/// "No snapshots this run (inputs unchanged): baseline from #12"
async fn nothing_sent(db: &DatabaseConnection, build: &builds::Model) -> Result<String> {
let reason = build.empty_reason.as_deref().map(|r| format!(" ({r})")).unwrap_or_default();
let base = match build.base_build_id {
Some(id) => builds::Entity::find_by_id(id).one(db).await?.map(|b| b.number),
None => None,
};
let baseline = base.map_or_else(|| "no baseline yet".to_string(), |n| format!("baseline from #{n}"));
Ok(format!("No snapshots this run{reason}: {baseline}"))
}

fn display_name(s: &snapshots::Model) -> String {
if s.platform.is_empty() { s.name.clone() } else { format!("{} ({})", s.name, s.platform) }
}
Expand Down
33 changes: 33 additions & 0 deletions server/tests/requests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,39 @@ async fn the_api_reads_numbers_sent_as_strings() {
.await;
}

/// A finalize that says why the build has no snapshots ("inputs unchanged") lets it be empty and keeps the reason
/// for its summary (sc-8866).
#[tokio::test]
#[serial]
async fn finalize_takes_a_reason_for_having_no_snapshots() {
request::<App, _, _>(|request, ctx| async move {
let auth = format!("Bearer {}", project_token(&ctx).await);
let mut params = build_params(None);
params["subset"] = serde_json::json!(true);
let r = request.post("/api/v1/builds").add_header("authorization", auth.clone()).json(&params).await;
let id = r.json::<serde_json::Value>()["id"].as_str().unwrap().to_string();
let r = request
.post(&format!("/api/v1/builds/{id}/finalize"))
.add_header("authorization", auth)
.json(&serde_json::json!({ "empty_reason": "inputs unchanged" }))
.await;
assert_eq!(r.status_code(), 200, "{}", r.text());
let saved = {
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
let pid: uuid::Uuid = id.parse().unwrap();
visualci_server::models::_entities::builds::Entity::find()
.filter(visualci_server::models::_entities::builds::Column::Pid.eq(pid))
.one(&ctx.db)
.await
.unwrap()
.unwrap()
};
assert!(saved.allow_empty);
assert_eq!(saved.empty_reason.as_deref(), Some("inputs unchanged"));
})
.await;
}

#[tokio::test]
#[serial]
async fn shards_with_the_same_nonce_share_a_build() {
Expand Down
Loading
Loading