-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrap up and tests for flow trigger action #12938
Merged
tmbo
merged 2 commits into
dm2
from
ENG-584-wrap-up-flow-trigger-action-refactor-tests-review
Oct 27, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import pytest | ||
from rasa.core.actions.action_trigger_flow import ActionTriggerFlow | ||
from rasa.core.channels import CollectingOutputChannel | ||
from rasa.core.nlg import TemplatedNaturalLanguageGenerator | ||
from rasa.dialogue_understanding.stack.dialogue_stack import DialogueStack | ||
from rasa.dialogue_understanding.stack.frames.flow_stack_frame import ( | ||
FlowStackFrameType, | ||
UserFlowStackFrame, | ||
) | ||
from rasa.shared.core.constants import DIALOGUE_STACK_SLOT | ||
from rasa.shared.core.domain import Domain | ||
from rasa.shared.core.events import ActiveLoop, SlotSet | ||
from rasa.shared.core.trackers import DialogueStateTracker | ||
|
||
|
||
async def test_action_trigger_flow(): | ||
tracker = DialogueStateTracker.from_events("test", []) | ||
action = ActionTriggerFlow("flow_foo") | ||
channel = CollectingOutputChannel() | ||
nlg = TemplatedNaturalLanguageGenerator({}) | ||
events = await action.run(channel, nlg, tracker, Domain.empty()) | ||
assert len(events) == 1 | ||
event = events[0] | ||
assert isinstance(event, SlotSet) | ||
assert event.key == DIALOGUE_STACK_SLOT | ||
assert len(event.value) == 1 | ||
assert event.value[0]["type"] == UserFlowStackFrame.type() | ||
assert event.value[0]["flow_id"] == "foo" | ||
assert event.value[0]["frame_type"] == FlowStackFrameType.REGULAR.value | ||
|
||
|
||
async def test_action_trigger_flow_with_slots(): | ||
tracker = DialogueStateTracker.from_events("test", []) | ||
action = ActionTriggerFlow("flow_foo") | ||
channel = CollectingOutputChannel() | ||
nlg = TemplatedNaturalLanguageGenerator({}) | ||
events = await action.run( | ||
channel, nlg, tracker, Domain.empty(), metadata={"slots": {"foo": "bar"}} | ||
) | ||
|
||
event = events[0] | ||
assert isinstance(event, SlotSet) | ||
assert event.key == DIALOGUE_STACK_SLOT | ||
assert len(event.value) == 1 | ||
assert event.value[0]["type"] == UserFlowStackFrame.type() | ||
assert event.value[0]["flow_id"] == "foo" | ||
|
||
assert len(events) == 2 | ||
event = events[1] | ||
assert isinstance(event, SlotSet) | ||
assert event.key == "foo" | ||
assert event.value == "bar" | ||
|
||
|
||
async def test_action_trigger_fails_if_name_is_invalid(): | ||
with pytest.raises(ValueError): | ||
ActionTriggerFlow("foo") | ||
|
||
|
||
async def test_action_trigger_ends_an_active_loop_on_the_tracker(): | ||
tracker = DialogueStateTracker.from_events("test", [ActiveLoop("loop_foo")]) | ||
action = ActionTriggerFlow("flow_foo") | ||
channel = CollectingOutputChannel() | ||
nlg = TemplatedNaturalLanguageGenerator({}) | ||
events = await action.run(channel, nlg, tracker, Domain.empty()) | ||
|
||
assert len(events) == 2 | ||
assert isinstance(events[1], ActiveLoop) | ||
assert events[1].name is None | ||
|
||
|
||
async def test_action_trigger_uses_interrupt_flow_type_if_stack_already_contains_flow(): | ||
user_frame = UserFlowStackFrame( | ||
flow_id="my_flow", step_id="collect_bar", frame_id="some-frame-id" | ||
) | ||
stack = DialogueStack(frames=[user_frame]) | ||
tracker = DialogueStateTracker.from_events("test", [stack.persist_as_event()]) | ||
|
||
action = ActionTriggerFlow("flow_foo") | ||
channel = CollectingOutputChannel() | ||
nlg = TemplatedNaturalLanguageGenerator({}) | ||
|
||
events = await action.run(channel, nlg, tracker, Domain.empty()) | ||
|
||
assert len(events) == 1 | ||
event = events[0] | ||
assert isinstance(event, SlotSet) | ||
assert event.key == DIALOGUE_STACK_SLOT | ||
assert len(event.value) == 2 | ||
assert event.value[1]["type"] == UserFlowStackFrame.type() | ||
assert event.value[1]["flow_id"] == "foo" | ||
assert event.value[1]["frame_type"] == FlowStackFrameType.INTERRUPT.value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please also test that it's a regular frame when there is nothing there yet :) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to align with other trigger action