M4: TranslationSession actor with epochs/one-in-flight streaming, PanelViewModel, non-activating NSPanel, streaming panel UI, searchable/recent target languages, warnings/errors and Copy/Retry/Replace actions. M5: InsertionCoordinator with target capture, AX direct replacement, secure-field/own-PID refusal, frontmost and selected-text verification, snapshot/⌘V/restore fallback, cancellation-safe restore and blocking-warning gate. M6: versioned AppSettings/SettingsStore, onboarding for Ollama/model/target/Accessibility, General/Model/Translation/Privacy/Diagnostics settings, launch-at-login via SMAppService, status menu (target, copy/replace last, setup, diagnostics, about), text-free diagnostics and first-run setup. Docs: PROGRESS M4–M6, ARCHITECTURE §10–§12, ADR-019/020, SELECTION_AND_CLIPBOARD and TESTING. Manual 10-app matrices, real AX/paste delivery, VoiceOver and focus checks remain open. Verified: make verify green (format, strict lint, scripts, privacy, Debug+Release signatures, 217 package tests); app launches and a two-copy clipboard smoke test opens the panel.
170 lines
5.7 KiB
Swift
170 lines
5.7 KiB
Swift
import Foundation
|
|
import SprachmittlerEngines
|
|
import SprachmittlerOllama
|
|
import SprachmittlerTestSupport
|
|
import Testing
|
|
@testable import SprachmittlerCore
|
|
|
|
@Suite("Onboarding")
|
|
@MainActor
|
|
struct OnboardingViewModelTests {
|
|
private let hyModel = InstalledModel(name: "hy-mt3", model: "hy-mt3", digest: "abc")
|
|
|
|
@Test func refreshReportsOllamaAndModel() async {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let catalog = FakeOllamaCatalog(version: "0.40.18", models: [hyModel])
|
|
let access = FakeAccessibilityPermission(isTrusted: false)
|
|
let model = OnboardingViewModel(
|
|
settingsStore: store,
|
|
catalogProvider: { _ in catalog },
|
|
accessibility: access
|
|
)
|
|
|
|
await model.refresh()
|
|
#expect(model.ollama == .ok("0.40.18"))
|
|
#expect(model.model == .ok("hy-mt3"))
|
|
#expect(!model.accessibilityTrusted)
|
|
#expect(!model.isChecking)
|
|
}
|
|
|
|
@Test func missingModelIsAFailedCheck() async {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let other = InstalledModel(name: "llama3", model: "llama3", digest: "x")
|
|
let model = OnboardingViewModel(
|
|
settingsStore: store,
|
|
catalogProvider: { _ in FakeOllamaCatalog(models: [other]) },
|
|
accessibility: FakeAccessibilityPermission()
|
|
)
|
|
|
|
await model.refresh()
|
|
guard case let .failed(message) = model.model else {
|
|
Issue.record("expected a failed model check")
|
|
return
|
|
}
|
|
#expect(message.contains("not installed"))
|
|
}
|
|
|
|
@Test func unreachableOllamaIsAFailedCheck() async {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let model = OnboardingViewModel(
|
|
settingsStore: store,
|
|
catalogProvider: { _ in throw FailingCatalog() },
|
|
accessibility: FakeAccessibilityPermission()
|
|
)
|
|
|
|
await model.refresh()
|
|
guard case let .failed(message) = model.ollama else {
|
|
Issue.record("expected a failed Ollama check")
|
|
return
|
|
}
|
|
#expect(!message.isEmpty)
|
|
}
|
|
|
|
@Test func targetAndCompletionArePersisted() throws {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let model = OnboardingViewModel(
|
|
settingsStore: store,
|
|
catalogProvider: { _ in FakeOllamaCatalog() },
|
|
accessibility: FakeAccessibilityPermission()
|
|
)
|
|
model.setTarget(HyMT3Languages.german)
|
|
try model.complete()
|
|
|
|
#expect(store.current().targetLanguage == "de")
|
|
#expect(store.current().hasCompletedOnboarding)
|
|
}
|
|
}
|
|
|
|
@Suite("Settings view model")
|
|
@MainActor
|
|
struct SettingsViewModelTests {
|
|
private let hyModel = InstalledModel(name: "hy-mt3", model: "hy-mt3", digest: "abc")
|
|
|
|
@Test func saveValidatesEndpointPersistsAndUpdatesLoginItem() {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let launch = FakeLaunchAtLogin()
|
|
let model = SettingsViewModel(
|
|
store: store,
|
|
catalogProvider: { _ in FakeOllamaCatalog() },
|
|
launchAtLogin: launch
|
|
)
|
|
model.draft.targetLanguage = "de"
|
|
model.draft.launchAtLogin = true
|
|
model.save()
|
|
|
|
#expect(model.saveError == nil)
|
|
#expect(store.current().targetLanguage == "de")
|
|
#expect(launch.requestedValues == [true])
|
|
}
|
|
|
|
@Test func invalidRemoteEndpointIsBlocked() throws {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let model = SettingsViewModel(
|
|
store: store,
|
|
catalogProvider: { _ in FakeOllamaCatalog() },
|
|
launchAtLogin: FakeLaunchAtLogin()
|
|
)
|
|
model.draft.endpoint = try #require(URL(string: "http://192.168.1.10:11434"))
|
|
model.draft.allowRemoteEndpoint = false
|
|
model.save()
|
|
|
|
#expect(model.saveError?.contains("remote") == true)
|
|
#expect(store.current().endpoint == AppSettings.defaultEndpoint)
|
|
}
|
|
|
|
@Test func resetRestoresDefaultsAndDisablesLoginItem() {
|
|
let store = SettingsStore(storage: InMemorySettingsDataStore())
|
|
let launch = FakeLaunchAtLogin(isEnabled: true)
|
|
let model = SettingsViewModel(
|
|
store: store,
|
|
catalogProvider: { _ in FakeOllamaCatalog() },
|
|
launchAtLogin: launch
|
|
)
|
|
model.draft.targetLanguage = "de"
|
|
model.save()
|
|
model.reset()
|
|
|
|
#expect(store.current() == AppSettings())
|
|
#expect(launch.requestedValues.last == false)
|
|
}
|
|
|
|
@Test func refreshModelsFiltersToHyMT3() async {
|
|
let other = InstalledModel(name: "llama3", model: "llama3", digest: "x")
|
|
let model = SettingsViewModel(
|
|
store: SettingsStore(storage: InMemorySettingsDataStore()),
|
|
catalogProvider: { _ in FakeOllamaCatalog(models: [hyModel, other]) },
|
|
launchAtLogin: FakeLaunchAtLogin()
|
|
)
|
|
await model.refreshModels()
|
|
#expect(model.installedModels.map(\.name) == ["hy-mt3"])
|
|
#expect(model.modelChoices.contains("hy-mt3"))
|
|
}
|
|
}
|
|
|
|
private struct FailingCatalog: OllamaCatalog, Error {
|
|
private var unreachable: OllamaError {
|
|
let url = URLComponents(string: "http://127.0.0.1:11434")?.url ?? URL(fileURLWithPath: "/")
|
|
return .unreachable(url)
|
|
}
|
|
|
|
func serverVersion() async throws -> String {
|
|
throw unreachable
|
|
}
|
|
|
|
func installedModels() async throws -> [InstalledModel] {
|
|
throw unreachable
|
|
}
|
|
|
|
func show(model: String) async throws -> ModelDetails {
|
|
throw OllamaError.modelNotInstalled(model)
|
|
}
|
|
|
|
func loadedModels() async throws -> [LoadedModel] {
|
|
[]
|
|
}
|
|
|
|
func refresh() async {}
|
|
|
|
func checkMinimumVersion() async throws {}
|
|
}
|