Files
Lyrebird/LiveCompile/Tests/LyrebirdLiveCompileUITests/ScratchModelConsoleTests.swift
T
josh 8519cabe42 v1.4.2 release: live-coding editor — Run Selection, slot release, engine panel, console, manual completion
Additive conveniences to the macOS-only Live Scratch editor. No changes to
existing public API.

- Run Selection (⌘E): evaluate just the highlighted text, additively.
- Graceful slot release: context.release(slot:) / free(slot:).
- Engine panel: live oscilloscope (ScopeCapture) + CPU avg/peak + counts.
- Reset Session / Restart to Reclaim Memory.
- Always-open console panel (report messages + errors with line:col).
- Faster typing: debounced highlight, updateNSView fast-path, publish guards.
- Manual code completion (Esc / F5), no auto-trigger on `.`; completion
  replaces the partial word, not the receiver expression.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 11:09:30 -07:00

77 lines
2.8 KiB
Swift

// ScratchModelConsoleTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
#if os(macOS)
import Testing
import LyrebirdSynth
@testable import LyrebirdLiveCompile
@testable import LyrebirdLiveCompileUI
@Suite("LyrebirdScratchModel console")
@MainActor
struct ScratchModelConsoleTests {
private func makeModel(text: String) -> LyrebirdScratchModel {
let engine: SynthesisEngine = SynthesisEngine(
blockSize: 64,
controlBlockSize: 16,
sampleRate: 48_000,
numOutputChannels: 2,
numInputChannels: 0,
numAudioBuses: 16,
numControlBuses: 16,
eventQueueCapacity: lyrebirdDefaultEventQueueCapacity,
driver: OfflineDriver()
)
return LyrebirdScratchModel(session: LiveSession(engine: engine), initialText: text)
}
@Test func successfulRunLogsInfo() async {
let model: LyrebirdScratchModel = makeModel(text: "OscSin(freq: 440) * 0.1")
model.switchMode(to: .graphDSL)
_ = await model.run(additive: false)
#expect(model.consoleEntries.contains { $0.kind == .info })
}
@Test func failedRunLogsErrorEntries() async {
let model: LyrebirdScratchModel = makeModel(text: "NotAGenerator(freq: 1)")
model.switchMode(to: .graphDSL)
_ = await model.run(additive: false)
#expect(model.consoleEntries.contains { $0.kind == .error })
#expect(model.consoleEntries.contains { $0.text.contains("NotAGenerator") })
}
@Test func reportMessagesAppearAsMessages() async {
// A DSL run pushes no messages; drive the log directly to prove the
// message → console wiring (drainMessages → .message entries).
let model: LyrebirdScratchModel = makeModel(text: "OscSin(freq: 440) * 0.1")
model.switchMode(to: .graphDSL)
model.session.appendMessage("hello from snippet")
_ = await model.run(additive: false)
#expect(model.consoleEntries.contains { $0.kind == .message && $0.text == "hello from snippet" })
}
@Test func clearConsoleEmpties() async {
let model: LyrebirdScratchModel = makeModel(text: "OscSin(freq: 440) * 0.1")
model.switchMode(to: .graphDSL)
_ = await model.run(additive: false)
#expect(!model.consoleEntries.isEmpty)
model.clearConsole()
#expect(model.consoleEntries.isEmpty)
}
@Test func resetSessionClearsConsole() async {
let model: LyrebirdScratchModel = makeModel(text: "OscSin(freq: 440) * 0.1")
model.switchMode(to: .graphDSL)
_ = await model.run(additive: false)
#expect(!model.consoleEntries.isEmpty)
model.resetSession()
#expect(model.consoleEntries.isEmpty)
}
}
#endif