Skip to content

test: stop the artwork tests using the user's real cache directory (#364) - #368

Merged
isaaclins merged 1 commit into
mainfrom
fix/364-artwork-cache-state
Sep 3, 2026
Merged

test: stop the artwork tests using the user's real cache directory (#364)#368
isaaclins merged 1 commit into
mainfrom
fix/364-artwork-cache-state

Conversation

@isaaclins

Copy link
Copy Markdown
Owner

Part of #364, follows #366.

ArtworkImageStore.cachedImageIfAvailable(for:) recomputed the default cache path inline, duplicating the shared store's own initializer. Tests could therefore only exercise it by writing into ~/Library/Caches/Spotiglass/Artwork, the directory the app and the rest of the suite share: anything that trimmed or cleared it mid-run made testBlurredArtworkHostsAndLoadsFromDiskCache fail, which is the intermittent failure recorded in #364. It also meant running the suite edited the caches of whoever ran it.

  • The default location is now defined once, as ArtworkImageStore.defaultDiskDirectory, used by both the shared store and the synchronous read.
  • cachedImageIfAvailable(for:diskDirectory:) takes the directory, defaulting to that shared location, so production call sites are unchanged.
  • Both tests now use their own temporary directory, and the view test feeds the decoded image in through ImmersiveBlurredArtwork(url:initialImage:) instead of relying on cache timing.

Not run locally: only build-for-testing, which succeeded. CI is the verdict.

Remaining in #364: a per-test watchdog so a hang fails fast instead of stalling the job.

cachedImageIfAvailable recomputed the default cache path inline, so the only way to exercise it was to write into ~/Library/Caches/Spotiglass/Artwork, the same directory the app and the rest of the suite share. Anything that trimmed or cleared that cache mid-run made the test fail, and running the suite edited the caches of whoever ran it. The location is now defined once and the read takes the directory as a parameter.
Copilot AI lite review requested due to automatic review settings September 3, 2026 15:45

Copilot AI 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.

🟡 Changes recommended

There are small but concrete maintainability issues (duplicate cache-root resolution in ArtworkImageStore init and a brittle path-suffix assertion in tests) with straightforward fixes.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR hardens artwork-related tests by eliminating reliance on the user’s real cache directory and centralizing the production disk-cache location so both async and synchronous read paths agree.

Changes:

  • Centralizes the artwork disk-cache directory as ArtworkImageStore.defaultDiskDirectory and uses it as the default for cachedImageIfAvailable(for:diskDirectory:).
  • Updates artwork cache tests to use per-test temporary directories instead of ~/Library/Caches/....
  • Updates the immersive blurred artwork view test to inject a pre-decoded initialImage rather than depending on cache timing.
File summaries
File Description
SpotiglassTests/ImmersiveLyricsViewsTests.swift Moves the blurred-artwork test off the user cache and injects initialImage for deterministic hosting/inspection.
SpotiglassTests/ArtworkImageStoreTests.swift Verifies synchronous cache reads against an explicitly provided directory and asserts the default cache location expectation.
Spotiglass/Utilities/ArtworkImageStore.swift Introduces defaultDiskDirectory and adds a diskDirectory default parameter to the synchronous cache read API.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 24 to 30
private init() {
let base = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first
?? FileManager.default.temporaryDirectory
let disk = base
.appendingPathComponent(AppMetadata.displayName, isDirectory: true)
.appendingPathComponent("Artwork", isDirectory: true)
let disk = Self.defaultDiskDirectory
let urlCacheDir = base.appendingPathComponent(AppMetadata.displayName, isDirectory: true)
.appendingPathComponent("ArtworkURLCache", isDirectory: true)
try? FileManager.default.createDirectory(at: urlCacheDir, withIntermediateDirectories: true)
Comment on lines +178 to +181
XCTAssertTrue(
ArtworkImageStore.defaultDiskDirectory.path.hasSuffix("/\(AppMetadata.displayName)/Artwork"),
"The shared store and the synchronous read must resolve the same cache directory"
)
@isaaclins
isaaclins merged commit f614831 into main Sep 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants