import Foundation import XCTest @testable import DocsKit /// The replica no longer snapshots or projects per command: its state is a /// base plus the updates since, and presentations patch only changed blocks. /// Each must stay exactly what a fresh replica of the same bytes shows. @MainActor final class CRDTIncrementalTests: XCTestCase { private func describe(_ nodes: [CRDTNode]) -> String { nodes.map { node in let runs = (node.runs ?? []).map { run in "\(run.insert)|\((run.marks ?? [:]).keys.sorted())" }.joined(separator: ",") return "\(node.id):\(node.type):\((node.attrs ?? [:]).sorted { $0.key < $1.key })[\(runs)]{\(describe(node.children ?? []))}" }.joined(separator: ";") } private func truth(_ replica: CRDTReplica) async throws -> String { let state = try await replica.persistentState().state let fresh = CRDTReplica(guid: "incremental") try await fresh.open(update: state) let projection = try await fresh.projection() await fresh.close() return describe(projection.children) } private func paragraphs(_ count: Int) -> [String: JSONValue] { let blocks: [JSONValue] = (0..