|
1 | 1 | package com.devoxx.genie.service.agent.tool; |
2 | 2 |
|
| 3 | +import com.devoxx.genie.service.agent.AgentLoopTracker; |
3 | 4 | import com.intellij.openapi.project.Project; |
4 | 5 | import com.intellij.openapi.util.SystemInfo; |
5 | 6 | import dev.langchain4j.agent.tool.ToolExecutionRequest; |
@@ -142,7 +143,7 @@ void execute_nonZeroExitCode_withOutput_returnsExitCodeAndOutput() { |
142 | 143 | .build(); |
143 | 144 |
|
144 | 145 | String result = executor.execute(request, null); |
145 | | - assertThat(result).contains("Exit code: 2").contains("failing"); |
| 146 | + assertThat(result).contains("exited with code 2").contains("failing"); |
146 | 147 | } |
147 | 148 |
|
148 | 149 | @Test |
@@ -247,7 +248,40 @@ void execute_nonZeroExitCode_returnsExitCode() { |
247 | 248 | .build(); |
248 | 249 |
|
249 | 250 | String result = executor.execute(request, null); |
250 | | - assertThat(result).contains("Exit code: 1"); |
| 251 | + assertThat(result).contains("exited with code 1"); |
| 252 | + } |
| 253 | + |
| 254 | + /** |
| 255 | + * Reproduces the bug where a command exiting with a non-zero code was rendered |
| 256 | + * with the green "success" icon in the agent Activity panel. The icon is decided |
| 257 | + * by {@link AgentLoopTracker#isErrorResult(String)}, which only flags strings |
| 258 | + * beginning with "Error:". A non-zero exit must therefore produce an |
| 259 | + * "Error:"-prefixed result so it is classified as TOOL_ERROR (red icon). |
| 260 | + */ |
| 261 | + @Test |
| 262 | + void execute_nonZeroExitCode_isClassifiedAsError() { |
| 263 | + ToolExecutionRequest request = ToolExecutionRequest.builder() |
| 264 | + .name("run_command") |
| 265 | + .arguments("{\"command\": \"exit 1\"}") |
| 266 | + .build(); |
| 267 | + |
| 268 | + String result = executor.execute(request, null); |
| 269 | + assertThat(AgentLoopTracker.isErrorResult(result)) |
| 270 | + .as("Non-zero exit code must be classified as an error result") |
| 271 | + .isTrue(); |
| 272 | + } |
| 273 | + |
| 274 | + @Test |
| 275 | + void execute_zeroExitCode_isNotClassifiedAsError() { |
| 276 | + ToolExecutionRequest request = ToolExecutionRequest.builder() |
| 277 | + .name("run_command") |
| 278 | + .arguments("{\"command\": \"echo ok\"}") |
| 279 | + .build(); |
| 280 | + |
| 281 | + String result = executor.execute(request, null); |
| 282 | + assertThat(AgentLoopTracker.isErrorResult(result)) |
| 283 | + .as("Successful command must not be classified as an error result") |
| 284 | + .isFalse(); |
251 | 285 | } |
252 | 286 |
|
253 | 287 | @Test |
|
0 commit comments