// 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 = Set(rigs.map { $0.id }) #expect(ids.count == rigs.count, "rig ids must be unique") let names: Set = 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 = 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)'") } } } @Test func factoryDetectionRecognisesEveryRigAndRejectsOthers() { let rigs: [FactoryRig] = FactoryRigLibrary.all #expect(FactoryRigLibrary.factoryIDs.count == rigs.count) for rig: FactoryRig in rigs { #expect(FactoryRigLibrary.isFactory(rig.id), "\(rig.name) not recognised as factory") } // A freshly generated id is not a factory rig. #expect(!FactoryRigLibrary.isFactory(UUID())) } // 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") } } }