fix(tests): correct patch-contract tests (test_05)

- set body via msg["body"] / read via msg["body"]; do not await message
  send() (returns None in slixmpp)
- str(msg["from"]) / str(pres["from"]) before .startswith (JID not str)
- mod_muc_unique: query a bare JID on the MUC component (a room JID), not a
  user on the main host. The item-not-found handler is registered on the
  component; a query to the user host is merely service-unavailable.
- offline-affiliate test: unlock the freshly-created room with configure_muc
  before setting affiliations

Verified the portmanager network_default_read_size patch end-to-end: chat
bodies up to 12000 bytes are delivered intact.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Part-of: <http://gitlab.vnc.biz/uxf/vnctalk-prosody/-/merge_requests/3>
This commit is contained in:
2026-07-15 17:58:02 +02:00
co-authored by Claude Opus 4.8
parent dca5a6ec11
commit ed2d5db342
+15 -10
View File
@@ -21,8 +21,11 @@ class TestModMucUniquePatch:
if not muc_domain:
pytest.skip("No MUC domain configured")
# Send to a bare JID (not the MUC service host)
target = f"someuser@{xmpp_config['domain']}"
# Send to a bare JID on the MUC component (a room JID), not the service
# host itself. mod_muc_unique returns item-not-found for bare JIDs and a
# unique name only for the host JID. (It is loaded on the MUC component,
# so a query to the main user host would just be service-unavailable.)
target = f"someroom_{uuid.uuid4().hex[:8]}@{muc_domain}"
iq = xmpp_client.make_iq_get(ito=target)
ET.SubElement(iq.xml, "{http://jabber.org/protocol/muc#unique}unique")
try:
@@ -81,16 +84,16 @@ class TestPortmanagerPatch:
def on_message(msg):
nonlocal received_body
if msg["type"] == "chat" and msg.body:
received_body = str(msg.body)
if msg["type"] == "chat" and msg["body"]:
received_body = str(msg["body"])
received.set()
second_client.add_event_handler("message", on_message)
try:
msg = xmpp_client.make_message(mto=second_client.boundjid.bare, mtype="chat")
msg["id"] = msg_id
msg.body = large_body
await msg.send()
msg["body"] = large_body # slixmpp: dict-style, not msg.body
msg.send() # message.send() returns None, not awaitable
await asyncio.wait_for(received.wait(), timeout=10)
assert received_body == large_body, (
f"Large stanza was truncated: expected {len(large_body)} chars, got {len(received_body or '')}. "
@@ -122,6 +125,8 @@ class TestMucLibPatch:
nick1 = "owner"
await xmpp_client.join_muc(room_jid, nick1)
# unlock the freshly-created (locked) room before affiliating others
await xmpp_client.configure_muc(room_jid)
await asyncio.sleep(0.5)
# Grant membership to second client without them joining
await xmpp_client.set_muc_affiliation(room_jid, second_client.boundjid.bare, "member")
@@ -130,14 +135,14 @@ class TestMucLibPatch:
received = asyncio.Event()
def on_message(msg):
if msg["type"] == "groupchat" and msg["from"].startswith(room_jid):
if msg["type"] == "groupchat" and str(msg["from"]).startswith(room_jid):
received.set()
second_client.add_event_handler("message", on_message)
try:
msg = xmpp_client.make_message(mto=room_jid, mtype="groupchat")
msg.body = "message to offline affiliate"
await msg.send()
msg["body"] = "message to offline affiliate" # slixmpp: dict-style
msg.send() # message.send() returns None, not awaitable
# Note: the broadcast-to-offline-affiliate logic in muc.lib.lua only fires
# for domains NOT hosted locally. For same-domain affiliates, standard
# MUC routing handles it. This test therefore primarily verifies no crash.
@@ -166,7 +171,7 @@ class TestMucLibPatch:
def on_presence(pres):
nonlocal self_unavailable_received
if pres["from"].startswith(room_jid) and pres["type"] == "unavailable":
if str(pres["from"]).startswith(room_jid) and pres["type"] == "unavailable":
x = pres.xml.find("{http://jabber.org/protocol/muc#user}x")
if x is not None:
for status in x.findall("{http://jabber.org/protocol/muc#user}status"):