SPB Git

Repository Public

NextNodesSyncTests.swift 4.1 KB 65 lines swift

1// SP Notes Core2// File: Tests/SPNotesSyncTests/NextNodesSyncTests.swift3// Description: The 3.0 document nodes through the whole pipeline (2.0): a page holding them is pulled, indexed4//              (transcript and annotation text reach the full-text index through the document's plain text),5//              edited through a typed view, pushed back, and the server copy keeps every attribute.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import Foundation10import Testing11import SPNotesDocument12import SPNotesStore13@testable import SPNotesSync14@testable import SPNotesTestSupport1516@Suite("3.0 nodes through sync")17struct NextNodesSyncTests {18    static let content = #"""19    {"type":"doc","content":[20      {"type":"paragraph","attrs":{"id":"p1","textAlign":null},"content":[{"type":"text","text":"Compte rendu"}]},21      {"type":"audio","attrs":{"id":"au1","attachmentId":"55555555-2222-4333-8444-555555555555","duration":65,"title":"Réunion budget","recordedAt":null,"transcript":[{"t":0,"text":"Bonjour à tous"},{"t":61,"text":"Le budget pharaonique est adopté"}],"transcriptStatus":"done","transcriptEngine":"whisper","summary":null,"futureAttr":{"keep":[1,2]}}},22      {"type":"pdf","attrs":{"id":"f1","attachmentId":"44444444-2222-4333-8444-555555555555","name":"Rapport.pdf","page":1,"annotations":[{"id":"a1","page":2,"kind":"highlight","color":"#ffd54a","rects":[[0.1,0.2,0.5,0.03]],"text":"La liquidité évanescente","note":"À vérifier scrupuleusement","createdAt":"2026-11-19T10:00:00.000Z"}]}},23      {"type":"mermaid","attrs":{"id":"m1","code":"graph TD\n  Alpha-->Omega","preview":null,"previewHash":null}},24      {"type":"hologram","attrs":{"id":"h1","frames":[1,2,3]}}25    ]}26    """#2728    @Test("transcript and annotation text are searchable after a pull; a typed edit is pushed without losing unknown attributes")29    func pullIndexEditPush() async throws {30        let world = World()31        let fake = world.fake32        let a = try world.device("A")33        let id = fake.webCreatePage(title: "Séance", content: Data(Self.content.utf8))34        #expect(await a.sync() == .completed)35        // The full-text index holds what the document's plain text holds.36        for query in ["pharaonique", "evanescente", "scrupuleusement", "Omega", "Rapport"] {37            #expect(try await a.store.search(query: query).map(\.id) == [id], "\(query)")38        }39        for query in ["whisper", "hologram", "55555555"] { #expect(try await a.store.search(query: query).isEmpty, "\(query)") }40        let page = try await a.page(id)41        #expect(page.plainText.contains("Le budget pharaonique est adopté") && page.wordCount == NoteDocument.wordCount(of: page.plainText))42        // An edit made through a typed view.43        var document = try NoteDocument(json: page.content)44        let line = try #require(document.lines.firstIndex { $0.type == NodeType.audio })45        guard case .audio(var audio)? = document.typedBlock(at: line) else { Issue.record("audio block expected"); return }46        audio.title = "Réunion budget 2027"47        let replaced = document.replaceBlockAtom(at: line, with: audio.node())48        #expect(replaced)49        let data = try document.jsonData()50        let digest = ContentDigest(content: data)51        #expect(try await a.store.updateContent(id: id, content: data, plainText: digest.plainText, wordCount: digest.wordCount, preview: digest.preview))52        #expect(await a.sync() == .completed)53        // The server has the edit, and everything this build does not know is still there.54        let server = try NoteDocument(json: try #require(fake.page(id)).content)55        let pushed = try #require(server.lines.compactMap(\.atomNode).first { $0.type == NodeType.audio })56        #expect(pushed.attrs?["title"] == "Réunion budget 2027")57        #expect(pushed.attrs?["futureAttr"] == ["keep": [1, 2]])58        #expect(pushed.attrs?["transcript"]?.arrayValue?.count == 2)59        #expect(server.lines.compactMap(\.atomNode).contains { $0.type == "hologram" && $0.attrs?["frames"] == [1, 2, 3] })60        #expect(try await a.store.search(query: "2027").map(\.id) == [id])61        try await expectMirror(a)62        await world.closeAll()63    }64}65
Files main
Menu

Theme