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.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/",
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.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/",
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.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"
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.19"
version = "0.2.20"
edition = "2024"
license = "Apache-2.0"
repository = "https://github.com/DocSpring/visualci"
Expand Down
2 changes: 1 addition & 1 deletion app/Cargo.lock

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

37 changes: 23 additions & 14 deletions crates/visualci-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn par_map<T: Sync, R: Send>(items: &[T], f: impl Fn(&T) -> Result<R> + 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.
Expand Down Expand Up @@ -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)?)?)
}
Expand Down Expand Up @@ -407,7 +409,7 @@ pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec<u8>)> {
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)?
};
Expand All @@ -416,11 +418,10 @@ pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec<u8>)> {
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,
Expand All @@ -429,6 +430,10 @@ pub fn registration(s: &Snapshot) -> Result<(serde_json::Value, Vec<u8>)> {
"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))
}

Expand All @@ -453,7 +458,8 @@ pub fn entry_of(params: &serde_json::Value) -> Result<visualci_core::manifest::E
name,
platform: str_of("platform").unwrap_or_default(),
kind,
fingerprint: str_of("fingerprint").unwrap_or_default(),
// An image's entry holds its file's hash, as `check_groups` tells the server (`image_hash`).
fingerprint: str_of("fingerprint").or_else(|| str_of("sha256")).unwrap_or_default(),
format,
engine: str_of("engine"),
threshold: params["threshold"].as_f64(),
Expand All @@ -462,11 +468,13 @@ pub fn entry_of(params: &serde_json::Value) -> Result<visualci_core::manifest::E
})
}

/// Kind, fingerprint and content type of a file.
pub fn classify(path: &Path, bytes: &[u8]) -> 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<String>, &'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"),
Expand All @@ -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.
Expand Down Expand Up @@ -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));
Expand Down
7 changes: 4 additions & 3 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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.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": {
Expand Down
2 changes: 1 addition & 1 deletion server/frontend/content/docs/pdfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions server/frontend/content/docs/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project token>` (`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"`).

Expand Down Expand Up @@ -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 <file>` 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 <file>` 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.
Expand Down
5 changes: 5 additions & 0 deletions server/frontend/content/docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Adds files or directories of them to a build: PDFs, PNG, JPEG and WebP images, a
| `--manifest <file>` | 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
Expand Down
2 changes: 1 addition & 1 deletion server/frontend/content/docs/screenshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion skills/visualci-pdfs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading