Skip to content

Commit 62fbbb9

Browse files
committed
fix: improve appendToolCallStatus method to handle non-error statuses correctly
1 parent 81ab5f9 commit 62fbbb9

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

com.microsoft.copilot.eclipse.ui.test/src/com/microsoft/copilot/eclipse/ui/chat/BaseTurnWidgetToolCallStatusTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@ void appendToolCallStatus_errorFallsBackToProgressMessage_whenErrorIsNull() {
181181
});
182182
}
183183

184+
@Test
185+
void appendToolCallStatus_nonErrorStatusWithOnlyError_isIgnored() {
186+
SwtUtils.invokeOnDisplayThread(() -> {
187+
try (MockedStatic<CopilotUi> copilotUiMock = mockStatic(CopilotUi.class)) {
188+
CopilotUi mockPlugin = mock(CopilotUi.class);
189+
copilotUiMock.when(CopilotUi::getPlugin).thenReturn(mockPlugin);
190+
lenient().when(mockPlugin.getChatServiceManager()).thenReturn(mockChatServiceManager);
191+
192+
CopilotTurnWidget widget = new CopilotTurnWidget(shell, SWT.NONE, mockChatServiceManager, TURN_ID);
193+
194+
// Non-error events with only `error` populated must be dropped; otherwise
195+
// setRunningStatus/setCompletedStatus/setText would call setMarkup(null).
196+
widget.appendToolCallStatus(buildToolCall("running", null, ERROR_MESSAGE));
197+
widget.appendToolCallStatus(buildToolCall("completed", " ", ERROR_MESSAGE));
198+
widget.appendToolCallStatus(buildToolCall("cancelled", null, ERROR_MESSAGE));
199+
200+
@SuppressWarnings("unchecked")
201+
Map<String, AgentStatusLabel> labels = (Map<String, AgentStatusLabel>) getField(widget, "statusLabels");
202+
assertTrue(labels.isEmpty(),
203+
"Non-error events without progressMessage should be ignored, got: " + labels.keySet());
204+
}
205+
});
206+
}
207+
184208
private static AgentToolCall buildToolCall(String status, String progressMessage, String error) {
185209
Gson gson = new Gson();
186210
java.util.Map<String, Object> fields = new java.util.HashMap<>();

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/chat/BaseTurnWidget.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,16 @@ public void appendMessage(String message) {
226226
* @param toolCall the tool call of the agent turn
227227
*/
228228
public void appendToolCallStatus(AgentToolCall toolCall) {
229-
if (toolCall == null
230-
|| (StringUtils.isBlank(toolCall.getProgressMessage()) && StringUtils.isBlank(toolCall.getError()))) {
229+
if (toolCall == null || toolCall.getStatus() == null) {
230+
return;
231+
}
232+
233+
String status = toolCall.getStatus().toLowerCase();
234+
// Require a non-blank progressMessage for non-error events. For error events,
235+
// also accept a non-blank `error` field as the displayable text.
236+
boolean isError = "error".equals(status);
237+
if (StringUtils.isBlank(toolCall.getProgressMessage())
238+
&& (!isError || StringUtils.isBlank(toolCall.getError()))) {
231239
return;
232240
}
233241

@@ -255,7 +263,6 @@ public void appendToolCallStatus(AgentToolCall toolCall) {
255263
AgentStatusLabel statusLabel = statusLabels.computeIfAbsent(toolCall.getId(),
256264
id -> new AgentStatusLabel(this, SWT.LEFT));
257265

258-
String status = toolCall.getStatus().toLowerCase();
259266
switch (status) {
260267
case "running":
261268
statusLabel.setRunningStatus(toolCall.getProgressMessage());

0 commit comments

Comments
 (0)