fix: 避免空引用集合触发无效查询
- Agent 与 Skill 引用查询在空 ID 集合时直接返回 - 补充不调用 listByIds 的回归测试
This commit is contained in:
@@ -51,6 +51,9 @@ public class AgentSkillReferenceProvider implements SkillReferenceProvider {
|
||||
ids.add(agent.getId());
|
||||
}
|
||||
}
|
||||
if (ids.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
for (Agent agent : agentService.listByIds(ids)) {
|
||||
result.add("智能体“" + (agent.getName() == null ? "未命名智能体" : agent.getName()) + "”");
|
||||
|
||||
@@ -50,6 +50,22 @@ public class AgentSkillReferenceProviderTest {
|
||||
"智能体“线上引用智能体”"), references);
|
||||
}
|
||||
|
||||
/**
|
||||
* 没有 Agent 引用 Skill 时不应执行空主键集合查询。
|
||||
*/
|
||||
@Test
|
||||
public void shouldSkipEntityQueryWhenSkillHasNoReferences() {
|
||||
AgentService agentService = Mockito.mock(AgentService.class);
|
||||
AgentSkillBindingService bindingService = Mockito.mock(AgentSkillBindingService.class);
|
||||
Mockito.when(bindingService.list(Mockito.any(QueryWrapper.class))).thenReturn(List.of());
|
||||
Mockito.when(agentService.list(Mockito.any(QueryWrapper.class))).thenReturn(List.of());
|
||||
AgentSkillReferenceProvider provider = new AgentSkillReferenceProvider(
|
||||
agentService, bindingService);
|
||||
|
||||
Assert.assertTrue(provider.listReferences(BigInteger.TEN).isEmpty());
|
||||
Mockito.verify(agentService, Mockito.never()).listByIds(Mockito.anyCollection());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 Agent 摘要。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user