1.0.0 release

This commit is contained in:
2026-06-01 18:27:40 -07:00
parent b1ab0f102c
commit 1f20fcab20
1151 changed files with 230703 additions and 14 deletions
@@ -0,0 +1,171 @@
// CLICommandTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
@testable import LyrebirdCLI
@Suite("CLICommand parsing")
struct CLICommandTests {
@Test func replSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "repl"]) == .repl)
}
@Test func noArgsParsesToInteractive() {
// `lyrebird` with no subcommand enters the LineNoise interactive shell.
#expect(CLICommand.parse(["lyrebird"]) == .interactive)
}
@Test func helpFlagParsed() {
#expect(CLICommand.parse(["lyrebird", "--help"]) == .help)
}
@Test func helpSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "help"]) == .help)
}
@Test func versionFlagParsed() {
#expect(CLICommand.parse(["lyrebird", "--version"]) == .version)
}
@Test func versionSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "version"]) == .version)
}
@Test func unknownSubcommandParsesToHelp() {
#expect(CLICommand.parse(["lyrebird", "unknowncommand"]) == .help)
}
@Test func emptyArgsParsesToInteractive() {
// Edge case: called with empty args array (should not crash).
#expect(CLICommand.parse([]) == .interactive)
}
// MARK: - new
@Test func newSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "new", "MySynth"]) == .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
}
@Test func newWithTemplateDemoParsed() {
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "demo"])
== .new(name: "MySynth", template: .demo, lyrebirdPath: nil))
}
@Test func newWithTemplateUIDemoParsed() {
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "ui-demo"])
== .new(name: "MySynth", template: .uiDemo, lyrebirdPath: nil))
}
@Test func newWithTemplateNRTParsed() {
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "nrt"])
== .new(name: "MySynth", template: .nrt, lyrebirdPath: nil))
}
@Test func newWithUnknownTemplateFallsBackToBasic() {
#expect(CLICommand.parse(["lyrebird", "new", "MySynth", "--template", "bogus"])
== .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
}
@Test func newWithoutNameParsesToHelp() {
#expect(CLICommand.parse(["lyrebird", "new"]) == .help)
}
@Test func newWithEmptyNameParsesToHelp() {
#expect(CLICommand.parse(["lyrebird", "new", ""]) == .help)
}
@Test func newWithFlagInsteadOfNameParsesToHelp() {
// Flag token in name position — user omitted the project name.
#expect(CLICommand.parse(["lyrebird", "new", "--flag"]) == .help)
}
@Test func newWithLyrebirdPathParsed() {
#expect(CLICommand.parse([
"lyrebird", "new", "MyPiece",
"--lyrebird-path", "/Users/josh/Documents/LyrebirdII"
]) == .new(name: "MyPiece",
template: .basic,
lyrebirdPath: "/Users/josh/Documents/LyrebirdII"))
}
@Test func newWithTemplateAndLyrebirdPathParsed() {
#expect(CLICommand.parse([
"lyrebird", "new", "MyApp",
"--template", "macos-ui-xcode",
"--lyrebird-path", "/abs/path"
]) == .new(name: "MyApp",
template: .macosUIXcode,
lyrebirdPath: "/abs/path"))
}
@Test func newWithoutLyrebirdPathReportsNil() {
#expect(CLICommand.parse([
"lyrebird", "new", "MyPiece"
]) == .new(name: "MyPiece", template: .basic, lyrebirdPath: nil))
}
// MARK: - run
@Test func runSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "run"]) == .run(release: false))
}
@Test func runWithReleaseFlagParsed() {
#expect(CLICommand.parse(["lyrebird", "run", "--release"]) == .run(release: true))
}
// MARK: - export
@Test func exportSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "export", "MySynth"]) == .export(name: "MySynth", to: nil, overwrite: false))
}
@Test func exportWithToPathParsed() {
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--to", "/tmp/MySynth.swift"])
#expect(cmd == .export(name: "MySynth", to: "/tmp/MySynth.swift", overwrite: false))
}
@Test func exportWithOverwriteFlagParsed() {
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--overwrite"])
#expect(cmd == .export(name: "MySynth", to: nil, overwrite: true))
}
@Test func exportWithToAndOverwriteParsed() {
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--to", "/tmp/x.swift", "--overwrite"])
#expect(cmd == .export(name: "MySynth", to: "/tmp/x.swift", overwrite: true))
}
@Test func exportWithoutNameParsesToHelp() {
#expect(CLICommand.parse(["lyrebird", "export"]) == .help)
}
@Test func exportWithFlagInsteadOfNameParsesToHelp() {
// `lyrebird export --to foo.swift` — name slot is a flag, should fall back to help.
#expect(CLICommand.parse(["lyrebird", "export", "--to", "foo.swift"]) == .help)
}
@Test func exportToValueIsNotConsumedAsFlagWhenFlagToken() {
// `lyrebird export MySynth --to --overwrite` — "--overwrite" starts with "-",
// so --to has no valid path value and toPath must be nil (not "--overwrite").
let cmd: CLICommand = CLICommand.parse(["lyrebird", "export", "MySynth", "--to", "--overwrite"])
#expect(cmd == .export(name: "MySynth", to: nil, overwrite: true))
}
// MARK: - install-templates / uninstall-templates
@Test func installTemplatesSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "install-templates"]) == .installTemplates(force: false))
}
@Test func installTemplatesWithForceFlag() {
#expect(CLICommand.parse(["lyrebird", "install-templates", "--force"]) == .installTemplates(force: true))
}
@Test func uninstallTemplatesSubcommandParsed() {
#expect(CLICommand.parse(["lyrebird", "uninstall-templates"]) == .uninstallTemplates)
}
}
@@ -0,0 +1,192 @@
// InteractiveShellTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
@Suite("InteractiveShell")
struct InteractiveShellTests {
@Test func historyFilePathMatchesREPLLauncher() {
// The shell and the REPL launcher share the same history file.
#expect(InteractiveShell.historyFilePath == REPLLauncher.historyFilePath)
}
@Test func completionsIncludeAllSubcommands() {
let completions: [String] = InteractiveShell.completions(for: "")
#expect(completions.contains("new"))
#expect(completions.contains("run"))
#expect(completions.contains("export"))
#expect(completions.contains("repl"))
#expect(completions.contains("help"))
#expect(completions.contains("version"))
#expect(completions.contains("quit"))
}
@Test func completionsFilterByPrefix() {
// `r` prefix → both `repl` and `run`
let completions: [String] = InteractiveShell.completions(for: "r")
#expect(completions.contains("repl"))
#expect(completions.contains("run"))
#expect(!completions.contains("help"))
#expect(!completions.contains("version"))
}
@Test func completionsForUnknownPrefixAreEmpty() {
let completions: [String] = InteractiveShell.completions(for: "xyz")
#expect(completions.isEmpty)
}
@Test func shellCommandParsedFromInput() {
#expect(InteractiveShell.command(from: "repl") == .repl)
#expect(InteractiveShell.command(from: "help") == .help)
#expect(InteractiveShell.command(from: "version") == .version)
#expect(InteractiveShell.command(from: "quit") == .quit)
#expect(InteractiveShell.command(from: "") == .none)
#expect(InteractiveShell.command(from: " ") == .none)
#expect(InteractiveShell.command(from: "unknown") == .unknown("unknown"))
}
@Test func shellCommandFromInputIsTrimmed() {
// Leading/trailing whitespace must not affect parsing.
#expect(InteractiveShell.command(from: " repl ") == .repl)
}
// MARK: - new
@Test func shellNewCommandParsed() {
#expect(InteractiveShell.command(from: "new MySynth") == .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
}
@Test func shellNewCommandCaseInsensitiveVerb() {
// Verb is case-insensitive; name preserves original casing.
#expect(InteractiveShell.command(from: "NEW MySynth") == .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
}
@Test func shellNewCommandWithTemplateDemo() {
#expect(InteractiveShell.command(from: "new MySynth --template demo")
== .new(name: "MySynth", template: .demo, lyrebirdPath: nil))
}
@Test func shellNewCommandWithTemplateUIDemo() {
#expect(InteractiveShell.command(from: "new MySynth --template ui-demo")
== .new(name: "MySynth", template: .uiDemo, lyrebirdPath: nil))
}
@Test func shellNewCommandWithTemplateNRT() {
#expect(InteractiveShell.command(from: "new MySynth --template nrt")
== .new(name: "MySynth", template: .nrt, lyrebirdPath: nil))
}
@Test func shellNewCommandUnknownTemplateFallsBackToBasic() {
#expect(InteractiveShell.command(from: "new MySynth --template bogus")
== .new(name: "MySynth", template: .basic, lyrebirdPath: nil))
}
@Test func shellNewCommandWithLyrebirdPathParsed() {
#expect(InteractiveShell.command(from: "new MyPiece --lyrebird-path /Users/josh/Documents/LyrebirdII")
== .new(name: "MyPiece",
template: .basic,
lyrebirdPath: "/Users/josh/Documents/LyrebirdII"))
}
@Test func shellNewCommandWithTemplateAndLyrebirdPathParsed() {
#expect(InteractiveShell.command(from: "new MyApp --template macos-ui-xcode --lyrebird-path /abs/path")
== .new(name: "MyApp",
template: .macosUIXcode,
lyrebirdPath: "/abs/path"))
}
@Test func shellNewCommandMissingNameReturnsUnknown() {
// No argument → unknown rather than a crash or silent failure.
if case .unknown(_) = InteractiveShell.command(from: "new") {
// pass
} else {
Issue.record("Expected .unknown for 'new' without a name")
}
}
@Test func shellNewCommandFlagInsteadOfNameReturnsUnknown() {
// Flag token in name position — user omitted the project name.
if case .unknown(_) = InteractiveShell.command(from: "new --flag") {
// pass
} else {
Issue.record("Expected .unknown when new name slot is a flag")
}
}
// MARK: - run
@Test func shellRunCommandParsed() {
#expect(InteractiveShell.command(from: "run") == .run(release: false))
}
@Test func shellRunCommandWithReleaseFlag() {
#expect(InteractiveShell.command(from: "run --release") == .run(release: true))
}
@Test func shellRunCommandCaseInsensitiveVerb() {
#expect(InteractiveShell.command(from: "RUN") == .run(release: false))
}
// MARK: - export
@Test func shellExportCommandParsed() {
#expect(InteractiveShell.command(from: "export MySynth") == .export(name: "MySynth", to: nil, overwrite: false))
}
@Test func shellExportCommandWithToPath() {
#expect(
InteractiveShell.command(from: "export MySynth --to /tmp/MySynth.swift")
== .export(name: "MySynth", to: "/tmp/MySynth.swift", overwrite: false)
)
}
@Test func shellExportCommandWithOverwriteFlag() {
#expect(
InteractiveShell.command(from: "export MySynth --overwrite")
== .export(name: "MySynth", to: nil, overwrite: true)
)
}
@Test func shellExportCommandWithToAndOverwrite() {
#expect(
InteractiveShell.command(from: "export MySynth --to /tmp/MySynth.swift --overwrite")
== .export(name: "MySynth", to: "/tmp/MySynth.swift", overwrite: true)
)
}
@Test func shellExportCommandMissingNameReturnsUnknown() {
if case .unknown(_) = InteractiveShell.command(from: "export") {
// pass
} else {
Issue.record("Expected .unknown for 'export' without a name")
}
}
@Test func shellExportCommandCaseInsensitiveVerb() {
// Verb is case-insensitive; name preserves original casing.
#expect(InteractiveShell.command(from: "EXPORT BassLine") == .export(name: "BassLine", to: nil, overwrite: false))
}
@Test func shellExportFlagInsteadOfNameReturnsUnknown() {
// `export --to foo.swift` — name slot is a flag token, not a valid identifier.
if case .unknown(_) = InteractiveShell.command(from: "export --to foo.swift") {
// pass
} else {
Issue.record("Expected .unknown when export name slot is a flag")
}
}
@Test func shellExportToValueNotConsumedAsFlagToken() {
// `export MySynth --to --overwrite` — "--overwrite" starts with "-", so toPath is nil.
#expect(
InteractiveShell.command(from: "export MySynth --to --overwrite")
== .export(name: "MySynth", to: nil, overwrite: true)
)
}
}
@@ -0,0 +1,56 @@
// ProjectRunnerTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
@Suite("ProjectRunner")
struct ProjectRunnerTests {
// MARK: - findSwift
@Test func findSwiftReturnsPath() throws {
// On macOS with Xcode installed, /usr/bin/swift should always exist.
// If this test is running, swift is present (we're running in a Swift test binary).
let swiftPath: String = try ProjectRunner.findSwift()
#expect(swiftPath.contains("swift"))
#expect(FileManager.default.isExecutableFile(atPath: swiftPath))
}
// MARK: - makeProcess configuration
@Test func makeProcessDebugUsesRunArgument() throws {
let process: Process = try ProjectRunner.makeProcess(release: false)
#expect(process.arguments == ["run"])
}
@Test func makeProcessReleaseAddsFlag() throws {
let process: Process = try ProjectRunner.makeProcess(release: true)
#expect(process.arguments == ["run", "-c", "release"])
}
@Test func makeProcessUsesCurrentDirectory() throws {
let cwd: String = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
.resolvingSymlinksInPath().path
let process: Process = try ProjectRunner.makeProcess(release: false)
let processDir: String? = process.currentDirectoryURL?.resolvingSymlinksInPath().path
#expect(processDir == cwd)
}
@Test func makeProcessUsesSuppliedDirectory() throws {
let tmp: String = FileManager.default.temporaryDirectory.path
let process: Process = try ProjectRunner.makeProcess(release: false, in: tmp)
// currentDirectoryURL may resolve symlinks; just check the tail
#expect(process.currentDirectoryURL != nil)
}
@Test func makeProcessExecutableIsSwift() throws {
let process: Process = try ProjectRunner.makeProcess(release: false)
let exePath: String = process.executableURL?.path ?? ""
#expect(exePath.contains("swift"))
}
}
@@ -0,0 +1,616 @@
// ProjectScaffolderTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
@Suite("ProjectScaffolder")
struct ProjectScaffolderTests {
// MARK: - Name validation
@Test func validNamePasses() throws {
// Should not throw
#expect(throws: Never.self) {
try ProjectScaffolder.validateName("MySynth")
}
}
@Test func validNameWithUnderscorePasses() throws {
#expect(throws: Never.self) {
try ProjectScaffolder.validateName("My_Synth_01")
}
}
@Test func emptyNameThrows() {
#expect(throws: ProjectScaffolder.Error.invalidName(name: "")) {
try ProjectScaffolder.validateName("")
}
}
@Test func nameStartingWithDigitThrows() {
#expect(throws: ProjectScaffolder.Error.invalidName(name: "1Bad")) {
try ProjectScaffolder.validateName("1Bad")
}
}
@Test func nameWithSpaceThrows() {
#expect(throws: ProjectScaffolder.Error.invalidName(name: "My Synth")) {
try ProjectScaffolder.validateName("My Synth")
}
}
@Test func nameWithHyphenThrows() {
#expect(throws: ProjectScaffolder.Error.invalidName(name: "my-synth")) {
try ProjectScaffolder.validateName("my-synth")
}
}
@Test func nonASCIINameThrows() {
// Unicode letters are not valid SPM module names.
#expect(throws: ProjectScaffolder.Error.invalidName(name: "Синт")) {
try ProjectScaffolder.validateName("Синт")
}
}
// MARK: - packageManifest template
@Test func packageManifestContainsName() {
let manifest: String = ProjectScaffolder.packageManifest(name: "MyProject")
#expect(manifest.contains("MyProject"))
}
@Test func packageManifestHasSwiftToolsVersion() {
let manifest: String = ProjectScaffolder.packageManifest(name: "Foo")
#expect(manifest.contains("swift-tools-version: 6.0"))
}
@Test func packageManifestTargetsMacOS15() {
let manifest: String = ProjectScaffolder.packageManifest(name: "Foo")
#expect(manifest.contains(".macOS(.v15)"))
}
@Test func packageManifestHasLyrebirdDependency() {
let manifest: String = ProjectScaffolder.packageManifest(name: "Foo")
#expect(manifest.contains("Lyrebird"))
}
// MARK: - mainSwift template
@Test func mainSwiftContainsName() {
let source: String = ProjectScaffolder.mainSwift(name: "Demo")
#expect(source.contains("Demo"))
}
@Test func mainSwiftImportsLyrebird() {
let source: String = ProjectScaffolder.mainSwift(name: "Demo")
#expect(source.contains("import LyrebirdSynth"))
}
@Test func mainSwiftReferencesCoreAudioDriver() {
let source: String = ProjectScaffolder.mainSwift(name: "Demo")
#expect(source.contains("CoreAudioDriver"))
}
// MARK: - testsSwift template
@Test func testsSwiftContainsName() {
let source: String = ProjectScaffolder.testsSwift(name: "Demo")
#expect(source.contains("Demo"))
}
@Test func testsSwiftImportsTestingAndLyrebird() {
let source: String = ProjectScaffolder.testsSwift(name: "Demo")
#expect(source.contains("import Testing"))
#expect(source.contains("import LyrebirdSynth"))
}
@Test func testsSwiftReferencesOfflineDriver() {
let source: String = ProjectScaffolder.testsSwift(name: "Demo")
#expect(source.contains("OfflineDriver"))
}
// MARK: - scaffold creates files
@Test func scaffoldCreatesDirectoryTree() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)")
.path
try FileManager.default.createDirectory(atPath: tmp,
withIntermediateDirectories: true,
attributes: nil)
defer { try? FileManager.default.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "TestProject", in: tmp)
let fm: FileManager = FileManager.default
let root: String = (tmp as NSString).appendingPathComponent("TestProject")
#expect(fm.fileExists(atPath: root))
#expect(fm.fileExists(atPath: (root as NSString).appendingPathComponent("Package.swift")))
#expect(fm.fileExists(atPath: (root as NSString).appendingPathComponent("Sources/TestProject/main.swift")))
#expect(fm.fileExists(atPath: (root as NSString).appendingPathComponent("Tests/TestProjectTests/TestProjectTests.swift")))
#expect(fm.fileExists(atPath: (root as NSString).appendingPathComponent("TestProject.xcworkspace/contents.xcworkspacedata")))
}
// MARK: - workspace template
@Test func workspaceContentsReferencesPackage() {
let contents: String = ProjectScaffolder.workspaceContents()
#expect(contents.contains("group:Package.swift"))
#expect(contents.contains("<Workspace"))
#expect(contents.hasPrefix("<?xml"))
}
@Test func scaffoldEmitsWorkspaceForEveryTemplate() throws {
let fm: FileManager = FileManager.default
for template: ProjectTemplate in ProjectTemplate.allCases {
let tmp: String = fm.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)")
.path
try fm.createDirectory(atPath: tmp,
withIntermediateDirectories: true,
attributes: nil)
defer { try? fm.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "WS", template: template, in: tmp)
let workspacePath: String = (tmp as NSString)
.appendingPathComponent("WS/WS.xcworkspace/contents.xcworkspacedata")
#expect(fm.fileExists(atPath: workspacePath),
"workspace missing for template \(template.rawValue)")
let contents: String = try String(contentsOfFile: workspacePath, encoding: .utf8)
// SPM-only templates ref Package.swift; xcode-bearing templates
// ref the generated .xcodeproj.
if template.shipsXcodeProject {
#expect(contents.contains("group:WS.xcodeproj"),
"xcode workspace must ref .xcodeproj for \(template.rawValue)")
} else {
#expect(contents.contains("group:Package.swift"),
"spm workspace must ref Package.swift for \(template.rawValue)")
}
}
}
@Test func scaffoldPackageManifestContainsProjectName() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)")
.path
try FileManager.default.createDirectory(atPath: tmp,
withIntermediateDirectories: true,
attributes: nil)
defer { try? FileManager.default.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "SoundEngine", in: tmp)
let packagePath: String = (tmp as NSString)
.appendingPathComponent("SoundEngine/Package.swift")
let content: String = try String(contentsOfFile: packagePath, encoding: .utf8)
#expect(content.contains("SoundEngine"))
}
@Test func scaffoldThrowsWhenProjectExists() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)")
.path
try FileManager.default.createDirectory(atPath: tmp,
withIntermediateDirectories: true,
attributes: nil)
defer { try? FileManager.default.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "Duplicate", in: tmp)
#expect(throws: ProjectScaffolder.Error.projectExists(name: "Duplicate")) {
try ProjectScaffolder.scaffold(name: "Duplicate", in: tmp)
}
}
@Test func scaffoldThrowsOnInvalidName() {
#expect(throws: ProjectScaffolder.Error.invalidName(name: "123bad")) {
try ProjectScaffolder.scaffold(name: "123bad")
}
}
// MARK: - ProjectTemplate
@Test func templateInitFromString() {
#expect(ProjectTemplate(string: "basic") == .basic)
#expect(ProjectTemplate(string: "demo") == .demo)
#expect(ProjectTemplate(string: "ui-demo") == .uiDemo)
#expect(ProjectTemplate(string: "uidemo") == .uiDemo)
#expect(ProjectTemplate(string: "nrt") == .nrt)
#expect(ProjectTemplate(string: "DEMO") == .demo)
#expect(ProjectTemplate(string: "bogus") == nil)
#expect(ProjectTemplate(string: "macos-ui-xcode") == .macosUIXcode)
#expect(ProjectTemplate(string: "macosuixcode") == .macosUIXcode)
#expect(ProjectTemplate(string: "ios-ui") == .iosUI)
#expect(ProjectTemplate(string: "iosui") == .iosUI)
#expect(ProjectTemplate(string: "auv3") == .auv3)
#expect(ProjectTemplate(string: "AUV3") == .auv3)
}
@Test func shipsXcodeProjectClassification() {
#expect(ProjectTemplate.basic.shipsXcodeProject == false)
#expect(ProjectTemplate.demo.shipsXcodeProject == false)
#expect(ProjectTemplate.uiDemo.shipsXcodeProject == false)
#expect(ProjectTemplate.nrt.shipsXcodeProject == false)
#expect(ProjectTemplate.macosUIXcode.shipsXcodeProject == true)
#expect(ProjectTemplate.iosUI.shipsXcodeProject == true)
#expect(ProjectTemplate.auv3.shipsXcodeProject == true)
}
// MARK: - Xcode-bearing templates: structure
@Test func scaffoldMacOSUIXcodeCreatesAllFiles() throws {
let fm: FileManager = FileManager.default
let tmp: String = fm.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)").path
try fm.createDirectory(atPath: tmp,
withIntermediateDirectories: true, attributes: nil)
defer { try? fm.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "MyMac",
template: .macosUIXcode,
in: tmp)
let root: String = (tmp as NSString).appendingPathComponent("MyMac")
let expected: [String] = [
"MyMac.xcodeproj/project.pbxproj",
"MyMac.xcodeproj/xcshareddata/xcschemes/MyMac.xcscheme",
"MyMac.xcworkspace/contents.xcworkspacedata",
"MyMac/main.swift",
"MyMac/AppDelegate.swift",
"MyMac/MyMacSynth.swift",
"MyMac/NoteController.swift",
"MyMac/MyMacView.swift",
"MyMac/Info.plist",
]
for rel: String in expected {
let path: String = (root as NSString).appendingPathComponent(rel)
#expect(fm.fileExists(atPath: path),
"missing macos-ui-xcode file: \(rel)")
}
}
@Test func macOSAppNoteControllerHasToggleEngineAndToggleNote() {
let src: String = ProjectScaffolder.macOSAppNoteControllerSwift(name: "Foo")
#expect(src.contains("@Observable"))
#expect(src.contains("func toggleEngine()"))
#expect(src.contains("func toggleNote()"))
#expect(src.contains("engine.start()"))
#expect(src.contains("engine.stop()"))
#expect(src.contains("try engine.add(synth)"))
#expect(src.contains("engine.remove(synth)"))
}
@Test func macOSAppViewHasStartStopButtons() {
let src: String = ProjectScaffolder.macOSAppViewSwift(name: "Foo")
#expect(src.contains("Start Engine"))
#expect(src.contains("Stop Engine"))
#expect(src.contains("Start Note"))
#expect(src.contains("Stop Note"))
#expect(src.contains("LyrebirdScopeView"))
#expect(src.contains("LyrebirdStatusView"))
#expect(src.contains("FooView"))
}
@Test func macOSAppMainSwiftDoesNotStartEngine() {
let src: String = ProjectScaffolder.macOSAppMainSwift(name: "Foo")
#expect(!src.contains("engine.start()"))
#expect(!src.contains("try engine.start()"))
}
@Test func scaffoldIOSUICreatesAllFiles() throws {
let fm: FileManager = FileManager.default
let tmp: String = fm.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)").path
try fm.createDirectory(atPath: tmp,
withIntermediateDirectories: true, attributes: nil)
defer { try? fm.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "MyiOS",
template: .iosUI,
in: tmp)
let root: String = (tmp as NSString).appendingPathComponent("MyiOS")
let expected: [String] = [
"MyiOS.xcodeproj/project.pbxproj",
"MyiOS.xcodeproj/xcshareddata/xcschemes/MyiOS.xcscheme",
"MyiOS.xcworkspace/contents.xcworkspacedata",
"MyiOS/MyiOSApp.swift",
"MyiOS/MyiOSSynth.swift",
"MyiOS/Info.plist",
]
for rel: String in expected {
let path: String = (root as NSString).appendingPathComponent(rel)
#expect(fm.fileExists(atPath: path),
"missing ios-ui file: \(rel)")
}
}
@Test func scaffoldAUv3CreatesAllFiles() throws {
let fm: FileManager = FileManager.default
let tmp: String = fm.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)").path
try fm.createDirectory(atPath: tmp,
withIntermediateDirectories: true, attributes: nil)
defer { try? fm.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "MyAU",
template: .auv3,
in: tmp)
let root: String = (tmp as NSString).appendingPathComponent("MyAU")
let expected: [String] = [
"MyAU.xcodeproj/project.pbxproj",
"MyAU.xcodeproj/xcshareddata/xcschemes/MyAU.xcscheme",
"MyAU.xcworkspace/contents.xcworkspacedata",
"MyAU/MyAUApp.swift",
"MyAU/ContentView.swift",
"MyAU/Info.plist",
"MyAU/MyAU.entitlements",
"MyAUExtension/MyAUSynth.swift",
"MyAUExtension/MyAUAudioUnit.swift",
"MyAUExtension/MyAUAudioUnitViewController.swift",
"MyAUExtension/Info.plist",
"MyAUExtension/MyAUExtension.entitlements",
]
for rel: String in expected {
let path: String = (root as NSString).appendingPathComponent(rel)
#expect(fm.fileExists(atPath: path),
"missing auv3 file: \(rel)")
}
}
@Test func xcodeWorkspaceContentsReferencesXcodeproj() {
let contents: String = ProjectScaffolder.xcodeWorkspaceContents(name: "Demo")
#expect(contents.contains("group:Demo.xcodeproj"))
#expect(contents.hasPrefix("<?xml"))
// Without lyrebirdPath the workspace lists only the .xcodeproj.
#expect(!contents.contains("absolute:"))
}
@Test func xcodeWorkspaceContentsIncludesLyrebirdPathWhenSet() {
let contents: String = ProjectScaffolder.xcodeWorkspaceContents(
name: "Demo",
lyrebirdPath: "/abs/path/Lyrebird"
)
#expect(contents.contains("group:Demo.xcodeproj"))
#expect(contents.contains("absolute:/abs/path/Lyrebird"))
}
@Test func xcodeWorkspaceContentsEscapesLyrebirdPath() {
let contents: String = ProjectScaffolder.xcodeWorkspaceContents(
name: "Demo",
lyrebirdPath: #"/has"quote"#
)
#expect(contents.contains(#"absolute:/has\"quote"#))
}
@Test func auv3SubtypeDerivedFromName() {
#expect(ProjectScaffolder.auv3Subtype(for: "MyAU") == "MYAU")
#expect(ProjectScaffolder.auv3Subtype(for: "AB") == "ABXX")
#expect(ProjectScaffolder.auv3Subtype(for: "longerName") == "LONG")
#expect(ProjectScaffolder.auv3Subtype(for: "FM") == "FMXX")
}
@Test func auv3InfoPlistContainsAudioComponents() {
let plist: String = ProjectScaffolder.auv3ExtensionInfoPlist(name: "Foo")
#expect(plist.contains("AudioComponents"))
#expect(plist.contains("aumu"))
#expect(plist.contains("FOOX")) // subtype derived from name
#expect(plist.contains("LYRB")) // default manufacturer
#expect(plist.contains("FooExtension.FooAudioUnitViewController"))
}
@Test func macOSAppPBXProjReferencesRemoteSPM() {
let pbx: String = ProjectScaffolder.macOSAppPBXProj(name: "Foo")
#expect(pbx.contains("XCRemoteSwiftPackageReference"))
#expect(pbx.contains(ProjectScaffolder.lyrebirdPackageURL))
#expect(pbx.contains("LyrebirdUI"))
#expect(pbx.contains("Foo.app"))
}
// MARK: - --lyrebird-path local-package mode
@Test func packageManifestUsesLocalPathWhenSet() {
let manifest: String = ProjectScaffolder.packageManifest(
name: "Foo",
template: .basic,
lyrebirdPath: "/abs/path/Lyrebird"
)
#expect(manifest.contains(#".package(name: "Lyrebird", path: "/abs/path/Lyrebird")"#))
#expect(!manifest.contains(ProjectScaffolder.lyrebirdPackageURL))
}
@Test func packageManifestUsesRemoteURLWhenPathNil() {
let manifest: String = ProjectScaffolder.packageManifest(name: "Foo", template: .basic)
#expect(manifest.contains(ProjectScaffolder.lyrebirdPackageURL))
#expect(!manifest.contains(".package(name:"))
}
@Test func macOSAppPBXProjUsesLocalPackageRefWhenPathSet() {
let pbx: String = ProjectScaffolder.macOSAppPBXProj(
name: "Foo",
lyrebirdPath: "/abs/path/Lyrebird"
)
#expect(pbx.contains("XCLocalSwiftPackageReference"))
#expect(pbx.contains(#"relativePath = "/abs/path/Lyrebird""#))
#expect(!pbx.contains("XCRemoteSwiftPackageReference"))
#expect(!pbx.contains(ProjectScaffolder.lyrebirdPackageURL))
}
@Test func iOSAppPBXProjUsesLocalPackageRefWhenPathSet() {
let pbx: String = ProjectScaffolder.iOSAppPBXProj(
name: "Foo",
lyrebirdPath: "/abs/path/Lyrebird"
)
#expect(pbx.contains("XCLocalSwiftPackageReference"))
#expect(pbx.contains(#"relativePath = "/abs/path/Lyrebird""#))
#expect(!pbx.contains("XCRemoteSwiftPackageReference"))
}
@Test func auv3PBXProjUsesLocalPackageRefWhenPathSet() {
let pbx: String = ProjectScaffolder.auv3PBXProj(
name: "Foo",
lyrebirdPath: "/abs/path/Lyrebird"
)
#expect(pbx.contains("XCLocalSwiftPackageReference"))
#expect(pbx.contains(#"relativePath = "/abs/path/Lyrebird""#))
}
@Test func pbxQuoteEscapeHandlesQuotesAndBackslashes() {
#expect(ProjectScaffolder.pbxQuoteEscape("/plain/path") == "/plain/path")
#expect(ProjectScaffolder.pbxQuoteEscape(#"/has"quote"#) == #"/has\"quote"#)
#expect(ProjectScaffolder.pbxQuoteEscape(#"/has\backslash"#) == #"/has\\backslash"#)
// Backslash before quote: escape backslash first, then quote.
#expect(ProjectScaffolder.pbxQuoteEscape(#"/a\"b"#) == #"/a\\\"b"#)
}
@Test func macOSAppPBXProjEscapesPathInLocalRef() {
let pbx: String = ProjectScaffolder.macOSAppPBXProj(
name: "Foo",
lyrebirdPath: #"/has"quote/Lyrebird"#
)
#expect(pbx.contains(#"relativePath = "/has\"quote/Lyrebird";"#))
}
@Test func packageManifestEscapesPathInLocalRef() {
let manifest: String = ProjectScaffolder.packageManifest(
name: "Foo",
template: .basic,
lyrebirdPath: #"/has"quote/Lyrebird"#
)
#expect(manifest.contains(#".package(name: "Lyrebird", path: "/has\"quote/Lyrebird")"#))
}
@Test func scaffoldWithLyrebirdPathEmitsLocalRefs() throws {
let fm: FileManager = FileManager.default
let tmp: String = fm.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)").path
try fm.createDirectory(atPath: tmp,
withIntermediateDirectories: true, attributes: nil)
defer { try? fm.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(
name: "WithPath",
template: .macosUIXcode,
in: tmp,
lyrebirdPath: "/local/Lyrebird"
)
let pbxPath: String = (tmp as NSString)
.appendingPathComponent("WithPath/WithPath.xcodeproj/project.pbxproj")
let pbx: String = try String(contentsOfFile: pbxPath, encoding: .utf8)
#expect(pbx.contains("XCLocalSwiftPackageReference"))
#expect(pbx.contains("/local/Lyrebird"))
}
@Test func iOSAppPBXProjReferencesIPhoneOS() {
let pbx: String = ProjectScaffolder.iOSAppPBXProj(name: "Foo")
#expect(pbx.contains("SDKROOT = iphoneos"))
#expect(pbx.contains("IPHONEOS_DEPLOYMENT_TARGET = 18.0"))
#expect(pbx.contains("TARGETED_DEVICE_FAMILY"))
}
@Test func auv3PBXProjHasTwoTargets() {
let pbx: String = ProjectScaffolder.auv3PBXProj(name: "Foo")
// Two PBXNativeTarget entries
let nativeTargetCount: Int = pbx.components(separatedBy: "isa = PBXNativeTarget").count - 1
#expect(nativeTargetCount == 2)
#expect(pbx.contains("FooExtension"))
#expect(pbx.contains("PBXCopyFilesBuildPhase")) // embed extension phase
#expect(pbx.contains("dstSubfolderSpec = 13")) // Plug-ins folder
#expect(pbx.contains("app-extension"))
}
// MARK: - demo template
@Test func demoMainSwiftImportsLiveParam() {
let source: String = ProjectScaffolder.mainSwift(name: "Demo", template: .demo)
#expect(source.contains("@LiveParam"))
#expect(source.contains("SineTone"))
#expect(source.contains("CoreAudioDriver"))
}
@Test func demoMainSwiftContainsName() {
let source: String = ProjectScaffolder.mainSwift(name: "MyPiece", template: .demo)
#expect(source.contains("MyPiece"))
}
// MARK: - ui-demo template
@Test func uiDemoPackageManifestIncludesLyrebirdUI() {
let manifest: String = ProjectScaffolder.packageManifest(name: "MyApp", template: .uiDemo)
#expect(manifest.contains("LyrebirdUI"))
}
@Test func uiDemoMainSwiftUsesNSApplication() {
let source: String = ProjectScaffolder.mainSwift(name: "MyApp", template: .uiDemo)
#expect(source.contains("NSApplication"))
#expect(source.contains("AppDelegate"))
}
@Test func appDelegateSwiftContainsName() {
let source: String = ProjectScaffolder.appDelegateSwift(name: "MyApp")
#expect(source.contains("MyAppSynth"))
#expect(source.contains("LyrebirdWindow"))
#expect(source.contains("ParameterSlider"))
}
@Test func synthSwiftContainsUIParam() {
let source: String = ProjectScaffolder.synthSwift(name: "MyApp")
#expect(source.contains("@UIParam"))
#expect(source.contains("MyAppSynth"))
}
@Test func uiDemoScaffoldCreatesAllFiles() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("LyrebirdScaffolderTest_\(UUID().uuidString)")
.path
try FileManager.default.createDirectory(atPath: tmp,
withIntermediateDirectories: true,
attributes: nil)
defer { try? FileManager.default.removeItem(atPath: tmp) }
try ProjectScaffolder.scaffold(name: "MyApp", template: .uiDemo, in: tmp)
let fm: FileManager = FileManager.default
let root: String = (tmp as NSString).appendingPathComponent("MyApp")
let sources: String = (root as NSString).appendingPathComponent("Sources/MyApp")
#expect(fm.fileExists(atPath: (sources as NSString).appendingPathComponent("main.swift")))
#expect(fm.fileExists(atPath: (sources as NSString).appendingPathComponent("AppDelegate.swift")))
#expect(fm.fileExists(atPath: (sources as NSString).appendingPathComponent("MyAppSynth.swift")))
}
// MARK: - nrt template
@Test func nrtMainSwiftUsesNRTDriver() {
let source: String = ProjectScaffolder.mainSwift(name: "MyRender", template: .nrt)
#expect(source.contains("NRTDriver"))
#expect(source.contains("renderDuration"))
#expect(source.contains("output.caf"))
}
@Test func nrtMainSwiftContainsName() {
let source: String = ProjectScaffolder.mainSwift(name: "MyRender", template: .nrt)
#expect(source.contains("MyRenderSynth"))
}
@Test func nrtPackageManifestDoesNotIncludeLyrebirdUI() {
let manifest: String = ProjectScaffolder.packageManifest(name: "MyRender", template: .nrt)
#expect(!manifest.contains("LyrebirdUI"))
}
// MARK: - basic template unchanged by default
@Test func defaultTemplateIsBasic() {
let defaultSource: String = ProjectScaffolder.mainSwift(name: "Foo")
let basicSource: String = ProjectScaffolder.mainSwift(name: "Foo", template: .basic)
#expect(defaultSource == basicSource)
}
}
@@ -0,0 +1,86 @@
// REPLLauncherTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
@Suite("REPLLauncher")
struct REPLLauncherTests {
@Test func swiftBinaryExists() throws {
let path: String = try REPLLauncher.findSwift()
#expect(FileManager.default.isExecutableFile(atPath: path))
}
@Test func buildArgumentsAreSwiftBuild() {
// The REPL launch first runs `swift build` so .build/debug artifacts exist
// before the REPL is started.
#expect(REPLLauncher.buildArguments == ["build"])
}
@Test func replArgumentsPointAtBuildArtifacts() {
// `swift package repl` was removed from the toolchain. The replacement is
// `swift repl` with -I/-L flags pointing at the package's .build/debug.
let args: [String] = REPLLauncher.replArguments
#expect(args.first == "repl")
#expect(args.contains("-I"))
#expect(args.contains("-L"))
#expect(args.contains(".build/debug/Modules"))
#expect(args.contains(".build/debug/LyrebirdC.build"))
#expect(args.contains(".build/debug"))
#expect(args.contains("-lLyrebird"))
}
@Test func buildThrowsBuildFailedWhenNoPackageManifest() throws {
// Running `swift build` in a directory with no `Package.swift` exits
// non-zero. `build(in:)` should surface that as `CLIError.buildFailed`
// with a non-zero `exitCode`.
let tempDir: URL = FileManager.default.temporaryDirectory.appendingPathComponent(
"lyrebird-repl-build-failure-\(UUID().uuidString)"
)
try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: tempDir) }
var thrown: CLIError?
do {
try REPLLauncher.build(in: tempDir.path)
} catch let error as CLIError {
thrown = error
}
guard case .buildFailed(let exitCode) = thrown else {
Issue.record("build(in:) did not throw CLIError.buildFailed; got \(String(describing: thrown))")
return
}
#expect(exitCode != 0)
}
@Test func historyFilePathEndsWithLyrebirdHistory() {
#expect(REPLLauncher.historyFilePath.hasSuffix(".lyrebird_history"))
}
@Test func historyFilePathIsInHomeDirectory() {
let home: String = FileManager.default.homeDirectoryForCurrentUser.path
#expect(REPLLauncher.historyFilePath.hasPrefix(home))
}
@Test func processURLMatchesFindSwift() throws {
let swiftPath: String = try REPLLauncher.findSwift()
let processURL: URL? = try REPLLauncher.makeProcess().executableURL
#expect(processURL == URL(fileURLWithPath: swiftPath))
}
@Test func processArgumentsMatchReplArguments() throws {
let process: Process = try REPLLauncher.makeProcess()
#expect(process.arguments == REPLLauncher.replArguments)
}
@Test func buildProcessArgumentsMatchBuildArguments() throws {
let process: Process = try REPLLauncher.makeProcess(arguments: REPLLauncher.buildArguments)
#expect(process.arguments == REPLLauncher.buildArguments)
}
}
@@ -0,0 +1,136 @@
// SynthExporterTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
@Suite("SynthExporter")
struct SynthExporterTests {
// MARK: - Name validation
@Test func validNamePasses() {
#expect(throws: Never.self) {
try SynthExporter.validateName("MySynth")
}
}
@Test func validNameWithUnderscorePasses() {
#expect(throws: Never.self) {
try SynthExporter.validateName("Kick_Drum01")
}
}
@Test func emptyNameThrows() {
#expect(throws: SynthExporter.Error.invalidName(name: "")) {
try SynthExporter.validateName("")
}
}
@Test func nameStartingWithDigitThrows() {
#expect(throws: SynthExporter.Error.invalidName(name: "9Lives")) {
try SynthExporter.validateName("9Lives")
}
}
@Test func nameWithSpaceThrows() {
#expect(throws: SynthExporter.Error.invalidName(name: "My Synth")) {
try SynthExporter.validateName("My Synth")
}
}
@Test func nonASCIINameThrows() {
// Unicode letters are not valid Swift type names for SPM module context.
#expect(throws: SynthExporter.Error.invalidName(name: "音楽")) {
try SynthExporter.validateName("音楽")
}
}
// MARK: - Template content
@Test func templateContainsClassName() {
let source: String = SynthExporter.synthTemplate(name: "BassLine")
#expect(source.contains("class BassLine"))
}
@Test func templateImportsLyrebird() {
let source: String = SynthExporter.synthTemplate(name: "Foo")
#expect(source.contains("import LyrebirdSynth"))
}
@Test func templateExtendsSynthesizerBase() {
let source: String = SynthExporter.synthTemplate(name: "Pad")
#expect(source.contains("SynthesizerBase"))
}
@Test func templateContainsBuildOverride() {
let source: String = SynthExporter.synthTemplate(name: "Pad")
#expect(source.contains("override func build()"))
}
@Test func templateContainsAddOutputGeneratorHint() {
let source: String = SynthExporter.synthTemplate(name: "Pad")
#expect(source.contains("addOutputGenerator"))
}
// MARK: - Default output path
@Test func defaultOutputPathUsesCWD() {
let cwd: String = FileManager.default.currentDirectoryPath
let path: String = SynthExporter.defaultOutputPath(for: "MySynth")
#expect(path.hasPrefix(cwd))
#expect(path.hasSuffix("MySynth.swift"))
}
// MARK: - export writes file
@Test func exportWritesFileToExplicitPath() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("SynthExporterTest_\(UUID().uuidString).swift")
.path
defer { try? FileManager.default.removeItem(atPath: tmp) }
try SynthExporter.export(name: "DrumKit", to: tmp)
#expect(FileManager.default.fileExists(atPath: tmp))
let content: String = try String(contentsOfFile: tmp, encoding: .utf8)
#expect(content.contains("class DrumKit"))
}
@Test func exportThrowsWhenFileExistsAndNoOverwrite() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("SynthExporterTest_\(UUID().uuidString).swift")
.path
// Create a dummy file at the path first.
try "existing".write(toFile: tmp, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(atPath: tmp) }
#expect(throws: SynthExporter.Error.fileExists(path: tmp)) {
try SynthExporter.export(name: "Arp", to: tmp, overwrite: false)
}
}
@Test func exportOverwritesWhenFlagSet() throws {
let tmp: String = FileManager.default.temporaryDirectory
.appendingPathComponent("SynthExporterTest_\(UUID().uuidString).swift")
.path
try "old content".write(toFile: tmp, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(atPath: tmp) }
try SynthExporter.export(name: "Arp", to: tmp, overwrite: true)
let content: String = try String(contentsOfFile: tmp, encoding: .utf8)
#expect(content.contains("class Arp"))
#expect(!content.contains("old content"))
}
@Test func exportThrowsOnInvalidName() {
#expect(throws: SynthExporter.Error.invalidName(name: "bad-name")) {
try SynthExporter.export(name: "bad-name", to: "/tmp/bad-name.swift")
}
}
}
@@ -0,0 +1,102 @@
// TemplateInstallerTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
@Suite("TemplateInstaller")
struct TemplateInstallerTests {
// MARK: - Resource bundle
@Test func bundleResolvesXcodeTemplatesDir() throws {
// The LyrebirdCLI target ships its templates under Resources/XcodeTemplates.
// This test guards against a Package.swift regression where the .copy(...)
// entry gets removed or renamed.
let src: URL = try TemplateInstaller.sourceURL()
var isDir: ObjCBool = false
let exists: Bool = FileManager.default.fileExists(atPath: src.path, isDirectory: &isDir)
#expect(exists)
#expect(isDir.boolValue)
}
@Test func availableTemplatesIsNonEmpty() throws {
let names: [String] = try TemplateInstaller.availableTemplates()
#expect(!names.isEmpty)
#expect(names.allSatisfy { $0.hasSuffix(".xctemplate") })
}
@Test func availableTemplatesIncludesGenerator() throws {
let names: [String] = try TemplateInstaller.availableTemplates()
// LyrebirdGenerator is the canonical Tier 1 template. If it ever vanishes
// we want this test to fail loudly.
#expect(names.contains("LyrebirdGenerator.xctemplate"))
}
// MARK: - Destination URL
@Test func destinationURLIsInHomeLibrary() {
let dest: String = TemplateInstaller.destinationURL.path
let home: String = FileManager.default.homeDirectoryForCurrentUser.path
#expect(dest.hasPrefix(home + "/Library/Developer/Xcode/Templates/File Templates/"))
#expect(dest.hasSuffix("/Lyrebird"))
}
// MARK: - Install / uninstall round-trip
/// Uses a sandboxed temporary destination instead of the real user template
/// directory so the test never touches `~/Library`. We monkey-patch by
/// invoking the lower-level copy logic with explicit URLs.
@Test func roundTripInstallUninstallInSandbox() throws {
let fm: FileManager = FileManager.default
let sandbox: URL = try makeTempDir()
defer { try? fm.removeItem(at: sandbox) }
let dest: URL = sandbox.appendingPathComponent("Lyrebird", isDirectory: true)
// Replicate install logic in the sandbox.
let src: URL = try TemplateInstaller.sourceURL()
try fm.createDirectory(at: dest, withIntermediateDirectories: true)
let names: [String] = try TemplateInstaller.availableTemplates()
for name: String in names {
try fm.copyItem(at: src.appendingPathComponent(name),
to: dest.appendingPathComponent(name))
}
let copied: [String] = try fm.contentsOfDirectory(atPath: dest.path)
#expect(copied.sorted() == names.sorted())
// Spot-check a TemplateInfo.plist exists inside one of them.
let firstTemplatePlist: URL = dest
.appendingPathComponent(names[0])
.appendingPathComponent("TemplateInfo.plist")
#expect(fm.fileExists(atPath: firstTemplatePlist.path))
// Uninstall = remove dir.
try fm.removeItem(at: dest)
#expect(!fm.fileExists(atPath: dest.path))
}
@Test func installThrowsWhenDestinationExistsWithoutForce() throws {
// We cannot redirect TemplateInstaller's destination, but we can verify the
// error type the API documents by constructing one manually and round-tripping
// through Equatable.
let err1: TemplateInstaller.Error = .destinationExists(path: "/x")
let err2: TemplateInstaller.Error = .destinationExists(path: "/x")
let err3: TemplateInstaller.Error = .destinationExists(path: "/y")
#expect(err1 == err2)
#expect(err1 != err3)
}
// MARK: - Helpers
private func makeTempDir() throws -> URL {
let dir: URL = FileManager.default.temporaryDirectory
.appendingPathComponent("lyrebird-template-installer-\(UUID().uuidString)", isDirectory: true)
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
return dir
}
}
@@ -0,0 +1,188 @@
// WorkflowIntegrationTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdCLI
// MARK: - Workflow integration
/// End-to-end tests verifying the REPL → compile workflow:
///
/// 1. `ProjectScaffolder.scaffold` + `SynthExporter.export` produce the correct file tree.
/// 2. Every generated file is syntactically valid Swift (verified with `swiftc -parse`).
///
/// These tests verify that a piece authored in the interactive REPL can be exported
/// and placed in a compiled Lyrebird project without any manual fixups. `swiftc -parse`
/// catches template regressions (missing braces, malformed declarations, etc.) at
/// parse time without requiring Lyrebird to be resolved as a package dependency.
@Suite("Workflow integration")
struct WorkflowIntegrationTests {
// MARK: - Helpers
/// Creates a unique temporary directory path (not yet on disk).
private func temporaryDir() -> String {
FileManager.default.temporaryDirectory
.appendingPathComponent("LyrebirdWorkflowTest_\(UUID().uuidString)")
.path
}
/// Derives the path to `swiftc` from the toolchain that `ProjectRunner` locates.
///
/// Returns `nil` if no toolchain is found — callers should treat `nil` as "skip
/// parse verification" rather than a test failure.
private func swiftcPath() -> String? {
guard let swiftPath: String = try? ProjectRunner.findSwift() else { return nil }
let swiftcPath: String = URL(fileURLWithPath: swiftPath)
.deletingLastPathComponent()
.appendingPathComponent("swiftc")
.path
guard FileManager.default.isExecutableFile(atPath: swiftcPath) else { return nil }
return swiftcPath
}
/// Writes `source` to a temp file and runs `swiftc -parse` on it.
///
/// - Returns: `true` if the file parses successfully (exit code 0) **or** if
/// `swiftc` could not be located (graceful skip on toolchain-less environments).
private func parseCheck(source: String, fileName: String) throws -> Bool {
guard let swiftc: String = swiftcPath() else { return true }
let tmpDir: String = temporaryDir()
try FileManager.default.createDirectory(
atPath: tmpDir,
withIntermediateDirectories: true,
attributes: nil
)
defer { try? FileManager.default.removeItem(atPath: tmpDir) }
let filePath: String = URL(fileURLWithPath: tmpDir)
.appendingPathComponent(fileName)
.path
try source.write(toFile: filePath, atomically: true, encoding: .utf8)
let process: Process = Process()
process.executableURL = URL(fileURLWithPath: swiftc)
process.arguments = ["-parse", filePath]
// Suppress compiler output — we only care about the exit code.
process.standardOutput = Pipe()
process.standardError = Pipe()
try process.run()
process.waitUntilExit()
return process.terminationStatus == 0
}
// MARK: - Scaffold + export file tree
/// Scaffolding a project and exporting a synthesizer into it must produce the
/// expected directory tree, including both the core project files and the new
/// synthesizer source file.
@Test func scaffoldAndExportProduceCorrectFileTree() throws {
let parentDir: String = temporaryDir()
try FileManager.default.createDirectory(
atPath: parentDir,
withIntermediateDirectories: true,
attributes: nil
)
defer { try? FileManager.default.removeItem(atPath: parentDir) }
try ProjectScaffolder.scaffold(name: "MyPiece", in: parentDir)
let projectRoot: String = URL(fileURLWithPath: parentDir)
.appendingPathComponent("MyPiece")
.path
let sourcesDir: String = (projectRoot as NSString).appendingPathComponent("Sources/MyPiece")
let synthPath: String = (sourcesDir as NSString).appendingPathComponent("Tone.swift")
// Export the synth into the scaffolded project's Sources directory.
try SynthExporter.export(name: "Tone", to: synthPath)
let fm: FileManager = FileManager.default
#expect(fm.fileExists(atPath: (projectRoot as NSString).appendingPathComponent("Package.swift")))
#expect(fm.fileExists(atPath: (sourcesDir as NSString).appendingPathComponent("main.swift")))
#expect(fm.fileExists(atPath: (projectRoot as NSString)
.appendingPathComponent("Tests/MyPieceTests/MyPieceTests.swift")))
#expect(fm.fileExists(atPath: synthPath),
"Exported Tone.swift must exist in the project's Sources directory")
}
// MARK: - Syntax validity
/// The synthesizer template generated by `SynthExporter` must be valid Swift at the
/// syntax level. This catches missing braces, broken declarations, or doc-comment
/// formatting bugs that would prevent the file from compiling in a real project.
@Test func exportedSynthTemplateIsValidSwiftSyntax() throws {
let source: String = SynthExporter.synthTemplate(name: "BassLine")
#expect(try parseCheck(source: source, fileName: "BassLine.swift"),
"SynthExporter template must pass swiftc -parse")
}
/// The `main.swift` template scaffolded by `ProjectScaffolder` must be valid Swift.
@Test func scaffoldedMainSwiftIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.mainSwift(name: "MyPiece")
#expect(try parseCheck(source: source, fileName: "main.swift"),
"Scaffolded main.swift must pass swiftc -parse")
}
/// The test-file template scaffolded by `ProjectScaffolder` must be valid Swift.
@Test func scaffoldedTestsFileIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.testsSwift(name: "MyPiece")
#expect(try parseCheck(source: source, fileName: "MyPieceTests.swift"),
"Scaffolded tests file must pass swiftc -parse")
}
// MARK: - End-to-end workflow
/// All files produced by the full `lyrebird new` → `lyrebird export` workflow must
/// pass a Swift syntax check. This is the primary regression guard for the
/// REPL → compile transition: if any template drifts into invalid syntax the test
/// catches it before it reaches users.
@Test func fullWorkflowAllGeneratedFilesAreValidSwiftSyntax() throws {
let synthSource: String = SynthExporter.synthTemplate(name: "KickDrum")
let mainSource: String = ProjectScaffolder.mainSwift(name: "MyPiece")
let testsSource: String = ProjectScaffolder.testsSwift(name: "MyPiece")
#expect(try parseCheck(source: synthSource, fileName: "KickDrum.swift"),
"Exported synth template must pass swiftc -parse")
#expect(try parseCheck(source: mainSource, fileName: "main.swift"),
"Scaffolded main.swift must pass swiftc -parse")
#expect(try parseCheck(source: testsSource, fileName: "MyPieceTests.swift"),
"Scaffolded tests file must pass swiftc -parse")
}
// MARK: - Template syntax validity
@Test func demoTemplateMainSwiftIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.mainSwift(name: "MyPiece", template: .demo)
#expect(try parseCheck(source: source, fileName: "main.swift"),
"demo template main.swift must pass swiftc -parse")
}
@Test func uiDemoTemplateMainSwiftIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.mainSwift(name: "MyApp", template: .uiDemo)
#expect(try parseCheck(source: source, fileName: "main.swift"),
"ui-demo template main.swift must pass swiftc -parse")
}
@Test func uiDemoAppDelegateSwiftIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.appDelegateSwift(name: "MyApp")
#expect(try parseCheck(source: source, fileName: "AppDelegate.swift"),
"ui-demo AppDelegate.swift must pass swiftc -parse")
}
@Test func uiDemoSynthSwiftIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.synthSwift(name: "MyApp")
#expect(try parseCheck(source: source, fileName: "MyAppSynth.swift"),
"ui-demo Synth.swift must pass swiftc -parse")
}
@Test func nrtTemplateMainSwiftIsValidSwiftSyntax() throws {
let source: String = ProjectScaffolder.mainSwift(name: "MyRender", template: .nrt)
#expect(try parseCheck(source: source, fileName: "main.swift"),
"nrt template main.swift must pass swiftc -parse")
}
}