Repository Public License
1import Foundation2import NavigatorCore3import Persistence45/// A clock the test moves by hand.6final class TestClock: @unchecked Sendable {7 private let lock = NSLock()8 private var date: Date9 /// 2026-11-25 12:00:00 UTC.10 init(_ start: TimeInterval = 1_795_608_000) { date = Date(timeIntervalSince1970: start) }11 var now: Date { lock.withLock { date } }12 func advance(_ seconds: TimeInterval) { lock.withLock { date.addTimeInterval(seconds) } }13}1415struct Fixture {16 let database: NavigatorDatabase17 let profile: Profile18 let space: OrbitSpace19 let clock = TestClock()2021 static func make() async throws -> Fixture {22 let database = try await NavigatorDatabase.inMemory()23 let profile = Profile(name: "Personal")24 try await database.profiles.save(profile)25 let space = OrbitSpace(profileID: profile.id, name: "Home")26 try await database.spaces.save(space)27 return Fixture(database: database, profile: profile, space: space)28 }29}3031/// Rows per table, to prove that an operation wrote nothing.32func tableCounts(_ database: NavigatorDatabase) async throws -> [String: Int] {33 try await database.sqlite.read { connection in34 var result: [String: Int] = [:]35 let tables = try connection.query("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'")36 .map { try $0.get("name", as: String.self) }37 for table in tables { result[table] = try connection.scalar("SELECT count(*) FROM \"\(table)\"", as: Int.self) ?? 0 }38 return result39 }40}4142let https = WebOrigin(scheme: "https", host: "example.com")43