Files
honeyDueKMP/scripts/add_snapshot_testing.rb
Trey T 6f2fb629c9 P3: iOS parity gallery (swift-snapshot-testing, 1.17.0+)
Records 58 baseline PNGs across 29 primary SwiftUI screens × {light, dark}
for the honeyDue iOS app. Covers auth, password reset, onboarding,
residences, tasks, contractors, documents, profile, and subscription
surfaces — everything that's instantiable without complex runtime context.

State coverage is empty-only for this first pass: views currently spin up
their own ViewModels which read DataManagerObservable.shared directly, and
the test host has no login → all flows render their empty states. A
follow-up PR adds an optional `dataManager:` init param to each
*ViewModel.swift so populated-state snapshots (backed by P1's
FixtureDataManager) can land.

Tolerance knobs: pixelPrecision 0.97 / perceptualPrecision 0.95 — tuned to
absorb animation-frame drift (gradient blobs, focus rings) while catching
structural regressions.

Tooling: swift-snapshot-testing SPM dep added to the HoneyDueTests target
only (not the app target) via scripts/add_snapshot_testing.rb, which is an
idempotent xcodeproj-gem script so the edit is reproducible rather than a
hand-crafted pbxproj diff. Pins resolve to 1.19.2 (up-to-next-major from
the 1.17.0 plan floor).

Blocks regressions at PR time via `xcodebuild test
-only-testing:HoneyDueTests/SnapshotGalleryTests`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 19:37:09 -05:00

71 lines
2.5 KiB
Ruby

#!/usr/bin/env ruby
# Adds swift-snapshot-testing SPM dependency to the HoneyDueTests target.
# Idempotent — safe to run repeatedly.
#
# Usage:
# ruby scripts/add_snapshot_testing.rb
#
# Requires:
# gem install xcodeproj
#
# Repo-root-relative; must be run from repo root or via absolute path.
require 'xcodeproj'
PROJECT_PATH = File.expand_path('../iosApp/honeyDue.xcodeproj', __dir__)
PACKAGE_URL = 'https://github.com/pointfreeco/swift-snapshot-testing'
PACKAGE_VERSION = '1.17.0'
PRODUCT = 'SnapshotTesting'
TARGET_NAME = 'HoneyDueTests'
project = Xcodeproj::Project.open(PROJECT_PATH)
target = project.targets.find { |t| t.name == TARGET_NAME }
abort("Target #{TARGET_NAME} not found") unless target
# 1. XCRemoteSwiftPackageReference — create if missing
pkg_ref = project.root_object.package_references.find do |ref|
ref.respond_to?(:repositoryURL) && ref.repositoryURL == PACKAGE_URL
end
if pkg_ref.nil?
pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
pkg_ref.repositoryURL = PACKAGE_URL
pkg_ref.requirement = { 'kind' => 'upToNextMajorVersion', 'minimumVersion' => PACKAGE_VERSION }
project.root_object.package_references << pkg_ref
puts "Added XCRemoteSwiftPackageReference: #{PACKAGE_URL}"
else
pkg_ref.requirement = { 'kind' => 'upToNextMajorVersion', 'minimumVersion' => PACKAGE_VERSION }
puts "XCRemoteSwiftPackageReference already exists: #{PACKAGE_URL}"
end
# 2. XCSwiftPackageProductDependency — SnapshotTesting product tied to package ref
prod_dep = target.package_product_dependencies.find { |d| d.product_name == PRODUCT }
if prod_dep.nil?
prod_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
prod_dep.package = pkg_ref
prod_dep.product_name = PRODUCT
target.package_product_dependencies << prod_dep
puts "Added XCSwiftPackageProductDependency: #{PRODUCT} -> #{TARGET_NAME}"
else
puts "XCSwiftPackageProductDependency #{PRODUCT} already linked to #{TARGET_NAME}"
end
# 3. Frameworks build phase — add build file referencing the product dep
frameworks_phase = target.frameworks_build_phase
already_linked = frameworks_phase.files.any? do |bf|
bf.file_ref.nil? && bf.product_ref == prod_dep
end
unless already_linked
build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
build_file.product_ref = prod_dep
frameworks_phase.files << build_file
puts "Added #{PRODUCT} to Frameworks build phase of #{TARGET_NAME}"
else
puts "#{PRODUCT} already in Frameworks build phase"
end
project.save
puts "Saved project."