Skip to content

Cache SetupBuilder artifacts and split CI cache keys#89

Merged
obj-p merged 4 commits intomainfrom
worktree-setup-cache-spec
Apr 13, 2026
Merged

Cache SetupBuilder artifacts and split CI cache keys#89
obj-p merged 4 commits intomainfrom
worktree-setup-cache-spec

Conversation

@obj-p
Copy link
Copy Markdown
Owner

@obj-p obj-p commented Apr 12, 2026

Summary

  • Add SetupCache that skips redundant swift build when setup package sources haven't changed — warm preview_start drops from ~3-10s to <100ms for the setup step
  • Cache key: SHA256 of Package.swift + Package.resolved + Sources/**/*.swift + iOS SDK path + Swift toolchain version
  • Artifact validation on cache hit: verifies .swiftmodule, static libs, and frameworks still exist on disk
  • Split CI SPM cache key into per-job keys (spm-...-build- / spm-...-ios-) so build-and-test and ios-tests no longer clobber each other

Closes #81

Test plan

  • 16 new tests in SetupCacheTests — hashing stability/sensitivity, store/load round-trip, corrupt JSON handling, missing artifact detection, read-only filesystem, platform isolation, warm cache speedup, source change invalidation
  • All 192 PreviewsCoreTests pass (no regressions)
  • swift-format lint clean
  • CI runs green with split cache keys (verify distinct keys in Actions logs)

🤖 Generated with Claude Code

obj-p and others added 4 commits April 12, 2026 17:32
Skip redundant `swift build` invocations when the setup package sources
haven't changed. SetupCache hashes Package.swift, Package.resolved, and
Sources/**/*.swift (plus SDK path and Swift version) to produce a cache
key, stores the build result as JSON under .build/previewsmcp-setup-cache/,
and validates that all referenced artifacts still exist on load.

Also splits the shared CI SPM cache key into per-job keys so
build-and-test and ios-tests no longer race on save.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Convert the implementation spec into a technical reference doc under
docs/. Strips spec scaffolding (success criteria checklists, rollout
plan, open questions) and keeps the cache design, artifact validation,
error handling, and CI integration details.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Include Swift toolchain version in hashSources so each toolchain gets
  its own cache entry instead of thrashing on toolchain switches
- Add defense-in-depth guards: verify sourceHash and platform fields in
  Entry match the lookup parameters, not just the filename
- Validate .swiftmodule directory is non-empty (catches partial clean)
- Rename test to reflect actual behavior (only hashes Package + Sources)
- Use fixed 1s threshold for warm cache assertion instead of flaky ratio
- Strengthen invalidation test: assert new cache files are a superset
- Add swiftVersion sensitivity test for hashSources

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The 1s threshold was too tight for GitHub Actions shared runners where
subprocess overhead (resolveSwiftVersion, hashSources) is higher due to
contention. Bump to 3s — still meaningful vs the ~19s cold build on CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@obj-p obj-p merged commit c8c0fdc into main Apr 13, 2026
4 checks passed
@obj-p obj-p deleted the worktree-setup-cache-spec branch April 13, 2026 00:37
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.

Cache SetupBuilder build artifacts across preview sessions

1 participant