スプライトのゴールデン画像がマシン依存で CI に落ちる問題を修正 - #43
Merged
Merged
Conversation
The two canvas goldens added with `TortoiseSprite` passed locally but failed on CI with a pure color shift (perceptual precision 0.956, geometry intact); the 16 pre-existing scenario goldens were unaffected. The sprite image was rendered from a SwiftUI view via `ImageRenderer`, which made it depend on the host machine twice over: `Color.red` / `Color.blue` are semantic colors whose components vary with display gamut and appearance, and `ImageRenderer.nsImage` returns a bitmap tagged with the host's display profile. The scenario goldens escaped this because they only draw vector paths in explicitly-constructed sRGB colors. Build the sprite from raw sRGB bytes through `CGImage` + `Image(decorative:scale:)` instead, so no color resolution happens. The recorded pixels now come out byte-identical to the values written in. Also pin the tests to `.tortoiseViewport(.original)` and size the source bitmaps so they map 1:1 onto device pixels (80x80 px at scale 2 into a 40x40 box; 160x80 into 80x80), removing image resampling as a second source of cross-machine drift. Both goldens were re-recorded and visually inspected.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
==========================================
+ Coverage 91.89% 92.57% +0.68%
==========================================
Files 15 16 +1
Lines 913 943 +30
==========================================
+ Hits 839 873 +34
+ Misses 74 70 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
#42 で追加した canvas ゴールデン2件が CI(
Build & Test)で失敗していました。マージ後に main でも赤のままなので、その修正です。失敗は色ズレのみで、幾何は一致していました:
既存の16件のシナリオゴールデンは影響を受けていません。
原因
テスト用のスプライト画像を SwiftUI ビューから
ImageRendererで生成していたため、ホストマシンに二重に依存していました。Color.red/Color.blueはセマンティックカラーで、実際の成分値がディスプレイの色域(P3 / sRGB)や外観設定で変わるImageRenderer.nsImageが返すビットマップはホストのディスプレイプロファイルでタグ付けされる既存のシナリオゴールデンがこれを免れていたのは、
Color(red:green:blue:)で明示的に構築した sRGB 色のベクター描画しかしていないためです。対応
CGImage+Image(decorative:scale:)で sRGB の生ピクセルから直接構築し、色解決を経由しないようにしました。記録されたゴールデンのピクセル値が、書き込んだバイト値と完全一致することを確認済みです(赤220,30,30/ 青30,30,220)。.tortoiseViewport(.original)に固定し、元ビットマップのサイズをデバイスピクセルに 1:1 で対応させました(scale 2 で 80×80 px を 40×40 のボックスへ、160×80 px を 80×80 のボックスへ)。これで画像のリサンプリングという2つ目のブレ要因も排除しています。プロダクションコードの変更はありません。
TortoiseSpriteの仕様・描画結果は #42 のままです。関連
#42 のフォローアップ
チェックリスト
swift testがローカルで通る(120件)xcrun swift-format lint --recursive --strict Sources Testsが通るCHANGELOG.mdを更新(該当なし。ユーザーから見える変更なし).original化で構図が変わっています)