evennia.server.portal.test_wire_formats

Tests for WebSocket wire formats and subprotocol negotiation.

Tests cover:
  • gmcp_utils.py: encode_gmcp / decode_gmcp

  • Wire format codecs: EvenniaV1, Terminal, JsonStandard, GmcpStandard

  • WebSocket subprotocol negotiation in webclient.py

class evennia.server.portal.test_wire_formats.TestGmcpEncode(methodName='runTest')[source]

Bases: TestCase

Tests for gmcp_utils.encode_gmcp().

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_known_mapping()[source]

Commands in EVENNIA_TO_GMCP should use the mapped name.

test_known_mapping_with_args()[source]
test_underscore_to_dotted()[source]

Underscored names should become dotted with capitalization.

test_no_underscore_gets_core_prefix()[source]

Single-word commands get Core. prefix.

test_already_title_case_preserved()[source]
test_fully_uppercase_preserved()[source]

Fully uppercase segments should stay uppercase.

test_no_args_no_kwargs()[source]
test_single_arg()[source]
test_multiple_args()[source]
test_kwargs_only()[source]
test_args_and_kwargs()[source]
class evennia.server.portal.test_wire_formats.TestGmcpDecode(methodName='runTest')[source]

Bases: TestCase

Tests for gmcp_utils.decode_gmcp().

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_known_mapping()[source]

Known GMCP package names should map to Evennia names.

test_package_to_underscore()[source]

Unknown package names should become lowercase underscore.

test_core_prefix_stripped()[source]

Core. prefix should be stripped from the command name.

test_string_arg()[source]
test_array_arg()[source]
test_dict_arg()[source]
test_bytes_input()[source]
test_empty_input()[source]
test_non_json_structure()[source]

Non-JSON data after command name should be treated as string.

test_falsy_scalar_zero()[source]

GMCP payloads of 0 should not be dropped.

test_falsy_scalar_false()[source]

GMCP payloads of false should not be dropped.

test_null_payload()[source]

GMCP payloads of null should be passed through.

class evennia.server.portal.test_wire_formats.TestWireFormatBase(methodName='runTest')[source]

Bases: TestCase

Tests for the WireFormat abstract base class.

test_abstract_methods_raise()[source]
test_encode_prompt_delegates_to_encode_text()[source]

Default encode_prompt should call encode_text with send_prompt=True.

class evennia.server.portal.test_wire_formats.TestEvenniaV1Format(methodName='runTest')[source]

Bases: TestCase

Tests for the v1.evennia.com wire format.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_name()[source]
test_supports_oob()[source]
test_decode_text()[source]
test_decode_oob_command()[source]
test_decode_invalid_json()[source]
test_decode_short_array()[source]
test_encode_text_basic()[source]
test_encode_text_none()[source]
test_encode_text_no_args()[source]
test_encode_text_prompt()[source]
test_encode_text_nocolor()[source]
test_encode_default()[source]
test_encode_default_options_skipped()[source]

The ‘options’ command should be silently dropped.

class evennia.server.portal.test_wire_formats.TestTerminalFormat(methodName='runTest')[source]

Bases: TestCase

Tests for the terminal.mudstandards.org wire format.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_name()[source]
test_no_oob()[source]
test_decode_binary()[source]
test_decode_strips_whitespace()[source]
test_decode_empty()[source]
test_decode_invalid_utf8()[source]
test_encode_text_binary_frame()[source]
test_encode_text_preserves_ansi()[source]

Terminal format should output real ANSI escape sequences.

test_encode_text_none()[source]
test_encode_default_returns_none()[source]

OOB should be silently dropped for terminal format.

class evennia.server.portal.test_wire_formats.TestJsonStandardFormat(methodName='runTest')[source]

Bases: TestCase

Tests for the json.mudstandards.org wire format.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_name()[source]
test_supports_oob()[source]
test_decode_binary_as_text()[source]

BINARY frames should be treated as raw text input.

test_decode_binary_empty()[source]
test_decode_text_envelope()[source]

TEXT frames should be parsed as JSON envelopes.

test_decode_gmcp_envelope()[source]

GMCP-in-JSON envelopes should be decoded.

test_decode_gmcp_envelope_with_data()[source]
test_decode_websocket_close()[source]
test_decode_invalid_json_text_frame()[source]
test_decode_generic_proto()[source]

Unknown proto should pass through as-is.

test_encode_text_binary_frame()[source]

Text should be sent as BINARY frames with raw ANSI.

test_encode_text_preserves_ansi()[source]
test_encode_prompt_as_json_text_frame()[source]

Prompts should be JSON envelopes in TEXT frames.

test_encode_default_gmcp_in_json()[source]

OOB should be encoded as GMCP-in-JSON envelope.

test_encode_default_options_skipped()[source]
class evennia.server.portal.test_wire_formats.TestGmcpStandardFormat(methodName='runTest')[source]

Bases: TestCase

Tests for the gmcp.mudstandards.org wire format.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_name()[source]
test_supports_oob()[source]
test_decode_binary_as_text()[source]
test_decode_text_as_gmcp()[source]

TEXT frames should be parsed as raw GMCP strings.

test_decode_gmcp_with_data()[source]
test_decode_binary_invalid_utf8()[source]
test_decode_text_invalid_utf8()[source]
test_encode_text_binary_frame()[source]
test_encode_prompt_binary_frame()[source]

GMCP format sends prompts as BINARY frames like regular text.

