mirror of
https://github.com/block/buzz.git
synced 2026-11-03 07:51:22 +00:00
## Summary Deletes mobile code that no longer has a user-reachable path and has no counterpart in buzz-app, so it is unlikely to come back for parity. Net: 104 files, about 5,500 lines removed. No intended behavior change. - **iOS native message menu and action surface:** `NativeMessageMenu.swift` and `NativeMessageActionSurface.swift`, the `message`/`supportsMessage` coordinator branches, and the Dart selection hook. Dart stopped creating this view in [#8280](https://github.com/block/buzz/pull/8280). The native reactions sheet in the same coordinator is kept. - **Old home quick-actions launcher and `ComposeMorphIcon`:** only instantiated in tests since the nav-bar creation actions replaced them. - **Retired local theme stack:** `ThemeNotifier`, `AccentNotifier`, `SchemeNotifier`, `adaptive_theme.dart`, `AccentPickerPage`, the appearance-mode sheet and their helpers. These predate per-community theme sync. The legacy prefs migration in `community_theme_preference.dart` is kept. - **Unused widgets:** `ProfileAvatar` and `MaskedAvatarBadge`. - **Push permission-status plumbing:** the iOS `notificationAuthorizationStatus`/`openNotificationSettings` handlers, plus the uncalled strict age-gate snapshot registration and its Swift `syncAgeGatePushSnapshot` path. - **Orphaned files** with no importer: `profile_text_edit_sheet`, `editor_option_button`, `retained_page_transition`, `tappable_flapping_bee`, `agent_model_info`, `community_bot_profiles`, `sheet_divider`, `success_haptic`. - **Uncalled helpers:** the `pickAndUpload*`/camera helpers in `media_upload.dart`, unused `NostrFilters` builders, `mediaGetHeadersFor*`, and about 20 other uncalled functions, providers and styles. - **Removed-UI leftovers:** the never-wired invite directory providers, `AuthNotifier.signOut` and `removeActiveCommunityForSignOut` (the Sign out row is gone), `renameCommunity`, `HomePage.profilePageBuilder`/`SettingsPage.embedded`, and the create-forum branches of the create-channel sheet. Forum viewing is unchanged. Tests that only covered deleted code are removed. Tests of surviving code that used deleted helpers as drivers were repointed to the surviving API. An audit of `mobile/android` found no dead Kotlin, resources, manifest entries or Gradle dependencies, so Android code is unchanged. ## Validation - `flutter analyze`: no issues. - After rebasing onto main ([93b8b8f](https://github.com/block/buzz/commit/93b8b8febc)), `just mobile-check` is clean (format and analyze), and `just mobile-test` passes (4,070 passed, 35 skipped, 0 failed, plus the push-unconfigured and secp256k1 suites). - `dart format`: clean. - Android: `just mobile-build-android` builds the debug APK, and `./gradlew :app:testDebugUnitTest` passes. - iOS: `build-for-testing` succeeds and BuzzPushKit `swift test` passes (65 tests). In RunnerTests, 97 of 98 pass. `testNativeNavigationTitleExpandsAgainAtTop` fails, but it fails the same way on unmodified `main` (acf56fff6f) on the same machine (Xcode 27, iPhone 17 Pro simulator), so it is not caused by this change. - Agent review of the diff ran. Its one blocker (stale `project.pbxproj` entries for the deleted Swift files) is fixed. - In-app smoke run at [66141c1](66141c10b9): a debug build on a fresh iPhone 17 Pro simulator (iOS 27), signed in to the internal community. The following flows all worked with no errors: - Home: the New menu (channel, DM, workspace, chat) and the create-channel sheet, including its channel-type options. - A chat, with the message action sheet (reactions row, Reply, Copy link, Remind me, Mark unread, Copy text, Edit and Delete). - Appearance: the previews, and cycling the System and Light modes. - Settings: the profile header, the display name editor, and Edit photo (Image and Emoji tabs). - The Agents directory. - Search, including the Channels filter, plus opening a team channel from the results. - Tapping a reaction summary, which opens the native iOS Reactions sheet. - The recording isn't attached here because it shows internal channels and messages. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
195 lines
9.1 KiB
Swift
195 lines
9.1 KiB
Swift
import UIKit
|
|
import XCTest
|
|
@testable import Buzz
|
|
|
|
final class NativeMessageImageLoaderTests: XCTestCase {
|
|
private func loader(limit: Int = 1) -> NativeMessageImageLoader {
|
|
let configuration = URLSessionConfiguration.ephemeral
|
|
configuration.protocolClasses = [MessageImageProtocol.self]
|
|
return NativeMessageImageLoader(configuration: configuration, maximumConcurrent: limit)
|
|
}
|
|
|
|
@MainActor func testRejectsDeclaredOversizeWithoutFinishingBody() async {
|
|
let done = expectation(description: "rejected")
|
|
MessageImageProtocol.start = { transport in
|
|
transport.client?.urlProtocol(transport, didReceive: HTTPURLResponse(
|
|
url: transport.request.url!, statusCode: 200, httpVersion: nil,
|
|
headerFields: ["Content-Length": "\(NativeMessageImageLoader.maximumBytes + 1)", "Content-Type": "image/png"]
|
|
)!, cacheStoragePolicy: .notAllowed)
|
|
// Let URLProtocol deliver its headers without finishing the body. A
|
|
// completion-handler byte check would hang here, rather than reject.
|
|
transport.client?.urlProtocol(transport, didLoad: Data(count: 1024))
|
|
}
|
|
let loader = loader()
|
|
_ = loader.load(URLRequest(url: URL(string: "https://example.com/declared")!)) { image in
|
|
XCTAssertNil(image)
|
|
done.fulfill()
|
|
}
|
|
await fulfillment(of: [done], timeout: 2)
|
|
}
|
|
|
|
@MainActor func testRejectsChunkedOversizeWithoutWaitingForCompletion() async {
|
|
let done = expectation(description: "stream cancelled")
|
|
MessageImageProtocol.start = { transport in
|
|
transport.client?.urlProtocol(transport, didReceive: HTTPURLResponse(
|
|
url: transport.request.url!, statusCode: 200, httpVersion: nil, headerFields: nil
|
|
)!, cacheStoragePolicy: .notAllowed)
|
|
transport.client?.urlProtocol(transport, didLoad: Data(count: NativeMessageImageLoader.maximumBytes))
|
|
transport.client?.urlProtocol(transport, didLoad: Data([0]))
|
|
// No finish callback: the streaming byte guard must terminate the load.
|
|
}
|
|
let loader = loader()
|
|
_ = loader.load(URLRequest(url: URL(string: "https://example.com/chunked")!)) { image in
|
|
XCTAssertNil(image)
|
|
done.fulfill()
|
|
}
|
|
await fulfillment(of: [done], timeout: 2)
|
|
}
|
|
|
|
@MainActor func testDeduplicatesAndCancellationReleasesAdmission() async {
|
|
let first = expectation(description: "first admitted")
|
|
let second = expectation(description: "second admitted after cancellation")
|
|
var started = [String]()
|
|
MessageImageProtocol.start = { transport in
|
|
DispatchQueue.main.async {
|
|
started.append(transport.request.url!.path)
|
|
if started.count == 1 { first.fulfill() } else { second.fulfill() }
|
|
}
|
|
}
|
|
let loader = loader()
|
|
let request = URLRequest(url: URL(string: "https://example.com/shared")!)
|
|
let cancelFirst = loader.load(request) { _ in XCTFail("cancelled subscriber called") }
|
|
let cancelDuplicate = loader.load(request) { _ in XCTFail("cancelled duplicate called") }
|
|
let cancelQueued = loader.load(URLRequest(url: URL(string: "https://example.com/queued")!)) { _ in
|
|
XCTFail("cancelled queued subscriber called")
|
|
}
|
|
let cancelNext = loader.load(URLRequest(url: URL(string: "https://example.com/next")!)) { _ in }
|
|
await fulfillment(of: [first], timeout: 2)
|
|
XCTAssertEqual(started, ["/shared"])
|
|
cancelFirst()
|
|
cancelQueued()
|
|
// One subscriber remains: cancelling the first must not cancel its peer.
|
|
let turn = expectation(description: "cancellation processed")
|
|
DispatchQueue.main.async { turn.fulfill() }
|
|
await fulfillment(of: [turn], timeout: 2)
|
|
XCTAssertEqual(started, ["/shared"])
|
|
cancelDuplicate()
|
|
await fulfillment(of: [second], timeout: 2)
|
|
XCTAssertEqual(started, ["/shared", "/next"])
|
|
cancelNext()
|
|
}
|
|
|
|
@MainActor func testCachesDecodedImages() async {
|
|
let done = expectation(description: "decoded")
|
|
let image = UIGraphicsImageRenderer(size: CGSize(width: 1, height: 1)).pngData { _ in }
|
|
var requests = 0
|
|
MessageImageProtocol.start = { transport in
|
|
requests += 1
|
|
transport.client?.urlProtocol(transport, didReceive: HTTPURLResponse(
|
|
url: transport.request.url!, statusCode: 200, httpVersion: nil, headerFields: nil
|
|
)!, cacheStoragePolicy: .notAllowed)
|
|
transport.client?.urlProtocol(transport, didLoad: image)
|
|
transport.client?.urlProtocolDidFinishLoading(transport)
|
|
}
|
|
let loader = loader()
|
|
let request = URLRequest(url: URL(string: "https://example.com/cached")!)
|
|
_ = loader.load(request) { image in XCTAssertNotNil(image); done.fulfill() }
|
|
await fulfillment(of: [done], timeout: 2)
|
|
var cached = false
|
|
_ = loader.load(request) { image in cached = image != nil }
|
|
XCTAssertTrue(cached)
|
|
XCTAssertEqual(requests, 1)
|
|
}
|
|
}
|
|
|
|
private final class MessageImageProtocol: URLProtocol {
|
|
static var start: ((MessageImageProtocol) -> Void)?
|
|
override class func canInit(with request: URLRequest) -> Bool { true }
|
|
override class func canonicalRequest(for request: URLRequest) -> URLRequest { request }
|
|
override func startLoading() { Self.start?(self) }
|
|
override func stopLoading() {}
|
|
}
|
|
|
|
|
|
final class NativeReactionDetailsTests: XCTestCase {
|
|
@MainActor func testInlineEmojiAvatarRendersEmojiAndBackground() {
|
|
let controller = NativeReactionDetailsViewController(data: [
|
|
"reactions": [["emoji": "❤️", "label": "Heart", "users": ["person"]]],
|
|
"profiles": ["person": ["name": "Kenny", "avatarEmoji": "😊", "avatarColor": NSNumber(value: UInt32(0xFFFF6B9A))]],
|
|
])
|
|
let cell = controller.tableView(UITableView(), cellForRowAt: IndexPath(row: 0, section: 0))
|
|
let row = cell.contentView.subviews.compactMap { $0 as? UIStackView }.first!
|
|
let avatar = row.arrangedSubviews[0] as! NativeMessageGlyph
|
|
XCTAssertEqual(avatar.subviews.compactMap { $0 as? UILabel }.first?.text, "😊")
|
|
XCTAssertEqual(avatar.backgroundColor, UIColor(red: 1, green: 107.0 / 255, blue: 154.0 / 255, alpha: 1))
|
|
controller.updateProfiles(["person": ["name": "Kenny", "avatarEmoji": "🎉", "avatarColor": NSNumber(value: UInt32(0xFFFFE75C))]])
|
|
let updated = controller.tableView(UITableView(), cellForRowAt: IndexPath(row: 0, section: 0))
|
|
let updatedRow = updated.contentView.subviews.compactMap { $0 as? UIStackView }.first!
|
|
XCTAssertEqual(updatedRow.arrangedSubviews[0].subviews.compactMap { $0 as? UILabel }.first?.text, "🎉")
|
|
}
|
|
|
|
@MainActor func testTogglesListEveryReactorAndRelabelUpdatedProfiles() {
|
|
let controller = NativeReactionDetailsViewController(data: [
|
|
"reactions": [
|
|
["emoji": "❤️", "label": "Heart", "count": 2, "users": ["human", "agent"]],
|
|
["emoji": "🔥", "label": "Fire", "count": 1, "users": ["agent"]],
|
|
],
|
|
"profiles": ["human": ["name": "Honey"], "agent": ["name": "Honey (agent)"]],
|
|
])
|
|
var toggled: [String] = []
|
|
controller.onToggle = { toggled.append($0) }
|
|
controller.loadViewIfNeeded()
|
|
let table = UITableView()
|
|
func labels() -> [String] {
|
|
(0..<controller.tableView(table, numberOfRowsInSection: 0)).map {
|
|
controller.tableView(table, cellForRowAt: IndexPath(row: $0, section: 0)).accessibilityLabel ?? ""
|
|
}
|
|
}
|
|
func descendants(_ view: UIView) -> [UIView] {
|
|
view.subviews.flatMap { [$0] + descendants($0) }
|
|
}
|
|
func tap(_ label: String) {
|
|
let button = descendants(controller.view).compactMap { $0 as? UIButton }
|
|
.first { $0.accessibilityLabel == label }
|
|
XCTAssertNotNil(button, label)
|
|
button?.sendActions(for: .primaryActionTriggered)
|
|
}
|
|
XCTAssertEqual(labels(), ["Honey, Heart", "Honey (agent), Heart", "Honey (agent), Fire"])
|
|
tap("Fire 1")
|
|
tap("Heart 2")
|
|
XCTAssertEqual(toggled, ["🔥", "❤️"])
|
|
controller.updateProfiles(["agent": ["name": "Helper (agent)"]])
|
|
XCTAssertEqual(labels(), ["Honey, Heart", "Helper (agent), Heart", "Helper (agent), Fire"])
|
|
}
|
|
}
|
|
|
|
|
|
final class NativeMessageLayoutTests: XCTestCase {
|
|
private func descendants(_ view: UIView) -> [UIView] {
|
|
view.subviews.flatMap { [$0] + descendants($0) }
|
|
}
|
|
|
|
@MainActor func testReactionFiltersFitAccessibilityText() {
|
|
let parent = UIViewController()
|
|
let controller = NativeReactionDetailsViewController(data: [
|
|
"reactions": [["emoji": "❤️", "label": "Heart", "count": 12345, "users": ["a"]]],
|
|
])
|
|
parent.addChild(controller)
|
|
parent.setOverrideTraitCollection(UITraitCollection(preferredContentSizeCategory: .accessibilityExtraExtraExtraLarge), forChild: controller)
|
|
parent.view.addSubview(controller.view)
|
|
controller.view.frame = CGRect(x: 0, y: 0, width: 390, height: 844)
|
|
controller.view.setNeedsLayout()
|
|
controller.view.layoutIfNeeded()
|
|
let filter = descendants(controller.view).compactMap { $0 as? UIButton }
|
|
.first { $0.accessibilityLabel == "Heart 12345" }
|
|
XCTAssertNotNil(filter)
|
|
let viewport = descendants(controller.view).compactMap { $0 as? UIScrollView }
|
|
.first { !($0 is UITableView) }
|
|
XCTAssertNotNil(viewport)
|
|
let needed = filter?.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height ?? 0
|
|
XCTAssertGreaterThan(needed, 48)
|
|
XCTAssertGreaterThanOrEqual(viewport?.bounds.height ?? 0, needed)
|
|
XCTAssertGreaterThanOrEqual(filter?.bounds.height ?? 0, needed)
|
|
}
|
|
}
|