Add local source ingest and podcasts

This commit is contained in:
Krishna Kumar
2026-07-02 01:11:03 -05:00
parent 4d875e12d6
commit f8693f4be0
18 changed files with 1044 additions and 31 deletions

View File

@@ -104,4 +104,76 @@ final class AppIntentsTests: XCTestCase {
func testAppShortcutsAreRegistered() {
XCTAssertGreaterThanOrEqual(MarksShortcuts.appShortcuts.count, 4)
}
// MARK: - Ingest payload parsing
func testIngestParsesDirectURL() {
let payload = IngestPayloadParser.parse(item: URL(string: "https://example.com/article")!)
XCTAssertEqual(payload?.url, "https://example.com/article")
XCTAssertEqual(payload?.notes, "")
}
func testIngestFindsURLInSharedEmailText() {
let text = """
Thought you might want to save this:
https://example.com/story?utm_source=newsletter
Sent from Spark
"""
let payload = IngestPayloadParser.parse(item: text, typeIdentifier: "public.plain-text")
XCTAssertEqual(payload?.url, "https://example.com/story?utm_source=newsletter")
XCTAssertTrue(payload?.notes.contains("Sent from Spark") == true)
}
func testIngestIgnoresMailLinksAndUsesWebURL() {
let text = "mailto:friend@example.com\nRead https://example.com/read-later."
let payload = IngestPayloadParser.parse(item: text, typeIdentifier: "public.plain-text")
XCTAssertEqual(payload?.url, "https://example.com/read-later")
}
func testIngestDecodesHTMLLinksFromEmailClients() {
let html = "<p>Save this: <a href=\"https://example.com/a?x=1&amp;y=2\">article</a></p>"
let payload = IngestPayloadParser.parse(item: html, typeIdentifier: "public.html")
XCTAssertEqual(payload?.url, "https://example.com/a?x=1&y=2")
}
// MARK: - Local sources
func testSourceStoreSavesAndLoadsMetadata() throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
defer { try? FileManager.default.removeItem(at: root) }
let store = IngestedSourceStore(rootURL: root)
let source = IngestedSource(kind: .text, title: "Meeting Notes", bodyText: "Follow up on paper receipts.", tags: ["receipts"])
try store.save([source])
let loaded = try store.load()
XCTAssertEqual(loaded.count, 1)
XCTAssertEqual(loaded.first?.id, source.id)
XCTAssertEqual(loaded.first?.kind, .text)
XCTAssertEqual(loaded.first?.title, "Meeting Notes")
XCTAssertEqual(loaded.first?.bodyText, "Follow up on paper receipts.")
XCTAssertEqual(loaded.first?.tags, ["receipts"])
}
func testSourceStoreImportsPlainTextFile() throws {
let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
let input = FileManager.default.temporaryDirectory.appendingPathComponent("\(UUID().uuidString).txt")
defer {
try? FileManager.default.removeItem(at: root)
try? FileManager.default.removeItem(at: input)
}
try Data("Offline clipping text".utf8).write(to: input)
let store = IngestedSourceStore(rootURL: root)
let source = try store.importFile(from: input, tags: ["offline"])
XCTAssertEqual(source.kind, .file)
XCTAssertEqual(source.bodyText, "Offline clipping text")
XCTAssertEqual(source.tags, ["offline"])
XCTAssertNotNil(store.fileURL(for: source))
}
}