import Testing import CoreSpotlight @testable import Marks /// End-to-end guard for the whole Spotlight path: index a bookmark, then /// retrieve it the way the on-device assistant does. /// /// Worth keeping. The bug this was written for made every item fail to /// translate into the index while `indexAppEntities` still reported success, /// so nothing short of a round trip would have caught it. struct SpotlightRetrievalTests { @Test func indexedBookmarkIsRetrievable() async throws { let b = Bookmark( id: 999_001, url: "https://github.com/example/zqxjkltest", title: "Zqxjkltest concurrency notes", description: "A distinctive probe document about zqxjkltest.", tagNames: ["zqxjkltest"], dateAdded: Date(), dateModified: Date(), isArchived: false, unread: false, shared: false, websiteTitle: nil, websiteDescription: nil, faviconUrl: nil, previewImageUrl: nil, aiSummary: nil, aiTags: nil ) await SpotlightIndexer.index([b]) var hits: [RetrievedBookmark] = [] for _ in 0..<20 { try? await Task.sleep(for: .milliseconds(700)) hits = await SpotlightBookmarkSearch.run(query: "zqxjkltest", limit: 5) if !hits.isEmpty { break } } await SpotlightIndexer.remove(ids: [999_001]) #expect(!hits.isEmpty, "Spotlight returned no hits for an indexed bookmark") let hit = try #require(hits.first) #expect(hit.title.contains("Zqxjkltest")) #expect(hit.url == "https://github.com/example/zqxjkltest", "url did not survive the round trip: \(hit.url)") #expect(hit.host == "github.com", "host was \(hit.host)") } @Test func indexedSourceIsRetrievable() async throws { let source = IngestedSource( kind: .text, title: "Wqvbnmtest meeting notes", bodyText: "A distinctive probe document about wqvbnmtest.", tags: ["wqvbnmtest"] ) await SourceSpotlightIndexer.index([source]) var hits: [RetrievedBookmark] = [] for _ in 0..<20 { try? await Task.sleep(for: .milliseconds(700)) hits = await SpotlightBookmarkSearch.run(query: "wqvbnmtest", limit: 5) if !hits.isEmpty { break } } await SourceSpotlightIndexer.remove(ids: [source.id]) #expect(!hits.isEmpty, "Spotlight returned no hits for an indexed source") #expect(hits.first?.title.contains("Wqvbnmtest") == true) } }