498f407585
Introduce optional Apple account-backed credits with scoped gateway access while preserving local and BYOK paths. Refresh assistant behavior, tests, privacy disclosures, docs, and the website for the 2.0 experience.
67 lines
2.2 KiB
Swift
67 lines
2.2 KiB
Swift
// LocalASRDownloadSourceSorterTests.swift
|
|
// OSGKeyboardTests
|
|
|
|
@testable import OSGKeyboardShared
|
|
import XCTest
|
|
|
|
final class LocalASRDownloadSourceSorterTests: XCTestCase {
|
|
|
|
private func source(_ type: String, priority: Int = 1) -> LocalASRDownloadSource {
|
|
LocalASRDownloadSource(
|
|
type: type,
|
|
priority: priority,
|
|
url: "https://example.com/\(type).tar.bz2",
|
|
baseURL: nil,
|
|
files: nil
|
|
)
|
|
}
|
|
|
|
func testChinaMainlandPrefersHFMirror() {
|
|
let sources = [
|
|
source("github"),
|
|
source("huggingface"),
|
|
source("hfmirror"),
|
|
source("modelscope")
|
|
]
|
|
let sorted = LocalASRDownloadSourceSorter.sorted(sources, region: Locale.Region("CN"))
|
|
XCTAssertEqual(sorted.map(\.type), ["hfmirror", "huggingface", "modelscope", "github"])
|
|
}
|
|
|
|
func testGlobalPrefersHuggingFace() {
|
|
let sources = [
|
|
source("github"),
|
|
source("huggingface"),
|
|
source("hfmirror"),
|
|
source("modelscope")
|
|
]
|
|
let sorted = LocalASRDownloadSourceSorter.sorted(sources, region: Locale.Region("US"))
|
|
XCTAssertEqual(sorted.map(\.type), ["huggingface", "hfmirror", "github", "modelscope"])
|
|
}
|
|
|
|
func testUnknownRegionFallsBackToMirror() {
|
|
let sources = [source("huggingface"), source("hfmirror")]
|
|
let sorted = LocalASRDownloadSourceSorter.sorted(sources, region: nil)
|
|
XCTAssertEqual(sorted.map(\.type), ["hfmirror", "huggingface"])
|
|
}
|
|
|
|
func testManualPreferenceOverridesRegion() {
|
|
let sources = [source("hfmirror"), source("huggingface")]
|
|
// Even in China, an explicit HF preference wins.
|
|
let sorted = LocalASRDownloadSourceSorter.sorted(
|
|
sources,
|
|
region: Locale.Region("CN"),
|
|
preferred: .huggingface
|
|
)
|
|
XCTAssertEqual(sorted.map(\.type), ["huggingface", "hfmirror"])
|
|
}
|
|
|
|
func testSameTypeUsesPriority() {
|
|
let sources = [
|
|
source("github", priority: 2),
|
|
source("github", priority: 1)
|
|
]
|
|
let sorted = LocalASRDownloadSourceSorter.sorted(sources, region: Locale.Region("US"))
|
|
XCTAssertEqual(sorted.map(\.priority), [1, 2])
|
|
}
|
|
}
|