feat(rigs): ship built-in factory starter rigs

Add a factory rig library: 8 curated starter pedalboard rigs seeded into
an empty rig library on first launch. Rigs are compile-checked builders
(construct concrete pedals, set typed @UIParam values, board.add) rather
than hand-written JSON, so a renamed pedal control is a build error, not a
silently corrupted preset.

Seeding builds each rig in a throwaway offline (never-started) engine,
captures a RigEntry with a stable per-rig UUID (idempotent re-seed), and
saves to the store. Bootstrap rolls back this run's saves if any store.save
fails, so a partial library can't freeze future seeding (gated on isEmpty).

Rigs are named/described by sound, not trademarked products or artists; a
test guards against brand names leaking into names/blurbs. Full ship-path
test loads and renders every rig to non-silent output.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 12:37:34 -07:00
parent 2fd7eaee57
commit 4eb1cbdd61
5 changed files with 700 additions and 4 deletions
@@ -0,0 +1,105 @@
// FactoryRigLibraryTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
import LyrebirdSynth
import LyrebirdUI
@testable import LyrebirdShoeGaze
@MainActor
@Suite("FactoryRigLibrary")
struct FactoryRigLibraryTests {
// MARK: - Catalog integrity
@Test func catalogIsWellFormed() {
let rigs: [FactoryRig] = FactoryRigLibrary.all
#expect(rigs.count >= 6, "expected a full starter slate")
let ids: Set<UUID> = Set(rigs.map { $0.id })
#expect(ids.count == rigs.count, "rig ids must be unique")
let names: Set<String> = Set(rigs.map { $0.name })
#expect(names.count == rigs.count, "rig names must be unique")
let minBlurbLength: Int = 20
for rig: FactoryRig in rigs {
#expect(!rig.name.isEmpty, "\(rig.name) has empty name")
#expect(rig.blurb.count >= minBlurbLength, "\(rig.name) blurb too short")
}
// The slate should span more than one sonic family.
let categories: Set<FactoryRigCategory> = Set(rigs.map { $0.category })
#expect(categories.count >= 3, "starter slate should cover several categories")
}
@Test func blurbsAvoidTrademarkedProductNames() {
// Guard against a blurb accidentally naming a real amp/pedal brand: factory rigs describe
// the sound, never a trademarked product.
let forbidden: [String] = [
"marshall", "fender", "vox", "mesa", "boss", "orange", "dumble", "roland", "ibanez",
]
for rig: FactoryRig in FactoryRigLibrary.all {
let haystack: String = (rig.name + " " + rig.blurb).lowercased()
for brand: String in forbidden {
#expect(!haystack.contains(brand), "\(rig.name) mentions '\(brand)'")
}
}
}
// MARK: - Seeding entries
@Test func makeEntriesMatchesCatalogAndIsStable() throws {
let entries: [RigEntry] = try FactoryRigLibrary.makeEntries()
let rigs: [FactoryRig] = FactoryRigLibrary.all
#expect(entries.count == rigs.count, "one entry per rig")
for (entry, rig): (RigEntry, FactoryRig) in zip(entries, rigs) {
#expect(entry.id == rig.id, "entry id must be the rig's stable id")
#expect(entry.name == rig.name)
#expect(entry.state.boards.count == 1, "\(rig.name) should build exactly one board")
let pedalCount: Int = entry.state.boards.first?.pedals.count ?? 0
#expect(pedalCount >= 3, "\(rig.name) should build a non-trivial chain")
}
// Stable ids: re-seeding yields identical ids (so a re-seed overwrites in place).
let again: [RigEntry] = try FactoryRigLibrary.makeEntries()
#expect(entries.map { $0.id } == again.map { $0.id })
}
@Test func entriesRoundTripThroughJSON() throws {
let encoder: JSONEncoder = JSONEncoder()
let decoder: JSONDecoder = JSONDecoder()
for entry: RigEntry in try FactoryRigLibrary.makeEntries() {
let data: Data = try encoder.encode(entry)
let decoded: RigEntry = try decoder.decode(RigEntry.self, from: data)
#expect(decoded == entry, "\(entry.name) did not survive a JSON round-trip")
}
}
// MARK: - Load + render (full ship path)
@Test func everyFactoryEntryLoadsAndRenders() throws {
let renderDuration: Double = 0.2
let numAudioBuses: Int = 128
for entry: RigEntry in try FactoryRigLibrary.makeEntries() {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numAudioBuses: numAudioBuses
)
defer { try? FileManager.default.removeItem(at: url) }
let session: ShoeGaze = ShoeGaze(engine: engine)
try session.loadRig(from: entry.state)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(hasNonSilentOutput(samples), "\(entry.name) rendered silence")
}
}
}