import Foundation import Testing @testable import EquipoKit @MainActor @Suite struct SignInLifetimeTests { @Test func endedOrForeignLifetimesCannotPersistAnything() throws { let store = MemorySecretStore() let accounts = DeviceAccounts(store: store) let old = accounts.lifetimes.current var account = DeviceAccount.new(origin: URL(string: "https://example.test")!, label: "Test") account.credential = try Fixture.decode("device-credential") try accounts.commit(.save(account), lifetime: old) old.end() let before = store.accounts.sorted().map { store.read($0) } for token in [old, SignInLifetimes().current] { for change in [DeviceAccounts.Change.save(account), .remove(account), .route("pairing")] { #expect(throws: CancellationError.self) { try accounts.commit(change, lifetime: token) } } } #expect(store.accounts.sorted().map { store.read($0) } == before) let next = accounts.lifetimes.begin() #expect(!old.isActive) #expect(next !== old) try accounts.commit(.remove(account), lifetime: next) #expect(accounts.all().isEmpty) } }