"""TDD — push uses plain MWP frames over HTTPS POST. Rules: P1 _frame_generator yields raw MWP frames — each starts with b"muse" magic. P2 push_stream_coro sends Content-Type: application/x-muse-wire. P3 push_stream_coro uses client.post(), not client.stream() — upload-first means we POST the full body and read the response after, not concurrently. """ from __future__ import annotations import inspect # --------------------------------------------------------------------------- # P1 — _frame_generator yields raw MWP frames # --------------------------------------------------------------------------- def test_p1_frame_generator_mwp_magic() -> None: from muse.core.transport import _frame_generator frames = list(_frame_generator([], [], [], local_head=None)) assert frames, "_frame_generator must yield at least H and E frames" for i, frame in enumerate(frames): assert len(frame) >= 4, f"Frame {i} too short: {len(frame)} bytes" assert frame[:4] == b"muse", ( f"Frame {i} starts with {frame[:4]!r} — expected MWP magic b'muse'." ) def test_p1_frame_generator_with_objects() -> None: from muse.core._types import blob_id from muse.core.transport import _frame_generator raw = b"x" * 1024 oid = blob_id(raw) obj = {"object_id": oid, "content": raw, "path": "a.txt", "encoding": "raw"} frames = list(_frame_generator([obj], [], [], local_head=None)) assert len(frames) >= 3, "Expected H + O + E frames" for i, frame in enumerate(frames): assert frame[:4] == b"muse", ( f"Frame {i} starts with {frame[:4]!r}, not MWP magic." ) # --------------------------------------------------------------------------- # P2 — push_stream_coro uses application/x-muse-wire # --------------------------------------------------------------------------- def test_p2_push_uses_wire_content_type() -> None: from muse.core import transport as _t source = inspect.getsource(_t.HttpTransport.push_stream_coro) assert "WIRE_CONTENT_TYPE" in source or "application/x-muse-wire" in source, ( "push_stream_coro must use WIRE_CONTENT_TYPE (application/x-muse-wire)." ) # --------------------------------------------------------------------------- # P3 — push_stream_coro uses client.post(), not client.stream() # --------------------------------------------------------------------------- def test_p3_push_upload_first() -> None: from muse.core import transport as _t source = inspect.getsource(_t.HttpTransport.push_stream_coro) assert "client.stream(" not in source, ( "push_stream_coro uses client.stream() — replace with client.post()." )