import pytest from tamq.routing import ( is_delivery_line, parse_address_line, parse_command_line, parse_worker_address_line, ) @pytest.mark.parametrize("keyword", ["to", "To", "TO", "tO"]) def test_direct_address_keyword_is_case_insensitive(keyword): routed = parse_address_line( f"{keyword}:railiance-platform: do something!" ) assert routed.body == "do something!" assert routed.target_repo == "railiance-platform" @pytest.mark.parametrize( "line", [ "@repo: removed", "#repo: removed", "hello To:repo: not at start", "To:repo:", "From:repo: inbound envelope", ], ) def test_non_protocol_and_legacy_input_is_not_routed(line): assert parse_address_line(line) is None @pytest.mark.parametrize("keyword", ["cmd", "Cmd", "CMD", "cMd"]) def test_operator_command_keyword_is_case_insensitive(keyword): assert parse_command_line(f"{keyword}: mode=trigger") == "mode=trigger" assert parse_command_line(f"{keyword}: reset-limits") == "reset-limits" @pytest.mark.parametrize("keyword", ["from", "From", "FROM", "fRoM"]) def test_delivery_keyword_is_case_insensitive(keyword): assert is_delivery_line(f"{keyword}:repo: inbound envelope") is True @pytest.mark.parametrize("gutter", ["• ", " ● ", "▪ ", "◆ "]) def test_worker_address_accepts_terminal_output_gutter(gutter): routed = parse_worker_address_line(f"{gutter}tO:target: worker reply") assert routed == parse_address_line("To:target: worker reply") @pytest.mark.parametrize("gutter", ["› ", "> ", "$ ", "# ", "* ", "- "]) def test_worker_address_rejects_operator_and_markup_gutters(gutter): assert parse_worker_address_line(f"{gutter}To:target: operator echo") is None