Files
helder/Tests/HelderUITests/Support/WorkspaceHarness.swift
T
2026-10-23 09:40:20 +02:00

87 lines
3.0 KiB
Swift

import Foundation
import HelderCore
import HelderServices
@testable import HelderUI
/// A workspace wired entirely to fakes (no disk, no git, no user defaults), with a handle on each fake.
@MainActor
struct WorkspaceHarness {
let root: URL
let model: WorkspaceModel
let git: FakeGit
let files: FakeFiles
let config: FakeConfig
let notes: FakeNotes
let symbols: FakeSymbols
let recentFiles: FakeRecentFiles
let recents: FakeRecentProjects
let session: FakeSession
let layouts: FakeLayouts
let system: FakeSystem
let speech: FakeSpeech
let watchers: WatcherBox
let agent = FakeTerminal()
final class WatcherBox {
var made: [FakeWatcher] = []
var last: FakeWatcher? { made.last }
}
init(root: URL? = URL(fileURLWithPath: "/fake/project"), config: HelderConfig = .defaults, note: String = "",
git: GitSnapshot? = nil, tree: FileNode = sampleTree(), contents: [String: String] = [:],
recents: [RecentProject] = [], session: FakeSession = FakeSession()) {
let git = FakeGit(git)
let files = FakeFiles(tree: tree, contents: contents, root: root ?? URL(fileURLWithPath: "/"))
let config = FakeConfig(config)
let notes = FakeNotes(note)
let symbols = FakeSymbols()
let recentFiles = FakeRecentFiles()
let recentStore = FakeRecentProjects(recents)
let layouts = FakeLayouts()
let system = FakeSystem()
let speech = FakeSpeech()
let watchers = WatcherBox()
let app = AppServices(
recentProjects: recentStore, session: session, layouts: layouts, system: system, speech: speech,
makeWorkspace: { _ in
WorkspaceServices(git: git, files: files, search: FakeSearch(), symbols: symbols,
config: config, notes: notes, recentFiles: recentFiles)
},
makeWatcher: {
let watcher = FakeWatcher()
watchers.made.append(watcher)
return watcher
}
)
model = WorkspaceModel(root: root, app: app, timings: .immediate)
self.root = root ?? URL(fileURLWithPath: "/")
self.git = git
self.files = files
self.config = config
self.notes = notes
self.symbols = symbols
self.recentFiles = recentFiles
self.recents = recentStore
self.session = session
self.layouts = layouts
self.system = system
self.speech = speech
self.watchers = watchers
model.terminal.attach(agent, as: .agent)
}
/// Starts the model and waits for everything it kicked off.
func start() async {
await model.start()
await model.settle()
}
/// Runs a command and waits for the work it started.
func perform(_ command: Command) async {
model.perform(command)
await model.settle()
}
var toastTitles: [String] { model.toasts.toasts.map(\.title) }
}