Fix SyncTypeFlags tests: bit 8 (boardPost) is a known type (#1390)

#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 <jackjackbits@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jack
2026-07-07 14:35:51 +02:00
committed by GitHub
co-authored by jack Claude Fable 5
parent 3c610a83cd
commit cee2bcd535
+19 -9
View File
@@ -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)
}
}