Files
Lyrebird/LiveCompile/Tests/LyrebirdLiveCompileUITests/ScratchModelResetTests.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

59 lines
1.9 KiB
Swift

// ScratchModelResetTests.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 resetSession")
@MainActor
struct ScratchModelResetTests {
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 resetStopsAudioAndClearsDiagnosticsButKeepsBuffer() async {
let source: String = "OscSin(freq: 440) * 0.1"
let model: LyrebirdScratchModel = makeModel(text: source)
model.switchMode(to: .graphDSL)
_ = await model.run(additive: false) // tracked 1
#expect(model.trackedSynthCount == 1)
model.resetSession()
#expect(model.trackedSynthCount == 0) // audio stopped
#expect(model.diagnostics.isEmpty)
// Non-destructive: the user's buffer is preserved.
#expect(model.text == source)
#expect(model.statusMessage.contains("reset"))
}
@Test func resetLeavesAFreshDirtyBaseline() async {
let model: LyrebirdScratchModel = makeModel(text: "OscSin(freq: 440) * 0.1")
model.switchMode(to: .graphDSL)
_ = await model.run(additive: false) // .clean
model.resetSession()
// The placeholder buffer was never run in this fresh session → .dirty.
#expect(model.reevalState == .dirty)
}
}
#endif