Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/component/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _invoke(self, **kwargs):
self.set_output("_next", cond["to"])
return

if all(res):
if res and all(res):
self.set_output("next", [self._canvas.get_component_name(cpn_id) for cpn_id in cond["to"]])
self.set_output("_next", cond["to"])
return
Expand Down
59 changes: 59 additions & 0 deletions test/unit_test/agent/component/test_switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from agent.component.switch import Switch, SwitchParam


class _Canvas:
def __init__(self, variables=None):
self.variables = variables or {}

def is_canceled(self):
return False

def get_variable_value(self, cpn_id):
return self.variables[cpn_id]

def get_component_name(self, cpn_id):
return cpn_id


def _switch(param, variables=None):
cpn = Switch.__new__(Switch)
cpn._canvas = _Canvas(variables)
cpn._id = "switch"
cpn._param = param
return cpn


def test_switch_empty_condition_falls_through_to_else():
param = SwitchParam()
param.conditions = [
{
"logical_operator": "and",
"items": [{"cpn_id": "", "operator": "=", "value": "yes"}],
"to": ["case_target"],
}
]
param.end_cpn_ids = ["else_target"]

cpn = _switch(param)
cpn._invoke()

assert cpn.output("_next") == ["else_target"]
assert cpn.output("next") == ["else_target"]
Comment on lines +26 to +41
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add pytest priority markers to test functions.

Both test functions are missing priority markers (@pytest.mark.p1, @pytest.mark.p2, or @pytest.mark.p3). As per coding guidelines, all tests in test/**/*.py should use pytest priority markers.

📝 Proposed fix to add priority markers
+import pytest
+

 from agent.component.switch import Switch, SwitchParam


 class _Canvas:
+@pytest.mark.p1
 def test_switch_empty_condition_falls_through_to_else():
     param = SwitchParam()
+@pytest.mark.p1
 def test_switch_non_empty_and_condition_still_matches():
     param = SwitchParam()

Also applies to: 44-59

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit_test/agent/component/test_switch.py` around lines 26 - 41, Add the
appropriate pytest priority marker to the test function
test_switch_empty_condition_falls_through_to_else (and the other test in the
same file referenced at lines 44-59) by decorating each test with
`@pytest.mark.p1` (or the correct priority per test suite rules); ensure pytest is
imported at the top of test_switch.py (add "import pytest" if absent) so the
decorator resolves.



def test_switch_non_empty_and_condition_still_matches():
param = SwitchParam()
param.conditions = [
{
"logical_operator": "and",
"items": [{"cpn_id": "answer", "operator": "=", "value": "yes"}],
"to": ["case_target"],
}
]
param.end_cpn_ids = ["else_target"]

cpn = _switch(param, {"answer": "yes"})
cpn._invoke()

assert cpn.output("_next") == ["case_target"]
assert cpn.output("next") == ["case_target"]
Loading