commit d14585f5c640c6ac19105cc8b49925c3911e5602 parent 6d52432ce8b3de151b403d7535a3879e44ceb0a5 Author: triesap <tyson@radroots.org> Date: Sun, 11 Oct 2026 16:29:13 +0000 today: fence supporting reads and current media - Share complete source, policy, context and promoted-generation read identity. - Revalidate current receipts and artifact authorization after asynchronous work. - Invalidate supporting presentation and observe current detail identities. - Verify offline reopen, read races, native revocation and ordinary media progress. Diffstat:
36 files changed, 2206 insertions(+), 478 deletions(-)
diff --git a/Package.swift b/Package.swift @@ -216,6 +216,7 @@ let package = Package( "Views/TeraEditingProtectionUITestSurface.swift", "Views/TeraRecoveryUITestSurface.swift", "Views/TeraSupportingViews.swift", + "Views/TeraSupportingCurrentDetail.swift", "Views/TeraSettingsView.swift", "Views/TeraSupportSettingsSection.swift", "Views/TeraStorageSettingsSection.swift", diff --git a/Tera.xcodeproj/project.pbxproj b/Tera.xcodeproj/project.pbxproj @@ -103,6 +103,7 @@ 9ABCF9A1CDFE20E2BB84A22F /* TeraRestoreRecoveryStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D73E45C67FF1D7BC2791A13 /* TeraRestoreRecoveryStoreTests.swift */; }; 9AD968F0B37C64B5AF8D9A68 /* TeraRootShellTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B8677670E203FF68EC88983 /* TeraRootShellTests.swift */; }; 9B37084901EC52EB44969304 /* TeraRuntimeResourceLifecycleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226F5C2370522AAFAD9D1C3D /* TeraRuntimeResourceLifecycleTests.swift */; }; + 9D8DC127A0E8D6FA1E095BD3 /* TeraSupportingFreshnessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FDC1D0EFD97CE715A5B253B /* TeraSupportingFreshnessTests.swift */; }; A1AD2A380F09994786889AF1 /* TeraAddStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F22CFABCF27A28408F68D25 /* TeraAddStoreTests.swift */; }; A5A98A2C7BE78267E6B23598 /* TeraKeyRemovalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F06622DFA682235F4BFA0841 /* TeraKeyRemovalTests.swift */; }; A64C7350AC157F600995440D /* TeraLocalRestoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10D9FACDF6B5330E86ADC240 /* TeraLocalRestoreTests.swift */; }; @@ -281,6 +282,7 @@ 9F22CFABCF27A28408F68D25 /* TeraAddStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeraAddStoreTests.swift; sourceTree = "<group>"; }; 9F54FC4930051FC4611B37D3 /* tera */ = {isa = PBXFileReference; lastKnownFileType = folder; name = tera; path = .; sourceTree = SOURCE_ROOT; }; 9F8B650ED2D867EF94248F6F /* TeraOperationRecoveryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeraOperationRecoveryTests.swift; sourceTree = "<group>"; }; + 9FDC1D0EFD97CE715A5B253B /* TeraSupportingFreshnessTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeraSupportingFreshnessTests.swift; sourceTree = "<group>"; }; A195B277BEDC31DE3A0D7601 /* TeraPublicationNavigationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeraPublicationNavigationTests.swift; sourceTree = "<group>"; }; A1CC48A95774B931BE8D1E4A /* TeraAddSignerFixture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeraAddSignerFixture.swift; sourceTree = "<group>"; }; A48EE7852ECF14C15F7DD902 /* TeraRevisionTestBackend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TeraRevisionTestBackend.swift; sourceTree = "<group>"; }; @@ -519,6 +521,7 @@ 194084009776463236C79B72 /* TeraSubmissionStoreTests.swift */, 8F171058FA0BF27ABA9E4164 /* TeraSubmissionTestBackend.swift */, 3D57113A80647B7448AEDB2B /* TeraSupportingBackend.swift */, + 9FDC1D0EFD97CE715A5B253B /* TeraSupportingFreshnessTests.swift */, C0636AEDEB50DDDD328374A9 /* TeraSupportingStoreTests.swift */, B4D3FEE2830E056E82AF05FD /* TeraTodayBackfillTests.swift */, 53CB51FEF4CE772320B3264C /* TeraTodayCacheFirstTests.swift */, @@ -867,6 +870,7 @@ 81EEC471523EBFC3C860698C /* TeraSubmissionStoreTests.swift in Sources */, 304D13AD257E8214855CFA5F /* TeraSubmissionTestBackend.swift in Sources */, 87575701D81B1FF173D9BB5A /* TeraSupportingBackend.swift in Sources */, + 9D8DC127A0E8D6FA1E095BD3 /* TeraSupportingFreshnessTests.swift in Sources */, 2479571FA99A7962794999C4 /* TeraSupportingStoreTests.swift in Sources */, 8422EAEECA73BB72974D002A /* TeraTodayBackfillTests.swift in Sources */, E98A5C885E3955D4DC4BB1EC /* TeraTodayCacheFirstTests.swift in Sources */, diff --git a/Tera/App/TeraProductStores.swift b/Tera/App/TeraProductStores.swift @@ -25,14 +25,26 @@ final class TeraProductStores { visibility = TeraVisibilityStore(runtimeClient: runtimeClient) visibility.willChange = { [today] in today.invalidateVisibility() } visibility.didChange = { [today] in await today.reload(refreshProjection: false) } - today.mediaWillChange = { [media] previous, current, context in - media.reconcileVisibility(previous: previous, current: current, context: context) + today.mediaWillChange = { [weak search, weak me, media] previous, current, context in + let permitted = current + (search?.currentMedia(context: context) ?? []) + + (me?.currentMedia(context: context) ?? []) + media.reconcileVisibility(previous: previous, current: permitted, context: context) + } + search.mediaWillChange = { [weak today, weak me, media] previous, current, context in + let todayMedia = today?.selectedContext == context ? today?.cards.flatMap(\.media) ?? [] : [] + let permitted = current + todayMedia + (me?.currentMedia(context: context) ?? []) + media.reconcileVisibility(previous: previous, current: permitted, context: context) + } + me.mediaWillChange = { [weak today, weak search, media] previous, current, context in + let todayMedia = today?.selectedContext == context ? today?.cards.flatMap(\.media) ?? [] : [] + let permitted = current + todayMedia + (search?.currentMedia(context: context) ?? []) + media.reconcileVisibility(previous: previous, current: permitted, context: context) } today.scopeWillChange = { [search, me, media] context in - search.stop() search.configure(context: context) - me.stop() + search.invalidatePresentation() me.configure(context: context) + me.invalidatePresentation() media.reset() } } diff --git a/Tera/State/TeraStoreObservation.swift b/Tera/State/TeraStoreObservation.swift @@ -54,6 +54,11 @@ final class TeraStoreObservation { task != nil } + /// Join the existing reconciliation when it superseded an awaited initial read. + func waitForRefresh() async { + await refreshTask?.value + } + deinit { task?.cancel() refreshTask?.cancel() @@ -73,6 +78,7 @@ final class TeraStoreObservation { buffer: (capacity: Int, delay: @Sendable (UInt32) async throws -> Void), state: @escaping @MainActor (TeraRuntimeObservationState) -> Void, accepts: @escaping @MainActor (TeraRuntimeChange) -> Bool, + invalidate: @escaping @MainActor (TeraObservationBatch) -> Void = { _ in }, refresh: @escaping @MainActor (TeraObservationBatch) async -> Void ) { guard task == nil, generation.isActive else { return } @@ -88,11 +94,15 @@ final class TeraStoreObservation { let changes = try await client.changes(bufferCapacity: buffer.capacity) guard self?.isCurrent(requested) == true else { break } state(.active) + invalidate(.currentState) self?.requireCurrentState(requested, refresh: refresh) for await value in changes { guard self?.isCurrent(requested) == true else { break } attempt = 0 if accepts(value) { + var changed = TeraObservationBatch() + changed.insert(value) + invalidate(changed) self?.pending.insert(value) self?.startRefresh(requested, refresh: refresh) } diff --git a/Tera/State/TeraSupportingStores.swift b/Tera/State/TeraSupportingStores.swift @@ -16,36 +16,78 @@ final class TeraSearchStore: ObservableObject { @Published private(set) var query = "" @Published private(set) var results: [TeraSearchResult] = [] @Published private(set) var state: TeraSupportingLoadState = .idle + @Published private(set) var observationState: TeraRuntimeObservationState = .inactive + var mediaWillChange: ([TeraMediaReference], [TeraMediaReference], TeraLocalNetwork?) -> Void = { _, _, _ in } private let runtimeClient: TeraRuntimeClient private let clock: TeraClock + private let observationDelay: @Sendable (UInt32) async throws -> Void private var context: TeraLocalNetwork? private var generation = TeraSessionGeneration.initial + private let observation = TeraStoreObservation() init( runtimeClient: TeraRuntimeClient, - clock: TeraClock = .system + clock: TeraClock = .system, + observationDelay: @escaping @Sendable (UInt32) async throws -> Void = TeraRuntimeObservationBackoff.sleep ) { self.runtimeClient = runtimeClient self.clock = clock + self.observationDelay = observationDelay } func configure(context: TeraLocalNetwork?) { guard self.context != context else { return } generation = generation.invalidated() + replaceResults([]) self.context = context query = "" - results = [] state = .idle + if observation.isActive { + observation.stop() + start() + } } func updateQuery(_ value: String) { generation = generation.invalidated() query = value - results = [] + replaceResults([]) + state = .idle + } + + func start() { + observation.start( + client: runtimeClient, buffer: (capacity: 8, delay: observationDelay), + state: { [weak self] in self?.observationState = $0 }, + accepts: { [weak self] in $0.matches(context: self?.context) }, + invalidate: { [weak self] batch in + guard batch.contains(anyOf: [.today, .identity, .profile]) else { return } + self?.invalidatePresentation() + }, + refresh: { [weak self] batch in + guard batch.contains(anyOf: [.today, .identity, .profile]) else { return } + await self?.search() + } + ) + } + + func invalidatePresentation() { + generation = generation.invalidated() + replaceResults([]) state = .idle } + func currentResult(id: String, type: TeraSearchResultType, context: TeraLocalNetwork?) -> TeraSearchResult? { + guard self.context == context else { return nil } + return results.first { $0.id == id && $0.type == type } + } + + func currentMedia(context: TeraLocalNetwork?) -> [TeraMediaReference] { + guard self.context == context else { return [] } + return results.flatMap { supportingMedia(card: $0.card, profile: $0.profile) } + } + func search() async { guard let context else { state = .failed("Choose a local network before searching.") @@ -54,7 +96,7 @@ final class TeraSearchStore: ObservableObject { guard query.utf8.count <= Self.rawQueryBytesMax, !query.unicodeScalars.contains(where: CharacterSet.controlCharacters.contains) else { - results = [] + replaceResults([]) state = .idle return } @@ -62,7 +104,7 @@ final class TeraSearchStore: ObservableObject { guard !normalized.isEmpty, normalized.lowercased().utf8.count <= Self.normalizedQueryBytesMax else { - results = [] + replaceResults([]) state = .idle return } @@ -78,22 +120,32 @@ final class TeraSearchStore: ObservableObject { asOfUnixSeconds: clock.unixSeconds() ) guard requestedGeneration == generation, generation.isActive, !Task.isCancelled else { return } - results = Self.unique(loaded) + replaceResults(Self.unique(loaded)) state = results.isEmpty ? .empty : .loaded } catch { guard requestedGeneration == generation, generation.isActive, !Task.isCancelled else { return } - results = [] + replaceResults([]) state = .failed(Self.message(for: error)) } } func stop() { generation = generation.invalidated() + observation.stop() + observationState = .stopped query = "" - results = [] + replaceResults([]) state = .idle } + private func replaceResults(_ values: [TeraSearchResult]) { + mediaWillChange( + results.flatMap { supportingMedia(card: $0.card, profile: $0.profile) }, + values.flatMap { supportingMedia(card: $0.card, profile: $0.profile) }, context + ) + results = values + } + private static func unique(_ values: [TeraSearchResult]) -> [TeraSearchResult] { var identifiers = Set<String>() return values.filter { identifiers.insert("\($0.type):\($0.id)").inserted } @@ -109,6 +161,7 @@ final class TeraMeStore: ObservableObject { @Published private(set) var snapshot: TeraMeSnapshot? @Published private(set) var state: TeraSupportingLoadState = .idle @Published private(set) var observationState: TeraRuntimeObservationState = .inactive + var mediaWillChange: ([TeraMediaReference], [TeraMediaReference], TeraLocalNetwork?) -> Void = { _, _, _ in } private let runtimeClient: TeraRuntimeClient private let clock: TeraClock @@ -136,8 +189,8 @@ final class TeraMeStore: ObservableObject { generation = generation.invalidated() reloadTask?.cancel() reloadTask = nil + replaceSnapshot(nil) self.context = context - snapshot = nil state = .idle if observation.isActive { observation.stop() @@ -151,11 +204,13 @@ final class TeraMeStore: ObservableObject { reloadTask = Task { [weak self] in await self?.reload() } let task = reloadTask await withTaskCancellationHandler { await task?.value } onCancel: { task?.cancel() } + guard !Task.isCancelled else { return } + await observation.waitForRefresh() } func reload() async { guard let context else { - snapshot = nil + replaceSnapshot(nil) state = .failed("Choose a local network before loading your profile.") return } @@ -170,10 +225,13 @@ final class TeraMeStore: ObservableObject { asOfUnixSeconds: clock.unixSeconds() ) guard requestedGeneration == generation, generation.isActive, !Task.isCancelled else { return } - snapshot = loaded + replaceSnapshot(loaded) state = loaded.cards.isEmpty && loaded.profile == nil ? .empty : .loaded } catch { guard requestedGeneration == generation, generation.isActive, !Task.isCancelled else { return } + if Self.refusesCurrentScope(error) { + replaceSnapshot(nil) + } state = .failed(Self.message(for: error)) } } @@ -184,17 +242,51 @@ final class TeraMeStore: ObservableObject { reloadTask?.cancel() reloadTask = nil observationState = .stopped - snapshot = nil + replaceSnapshot(nil) state = .idle } + func invalidatePresentation() { + generation = generation.invalidated() + reloadTask?.cancel() + replaceSnapshot(nil) + state = .idle + } + + func currentCard(id: String, context: TeraLocalNetwork?) -> TeraTodayCard? { + guard self.context == context else { return nil } + return snapshot?.cards.first { $0.id == id } + } + + func currentProfile(context: TeraLocalNetwork?) -> TeraProfileSummary? { + self.context == context ? snapshot?.profile : nil + } + + func currentMedia(context: TeraLocalNetwork?) -> [TeraMediaReference] { + self.context == context ? Self.references(snapshot) : [] + } + + private func replaceSnapshot(_ value: TeraMeSnapshot?) { + mediaWillChange(Self.references(snapshot), Self.references(value), context) + snapshot = value + } + + private static func references(_ snapshot: TeraMeSnapshot?) -> [TeraMediaReference] { + (snapshot?.cards ?? []).flatMap { supportingMedia(card: $0, profile: nil) } + + supportingMedia(card: nil, profile: snapshot?.profile) + } + private func startObservation() { observation.start( client: runtimeClient, buffer: (capacity: 8, delay: observationDelay), state: { [weak self] in self?.observationState = $0 }, accepts: { [weak self] in $0.matches(context: self?.context) }, + invalidate: { [weak self] batch in + guard batch.contains(anyOf: [.today, .identity, .profile, .drafts]) else { return } + self?.invalidatePresentation() + }, refresh: { [weak self] batch in - guard batch.contains(anyOf: [.today, .identity, .profile, .media, .drafts]) else { return } + guard batch.contains(anyOf: [.today, .identity, .profile, .drafts]) else { return } await self?.reloadTask?.value guard !Task.isCancelled else { return } await self?.reload() @@ -202,7 +294,26 @@ final class TeraMeStore: ObservableObject { ) } + private static func refusesCurrentScope(_ error: Error) -> Bool { + switch TeraRuntimeClient.failure(from: error, operation: "me").code { + case "today_invalid_request", "today_refresh_required", "today_projection_rebuilding", + "today_cursor_invalid", "today_reader_unsupported", "today_runtime_unavailable", "today_state_failed", + "storage_space_insufficient": + true + default: + false + } + } + private static func message(for error: Error) -> String { TeraUserMessages.text(for: error, fallback: .profileUnavailable) } } + +private func supportingMedia(card: TeraTodayCard?, profile: TeraProfileSummary?) -> [TeraMediaReference] { + func references(_ value: TeraProfileSummary?) -> [TeraMediaReference] { + [value?.picture, value?.banner].compactMap(\.self) + } + return (card?.media ?? []) + references(card?.authorProfile) + references(profile) + + (card?.thread ?? []).flatMap { references($0.authorProfile) } +} diff --git a/Tera/Views/TeraSupportingCurrentDetail.swift b/Tera/Views/TeraSupportingCurrentDetail.swift @@ -0,0 +1,70 @@ +import SwiftUI + +/// Navigation holds identity and context, while the observed owner supplies +/// the current value. Mandatory invalidation removes even an open detail. +struct TeraSearchCurrentDetail: View { + let resultID: String + let type: TeraSearchResultType + @ObservedObject var store: TeraSearchStore + let context: TeraLocalNetwork? + @ObservedObject var mediaStore: TeraMediaStore + let publicKey: String + let revise: (TeraTodayCard) -> Void + let retract: (TeraTodayCard) -> Void + + var body: some View { + if let result = store.currentResult(id: resultID, type: type, context: context) { + if let card = result.card { + TeraTodayDetailView( + card: card, context: context, mediaStore: mediaStore, + canRevise: card.authorPublicKey == publicKey && card.localOperationID != nil, + canRetract: card.authorPublicKey == publicKey, revise: revise, retract: retract + ) + } else if let profile = result.profile { + TeraProfileView(profile: profile, context: context, mediaStore: mediaStore) + } else { + TeraSupportingUnavailableDetail() + } + } else { + TeraSupportingUnavailableDetail() + } + } +} + +struct TeraMeCurrentDetail: View { + let cardID: String? + @ObservedObject var store: TeraMeStore + let context: TeraLocalNetwork? + @ObservedObject var mediaStore: TeraMediaStore + let publicKey: String + let revise: (TeraTodayCard) -> Void + let retract: (TeraTodayCard) -> Void + + var body: some View { + if let cardID { + if let card = store.currentCard(id: cardID, context: context) { + TeraTodayDetailView( + card: card, context: context, mediaStore: mediaStore, + canRevise: card.authorPublicKey == publicKey && card.localOperationID != nil, + canRetract: card.authorPublicKey == publicKey, revise: revise, retract: retract + ) + } else { + TeraSupportingUnavailableDetail() + } + } else if let profile = store.currentProfile(context: context) { + TeraProfileView(profile: profile, context: context, mediaStore: mediaStore) + } else { + TeraSupportingUnavailableDetail() + } + } +} + +private struct TeraSupportingUnavailableDetail: View { + var body: some View { + ContentUnavailableView( + "Content unavailable", systemImage: "eye.slash", + description: Text("This content is no longer available in this local network.") + ) + .accessibilityIdentifier("tera.supporting.detail.unavailable") + } +} diff --git a/Tera/Views/TeraSupportingViews.swift b/Tera/Views/TeraSupportingViews.swift @@ -45,7 +45,10 @@ struct TeraSearchSheet: View { } } } - .task(id: context) { store.configure(context: context) } + .task(id: context) { + store.configure(context: context) + store.start() + } .accessibilityIdentifier("radroots.support.search.sheet") } @@ -54,15 +57,10 @@ struct TeraSearchSheet: View { switch (result.card, result.profile) { case let (card?, _): NavigationLink { - TeraTodayDetailView( - card: card, - context: context, - mediaStore: mediaStore, - canRevise: card.authorPublicKey == snapshot.identity.publicKeyHex - && card.localOperationID != nil, - canRetract: card.authorPublicKey == snapshot.identity.publicKeyHex, - revise: revise, - retract: retract + TeraSearchCurrentDetail( + resultID: result.id, type: result.type, store: store, + context: context, mediaStore: mediaStore, + publicKey: snapshot.identity.publicKeyHex, revise: revise, retract: retract ) } label: { TeraTodayCardView(card: card, context: context, mediaStore: mediaStore) @@ -70,7 +68,11 @@ struct TeraSearchSheet: View { .accessibilityIdentifier("radroots.search.card.\(result.id)") case let (_, profile?): NavigationLink { - TeraProfileView(profile: profile, context: context, mediaStore: mediaStore) + TeraSearchCurrentDetail( + resultID: result.id, type: result.type, store: store, + context: context, mediaStore: mediaStore, + publicKey: snapshot.identity.publicKeyHex, revise: revise, retract: retract + ) } label: { TeraProfileRow(profile: profile, context: context, mediaStore: mediaStore) } @@ -148,7 +150,10 @@ struct TeraMeSheet: View { Section { if let profile = store.snapshot?.profile { NavigationLink { - TeraProfileView(profile: profile, context: context, mediaStore: mediaStore) + TeraMeCurrentDetail( + cardID: nil, store: store, context: context, mediaStore: mediaStore, + publicKey: runtimeSnapshot.identity.publicKeyHex, revise: revise, retract: retract + ) } label: { TeraProfileRow(profile: profile, context: context, mediaStore: mediaStore) } @@ -188,15 +193,9 @@ struct TeraMeSheet: View { } ForEach(store.snapshot?.cards ?? []) { card in NavigationLink { - TeraTodayDetailView( - card: card, - context: context, - mediaStore: mediaStore, - canRevise: card.localOperationID != nil, - canRetract: card.authorPublicKey - == (store.snapshot?.publicKey ?? runtimeSnapshot.identity.publicKeyHex), - revise: revise, - retract: retract + TeraMeCurrentDetail( + cardID: card.id, store: store, context: context, mediaStore: mediaStore, + publicKey: runtimeSnapshot.identity.publicKeyHex, revise: revise, retract: retract ) } label: { TeraTodayCardView(card: card, context: context, mediaStore: mediaStore) diff --git a/TeraFFI/provenance.json b/TeraFFI/provenance.json @@ -22,9 +22,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 82111672, + "bytes": 82137352, "path": "TeraFFI.xcframework/ios-arm64-simulator/libtera_ffi.a", - "sha256": "b0a9987c8b300a0ad9c8ad60842c890eb4f58a6f72ef80c0ecfd55a72aa359d8" + "sha256": "8dbaaaa5d5beb906f566ca3569ccd0636485347b88b67b6f93df205f9efd53ae" }, { "bytes": 106232, @@ -37,9 +37,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 82189864, + "bytes": 82215400, "path": "TeraFFI.xcframework/ios-arm64/libtera_ffi.a", - "sha256": "280e02aa32a717452c6563ee1e467c95c73dca459238b235c9546ec0033681e8" + "sha256": "610f913ec135ed4b308705934a666a5b3e154234267f6bea34e8992dc3259e67" }, { "bytes": 65428, @@ -77,34 +77,34 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 24583888, + "bytes": 24581008, "path": "native/aarch64-apple-darwin/libtera_ffi.dylib", - "sha256": "3cb8058b52d34659958f2e43d6d2bd3139068bf8990bc9fbb8fd8aa2333f3f8a" + "sha256": "4784093400af0731a1dce8e38f03f526c177330f3886290928138f5d9f8393f9" }, { - "bytes": 82111672, + "bytes": 82137352, "path": "native/aarch64-apple-ios-sim/libtera_ffi.a", - "sha256": "b0a9987c8b300a0ad9c8ad60842c890eb4f58a6f72ef80c0ecfd55a72aa359d8" + "sha256": "8dbaaaa5d5beb906f566ca3569ccd0636485347b88b67b6f93df205f9efd53ae" }, { - "bytes": 82189864, + "bytes": 82215400, "path": "native/aarch64-apple-ios/libtera_ffi.a", - "sha256": "280e02aa32a717452c6563ee1e467c95c73dca459238b235c9546ec0033681e8" + "sha256": "610f913ec135ed4b308705934a666a5b3e154234267f6bea34e8992dc3259e67" }, { - "bytes": 167886, + "bytes": 169621, "path": "source/aarch64-apple-darwin.json", - "sha256": "946dce32b306231d0a53dbfcfeaf94af512a79ae938a71fbca2f14318ebf2c90" + "sha256": "0ec7a313222e7075195f908d022674592a3859fdf2181b645274a5f24e70c988" }, { - "bytes": 167811, + "bytes": 169546, "path": "source/aarch64-apple-ios-sim.json", - "sha256": "b0c6c9db8e90f50e0cfba7a60fae42e7adb424dc38befafe153ec2dc89ba3104" + "sha256": "7a637781fbaa1d12ac6311e96d89d18576921ab67245df07cb4af5a30d1c4ea1" }, { - "bytes": 167781, + "bytes": 169516, "path": "source/aarch64-apple-ios.json", - "sha256": "324ca4722fc5fdb8812fe53b69eda0f76862c5643d2bca20a455b20f5dbc543a" + "sha256": "b1e10a6f8bb4db798d63daee0ef882ea451cb1b925c6524371044f1777b7aaf0" } ], "language": "swift", @@ -112,7 +112,7 @@ "schema": "radroots.artifact-manifest.v2", "source": { "repository": "https://github.com/radrootslabs/tera", - "tree": "450471e2ff1feb3675f676ededf0f8446c1a5099" + "tree": "0e803c4e3df6d4d4cbfaadf518a5fc96e5f9496d" }, "source_records": { "aarch64-apple-darwin": "source/aarch64-apple-darwin.json", @@ -139,9 +139,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 82111672, + "bytes": 82137352, "path": "Tera/Frameworks/TeraFFI.xcframework/ios-arm64-simulator/libtera_ffi.a", - "sha256": "b0a9987c8b300a0ad9c8ad60842c890eb4f58a6f72ef80c0ecfd55a72aa359d8" + "sha256": "8dbaaaa5d5beb906f566ca3569ccd0636485347b88b67b6f93df205f9efd53ae" }, { "bytes": 106232, @@ -154,9 +154,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 82189864, + "bytes": 82215400, "path": "Tera/Frameworks/TeraFFI.xcframework/ios-arm64/libtera_ffi.a", - "sha256": "280e02aa32a717452c6563ee1e467c95c73dca459238b235c9546ec0033681e8" + "sha256": "610f913ec135ed4b308705934a666a5b3e154234267f6bea34e8992dc3259e67" }, { "bytes": 811943, @@ -174,19 +174,19 @@ "sha256": "2479b0d8c0b5091dff93eaaee79902c3e1b5ebe86d8e08662b0066699b61bb15" }, { - "bytes": 167886, + "bytes": 169621, "path": "TeraFFI/source/aarch64-apple-darwin.json", - "sha256": "946dce32b306231d0a53dbfcfeaf94af512a79ae938a71fbca2f14318ebf2c90" + "sha256": "0ec7a313222e7075195f908d022674592a3859fdf2181b645274a5f24e70c988" }, { - "bytes": 167811, + "bytes": 169546, "path": "TeraFFI/source/aarch64-apple-ios-sim.json", - "sha256": "b0c6c9db8e90f50e0cfba7a60fae42e7adb424dc38befafe153ec2dc89ba3104" + "sha256": "7a637781fbaa1d12ac6311e96d89d18576921ab67245df07cb4af5a30d1c4ea1" }, { - "bytes": 167781, + "bytes": 169516, "path": "TeraFFI/source/aarch64-apple-ios.json", - "sha256": "324ca4722fc5fdb8812fe53b69eda0f76862c5643d2bca20a455b20f5dbc543a" + "sha256": "b1e10a6f8bb4db798d63daee0ef882ea451cb1b925c6524371044f1777b7aaf0" } ], "schema": "tera.installed-native-artifacts.v1" diff --git a/TeraFFI/source.lock b/TeraFFI/source.lock @@ -1,7 +1,7 @@ schema = "tera.installed-source.v1" repository = "https://github.com/radrootslabs/tera" -source_tree = "450471e2ff1feb3675f676ededf0f8446c1a5099" -manifest_sha256 = "2568fa4c903dee8188f55f76cb4d6e3a61fbb6ebfda89b1328fa0d87fa87f94a" +source_tree = "0e803c4e3df6d4d4cbfaadf518a5fc96e5f9496d" +manifest_sha256 = "bb39737e3b056fcdca01ac6a84a91752f27679f3b171836b37b571fe2b596ba9" source_date_epoch = 1787871027 [foundation] diff --git a/TeraFFI/source/aarch64-apple-darwin.json b/TeraFFI/source/aarch64-apple-darwin.json @@ -1880,10 +1880,10 @@ "sha256": "1d105fa23b9914c466009402f60bf3de83be3cf302be39b818392d5ae11faa6c" }, "core/crates/tera_core/src/runtime/product_surface/today.rs": { - "bytes": 127476, - "git_blob": "6e9912b9e9d4a2df792865edeab5cb1deae7ee9d", + "bytes": 126800, + "git_blob": "210c4acef48106c5004e2ee3908a899ce8863a87", "mode": "100644", - "sha256": "419f0106e47dca743203d923ad4e884844cae27daa06b826ce6baaec3aa06527" + "sha256": "f26602b01043dab35517bd5065e5b29c8b5b99ad18f068b585e436fa151800b5" }, "core/crates/tera_core/src/runtime/product_surface/today_admission_tests.rs": { "bytes": 13548, @@ -1988,10 +1988,10 @@ "sha256": "8774767e2d6488655b8d7a56139a5e7fce97f7f51eb5492755143858e6f3a23d" }, "core/crates/tera_core/src/runtime/product_surface/today_counted_storage_tests.rs": { - "bytes": 25854, - "git_blob": "ccf52e393ae713c829c445358b4b7185beec0494", + "bytes": 26791, + "git_blob": "97c79b66a0f20c003d516601cb4f1258fed07366", "mode": "100644", - "sha256": "b1af299b1e921d0bce5cea5a14f9231545a0c33aaaf045b88ce422dbb0c72035" + "sha256": "6f8044baaa9af99cbd6d69c3f196d4fa9529c2825473f5eaa1191c54e4c3149d" }, "core/crates/tera_core/src/runtime/product_surface/today_interruption_tests.rs": { "bytes": 11466, @@ -2023,23 +2023,29 @@ "mode": "100644", "sha256": "bfb337035bc2e4bdb568f8b7ec6c5ad440c63034ed43bac44f0d8f027be06949" }, + "core/crates/tera_core/src/runtime/product_surface/today_media_read_scope_tests.rs": { + "bytes": 3108, + "git_blob": "183d14c0ad8cff085775d778560b24f9fccf2e46", + "mode": "100644", + "sha256": "a8160373a47a29a024537e209c258072ddf553b7199f9fa1de54a86da6dc5ee6" + }, "core/crates/tera_core/src/runtime/product_surface/today_media_retrieval.rs": { - "bytes": 8726, - "git_blob": "5998af928f14e9d196705399556cb53861c7393b", + "bytes": 9606, + "git_blob": "0ed2dd33dd174abfb39eae73e32549243a9f1992", "mode": "100644", - "sha256": "fe7d0381ef8886e3735fd85a2624bd853e5395722eccb83e40f4b4923ae9ca59" + "sha256": "531c6456610c4d362e9cf2c6a976eb8e984ebb35d98ed834179f1871877ff2bd" }, "core/crates/tera_core/src/runtime/product_surface/today_media_visibility.rs": { - "bytes": 1249, - "git_blob": "f840e6ce45a25efef496d33e8e6fde5ffe65a7ab", + "bytes": 1843, + "git_blob": "e6b744f63bca5569aff8a2d3b28a3124ebaebcb2", "mode": "100644", - "sha256": "ba95996f99480061d07d7961ed35aac3670ccaa4da6a97f5036bb9b181a95493" + "sha256": "0469cb5c7a1408c53378ac8c231c1bdd26ca0b725d83c0812ef4312154353441" }, "core/crates/tera_core/src/runtime/product_surface/today_media_visibility_tests.rs": { - "bytes": 13288, - "git_blob": "4342cef551f467a586b46c536640952d68ce4fcd", + "bytes": 13349, + "git_blob": "913343cdbdb570e33303fbf31c98a63a502ce129", "mode": "100644", - "sha256": "531717678a8cdde8468201c051d5819486f9796d9152d8a68f91e56cbaaf87dc" + "sha256": "fe65264500b7cd5fce7719e0d7c70142b59a90bff5d3ce2d143f550a5adce9a6" }, "core/crates/tera_core/src/runtime/product_surface/today_page_budget.rs": { "bytes": 5877, @@ -2066,10 +2072,10 @@ "sha256": "736f01c1db7b13e2f6743677ee8cd7067040984fd95e60ca73a39f9401653b03" }, "core/crates/tera_core/src/runtime/product_surface/today_page_scope.rs": { - "bytes": 7094, - "git_blob": "d548b7405e945b9994f88bdae71b71efc04fc1c0", + "bytes": 2810, + "git_blob": "0804654416c0f99af28590983074bf465ebe1caf", "mode": "100644", - "sha256": "b664429e38b559ab6dd61f86e6197f2b9267ddfab1914560911c81f01dcbc540" + "sha256": "304fb63c3b659547977a623f93c00263401346549d4ba4cd22f6ac08bd731d11" }, "core/crates/tera_core/src/runtime/product_surface/today_page_threads.rs": { "bytes": 4556, @@ -2078,10 +2084,10 @@ "sha256": "11c7577045eb8dec87771fd1b5e04d9a071b1d8f5889d88a091f3f01355784ca" }, "core/crates/tera_core/src/runtime/product_surface/today_paging.rs": { - "bytes": 13443, - "git_blob": "9187b064d7d4f11a4c33801113b02cd1a5690ae2", + "bytes": 13047, + "git_blob": "ba1e620ba0ea5a46b4c9df1680819d13546ef443", "mode": "100644", - "sha256": "e261a08ffea6367b451047b3f7c04a4357e7d5a186b6e79aff360d8cf81d8171" + "sha256": "d95eb0ed30622961570e3d1e85811b998f8bbc5c619981421a020db414b19030" }, "core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs": { "bytes": 1800, @@ -2119,11 +2125,35 @@ "mode": "100644", "sha256": "a86244463cbf1b840706de7666459125729156305f398817a8e0f23014a58b7b" }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope.rs": { + "bytes": 9477, + "git_blob": "7b331721aecb1737f1f07d8ef59a5a19ac376973", + "mode": "100644", + "sha256": "c37c4b123db196464bef537688182ea753b0fd6c9a319923b5850442d1a527ec" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_conflict_tests.rs": { + "bytes": 7597, + "git_blob": "b89687b9ff83d1e54acbf02018228a95ad48deca", + "mode": "100644", + "sha256": "005ad61ec7fa431d37e8bcbee0e58538a63f2c1a4e1416c01d0b4244e435e95f" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_reopen_tests.rs": { + "bytes": 5896, + "git_blob": "05e73f80663dece19d5e3997f6312a3bc09ba723", + "mode": "100644", + "sha256": "30c747051393deca2aabfbea31411c73305f8eddd87c73f72dec3091e5a07028" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs": { + "bytes": 13416, + "git_blob": "b6391d89aed68656245b6d937e4ef6375b59d900", + "mode": "100644", + "sha256": "8fb8db7ed04c77954ea7b59ecbd64a7224c6e721a07626f2a852fc0e4a8e152a" + }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs": { - "bytes": 2370, - "git_blob": "1cbd2c87dfb8803aa0da3a95205572d77d1cd0f8", + "bytes": 1976, + "git_blob": "344cb579f1ffc97ab0066e7a7eba23b14f87b3f8", "mode": "100644", - "sha256": "25478bff1ff14f4ee81c9995d5882388e3f21de7e8a51187ee19d6ccee56c187" + "sha256": "7845e15d4c2b1ace6660c5a0349cbe7d7369f9c9df0cfefe499548a66666f1fa" }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation_tests.rs": { "bytes": 3678, @@ -2132,16 +2162,16 @@ "sha256": "25fdb0267fba678ab8952d94e5d4a278f6ee062c32b2fc65b9ad5c6ec6e4300e" }, "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs": { - "bytes": 5338, - "git_blob": "58a5d0df68645ff81b239dad1e1caf88d1da0c26", + "bytes": 5472, + "git_blob": "77e71c3ebd33137feb083b7d685e70a605a1dc5b", "mode": "100644", - "sha256": "18d99f9115f91e8eef599be165649737932a0c8cf52d1fc07815d045323cd383" + "sha256": "fe19ed4f3aeb0c9a54cb9438dad694dd1b096bd9ea6ea4025ead308db3339907" }, "core/crates/tera_core/src/runtime/product_surface/today_row_state.rs": { - "bytes": 5504, - "git_blob": "9764b80190493bbd33a3f3e77fafda8e25302dee", + "bytes": 5584, + "git_blob": "274950e8e4bd38c6f30e50ec1f9b8412dfb6e35e", "mode": "100644", - "sha256": "e4e0c3542a0da7a9fde42178b41e3cbeb3f456c4809a40ded1ee93e2fe43573b" + "sha256": "6f40d1538aeaad28f6fa0ea4c530ebff65a7bfb9702866c4375d8ed32300814e" }, "core/crates/tera_core/src/runtime/product_surface/today_rows.rs": { "bytes": 3390, @@ -2336,10 +2366,10 @@ "sha256": "0dbf39b1a85db893ba348b9d4b743b04a9fd76eee6fe2a1341e547e82821baf7" }, "core/crates/tera_core/src/runtime/visibility.rs": { - "bytes": 7833, - "git_blob": "bf4014d35cbc3cc874cee9717a58845a572a2994", + "bytes": 7398, + "git_blob": "62bb69a610a57d193e7bba0d72888ab44ce3b526", "mode": "100644", - "sha256": "6c9aa6897af072d9d498f19992438480cdf7f524059ea2387f0d14bf2331a4b8" + "sha256": "7066360476549caa6d2538ae1b0295802bf6dfdefd5d843122757db195649864" }, "core/crates/tera_core/src/runtime/visibility_tests.rs": { "bytes": 4047, @@ -2498,10 +2528,10 @@ "sha256": "a561c4a2249021d13125570413af511495689ff2fe1f5263187d76043183b7d6" }, "core/crates/tera_ffi/src/error.rs": { - "bytes": 22155, - "git_blob": "2fa463064d3893ae2fe9b9ec6202b32b58314b23", + "bytes": 24109, + "git_blob": "900899781e5426085195b2be8e073f8fc7ba0298", "mode": "100644", - "sha256": "0da6d975046e1d9ba5223c74966f3bd790568aaaa279c99aedce43c76bd6a569" + "sha256": "6f4b53abee3e2e1a62e739b5aee1f08f5fbdeeb40db5910641e7ecff8c6ccc4f" }, "core/crates/tera_ffi/src/invalidation.rs": { "bytes": 6914, @@ -3115,6 +3145,12 @@ "mode": "100644", "sha256": "e1f06a645f94e32b00835f70f4e9c769c2582ad581d7db43a29dfb9e87bef89a" }, + "scripts/fixture_alias_tool.py": { + "bytes": 1360, + "git_blob": "37113dc940e1ff44130ddd711805a5773f9e2378", + "mode": "100644", + "sha256": "66577e29849405b3a0ebb3f435600fde8da3f708ab66f573750334b4b2d8e015" + }, "scripts/fixture_connections.py": { "bytes": 4555, "git_blob": "854e2ad0a043475ccec002552c17273417a1246f", @@ -3404,10 +3440,10 @@ "sha256": "72fa6f6e3d481d7d91a8c650539af108a43c0bb9c9fd06a170ee929a478b17d1" }, "scripts/test_ffi_native.py": { - "bytes": 33161, - "git_blob": "bb0b05666d892062b496eadc36dfc35db16988d3", + "bytes": 33785, + "git_blob": "e6d9f75b296bb889b375ff22d62d0c3c059f8554", "mode": "100644", - "sha256": "782dd020ef450d207e12896a9bb781edbecd25bc4b795df2664be102b05ae4b0" + "sha256": "1a376ad4ebee22a0cf70c1fe23223b549f7efe7249323d931ea0066c82592bcf" }, "scripts/test_ffi_native_cache.py": { "bytes": 12040, @@ -3560,13 +3596,13 @@ "sha256": "0164f2b369fdcf734f73bd1df2a2f5b2e05b7bbd94c2d3ae75869fff6d876140" }, "test-fixtures/legacy-identifiers.v1.json": { - "bytes": 202268, - "git_blob": "7b2dc4df8abce5c2600f006c538da261373f16f9", + "bytes": 203133, + "git_blob": "72498d68317322b4841663b2a4d20a2e24158bdf", "mode": "100644", - "sha256": "a74c043b9135e1062f95901ba06fbf8f5e485f4211e239c27d2295bdebd6b2b3" + "sha256": "71edd6b04550d9b105a703985be1bdee0be348a1546a2ae071630d2a424a100e" } }, "policy": "staged_inputs", - "tree": "450471e2ff1feb3675f676ededf0f8446c1a5099" + "tree": "0e803c4e3df6d4d4cbfaadf518a5fc96e5f9496d" } } diff --git a/TeraFFI/source/aarch64-apple-ios-sim.json b/TeraFFI/source/aarch64-apple-ios-sim.json @@ -1878,10 +1878,10 @@ "sha256": "1d105fa23b9914c466009402f60bf3de83be3cf302be39b818392d5ae11faa6c" }, "core/crates/tera_core/src/runtime/product_surface/today.rs": { - "bytes": 127476, - "git_blob": "6e9912b9e9d4a2df792865edeab5cb1deae7ee9d", + "bytes": 126800, + "git_blob": "210c4acef48106c5004e2ee3908a899ce8863a87", "mode": "100644", - "sha256": "419f0106e47dca743203d923ad4e884844cae27daa06b826ce6baaec3aa06527" + "sha256": "f26602b01043dab35517bd5065e5b29c8b5b99ad18f068b585e436fa151800b5" }, "core/crates/tera_core/src/runtime/product_surface/today_admission_tests.rs": { "bytes": 13548, @@ -1986,10 +1986,10 @@ "sha256": "8774767e2d6488655b8d7a56139a5e7fce97f7f51eb5492755143858e6f3a23d" }, "core/crates/tera_core/src/runtime/product_surface/today_counted_storage_tests.rs": { - "bytes": 25854, - "git_blob": "ccf52e393ae713c829c445358b4b7185beec0494", + "bytes": 26791, + "git_blob": "97c79b66a0f20c003d516601cb4f1258fed07366", "mode": "100644", - "sha256": "b1af299b1e921d0bce5cea5a14f9231545a0c33aaaf045b88ce422dbb0c72035" + "sha256": "6f8044baaa9af99cbd6d69c3f196d4fa9529c2825473f5eaa1191c54e4c3149d" }, "core/crates/tera_core/src/runtime/product_surface/today_interruption_tests.rs": { "bytes": 11466, @@ -2021,23 +2021,29 @@ "mode": "100644", "sha256": "bfb337035bc2e4bdb568f8b7ec6c5ad440c63034ed43bac44f0d8f027be06949" }, + "core/crates/tera_core/src/runtime/product_surface/today_media_read_scope_tests.rs": { + "bytes": 3108, + "git_blob": "183d14c0ad8cff085775d778560b24f9fccf2e46", + "mode": "100644", + "sha256": "a8160373a47a29a024537e209c258072ddf553b7199f9fa1de54a86da6dc5ee6" + }, "core/crates/tera_core/src/runtime/product_surface/today_media_retrieval.rs": { - "bytes": 8726, - "git_blob": "5998af928f14e9d196705399556cb53861c7393b", + "bytes": 9606, + "git_blob": "0ed2dd33dd174abfb39eae73e32549243a9f1992", "mode": "100644", - "sha256": "fe7d0381ef8886e3735fd85a2624bd853e5395722eccb83e40f4b4923ae9ca59" + "sha256": "531c6456610c4d362e9cf2c6a976eb8e984ebb35d98ed834179f1871877ff2bd" }, "core/crates/tera_core/src/runtime/product_surface/today_media_visibility.rs": { - "bytes": 1249, - "git_blob": "f840e6ce45a25efef496d33e8e6fde5ffe65a7ab", + "bytes": 1843, + "git_blob": "e6b744f63bca5569aff8a2d3b28a3124ebaebcb2", "mode": "100644", - "sha256": "ba95996f99480061d07d7961ed35aac3670ccaa4da6a97f5036bb9b181a95493" + "sha256": "0469cb5c7a1408c53378ac8c231c1bdd26ca0b725d83c0812ef4312154353441" }, "core/crates/tera_core/src/runtime/product_surface/today_media_visibility_tests.rs": { - "bytes": 13288, - "git_blob": "4342cef551f467a586b46c536640952d68ce4fcd", + "bytes": 13349, + "git_blob": "913343cdbdb570e33303fbf31c98a63a502ce129", "mode": "100644", - "sha256": "531717678a8cdde8468201c051d5819486f9796d9152d8a68f91e56cbaaf87dc" + "sha256": "fe65264500b7cd5fce7719e0d7c70142b59a90bff5d3ce2d143f550a5adce9a6" }, "core/crates/tera_core/src/runtime/product_surface/today_page_budget.rs": { "bytes": 5877, @@ -2064,10 +2070,10 @@ "sha256": "736f01c1db7b13e2f6743677ee8cd7067040984fd95e60ca73a39f9401653b03" }, "core/crates/tera_core/src/runtime/product_surface/today_page_scope.rs": { - "bytes": 7094, - "git_blob": "d548b7405e945b9994f88bdae71b71efc04fc1c0", + "bytes": 2810, + "git_blob": "0804654416c0f99af28590983074bf465ebe1caf", "mode": "100644", - "sha256": "b664429e38b559ab6dd61f86e6197f2b9267ddfab1914560911c81f01dcbc540" + "sha256": "304fb63c3b659547977a623f93c00263401346549d4ba4cd22f6ac08bd731d11" }, "core/crates/tera_core/src/runtime/product_surface/today_page_threads.rs": { "bytes": 4556, @@ -2076,10 +2082,10 @@ "sha256": "11c7577045eb8dec87771fd1b5e04d9a071b1d8f5889d88a091f3f01355784ca" }, "core/crates/tera_core/src/runtime/product_surface/today_paging.rs": { - "bytes": 13443, - "git_blob": "9187b064d7d4f11a4c33801113b02cd1a5690ae2", + "bytes": 13047, + "git_blob": "ba1e620ba0ea5a46b4c9df1680819d13546ef443", "mode": "100644", - "sha256": "e261a08ffea6367b451047b3f7c04a4357e7d5a186b6e79aff360d8cf81d8171" + "sha256": "d95eb0ed30622961570e3d1e85811b998f8bbc5c619981421a020db414b19030" }, "core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs": { "bytes": 1800, @@ -2117,11 +2123,35 @@ "mode": "100644", "sha256": "a86244463cbf1b840706de7666459125729156305f398817a8e0f23014a58b7b" }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope.rs": { + "bytes": 9477, + "git_blob": "7b331721aecb1737f1f07d8ef59a5a19ac376973", + "mode": "100644", + "sha256": "c37c4b123db196464bef537688182ea753b0fd6c9a319923b5850442d1a527ec" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_conflict_tests.rs": { + "bytes": 7597, + "git_blob": "b89687b9ff83d1e54acbf02018228a95ad48deca", + "mode": "100644", + "sha256": "005ad61ec7fa431d37e8bcbee0e58538a63f2c1a4e1416c01d0b4244e435e95f" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_reopen_tests.rs": { + "bytes": 5896, + "git_blob": "05e73f80663dece19d5e3997f6312a3bc09ba723", + "mode": "100644", + "sha256": "30c747051393deca2aabfbea31411c73305f8eddd87c73f72dec3091e5a07028" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs": { + "bytes": 13416, + "git_blob": "b6391d89aed68656245b6d937e4ef6375b59d900", + "mode": "100644", + "sha256": "8fb8db7ed04c77954ea7b59ecbd64a7224c6e721a07626f2a852fc0e4a8e152a" + }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs": { - "bytes": 2370, - "git_blob": "1cbd2c87dfb8803aa0da3a95205572d77d1cd0f8", + "bytes": 1976, + "git_blob": "344cb579f1ffc97ab0066e7a7eba23b14f87b3f8", "mode": "100644", - "sha256": "25478bff1ff14f4ee81c9995d5882388e3f21de7e8a51187ee19d6ccee56c187" + "sha256": "7845e15d4c2b1ace6660c5a0349cbe7d7369f9c9df0cfefe499548a66666f1fa" }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation_tests.rs": { "bytes": 3678, @@ -2130,16 +2160,16 @@ "sha256": "25fdb0267fba678ab8952d94e5d4a278f6ee062c32b2fc65b9ad5c6ec6e4300e" }, "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs": { - "bytes": 5338, - "git_blob": "58a5d0df68645ff81b239dad1e1caf88d1da0c26", + "bytes": 5472, + "git_blob": "77e71c3ebd33137feb083b7d685e70a605a1dc5b", "mode": "100644", - "sha256": "18d99f9115f91e8eef599be165649737932a0c8cf52d1fc07815d045323cd383" + "sha256": "fe19ed4f3aeb0c9a54cb9438dad694dd1b096bd9ea6ea4025ead308db3339907" }, "core/crates/tera_core/src/runtime/product_surface/today_row_state.rs": { - "bytes": 5504, - "git_blob": "9764b80190493bbd33a3f3e77fafda8e25302dee", + "bytes": 5584, + "git_blob": "274950e8e4bd38c6f30e50ec1f9b8412dfb6e35e", "mode": "100644", - "sha256": "e4e0c3542a0da7a9fde42178b41e3cbeb3f456c4809a40ded1ee93e2fe43573b" + "sha256": "6f40d1538aeaad28f6fa0ea4c530ebff65a7bfb9702866c4375d8ed32300814e" }, "core/crates/tera_core/src/runtime/product_surface/today_rows.rs": { "bytes": 3390, @@ -2334,10 +2364,10 @@ "sha256": "0dbf39b1a85db893ba348b9d4b743b04a9fd76eee6fe2a1341e547e82821baf7" }, "core/crates/tera_core/src/runtime/visibility.rs": { - "bytes": 7833, - "git_blob": "bf4014d35cbc3cc874cee9717a58845a572a2994", + "bytes": 7398, + "git_blob": "62bb69a610a57d193e7bba0d72888ab44ce3b526", "mode": "100644", - "sha256": "6c9aa6897af072d9d498f19992438480cdf7f524059ea2387f0d14bf2331a4b8" + "sha256": "7066360476549caa6d2538ae1b0295802bf6dfdefd5d843122757db195649864" }, "core/crates/tera_core/src/runtime/visibility_tests.rs": { "bytes": 4047, @@ -2496,10 +2526,10 @@ "sha256": "a561c4a2249021d13125570413af511495689ff2fe1f5263187d76043183b7d6" }, "core/crates/tera_ffi/src/error.rs": { - "bytes": 22155, - "git_blob": "2fa463064d3893ae2fe9b9ec6202b32b58314b23", + "bytes": 24109, + "git_blob": "900899781e5426085195b2be8e073f8fc7ba0298", "mode": "100644", - "sha256": "0da6d975046e1d9ba5223c74966f3bd790568aaaa279c99aedce43c76bd6a569" + "sha256": "6f4b53abee3e2e1a62e739b5aee1f08f5fbdeeb40db5910641e7ecff8c6ccc4f" }, "core/crates/tera_ffi/src/invalidation.rs": { "bytes": 6914, @@ -3113,6 +3143,12 @@ "mode": "100644", "sha256": "e1f06a645f94e32b00835f70f4e9c769c2582ad581d7db43a29dfb9e87bef89a" }, + "scripts/fixture_alias_tool.py": { + "bytes": 1360, + "git_blob": "37113dc940e1ff44130ddd711805a5773f9e2378", + "mode": "100644", + "sha256": "66577e29849405b3a0ebb3f435600fde8da3f708ab66f573750334b4b2d8e015" + }, "scripts/fixture_connections.py": { "bytes": 4555, "git_blob": "854e2ad0a043475ccec002552c17273417a1246f", @@ -3402,10 +3438,10 @@ "sha256": "72fa6f6e3d481d7d91a8c650539af108a43c0bb9c9fd06a170ee929a478b17d1" }, "scripts/test_ffi_native.py": { - "bytes": 33161, - "git_blob": "bb0b05666d892062b496eadc36dfc35db16988d3", + "bytes": 33785, + "git_blob": "e6d9f75b296bb889b375ff22d62d0c3c059f8554", "mode": "100644", - "sha256": "782dd020ef450d207e12896a9bb781edbecd25bc4b795df2664be102b05ae4b0" + "sha256": "1a376ad4ebee22a0cf70c1fe23223b549f7efe7249323d931ea0066c82592bcf" }, "scripts/test_ffi_native_cache.py": { "bytes": 12040, @@ -3558,13 +3594,13 @@ "sha256": "0164f2b369fdcf734f73bd1df2a2f5b2e05b7bbd94c2d3ae75869fff6d876140" }, "test-fixtures/legacy-identifiers.v1.json": { - "bytes": 202268, - "git_blob": "7b2dc4df8abce5c2600f006c538da261373f16f9", + "bytes": 203133, + "git_blob": "72498d68317322b4841663b2a4d20a2e24158bdf", "mode": "100644", - "sha256": "a74c043b9135e1062f95901ba06fbf8f5e485f4211e239c27d2295bdebd6b2b3" + "sha256": "71edd6b04550d9b105a703985be1bdee0be348a1546a2ae071630d2a424a100e" } }, "policy": "staged_inputs", - "tree": "450471e2ff1feb3675f676ededf0f8446c1a5099" + "tree": "0e803c4e3df6d4d4cbfaadf518a5fc96e5f9496d" } } diff --git a/TeraFFI/source/aarch64-apple-ios.json b/TeraFFI/source/aarch64-apple-ios.json @@ -1878,10 +1878,10 @@ "sha256": "1d105fa23b9914c466009402f60bf3de83be3cf302be39b818392d5ae11faa6c" }, "core/crates/tera_core/src/runtime/product_surface/today.rs": { - "bytes": 127476, - "git_blob": "6e9912b9e9d4a2df792865edeab5cb1deae7ee9d", + "bytes": 126800, + "git_blob": "210c4acef48106c5004e2ee3908a899ce8863a87", "mode": "100644", - "sha256": "419f0106e47dca743203d923ad4e884844cae27daa06b826ce6baaec3aa06527" + "sha256": "f26602b01043dab35517bd5065e5b29c8b5b99ad18f068b585e436fa151800b5" }, "core/crates/tera_core/src/runtime/product_surface/today_admission_tests.rs": { "bytes": 13548, @@ -1986,10 +1986,10 @@ "sha256": "8774767e2d6488655b8d7a56139a5e7fce97f7f51eb5492755143858e6f3a23d" }, "core/crates/tera_core/src/runtime/product_surface/today_counted_storage_tests.rs": { - "bytes": 25854, - "git_blob": "ccf52e393ae713c829c445358b4b7185beec0494", + "bytes": 26791, + "git_blob": "97c79b66a0f20c003d516601cb4f1258fed07366", "mode": "100644", - "sha256": "b1af299b1e921d0bce5cea5a14f9231545a0c33aaaf045b88ce422dbb0c72035" + "sha256": "6f8044baaa9af99cbd6d69c3f196d4fa9529c2825473f5eaa1191c54e4c3149d" }, "core/crates/tera_core/src/runtime/product_surface/today_interruption_tests.rs": { "bytes": 11466, @@ -2021,23 +2021,29 @@ "mode": "100644", "sha256": "bfb337035bc2e4bdb568f8b7ec6c5ad440c63034ed43bac44f0d8f027be06949" }, + "core/crates/tera_core/src/runtime/product_surface/today_media_read_scope_tests.rs": { + "bytes": 3108, + "git_blob": "183d14c0ad8cff085775d778560b24f9fccf2e46", + "mode": "100644", + "sha256": "a8160373a47a29a024537e209c258072ddf553b7199f9fa1de54a86da6dc5ee6" + }, "core/crates/tera_core/src/runtime/product_surface/today_media_retrieval.rs": { - "bytes": 8726, - "git_blob": "5998af928f14e9d196705399556cb53861c7393b", + "bytes": 9606, + "git_blob": "0ed2dd33dd174abfb39eae73e32549243a9f1992", "mode": "100644", - "sha256": "fe7d0381ef8886e3735fd85a2624bd853e5395722eccb83e40f4b4923ae9ca59" + "sha256": "531c6456610c4d362e9cf2c6a976eb8e984ebb35d98ed834179f1871877ff2bd" }, "core/crates/tera_core/src/runtime/product_surface/today_media_visibility.rs": { - "bytes": 1249, - "git_blob": "f840e6ce45a25efef496d33e8e6fde5ffe65a7ab", + "bytes": 1843, + "git_blob": "e6b744f63bca5569aff8a2d3b28a3124ebaebcb2", "mode": "100644", - "sha256": "ba95996f99480061d07d7961ed35aac3670ccaa4da6a97f5036bb9b181a95493" + "sha256": "0469cb5c7a1408c53378ac8c231c1bdd26ca0b725d83c0812ef4312154353441" }, "core/crates/tera_core/src/runtime/product_surface/today_media_visibility_tests.rs": { - "bytes": 13288, - "git_blob": "4342cef551f467a586b46c536640952d68ce4fcd", + "bytes": 13349, + "git_blob": "913343cdbdb570e33303fbf31c98a63a502ce129", "mode": "100644", - "sha256": "531717678a8cdde8468201c051d5819486f9796d9152d8a68f91e56cbaaf87dc" + "sha256": "fe65264500b7cd5fce7719e0d7c70142b59a90bff5d3ce2d143f550a5adce9a6" }, "core/crates/tera_core/src/runtime/product_surface/today_page_budget.rs": { "bytes": 5877, @@ -2064,10 +2070,10 @@ "sha256": "736f01c1db7b13e2f6743677ee8cd7067040984fd95e60ca73a39f9401653b03" }, "core/crates/tera_core/src/runtime/product_surface/today_page_scope.rs": { - "bytes": 7094, - "git_blob": "d548b7405e945b9994f88bdae71b71efc04fc1c0", + "bytes": 2810, + "git_blob": "0804654416c0f99af28590983074bf465ebe1caf", "mode": "100644", - "sha256": "b664429e38b559ab6dd61f86e6197f2b9267ddfab1914560911c81f01dcbc540" + "sha256": "304fb63c3b659547977a623f93c00263401346549d4ba4cd22f6ac08bd731d11" }, "core/crates/tera_core/src/runtime/product_surface/today_page_threads.rs": { "bytes": 4556, @@ -2076,10 +2082,10 @@ "sha256": "11c7577045eb8dec87771fd1b5e04d9a071b1d8f5889d88a091f3f01355784ca" }, "core/crates/tera_core/src/runtime/product_surface/today_paging.rs": { - "bytes": 13443, - "git_blob": "9187b064d7d4f11a4c33801113b02cd1a5690ae2", + "bytes": 13047, + "git_blob": "ba1e620ba0ea5a46b4c9df1680819d13546ef443", "mode": "100644", - "sha256": "e261a08ffea6367b451047b3f7c04a4357e7d5a186b6e79aff360d8cf81d8171" + "sha256": "d95eb0ed30622961570e3d1e85811b998f8bbc5c619981421a020db414b19030" }, "core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs": { "bytes": 1800, @@ -2117,11 +2123,35 @@ "mode": "100644", "sha256": "a86244463cbf1b840706de7666459125729156305f398817a8e0f23014a58b7b" }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope.rs": { + "bytes": 9477, + "git_blob": "7b331721aecb1737f1f07d8ef59a5a19ac376973", + "mode": "100644", + "sha256": "c37c4b123db196464bef537688182ea753b0fd6c9a319923b5850442d1a527ec" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_conflict_tests.rs": { + "bytes": 7597, + "git_blob": "b89687b9ff83d1e54acbf02018228a95ad48deca", + "mode": "100644", + "sha256": "005ad61ec7fa431d37e8bcbee0e58538a63f2c1a4e1416c01d0b4244e435e95f" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_reopen_tests.rs": { + "bytes": 5896, + "git_blob": "05e73f80663dece19d5e3997f6312a3bc09ba723", + "mode": "100644", + "sha256": "30c747051393deca2aabfbea31411c73305f8eddd87c73f72dec3091e5a07028" + }, + "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs": { + "bytes": 13416, + "git_blob": "b6391d89aed68656245b6d937e4ef6375b59d900", + "mode": "100644", + "sha256": "8fb8db7ed04c77954ea7b59ecbd64a7224c6e721a07626f2a852fc0e4a8e152a" + }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs": { - "bytes": 2370, - "git_blob": "1cbd2c87dfb8803aa0da3a95205572d77d1cd0f8", + "bytes": 1976, + "git_blob": "344cb579f1ffc97ab0066e7a7eba23b14f87b3f8", "mode": "100644", - "sha256": "25478bff1ff14f4ee81c9995d5882388e3f21de7e8a51187ee19d6ccee56c187" + "sha256": "7845e15d4c2b1ace6660c5a0349cbe7d7369f9c9df0cfefe499548a66666f1fa" }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation_tests.rs": { "bytes": 3678, @@ -2130,16 +2160,16 @@ "sha256": "25fdb0267fba678ab8952d94e5d4a278f6ee062c32b2fc65b9ad5c6ec6e4300e" }, "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs": { - "bytes": 5338, - "git_blob": "58a5d0df68645ff81b239dad1e1caf88d1da0c26", + "bytes": 5472, + "git_blob": "77e71c3ebd33137feb083b7d685e70a605a1dc5b", "mode": "100644", - "sha256": "18d99f9115f91e8eef599be165649737932a0c8cf52d1fc07815d045323cd383" + "sha256": "fe19ed4f3aeb0c9a54cb9438dad694dd1b096bd9ea6ea4025ead308db3339907" }, "core/crates/tera_core/src/runtime/product_surface/today_row_state.rs": { - "bytes": 5504, - "git_blob": "9764b80190493bbd33a3f3e77fafda8e25302dee", + "bytes": 5584, + "git_blob": "274950e8e4bd38c6f30e50ec1f9b8412dfb6e35e", "mode": "100644", - "sha256": "e4e0c3542a0da7a9fde42178b41e3cbeb3f456c4809a40ded1ee93e2fe43573b" + "sha256": "6f40d1538aeaad28f6fa0ea4c530ebff65a7bfb9702866c4375d8ed32300814e" }, "core/crates/tera_core/src/runtime/product_surface/today_rows.rs": { "bytes": 3390, @@ -2334,10 +2364,10 @@ "sha256": "0dbf39b1a85db893ba348b9d4b743b04a9fd76eee6fe2a1341e547e82821baf7" }, "core/crates/tera_core/src/runtime/visibility.rs": { - "bytes": 7833, - "git_blob": "bf4014d35cbc3cc874cee9717a58845a572a2994", + "bytes": 7398, + "git_blob": "62bb69a610a57d193e7bba0d72888ab44ce3b526", "mode": "100644", - "sha256": "6c9aa6897af072d9d498f19992438480cdf7f524059ea2387f0d14bf2331a4b8" + "sha256": "7066360476549caa6d2538ae1b0295802bf6dfdefd5d843122757db195649864" }, "core/crates/tera_core/src/runtime/visibility_tests.rs": { "bytes": 4047, @@ -2496,10 +2526,10 @@ "sha256": "a561c4a2249021d13125570413af511495689ff2fe1f5263187d76043183b7d6" }, "core/crates/tera_ffi/src/error.rs": { - "bytes": 22155, - "git_blob": "2fa463064d3893ae2fe9b9ec6202b32b58314b23", + "bytes": 24109, + "git_blob": "900899781e5426085195b2be8e073f8fc7ba0298", "mode": "100644", - "sha256": "0da6d975046e1d9ba5223c74966f3bd790568aaaa279c99aedce43c76bd6a569" + "sha256": "6f4b53abee3e2e1a62e739b5aee1f08f5fbdeeb40db5910641e7ecff8c6ccc4f" }, "core/crates/tera_ffi/src/invalidation.rs": { "bytes": 6914, @@ -3113,6 +3143,12 @@ "mode": "100644", "sha256": "e1f06a645f94e32b00835f70f4e9c769c2582ad581d7db43a29dfb9e87bef89a" }, + "scripts/fixture_alias_tool.py": { + "bytes": 1360, + "git_blob": "37113dc940e1ff44130ddd711805a5773f9e2378", + "mode": "100644", + "sha256": "66577e29849405b3a0ebb3f435600fde8da3f708ab66f573750334b4b2d8e015" + }, "scripts/fixture_connections.py": { "bytes": 4555, "git_blob": "854e2ad0a043475ccec002552c17273417a1246f", @@ -3402,10 +3438,10 @@ "sha256": "72fa6f6e3d481d7d91a8c650539af108a43c0bb9c9fd06a170ee929a478b17d1" }, "scripts/test_ffi_native.py": { - "bytes": 33161, - "git_blob": "bb0b05666d892062b496eadc36dfc35db16988d3", + "bytes": 33785, + "git_blob": "e6d9f75b296bb889b375ff22d62d0c3c059f8554", "mode": "100644", - "sha256": "782dd020ef450d207e12896a9bb781edbecd25bc4b795df2664be102b05ae4b0" + "sha256": "1a376ad4ebee22a0cf70c1fe23223b549f7efe7249323d931ea0066c82592bcf" }, "scripts/test_ffi_native_cache.py": { "bytes": 12040, @@ -3558,13 +3594,13 @@ "sha256": "0164f2b369fdcf734f73bd1df2a2f5b2e05b7bbd94c2d3ae75869fff6d876140" }, "test-fixtures/legacy-identifiers.v1.json": { - "bytes": 202268, - "git_blob": "7b2dc4df8abce5c2600f006c538da261373f16f9", + "bytes": 203133, + "git_blob": "72498d68317322b4841663b2a4d20a2e24158bdf", "mode": "100644", - "sha256": "a74c043b9135e1062f95901ba06fbf8f5e485f4211e239c27d2295bdebd6b2b3" + "sha256": "71edd6b04550d9b105a703985be1bdee0be348a1546a2ae071630d2a424a100e" } }, "policy": "staged_inputs", - "tree": "450471e2ff1feb3675f676ededf0f8446c1a5099" + "tree": "0e803c4e3df6d4d4cbfaadf518a5fc96e5f9496d" } } diff --git a/TeraTests/TeraScopeBackend.swift b/TeraTests/TeraScopeBackend.swift @@ -26,6 +26,8 @@ actor TeraScopeBackend: TeraRuntimeBackend { private var media: TeraVerifiedMediaArtifact private var pages: [String: TeraTodayPage] = [:] private var meCards = [TeraScopeFixtures.card("old")] + private var meProfile: TeraProfileSummary? + private var searchResults: [TeraSearchResult]? private var revision: UInt64 = 0 private var syncReceipt: TeraTodaySyncReceipt? var recoveryCompletion: (@Sendable (TeraRecoveryUploadReceipt, TeraPreparedMediaHandle) async throws -> TeraRecoveryCompletionReceipt)? @@ -87,10 +89,18 @@ actor TeraScopeBackend: TeraRuntimeBackend { pages[cursor] = value } + func setMeProfile(_ value: TeraProfileSummary) { + meProfile = value + } + func setMeCards(_ values: [TeraTodayCard]) { meCards = values } + func setSearchResults(_ values: [TeraSearchResult]) { + searchResults = values + } + func setReconciliation(_ cards: [TeraTodayCard], generation: UInt64) { reconciliationCards = cards reconciliationGeneration = generation @@ -224,13 +234,14 @@ actor TeraScopeBackend: TeraRuntimeBackend { func search( context _: TeraLocalNetwork, query: String, limit _: UInt16, asOfUnixSeconds _: UInt64 ) async throws -> [TeraSearchResult] { + let result = searchResults ?? [TeraSearchResult(type: .card, id: query, card: TeraScopeFixtures.card(query), profile: nil)] try await wait(.search) - return [TeraSearchResult(type: .card, id: query, card: TeraScopeFixtures.card(query), profile: nil)] + return result } func me(context: TeraLocalNetwork, asOfUnixSeconds _: UInt64) async throws -> TeraMeSnapshot { lastMeContext = context - let result = TeraMeSnapshot(publicKey: value.identity.publicKeyHex, profile: nil, cards: meCards) + let result = TeraMeSnapshot(publicKey: value.identity.publicKeyHex, profile: meProfile, cards: meCards) try await wait(.me) return result } diff --git a/TeraTests/TeraSupportingFreshnessTests.swift b/TeraTests/TeraSupportingFreshnessTests.swift @@ -0,0 +1,332 @@ +@testable import TeraApp +import XCTest + +@MainActor +final class TeraSupportingFreshnessTests: XCTestCase { + func testSearchMandatoryFailureClearsOpenDetailAndRevokesMedia() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let stores = TeraProductStores(runtimeClient: client) + stores.configure(snapshot: TeraScopeFixtures.snapshot()) + let store = stores.search + let reference = TeraScopeFixtures.reference() + let profile = profile(reference) + let result = TeraSearchResult(type: .profile, id: profile.authorPublicKey, card: nil, profile: profile) + await backend.setSearchResults([result]) + store.updateQuery("old farm") + store.start() + await TeraScopeFixtures.eventually { store.state == .loaded } + XCTAssertNotNil(store.currentResult(id: result.id, type: .profile, context: context)) + let media = await backend.pause(.media) + stores.media.load(media: reference, context: context) + await media.entered.wait() + let failure = await backend.pause(.search, fails: true) + await backend.emit(.today, context: context) + await failure.entered.wait() + XCTAssertEqual(store.query, "old farm") + XCTAssertTrue(store.results.isEmpty) + XCTAssertNil(store.currentResult(id: result.id, type: .profile, context: context)) + XCTAssertEqual(stores.media.state(for: reference, context: context), .unavailable) + await media.resume.open() + await failure.resume.open() + await TeraScopeFixtures.eventually { + if case .failed = store.state { + true + } else { + false + } + } + XCTAssertTrue(store.results.isEmpty) + XCTAssertNil(stores.media.image(for: reference, context: context)) + XCTAssertEqual(stores.media.cachedByteCount, 0) + stores.stop() + _ = try await client.stop() + } + + func testSearchPausedOldResultCannotReturnAfterReplacementInvalidation() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let store = TeraSearchStore(runtimeClient: client) + store.configure(context: context) + store.updateQuery("scope") + await backend.setSearchResults([result("old")]) + store.start() + await TeraScopeFixtures.eventually { store.results.first?.id == "old" } + let first = await backend.pause(.search) + await backend.emit(.today, context: context) + await first.entered.wait() + let current = await backend.pause(.search) + await backend.setSearchResults([result("current")]) + await backend.emit(.profile, context: context) + XCTAssertTrue(store.results.isEmpty) + await first.resume.open() + await current.entered.wait() + XCTAssertTrue(store.results.isEmpty, "The completed old read must remain fenced") + await current.resume.open() + await TeraScopeFixtures.eventually { store.results.first?.id == "current" } + XCTAssertNil(store.currentResult(id: "old", type: .card, context: context)) + XCTAssertNotNil(store.currentResult(id: "current", type: .card, context: context)) + let calls = await backend.counts[.search] + XCTAssertEqual(calls, 3, "Initial read and one bounded worker with one pending reconciliation") + store.stop() + _ = try await client.stop() + } + + func testMeVoluntaryOfflineFailureKeepsCacheButMandatoryFailureClearsIt() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let store = TeraMeStore(runtimeClient: client) + store.configure(context: context) + await store.reload() + XCTAssertNotNil(store.currentCard(id: "old", context: context)) + let voluntary = await backend.pause(.me, failure: .local( + operation: "today", code: "today_storage_failed", safeMessage: "The local store is temporarily unavailable." + )) + let reload = Task { await store.reload() } + await voluntary.entered.wait() + await voluntary.resume.open() + await reload.value + XCTAssertNotNil(store.currentCard(id: "old", context: context)) + let mandatory = await backend.pause(.me, fails: true) + store.invalidatePresentation() + XCTAssertNil(store.snapshot) + let reconcile = Task { await store.reload() } + await mandatory.entered.wait() + await mandatory.resume.open() + await reconcile.value + XCTAssertNil(store.snapshot) + XCTAssertNil(store.currentCard(id: "old", context: context)) + store.stop() + _ = try await client.stop() + } + + func testMeObservationInvalidatesPausedReadAndGapReconcilesCurrentValues() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let store = TeraMeStore(runtimeClient: client) + store.configure(context: context) + await store.start() + XCTAssertNotNil(store.snapshot, "Awaited startup includes the mandatory initial reconciliation") + await TeraScopeFixtures.eventually { store.state == .loaded } + let old = await backend.pause(.me) + await backend.emit(.today, context: context) + await old.entered.wait() + let current = await backend.pause(.me) + await backend.setMeCards([TeraScopeFixtures.card("current")]) + await backend.emit(.initial, delivery: .resnapshotRequired, context: context) + XCTAssertNil(store.snapshot) + await old.resume.open() + await current.entered.wait() + XCTAssertNil(store.snapshot) + await current.resume.open() + await TeraScopeFixtures.eventually { store.snapshot?.cards.first?.id == "current" } + XCTAssertNil(store.currentCard(id: "old", context: context)) + store.stop() + _ = try await client.stop() + } + + func testFullContextChangeAndStopFenceSupportingReads() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let first = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let second = TeraLocalNetwork( + schemaVersion: first.schemaVersion, id: first.id, label: first.label, + relayURLs: first.relayURLs, locality: "Another locality", + followedAuthors: first.followedAuthors, generation: first.generation + ) + let search = TeraSearchStore(runtimeClient: client) + let me = TeraMeStore(runtimeClient: client) + search.configure(context: first) + search.updateQuery("old") + me.configure(context: first) + let searchPause = await backend.pause(.search) + let mePause = await backend.pause(.me) + let searchTask = Task { await search.search() } + let meTask = Task { await me.reload() } + await searchPause.entered.wait() + await mePause.entered.wait() + search.configure(context: second) + me.configure(context: second) + await searchPause.resume.open() + await mePause.resume.open() + await searchTask.value + await meTask.value + XCTAssertTrue(search.results.isEmpty) + XCTAssertNil(me.snapshot) + search.updateQuery("new") + await search.search() + await me.reload() + XCTAssertNil(search.currentResult(id: "new", type: .card, context: first)) + XCTAssertNotNil(search.currentResult(id: "new", type: .card, context: second)) + XCTAssertNil(me.currentCard(id: "old", context: first)) + XCTAssertNotNil(me.currentCard(id: "old", context: second)) + search.stop() + me.stop() + XCTAssertTrue(search.results.isEmpty) + XCTAssertNil(me.snapshot) + _ = try await client.stop() + } + + func testMeMandatoryObserverFailureRemovesCurrentDetail() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let store = TeraMeStore(runtimeClient: client) + store.configure(context: context) + await store.start() + await TeraScopeFixtures.eventually { store.state == .loaded } + XCTAssertNotNil(store.currentCard(id: "old", context: context)) + let failed = await backend.pause(.me, fails: true) + await backend.emit(.today, context: context) + await failed.entered.wait() + XCTAssertNil(store.currentCard(id: "old", context: context)) + await failed.resume.open() + await TeraScopeFixtures.eventually { + if case .failed = store.state { + true + } else { + false + } + } + XCTAssertNil(store.snapshot) + store.stop() + _ = try await client.stop() + } + + func testOrdinaryMediaProgressPreservesCurrentSupportingContent() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let search = TeraSearchStore(runtimeClient: client) + let me = TeraMeStore(runtimeClient: client) + search.configure(context: context) + search.updateQuery("scope") + search.start() + me.configure(context: context) + await me.start() + await TeraScopeFixtures.eventually { search.state == .loaded && me.state == .loaded } + let results = search.results + let snapshot = me.snapshot + let before = await backend.counts + for _ in 1 ... 8 { + await backend.emit(.media, context: context) + try await Task.sleep(for: .milliseconds(10)) + } + let after = await backend.counts + XCTAssertEqual(after[.search], before[.search]) + XCTAssertEqual(after[.me], before[.me]) + XCTAssertEqual(search.results, results) + XCTAssertEqual(me.snapshot, snapshot) + search.stop() + me.stop() + _ = try await client.stop() + } + + private func result(_ id: String) -> TeraSearchResult { + TeraSearchResult(type: .card, id: id, card: TeraScopeFixtures.card(id), profile: nil) + } + + private func profile(_ reference: TeraMediaReference) -> TeraProfileSummary { + TeraProfileSummary( + authorPublicKey: String(repeating: "a", count: 64), name: "Farm", displayName: nil, + about: nil, picture: reference, banner: nil, nip05: nil, website: nil, lightningAddress: nil + ) + } +} + +extension TeraSupportingFreshnessTests { + func testMeTypedCurrentScopeRefusalClearsCacheWithoutNotification() async throws { + let codes = [ + "today_invalid_request", "today_refresh_required", "today_projection_rebuilding", + "today_cursor_invalid", "today_reader_unsupported", "today_runtime_unavailable", "today_state_failed", + "storage_space_insufficient", + ] + for code in codes { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let stores = TeraProductStores(runtimeClient: client) + stores.configure(snapshot: TeraScopeFixtures.snapshot()) + let store = stores.me + let reference = TeraScopeFixtures.reference() + await backend.setMeProfile(profile(reference)) + await store.reload() + XCTAssertNotNil(store.currentCard(id: "old", context: context), code) + XCTAssertNotNil(store.currentProfile(context: context), code) + stores.media.load(media: reference, context: context) + await TeraScopeFixtures.eventually { stores.media.image(for: reference, context: context) != nil } + XCTAssertGreaterThan(stores.media.cachedByteCount, 0, code) + let pause = await backend.pause(.me, failure: .local( + operation: "today", code: code, safeMessage: "The current content could not be confirmed." + )) + let reload = Task { await store.reload() } + await pause.entered.wait() + await pause.resume.open() + await reload.value + XCTAssertNil(store.snapshot, code) + XCTAssertNil(store.currentCard(id: "old", context: context), code) + XCTAssertNil(store.currentProfile(context: context), code) + XCTAssertEqual(stores.media.state(for: reference, context: context), .unavailable, code) + XCTAssertNil(stores.media.image(for: reference, context: context), code) + XCTAssertEqual(stores.media.cachedByteCount, 0, code) + if case .failed = store.state {} else { + XCTFail("Expected a typed read refusal for \(code)") + } + stores.stop() + _ = try await client.stop() + } + } +} + +extension TeraSupportingFreshnessTests { + func testSearchQueryChangeAndStopPreserveMeSharedMediaUntilLastCurrentReferenceLeaves() async throws { + let backend = try TeraScopeBackend() + let client = try await TeraScopeFixtures.client(backend) + let context = TeraLocalNetwork.defaultContext(snapshot: TeraScopeFixtures.snapshot()) + let stores = TeraProductStores(runtimeClient: client) + stores.configure(snapshot: TeraScopeFixtures.snapshot()) + let reference = TeraScopeFixtures.reference() + let shared = profile(reference) + let result = TeraSearchResult(type: .profile, id: shared.authorPublicKey, card: nil, profile: shared) + await backend.setMeProfile(shared) + await stores.me.reload() + await backend.setSearchResults([result]) + stores.search.updateQuery("farm") + await stores.search.search() + XCTAssertNotNil(stores.me.currentProfile(context: context)) + XCTAssertNotNil(stores.search.currentResult(id: result.id, type: .profile, context: context)) + stores.media.load(media: reference, context: context) + await TeraScopeFixtures.eventually { stores.media.image(for: reference, context: context) != nil } + let expected = try TeraScopeFixtures.artifact("a") + XCTAssertEqual(stores.media.state(for: reference, context: context), .ready(expected)) + stores.search.updateQuery("different query") + XCTAssertTrue(stores.search.results.isEmpty) + XCTAssertNil(stores.search.currentResult(id: result.id, type: .profile, context: context)) + XCTAssertEqual(stores.me.currentProfile(context: context), shared) + XCTAssertNotNil(stores.media.image(for: reference, context: context)) + XCTAssertEqual(stores.media.state(for: reference, context: context), .ready(expected)) + stores.media.load(media: reference, context: context) + stores.media.retry(media: reference, context: context) + await TeraScopeFixtures.eventually { stores.media.state(for: reference, context: context) == .ready(expected) } + let calls = await backend.counts[.media] + XCTAssertEqual(calls, 2, "Retry remains usable for the unchanged current Me picture") + await stores.search.search() + stores.search.stop() + XCTAssertEqual(stores.me.currentProfile(context: context), shared) + XCTAssertNotNil(stores.media.image(for: reference, context: context)) + stores.me.invalidatePresentation() + XCTAssertNil(stores.me.currentProfile(context: context)) + XCTAssertNil(stores.media.image(for: reference, context: context)) + XCTAssertEqual(stores.media.cachedByteCount, 0) + stores.media.load(media: reference, context: context) + stores.media.retry(media: reference, context: context) + let finalCalls = await backend.counts[.media] + XCTAssertEqual(finalCalls, 2, "Last-reference invalidation must still deny load and retry") + stores.stop() + _ = try await client.stop() + } +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today.rs b/core/crates/tera_core/src/runtime/product_surface/today.rs @@ -103,6 +103,8 @@ mod paging; mod paging_scope; #[path = "today_projection_collection.rs"] mod projection_collection; +#[path = "today_read_scope.rs"] +mod read_scope; #[path = "today_refresh.rs"] mod refresh; #[path = "today_row_state.rs"] @@ -159,6 +161,10 @@ mod keyset_tests; #[path = "today_scope_tests.rs"] mod scope_tests; +#[cfg(test)] +#[path = "today_read_scope_tests.rs"] +mod read_scope_tests; + #[cfg(all(test, feature = "mobile-social"))] #[path = "today_sync_tests.rs"] mod sync_tests; @@ -381,14 +387,7 @@ impl TeraRuntime { { return Err(TodayError::InvalidRequest); } - let storage = self - .client - .storage() - .map_err(|_| TodayError::RuntimeUnavailable)?; - let state = self - .calendar_state_for_read(storage, context, as_of) - .await? - .ok_or(TodayError::ProjectionMissing)?; + let (_projection, state) = self.calendar_state_for_read(context, as_of, false).await?; let cards = ranked_cards(&state, context, &calendar)?; let mut results = Vec::new(); for card in cards { @@ -462,14 +461,7 @@ impl TeraRuntime { { return Err(TodayError::InvalidRequest); } - let storage = self - .client - .storage() - .map_err(|_| TodayError::RuntimeUnavailable)?; - let state = self - .calendar_state_for_read(storage, context, as_of) - .await? - .ok_or(TodayError::ProjectionMissing)?; + let (_projection, state) = self.calendar_state_for_read(context, as_of, false).await?; let cards = ranked_cards(&state, context, &calendar)? .into_iter() .filter(|card| card.card.author_pubkey == public_key) @@ -511,6 +503,7 @@ impl TeraRuntime { if changed { state = trial; persist_media_state(self, storage, context, generation, &mut state).await?; + media_visibility::confirm_state(self, context, &state).await?; } Ok(changed) } @@ -535,6 +528,7 @@ impl TeraRuntime { })?; if changed { persist_media_state(self, storage, context, generation, &mut state).await?; + media_visibility::confirm_state(self, context, &state).await?; } Ok(changed) } @@ -573,6 +567,7 @@ impl TeraRuntime { } state = trial; persist_media_state(self, storage, context, generation, &mut state).await?; + media_visibility::confirm_state(self, context, &state).await?; Ok(evicted) } @@ -987,17 +982,6 @@ fn refresh_thread_profiles(state: &mut TodayProjectionState) { } } -// A bounded owner query authenticates the source generation without invoking -// full visibility/status reduction. The backend may read one look-ahead row. -async fn current_store_generation(storage: &dyn EventStore) -> Result<[u8; 32], TodayError> { - Ok( - *EventStore::query_raw(storage, EventQuery::all(EventQueryBounds::first(1)?)) - .await? - .generation() - .as_bytes(), - ) -} - #[cfg(test)] async fn query_all_visible( storage: &dyn radroots_storage::Storage, @@ -1201,12 +1185,6 @@ fn locality_evidence(selected: Option<&str>, locality: &[LocalityTag]) -> Locali } } -fn calendar_projection_ready(state: &TodayProjectionState) -> bool { - state.cards.iter().all(|entry| { - entry.card.card_type != TodayCardType::Event || entry.card.calendar_timing.is_some() - }) -} - fn ranked_cards( state: &TodayProjectionState, context: &LocalNetwork, diff --git a/core/crates/tera_core/src/runtime/product_surface/today_counted_storage_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_counted_storage_tests.rs @@ -61,8 +61,11 @@ impl CountedStorage { impl EventStore for CountedStorage { fn source_token(&self) -> BoxFuture<'_, Result<EventSourceToken, Error>> { Box::pin(async move { + self.counts.faults.boundary("read_source", false).await?; self.counts.add("event.source_token", 1); - EventStore::source_token(self.storage()).await + let result = EventStore::source_token(self.storage()).await; + self.counts.faults.boundary("read_source", true).await?; + result }) } fn maintain_visibility( @@ -80,8 +83,10 @@ impl EventStore for CountedStorage { source: EventSourceToken, ) -> BoxFuture<'_, Result<EventPage<StoredVisibleEvent>, Error>> { Box::pin(async move { + self.counts.faults.boundary("read_visible", false).await?; self.counts.add("event.query_visible_at", 1); let result = EventStore::query_visible_at(self.storage(), query, source).await; + self.counts.faults.boundary("read_visible", true).await?; if let Ok(page) = &result { self.counts.add("event.rows", page.items().len() as u64); self.counts @@ -272,6 +277,11 @@ impl ProjectionStore for CountedStorage { active: ProjectionGeneration, ) -> BoxFuture<'_, Result<document_query::ProjectionDocumentPage, Error>> { Box::pin(async move { + self.counts.faults.boundary("read_query", false).await?; + if query.limit() == 64 { + self.counts.faults.boundary("read_payload", false).await?; + self.counts.add("projection.payload_queries", 1); + } self.counts.add("projection.query_documents_at", 1); let limit = query.limit(); let result = ProjectionStore::query_projection_documents_at( @@ -284,6 +294,10 @@ impl ProjectionStore for CountedStorage { if let Ok(page) = &result { self.counts.selected(limit, page); } + if limit == 64 { + self.counts.faults.boundary("read_payload", true).await?; + } + self.counts.faults.boundary("read_query", true).await?; result }) } @@ -409,14 +423,17 @@ impl ProjectionStore for CountedStorage { document: ProjectionDocument, ) -> BoxFuture<'_, Result<(), Error>> { Box::pin(async move { + self.counts.faults.boundary("document_write", false).await?; self.counts.add("projection.put_projection_document", 1); - ProjectionStore::put_projection_document( + let result = ProjectionStore::put_projection_document( self.storage(), projection_id, generation, document, ) - .await + .await; + self.counts.faults.boundary("document_write", true).await?; + result }) } fn projection_document( diff --git a/core/crates/tera_core/src/runtime/product_surface/today_media_read_scope_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_media_read_scope_tests.rs @@ -0,0 +1,80 @@ +//! Actual post-file and acknowledged local-write authorization boundaries. +use super::super::super::performance_tests::counted_storage::{CountedStorage, QueryCounts}; +use super::*; + +#[tokio::test] +async fn cached_media_after_file_read_and_acknowledged_touch_refuses_source_change() { + for boundary in ["after_file", "after_touch"] { + let f = fixture().await; + let (started, entered) = oneshot::channel(); + let (resume, wait) = oneshot::channel(); + let server = tokio::spawn(serve(f.listener, f.bytes, started, wait)); + resume.send(()).unwrap(); + let artifact = retrieve(&f.runtime, &f.selected, f.fingerprint) + .await + .unwrap(); + entered.await.unwrap(); + server.await.unwrap(); + let mut runtime = Arc::try_unwrap(f.runtime) + .unwrap_or_else(|_| panic!("fixture has no outstanding owner")); + let counts = Arc::new(QueryCounts::default()); + // This read-only cached-artifact command needs no network SDK. Preserve + // the actual owner/runtime and file cache, wrapping its real storage. + runtime.client = radroots_sdk::ClientBuilder::new() + .storage(Arc::new(CountedStorage { + client: runtime.client.clone(), + counts: counts.clone(), + })) + .build() + .unwrap(); + let pause = if boundary == "after_file" { + counts.faults.pause("read_query", 4, true) + } else { + counts.faults.pause("document_write", 1, true) + }; + let runtime = Arc::new(runtime); + let reader = { + let runtime = runtime.clone(); + let selected = f.selected.clone(); + let id = artifact.artifact_id(); + tokio::spawn(async move { + runtime + .phase1_verified_media_artifact(&selected, id, (NOW + 100) * 1_000) + .await + }) + }; + tokio::time::timeout(Duration::from_secs(2), pause.entered.notified()) + .await + .unwrap(); + let receipt = EventStore::admit( + runtime.client.storage().unwrap(), + visible_admission( + signed(5, vec![vec!["e", &f.source]], "", NOW + 4), + (NOW + 4) * 1_000, + ), + ) + .await + .unwrap(); + pause.resume.notify_one(); + assert!( + reader.await.unwrap().is_err(), + "{boundary} must not publish superseded render authority" + ); + assert!( + artifact.local_path().exists(), + "An authorization refusal does not delete shared custody bytes" + ); + let retained = EventStore::query_raw( + runtime.client.storage().unwrap(), + EventQuery::for_ids( + EventQueryBounds::first(1).unwrap(), + vec![*receipt.event_id()], + ) + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(retained.items()[0].position(), receipt.position()); + runtime.shutdown().await.unwrap(); + } +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_media_retrieval.rs b/core/crates/tera_core/src/runtime/product_surface/today_media_retrieval.rs @@ -29,9 +29,13 @@ impl TeraRuntime { match super::super::media::verified_artifact(directory, &receipt).await { Ok(artifact) => { state = media_visibility::current_state(self, context).await?; + if verified_receipt(&state, artifact_id).as_ref() != Some(&receipt) { + return Err(TodayError::InvalidRequest); + } if state.media_cache.touch(artifact_id, observed_at_unix_ms)? { persist_media_state(self, storage, context, generation, &mut state).await?; } + media_visibility::confirm_state(self, context, &state).await?; Ok(Some(artifact)) } Err(error) => { @@ -189,7 +193,7 @@ impl TeraRuntime { context, reference_fingerprint, operation_id, - receipt, + receipt.clone(), policy, sdk_receipt.verified_at_unix_ms(), ) @@ -211,6 +215,12 @@ impl TeraRuntime { }; let _projection = self.today_projection_lock.lock().await; media_collection::collect(self, directory, &evicted, &_guard, &_projection).await?; + let state = media_visibility::current_state(self, context).await?; + if verified_receipt(&state, artifact.artifact_id()).as_ref() != Some(&receipt) + || structural_reference(&state, reference_fingerprint)? != structural + { + return Err(TodayError::InvalidRequest); + } Ok(artifact) } } @@ -221,7 +231,16 @@ async fn load_structural_reference( context: &LocalNetwork, reference_fingerprint: [u8; 32], ) -> Result<Phase1StructuralMediaReference, TodayError> { + let _projection = runtime.today_projection_lock.lock().await; let state = media_visibility::current_state(runtime, context).await?; + structural_reference(&state, reference_fingerprint) +} + +#[cfg(feature = "mobile-social")] +fn structural_reference( + state: &TodayProjectionState, + reference_fingerprint: [u8; 32], +) -> Result<Phase1StructuralMediaReference, TodayError> { state .cards .iter() diff --git a/core/crates/tera_core/src/runtime/product_surface/today_media_visibility.rs b/core/crates/tera_core/src/runtime/product_surface/today_media_visibility.rs @@ -4,30 +4,49 @@ use super::*; #[path = "today_media_visibility_tests.rs"] mod tests; -/// A cached reference is not authority after the selected query or visible -/// event set changes. The owner re-evaluates replacement/deletion semantics; -/// raw row counts and the store's identity generation cannot establish this. +/// Media has no calendar selection. It shares the same complete source, +/// policy, full context, owner, promoted generation and local-evidence scope. pub(super) async fn current_state( runtime: &TeraRuntime, context: &LocalNetwork, ) -> Result<TodayProjectionState, TodayError> { - let scope = paging_scope::query_scope(context, runtime.store_public_key)?; + let mut budget = page_budget::Budget::default(); + let scope = current_scope(runtime, context, &mut budget).await?; + let mut finish = budget.reserve_scope()?; + let state = scope.load_state(runtime, context).await?; + scope.check_current(runtime, context, &mut finish).await?; + Ok(state) +} + +/// After an acknowledged own receipt/LRU write, compare its resulting revision +/// rather than accidentally rejecting the write's intentional local change. +pub(super) async fn confirm_state( + runtime: &TeraRuntime, + context: &LocalNetwork, + state: &TodayProjectionState, +) -> Result<(), TodayError> { + let mut budget = page_budget::Budget::default(); + let scope = current_scope(runtime, context, &mut budget).await?; + scope.check_state(state)?; + let mut finish = budget.reserve_scope()?; + scope.check_current(runtime, context, &mut finish).await +} + +async fn current_scope( + runtime: &TeraRuntime, + context: &LocalNetwork, + budget: &mut page_budget::Budget, +) -> Result<read_scope::Scope, TodayError> { + if let Some(scope) = read_scope::Scope::load(runtime, context, budget).await? { + return Ok(scope); + } let storage = runtime .client .storage() .map_err(|_| TodayError::RuntimeUnavailable)?; - let state = match load_state(storage, context, projection_generation()?).await? { - Some(state) => state, - None if sidecar::load(storage, context).await?.is_some() => { - return Err(TodayError::InvalidRequest); - } - None => return Err(TodayError::ProjectionMissing), - }; - if state.query_scope != Some(scope) { - return Err(TodayError::InvalidRequest); - } - if state.visibility_digest != Some(runtime.projection_visibility_digest().await?) { - return Err(TodayError::InvalidRequest); + if sidecar::load(storage, context).await?.is_some() { + Err(TodayError::InvalidRequest) + } else { + Err(TodayError::ProjectionMissing) } - Ok(state) } diff --git a/core/crates/tera_core/src/runtime/product_surface/today_media_visibility_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_media_visibility_tests.rs @@ -18,6 +18,9 @@ use tokio::{ const NOW: u64 = 2_000_000_000; +#[path = "today_media_read_scope_tests.rs"] +mod read_scope; + #[tokio::test] async fn author_block_prevents_hidden_fetch_and_late_network_admission() { use crate::runtime::visibility::AuthorVisibility; diff --git a/core/crates/tera_core/src/runtime/product_surface/today_page_scope.rs b/core/crates/tera_core/src/runtime/product_surface/today_page_scope.rs @@ -1,16 +1,19 @@ -//! Read only a small promoted header and bounded sparse local evidence. +//! Frozen calendar cursors wrap the shared complete current-read identity. use super::*; -use radroots_storage::event::EventSourceToken; -use radroots_storage::projection::ProjectionHealth; pub(super) struct Scope { + read: read_scope::Scope, pub(super) cursor: CursorScope, - pub(super) source: EventSourceToken, - pub(super) local: sidecar::LocalState, - pub(super) header: build::progress::BuildProgress, pub(super) fingerprint: [u8; 32], } +impl std::ops::Deref for Scope { + type Target = read_scope::Scope; + fn deref(&self) -> &Self::Target { + &self.read + } +} + impl Scope { pub(super) async fn load( runtime: &TeraRuntime, @@ -18,126 +21,32 @@ impl Scope { calendar: super::super::ViewerCalendarContext, budget: &mut page_budget::Budget, ) -> Result<Option<Self>, TodayError> { - let storage = runtime - .client - .storage() - .map_err(|_| TodayError::RuntimeUnavailable)?; - if !calendar_ready(storage, budget).await? { - return Ok(None); - } - budget.charge(512, 1)?; - let query_scope = paging_scope::query_scope(context, runtime.store_public_key)?; - let source = EventStore::source_token(storage).await?; - if !runtime.author_visibility_fence.can_collect() { - return Err(TodayError::RuntimeUnavailable); - } - let (id, generation) = crate::runtime::visibility::identity()?; - let policy_document = budget - .document( - storage, - id, - generation, - crate::runtime::visibility::KEY.into(), - None, - ) - .await?; - let policy = - crate::runtime::visibility::decode_policy(policy_document.as_ref())?.cache_digest()?; - if !runtime.author_visibility_fence.can_collect() { - return Err(TodayError::RuntimeUnavailable); - } - let key = projection_document_key(context); - let Some(document) = budget - .document( - storage, - ProjectionId::parse(sidecar::ID)?, - projection_generation()?, - key.clone(), - None, - ) - .await? - else { - return Ok(None); - }; - let local: sidecar::LocalState = decode(document.value())?; - local.validate(&key)?; - if local.source != source || local.query_scope != query_scope { - return Ok(None); - } - let id = ProjectionId::parse(build::progress::ID)?; - let status = ProjectionStore::status(storage, id.clone()).await?; - if status.as_ref().is_none_or(|status| { - status.generation() != local.generation || status.health() != ProjectionHealth::Ready - }) { + let Some(read) = read_scope::Scope::load(runtime, context, budget).await? else { return Ok(None); - } - let Some(header) = budget - .document( - storage, - id, - local.generation, - build::progress::HEADER.into(), - Some(source), - ) - .await? - else { - return Err(TodayError::CorruptProjection); }; - let header: build::progress::BuildProgress = decode(header.value())?; - if !header.complete - || header.source != source - || header.generation != local.generation - || header.query_scope != query_scope - { - return Err(TodayError::CorruptProjection); - } - if header.index_schema != page_index::SCHEMA || header.policy != policy { - return Ok(None); - } - if header.index_rows < header.cards - || header.index_rows - > header - .cards - .checked_mul(4) - .ok_or(TodayError::CorruptProjection)? - { - return Err(TodayError::CorruptProjection); - } - if status - .and_then(|status| status.checkpoint().cloned()) - .is_none_or(|checkpoint| { - checkpoint.projected_rows() != header.document_rows().unwrap_or(u64::MAX) - }) - { - return Err(TodayError::CorruptProjection); - } - let local_digest: [u8; 32] = Sha256::digest(document.value()).into(); - let revision = - u64::from_be_bytes(local_digest[..8].try_into().expect("digest prefix")).max(1); let cursor = CursorScope::new( context.id.clone().into(), context.generation, calendar.as_of(), - *source.generation().as_bytes(), - row_state::content_generation(local.generation, revision)?, - query_scope, + *read.source.generation().as_bytes(), + read.projection_generation, + read.local.query_scope, calendar, )?; + // Retain the exact v4 fingerprint tuple and cursor encoding. let fingerprint = Sha256::digest(encode(&( "tera.today-keyset-scope.v4", - source, - local.generation, - query_scope, - policy, - local_digest, + read.source, + read.local.generation, + read.local.query_scope, + read.header.policy, + read.local_digest, &cursor.calendar, ))?) .into(); Ok(Some(Self { + read, cursor, - source, - local, - header, fingerprint, })) } @@ -172,24 +81,3 @@ impl Scope { } } } - -async fn calendar_ready( - storage: &dyn radroots_storage::Storage, - budget: &mut page_budget::Budget, -) -> Result<bool, TodayError> { - let Some(status) = ProjectionStore::status(storage, projection_id()?).await? else { - return Ok(true); - }; - if status.generation() == calendar_migration::legacy_generation()? { - return Ok(false); - } - if status.generation() != projection_generation()? { - return Err(TodayError::UnsupportedProjectionVersion); - } - if status.health() == ProjectionHealth::Ready { - return Ok(true); - } - let (id, generation, key) = coordination_retirement::document_identity()?; - let document = budget.document(storage, id, generation, key, None).await?; - coordination_retirement::retired_document(storage, &status, document.as_ref()).await -} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_paging.rs b/core/crates/tera_core/src/runtime/product_surface/today_paging.rs @@ -58,7 +58,8 @@ impl TeraRuntime { calendar.as_of(), TodayProjectionUpdate::Incremental, ) - .await?; + .await + .map_err(read_scope::current_repair_error)?; guard = self.today_projection_lock.lock().await; scope = page_scope::Scope::load(self, context, calendar, &mut budget).await?; } @@ -200,7 +201,7 @@ impl TeraRuntime { item.thread_next_cursor = thread_cursors.remove(&item.card.card_id); } paging_scope::validate_order(&items)?; - check_current(self, context, &scope, &mut finish).await?; + scope.check_current(self, context, &mut finish).await?; drop(guard); Ok(TodayPage { projection_generation: scope.cursor.projection_generation, @@ -255,7 +256,7 @@ impl TeraRuntime { state.thread = items; scope.local.apply(&mut state); validate_media_state(&state)?; - check_current(self, context, &scope, &mut finish).await?; + scope.check_current(self, context, &mut finish).await?; Ok(super::super::TodayThreadPage { card_id: card.card_id, items: state.thread, @@ -340,18 +341,3 @@ async fn validate_position( } Ok(()) } - -async fn check_current( - runtime: &TeraRuntime, - context: &LocalNetwork, - scope: &page_scope::Scope, - budget: &mut page_budget::Budget, -) -> Result<(), TodayError> { - let current = page_scope::Scope::load(runtime, context, scope.cursor.calendar.clone(), budget) - .await? - .ok_or(CursorError::Stale)?; - if current.fingerprint != scope.fingerprint { - return Err(CursorError::Stale.into()); - } - Ok(()) -} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_read_scope.rs b/core/crates/tera_core/src/runtime/product_surface/today_read_scope.rs @@ -0,0 +1,259 @@ +//! One complete bounded read identity for every current product surface. +use super::*; +use radroots_storage::event::EventSourceToken; +use radroots_storage::projection::ProjectionHealth; + +pub(super) struct Scope { + pub(super) projection_generation: u64, + pub(super) local_digest: [u8; 32], + pub(super) source: EventSourceToken, + pub(super) local: sidecar::LocalState, + pub(super) header: build::progress::BuildProgress, + pub(super) fingerprint: [u8; 32], +} + +impl Scope { + pub(super) async fn load( + runtime: &TeraRuntime, + context: &LocalNetwork, + budget: &mut page_budget::Budget, + ) -> Result<Option<Self>, TodayError> { + Self::load_with_context(runtime, context, budget, false).await + } + + pub(super) async fn load_matching_context( + runtime: &TeraRuntime, + context: &LocalNetwork, + budget: &mut page_budget::Budget, + ) -> Result<Option<Self>, TodayError> { + Self::load_with_context(runtime, context, budget, true).await + } + + async fn load_with_context( + runtime: &TeraRuntime, + context: &LocalNetwork, + budget: &mut page_budget::Budget, + require_matching_context: bool, + ) -> Result<Option<Self>, TodayError> { + let storage = runtime + .client + .storage() + .map_err(|_| TodayError::RuntimeUnavailable)?; + if !calendar_ready(storage, budget).await? { + return Ok(None); + } + budget.charge(512, 1)?; + let query_scope = paging_scope::query_scope(context, runtime.store_public_key)?; + let source = EventStore::source_token(storage).await?; + if !runtime.author_visibility_fence.can_collect() { + return Err(TodayError::RuntimeUnavailable); + } + let (id, generation) = crate::runtime::visibility::identity()?; + let policy_document = budget + .document( + storage, + id, + generation, + crate::runtime::visibility::KEY.into(), + None, + ) + .await?; + let policy = + crate::runtime::visibility::decode_policy(policy_document.as_ref())?.cache_digest()?; + if !runtime.author_visibility_fence.can_collect() { + return Err(TodayError::RuntimeUnavailable); + } + let key = projection_document_key(context); + let Some(document) = budget + .document( + storage, + ProjectionId::parse(sidecar::ID)?, + projection_generation()?, + key.clone(), + None, + ) + .await? + else { + return Ok(None); + }; + let local: sidecar::LocalState = decode(document.value())?; + local.validate(&key)?; + if require_matching_context && local.query_scope != query_scope { + return Err(CursorError::Stale.into()); + } + if local.source != source || local.query_scope != query_scope { + return Ok(None); + } + let id = ProjectionId::parse(build::progress::ID)?; + let status = ProjectionStore::status(storage, id.clone()).await?; + if status.as_ref().is_none_or(|status| { + status.generation() != local.generation || status.health() != ProjectionHealth::Ready + }) { + return Ok(None); + } + let Some(header) = budget + .document( + storage, + id, + local.generation, + build::progress::HEADER.into(), + Some(source), + ) + .await? + else { + return Err(TodayError::CorruptProjection); + }; + let header: build::progress::BuildProgress = decode(header.value())?; + if !header.complete + || header.source != source + || header.generation != local.generation + || header.query_scope != query_scope + { + return Err(TodayError::CorruptProjection); + } + if header.index_schema != page_index::SCHEMA || header.policy != policy { + return Ok(None); + } + if header.index_rows < header.cards + || header.index_rows + > header + .cards + .checked_mul(4) + .ok_or(TodayError::CorruptProjection)? + { + return Err(TodayError::CorruptProjection); + } + if status + .and_then(|status| status.checkpoint().cloned()) + .is_none_or(|checkpoint| { + checkpoint.projected_rows() != header.document_rows().unwrap_or(u64::MAX) + }) + { + return Err(TodayError::CorruptProjection); + } + let local_digest: [u8; 32] = Sha256::digest(document.value()).into(); + let revision = + u64::from_be_bytes(local_digest[..8].try_into().expect("digest prefix")).max(1); + let projection_generation = row_state::content_generation(local.generation, revision)?; + let fingerprint = Sha256::digest(encode(&( + "tera.today-read-scope.v1", + source, + local.generation, + query_scope, + policy, + local_digest, + ))?) + .into(); + budget.charge(512, 1)?; + if EventStore::source_token(storage).await? != source { + return Err(CursorError::Stale.into()); + } + Ok(Some(Self { + projection_generation, + local_digest, + source, + local, + header, + fingerprint, + })) + } + + /// Whole-view supporting hydration remains until the separately ordered + /// selected-query checkpoint. It never changes canonical source authority. + pub(super) async fn load_state( + &self, + runtime: &TeraRuntime, + context: &LocalNetwork, + ) -> Result<TodayProjectionState, TodayError> { + let storage = runtime + .client + .storage() + .map_err(|_| TodayError::RuntimeUnavailable)?; + let state = row_state::load(storage, context, self.local.clone()) + .await + .map_err(current_read_error)? + .ok_or(CursorError::Stale)?; + self.check_state(&state)?; + Ok(state) + } + + pub(super) fn check_state(&self, state: &TodayProjectionState) -> Result<(), TodayError> { + if state.source_token != Some(self.source) + || state.store_generation != *self.source.generation().as_bytes() + || state.row_generation != Some(self.local.generation) + || state.query_scope != Some(self.local.query_scope) + || state.author_visibility_digest != self.header.policy + || state.visibility_digest + != Some(crate::runtime::visibility::source_visibility_digest( + self.source, + self.header.policy, + )?) + || state.content_generation != self.projection_generation + { + return Err(CursorError::Stale.into()); + } + Ok(()) + } + + pub(super) async fn check_current( + &self, + runtime: &TeraRuntime, + context: &LocalNetwork, + budget: &mut page_budget::Budget, + ) -> Result<(), TodayError> { + let current = Self::load(runtime, context, budget) + .await? + .ok_or(CursorError::Stale)?; + if current.fingerprint != self.fingerprint { + return Err(CursorError::Stale.into()); + } + Ok(()) + } +} + +async fn calendar_ready( + storage: &dyn radroots_storage::Storage, + budget: &mut page_budget::Budget, +) -> Result<bool, TodayError> { + let Some(status) = ProjectionStore::status(storage, projection_id()?).await? else { + return Ok(true); + }; + if status.generation() == calendar_migration::legacy_generation()? { + return Ok(false); + } + if status.generation() != projection_generation()? { + return Err(TodayError::UnsupportedProjectionVersion); + } + if status.health() == ProjectionHealth::Ready { + return Ok(true); + } + let (id, generation, key) = coordination_retirement::document_identity()?; + let document = budget.document(storage, id, generation, key, None).await?; + coordination_retirement::retired_document(storage, &status, document.as_ref()).await +} + +/// A proven conditional-read conflict invalidates retained current content. +/// Ordinary unavailable storage still permits the host's voluntary cache policy. +pub(super) fn current_read_error(error: TodayError) -> TodayError { + match error { + TodayError::Storage( + radroots_storage::Error::SourceEpochChanged + | radroots_storage::Error::ProjectionRevisionConflict, + ) => CursorError::Stale.into(), + error => error, + } +} + +/// Called only after the reader has proved that its prior scope is unavailable. +/// Capacity keeps its existing recovery report; other failed storage repair +/// cannot authorize the already superseded presentation as voluntary cache. +pub(super) fn current_repair_error(error: TodayError) -> TodayError { + match current_read_error(error) { + error @ TodayError::Storage( + radroots_storage::Error::SpaceInsufficient + | radroots_storage::Error::SourceGenerationChanged, + ) => error, + TodayError::Storage(_) => TodayError::ProjectionMissing, + error => error, + } +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_read_scope_conflict_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_read_scope_conflict_tests.rs @@ -0,0 +1,192 @@ +//! Actual SQLite payload/repair conflicts retain their current-read meaning. +use super::*; +use radroots_storage::projection::{InvalidationReason, ProjectionInvalidation}; + +async fn seeded(runtime: &TeraRuntime, selected: &LocalNetwork) -> Vec<String> { + // More than64 projected rows makes the second supporting payload page real. + for index in 0..33 { + EventStore::admit( + runtime.client.storage().unwrap(), + visible_admission( + signed(1, vec![], &format!("scope item {index}"), NOW), + NOW * 1_000, + ), + ) + .await + .unwrap(); + } + runtime + .phase1_refresh_today(selected, NOW, TodayProjectionUpdate::Rebuild) + .await + .unwrap(); + runtime + .phase1_today_page(selected, TodayPageRequest::first(100, NOW, "UTC")) + .await + .unwrap() + .items + .into_iter() + .map(|card| card.card.card_id.to_hex()) + .collect() +} + +async fn conflict(runtime: &TeraRuntime, projection: bool) { + let storage = runtime.client.storage().unwrap(); + if projection { + let id = ProjectionId::parse(build::progress::ID).unwrap(); + let generation = ProjectionStore::status(storage, id.clone()) + .await + .unwrap() + .unwrap() + .generation(); + ProjectionStore::invalidate( + storage, + ProjectionInvalidation::new( + id, + generation, + ProjectionGeneration::new([19; 32]).unwrap(), + InvalidationReason::OperatorRequested, + NOW * 1_000 + 1, + ) + .unwrap(), + ) + .await + .unwrap(); + } else { + EventStore::admit( + storage, + visible_admission(signed(1, vec![], "scope new-current", NOW + 1), NOW * 1_000), + ) + .await + .unwrap(); + } +} + +#[tokio::test] +async fn sqlite_payload_pages_refuse_source_and_projection_conflicts_but_keep_offline_errors() { + for operation in 1..=3 { + for ordinal in [1, 2] { + for after in [false, true] { + for projection in [false, true] { + let root = tempfile::tempdir().unwrap(); + let (runtime, counts) = instrumented(&root).await; + let selected = context(None, 1); + let ids = seeded(&runtime, &selected).await; + counts.take(); + let pause = counts.faults.pause("read_payload", ordinal, after); + let runtime = Arc::new(runtime); + let reader = { + let runtime = runtime.clone(); + let selected = selected.clone(); + tokio::spawn( + async move { read_ids(&runtime, &selected, operation, &ids).await }, + ) + }; + tokio::time::timeout(Duration::from_secs(2), pause.entered.notified()) + .await + .unwrap(); + conflict(&runtime, projection).await; + pause.resume.notify_one(); + let result = reader.await.unwrap(); + assert!( + matches!(result, Err(TodayError::Cursor(CursorError::Stale))), + "{operation}/{ordinal}/{after}/{projection}: {result:?}" + ); + let reads = counts.take(); + assert_eq!(reads.get("event.rows").copied().unwrap_or(0), 0); + let attempted = reads + .get("projection.payload_queries") + .copied() + .unwrap_or(0); + assert!(attempted >= ordinal as u64); + assert!(attempted <= ordinal as u64 + u64::from(after)); + runtime.shutdown().await.unwrap(); + } + let root = tempfile::tempdir().unwrap(); + let (runtime, counts) = instrumented(&root).await; + let selected = context(None, 1); + let ids = seeded(&runtime, &selected).await; + counts.faults.failure("read_payload", ordinal, after); + assert!(matches!( + read_ids(&runtime, &selected, operation, &ids).await, + Err(TodayError::Storage( + radroots_storage::Error::BackendUnavailable + )) + )); + runtime.shutdown().await.unwrap(); + } + } + } +} + +#[tokio::test] +async fn sqlite_initial_read_repair_refuses_source_races_with_the_typed_stale_error() { + for operation in 0..4 { + for after in [false, true] { + let root = tempfile::tempdir().unwrap(); + let (runtime, counts) = instrumented(&root).await; + let selected = context(None, 1); + let ids = seeded(&runtime, &selected).await; + conflict(&runtime, false).await; + let pause = counts.faults.pause("read_visible", 1, after); + let runtime = Arc::new(runtime); + let reader = { + let runtime = runtime.clone(); + let selected = selected.clone(); + tokio::spawn(async move { read_ids(&runtime, &selected, operation, &ids).await }) + }; + tokio::time::timeout(Duration::from_secs(2), pause.entered.notified()) + .await + .unwrap(); + EventStore::admit( + runtime.client.storage().unwrap(), + visible_admission(signed(1, vec![], "scope newer", NOW + 2), NOW * 1_000), + ) + .await + .unwrap(); + pause.resume.notify_one(); + let result = reader.await.unwrap(); + assert!( + matches!(result, Err(TodayError::Cursor(CursorError::Stale))), + "{operation}/{after}: {result:?}" + ); + runtime.shutdown().await.unwrap(); + } + } +} + +#[tokio::test] +async fn known_stale_read_repair_offline_failure_refuses_cache_and_preserves_space_recovery() { + for operation in 0..4 { + for space in [false, true] { + let root = tempfile::tempdir().unwrap(); + let (runtime, counts) = instrumented(&root).await; + let selected = context(None, 1); + let ids = seeded(&runtime, &selected).await; + // A committed source mutation makes the previously Ready cache stale. + conflict(&runtime, false).await; + if space { + counts.faults.disk_full("read_visible", 1, false); + } else { + counts.faults.failure("read_visible", 1, false); + } + let result = read_ids(&runtime, &selected, operation, &ids).await; + if space { + assert!( + matches!( + result, + Err(TodayError::Storage( + radroots_storage::Error::SpaceInsufficient + )) + ), + "{operation}: preserve the existing capacity recovery: {result:?}" + ); + } else { + assert!( + matches!(result, Err(TodayError::ProjectionMissing)), + "{operation}: cannot retain cache already proved stale: {result:?}" + ); + } + runtime.shutdown().await.unwrap(); + } + } +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_read_scope_reopen_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_read_scope_reopen_tests.rs @@ -0,0 +1,163 @@ +use super::*; + +fn other_author(event: &SignedEvent) -> SignedEvent { + use nostr::secp256k1::{Keypair, Message, SECP256K1}; + let keys = nostr::Keys::parse(&"02".repeat(32)).unwrap(); + let mut wire = event.wire().clone(); + wire.pubkey = keys.public_key().to_string(); + let id = wire.computed_event_id().unwrap(); + wire.id = id.to_hex(); + wire.sig = SECP256K1 + .sign_schnorr_no_aux_rand( + &Message::from_digest(*id.as_bytes()), + &Keypair::from_secret_key(SECP256K1, keys.secret_key()), + ) + .to_string(); + let raw = serde_json::to_string(&wire).unwrap(); + SignedEvent::from_wire_verified_id(wire, raw).unwrap() +} + +#[tokio::test] +async fn sqlite_invalid_signature_and_wrong_author_deletion_cannot_hide_current_reads() { + for invalid in [false, true] { + for operation in 0..4 { + let root = tempfile::tempdir().unwrap(); + let runtime = reopen_counted_sqlite(&root).await; + let selected = context(None, 1); + let event = signed(1, vec![], "scope retained", NOW); + let expected = vec![event.id().to_hex()]; + ingest(&runtime, &selected, event, NOW).await; + let ids = runtime + .phase1_today_page(&selected, TodayPageRequest::first(100, NOW, "UTC")) + .await + .unwrap() + .items + .into_iter() + .map(|card| card.card.card_id.to_hex()) + .collect::<Vec<_>>(); + let deletion = signed(5, vec![vec!["e", &expected[0]]], "", NOW + 1); + let admission = if invalid { + let mut wire = deletion.wire().clone(); + wire.sig = "0".repeat(128); + let event = radroots_event_codec::decode::signed_event( + &serde_json::to_string(&wire).unwrap(), + ) + .unwrap(); + assert!(verify_nip01_event(event.envelope().clone()).is_err()); + EventAdmission::raw(observed(event)) + } else { + let event = other_author(&deletion); + assert!(verify_nip01_event(event.envelope().clone()).is_ok()); + visible_admission(event, NOW * 1_000) + }; + let receipt = EventStore::admit(runtime.client.storage().unwrap(), admission) + .await + .unwrap(); + runtime.shutdown().await.unwrap(); + let runtime = reopen_counted_sqlite(&root).await; + assert_eq!( + read_ids(&runtime, &selected, operation, &ids) + .await + .unwrap(), + expected + ); + let retained = EventStore::query_raw( + runtime.client.storage().unwrap(), + EventQuery::for_ids( + EventQueryBounds::first(1).unwrap(), + vec![*receipt.event_id()], + ) + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(retained.items()[0].position(), receipt.position()); + runtime.shutdown().await.unwrap(); + } + } +} + +#[tokio::test] +async fn sqlite_thread_cursor_refuses_unprojected_deletion_and_reopens_current_detail() { + let root = tempfile::tempdir().unwrap(); + let runtime = reopen_counted_sqlite(&root).await; + let selected = context(None, 1); + let event = signed(1, vec![], "scope root", NOW); + let identity = event.id().to_hex(); + ingest(&runtime, &selected, event, NOW).await; + ingest( + &runtime, + &selected, + signed(0, vec![], r#"{"name":"Current thread author"}"#, NOW), + NOW, + ) + .await; + let mut reply_ids = Vec::new(); + for index in 0..10 { + let reply = signed( + 1, + vec![vec!["e", &identity, "", "root"]], + &format!("scope reply {index}"), + NOW, + ); + reply_ids.push(reply.id().to_hex()); + ingest(&runtime, &selected, reply, NOW).await; + } + let page = runtime + .phase1_today_page(&selected, TodayPageRequest::first(20, NOW, "UTC")) + .await + .unwrap(); + let cursor = page.items[0].thread_next_cursor.clone().unwrap(); + let removed = page.items[0].thread[0].event_id.clone(); + EventStore::admit( + runtime.client.storage().unwrap(), + visible_admission( + signed(5, vec![vec!["e", &removed]], "", NOW + 1), + NOW * 1_000, + ), + ) + .await + .unwrap(); + runtime.shutdown().await.unwrap(); + let runtime = reopen_counted_sqlite(&root).await; + assert!(matches!( + runtime + .phase1_today_thread_page(&selected, 10, &cursor) + .await, + Err(TodayError::Cursor(CursorError::Stale)) + )); + let page = runtime + .phase1_today_page(&selected, TodayPageRequest::first(20, NOW + 10, "UTC")) + .await + .unwrap(); + let card = &page.items[0]; + let mut replies = card.thread.clone(); + let mut cursor = card.thread_next_cursor.clone(); + while let Some(value) = cursor { + let next = runtime + .phase1_today_thread_page(&selected, 10, &value) + .await + .unwrap(); + replies.extend(next.items); + cursor = next.next_cursor; + } + let mut actual = replies + .iter() + .map(|reply| reply.event_id.clone()) + .collect::<Vec<_>>(); + let mut expected = reply_ids + .into_iter() + .filter(|id| id != &removed) + .collect::<Vec<_>>(); + actual.sort(); + expected.sort(); + assert_eq!(actual, expected); + assert!(replies.iter().all(|reply| { + reply + .author_profile + .as_ref() + .and_then(|profile| profile.name.as_deref()) + == Some("Current thread author") + })); + runtime.shutdown().await.unwrap(); +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs @@ -0,0 +1,355 @@ +//! Current reads exercise real providers and committed source boundaries. +use super::performance_tests::{ + counted_storage::{CountedStorage, QueryCounts}, + reopen_counted_sqlite, +}; +use super::tests::{context, ingest, keys, signed, visible_admission}; +use super::*; +use radroots_event::{SignedEvent, admission::RawEvent}; +use radroots_event_codec::verify::Nip01SignatureVerifier; +use radroots_transport::{ + Target, TransportId, + source::{EventProvenance, ObservedEvent}, +}; +use std::{sync::Arc, time::Duration}; + +const NOW: u64 = 2_000_000_100; + +#[path = "today_read_scope_reopen_tests.rs"] +mod reopen_cases; + +#[path = "today_read_scope_conflict_tests.rs"] +mod conflict_cases; + +fn observed(event: SignedEvent) -> ObservedEvent { + let target = Target::nostr_relay("wss://relay.example").unwrap(); + ObservedEvent::new( + event, + EventProvenance::new( + TransportId::NOSTR, + target.fingerprint().clone(), + NOW * 1_000, + ) + .unwrap(), + ) +} + +fn verified(event: SignedEvent) -> EventAdmission { + let evidence = RawEvent::new(event.envelope().clone()) + .verify_id() + .unwrap() + .verify_signature(&Nip01SignatureVerifier) + .unwrap(); + EventAdmission::verified(observed(event), evidence).unwrap() +} + +async fn read_ids( + runtime: &TeraRuntime, + selected: &LocalNetwork, + operation: usize, + ids: &[String], +) -> Result<Vec<String>, TodayError> { + let cards = match operation { + 0 => { + runtime + .phase1_today_page(selected, TodayPageRequest::first(100, NOW + 10, "UTC")) + .await? + .items + } + 1 => runtime + .phase1_search(selected, "scope", 100, NOW + 10, "UTC") + .await? + .into_iter() + .filter_map(|result| result.card) + .collect(), + 2 => { + runtime + .phase1_me(selected, &keys().public_key().to_string(), NOW + 10, "UTC") + .await? + .cards + } + _ => { + runtime + .phase1_today_reconcile(selected, NOW + 10, ids, None, "UTC") + .await? + .items + } + }; + Ok(cards + .into_iter() + .map(|card| card.card.source_event_id) + .collect()) +} + +#[tokio::test] +async fn complete_same_id_generation_locality_repairs_search_me_and_paging() { + for sqlite in [false, true] { + for operation in 0..3 { + let root = tempfile::tempdir().unwrap(); + let runtime = if sqlite { + reopen_counted_sqlite(&root).await + } else { + TeraRuntime::test_memory().unwrap() + }; + let first = context(Some("first"), 1); + let second = context(Some("second"), 1); + let mut expected = Vec::new(); + for locality in ["first", "second"] { + for suffix in ["alpha", "bravo"] { + let event = signed( + 1, + vec![vec!["g", locality]], + &format!("scope {suffix}"), + NOW, + ); + if locality == "second" { + expected.push(event.id().to_hex()); + } + ingest(&runtime, &first, event, NOW).await; + } + } + assert_eq!( + read_ids(&runtime, &first, operation, &[]) + .await + .unwrap() + .len(), + 2 + ); + let mut actual = read_ids(&runtime, &second, operation, &[]).await.unwrap(); + actual.sort(); + expected.sort(); + assert_eq!( + actual, expected, + "{sqlite}/{operation}: include previously excluded current records" + ); + runtime.shutdown().await.unwrap(); + } + } +} + +#[tokio::test] +async fn sqlite_commit_without_projection_reopen_qualifies_every_supporting_reader() { + for scenario in ["deletion", "same_count_promotion", "unsupported_profile"] { + for operation in 0..4 { + let root = tempfile::tempdir().unwrap(); + let runtime = reopen_counted_sqlite(&root).await; + let selected = context(None, 1); + let original = signed(1, vec![], "scope original", NOW - 100); + let source_ids = vec![original.id().to_hex()]; + ingest(&runtime, &selected, original.clone(), NOW).await; + ingest( + &runtime, + &selected, + signed(0, vec![], r#"{"name":"Scope Farm"}"#, NOW - 100), + NOW, + ) + .await; + let ids = runtime + .phase1_today_page(&selected, TodayPageRequest::first(100, NOW, "UTC")) + .await + .unwrap() + .items + .into_iter() + .map(|card| card.card.card_id.to_hex()) + .collect::<Vec<_>>(); + let storage = runtime.client.storage().unwrap(); + let admission = match scenario { + "deletion" => visible_admission( + signed(5, vec![vec!["e", &source_ids[0]]], "", NOW - 99), + NOW * 1_000, + ), + "same_count_promotion" => { + let event = signed(1, vec![], "scope promoted", NOW - 99); + EventStore::admit(storage, EventAdmission::raw(observed(event.clone()))) + .await + .unwrap(); + runtime + .phase1_refresh_today(&selected, NOW, TodayProjectionUpdate::Incremental) + .await + .unwrap(); + visible_admission(event, NOW * 1_000) + } + _ => verified(signed(0, vec![], "unsupported valid profile", NOW - 99)), + }; + let count = EventStore::status(storage).await.unwrap().raw_events(); + let receipt = EventStore::admit(storage, admission).await.unwrap(); + if scenario == "same_count_promotion" { + assert_eq!( + EventStore::status(storage).await.unwrap().raw_events(), + count + ); + } + // No projection/refresh between the acknowledged source commit and close. + runtime.shutdown().await.unwrap(); + let runtime = reopen_counted_sqlite(&root).await; + let retained = EventStore::query_raw( + runtime.client.storage().unwrap(), + EventQuery::for_ids( + EventQueryBounds::first(1).unwrap(), + vec![*receipt.event_id()], + ) + .unwrap(), + ) + .await + .unwrap(); + assert_eq!(retained.items()[0].position(), receipt.position()); + let actual = read_ids(&runtime, &selected, operation, &ids) + .await + .unwrap(); + match scenario { + "deletion" => assert!( + actual.is_empty(), + "{operation} must not return deleted content" + ), + "same_count_promotion" if operation != 3 => assert_eq!(actual.len(), 2), + _ => assert_eq!(actual, source_ids, "{scenario}/{operation}"), + } + let me = runtime + .phase1_me(&selected, &keys().public_key().to_string(), NOW + 11, "UTC") + .await + .unwrap(); + assert_eq!(me.profile.is_none(), scenario == "unsupported_profile"); + runtime.shutdown().await.unwrap(); + } + } +} + +async fn instrumented(root: &tempfile::TempDir) -> (TeraRuntime, Arc<QueryCounts>) { + let mut runtime = reopen_counted_sqlite(root).await; + let counts = Arc::new(QueryCounts::default()); + runtime.client = radroots_sdk::ClientBuilder::new() + .storage(Arc::new(CountedStorage { + client: runtime.client.clone(), + counts: counts.clone(), + })) + .build() + .unwrap(); + (runtime, counts) +} + +#[tokio::test] +async fn actual_sqlite_reads_before_and_after_await_refuse_concurrent_source_change() { + for operation in 0..4 { + for ordinal in 1..=3 { + for after in [false, true] { + let root = tempfile::tempdir().unwrap(); + let (runtime, counts) = instrumented(&root).await; + let selected = context(None, 1); + let old = signed(1, vec![], "scope old", NOW); + ingest(&runtime, &selected, old, NOW).await; + let ids = runtime + .phase1_today_page(&selected, TodayPageRequest::first(100, NOW, "UTC")) + .await + .unwrap() + .items + .into_iter() + .map(|card| card.card.card_id.to_hex()) + .collect::<Vec<_>>(); + counts.take(); + let pause = counts.faults.pause("read_query", ordinal, after); + let runtime = Arc::new(runtime); + let reader = { + let runtime = runtime.clone(); + let selected = selected.clone(); + let ids = ids.clone(); + tokio::spawn( + async move { read_ids(&runtime, &selected, operation, &ids).await }, + ) + }; + tokio::time::timeout(Duration::from_secs(2), pause.entered.notified()) + .await + .unwrap(); + EventStore::admit( + runtime.client.storage().unwrap(), + visible_admission(signed(1, vec![], "scope new-current", NOW + 1), NOW * 1_000), + ) + .await + .unwrap(); + pause.resume.notify_one(); + assert!( + reader.await.unwrap().is_err(), + "{operation}/{ordinal}/{after} stale read must refuse" + ); + let reads = counts.take(); + assert_eq!(reads.get("event.rows").copied().unwrap_or(0), 0); + assert_eq!( + runtime + .phase1_search(&selected, "new-current", 10, NOW + 10, "UTC") + .await + .unwrap() + .len(), + 1, + "A read refusal must not fence acknowledged canonical work" + ); + runtime.shutdown().await.unwrap(); + } + } + } +} + +#[tokio::test] +async fn sqlite_same_source_policy_change_fences_supporting_payload_read() { + use crate::runtime::visibility::{AuthorVisibility, AuthorVisibilityPolicy}; + for operation in 1..=3 { + let root = tempfile::tempdir().unwrap(); + let (runtime, counts) = instrumented(&root).await; + let selected = context(None, 1); + let old = signed(1, vec![], "scope old", NOW); + ingest(&runtime, &selected, old, NOW).await; + let ids = runtime + .phase1_today_page(&selected, TodayPageRequest::first(100, NOW, "UTC")) + .await + .unwrap() + .items + .into_iter() + .map(|card| card.card.card_id.to_hex()) + .collect::<Vec<_>>(); + let pause = counts.faults.pause("read_query", 2, true); + let runtime = Arc::new(runtime); + let reader = { + let runtime = runtime.clone(); + let selected = selected.clone(); + let ids = ids.clone(); + tokio::spawn(async move { read_ids(&runtime, &selected, operation, &ids).await }) + }; + tokio::time::timeout(Duration::from_secs(2), pause.entered.notified()) + .await + .unwrap(); + let source = EventStore::source_token(runtime.client.storage().unwrap()) + .await + .unwrap(); + let mut policy = serde_json::to_value(AuthorVisibilityPolicy::default()).unwrap(); + policy["revision"] = 1.into(); + policy["entries"][keys().public_key().to_string()] = + serde_json::to_value(AuthorVisibility::Blocked).unwrap(); + let policy: AuthorVisibilityPolicy = serde_json::from_value(policy).unwrap(); + let (id, generation) = crate::runtime::visibility::identity().unwrap(); + ProjectionStore::put_projection_document( + runtime.client.storage().unwrap(), + id, + generation, + ProjectionDocument::new( + crate::runtime::visibility::KEY.into(), + serde_json::to_vec(&policy).unwrap(), + ) + .unwrap(), + ) + .await + .unwrap(); + assert_eq!( + EventStore::source_token(runtime.client.storage().unwrap()) + .await + .unwrap(), + source + ); + pause.resume.notify_one(); + assert!(reader.await.unwrap().is_err()); + assert!( + read_ids(&runtime, &selected, operation, &ids) + .await + .unwrap() + .is_empty() + ); + runtime.shutdown().await.unwrap(); + } +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs b/core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs @@ -34,20 +34,10 @@ impl TeraRuntime { if selected.len() != card_ids.len() { return Err(TodayError::InvalidRequest); } - let storage = self - .client - .storage() - .map_err(|_| TodayError::RuntimeUnavailable)?; - let state = self - .calendar_state_for_read(storage, context, as_of) - .await? - .ok_or(TodayError::ProjectionMissing)?; + let (_projection, state) = self.calendar_state_for_read(context, as_of, true).await?; if state.query_scope != Some(query_scope) || state.visibility_digest.is_none() - || state.author_visibility_digest - != self.load_author_visibility().await?.cache_digest()? || expected_generation.is_some_and(|value| value != state.content_generation) - || state.store_generation != current_store_generation(storage).await? { return Err(CursorError::Stale.into()); } diff --git a/core/crates/tera_core/src/runtime/product_surface/today_refresh.rs b/core/crates/tera_core/src/runtime/product_surface/today_refresh.rs @@ -99,26 +99,29 @@ impl TeraRuntime { pub(super) async fn calendar_state_for_read( &self, - storage: &dyn radroots_storage::Storage, context: &LocalNetwork, as_of: u64, - ) -> Result<Option<TodayProjectionState>, TodayError> { - let state = load_state(storage, context, projection_generation()?).await?; - let policy_digest = self.load_author_visibility().await?.cache_digest()?; - let needs_upgrade = state.as_ref().is_some_and(|value| { - !calendar_projection_ready(value) || value.author_visibility_digest != policy_digest - }) || (state.is_none() - && (sidecar::load(storage, context).await?.is_some() - || !calendar_migration::ready(storage).await? - || calendar_migration::legacy_state(storage, context) - .await? - .is_some())); - if needs_upgrade { - self.phase1_refresh_today(context, as_of, TodayProjectionUpdate::Rebuild) - .await?; - load_state(storage, context, projection_generation()?).await + require_matching_context: bool, + ) -> Result<(tokio::sync::MutexGuard<'_, ()>, TodayProjectionState), TodayError> { + let mut guard = self.today_projection_lock.lock().await; + let mut budget = page_budget::Budget::default(); + let mut scope = if require_matching_context { + read_scope::Scope::load_matching_context(self, context, &mut budget).await? } else { - Ok(state) + read_scope::Scope::load(self, context, &mut budget).await? + }; + if scope.is_none() { + drop(guard); + self.phase1_refresh_today(context, as_of, TodayProjectionUpdate::Rebuild) + .await + .map_err(read_scope::current_repair_error)?; + guard = self.today_projection_lock.lock().await; + scope = read_scope::Scope::load(self, context, &mut budget).await?; } + let scope = scope.ok_or(CursorError::Stale)?; + let mut finish = budget.reserve_scope()?; + let state = scope.load_state(self, context).await?; + scope.check_current(self, context, &mut finish).await?; + Ok((guard, state)) } } diff --git a/core/crates/tera_core/src/runtime/product_surface/today_row_state.rs b/core/crates/tera_core/src/runtime/product_surface/today_row_state.rs @@ -1,4 +1,4 @@ -//! Temporary whole-view reader bridge. C200 replaces it with bounded selected joins. +//! Whole-view supporting reader bridge, replaced by selected joins in C203. //! New builds never invoke this bridge and never persist a copied feed. use super::*; use radroots_storage::projection::document_query::{ @@ -26,9 +26,10 @@ pub(super) async fn load( let id = ProjectionId::parse(build::progress::ID)?; let status = ProjectionStore::status(storage, id.clone()).await?; if source != local.source - || status - .as_ref() - .is_none_or(|value| value.generation() != local.generation) + || status.as_ref().is_none_or(|value| { + value.generation() != local.generation + || value.health() != radroots_storage::projection::ProjectionHealth::Ready + }) { return Ok(None); } diff --git a/core/crates/tera_core/src/runtime/visibility.rs b/core/crates/tera_core/src/runtime/visibility.rs @@ -140,16 +140,6 @@ pub(crate) fn identity() -> Result<(ProjectionId, ProjectionGeneration), TodayEr } impl TeraRuntime { - pub(crate) async fn projection_visibility_digest(&self) -> Result<[u8; 32], TodayError> { - let policy = self.load_author_visibility().await?; - let storage = self - .client - .storage() - .map_err(|_| TodayError::RuntimeUnavailable)?; - let source = radroots_storage::EventStore::source_token(storage).await?; - source_visibility_digest(source, policy.cache_digest()?) - } - pub async fn author_visibility(&self) -> Result<AuthorVisibilityPolicy, TodayError> { let _command = self.lifecycle.enter()?; self.load_author_visibility().await diff --git a/core/crates/tera_ffi/src/error.rs b/core/crates/tera_ffi/src/error.rs @@ -181,6 +181,11 @@ impl From<TodayError> for TeraAppError { TodayError::Storage(radroots_storage::Error::SpaceInsufficient) => { return Self::needs_space("today"); } + TodayError::Storage( + radroots_storage::Error::SourceGenerationChanged + | radroots_storage::Error::SourceEpochChanged + | radroots_storage::Error::ProjectionRevisionConflict, + ) => ("today_cursor_invalid", true, &["restart_pagination"][..]), TodayError::Storage(_) => ("today_storage_failed", true, &["inspect_local_stores"][..]), TodayError::CorruptProjection | TodayError::Serialization => { ("today_state_failed", true, &["rebuild", "retry"][..]) @@ -339,6 +344,45 @@ mod tests { use super::*; #[test] + fn current_storage_conflicts_refuse_scope_without_collapsing_offline_or_capacity_reports() { + for conflict in [ + radroots_storage::Error::SourceGenerationChanged, + radroots_storage::Error::SourceEpochChanged, + radroots_storage::Error::ProjectionRevisionConflict, + ] { + let ffi = TeraAppError::from(TodayError::Storage(conflict)); + assert_eq!(ffi.report().code, "today_cursor_invalid"); + assert!(ffi.report().retryable); + assert_eq!(ffi.report().recovery_actions, ["restart_pagination"]); + let recovery = crate::recovery::classify_error_recovery( + ffi.report().schema_version, + ffi.report().code.clone(), + ); + assert_eq!( + recovery.disposition, + crate::recovery::FfiRecoveryDisposition::StaleCursor + ); + } + let offline = TeraAppError::from(TodayError::Storage( + radroots_storage::Error::BackendUnavailable, + )); + assert_eq!(offline.report().code, "today_storage_failed"); + assert_eq!(offline.report().recovery_actions, ["inspect_local_stores"]); + let space = TeraAppError::from(TodayError::Storage( + radroots_storage::Error::SpaceInsufficient, + )); + assert_eq!(space.report().code, "storage_space_insufficient"); + assert_eq!( + space.report().recovery_actions, + [ + "free_reconstructable_cache", + "preserve_local_work", + "reconcile_original_operation", + ] + ); + } + + #[test] fn mutation_admission_reports_the_existing_typed_recovery_contract() { let error = TeraAppError::from(Phase1DraftError::OperationInProgress); let report = error.report(); diff --git a/project.yml b/project.yml @@ -159,6 +159,7 @@ targets: - path: TeraTests/TeraBackgroundUploadFixtures.swift - path: TeraTests/TeraMutationAdmissionTests.swift - path: TeraTests/TeraSupportingStoreTests.swift + - path: TeraTests/TeraSupportingFreshnessTests.swift - path: TeraTests/TeraSupportingBackend.swift - path: TeraTests/TeraCapacityRecoveryTests.swift - path: TeraTests/TeraCapacitySettingsTests.swift diff --git a/release/provenance.json b/release/provenance.json @@ -2,11 +2,11 @@ "artifacts": { "app_api_sha256": "020924097c0d7efc33128cb8fd3d3b2026d95f57c44da71880e585aff80f070b", "ffi_api_sha256": "2479b0d8c0b5091dff93eaaee79902c3e1b5ebe86d8e08662b0066699b61bb15", - "ffi_provenance_sha256": "2568fa4c903dee8188f55f76cb4d6e3a61fbb6ebfda89b1328fa0d87fa87f94a", + "ffi_provenance_sha256": "bb39737e3b056fcdca01ac6a84a91752f27679f3b171836b37b571fe2b596ba9", "info_plist_sha256": "b55010dd73b34bf5ad910a888be0ea1ae45f2a5c14329fa6a57059a317bdbd42", "privacy_manifest_sha256": "0f2103257ba596fbcaeb1d6a4dffe3ae021e84c010178852c6bf500a8cfb0f19", "sbom_sha256": "8552ae21cfc9dd3c1b92c76423e2741f3487fb35b81fb7f4ebbe33afe360b3ee", - "xcode_project_sha256": "c5e7027969b51dc93f3eacd509f795d666d9bd382f6bee506b7d6c88c704eaeb" + "xcode_project_sha256": "cf31981c37cfa3513e933b4aaff78577869bf4095e7d9c08b95b6c452c8c2b24" }, "disposition": "unsigned", "platforms": [ @@ -20,10 +20,10 @@ "authored_app": { "files": { "Package.swift": { - "bytes": 10161, - "git_blob": "5eb3f406f0d9e1bf65263e530f02110d51fe63c9", + "bytes": 10212, + "git_blob": "4fe4f68b1c6a9ff00bb9ae8e9b937640ffc466ab", "mode": "100644", - "sha256": "4043cba85b9052246ab0ba3f6712fc62343d6ea82939374730bee924e5f0a02d" + "sha256": "9398e50611c45f6700025f55cb90777251af65a26e8e53650b7a9647560ba192" }, "Tera/App/App.swift": { "bytes": 233, @@ -50,10 +50,10 @@ "sha256": "ec56c0ea16ad8c9e09b92be77a21edce835d2e901676738442b23bcb84997ffb" }, "Tera/App/TeraProductStores.swift": { - "bytes": 3357, - "git_blob": "114da4fa05ea3c22e2dc7d4efe105cf82527ec31", + "bytes": 4301, + "git_blob": "3e81e5b5ebebe657d11738cd1413a0518831c044", "mode": "100644", - "sha256": "bf4ff96e578c356b9c40bd4bae45bac46833055e84fadf8e045d7671d2675fcc" + "sha256": "edec825374b449ae688d06d87dbda267d54d0b879ca0f16d2ef77e5089581ccd" }, "Tera/App/TeraProvider.swift": { "bytes": 1538, @@ -950,10 +950,10 @@ "sha256": "b404a635c2de60ada80345b80ad6e5307e510db7304f9aacd5fa502cf941fbca" }, "Tera/State/TeraStoreObservation.swift": { - "bytes": 5035, - "git_blob": "1ed6ac0fc4f7cd9272896dec82e4f5138589eabf", + "bytes": 5421, + "git_blob": "4a2953370d2123ecd85e6497eae793eb03158946", "mode": "100644", - "sha256": "28d56bd79b521800f0ebadd7b449c4055af4e940ed6059d0d2b5fd8bafb72de7" + "sha256": "e1cd944f011758320340953b308ab23a49352273552e220f795bf2b2e71a33b9" }, "Tera/State/TeraSubmissionEffects.swift": { "bytes": 5304, @@ -980,10 +980,10 @@ "sha256": "d6ab5a9f8047a84403a1e462a3533c6e31fbbf44d1d69ebe706887a813a66363" }, "Tera/State/TeraSupportingStores.swift": { - "bytes": 6818, - "git_blob": "bae464750c421031e3be45d1016c98a786213d94", + "bytes": 11566, + "git_blob": "b38fa8403d98d5f3ca93ef9e02ea65f7378d4be4", "mode": "100644", - "sha256": "a5b6f7c6ed0645df18e50f52c3d53104d702d42ea363d7bf835b1062802fe71a" + "sha256": "efd09d196246b7561f4795a125b580c2d3b235ec83a1d7d44ad732dc97c8d952" }, "Tera/State/TeraTodayDiscoveryPresentation.swift": { "bytes": 1245, @@ -1183,11 +1183,17 @@ "mode": "100644", "sha256": "ff63d0f0eb17e806a2be831363af5bde0c09e0ee1cf5c964a3b01276b7df697f" }, + "Tera/Views/TeraSupportingCurrentDetail.swift": { + "bytes": 2465, + "git_blob": "84880e33b6e1dfe51605825051b93d5024841198", + "mode": "100644", + "sha256": "1df5acec7e3424b98601d075f1eef7af9e0be4aaedbf45877a4f6107d3d6e925" + }, "Tera/Views/TeraSupportingViews.swift": { - "bytes": 11575, - "git_blob": "cf39a7a6fd2b76d41e5f7d66b94351cef0de8dcd", + "bytes": 11609, + "git_blob": "a3aad61b758fd24337e33a6aca09ebdde0dc4dce", "mode": "100644", - "sha256": "0854f7b71b9ffd2965a60672460a6f41b00a9578ba500b3d83bb32082e37b2ac" + "sha256": "74d7eed1a4b1b700d65173ff8672470684cd65fbf0e4183677accc643e337738" }, "Tera/Views/TeraTimedCalendarField.swift": { "bytes": 1880, @@ -1250,21 +1256,21 @@ "sha256": "0e28b784839be43bf9dd818f1f1bd494cbafd6d9fd021764e09a12b493545d16" }, "project.yml": { - "bytes": 10265, - "git_blob": "e91aa894d7c867ac9ee9f705a0287d993f194ac9", + "bytes": 10324, + "git_blob": "e16af3a172b6c94db1a1a5a58a16e5355366ff13", "mode": "100644", - "sha256": "804dbdb183582a7563b72498e5c5e22f1b78cc5841edae82037f04544f9c8a5a" + "sha256": "def0fb2ea463b6e6f020a1b2cd208ea33fe6d9ac5bbf103d7c63f33e1afc9807" } }, "policy": "staged_inputs", - "tree": "eb8f4667c73180f604cbc4c69b3e19ca71f539dd" + "tree": "2bd09aecfcc92b9c9605e2261ad0e7849e2730fb" }, "cargo_lock_sha256": "efb02ec8209f2a8de2065aed29a275e0b17adda4044a763a43a7a7f6a8a01181", "consumer_source_lock_sha256": "15151b7bb25a4f6bca910f61db6c122383fd333fa4266f06e60df50113bfb728", "lib_revision": "418acecb49437ce1200a6916822af9ef83eefec3", "source_date_epoch": 1787871027, "swift_package_lock_sha256": "8aec408132602a249111a65903c985cca5898ec316a45916d88ba756f08ea40d", - "tera_ffi_source_tree": "450471e2ff1feb3675f676ededf0f8446c1a5099", + "tera_ffi_source_tree": "0e803c4e3df6d4d4cbfaadf518a5fc96e5f9496d", "xcode_package_lock_sha256": "3656728f8251f3ea644aa150d154819766470ca7bd4f85b7c51fdf301d361d16" }, "version": "0.1.0-alpha" diff --git a/scripts/fixture_alias_tool.py b/scripts/fixture_alias_tool.py @@ -0,0 +1,39 @@ +"""Native alias fixture: exercise argv0 without an unrelated Python child.""" + +from __future__ import annotations + +import json +from pathlib import Path + +from fixture_tool_dispatch import CompilerCommand, FixtureDispatchError + + +def compile_alias_dispatch(root: Path, compiler: str | None, environment: dict): + if compiler is None: + raise FixtureDispatchError("native alias fixture compiler unavailable") + source = root / "alias-dispatch.c" + binary = root / "alias-dispatch" + source.write_text( + "#include <stdio.h>\n#include <string.h>\n" + "int main(int argc, char **argv) {\n" + " if (argc != 1 || argv[0] == NULL) return 64;\n" + " const char *name = strrchr(argv[0], '/');\n" + " return puts(name ? name + 1 : argv[0]) < 0 ? 74 : 0;\n" + "}\n" + ) + command = CompilerCommand( + [compiler, "-Wall", "-Wextra", "-Werror", "-o", str(binary), str(source)], + root, + env=environment, + ) + try: + result = command.execute() + finally: + (root / "alias-compilation.json").write_text(json.dumps(command.record)) + if ( + result.returncode + or not command.record["wait_reaped"] + or not command.record["group_absent"] + ): + raise FixtureDispatchError("native alias fixture compilation failed") + return binary, command.record diff --git a/scripts/test_ffi_native.py b/scripts/test_ffi_native.py @@ -6,6 +6,7 @@ import copy import json import itertools import os +import shutil import subprocess import sys import tempfile @@ -20,6 +21,7 @@ if str(SCRIPTS) not in sys.path: import ffi_build as builder # noqa: E402 import ffi_native as native # noqa: E402 import ffi_source as source # noqa: E402 +from fixture_alias_tool import compile_alias_dispatch # noqa: E402 # Literal cc 1.4.0 cargo_env_var_os inputs, independent of the production list. @@ -230,6 +232,8 @@ class NativeInputTests(unittest.TestCase): class NativeBindingTests(unittest.TestCase): def setUp(self) -> None: + self.alias_compiler = shutil.which("cc") + self.alias_compiler_environment = dict(os.environ) temporary = tempfile.TemporaryDirectory() self.addCleanup(temporary.cleanup) self.root = Path(temporary.name).resolve() @@ -300,11 +304,14 @@ class NativeBindingTests(unittest.TestCase): def test_public_fixture_aliases_retain_actual_argv0_dispatch(self) -> None: # These existing synthetic tools use explicitly substituted fixture roots. - dispatch = ( - f"#!{sys.executable}\nimport os,sys\nprint(os.path.basename(sys.argv[0]))\n" + binary, command = compile_alias_dispatch( + self.root, self.alias_compiler, self.alias_compiler_environment ) + self.assertTrue(command["wait_reaped"]) + self.assertTrue(command["group_absent"]) for name in ("libtool", "swift-frontend"): - (self.tools / name).write_text(dispatch) + shutil.copyfile(binary, self.tools / name) + (self.tools / name).chmod(0o755) for name in ("ranlib", "swiftc", "swift-symbolgraph-extract"): with self.subTest(tool=name): alias = self.tools / name @@ -324,6 +331,12 @@ class NativeBindingTests(unittest.TestCase): ) self.assertEqual(result.stdout.strip(), name) + def test_native_alias_dispatch_does_not_depend_on_python_loader(self) -> None: + with patch.object( + sys, "executable", str(self.root / "unavailable-python-loader") + ): + self.test_public_fixture_aliases_retain_actual_argv0_dispatch() + def test_literal_cargo_trim_capture_rejects_before_tool_queries(self) -> None: for overrides in CARGO_TRIM_OVERRIDES: with self.subTest(overrides=overrides), patch.dict(os.environ, overrides): diff --git a/test-fixtures/legacy-identifiers.v1.json b/test-fixtures/legacy-identifiers.v1.json @@ -5815,6 +5815,10 @@ "count": 6 }, { + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs", + "count": 1 + }, + { "path": "core/crates/tera_core/src/runtime/product_surface/today_rows_tests.rs", "count": 1 }, @@ -5945,6 +5949,14 @@ "count": 1 }, { + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope_reopen_tests.rs", + "count": 1 + }, + { + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs", + "count": 1 + }, + { "path": "core/crates/tera_core/src/runtime/product_surface/today_viewer_calendar_tests.rs", "count": 1 }, @@ -6565,6 +6577,10 @@ "count": 1 }, { + "path": "core/crates/tera_core/src/runtime/product_surface/today_media_read_scope_tests.rs", + "count": 1 + }, + { "path": "core/crates/tera_core/src/runtime/product_surface/today_media_visibility_tests.rs", "count": 1 }, @@ -6577,6 +6593,10 @@ "count": 1 }, { + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs", + "count": 1 + }, + { "path": "core/crates/tera_core/src/runtime/product_surface/today_sync_tests.rs", "count": 2 }, @@ -7117,10 +7137,6 @@ "count": 12 }, { - "path": "core/crates/tera_core/src/runtime/product_surface/today_page_scope.rs", - "count": 3 - }, - { "path": "core/crates/tera_core/src/runtime/product_surface/today_paging.rs", "count": 3 }, @@ -7133,12 +7149,16 @@ "count": 6 }, { - "path": "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs", - "count": 1 + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope.rs", + "count": 7 + }, + { + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope_conflict_tests.rs", + "count": 3 }, { "path": "core/crates/tera_core/src/runtime/product_surface/today_row_state.rs", - "count": 4 + "count": 5 }, { "path": "core/crates/tera_core/src/runtime/product_surface/today_rows.rs", @@ -7194,7 +7214,7 @@ }, { "path": "core/crates/tera_core/src/runtime/visibility.rs", - "count": 4 + "count": 3 }, { "path": "core/crates/tera_ffi/Cargo.toml", @@ -7218,7 +7238,7 @@ }, { "path": "core/crates/tera_ffi/src/error.rs", - "count": 1 + "count": 9 }, { "path": "core/crates/tera_ffi/src/restore/adapter.rs", @@ -7409,6 +7429,10 @@ "count": 1 }, { + "path": "core/crates/tera_core/src/runtime/product_surface/today_read_scope_tests.rs", + "count": 1 + }, + { "path": "core/crates/tera_core/src/runtime/product_surface/today_sync.rs", "count": 1 },