Skyvern/tests/unit/test_copilot_agent_helpers.py

60 lines
2.1 KiB
Python

"""Tests for agent.py helpers that are hard to drive through run_copilot_agent."""
from __future__ import annotations
from unittest.mock import MagicMock
class TestFailedTestResponseNormalization:
def test_rewrite_failed_test_response_avoids_success_language(self) -> None:
from skyvern.forge.sdk.copilot.agent import _rewrite_failed_test_response
from skyvern.forge.sdk.copilot.context import CopilotContext
ctx = CopilotContext(
organization_id="org-1",
workflow_id="wf-1",
workflow_permanent_id="wfp-1",
workflow_yaml="",
browser_session_id=None,
stream=MagicMock(),
last_update_block_count=2,
last_test_ok=False,
last_test_failure_reason=(
"Failed to navigate to url https://bad.example. "
"Error: net::ERR_NAME_NOT_RESOLVED Call log: navigating..."
),
)
rewritten = _rewrite_failed_test_response("The workflow was successfully created.", ctx)
assert "successfully created" not in rewritten.lower()
assert "draft workflow with 2 blocks" in rewritten
assert "test failed" in rewritten.lower()
assert "Call log:" not in rewritten
def test_failed_run_does_not_clear_last_workflow_state(self) -> None:
from skyvern.forge.sdk.copilot.tools import _record_run_blocks_result
sentinel_workflow = object()
ctx = MagicMock()
ctx.last_workflow = sentinel_workflow
ctx.last_test_ok = None
ctx.last_test_failure_reason = None
_record_run_blocks_result(
ctx,
{
"ok": False,
"data": {
"blocks": [
{
"label": "open_website",
"failure_reason": "net::ERR_NAME_NOT_RESOLVED",
}
]
},
},
)
assert ctx.last_workflow is sentinel_workflow
assert ctx.last_test_ok is False
assert ctx.last_test_failure_reason == "net::ERR_NAME_NOT_RESOLVED"