dropp baes64 use binary
This commit is contained in:
@@ -372,12 +372,53 @@ def test_relay_rpc_round_trips_http_request_to_peer():
|
||||
assert json.loads(response["body"]) == {"ok": True, "path": "/v1/chat/completions"}
|
||||
|
||||
|
||||
def test_binary_relay_frame_codecs_interoperate():
|
||||
"""Node and relay ship the same binary frame format as separate copies."""
|
||||
import os
|
||||
|
||||
from meshnet_node import relay_bridge
|
||||
from meshnet_relay import server as relay_server
|
||||
|
||||
header = {"request_id": "r-1", "status": 200, "headers": {"X": "y"}}
|
||||
body = os.urandom(4096)
|
||||
for encoder, decoder in (
|
||||
(relay_bridge.encode_binary_frame, relay_server.decode_binary_frame),
|
||||
(relay_server.encode_binary_frame, relay_bridge.decode_binary_frame),
|
||||
):
|
||||
assert decoder(encoder(header, body)) == (header, body)
|
||||
|
||||
try:
|
||||
relay_server.decode_binary_frame(b"not a frame")
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("garbage bytes must not decode as a binary frame")
|
||||
|
||||
|
||||
def test_activation_compression_round_trips_and_skips_small_bodies():
|
||||
"""Pipeline hops zstd-compress large activations; tiny decode bodies pass raw."""
|
||||
import os
|
||||
|
||||
from meshnet_node.server import _decompress_body
|
||||
from meshnet_node.torch_server import _maybe_compress_activation
|
||||
|
||||
small = os.urandom(1024)
|
||||
assert _maybe_compress_activation(small) == (small, None)
|
||||
|
||||
large = os.urandom(96 * 1024) * 2 # repetition so zstd actually shrinks it
|
||||
wire, encoding = _maybe_compress_activation(large)
|
||||
assert encoding == "zstd"
|
||||
assert len(wire) < len(large)
|
||||
assert _decompress_body(wire, encoding) == large
|
||||
|
||||
|
||||
def test_relay_rpc_carries_activation_sized_frames():
|
||||
"""A >1 MiB activation body must survive the full relay round trip.
|
||||
|
||||
Regression: the websockets library caps frames at 1 MiB by default, so
|
||||
prefill activations forwarded via /rpc/<peer> died with close code 1009
|
||||
at every hop (requester → relay, relay → bridge, bridge → relay → requester).
|
||||
The body now travels as binary frames — raw bytes, no base64.
|
||||
"""
|
||||
import http.server
|
||||
import os
|
||||
|
||||
@@ -278,6 +278,43 @@ def test_session_is_stable_and_decode_payloads_are_single_token():
|
||||
assert head_backend.released == [session_id]
|
||||
|
||||
|
||||
def test_large_prefill_activation_survives_zstd_compressed_hop():
|
||||
"""A prefill body above _COMPRESS_MIN_BYTES travels the hop zstd-compressed.
|
||||
|
||||
The head compresses and sets X-Meshnet-Encoding; the tail's /forward must
|
||||
decompress before shape validation, so a passing generation proves the
|
||||
compressed round trip (a mishandled encoding fails validation with 400).
|
||||
"""
|
||||
|
||||
class _BigHeadBackend(_CachedHeadBackend):
|
||||
def encode_prompt(self, prompt, session_id=None):
|
||||
self.prefills.append(session_id)
|
||||
if session_id:
|
||||
self._seq[session_id] = 2048
|
||||
return TensorPayload(
|
||||
body=b"\x00" * (1 * 2048 * 32 * 2), # 128 KiB, above the zstd threshold
|
||||
shape=[1, 2048, 32],
|
||||
attention_mask_header=None,
|
||||
position_ids_header=None,
|
||||
)
|
||||
|
||||
head_backend = _BigHeadBackend()
|
||||
tail_backend = _CachedTailBackend([(" a", 1), (" b", 2)])
|
||||
head = TorchNodeServer(backend=head_backend, tracker_mode=True)
|
||||
tail = TorchNodeServer(backend=tail_backend)
|
||||
head_port = head.start()
|
||||
tail_port = tail.start()
|
||||
try:
|
||||
content = _chat_once(head_port, tail_port, max_tokens=2)
|
||||
finally:
|
||||
head.stop()
|
||||
tail.stop()
|
||||
|
||||
assert content == " a b"
|
||||
assert tail_backend.calls[0]["mode"] == "prefill"
|
||||
assert tail_backend.calls[0]["shape"] == [1, 2048, 32]
|
||||
|
||||
|
||||
def test_eos_token_id_stops_generation():
|
||||
head_backend = _CachedHeadBackend()
|
||||
tail_backend = _CachedTailBackend([(" a", 1), ("", 99)])
|
||||
|
||||
Reference in New Issue
Block a user