test_encode_default_gmcp_text_frame()[source]

OOB should be raw GMCP strings in TEXT frames.

test_encode_default_with_args()[source]
test_encode_default_options_skipped()[source]
class evennia.server.portal.test_wire_formats.TestWireFormatRegistry(methodName='runTest')[source]

Bases: TestCase

Tests for the wire_formats package registry.

test_registry_has_all_formats()[source]
test_registry_order_prefers_json()[source]

json.mudstandards.org should be first (highest priority).

test_registry_instances_are_correct_types()[source]
class evennia.server.portal.test_wire_formats.TestWebSocketSubprotocolNegotiation(methodName='runTest')[source]

Bases: TestCase

Tests for the onConnect() subprotocol negotiation in WebSocketClient.

These test the negotiation logic in isolation without starting a full Twisted reactor, by directly calling onConnect() with mock request objects.

test_no_subprotocol_offered()[source]

Client sends no Sec-WebSocket-Protocol → v1 fallback, returns None.

test_v1_subprotocol_offered()[source]

Client offers v1.evennia.com → selected and returned.

test_json_subprotocol_offered()[source]
test_gmcp_subprotocol_offered()[source]
test_terminal_subprotocol_offered()[source]
test_server_preference_wins()[source]

When client offers multiple, server’s preference order wins.

test_unknown_subprotocol_falls_back()[source]

Client offers only unknown protocols → v1 fallback.

test_mixed_known_and_unknown()[source]

Client offers unknown + known → known is selected.

test_empty_subprotocols_setting()[source]

WEBSOCKET_SUBPROTOCOLS=[] disables negotiation; clients fall back to v1.

class evennia.server.portal.test_wire_formats.TestEvenniaV1RoundTrip(methodName='runTest')[source]

Bases: TestCase

Test encode → decode round-trip for v1.evennia.com.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_oob_roundtrip()[source]

Encode an OOB command and decode the result.

class evennia.server.portal.test_wire_formats.TestGmcpRoundTrip(methodName='runTest')[source]

Bases: TestCase

Test encode → decode round-trip for gmcp.mudstandards.org.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_oob_roundtrip_no_args()[source]

Encode a command without args and decode.

test_oob_roundtrip_with_kwargs()[source]

Encode a command with kwargs and decode.

class evennia.server.portal.test_wire_formats.TestJsonStandardRoundTrip(methodName='runTest')[source]

Bases: TestCase

Test encode → decode round-trip for json.mudstandards.org.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_oob_roundtrip()[source]

Encode an OOB command as GMCP-in-JSON and decode.

test_prompt_roundtrip()[source]

Encode a prompt and verify the envelope.

class evennia.server.portal.test_wire_formats.TestTerminalEdgeCases(methodName='runTest')[source]

Bases: TestCase

Edge-case tests for TerminalFormat.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_decode_text_frame_treated_as_text()[source]

TEXT frames should still be decoded as text input.

test_decode_empty_bytes()[source]

Empty bytes should return None.

test_decode_empty_bytes_text_frame()[source]

Empty TEXT frame bytes should return None.

class evennia.server.portal.test_wire_formats.TestJsonStandardEdgeCases(methodName='runTest')[source]

Bases: TestCase

Edge-case tests for JsonStandardFormat.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_decode_envelope_missing_proto()[source]

JSON envelope with missing proto should use empty string default.

test_decode_envelope_missing_all_fields()[source]

JSON envelope with no recognized fields returns None (empty funcname).

test_decode_envelope_missing_id_and_data()[source]

Envelope with only proto=”text” and no data should return None.

test_decode_binary_invalid_utf8()[source]

Invalid UTF-8 in BINARY frame should return None.

class evennia.server.portal.test_wire_formats.TestGmcpStandardEdgeCases(methodName='runTest')[source]

Bases: TestCase

Edge-case tests for GmcpStandardFormat.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_decode_empty_binary()[source]

Empty BINARY frame should return None.

test_decode_binary_whitespace_only()[source]

Whitespace-only BINARY frame should return None.

class evennia.server.portal.test_wire_formats.TestBaseWireFormatHelpers(methodName='runTest')[source]

Bases: TestCase

Tests for the shared helper methods on WireFormat base class.

setUp()[source]

Hook method for setting up the test fixture before exercising it.

test_extract_text_and_flags_basic()[source]

Basic extraction with no options or flags.

test_extract_text_and_flags_none_text()[source]

None as text should return None.

test_extract_text_and_flags_no_args()[source]

Empty args should return None.

test_extract_text_and_flags_options_override()[source]

Options should override protocol_flags.

test_extract_text_and_flags_raw_option()[source]

Raw option should be extracted into the result tuple.

test_extract_text_and_flags_raw_protocol_flag()[source]

RAW protocol flag should be used when option is absent.

test_extract_text_and_flags_from_protocol_flags()[source]

Protocol flags should be used when options are absent.

test_process_ansi_normal()[source]

Normal mode should produce ANSI escape sequences.

test_process_ansi_nocolor()[source]

Nocolor mode should strip all ANSI.

test_process_ansi_screenreader()[source]

Screenreader mode should strip ANSI and apply regex.

test_process_ansi_raw()[source]

Raw mode should return text unmodified.

test_process_ansi_trailing_reset()[source]

Normal mode should append |n to prevent color bleed.

test_process_ansi_trailing_pipe_preserved()[source]

A trailing literal pipe should be preserved, not stripped.