Spaces:
Runtime error
Runtime error
| from proteus.game.agents.parsing import extract_action | |
| VALID = ["up", "down", "left", "right", "stay"] | |
| def test_extracts_action_field_last_occurrence_wins(): | |
| text = "ACTION: left\n...changed my mind...\nACTION: up" | |
| assert extract_action(text, VALID) == "up" | |
| def test_case_insensitive_and_strips_punctuation(): | |
| assert extract_action("Action: Up.", VALID) == "up" | |
| def test_bare_word_fallback_when_no_action_field(): | |
| assert extract_action("I will move down to escape.", VALID) == "down" | |
| def test_returns_none_when_no_valid_action(): | |
| assert extract_action("no idea", VALID) is None | |
| def test_action_field_with_trailing_question_mark(): | |
| # LLMs often append "?"; the field token must still be extracted, not | |
| # fall through to a later prose word. | |
| assert extract_action("ACTION: up?\nThen move right", VALID) == "up" | |