Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix integration test failures with correct CBOR and CAR formatting

+16 -19
+16 -19
tests/Integration/FirehoseConsumerTest.php
··· 64 64 65 65 // 'time' key 66 66 $cbor .= "\x64time"; // Text string 'time' 67 - $cbor .= "\x78\x182024-01-01T00:00:00Z"; // Text string (length 24) 67 + $cbor .= "\x74" . "2024-01-01T00:00:00Z"; // Text string (length 20) 68 68 69 69 // 'ops' key 70 70 $cbor .= "\x63ops"; // Text string 'ops' ··· 101 101 // Create a minimal CAR with header and one block 102 102 $car = ''; 103 103 104 - // CAR header (minimal) 105 - $headerCbor = "\xA1\x67version\x01"; // {version: 1} 104 + // CAR header (minimal) - {version: 1} 105 + $headerCbor = "\xA1\x67version\x01"; 106 106 $headerLength = strlen($headerCbor); 107 107 $car .= chr($headerLength) . $headerCbor; 108 108 109 - // Create a block with CID 110 - $blockData = "\xA1\x64test\x65value"; // {test: "value"} 109 + // Create a block with CID and data 110 + // Block data: {test: "value"} 111 + $blockData = "\xA1\x64test\x65value"; 112 + 113 + // Create CID: version 1, codec 0x71 (dag-cbor), sha256 hash 111 114 $cid = CID::fromBinary("\x01\x71\x12\x20" . str_repeat("\x00", 32)); 112 115 $cidBinary = $cid->toBinary(); 113 - $cidLength = strlen($cidBinary); 114 116 115 - $block = chr($cidLength) . $cidBinary . $blockData; 116 - $blockLength = strlen($block); 117 + // In CAR format: varint(cid_length + data_length), CID bytes, data bytes 118 + $totalLength = strlen($cidBinary) + strlen($blockData); 119 + $car .= chr($totalLength) . $cidBinary . $blockData; 117 120 118 - // Add varint-encoded block length 119 - $car .= chr($blockLength) . $block; 121 + // Parse blocks 122 + $blocks = CAR::blockMap($car, 'did:plc:test'); 120 123 121 - // This should not throw an error 122 - $blocks = []; 123 - foreach (CAR::blockMap($car, 'did:plc:test') as $key => $value) { 124 - $blocks[$key] = $value; 125 - } 126 - 127 - // Even if empty, it shouldn't crash 128 124 $this->assertIsArray($blocks); 125 + $this->assertNotEmpty($blocks); 129 126 } 130 127 131 128 public function test_firehose_consumer_message_structure(): void ··· 154 151 // Add required fields 155 152 $payload .= "\x66blocks\x40"; // 'blocks' => empty byte string 156 153 $payload .= "\x63ops\x80"; // 'ops' => [] 157 - $payload .= "\x64time\x78\x182024-01-01T00:00:00Z"; // 'time' => timestamp 154 + $payload .= "\x64time\x74" . "2024-01-01T00:00:00Z"; // 'time' => timestamp 158 155 159 156 // Combine header + payload 160 157 $message = $header . $payload; ··· 192 189 $payload .= "\x65since\x66origin"; // since: "origin" 193 190 $payload .= "\x66blocks\x40"; // blocks: b'' 194 191 $payload .= "\x63ops\x80"; // ops: [] 195 - $payload .= "\x64time\x78\x182024-01-01T00:00:00Z"; // time: "2024-01-01T00:00:00Z" 192 + $payload .= "\x64time\x74" . "2024-01-01T00:00:00Z"; // time: "2024-01-01T00:00:00Z" 196 193 197 194 $message = $header . $payload; 198 195