Skip to content

Commit

Permalink
[ATO-1151] Parentheses in button title overwrite button payload in ra…
Browse files Browse the repository at this point in the history
…sa shell (#12534)

* fix button question

* fix lint

* add changelog

* edit changelog

* fix test

* skip flaky windows tests

* add skip

* skip additional

* add another test to skip

* skip lm featuizer on windows
  • Loading branch information
Urkem authored Jun 22, 2023
1 parent 06128ba commit faa7337
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog/12534.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Rich responses containing buttons with parentheses characters are now correctly parsed.
Previously any characters found between the first identified pair of `()` in response button took precedence.
2 changes: 1 addition & 1 deletion rasa/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ async def payload_from_button_question(button_question: "Question") -> Text:
response = await button_question.ask_async()
if response != FREE_TEXT_INPUT_PROMPT:
# Extract intent slash command if it's a button
response = response[response.find("(") + 1 : response.find(")")]
response = response[response.rfind("(") + 1 : response.rfind(")")]
return response


Expand Down
17 changes: 17 additions & 0 deletions tests/cli/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
import rasa.shared.utils.io
from tests.cli.conftest import RASA_EXE
from tests.conftest import AsyncMock


@contextlib.contextmanager
Expand Down Expand Up @@ -355,3 +356,19 @@ def test_validate_assistant_id_in_config_preserves_comment() -> None:

# reset input files to original state
rasa.shared.utils.io.write_yaml(original_config_data, config_file, True)


@pytest.mark.parametrize(
"text_input, button",
[
("hi this is test text\n", "hi this is test text"),
("hi this is test text (/button_one)", "/button_one"),
("hi this is test text (and something) (/button_one)", "/button_one"),
],
)
async def test_payload_from_button_question(text_input: str, button: str) -> None:
"""Test that the payload is extracted correctly from the text input."""
question = AsyncMock()
question.ask_async.return_value = text_input
result = await rasa.cli.utils.payload_from_button_question(question)
assert result == button
10 changes: 10 additions & 0 deletions tests/nlu/featurizers/test_lm_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ def evaluate_message_shapes(
assert intent_sentence_vec is None

@pytest.mark.timeout(120, func_only=True)
@pytest.mark.skip_on_windows
def test_lm_featurizer_shapes_in_process_training_data(
self,
model_name: Text,
Expand All @@ -386,6 +387,7 @@ def test_lm_featurizer_shapes_in_process_training_data(
)

@pytest.mark.timeout(120, func_only=True)
@pytest.mark.skip_on_windows
def test_lm_featurizer_shapes_in_process_messages(
self,
model_name: Text,
Expand Down Expand Up @@ -581,6 +583,7 @@ def check_subtokens(
)

@pytest.mark.timeout(120, func_only=True)
@pytest.mark.skip_on_windows
def test_lm_featurizer_num_sub_tokens_process_training_data(
self,
model_name: Text,
Expand All @@ -606,6 +609,7 @@ def test_lm_featurizer_num_sub_tokens_process_training_data(
)

@pytest.mark.timeout(120, func_only=True)
@pytest.mark.skip_on_windows
def test_lm_featurizer_num_sub_tokens_process_messages(
self,
model_name: Text,
Expand Down Expand Up @@ -635,6 +639,7 @@ def test_lm_featurizer_num_sub_tokens_process_messages(
"input_sequence_length, model_name, should_overflow",
[(20, "bert", False), (1000, "bert", True), (1000, "xlnet", False)],
)
@pytest.mark.skip_on_windows
def test_sequence_length_overflow_train(
input_sequence_length: int,
model_name: Text,
Expand Down Expand Up @@ -666,6 +671,7 @@ def test_sequence_length_overflow_train(
(np.ones((1, 256, 5)), [256], "bert", False),
],
)
@pytest.mark.skip_on_windows
def test_long_sequences_extra_padding(
sequence_embeddings: np.ndarray,
actual_sequence_lengths: List[int],
Expand Down Expand Up @@ -703,6 +709,7 @@ def test_long_sequences_extra_padding(
([[1] * 200], 200, 200, False),
],
)
@pytest.mark.skip_on_windows
def test_input_padding(
token_ids: List[List[int]],
max_sequence_length_model: int,
Expand Down Expand Up @@ -730,6 +737,7 @@ def test_input_padding(
(256, "bert", "bert-base-uncased", False),
],
)
@pytest.mark.skip_on_windows
def test_log_longer_sequence(
sequence_length: int,
model_name: Text,
Expand Down Expand Up @@ -760,6 +768,7 @@ def test_log_longer_sequence(
"actual_sequence_length, max_input_sequence_length, zero_start_index",
[(256, 512, 256), (700, 700, 700), (700, 512, 512)],
)
@pytest.mark.skip_on_windows
def test_attention_mask(
actual_sequence_length: int,
max_input_sequence_length: int,
Expand Down Expand Up @@ -792,6 +801,7 @@ def test_attention_mask(
)
],
)
@pytest.mark.skip_on_windows
def test_lm_featurizer_correctly_handle_whitespace_token(
text: Text,
tokens: List[Tuple[Text, int]],
Expand Down
1 change: 1 addition & 0 deletions tests/nlu/test_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_all_components_are_in_at_least_one_test_pipeline():

@pytest.mark.timeout(600, func_only=True)
@pytest.mark.parametrize("language, pipeline", pipelines_for_tests())
@pytest.mark.skip_on_windows
async def test_train_persist_load_parse(
language: Optional[Text],
pipeline: List[Dict],
Expand Down

0 comments on commit faa7337

Please sign in to comment.