Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/RigEntryTests.swift
T
josh dc42db0c59 Add iCloud-synced rig library
Replace the single hand-saved rig file with a managed library of named
rigs persisted in app storage and synced across devices and both builder
apps via a shared iCloud container (iCloud.net.realizedsound.ShoeGazeData),
falling back to local storage when iCloud is unavailable.

Core (LyrebirdShoeGaze/Presets):
- RigEntry: named, timestamped ShoeGazeState (a whole multi-board rig).
- RigArchive: portable multi-rig JSON bundle for backup/transfer; legacy
  single-rig files import as a one-rig archive.
- RigLibraryStore (@MainActor @Observable): one JSON file per rig, with
  NSFileCoordinator writes and NSMetadataQuery live remote-change watching.
- RigLibraryLocation: iCloud-or-local directory resolver (skips the slow
  ubiquity lookup when no iCloud account is signed in).
- ShoeGaze.loadRig(from: ShoeGazeState) + captureEntry; shared filename
  sanitizer factored out of BoardVersionStore.

UI (LyrebirdShoeGazeUI):
- RigLibrarySidebarView: persistent left listing with new/save/save-as/
  duplicate/rename/delete/erase-all and archive import/export.
- RigNamePrompt; RigLibraryBootstrap one-call shell setup.
- ShoeGazeBuilderView: sidebar wired in; selecting a rig replaces the
  session; File menu / sidebar do whole-library archive import/export.

Shells/entitlements: both builder targets own+start the store and carry
the iCloud Documents entitlement; NSUbiquitousContainers exposes the rigs
in the Files app. (macOS pbxproj also carries a pre-existing 1.0->1.1.1
version bump.)

Tests: RigEntry/RigArchive round-trip + RigLibraryStore CRUD/import/export
(15 new; full suite 206 passing).

Provisioning (manual, not done here): enable the iCloud container on both
App IDs and select it in Signing & Capabilities for both targets.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 17:56:10 -07:00

56 lines
2.0 KiB
Swift

// RigEntryTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdShoeGaze
@Suite("RigEntry")
struct RigEntryTests {
/// A minimal two-board rig state for snapshotting without an engine.
private func makeState() -> ShoeGazeState {
let board: BoardState = BoardState(label: "Lead", segments: [])
let other: BoardState = BoardState(label: "Clean", segments: [])
return ShoeGazeState(boards: [board, other])
}
@Test func jsonRoundTripIsLossless() throws {
let entry: RigEntry = RigEntry(name: "Ambient Wash", state: makeState())
let encoder: JSONEncoder = JSONEncoder()
encoder.dateEncodingStrategy = .secondsSince1970
let decoder: JSONDecoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
let data: Data = try encoder.encode(entry)
let decoded: RigEntry = try decoder.decode(RigEntry.self, from: data)
#expect(decoded == entry)
}
@Test func savedAtIsRoundedToWholeSeconds() {
let fractional: Date = Date(timeIntervalSince1970: 1_700_000_000.789)
let entry: RigEntry = RigEntry(name: "x", savedAt: fractional, state: makeState())
#expect(entry.savedAt.timeIntervalSince1970 == 1_700_000_001)
}
@Test func duplicatedGetsNewIdSameState() {
let original: RigEntry = RigEntry(name: "A", state: makeState())
let copy: RigEntry = original.duplicated(name: "A copy")
#expect(copy.id != original.id)
#expect(copy.name == "A copy")
#expect(copy.state == original.state)
}
@Test func renamedKeepsIdSameState() {
let original: RigEntry = RigEntry(name: "A", state: makeState())
let renamed: RigEntry = original.renamed(to: "B")
#expect(renamed.id == original.id)
#expect(renamed.name == "B")
#expect(renamed.state == original.state)
}
}