Skip to content

fix: stop snapshot tests from modifying source files - #2227

Open
bruschill wants to merge 5 commits into
meshtastic:mainfrom
bruschill:fix/snapshot-test-churn
Open

fix: stop snapshot tests from modifying source files#2227
bruschill wants to merge 5 commits into
meshtastic:mainfrom
bruschill:fix/snapshot-test-churn

Conversation

@bruschill

@bruschill bruschill commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What changed?

  • Require SNAPSHOT_RECORD=1 before snapshot tests create or replace reference PNGs.
  • Add the missing aboutMeshtastic reference and move formattingToolbar to test-only snapshots.
  • Remove three stale test-only references whose tests either write to the docs directory or no longer exist.
  • Insert node-row snapshot fixtures into the shared SwiftData container so the views render instead of returning EmptyView.
  • Run all 38 snapshot suites on pull requests and fail if they change reference files.
  • Keep screenshot cleanup separate from copy-snapshots.sh.

Why did it change?

A normal snapshot test run silently created missing PNGs and rewrote references when dimensions changed. copy-snapshots.sh also deleted an unreferenced docs snapshot, creating a record-delete-record loop.

The node-row snapshot fixtures had also been detached from SwiftData since the liveness guard in 98b5444e, so 19 tests rendered one-point-high empty views and rewrote their references.

Fixes #2213.

How is this tested?

  • Reproduced the missing-reference bug on upstream/main: the test passed and created an untracked PNG.
  • Confirmed the fixed helper fails on a missing reference without creating a file.
  • Confirmed TEST_RUNNER_SNAPSHOT_RECORD=1 records the two missing references.
  • Ran the About and MessagePreview suites: 6 tests passed with no reference changes.
  • Reproduced the node-row failure in a clean upstream/main worktree: 19 one-point-height failures and 19 rewritten references.
  • Confirmed the fixed fixtures render all 19 rows and do not rewrite references.
  • Recorded 16 canonical reference updates with the pull request workflow's Xcode 26.3/iOS 18.5 renderer: 15 repaired node-row snapshots and ackErrors.png.
  • Replaced the stale Xcode 16 workflow pin after CI showed that Xcode 16.3 lacked its simulator runtime and Xcode 16.4 could not compile the current Translation APIs. The final Xcode 26.3 verify-only run passed without reference changes.
  • Confirmed copy-snapshots.sh copied 99 referenced files without deleting an orphan sentinel.
  • Ran git diff --check, shell syntax checks, and workflow suite discovery. The workflow finds all 38 suites.

Screenshots/Videos (when applicable)

New reference images:

  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/aboutMeshtastic.png
  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/formattingToolbar.png

Checklist

  • My code adheres to the project's coding and style guidelines.
  • I have conducted a self-review of my code.
  • I have commented my code, particularly in complex areas.
  • I have verified whether these changes require updates to the in-app documentation under docs/user/ or docs/developer/, and updated accordingly (see copilot-instructions.md for the view → doc page mapping). No user-facing documentation change is needed; the skip-docs-check label is applied.
  • I have tested the change to ensure that it works as intended.

Summary by CodeRabbit

  • Bug Fixes

    • Documentation builds are now validated for pull requests and main-branch updates.
    • Snapshot tests now fail clearly when reference images are missing or dimensions differ.
    • Test-generated snapshots no longer unintentionally modify documentation assets.
  • Documentation

    • Clarified screenshot management and release behavior.
    • Screenshot copying no longer removes unrelated image files automatically.
  • Tests

    • Snapshot validation now runs against a consistent simulator configuration and verifies documentation assets remain unchanged.

@bruschill bruschill added the skip-docs-check Use this label to skip the automatic docs audit label Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b14c04bb-f16f-424c-9d9c-0814dad2d081

📥 Commits

Reviewing files that changed from the base of the PR and between 637e3be and 4db7a34.

📒 Files selected for processing (1)
  • MeshtasticTests/SwiftUIViewSnapshotTests.swift
