feat: use launch history to break search ranking ties

This commit is contained in:
2026-10-12 14:17:29 +02:00
parent a0a6f25c03
commit 0da8b8e241
5 changed files with 57 additions and 14 deletions
@@ -79,6 +79,36 @@ func applicationIdentityIgnoresDirectoryURLFormattingInLaunchHistory() {
#expect(history.suggestions(in: [historyApplication("Alpha"), plain]).first?.id == plain.id)
}
@Test @MainActor
func typedSearchUsesHistoryOnlyForEqualTextRanks() {
let suite = "ConjureHistoryTests.\(UUID().uuidString)"
let defaults = UserDefaults(suiteName: suite)!
defer { defaults.removePersistentDomain(forName: suite) }
var instant = Date(timeIntervalSinceReferenceDate: 5_000)
let history = LaunchHistory(defaults: defaults, now: { instant })
let apps = ["Code", "Code Alpha", "Code Recent", "Code Frequent", "Open Code", "Unrelated"].map(historyApplication)
history.recordLaunch(of: apps[3])
history.recordLaunch(of: apps[3])
instant += 10
history.recordLaunch(of: apps[2])
for _ in 0..<3 { history.recordLaunch(of: apps[4]) }
history.recordLaunch(of: apps[5])
#expect(history.results(for: "code", in: apps).map(\.name) == [
"Code", "Code Frequent", "Code Recent", "Code Alpha", "Open Code",
])
instant += 10
history.recordLaunch(of: apps[1])
#expect(history.results(for: "code", in: apps).map(\.name) == [
"Code", "Code Frequent", "Code Alpha", "Code Recent", "Open Code",
])
let fuzzy = ["AyB", "AzB", "xAyB", "AxxxxB"].map(historyApplication)
history.recordLaunch(of: fuzzy[1])
for _ in 0..<3 { history.recordLaunch(of: fuzzy[3]) }
#expect(history.results(for: "ab", in: fuzzy).map(\.name) == [
"AzB", "AyB", "xAyB", "AxxxxB",
])
}
private func historyApplication(_ name: String) -> Application {
Application(url: URL(fileURLWithPath: "/Applications/HistoryTests/\(name).app"), name: name)
}