fix: 避免空引用集合触发无效查询

- Agent 与 Skill 引用查询在空 ID 集合时直接返回

- 补充不调用 listByIds 的回归测试
This commit is contained in:
2026-08-26 18:12:56 +08:00
parent 98b34bd4bb
commit 3e79e99925
4 changed files with 23 additions and 0 deletions

View File

@@ -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()) + "");

View File

@@ -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 摘要。
*