-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_runner_direct_agent_fallback.py
More file actions
174 lines (153 loc) · 6.16 KB
/
Copy pathtest_runner_direct_agent_fallback.py
File metadata and controls
174 lines (153 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# SPDX-License-Identifier: Apache-2.0
# Copyright 2025 Provability-Fabric Contributors
from __future__ import annotations
import sys
from pathlib import Path
from unittest import mock
REPO_ROOT = Path(__file__).resolve().parent.parent
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
def test_runner_direct_agent_no_fallback_on_quality_failure(tmp_path: Path):
from bench.swebench import runner
from bench.swebench.engines.openhands_engine import EngineTrace, SolveResult
ws = tmp_path / "ws"
(ws / "repo").mkdir(parents=True)
(ws / "scratch").mkdir(parents=True)
# Had real edit attempts but patch still empty: quality path, do not re-run OpenHands.
da_result = SolveResult(
patch_diff_str="",
trace=EngineTrace(
raw_events=[{"kind": "MessageEvent", "timestamp": 1}],
tool_calls=[{"name": "edit_file", "args": {"path": "x.py"}}],
),
success=False,
error="empty patch",
)
with (
mock.patch.object(runner, "direct_agent_solve", return_value=da_result),
mock.patch.object(runner, "openhands_solve") as m_oh,
):
patch, log_text, trace = runner.run_engine_for_instance(
instance_dict={"instance_id": "x", "repo": "r", "base_commit": "c"},
engine="direct_agent",
run_dir=tmp_path,
instance_id="x",
workspace_path=ws,
task_text="fix",
openhands_config=None,
openhands_extra_env=None,
)
assert "fallback_openhands_invoked=1" not in log_text
assert patch == ""
assert trace is not None
assert trace.get("fallback_invoked") is None
assert m_oh.call_count == 0
def test_runner_direct_agent_fallback_when_empty_patch_no_edit_attempts(tmp_path: Path):
"""MessageEvent / DirectAgentStartEvent churn must not block OpenHands fallback."""
from bench.swebench import runner
from bench.swebench.engines.openhands_engine import EngineTrace, SolveResult
ws = tmp_path / "ws"
(ws / "repo").mkdir(parents=True)
(ws / "scratch").mkdir(parents=True)
da_result = SolveResult(
patch_diff_str="",
trace=EngineTrace(
raw_events=[
{"kind": "DirectAgentStartEvent", "timestamp": 0},
{"kind": "MessageEvent", "timestamp": 1},
],
),
success=False,
error="no successful edit actions",
)
oh_result = SolveResult(
patch_diff_str="diff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\n",
trace=EngineTrace(raw_events=[{"kind": "ActionEvent", "timestamp": 2}], files_modified=["x"]),
success=True,
error=None,
)
with (
mock.patch.object(runner, "direct_agent_solve", return_value=da_result),
mock.patch.object(runner, "openhands_solve", return_value=oh_result),
):
patch, log_text, trace = runner.run_engine_for_instance(
instance_dict={"instance_id": "x", "repo": "r", "base_commit": "c"},
engine="direct_agent",
run_dir=tmp_path,
instance_id="x",
workspace_path=ws,
task_text="fix",
openhands_config=None,
openhands_extra_env=None,
)
assert "fallback_openhands_invoked=1" in log_text
assert patch.startswith("diff --git")
assert trace is not None
assert trace.get("fallback_reason_type") == "runtime_or_provider"
def test_runner_direct_agent_no_fallback_when_patch_present(tmp_path: Path):
from bench.swebench import runner
from bench.swebench.engines.openhands_engine import EngineTrace, SolveResult
ws = tmp_path / "ws"
(ws / "repo").mkdir(parents=True)
(ws / "scratch").mkdir(parents=True)
da_result = SolveResult(
patch_diff_str="diff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\n",
trace=EngineTrace(raw_events=[{"kind": "ActionEvent", "timestamp": 1}], files_modified=["x"]),
success=True,
error=None,
)
with (
mock.patch.object(runner, "direct_agent_solve", return_value=da_result),
mock.patch.object(runner, "openhands_solve") as m_oh,
):
patch, log_text, trace = runner.run_engine_for_instance(
instance_dict={"instance_id": "x", "repo": "r", "base_commit": "c"},
engine="direct_agent",
run_dir=tmp_path,
instance_id="x",
workspace_path=ws,
task_text="fix",
openhands_config=None,
openhands_extra_env=None,
)
assert patch.startswith("diff --git")
assert "fallback_openhands_invoked=1" not in log_text
assert trace is not None
assert not trace.get("fallback_invoked")
assert m_oh.call_count == 0
def test_runner_direct_agent_fallback_on_provider_fault(tmp_path: Path):
from bench.swebench import runner
from bench.swebench.engines.openhands_engine import EngineTrace, SolveResult
ws = tmp_path / "ws"
(ws / "repo").mkdir(parents=True)
(ws / "scratch").mkdir(parents=True)
da_result = SolveResult(
patch_diff_str="",
trace=EngineTrace(raw_events=[]),
success=False,
error="HTTPError 429 rate limit",
)
oh_result = SolveResult(
patch_diff_str="diff --git a/x b/x\n--- a/x\n+++ b/x\n@@ -1 +1 @@\n-a\n+b\n",
trace=EngineTrace(raw_events=[{"kind": "ActionEvent", "timestamp": 2}], files_modified=["x"]),
success=True,
error=None,
)
with (
mock.patch.object(runner, "direct_agent_solve", return_value=da_result),
mock.patch.object(runner, "openhands_solve", return_value=oh_result),
):
patch, log_text, trace = runner.run_engine_for_instance(
instance_dict={"instance_id": "x", "repo": "r", "base_commit": "c"},
engine="direct_agent",
run_dir=tmp_path,
instance_id="x",
workspace_path=ws,
task_text="fix",
openhands_config=None,
openhands_extra_env=None,
)
assert "fallback_openhands_invoked=1" in log_text
assert patch.startswith("diff --git")
assert trace is not None
assert trace.get("fallback_reason_type") == "runtime_or_provider"