SPB Git

Repository Public

V1FixtureGenerator.swift 4.5 KB 57 lines swift

1// SP Notes Core2// File: Tests/SPNotesStoreTests/V1FixtureGenerator.swift3// Description: How Fixtures/v1.sqlite was made: a schema v1 database written by the shipped 1.0 code path (commit4//              267a673, before any v2 migration existed), holding every v1 table with realistic rows. Only runs when5//              SPN_MAKE_V1_FIXTURE=<output path> is set; on a build newer than v1 it refuses to run.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import Foundation10import Testing11@testable import SPNotesStore1213@Suite struct V1FixtureGenerator {14    @Test func generate() async throws {15        guard let out = ProcessInfo.processInfo.environment["SPN_MAKE_V1_FIXTURE"], !out.isEmpty else { return }16        #expect(NotesStore.schemaVersion == 1, "the v1 fixture can only be produced by the v1 code")17        guard NotesStore.schemaVersion == 1 else { return }18        let temp = TempDatabase()19        let store = try NotesStore(url: temp.url)20        // Synced pages from the server, with tags and an attachment.21        _ = try await store.applyRemote(22            pages: [23                remote("00000000-0000-4000-8000-000000000001", "Projet Alpha", "Notes de réunion du projet alpha", version: 3, tags: ["projet", "alpha"], pinned: true, rev: 11),24                remote("00000000-0000-4000-8000-000000000002", "Dossier", "", version: 1, properties: #"{"folder":true}"#, rev: 12),25                remote("00000000-0000-4000-8000-000000000003", "Enfant", "Texte de l'enfant éphémère", version: 2, parent: "00000000-0000-4000-8000-000000000002", tags: ["alpha"], rev: 13),26                remote("00000000-0000-4000-8000-000000000004", "À la corbeille", "bientôt supprimée", version: 1, deletedAt: epoch, rev: 14),27                remote("00000000-0000-4000-8000-000000000005", "Conflit", "version serveur un", version: 4, rev: 15),28            ],29            attachments: [RemoteAttachment(id: "00000000-0000-4000-8000-0000000000a1", pageId: "00000000-0000-4000-8000-000000000001",30                                           filename: "plan.pdf", mime: "application/pdf", size: 1234, sha256: "ab12", pageCount: 2, createdAt: epoch, rev: 16)],31            tombstones: [], tags: [RemoteTag(name: "projet", color: "#3157d5"), RemoteTag(name: "alpha", color: nil)], cursor: 16)32        // Local, unsynced work: a new page, an edit of a synced page (base copy), flags, tags.33        let created = try await store.createPage(draft("Brouillon local", "jamais synchronisé zèbre", id: "00000000-0000-4000-8000-000000000010", tags: ["local"]))34        _ = try await store.edit("00000000-0000-4000-8000-000000000001", text: "Notes de réunion du projet alpha, modifiées hors ligne")35        _ = try await store.setFavorite(id: "00000000-0000-4000-8000-000000000003", true)36        _ = try await store.edit("00000000-0000-4000-8000-000000000005", text: "version locale divergente")37        try await store.recordConflict(pageId: "00000000-0000-4000-8000-000000000005",38                                       server: ServerCopy(version: 5, title: "Conflit (serveur)", content: doc("version serveur deux"), properties: Data("{}".utf8), updatedAt: epoch))39        _ = try await store.snapshot(pageId: "00000000-0000-4000-8000-000000000001", reason: "manual")40        _ = try await store.addLocalAttachment(id: "00000000-0000-4000-8000-0000000000a2", pageId: created.id, filename: "photo.png", mime: "image/png",41                                               size: 42, sha256: "cd34", localPath: "attachments/photo.png")42        // Queue: known kinds and one kind this build does not know.43        _ = try await store.trash(id: "00000000-0000-4000-8000-000000000003")44        _ = try await store.enqueueOp(kind: "deleteAttachment", targetId: "00000000-0000-4000-8000-0000000000a1")45        _ = try await store.enqueueOp(kind: "futureKind", targetId: "x", payload: Data(#"{"a":1}"#.utf8))46        _ = try await store.createReminder(id: "00000000-0000-4000-8000-0000000000r1".replacingOccurrences(of: "r", with: "b"),47                                           pageId: "00000000-0000-4000-8000-000000000001", title: "Relancer le client", dueAt: epoch.addingTimeInterval(86_400))48        try await store.setMeta("workspace.name", "Atelier")49        try await store.checkpoint()50        #expect(try await store.integrityCheck().isEmpty)51        await store.close()52        let dest = URL(fileURLWithPath: out)53        try? FileManager.default.removeItem(at: dest)54        try FileManager.default.copyItem(at: temp.url, to: dest)55    }56}57
Files main
Menu

Theme