Fix E2E test gaps and add comprehensive E2E + parity test suites

- Fix pull consumer fetch: send original stream subject in HMSG (not inbox)
  so NATS client distinguishes data messages from control messages
- Fix MaxAge expiry: add background timer in StreamManager for periodic pruning
- Fix JetStream wire format: Go-compatible anonymous objects with string enums,
  proper offset-based pagination for stream/consumer list APIs
- Add 42 E2E black-box tests (core messaging, auth, TLS, accounts, JetStream)
- Add ~1000 parity tests across all subsystems (gaps closure)
- Update gap inventory docs to reflect implementation status
This commit is contained in:
Joseph Doherty
2026-03-12 14:09:23 -04:00
parent 79c1ee8776
commit c30e67a69d
226 changed files with 17801 additions and 709 deletions

View File

@@ -1,7 +1,24 @@
using System.Buffers.Binary;
using System.Text;
namespace NATS.Server.Mqtt;
public static class MqttPacketWriter
{
public static byte[] WriteString(string value)
=> WriteBytes(Encoding.UTF8.GetBytes(value));
public static byte[] WriteBytes(ReadOnlySpan<byte> bytes)
{
if (bytes.Length > ushort.MaxValue)
throw new ArgumentOutOfRangeException(nameof(bytes), "MQTT length-prefixed field cannot exceed 65535 bytes.");
var buffer = new byte[2 + bytes.Length];
BinaryPrimitives.WriteUInt16BigEndian(buffer.AsSpan(0, 2), (ushort)bytes.Length);
bytes.CopyTo(buffer.AsSpan(2));
return buffer;
}
public static byte[] Write(MqttControlPacketType type, ReadOnlySpan<byte> payload, byte flags = 0)
{
if (type == MqttControlPacketType.Reserved)
@@ -18,8 +35,10 @@ public static class MqttPacketWriter
internal static byte[] EncodeRemainingLength(int value)
{
if (value < 0 || value > 268_435_455)
throw new ArgumentOutOfRangeException(nameof(value), "MQTT remaining length must be between 0 and 268435455.");
if (value < 0 || value > MqttProtocolConstants.MaxPayloadSize)
throw new ArgumentOutOfRangeException(
nameof(value),
$"MQTT remaining length must be between 0 and {MqttProtocolConstants.MaxPayloadSize}.");
Span<byte> scratch = stackalloc byte[4];
var index = 0;