insta (Rust)

insta writes .snap files, by default to a snapshots/ directory next to each test file. VisualCI reads them (without insta's header) as one snapshot per file.

1. Stop committing snapshot files

The baselines live on VisualCI, so the snapshot files don't belong in git. Add them to .gitignore:

**/snapshots/*.snap
**/snapshots/*.snap.new

Then remove the committed copies (git rm -r --cached on those paths). In a new project, the first build has nothing to compare against and becomes the baseline. In a project that already has builds, the snapshots show as added the first time, for your agent to approve once.

2. Write snapshots instead of failing

Have insta write every snapshot and let the assertions pass, locally and in CI:

INSTA_UPDATE=always INSTA_FORCE_PASS=1 cargo test

By default insta doesn't write snapshots in CI and fails on any mismatch. INSTA_UPDATE=always overwrites the .snap files in place, and INSTA_FORCE_PASS=1 keeps a snapshot assertion from failing the test. VisualCI does the comparing.

3. Upload after the tests

In the CI job, after the tests (see Quick start for creating the build):

visualci upload --from insta .
visualci build finalize

Snapshot names are the file's path without the extension. --from auto detects each file's framework, for repositories with several.

When a snapshot changed, CI still passes and the pull request's check waits. Your coding agent reads the change with get_snapshot, which shows text snapshots as a unified diff and JSON as changes by path (items[3].price: 10 → 12), then approves it or fixes the code. See Coding agents.

Ignore volatile values

Timestamps, generated IDs and other values that change on every run would show up as changes. Ignore them in visualci.yml at the root of your repository. Each rule names the snapshots it applies to with a glob:

ignore:
  - snapshots: "src/api/**"
    json_paths: ["$.generated_at", "$.items[*].id"]
  - snapshots: "**"
    text_patterns: ['\d{4}-\d{2}-\d{2}T[\d:.]+Z']
  • json_paths for JSON snapshots: $.generated_at, $.items[*].id, $..request_id;
  • text_patterns, regular expressions for every text format.

Matching values are replaced with [ignored] on both sides before comparing, so a new rule takes effect without approving the baseline again. Projects without the file use the rules on the project's Settings tab.

Before you push

visualci check runs the same comparison from your laptop:

INSTA_UPDATE=always INSTA_FORCE_PASS=1 cargo test && visualci check --from insta .

It creates a local build, waits for the result and prints what changed, with a link to the diff. Approving a local change makes it the baseline for your branch, so CI matches it when you push. Screenshots keep a separate set per environment (ci, local-mac, local-linux); text and PDFs share one.