chore: bump project version to 1.52.0 and reformat multi-line strings across core modules
- Update pyproject.toml version from 1.51.0 to 1.52.0 - Reformat string quotes from single to double in autonomous mode extraction - Reformat tool_results list construction and __all__ exports with consistent indentation - Remove unused imports (time, uuid) and Spinner from assistant module - Reformat knowledge_context search results and graph_memory dataclass definitions - Fix missing space in KnowledgeEntry __str__ method's default parameter
This commit is contained in:
@@ -114,10 +114,6 @@ class TestAssistant(unittest.TestCase):
|
||||
process_message(assistant, "test message")
|
||||
|
||||
from rp.memory import KnowledgeEntry
|
||||
import json
|
||||
import time
|
||||
import uuid
|
||||
from unittest.mock import ANY
|
||||
|
||||
# Mock time.time() and uuid.uuid4() to return consistent values
|
||||
expected_entry = KnowledgeEntry(
|
||||
@@ -132,10 +128,10 @@ class TestAssistant(unittest.TestCase):
|
||||
created_at=1234567890.123456,
|
||||
updated_at=1234567890.123456,
|
||||
)
|
||||
expected_content = str(expected_entry)
|
||||
|
||||
str(expected_entry)
|
||||
|
||||
assistant.knowledge_store.add_entry.assert_called_once_with(expected_entry)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -696,4 +696,3 @@ class TestShowBackgroundEvents:
|
||||
def test_show_events_exception(self, mock_get):
|
||||
mock_get.side_effect = Exception("test")
|
||||
show_background_events(self.assistant)
|
||||
|
||||
|
||||
+60
-109
@@ -1,4 +1,3 @@
|
||||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
from rp.workflows.workflow_definition import ExecutionMode, Workflow, WorkflowStep
|
||||
@@ -16,7 +15,7 @@ class TestWorkflowStep:
|
||||
on_success=["step2"],
|
||||
on_failure=["step3"],
|
||||
retry_count=2,
|
||||
timeout_seconds=600
|
||||
timeout_seconds=600,
|
||||
)
|
||||
assert step.tool_name == "test_tool"
|
||||
assert step.arguments == {"arg1": "value1"}
|
||||
@@ -28,11 +27,7 @@ class TestWorkflowStep:
|
||||
assert step.timeout_seconds == 600
|
||||
|
||||
def test_to_dict(self):
|
||||
step = WorkflowStep(
|
||||
tool_name="test_tool",
|
||||
arguments={"arg1": "value1"},
|
||||
step_id="step1"
|
||||
)
|
||||
step = WorkflowStep(tool_name="test_tool", arguments={"arg1": "value1"}, step_id="step1")
|
||||
expected = {
|
||||
"tool_name": "test_tool",
|
||||
"arguments": {"arg1": "value1"},
|
||||
@@ -77,7 +72,7 @@ class TestWorkflow:
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.PARALLEL,
|
||||
variables={"var1": "value1"},
|
||||
tags=["tag1", "tag2"]
|
||||
tags=["tag1", "tag2"],
|
||||
)
|
||||
assert workflow.name == "test_workflow"
|
||||
assert workflow.description == "A test workflow"
|
||||
@@ -94,7 +89,7 @@ class TestWorkflow:
|
||||
steps=[step1],
|
||||
execution_mode=ExecutionMode.SEQUENTIAL,
|
||||
variables={"var1": "value1"},
|
||||
tags=["tag1"]
|
||||
tags=["tag1"],
|
||||
)
|
||||
expected = {
|
||||
"name": "test_workflow",
|
||||
@@ -110,16 +105,18 @@ class TestWorkflow:
|
||||
data = {
|
||||
"name": "test_workflow",
|
||||
"description": "A test workflow",
|
||||
"steps": [{
|
||||
"tool_name": "tool1",
|
||||
"arguments": {},
|
||||
"step_id": "step1",
|
||||
"condition": None,
|
||||
"on_success": None,
|
||||
"on_failure": None,
|
||||
"retry_count": 0,
|
||||
"timeout_seconds": 300,
|
||||
}],
|
||||
"steps": [
|
||||
{
|
||||
"tool_name": "tool1",
|
||||
"arguments": {},
|
||||
"step_id": "step1",
|
||||
"condition": None,
|
||||
"on_success": None,
|
||||
"on_failure": None,
|
||||
"retry_count": 0,
|
||||
"timeout_seconds": 300,
|
||||
}
|
||||
],
|
||||
"execution_mode": "parallel",
|
||||
"variables": {"var1": "value1"},
|
||||
"tags": ["tag1"],
|
||||
@@ -134,11 +131,7 @@ class TestWorkflow:
|
||||
assert workflow.tags == ["tag1"]
|
||||
|
||||
def test_add_step(self):
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[])
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow.add_step(step)
|
||||
assert workflow.steps == [step]
|
||||
@@ -147,9 +140,7 @@ class TestWorkflow:
|
||||
step1 = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
step2 = WorkflowStep(tool_name="tool2", arguments={}, step_id="step2")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step1, step2]
|
||||
name="test_workflow", description="A test workflow", steps=[step1, step2]
|
||||
)
|
||||
assert workflow.get_step("step1") == step1
|
||||
assert workflow.get_step("step2") == step2
|
||||
@@ -162,7 +153,7 @@ class TestWorkflow:
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.SEQUENTIAL
|
||||
execution_mode=ExecutionMode.SEQUENTIAL,
|
||||
)
|
||||
assert workflow.get_initial_steps() == [step1]
|
||||
|
||||
@@ -173,7 +164,7 @@ class TestWorkflow:
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.PARALLEL
|
||||
execution_mode=ExecutionMode.PARALLEL,
|
||||
)
|
||||
assert workflow.get_initial_steps() == [step1, step2]
|
||||
|
||||
@@ -184,7 +175,7 @@ class TestWorkflow:
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.CONDITIONAL
|
||||
execution_mode=ExecutionMode.CONDITIONAL,
|
||||
)
|
||||
assert workflow.get_initial_steps() == [step2] # Only step without condition
|
||||
|
||||
@@ -200,11 +191,7 @@ class TestWorkflowStorage:
|
||||
|
||||
def test_save_and_load_workflow(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[step])
|
||||
workflow_id = self.storage.save_workflow(workflow)
|
||||
loaded = self.storage.load_workflow(workflow_id)
|
||||
assert loaded is not None
|
||||
@@ -219,11 +206,7 @@ class TestWorkflowStorage:
|
||||
|
||||
def test_load_workflow_by_name(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[step])
|
||||
self.storage.save_workflow(workflow)
|
||||
loaded = self.storage.load_workflow_by_name("test_workflow")
|
||||
assert loaded is not None
|
||||
@@ -236,10 +219,7 @@ class TestWorkflowStorage:
|
||||
def test_list_workflows(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step],
|
||||
tags=["tag1"]
|
||||
name="test_workflow", description="A test workflow", steps=[step], tags=["tag1"]
|
||||
)
|
||||
self.storage.save_workflow(workflow)
|
||||
workflows = self.storage.list_workflows()
|
||||
@@ -250,16 +230,10 @@ class TestWorkflowStorage:
|
||||
def test_list_workflows_with_tag(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow1 = Workflow(
|
||||
name="test_workflow1",
|
||||
description="A test workflow",
|
||||
steps=[step],
|
||||
tags=["tag1"]
|
||||
name="test_workflow1", description="A test workflow", steps=[step], tags=["tag1"]
|
||||
)
|
||||
workflow2 = Workflow(
|
||||
name="test_workflow2",
|
||||
description="A test workflow",
|
||||
steps=[step],
|
||||
tags=["tag2"]
|
||||
name="test_workflow2", description="A test workflow", steps=[step], tags=["tag2"]
|
||||
)
|
||||
self.storage.save_workflow(workflow1)
|
||||
self.storage.save_workflow(workflow2)
|
||||
@@ -269,11 +243,7 @@ class TestWorkflowStorage:
|
||||
|
||||
def test_delete_workflow(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[step])
|
||||
workflow_id = self.storage.save_workflow(workflow)
|
||||
deleted = self.storage.delete_workflow(workflow_id)
|
||||
assert deleted is True
|
||||
@@ -286,11 +256,7 @@ class TestWorkflowStorage:
|
||||
|
||||
def test_save_execution(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[step])
|
||||
workflow_id = self.storage.save_workflow(workflow)
|
||||
context = WorkflowExecutionContext()
|
||||
context.set_step_result("step1", "result")
|
||||
@@ -303,11 +269,7 @@ class TestWorkflowStorage:
|
||||
|
||||
def test_get_execution_history(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[step])
|
||||
workflow_id = self.storage.save_workflow(workflow)
|
||||
context = WorkflowExecutionContext()
|
||||
context.set_step_result("step1", "result")
|
||||
@@ -318,11 +280,7 @@ class TestWorkflowStorage:
|
||||
|
||||
def test_get_execution_history_limit(self):
|
||||
step = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
workflow = Workflow(
|
||||
name="test_workflow",
|
||||
description="A test workflow",
|
||||
steps=[step]
|
||||
)
|
||||
workflow = Workflow(name="test_workflow", description="A test workflow", steps=[step])
|
||||
workflow_id = self.storage.save_workflow(workflow)
|
||||
for i in range(5):
|
||||
context = WorkflowExecutionContext()
|
||||
@@ -367,6 +325,7 @@ class TestWorkflowEngine:
|
||||
def test_init(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return f"executed {tool_name} with {args}"
|
||||
|
||||
engine = WorkflowEngine(tool_executor, max_workers=10)
|
||||
assert engine.tool_executor == tool_executor
|
||||
assert engine.max_workers == 10
|
||||
@@ -374,6 +333,7 @@ class TestWorkflowEngine:
|
||||
def test_evaluate_condition_true(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
assert engine._evaluate_condition("True", context) is True
|
||||
@@ -381,6 +341,7 @@ class TestWorkflowEngine:
|
||||
def test_evaluate_condition_false(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
assert engine._evaluate_condition("False", context) is False
|
||||
@@ -388,6 +349,7 @@ class TestWorkflowEngine:
|
||||
def test_evaluate_condition_with_variables(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
context.set_variable("test_var", "test_value")
|
||||
@@ -396,15 +358,12 @@ class TestWorkflowEngine:
|
||||
def test_substitute_variables(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
context.set_variable("var1", "value1")
|
||||
context.set_step_result("step1", "result1")
|
||||
arguments = {
|
||||
"arg1": "${var.var1}",
|
||||
"arg2": "${step.step1}",
|
||||
"arg3": "plain_value"
|
||||
}
|
||||
arguments = {"arg1": "${var.var1}", "arg2": "${step.step1}", "arg3": "plain_value"}
|
||||
substituted = engine._substitute_variables(arguments, context)
|
||||
assert substituted["arg1"] == "value1"
|
||||
assert substituted["arg2"] == "result1"
|
||||
@@ -412,16 +371,14 @@ class TestWorkflowEngine:
|
||||
|
||||
def test_execute_step_success(self):
|
||||
executed = []
|
||||
|
||||
def tool_executor(tool_name, args):
|
||||
executed.append((tool_name, args))
|
||||
return "success_result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
step = WorkflowStep(
|
||||
tool_name="test_tool",
|
||||
arguments={"arg": "value"},
|
||||
step_id="step1"
|
||||
)
|
||||
step = WorkflowStep(tool_name="test_tool", arguments={"arg": "value"}, step_id="step1")
|
||||
result = engine._execute_step(step, context)
|
||||
assert result["status"] == "success"
|
||||
assert result["step_id"] == "step1"
|
||||
@@ -431,16 +388,15 @@ class TestWorkflowEngine:
|
||||
|
||||
def test_execute_step_skipped(self):
|
||||
executed = []
|
||||
|
||||
def tool_executor(tool_name, args):
|
||||
executed.append((tool_name, args))
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
step = WorkflowStep(
|
||||
tool_name="test_tool",
|
||||
arguments={"arg": "value"},
|
||||
step_id="step1",
|
||||
condition="False"
|
||||
tool_name="test_tool", arguments={"arg": "value"}, step_id="step1", condition="False"
|
||||
)
|
||||
result = engine._execute_step(step, context)
|
||||
assert result["status"] == "skipped"
|
||||
@@ -449,18 +405,17 @@ class TestWorkflowEngine:
|
||||
|
||||
def test_execute_step_failed_with_retry(self):
|
||||
executed = []
|
||||
|
||||
def tool_executor(tool_name, args):
|
||||
executed.append((tool_name, args))
|
||||
if len(executed) < 2:
|
||||
raise Exception("Temporary failure")
|
||||
return "success_result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
step = WorkflowStep(
|
||||
tool_name="test_tool",
|
||||
arguments={"arg": "value"},
|
||||
step_id="step1",
|
||||
retry_count=1
|
||||
tool_name="test_tool", arguments={"arg": "value"}, step_id="step1", retry_count=1
|
||||
)
|
||||
result = engine._execute_step(step, context)
|
||||
assert result["status"] == "success"
|
||||
@@ -469,16 +424,15 @@ class TestWorkflowEngine:
|
||||
|
||||
def test_execute_step_failed(self):
|
||||
executed = []
|
||||
|
||||
def tool_executor(tool_name, args):
|
||||
executed.append((tool_name, args))
|
||||
raise Exception("Permanent failure")
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
context = WorkflowExecutionContext()
|
||||
step = WorkflowStep(
|
||||
tool_name="test_tool",
|
||||
arguments={"arg": "value"},
|
||||
step_id="step1",
|
||||
retry_count=1
|
||||
tool_name="test_tool", arguments={"arg": "value"}, step_id="step1", retry_count=1
|
||||
)
|
||||
result = engine._execute_step(step, context)
|
||||
assert result["status"] == "failed"
|
||||
@@ -488,6 +442,7 @@ class TestWorkflowEngine:
|
||||
def test_get_next_steps_sequential(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
step1 = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
step2 = WorkflowStep(tool_name="tool2", arguments={}, step_id="step2")
|
||||
@@ -495,7 +450,7 @@ class TestWorkflowEngine:
|
||||
name="test",
|
||||
description="test",
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.SEQUENTIAL
|
||||
execution_mode=ExecutionMode.SEQUENTIAL,
|
||||
)
|
||||
result = {"status": "success"}
|
||||
next_steps = engine._get_next_steps(step1, result, workflow)
|
||||
@@ -504,28 +459,22 @@ class TestWorkflowEngine:
|
||||
def test_get_next_steps_on_success(self):
|
||||
def tool_executor(tool_name, args):
|
||||
return "result"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
step1 = WorkflowStep(
|
||||
tool_name="tool1",
|
||||
arguments={},
|
||||
step_id="step1",
|
||||
on_success=["step2"]
|
||||
)
|
||||
step1 = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1", on_success=["step2"])
|
||||
step2 = WorkflowStep(tool_name="tool2", arguments={}, step_id="step2")
|
||||
workflow = Workflow(
|
||||
name="test",
|
||||
description="test",
|
||||
steps=[step1, step2]
|
||||
)
|
||||
workflow = Workflow(name="test", description="test", steps=[step1, step2])
|
||||
result = {"status": "success"}
|
||||
next_steps = engine._get_next_steps(step1, result, workflow)
|
||||
assert next_steps == [step2]
|
||||
|
||||
def test_execute_workflow_sequential(self):
|
||||
executed = []
|
||||
|
||||
def tool_executor(tool_name, args):
|
||||
executed.append(tool_name)
|
||||
return f"result_{tool_name}"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
step1 = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
step2 = WorkflowStep(tool_name="tool2", arguments={}, step_id="step2")
|
||||
@@ -533,7 +482,7 @@ class TestWorkflowEngine:
|
||||
name="test",
|
||||
description="test",
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.SEQUENTIAL
|
||||
execution_mode=ExecutionMode.SEQUENTIAL,
|
||||
)
|
||||
context = engine.execute_workflow(workflow)
|
||||
assert executed == ["tool1", "tool2"]
|
||||
@@ -542,9 +491,11 @@ class TestWorkflowEngine:
|
||||
|
||||
def test_execute_workflow_parallel(self):
|
||||
executed = []
|
||||
|
||||
def tool_executor(tool_name, args):
|
||||
executed.append(tool_name)
|
||||
return f"result_{tool_name}"
|
||||
|
||||
engine = WorkflowEngine(tool_executor)
|
||||
step1 = WorkflowStep(tool_name="tool1", arguments={}, step_id="step1")
|
||||
step2 = WorkflowStep(tool_name="tool2", arguments={}, step_id="step2")
|
||||
@@ -552,9 +503,9 @@ class TestWorkflowEngine:
|
||||
name="test",
|
||||
description="test",
|
||||
steps=[step1, step2],
|
||||
execution_mode=ExecutionMode.PARALLEL
|
||||
execution_mode=ExecutionMode.PARALLEL,
|
||||
)
|
||||
context = engine.execute_workflow(workflow)
|
||||
assert set(executed) == {"tool1", "tool2"}
|
||||
assert context.get_step_result("step1") == "result_tool1"
|
||||
assert context.get_step_result("step2") == "result_tool2"
|
||||
assert context.get_step_result("step2") == "result_tool2"
|
||||
|
||||
Reference in New Issue
Block a user