Merge remote-tracking branch 'origin/feat/private-groups' into feat/integration-all

# Conflicts:
#	bitchat/Protocols/BitchatProtocol.swift
#	bitchat/Protocols/PeerCapabilities+Local.swift
#	bitchat/Services/BLE/BLEOutboundPacketPolicy.swift
#	bitchat/Services/BLE/BLEService.swift
#	bitchat/Services/Transport.swift
#	bitchat/Sync/GossipSyncManager.swift
#	bitchat/Sync/SyncTypeFlags.swift
#	bitchat/ViewModels/ChatTransportEventCoordinator.swift
#	bitchat/ViewModels/ChatViewModel.swift
#	bitchat/ViewModels/NostrInboundPipeline.swift
#	bitchatTests/ChatTransportEventCoordinatorContextTests.swift
#	bitchatTests/GossipSyncManagerTests.swift
#	localPackages/BitFoundation/Sources/BitFoundation/MessageType.swift
This commit is contained in:
jack
2026-07-06 22:13:31 +02:00
32 changed files with 2887 additions and 36 deletions
@@ -0,0 +1,62 @@
//
// SyncTypeFlagsGroupTests.swift
// bitchat
//
// Wire-compat proof for the groupMessage sync bit (bit 10): the types
// bitfield widens from 1 to 2 bytes, and clients that don't know the bit
// simply ignore it.
//
// This is free and unencumbered software released into the public domain.
// For more information, see <https://unlicense.org>
//
import Foundation
import Testing
import BitFoundation
@testable import bitchat
struct SyncTypeFlagsGroupTests {
@Test func groupMessageOccupiesBitTen() {
#expect(SyncTypeFlags.groupMessage.rawValue == 1 << 10)
#expect(SyncTypeFlags.groupMessage.contains(.groupMessage))
#expect(!SyncTypeFlags.publicMessages.contains(.groupMessage))
}
@Test func extendedBitfieldWidensToTwoBytes() throws {
// Legacy flags fit one byte
#expect(SyncTypeFlags.publicMessages.toData() == Data([0x03]))
// the group bit widens the little-endian encoding to two bytes.
let combined = SyncTypeFlags.publicMessages.union(.groupMessage)
let encoded = try #require(combined.toData())
#expect(encoded == Data([0x03, 0x04]))
let decoded = try #require(SyncTypeFlags.decode(encoded))
#expect(decoded == combined)
#expect(Set(decoded.toMessageTypes()) == Set([.announce, .message, .groupMessage]))
}
@Test func unknownBitsAreIgnoredNotRejected() throws {
// An "old client" reading a 2-byte field keeps the raw bits but maps
// unknown bit indices to no message type it answers with the types
// it knows instead of dropping the request.
let futuristic = try #require(SyncTypeFlags.decode(Data([0x03, 0xFC])))
#expect(Set(futuristic.toMessageTypes()) == Set([.announce, .message, .groupMessage]))
#expect(futuristic.contains(.announce))
#expect(futuristic.contains(.message))
}
@Test func requestSyncPacketRoundTripsGroupFlag() throws {
let types = SyncTypeFlags.publicMessages.union(.groupMessage)
let packet = RequestSyncPacket(p: 8, m: 1024, data: Data([0xAB, 0xCD]), types: types)
let encoded = packet.encode()
let decoded = try #require(RequestSyncPacket.decode(from: encoded))
#expect(decoded.types == types)
#expect(decoded.types?.contains(.groupMessage) == true)
#expect(decoded.p == 8)
#expect(decoded.m == 1024)
#expect(decoded.data == Data([0xAB, 0xCD]))
}
}