mirror of
https://github.com/block/buzz.git
synced 2026-10-28 04:51:40 +00:00
Follow-up to [#8294](https://github.com/block/buzz/pull/8294). Malformed trailing thread tags could make a notification open the right thread while Flutter indexed its reply elsewhere; uppercase references could similarly miss lowercase event IDs. Share one validated thread-reference parser between the mobile timeline, Inbox, and feed helper. It ignores malformed markers, keeps the last valid root/reply, and normalizes lookup IDs to lowercase. Native push parsing now uses the same casing. Existing thread fixtures use valid event IDs so they continue exercising real thread relationships. Add RunnerTests coverage for the production native-to-Flutter argument conversion, including buffered cold-start navigation and omitted optional thread IDs, and run it in the native CI lane. ### Validation - New parser and Inbox regressions cover malformed markers and uppercase references. Widget regressions open and highlight the exact reply for valid, uppercase, and trailing-malformed tags. - After integrating [#8106](https://github.com/block/buzz/pull/8106), Flutter analysis and the complete mobile suite pass: 3,337 tests, four existing skips. Integration preserves per-event read predicates and migrates incoming thread fixtures to valid IDs. An unchanged keyboard-history test also failed with main's original parser; recording reads before the scroll transition fixes its timing assumption while retaining visibility assertions. - Native package tests passed (127 tests), and both Runner bridge tests passed on an iOS simulator with Xcode 26.5. Removing the production `threadRootId` assignment made the bridge regression fail; restoring it passed. Native code is unchanged by the main integration. - [Current-head CI passed](https://github.com/block/buzz/actions/runs/38659307247), including Mobile and Mobile Swift. [Codex review](https://github.com/block/buzz/pull/8332#issuecomment-6181458528) and [security review](https://github.com/block/buzz/pull/8332#issuecomment-6181449235) found no issues on the integrated commit. [Owner approval](https://github.com/block/buzz/pull/8332#pullrequestreview-5526812957) covers the exact integrated commit. - Standards and spec reviews found no blockers, including the merge resolutions and test adjustments. Validation is scoped to mobile/native per VISION_MOBILE; unrelated repository-wide checks were stopped, not counted as passing. The bridge test covers serialization and buffering, not end-to-end APNs delivery or app launch. No new physical-device acceptance is claimed; routine post-merge dogfood remains human-owned. --------- Signed-off-by: Tom Brow <tomb@block.xyz>
140 lines
4.5 KiB
Swift
140 lines
4.5 KiB
Swift
import Foundation
|
|
import Testing
|
|
|
|
@testable import BuzzPushKit
|
|
|
|
@Test func `Round-trip opaque navigation target through notification user info`() {
|
|
let target = BuzzPushNavigationTarget(
|
|
eventID: "MESSAGE-ID",
|
|
communityID: "community-id",
|
|
channelID: "CHANNEL/GENERAL"
|
|
)
|
|
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [BuzzPushNavigationTarget.userInfoKey: target.userInfoValue]
|
|
) == target
|
|
)
|
|
#expect(target.eventID == "MESSAGE-ID")
|
|
#expect(target.channelID == "CHANNEL/GENERAL")
|
|
}
|
|
|
|
@Test func `Reject incomplete or malformed navigation target`() {
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [
|
|
BuzzPushNavigationTarget.userInfoKey: [
|
|
"event_id": "message-id",
|
|
"community_id": "community-id",
|
|
]
|
|
]
|
|
) == nil
|
|
)
|
|
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [
|
|
BuzzPushNavigationTarget.userInfoKey: [
|
|
"event_id": "",
|
|
"community_id": "community-id",
|
|
"channel_id": "channel-id",
|
|
]
|
|
]
|
|
) == nil
|
|
)
|
|
|
|
#expect(
|
|
BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [
|
|
BuzzPushNavigationTarget.userInfoKey: [
|
|
"event_id": "message-id",
|
|
"community_id": "community-id",
|
|
"channel_id": "",
|
|
]
|
|
]
|
|
) == nil
|
|
)
|
|
}
|
|
|
|
@Test func `Buffer preserves cold-start target until consumed`() {
|
|
let first = BuzzPushNavigationTarget(
|
|
eventID: String(repeating: "a", count: 64),
|
|
communityID: "community-id",
|
|
channelID: "123e4567-e89b-42d3-a456-426614174000"
|
|
)
|
|
let second = BuzzPushNavigationTarget(
|
|
eventID: String(repeating: "b", count: 64),
|
|
communityID: "community-id",
|
|
channelID: "123e4567-e89b-42d3-a456-426614174000"
|
|
)
|
|
let buffer = BuzzPushNavigationBuffer()
|
|
|
|
buffer.record(first)
|
|
buffer.remove(ifMatching: second)
|
|
#expect(buffer.peek() == first)
|
|
#expect(buffer.take() == first)
|
|
#expect(buffer.take() == nil)
|
|
}
|
|
|
|
@Test func `Reply target preserves containing thread through user info and cold-start buffer`() {
|
|
let target = BuzzPushNavigationTarget(
|
|
eventID: "reply", communityID: "community", channelID: "channel", threadRootID: "parent"
|
|
)
|
|
let decoded = BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [BuzzPushNavigationTarget.userInfoKey: target.userInfoValue]
|
|
)
|
|
#expect(decoded == target)
|
|
let buffer = BuzzPushNavigationBuffer()
|
|
buffer.record(target)
|
|
#expect(buffer.take() == target)
|
|
}
|
|
|
|
@Test func `Reject malformed optional thread and unknown navigation fields`() {
|
|
let cases: [[String: Any]] = [
|
|
["thread_root_id": ""], ["thread_root_id": 42], ["unknown": "value"],
|
|
]
|
|
for extra in cases {
|
|
var raw: [String: Any] = [
|
|
"event_id": "reply", "community_id": "community", "channel_id": "channel",
|
|
]
|
|
raw.merge(extra) { _, new in new }
|
|
#expect(BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [BuzzPushNavigationTarget.userInfoKey: raw]
|
|
) == nil)
|
|
}
|
|
}
|
|
|
|
@Test func `Empty reply marker preserves channel navigation`() {
|
|
let thread = BuzzPushNavigationTarget.threadRootID(in: [["e", "", "", "reply"]])
|
|
#expect(thread == nil)
|
|
let target = BuzzPushNavigationTarget(
|
|
eventID: "message", communityID: "community", channelID: "channel", threadRootID: thread
|
|
)
|
|
#expect(BuzzPushNavigationTarget.decodeIfPresent(
|
|
from: [BuzzPushNavigationTarget.userInfoKey: target.userInfoValue]
|
|
) == target)
|
|
}
|
|
|
|
@Test func `Thread destination keeps direct parent and broadcast semantics`() {
|
|
let parent = String(repeating: "a", count: 64)
|
|
let tags = [["e", "outer-root", "", "root"], ["e", parent, "", "reply"]]
|
|
#expect(BuzzPushNavigationTarget.threadRootID(in: tags) == parent)
|
|
#expect(BuzzPushNavigationTarget.threadRootID(in: tags + [["broadcast", "1"]]) == nil)
|
|
#expect(BuzzPushNavigationTarget.threadRootID(in: [["e", "outer-root", "", "root"]]) == nil)
|
|
}
|
|
|
|
@Test func `Last valid reply marker wins despite trailing malformed markers`() {
|
|
let first = String(repeating: "a", count: 64)
|
|
let last = String(repeating: "B", count: 64)
|
|
let invalidIDs = ["", "bad", String(repeating: "a", count: 63),
|
|
String(repeating: "a", count: 65), String(repeating: "g", count: 64),
|
|
String(repeating: "é", count: 64)]
|
|
for invalid in invalidIDs {
|
|
let invalidTag = ["e", invalid, "", "reply"]
|
|
#expect(BuzzPushNavigationTarget.threadRootID(in: [invalidTag]) == nil)
|
|
#expect(BuzzPushNavigationTarget.threadRootID(in: [
|
|
["e", first, "", "reply"], ["e", last, "", "reply"], invalidTag,
|
|
]) == last.lowercased())
|
|
}
|
|
}
|