diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index e79b66da..5f329a7f 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.47", + "version": "0.1.48", "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 34ab9a4e..9f780b56 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.47", + "version": "0.1.48", "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 223f9a3b..8b52af92 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.47", + "version": "0.1.48", "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 4617edd7..598266f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5238,7 +5238,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "visualci-cli" -version = "0.2.19" +version = "0.2.20" dependencies = [ "anyhow", "base64 0.22.1", @@ -5255,7 +5255,7 @@ dependencies = [ [[package]] name = "visualci-core" -version = "0.2.19" +version = "0.2.20" dependencies = [ "globset", "hex", @@ -5275,7 +5275,7 @@ dependencies = [ [[package]] name = "visualci-renderer" -version = "0.2.19" +version = "0.2.20" dependencies = [ "anyhow", "image", @@ -5290,7 +5290,7 @@ dependencies = [ [[package]] name = "visualci-wasm" -version = "0.2.19" +version = "0.2.20" dependencies = [ "image", "serde", @@ -5300,7 +5300,7 @@ dependencies = [ [[package]] name = "visualci_server" -version = "0.2.19" +version = "0.2.20" dependencies = [ "aes-gcm", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 4a345631..42523320 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/*", "server", "server/migration"] [workspace.package] -version = "0.2.19" +version = "0.2.20" edition = "2024" license = "Apache-2.0" repository = "https://github.com/DocSpring/visualci" diff --git a/app/Cargo.lock b/app/Cargo.lock index 559835ef..c1fce808 100644 --- a/app/Cargo.lock +++ b/app/Cargo.lock @@ -4949,7 +4949,7 @@ dependencies = [ [[package]] name = "visualci-core" -version = "0.2.19" +version = "0.2.20" dependencies = [ "globset", "hex", diff --git a/crates/visualci-cli/src/client.rs b/crates/visualci-cli/src/client.rs index f617eb51..cb398533 100644 --- a/crates/visualci-cli/src/client.rs +++ b/crates/visualci-cli/src/client.rs @@ -58,7 +58,7 @@ pub fn par_map(items: &[T], f: impl Fn(&T) -> Result + Sync }) } -/// Every snapshot's registration and bytes (`registration`), decoded and fingerprinted in parallel, in order. +/// Every snapshot's registration and bytes (`registration`), hashed in parallel, in order. /// /// # Errors /// The first snapshot (in order) whose file can't be read or classified. @@ -274,6 +274,8 @@ impl Client { "manifest_hash": manifest::manifest_hash(entries), "group_depth": group_depth, "groups": groups, + // Images' entries hold their files' hashes (`entry_of`), not pixel fingerprints. + "image_hash": "sha256", }); Ok(serde_json::from_value(self.post(&format!("/api/v1/builds/{build_id}/groups"), &body)?)?) } @@ -407,7 +409,7 @@ pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec)> { 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") + ("text", Some(visualci_core::sha256_hex(&bytes)), "text/plain") } else { classify(&s.path, &bytes)? }; @@ -416,11 +418,10 @@ pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec)> { content_type = Format::detect(s.format.as_deref(), None, if s.content.is_some() { None } else { name }).content_type(); } - let params = json!({ + let mut 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, @@ -429,6 +430,10 @@ pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec)> { "format": s.format, "ignore": s.ignore, }); + // An image goes by its file's hash alone: the server fingerprints the files it doesn't have (sc-8999). + if let Some(fingerprint) = fingerprint { + params["fingerprint"] = json!(fingerprint); + } Ok((params, bytes)) } @@ -453,7 +458,8 @@ pub fn entry_of(params: &serde_json::Value) -> Result Result Result<(&'static str, String, &'static str)> { +/// Kind, fingerprint and content type of a file. An image has no fingerprint here: it isn't decoded, and the server +/// fingerprints the images it hasn't seen (sc-8999). A PDF keeps its fingerprint, since its bytes change from run to +/// run (dates, IDs) while what it draws doesn't, and the fingerprint saves the upload and the render. +pub fn classify(path: &Path, bytes: &[u8]) -> Result<(&'static str, Option, &'static str)> { let ext = path.extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase(); if bytes.starts_with(b"%PDF") { - return Ok(("document", visualci_core::pdf::fingerprint_bytes(bytes).document, "application/pdf")); + return Ok(("document", Some(visualci_core::pdf::fingerprint_bytes(bytes).document), "application/pdf")); } let image_type = match ext.as_str() { "png" => Some("image/png"), @@ -475,12 +483,10 @@ pub fn classify(path: &Path, bytes: &[u8]) -> Result<(&'static str, String, &'st _ => None, }; if let Some(content_type) = image_type { - let fp = visualci_core::image_hash::fingerprint_bytes(bytes) - .with_context(|| format!("decoding {}", path.display()))?; - return Ok(("image", fp, content_type)); + return Ok(("image", None, content_type)); } let name = path.file_name().and_then(|n| n.to_str()); - Ok(("text", visualci_core::sha256_hex(bytes), Format::detect(None, None, name).content_type())) + Ok(("text", Some(visualci_core::sha256_hex(bytes)), Format::detect(None, None, name).content_type())) } /// One snapshot split out of a snapshot file: its name, format, content and the file it came from. @@ -794,8 +800,11 @@ mod tests { let sequential: Vec<_> = snaps.iter().map(|s| registration(s).unwrap()).collect(); let parallel = registrations(&snaps).unwrap(); assert_eq!(parallel, sequential); - // Distinct images got distinct fingerprints, so the order really was checked. - assert_ne!(parallel[0].0["fingerprint"], parallel[1].0["fingerprint"]); + // Distinct images got distinct hashes, so the order really was checked. + assert_ne!(parallel[0].0["sha256"], parallel[1].0["sha256"]); + // Images go by their hash alone, undecoded; texts keep their fingerprint. + assert!(parallel[0].0.get("fingerprint").is_none(), "{}", parallel[0].0); + assert!(parallel.iter().any(|(p, _)| p["kind"] == "text" && p["fingerprint"].is_string())); // The first failing snapshot's error, as the sequential loop gave. snaps.insert(5, snap("missing-a", dir.join("missing-a.png"), None)); diff --git a/docs/design.md b/docs/design.md index f1a0fd85..4346e93f 100644 --- a/docs/design.md +++ b/docs/design.md @@ -89,9 +89,10 @@ render moves to the fingerprint when the project has none under it). A re-encode after a browser upgrade) is uploaded once and kept as its own blob under its own hash, with the same fingerprint, so it compares unchanged and later runs match it by hash with no upload or decode. Blobs are never merged by fingerprint. -The CLI still fingerprints PDFs (with the same open-source library the server and renderer use): a PDF's bytes change -on every run (creation dates, IDs) while what it draws doesn't, so the fingerprint saves an upload and a render. Older -CLIs send every fingerprint, and the server takes them as they are. Registration costs the same few statements for 1 +The CLI sends images by their hash alone and the server fingerprints them (Nathan's decision, sc-8999). PDFs still +carry the CLI's fingerprint (with the same open-source library the server and renderer use): a PDF's bytes change on +every run (creation dates, IDs) while what it draws doesn't, so without it every PDF would be uploaded, and drawn, on +every run. CLIs before 0.2.20 send every fingerprint, and the server takes them as they are. Registration costs the same few statements for 1 snapshot or 1,000 (the blobs' upsert and read, one renders query, the snapshots' upsert). ### Large suites: manifest and group hashes (sc-8868) diff --git a/gemini-extension.json b/gemini-extension.json index 326ed8f5..8348fae7 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.47", + "version": "0.1.48", "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/pdfs.md b/server/frontend/content/docs/pdfs.md index 3f1eea46..a4547e91 100644 --- a/server/frontend/content/docs/pdfs.md +++ b/server/frontend/content/docs/pdfs.md @@ -41,7 +41,7 @@ Documents are compared exactly by default: any changed pixel is a change. ## Fingerprints -Before uploading, the CLI fingerprints each PDF by what it draws. The fingerprint leaves out creation dates, document IDs and producer strings, so a regenerated PDF that draws the same thing still matches, and nothing is uploaded, rendered or diffed. +Before uploading, the CLI fingerprints each PDF by what it draws. The fingerprint leaves out creation dates, document IDs and producer strings, so a regenerated PDF that draws the same thing still matches, and nothing is uploaded, rendered or diffed. (Images are sent by their file's hash alone, but a PDF's bytes change on every run, so it keeps its fingerprint: without it, every PDF would be uploaded every run.) Each page is fingerprinted too, so pages are matched by content instead of by position. A document that gains a page shows one inserted page, not every later page changed. diff --git a/server/frontend/content/docs/reference/api.md b/server/frontend/content/docs/reference/api.md index 1c1288ba..cc09c8e0 100644 --- a/server/frontend/content/docs/reference/api.md +++ b/server/frontend/content/docs/reference/api.md @@ -3,7 +3,7 @@ title: API reference description: VisualCI's CI API (builds, snapshots, finalize), its project settings, and the MCP server for everything else. --- -The CLI uses this API. Most integrations should use the CLI, which fingerprints files and uploads them for you. Coding agents use the [MCP server](/docs/agents/), which covers everything the web app does. +The CLI uses this API. Most integrations should use the CLI, which hashes files and uploads the new ones for you. Coding agents use the [MCP server](/docs/agents/), which covers everything the web app does. All requests go to `https://api.visualci.com/api/v1` with `Authorization: Bearer ` (`vci_...`). Bodies and responses are JSON. A body with a field the endpoint doesn't take is refused (422, naming the field and the ones it takes), so a misspelt field never passes unnoticed. The MCP server's tools do the same. Numbers may be sent as JSON numbers or as strings holding them (`"2"`). @@ -48,7 +48,7 @@ All requests go to `https://api.visualci.com/api/v1` with `Authorization: Bearer ``` - `kind` is `document` (a PDF), `image` or `text`. -- `sha256` is the SHA-256 of the file's bytes. `fingerprint` is optional: the PDF fingerprint for documents, the pixel fingerprint for images, and the SHA-256 of the text for text (`visualci fingerprint ` prints the first two). Without it, VisualCI uses the fingerprint it computed for the file before, or computes it once the file is uploaded. Sending a PDF's fingerprint saves an upload when only its bytes changed (a new creation date). +- `sha256` is the SHA-256 of the file's bytes. `fingerprint` is optional: the PDF fingerprint for documents, the pixel fingerprint for images, and the SHA-256 of the text for text (`visualci fingerprint ` prints the first two). Without it, VisualCI uses the fingerprint it computed for the file before, or computes it once the file is uploaded. The CLI sends images by their hash alone and lets VisualCI fingerprint them, and sends each PDF's fingerprint: a PDF's bytes change on every run (its creation date and ID) while what it draws doesn't, so without the fingerprint every PDF would be uploaded on every run. - Optional: `threshold`, `ignore_anti_aliasing`, `engine` (`pdfbox` or `mutool`), `format` (`text`, `json` or `html`; without it the content type decides), `ignore` (`{"json_paths": [...], "text_patterns": [...]}`, set in the test, for this snapshot only). The response lists each snapshot with an `upload_url`. PUT the file's bytes there with its `content_type`, within 15 minutes (register again for a fresh link). `upload_url` is `null` when VisualCI already has the file. A file can be at most 64 MiB, and its bytes must match its `sha256`: anything else is discarded and reported missing. diff --git a/server/frontend/content/docs/reference/cli.md b/server/frontend/content/docs/reference/cli.md index fac8bca4..f3909176 100644 --- a/server/frontend/content/docs/reference/cli.md +++ b/server/frontend/content/docs/reference/cli.md @@ -41,6 +41,11 @@ 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. | +`upload` sends each image by its file's SHA-256 alone, without decoding it: a file VisualCI already has isn't uploaded, +and VisualCI fingerprints the new ones by their pixels itself. PDFs still carry the CLI's fingerprint of what they draw, +because a PDF's bytes change on every run (its creation date and ID) while what it draws doesn't: without the +fingerprint, every PDF would be uploaded on every run. + 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 diff --git a/server/frontend/content/docs/screenshots.md b/server/frontend/content/docs/screenshots.md index 4382772d..a08da325 100644 --- a/server/frontend/content/docs/screenshots.md +++ b/server/frontend/content/docs/screenshots.md @@ -9,7 +9,7 @@ VisualCI compares PNG, JPEG and WebP images. Send the screenshots your tests alr visualci upload tmp/screenshots ``` -Each file's path, relative to the directory you upload, without the extension, is its snapshot name. The CLI fingerprints each image by its pixels first, so an image VisualCI has already seen isn't uploaded or diffed again. +Each file's path, relative to the directory you upload, without the extension, is its snapshot name. The CLI sends each image's SHA-256 first, so a file VisualCI already has isn't uploaded again. VisualCI fingerprints new images by their pixels, so a re-encoded screenshot with the same pixels (after a browser upgrade, say) is uploaded once and compares unchanged, without a diff. ## Platforms diff --git a/skills/visualci-pdfs/SKILL.md b/skills/visualci-pdfs/SKILL.md index 2661a084..050f260f 100644 --- a/skills/visualci-pdfs/SKILL.md +++ b/skills/visualci-pdfs/SKILL.md @@ -46,7 +46,7 @@ Documents are compared exactly by default: any changed pixel is a change. ## Fingerprints -Before uploading, the CLI fingerprints each PDF by what it draws. The fingerprint leaves out creation dates, document IDs and producer strings, so a regenerated PDF that draws the same thing still matches, and nothing is uploaded, rendered or diffed. +Before uploading, the CLI fingerprints each PDF by what it draws. The fingerprint leaves out creation dates, document IDs and producer strings, so a regenerated PDF that draws the same thing still matches, and nothing is uploaded, rendered or diffed. (Images are sent by their file's hash alone, but a PDF's bytes change on every run, so it keeps its fingerprint: without it, every PDF would be uploaded every run.) Each page is fingerprinted too, so pages are matched by content instead of by position. A document that gains a page shows one inserted page, not every later page changed.