84 lines
2.8 KiB
Swift
84 lines
2.8 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 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,
|
|
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 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, 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.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) }
|
|
}
|