🚧 Files skipped from review as they are similar to previous changes (1)
  • MeshtasticTests/SwiftUIViewSnapshotTests.swift

📝 Walkthrough

Walkthrough

Snapshot tests now require explicit recording. CI discovers and validates 38 snapshot suites on pull requests and pushes to main. Screenshot copying no longer triggers cleanup.

Changes

Snapshot documentation validation

Layer / File(s) Summary
Explicit snapshot recording and fixtures
MeshtasticTests/SwiftUIViewSnapshotTests.swift
Snapshot references are created or replaced only when recording is enabled. Missing references fail otherwise. Node fixtures use the shared model context, and the formatting toolbar remains test-only.
CI snapshot discovery and tree validation
.github/workflows/docs-deploy.yml
Documentation validation targets pull requests and pushes to main, selects Xcode 26.3, discovers 38 suites on an iPhone 16 simulator running iOS 18.5, and fails when snapshot or screenshot files change.
Separate screenshot copying and cleanup
scripts/copy-snapshots.sh, specs/013-docs-release-versioning/contracts/script-contract.md, specs/013-docs-release-versioning/research.md
Screenshot copying no longer invokes cleanup. The specifications describe copying and destructive cleanup as separate operations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PullRequest
  participant DocsWorkflow
  participant SnapshotTests
  participant Repository
  PullRequest->>DocsWorkflow: trigger validation for main
  DocsWorkflow->>SnapshotTests: run 38 discovered selectors
  SnapshotTests->>Repository: compare or record references
  DocsWorkflow->>Repository: inspect modified snapshot and screenshot paths
  DocsWorkflow-->>PullRequest: report validation result
Loading

Poem

A rabbit records only by command,
While snapshots stay in the checked tree.
Thirty-eight suites run as planned,
CI checks each changed file.
Copying waits; cleanup stays apart.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: preventing snapshot tests from modifying source files.
Description check ✅ Passed The description covers the required sections and provides clear change, rationale, testing, screenshots, and checklist details.
Linked Issues check ✅ Passed The PR addresses the coding objectives in [#2213], including opt-in recording, stale references, cleanup separation, and CI change detection.
Out of Scope Changes check ✅ Passed The workflow, test, script, and specification changes are related to the snapshot file modification issue and its stated requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@MeshtasticTests/SwiftUIViewSnapshotTests.swift`:
- Around line 138-150: Update the shouldRecord branch in the snapshot
dimension-change flow to return immediately after pngData.write(to:
snapshotFile) succeeds. Preserve the existing error Issue.record and return for
failed writes, and keep the later Issue.record only for the non-recording path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 00ddc2a4-2c81-4cdb-8d42-7446858f5370

📥 Commits

Reviewing files that changed from the base of the PR and between de26cc4 and fb8427c.

⛔ Files ignored due to path filters (5)
  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/aboutMeshtastic.png is excluded by !**/*.png
  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/batteryPluggedIn.png is excluded by !**/*.png
  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/formattingToolbar.png is excluded by !**/*.png
  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/securityVersionNag.png is excluded by !**/*.png
  • MeshtasticTests/__Snapshots__/SwiftUIViewSnapshotTests/signalBLE_all.png is excluded by !**/*.png
📒 Files selected for processing (5)
  • .github/workflows/docs-deploy.yml
  • MeshtasticTests/SwiftUIViewSnapshotTests.swift
  • scripts/copy-snapshots.sh
  • specs/013-docs-release-versioning/contracts/script-contract.md
  • specs/013-docs-release-versioning/research.md
💤 Files with no reviewable changes (2)
  • specs/013-docs-release-versioning/contracts/script-contract.md
  • scripts/copy-snapshots.sh

Comment thread MeshtasticTests/SwiftUIViewSnapshotTests.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-docs-check Use this label to skip the automatic docs audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 [Bug]: Snapshot tests write untracked PNGs into the source tree on every run

1 participant