From cee2bcd535657a4ec7d9ee7af8dfa805623c2737 Mon Sep 17 00:00:00 2001 From: jack <212554440+jackjackbits@users.noreply.github.com> Date: Tue, 7 Jul 2026 14:35:51 +0200 Subject: [PATCH] Fix SyncTypeFlags tests: bit 8 (boardPost) is a known type (#1390) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #1379 (board) mapped bit 8 -> .boardPost in SyncTypeFlags, making it a known bit that spills the encoded bitfield into a second byte. But the phantom-bit tests (added by #1373) predate that change and still assert bit 8 is unknown, so main went red once both landed. Neither PR's CI caught it — each was green against a main without the other. The impl is correct (board is a real sync type); the tests were stale. Update them to treat bits 9+ as phantom, expect the all-known field to serialize to 2 bytes, and add a regression test that the board bit survives decode while the phantom high bits are stripped. Co-authored-by: jack Co-authored-by: Claude Fable 5 --- bitchatTests/Sync/SyncTypeFlagsTests.swift | 28 +++++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/bitchatTests/Sync/SyncTypeFlagsTests.swift b/bitchatTests/Sync/SyncTypeFlagsTests.swift index a3ab3cc4..d4684afc 100644 --- a/bitchatTests/Sync/SyncTypeFlagsTests.swift +++ b/bitchatTests/Sync/SyncTypeFlagsTests.swift @@ -13,31 +13,41 @@ struct SyncTypeFlagsTests { } @Test func decodeDropsPhantomBits() { - // Bits 8+ map to no message type. They must not survive decode as - // phantom membership. - let phantom = Data([0x00, 0xFF]) // bits 8..15 set, no known type + // Bits 9+ map to no message type (bit 8 is boardPost). They must not + // survive decode as phantom membership. + let phantom = Data([0x00, 0xFE]) // bits 9..15 set, no known type let decoded = SyncTypeFlags.decode(phantom) #expect(decoded?.rawValue == 0) #expect(decoded?.toMessageTypes().isEmpty == true) } + @Test func boardBitSurvivesDecode() { + // Bit 8 maps to boardPost and spills the field into a second byte; + // it must survive decode while the phantom high bits are stripped. + let mixed = Data([0x00, 0xFF]) // bit 8 (board) known, bits 9..15 phantom + let decoded = SyncTypeFlags.decode(mixed) + #expect(decoded?.contains(.board) == true) + #expect(decoded?.rawValue == 0b1_0000_0000) + } + @Test func phantomBitsAreStrippedButKnownBitsSurvive() { - // Low byte = announce(0) + message(1); high byte = phantom. - let mixed = Data([0b0000_0011, 0xFF]) + // Low byte = announce(0) + message(1); high byte bits 9+ are phantom. + let mixed = Data([0b0000_0011, 0xFE]) let decoded = SyncTypeFlags.decode(mixed) #expect(decoded?.contains(.announce) == true) #expect(decoded?.contains(.message) == true) - // Only the two known bits remain; phantom high byte is gone. + // Only the two known bits remain; phantom high bits are gone. #expect(decoded?.rawValue == 0b0000_0011) } @Test func rawValueInitNormalizesPhantomBits() { let flags = SyncTypeFlags(rawValue: 0xFFFF_FFFF_FFFF_FFFF) - // Every known type bit is set; nothing above them survives, so the - // field serializes to a single byte. + // Every known type bit is set; nothing above them survives. boardPost + // occupies bit 8, so the known set spills into a second byte. #expect(flags.contains(.announce)) #expect(flags.contains(.fileTransfer)) + #expect(flags.contains(.board)) let data = flags.toData() - #expect(data?.count == 1) + #expect(data?.count == 2) } }