fix: 避免空引用集合触发无效查询
- Agent 与 Skill 引用查询在空 ID 集合时直接返回 - 补充不调用 listByIds 的回归测试
This commit is contained in:
@@ -51,6 +51,9 @@ public class AgentSkillReferenceProvider implements SkillReferenceProvider {
|
|||||||
ids.add(agent.getId());
|
ids.add(agent.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
List<String> result = new ArrayList<>();
|
List<String> result = new ArrayList<>();
|
||||||
for (Agent agent : agentService.listByIds(ids)) {
|
for (Agent agent : agentService.listByIds(ids)) {
|
||||||
result.add("智能体“" + (agent.getName() == null ? "未命名智能体" : agent.getName()) + "”");
|
result.add("智能体“" + (agent.getName() == null ? "未命名智能体" : agent.getName()) + "”");
|
||||||
|
|||||||
@@ -50,6 +50,22 @@ public class AgentSkillReferenceProviderTest {
|
|||||||
"智能体“线上引用智能体”"), references);
|
"智能体“线上引用智能体”"), 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 摘要。
|
* 创建 Agent 摘要。
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ public class SkillToolReferenceProviderImpl implements SkillToolReferenceProvide
|
|||||||
ids.add(skill.getId());
|
ids.add(skill.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
List<OfflineImpactBindingVo> result = new ArrayList<>();
|
List<OfflineImpactBindingVo> result = new ArrayList<>();
|
||||||
for (Skill skill : skillService.listByIds(ids)) {
|
for (Skill skill : skillService.listByIds(ids)) {
|
||||||
OfflineImpactBindingVo item = new OfflineImpactBindingVo();
|
OfflineImpactBindingVo item = new OfflineImpactBindingVo();
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public class SkillToolReferenceProviderImplTest {
|
|||||||
skillService, bindingService);
|
skillService, bindingService);
|
||||||
|
|
||||||
Assert.assertTrue(provider.listSkillsByMcpId(BigInteger.TEN).isEmpty());
|
Assert.assertTrue(provider.listSkillsByMcpId(BigInteger.TEN).isEmpty());
|
||||||
|
Mockito.verify(skillService, Mockito.never()).listByIds(Mockito.anyCollection());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user