diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 4e7f4486..0cbdedf3 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.38", + "version": "0.1.42", "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 dbf3251d..91827860 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.38", + "version": "0.1.42", "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 8d56539e..940faebe 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.38", + "version": "0.1.42", "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/Cargo.lock b/Cargo.lock index 4b3faea1..dc7b8161 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5206,7 +5206,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "visualci-cli" -version = "0.2.13" +version = "0.2.15" dependencies = [ "anyhow", "base64 0.22.1", @@ -5223,7 +5223,7 @@ dependencies = [ [[package]] name = "visualci-core" -version = "0.2.13" +version = "0.2.15" dependencies = [ "globset", "hex", @@ -5240,7 +5240,7 @@ dependencies = [ [[package]] name = "visualci-renderer" -version = "0.2.13" +version = "0.2.15" dependencies = [ "anyhow", "image", @@ -5255,7 +5255,7 @@ dependencies = [ [[package]] name = "visualci-wasm" -version = "0.2.13" +version = "0.2.15" dependencies = [ "image", "serde", @@ -5265,7 +5265,7 @@ dependencies = [ [[package]] name = "visualci_server" -version = "0.2.13" +version = "0.2.15" dependencies = [ "aes-gcm", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 6e962aa4..47a47e25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/*", "server", "server/migration"] [workspace.package] -version = "0.2.13" +version = "0.2.15" edition = "2024" license = "Apache-2.0" repository = "https://github.com/DocSpring/visualci" diff --git a/crates/visualci-cli/src/client.rs b/crates/visualci-cli/src/client.rs index 008c57b5..9aeb917f 100644 --- a/crates/visualci-cli/src/client.rs +++ b/crates/visualci-cli/src/client.rs @@ -183,40 +183,36 @@ impl Client { } /// Register snapshots and upload the files the server doesn't have. Returns (registered, uploaded). + /// Large suites (sc-8868): send the run's manifest hash and one hash per group of names, and get back which + /// groups the server needs. Groups that match their baselines are carried forward on the server. + pub fn check_groups( + &self, + build_id: &str, + entries: &[visualci_core::manifest::Entry], + group_depth: Option, + ) -> Result { + use visualci_core::manifest; + let grouping = group_depth.map_or(manifest::Grouping::default(), |d| manifest::Grouping::Depth(d as usize)); + let groups: Vec = manifest::groups(entries, grouping) + .into_iter() + .map(|g| json!({ "key": g.key, "hash": g.hash, "count": g.count })) + .collect(); + let body = json!({ + "manifest_hash": manifest::manifest_hash(entries), + "group_depth": group_depth, + "groups": groups, + }); + Ok(serde_json::from_value(self.post(&format!("/api/v1/builds/{build_id}/groups"), &body)?)?) + } + pub fn add_snapshots(&self, build_id: &str, snapshots: &[Snapshot]) -> Result<(usize, usize)> { let mut uploaded = 0; for chunk in snapshots.chunks(BATCH) { let mut files = Vec::with_capacity(chunk.len()); let mut params = Vec::with_capacity(chunk.len()); for s in chunk { - let bytes = match &s.content { - Some(c) => c.clone(), - None => std::fs::read(&s.path).with_context(|| format!("reading {}", s.path.display()))?, - }; - let (kind, fingerprint, mut content_type) = if s.content.is_some() { - ("text", visualci_core::sha256_hex(&bytes), "text/plain") - } else { - classify(&s.path, &bytes)? - }; - if kind == "text" { - let name = s.path.file_name().and_then(|n| n.to_str()); - content_type = - Format::detect(s.format.as_deref(), None, if s.content.is_some() { None } else { name }) - .content_type(); - } - params.push(json!({ - "name": s.name, - "platform": s.platform, - "kind": kind, - "fingerprint": fingerprint, - "sha256": visualci_core::sha256_hex(&bytes), - "size": bytes.len(), - "content_type": content_type, - "threshold": s.threshold, - "engine": s.engine, - "format": s.format, - "ignore": s.ignore, - })); + let (p, bytes) = registration(s)?; + params.push(p); files.push(bytes); } let response = @@ -295,6 +291,80 @@ pub fn mcp_url_for(api_url: &str) -> String { } } +/// What the server's answer to `check_groups` says. +#[derive(Debug, Deserialize)] +pub struct GroupCheck { + /// The whole manifest matched this build's: nothing needs sending. + pub same_as_build: Option, + pub changed: Vec, + pub unchanged: Vec, +} + +/// A snapshot's registration (as `POST /builds/:id/snapshots` takes it) and its bytes. +/// +/// # Errors +/// When the file can't be read or classified. +pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec)> { + let bytes = match &s.content { + Some(c) => c.clone(), + None => std::fs::read(&s.path).with_context(|| format!("reading {}", s.path.display()))?, + }; + let (kind, fingerprint, mut content_type) = if s.content.is_some() { + ("text", visualci_core::sha256_hex(&bytes), "text/plain") + } else { + classify(&s.path, &bytes)? + }; + if kind == "text" { + let name = s.path.file_name().and_then(|n| n.to_str()); + content_type = + Format::detect(s.format.as_deref(), None, if s.content.is_some() { None } else { name }).content_type(); + } + let params = json!({ + "name": s.name, + "platform": s.platform, + "kind": kind, + "fingerprint": fingerprint, + "sha256": visualci_core::sha256_hex(&bytes), + "size": bytes.len(), + "content_type": content_type, + "threshold": s.threshold, + "engine": s.engine, + "format": s.format, + "ignore": s.ignore, + }); + Ok((params, bytes)) +} + +/// A registration as a manifest entry, normalized as the server stores the snapshot (`models::build_groups::entry_of`): +/// a text snapshot's format as the server detects it, the ignore rules as their full JSON. +/// +/// # Errors +/// When the ignore rules aren't valid. +pub fn entry_of(params: &serde_json::Value) -> Result { + let str_of = |k: &str| params[k].as_str().map(str::to_string); + let kind = str_of("kind").unwrap_or_default(); + let name = str_of("name").unwrap_or_default(); + let format = (kind == "text").then(|| { + Format::detect(params["format"].as_str(), params["content_type"].as_str(), Some(&name)).as_str().to_string() + }); + let ignore: visualci_core::snapshot_text::IgnoreRules = if params["ignore"].is_null() { + visualci_core::snapshot_text::IgnoreRules::default() + } else { + serde_json::from_value(params["ignore"].clone()).context("reading a snapshot's ignore rules")? + }; + Ok(visualci_core::manifest::Entry { + name, + platform: str_of("platform").unwrap_or_default(), + kind, + fingerprint: str_of("fingerprint").unwrap_or_default(), + format, + engine: str_of("engine"), + threshold: params["threshold"].as_f64(), + ignore_anti_aliasing: params["ignore_anti_aliasing"].as_bool(), + ignore: serde_json::to_value(ignore)?, + }) +} + /// Kind, fingerprint and content type of a file. pub fn classify(path: &Path, bytes: &[u8]) -> Result<(&'static str, String, &'static str)> { let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase(); diff --git a/crates/visualci-cli/src/main.rs b/crates/visualci-cli/src/main.rs index 2e63601a..f19e1341 100644 --- a/crates/visualci-cli/src/main.rs +++ b/crates/visualci-cli/src/main.rs @@ -613,8 +613,7 @@ fn run() -> Result<()> { eprintln!("visualci: nothing to upload (--allow-empty)"); return Ok(()); } - let (registered, uploaded) = client.add_snapshots(&build_id(build)?, &snapshots)?; - eprintln!("{registered} snapshots, {uploaded} uploaded"); + send_snapshots(&client, &build_id(build)?, &snapshots)?; } Command::Compare { names, platform, build, wait, timeout, json, connection } => { let client = Client::from_env(connection.api_url, connection.token, connection.project)?; @@ -693,8 +692,7 @@ fn run() -> Result<()> { let snapshots = configured_uploads(&snapshot)?; client::check_unique(&snapshots)?; if !snapshots.is_empty() { - let (registered, uploaded) = client.add_snapshots(&build.id, &snapshots)?; - eprintln!("{registered} snapshots, {uploaded} uploaded"); + send_snapshots(&client, &build.id, &snapshots)?; } } // Finalized whatever happened to the tests: a run that sent nothing (it failed before any snapshot) too. @@ -714,8 +712,8 @@ fn run() -> Result<()> { if snapshots.is_empty() { bail!("nothing to check: no snapshot files in {}", describe_paths(&paths)); } - let (registered, uploaded) = client.add_snapshots(&build.id, &snapshots)?; - eprintln!("{registered} snapshots, {uploaded} uploaded; waiting for build #{}", build.number); + send_snapshots(&client, &build.id, &snapshots)?; + eprintln!("waiting for build #{}", build.number); client.finalize(&build.id, None, false)?; let build = client.wait(&build.id, Duration::from_secs(timeout))?; print_build(&client, &build)?; @@ -814,7 +812,49 @@ impl Drop for IgnoreInterrupts { } } -/// The device-code sign-in:/// The device-code sign-in: ask for a code pair, show the link and code, wait for the person to approve it in the +/// From this many snapshots, a run first sends its manifest and group hashes (sc-8868), then only the groups that +/// changed. `VISUALCI_GROUPS=0` turns that off, `VISUALCI_GROUPS=1` turns it on for any size. +const GROUP_MIN: usize = 500; + +/// Send snapshots to a build and say what happened. A large suite (`GROUP_MIN`) asks first which groups of names +/// match their baselines, and sends only the others: the server carries the matched ones forward, charged per group. +fn send_snapshots(client: &Client, build_id: &str, snapshots: &[Snapshot]) -> Result<()> { + let grouped = match std::env::var("VISUALCI_GROUPS").as_deref() { + Ok("0" | "false") => false, + Ok("1" | "true") => true, + _ => snapshots.len() >= GROUP_MIN, + }; + if !grouped { + let (registered, uploaded) = client.add_snapshots(build_id, snapshots)?; + eprintln!("{registered} snapshots, {uploaded} uploaded"); + return Ok(()); + } + let group_depth = config_file::discover().ok().flatten().and_then(|f| f.config.group_depth); + let entries = snapshots + .iter() + .map(|s| client::registration(s).and_then(|(params, _)| client::entry_of(¶ms))) + .collect::>>()?; + let check = client.check_groups(build_id, &entries, group_depth)?; + if let Some(n) = check.same_as_build { + eprintln!("{} snapshots: nothing changed since build #{n}", snapshots.len()); + return Ok(()); + } + let grouping = group_depth + .map_or(visualci_core::manifest::Grouping::default(), |d| visualci_core::manifest::Grouping::Depth(d as usize)); + let changed: std::collections::HashSet<&str> = check.changed.iter().map(String::as_str).collect(); + let send: Vec = + snapshots.iter().filter(|s| changed.contains(grouping.key(&s.name).as_str())).cloned().collect(); + let (registered, uploaded) = if send.is_empty() { (0, 0) } else { client.add_snapshots(build_id, &send)? }; + eprintln!( + "{} snapshots: {} of {} groups unchanged; {registered} sent, {uploaded} uploaded", + snapshots.len(), + check.unchanged.len(), + check.unchanged.len() + check.changed.len() + ); + Ok(()) +} + +/// The device-code sign-in:/// The device-code sign-in:/// The device-code sign-in: ask for a code pair, show the link and code, wait for the person to approve it in the /// browser, then keep the personal access token it gives. fn login(api: &str, no_browser: bool) -> Result<()> { let http = reqwest::blocking::Client::builder() diff --git a/crates/visualci-core/src/config.rs b/crates/visualci-core/src/config.rs index 8e7764b7..b85075aa 100644 --- a/crates/visualci-core/src/config.rs +++ b/crates/visualci-core/src/config.rs @@ -47,6 +47,10 @@ pub struct Config { /// unapproved changes) or `wait` (`finalize --wait` waits for a decision). #[serde(default, skip_serializing_if = "Option::is_none")] pub ci_mode: Option, + /// Large suites: names are grouped for group hashes by their first this many path segments (by default, all but + /// the last two). A group whose snapshots match their baselines isn't sent again (sc-8868). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub group_depth: Option, /// What a bare `visualci upload` sends. #[serde(default, skip_serializing_if = "Vec::is_empty")] pub uploads: Vec, diff --git a/crates/visualci-core/src/lib.rs b/crates/visualci-core/src/lib.rs index b40e8eaf..0b9035f1 100644 --- a/crates/visualci-core/src/lib.rs +++ b/crates/visualci-core/src/lib.rs @@ -9,6 +9,7 @@ pub mod align; pub mod config; pub mod diff; pub mod image_hash; +pub mod manifest; pub mod pdf; /// Text snapshots: the `snapshot-diff` crate. pub mod snapshot_text { diff --git a/crates/visualci-core/src/manifest.rs b/crates/visualci-core/src/manifest.rs new file mode 100644 index 00000000..daf7cf89 --- /dev/null +++ b/crates/visualci-core/src/manifest.rs @@ -0,0 +1,165 @@ +//! Manifest and group hashes for large suites (sc-8868): a hash over every snapshot of a run, and one per group of +//! names, so a client can ask "is this group the same as its baseline?" without sending the group's files. +//! +//! The CLI computes them from what it would register, and the server computes the baseline's side from its own stored +//! snapshot rows (never from anything a client claims), with the same functions here, so the two agree exactly. +//! +//! An entry is everything that decides whether a snapshot compares as unchanged: its name and platform, its kind, its +//! fingerprint (the PDF's, the decoded pixels', or the text's SHA-256: what the server compares, not the file's bytes) +//! and the settings that change a comparison (threshold, anti-aliasing, render engine, text format, ignore rules). + +use std::collections::BTreeMap; + +use sha2::{Digest, Sha256}; + +/// The hashes' version: part of every hash, so a change to what's hashed never matches an old hash. +pub const VERSION: &str = "vci-manifest-1"; + +/// One snapshot, as hashed. Settings are as the server stores them: `format` only for text, `ignore` as the JSON of +/// the snapshot's own ignore rules (`{"json_paths":[],"text_patterns":[]}` when it has none). +#[derive(Clone, Debug, PartialEq)] +pub struct Entry { + pub name: String, + pub platform: String, + pub kind: String, + pub fingerprint: String, + pub format: Option, + pub engine: Option, + pub threshold: Option, + pub ignore_anti_aliasing: Option, + pub ignore: serde_json::Value, +} + +impl Entry { + /// The entry's line in a hash: a JSON array, so no field can run into the next. + fn line(&self) -> String { + serde_json::json!([ + self.name, + self.platform, + self.kind, + self.fingerprint, + self.format, + self.engine, + self.threshold, + self.ignore_anti_aliasing, + self.ignore, + ]) + .to_string() + } +} + +/// How names are grouped: by default a name's group is the name without its last two segments +/// (`pdf_engine/forms/w9/page-1` → `pdf_engine/forms`); `Depth(n)` keeps the first `n` segments instead. A name with +/// too few segments is in the root group, `""`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum Grouping { + #[default] + AllButLastTwo, + Depth(usize), +} + +impl Grouping { + /// The group a snapshot name is in. + #[must_use] + pub fn key(self, name: &str) -> String { + let segments: Vec<&str> = name.split('/').collect(); + let keep = match self { + Self::AllButLastTwo => segments.len().saturating_sub(2), + // A group never takes the whole name: the last segment is always the snapshot's own. + Self::Depth(n) => n.min(segments.len().saturating_sub(1)), + }; + segments[..keep].join("/") + } +} + +fn hash_of<'a>(entries: impl Iterator) -> String { + let mut lines: Vec = entries.map(Entry::line).collect(); + lines.sort_unstable(); + let mut h = Sha256::new(); + h.update(VERSION.as_bytes()); + for line in lines { + h.update(b"\n"); + h.update(line.as_bytes()); + } + hex::encode(h.finalize()) +} + +/// The hash of a whole run: every entry, in any order. +#[must_use] +pub fn manifest_hash(entries: &[Entry]) -> String { + hash_of(entries.iter()) +} + +/// One group: its key, its hash and how many snapshots it has. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Group { + pub key: String, + pub hash: String, + pub count: usize, +} + +/// The entries' groups, sorted by key. +#[must_use] +pub fn groups(entries: &[Entry], grouping: Grouping) -> Vec { + let mut by_key: BTreeMap> = BTreeMap::new(); + for e in entries { + by_key.entry(grouping.key(&e.name)).or_default().push(e); + } + by_key + .into_iter() + .map(|(key, members)| Group { hash: hash_of(members.iter().copied()), count: members.len(), key }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + + fn entry(name: &str, fingerprint: &str) -> Entry { + Entry { + name: name.into(), + platform: String::new(), + kind: "image".into(), + fingerprint: fingerprint.into(), + format: None, + engine: None, + threshold: None, + ignore_anti_aliasing: None, + ignore: serde_json::json!({ "json_paths": [], "text_patterns": [] }), + } + } + + #[test] + fn groups_names_by_all_but_their_last_two_segments_by_default() { + let g = Grouping::default(); + assert_eq!(g.key("pdf_engine/forms/w9/page-1"), "pdf_engine/forms"); + assert_eq!(g.key("forms/page-1"), ""); + assert_eq!(g.key("page-1"), ""); + assert_eq!(Grouping::Depth(1).key("pdf_engine/forms/w9/page-1"), "pdf_engine"); + assert_eq!(Grouping::Depth(9).key("pdf_engine/forms/w9/page-1"), "pdf_engine/forms/w9"); + } + + #[test] + fn hashes_ignore_order_and_change_with_any_field() { + let a = vec![entry("a/b/c/1", "f1"), entry("a/b/c/2", "f2")]; + let b = vec![entry("a/b/c/2", "f2"), entry("a/b/c/1", "f1")]; + assert_eq!(manifest_hash(&a), manifest_hash(&b)); + let mut changed = a.clone(); + changed[1].threshold = Some(0.1); + assert_ne!(manifest_hash(&a), manifest_hash(&changed)); + let mut renamed = a.clone(); + renamed[0].platform = "chromium-linux".into(); + assert_ne!(manifest_hash(&a), manifest_hash(&renamed)); + } + + #[test] + fn a_change_shows_in_its_own_group_only() { + let before = vec![entry("x/one/a/1", "f1"), entry("x/one/a/2", "f2"), entry("x/two/b/1", "f3")]; + let mut after = before.clone(); + after[2].fingerprint = "f4".into(); + let (b, a) = (groups(&before, Grouping::default()), groups(&after, Grouping::default())); + assert_eq!(b.iter().map(|g| (g.key.as_str(), g.count)).collect::>(), [("x/one", 2), ("x/two", 1)]); + assert_eq!(b[0].hash, a[0].hash); + assert_ne!(b[1].hash, a[1].hash); + } +} diff --git a/docs/design.md b/docs/design.md index e9e8f602..fbcc5c47 100644 --- a/docs/design.md +++ b/docs/design.md @@ -81,6 +81,21 @@ client Fingerprints for step 2 are computed on the client with the same open-source library the server uses (Rust, compiled into the CLI and the Ruby gem's native extension or WASM), so a hash hit never uploads a byte. +### Large suites: manifest and group hashes (sc-8868) + +A run of 500 or more snapshots (the CLI decides; `VISUALCI_GROUPS` overrides) first sends `POST /builds/:id/groups`: +a hash of the whole run and one hash per group of names (a name's group is its path without the last two segments, +or its first `group_depth` segments). Hashes come from `visualci_core::manifest`, over each snapshot's name, +platform, kind, fingerprint and comparison settings, so the CLI and the server compute them the same way. The +server computes the baseline's side from its own rows (`baselines::resolve`), never from a client's claim, records +each group in `build_groups` and answers which groups differ. The client sends only those groups' files. + +When the build processes, the snapshots of matched groups (all of them, when the whole run matched: +`builds.manifest_same_as_build_id`) are carried forward from their baselines, as a subset build's missing snapshots +are, so every later reader sees a complete build. A matched group costs `CREDITS_PER_GROUP_CHECK` (1) and a matched +run 1 in all; changed groups' snapshots are charged as usual. A group can be sent by one shard only. The UI and +`get_build` show the matched groups collapsed ("N groups unchanged, the same as #M"). + ### Source fingerprints - **PDF, byte-stable producers** (ironpress, which has no dates, IDs or Producer): `sha256(bytes)` is enough. It's diff --git a/gemini-extension.json b/gemini-extension.json index 141bfdde..c86b69a8 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.38", + "version": "0.1.42", "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/reference/cli.md b/server/frontend/content/docs/reference/cli.md index 5634b744..366de67f 100644 --- a/server/frontend/content/docs/reference/cli.md +++ b/server/frontend/content/docs/reference/cli.md @@ -41,6 +41,10 @@ Adds files or directories of them to a build: PDFs, PNG, JPEG and WebP images, a | `--manifest ` | A JSON array or JSON Lines of `{"name", "path", "platform"?, "threshold"?, "engine"?, "format"?, "ignore"?}`, for test helpers that choose names themselves. `ignore` is `{"json_paths": [...], "text_patterns": [...]}` for that snapshot only. | | `--allow-empty` | Succeed when there's nothing to upload. Without it, an upload that finds no snapshot files is an error. | +With 500 or more snapshots, `upload` first sends a hash of the run and one per group of names (`group_depth` in +visualci.yml), and then only the snapshots of groups that differ from their baselines; the rest are carried forward on +the server, at 1 credit per group (see [Large suites](/docs/reference/credits/#large-suites)). It says how many groups +were unchanged. `VISUALCI_GROUPS=0` turns this off, and `VISUALCI_GROUPS=1` uses it for any size. ## visualci snapshot `visualci snapshot ` adds one file under the given name. It takes the same options as `upload`, except `--manifest`. diff --git a/server/frontend/content/docs/reference/config.md b/server/frontend/content/docs/reference/config.md index eda0c74a..90252567 100644 --- a/server/frontend/content/docs/reference/config.md +++ b/server/frontend/content/docs/reference/config.md @@ -50,6 +50,7 @@ The build's page shows the file it was sent, and `get_build` returns it as `conf | `pdf.engine` | `pdfbox` or `mutool`. | | `pdf.dpi` | Render resolution, 36 to 600. | | `ci_mode` | `review`, `wait` or `strict`. The file can only make the project's mode stricter (in that order); a looser value is ignored, with a warning on the build. See [GitLab CI](/docs/ci/gitlab/#reviewing-without-a-github-check). | +| `group_depth` | Large suites: how many leading path segments of a snapshot's name make its group, for runs checked by group (500 or more snapshots). By default, all but the last two. See [Large suites](/docs/reference/credits/#large-suites). | | `uploads` | What a bare `visualci upload` sends: a list of `path` (relative to the file), with optional `from` (`jest`, `vitest`, `insta`, `syrupy`, `rspec` or `auto`), `prefix` and `format`. | | `gallery` | Screenshots to publish at public URLs, in groups: `groups` is a list of `name`, an optional `title`, and `include` (snapshot globs). Nothing is public unless a group includes it. See [Public gallery](/docs/gallery/). | diff --git a/server/frontend/content/docs/reference/credits.md b/server/frontend/content/docs/reference/credits.md index e0fef93a..e858a491 100644 --- a/server/frontend/content/docs/reference/credits.md +++ b/server/frontend/content/docs/reference/credits.md @@ -8,6 +8,7 @@ Builds use credits. Work VisualCI has done before is never done again: a PDF pag | Work | Credits | | --- | --- | | A snapshot checked | 1 | +| A group of snapshots unchanged since its baseline (runs of 500 or more snapshots) | 1 | | A text diff (a text, JSON or HTML snapshot that changed) | 5 | | An image diff (a changed page or screenshot) | 10 | | A PDF page drawn | 20 | @@ -15,6 +16,23 @@ Builds use credits. Work VisualCI has done before is never done again: a PDF pag Snapshots carried forward from skipped shards (`--subset`) cost nothing. +## Large suites + +A run of 500 or more snapshots is checked by group. Before sending any files, the CLI sends a hash of the whole run +and one hash per group of names, and VisualCI compares them with the build's baselines: + +- **Nothing changed:** the run's hash matches its baseline's, so nothing is sent, and the build costs 1 credit. +- **Some groups changed:** each group whose hash matches its baseline costs 1 credit, whatever its size, and isn't + sent. The changed groups' snapshots are sent and charged as usual, 1 per snapshot checked plus any diffs. + +A name's group is its path without the last two segments: `pdf/forms/w9/page-1` is in `pdf/forms`. To group by fewer +or more segments, set `group_depth` in [visualci.yml](/docs/reference/config/). A group's snapshots must be sent from +one shard of a sharded build. `VISUALCI_GROUPS=0` turns grouping off, and `VISUALCI_GROUPS=1` uses it for runs of any +size. + +For example, 4,000 PDF page screenshots in 300 groups, where one screenshot changed: the 299 unchanged groups cost 299 +credits, and the changed group's 14 snapshots cost 14 credits plus 10 for the image diff, 323 in all, instead of 4,010. + ## Plans - **Free:** 25,000 credits a month. When they're used up, builds stop being compared until the allowance renews on the 1st. diff --git a/server/frontend/content/llms-header.md b/server/frontend/content/llms-header.md index 7a4eaf57..49f6a193 100644 --- a/server/frontend/content/llms-header.md +++ b/server/frontend/content/llms-header.md @@ -37,7 +37,7 @@ A changed snapshot doesn't fail CI: the GitHub check waits until the change is a - Ignore rules (in `visualci.yml` under `ignore`, or the project's Settings tab, or `update_project` with `ignore_rules`): each rule has `snapshots` (a required glob over snapshot names, `**` for all), `json_paths` such as `$.generated_at`, `$.items[*].id` or `$..request_id`, and `text_patterns` (regular expressions). Matches are replaced with `[ignored]` on both sides before comparing. A test can add rules for one snapshot (`ignore` in the upload manifest, or `ignore:` in the Ruby helpers). - Existing snapshot files: `visualci upload --from auto ` splits Jest and Vitest `__snapshots__/*.snap` files (one snapshot per test), insta `.snap` files, syrupy `.ambr` files (one per test) and rspec-snapshot `.snap` files. `--from jest|vitest|insta|syrupy|rspec` forces one framework. - Ruby: `expect_json_to_match_snapshot(name, hash)`, `expect_html_to_match_snapshot`, `expect_text_to_match_snapshot` from `visualci/rspec`. -- Credits: 1 per snapshot checked, 5 per text diff (a text, JSON or HTML snapshot that changed), 10 per image diff (a changed page or screenshot) and 20 per PDF page drawn. Work done before is never charged again. Details: https://visualci.com/docs/reference/credits/ +- Credits: 1 per snapshot checked (or 1 per unchanged group of snapshots in runs of 500 or more), 5 per text diff (a text, JSON or HTML snapshot that changed), 10 per image diff (a changed page or screenshot) and 20 per PDF page drawn. Work done before is never charged again. Details: https://visualci.com/docs/reference/credits/ ## Support for agents (Standard Support, level 1) diff --git a/server/frontend/content/pages/compare/argos.md b/server/frontend/content/pages/compare/argos.md index ec7b6c6e..deb4e9b7 100644 --- a/server/frontend/content/pages/compare/argos.md +++ b/server/frontend/content/pages/compare/argos.md @@ -41,7 +41,7 @@ month free, on any plan. ($0.0015 for Storybook screenshots), with a 14-day trial. Enterprise is priced by quote. Agent use isn't charged separately. -For 35,000 screenshots a month with 2,000 changes, VisualCI uses 55,000 credits, which fits the $29 Team plan. Argos +For 35,000 screenshots a month with 2,000 changes, VisualCI uses at most 55,000 credits (less when runs of 500 or more are checked by group), which fits the $29 Team plan. Argos Pro covers the same month for $100. Prices as of 1 December 2026. ## When to choose Argos diff --git a/server/frontend/content/pages/compare/chromatic.md b/server/frontend/content/pages/compare/chromatic.md index f26fcc17..75500de0 100644 --- a/server/frontend/content/pages/compare/chromatic.md +++ b/server/frontend/content/pages/compare/chromatic.md @@ -43,7 +43,7 @@ month free, on any plan. snapshot. Pro is $399 a month for 85,000. Enterprise is priced by quote. With TurboSnap, a story that didn't change counts as a fifth of a snapshot. -For 35,000 screenshots a month with 2,000 changes, VisualCI uses 55,000 credits, which fits the $29 Team plan. +For 35,000 screenshots a month with 2,000 changes, VisualCI uses at most 55,000 credits (less when runs of 500 or more are checked by group), which fits the $29 Team plan. Chromatic's Starter plan at $179 covers the same 35,000 snapshots. Prices as of 1 December 2026. ## When to choose Chromatic diff --git a/server/frontend/content/pages/compare/happo.md b/server/frontend/content/pages/compare/happo.md index db57fe89..e6f0abf2 100644 --- a/server/frontend/content/pages/compare/happo.md +++ b/server/frontend/content/pages/compare/happo.md @@ -38,7 +38,7 @@ fee. Team is $199 a month for 66,000 snapshots, then $3 per 1,000. Pro is $599 a Enterprise starts at $1,499 a month. Yearly billing is 10% off. Each browser and the accessibility check count as separate snapshots. -For 35,000 screenshots a month with 2,000 changes, VisualCI uses 55,000 credits, which fits the $29 Team plan. On +For 35,000 screenshots a month with 2,000 changes, VisualCI uses at most 55,000 credits (less when runs of 500 or more are checked by group), which fits the $29 Team plan. On Happo's pay-as-you-go plan the same 35,000 snapshots in one browser cost $140. Prices as of 1 December 2026. ## When to choose Happo diff --git a/server/frontend/content/pages/compare/percy.md b/server/frontend/content/pages/compare/percy.md index 93c08351..640e678e 100644 --- a/server/frontend/content/pages/compare/percy.md +++ b/server/frontend/content/pages/compare/percy.md @@ -37,7 +37,7 @@ month free, on any plan. screenshots, with 25,000 and custom tiers; extra screenshots cost $0.036. Desktop & Mobile starts at $599 a month, billed annually, with extra screenshots at $0.048. Enterprise is priced by quote. -For 35,000 screenshots a month with 2,000 changes, VisualCI uses 55,000 credits, which fits the $29 Team plan. On +For 35,000 screenshots a month with 2,000 changes, VisualCI uses at most 55,000 credits (less when runs of 500 or more are checked by group), which fits the $29 Team plan. On Percy, that volume is above the Desktop plan's 10,000 and 25,000 tiers. Prices as of 1 December 2026. ## When to choose Percy diff --git a/server/frontend/content/pages/compare/uiverify.md b/server/frontend/content/pages/compare/uiverify.md index ceca8252..e5fe5459 100644 --- a/server/frontend/content/pages/compare/uiverify.md +++ b/server/frontend/content/pages/compare/uiverify.md @@ -42,7 +42,7 @@ month free, on any plan. a month for 30,000 snapshots and 1,000 AI reviews. Pro is $199 a month for 65,000 snapshots and 2,500 AI reviews. Extra snapshots cost $0.004 and extra AI reviews $0.03. Stories it skips as unchanged aren't billed. -For 35,000 screenshots a month with 2,000 changes, VisualCI uses 55,000 credits, which fits the $29 Team plan. On UI +For 35,000 screenshots a month with 2,000 changes, VisualCI uses at most 55,000 credits (less when runs of 500 or more are checked by group), which fits the $29 Team plan. On UI Verify's Starter plan the same month is $89 plus $20 for 5,000 extra snapshots, or less when stories are skipped as unchanged. Prices as of 1 December 2026. diff --git a/server/frontend/public/visualci.schema.json b/server/frontend/public/visualci.schema.json index c2458910..6acea188 100644 --- a/server/frontend/public/visualci.schema.json +++ b/server/frontend/public/visualci.schema.json @@ -197,6 +197,15 @@ ], "description": "Screenshots to publish: their approved default-branch versions are served at public URLs and in an embeddable\ngallery. Nothing is public unless a group includes it." }, + "group_depth": { + "description": "Large suites: names are grouped for group hashes by their first this many path segments (by default, all but\nthe last two). A group whose snapshots match their baselines isn't sent again (sc-8868).", + "format": "uint32", + "minimum": 0, + "type": [ + "integer", + "null" + ] + }, "ignore": { "description": "Values that change on every run, replaced with `[ignored]` before text snapshots are compared. Each rule names\nthe snapshots it applies to. When the file has `ignore`, the project's own rules aren't used.", "items": { diff --git a/server/frontend/src/api/types.ts b/server/frontend/src/api/types.ts index 1a41d5a3..1bc44eb7 100644 --- a/server/frontend/src/api/types.ts +++ b/server/frontend/src/api/types.ts @@ -331,6 +331,18 @@ export type BuildDetail = BuildSummary & { config: Record | null /** About the build's settings: a ci_mode the file can't loosen, ignore rules that matched nothing. */ warnings?: string[] + /** A large suite's groups (sc-8868): those that matched their baselines were carried forward, not sent. */ + groups?: BuildGroups | null +} + +/** A build's groups of snapshots, for a large suite that sent group hashes. */ +export type BuildGroups = { + manifest_matched: boolean + unchanged_groups: number + unchanged_snapshots: number + same_as_build: number | null + changed_groups: string[] + unchanged_group_keys: string[] } /** An ignore rule applied to a text snapshot: from the build's visualci.yml, the test, or the project's settings. */ diff --git a/server/frontend/src/pages/BuildPage.tsx b/server/frontend/src/pages/BuildPage.tsx index 978cd537..4a636606 100644 --- a/server/frontend/src/pages/BuildPage.tsx +++ b/server/frontend/src/pages/BuildPage.tsx @@ -14,7 +14,7 @@ import { XIcon, } from '@phosphor-icons/react' import { useBuild, useProject, useReview } from '../api/hooks' -import type { ApprovedElsewhere, BuildDetail, BuildReview, SnapshotRow, SnapshotState } from '../api/types' +import type { ApprovedElsewhere, BuildDetail, BuildGroups, BuildReview, SnapshotRow, SnapshotState } from '../api/types' import { errorMessage } from '../api/client' import { QueryState } from '../components/QueryState' import { PresignedImg, useExpiredRefetch } from '../components/PresignedImg' @@ -151,6 +151,7 @@ export function BuildPage() {

)} + {build.groups && build.groups.unchanged_groups > 0 && } {build.summary &&

{build.summary}

}