Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/RigArchiveTests.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

44 lines
1.5 KiB
Swift

// RigArchiveTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdShoeGaze
@Suite("RigArchive")
struct RigArchiveTests {
private func makeEntry(_ name: String) -> RigEntry {
RigEntry(name: name, state: ShoeGazeState(boards: [BoardState(label: name, segments: [])]))
}
@Test func jsonRoundTripIsLossless() throws {
let archive: RigArchive = RigArchive(rigs: [makeEntry("A"), makeEntry("B")])
let encoder: JSONEncoder = JSONEncoder()
encoder.dateEncodingStrategy = .secondsSince1970
let decoder: JSONDecoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
let data: Data = try encoder.encode(archive)
let decoded: RigArchive = try decoder.decode(RigArchive.self, from: data)
#expect(decoded == archive)
#expect(decoded.version == rigArchiveFormatVersion)
#expect(decoded.rigs.count == 2)
}
@Test func emptyArchiveRoundTrips() throws {
let archive: RigArchive = RigArchive(rigs: [])
let encoder: JSONEncoder = JSONEncoder()
encoder.dateEncodingStrategy = .secondsSince1970
let decoder: JSONDecoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
let data: Data = try encoder.encode(archive)
let decoded: RigArchive = try decoder.decode(RigArchive.self, from: data)
#expect(decoded.rigs.isEmpty)
}
}