fix(release): enforce AIHR tenant collation contract

This commit is contained in:
2026-07-15 13:33:56 +08:00
parent bd19cdd255
commit ab406e616a
19 changed files with 243 additions and 67 deletions
@@ -1138,7 +1138,7 @@ public class AihrSopSeedService {
return Optional.ofNullable(jdbcTemplate.queryForObject("""
select o.ext1, coalesce(k.name, '') as category
from aihr_knowledge_attach a
join sys_oss o on o.oss_id = a.oss_id and o.tenant_id = a.tenant_id
join sys_oss o on o.oss_id = a.oss_id and binary o.tenant_id = binary a.tenant_id
left join aihr_knowledge_info k on k.id = a.knowledge_id and k.tenant_id = a.tenant_id
where a.tenant_id = ? and a.id = ?
limit 1
@@ -1169,7 +1169,7 @@ public class AihrSopSeedService {
else 'name-size'
end as match_type
from aihr_knowledge_attach a
join sys_oss o on o.oss_id = a.oss_id and o.tenant_id = a.tenant_id
join sys_oss o on o.oss_id = a.oss_id and binary o.tenant_id = binary a.tenant_id
where a.tenant_id = ?
and (
json_unquote(json_extract(o.ext1, '$.aihrFileSha256')) = ?
@@ -1291,8 +1291,7 @@ public class AihrSopSeedService {
}
private List<ProcessingTaskRow> processingRows() {
try {
return jdbcTemplate.query("""
return jdbcTemplate.query("""
select a.id,
a.oss_id,
i.name as category,
@@ -1307,7 +1306,7 @@ public class AihrSopSeedService {
from aihr_knowledge_attach a
join aihr_knowledge_info i on i.id = a.knowledge_id and i.tenant_id = a.tenant_id
left join aihr_knowledge_fragment f on f.tenant_id = a.tenant_id and f.knowledge_id = a.knowledge_id and f.doc_id = a.doc_id
left join sys_oss o on o.oss_id = a.oss_id and o.tenant_id = a.tenant_id
left join sys_oss o on o.oss_id = a.oss_id and binary o.tenant_id = binary a.tenant_id
where a.tenant_id = ?
group by a.id, a.oss_id, i.name, a.name, a.type, a.status, a.update_time, a.remark, o.ext1
order by a.update_time desc, a.id desc
@@ -1332,9 +1331,6 @@ public class AihrSopSeedService {
insight.reason()
);
}, tenantId());
} catch (DataAccessException e) {
return List.of();
}
}
private ProcessingTaskResponse processingTask(ProcessingTaskRow row) {
@@ -5,6 +5,7 @@ import org.dromara.aihr.domain.AihrSopDto;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@@ -18,6 +19,7 @@ import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
@@ -349,13 +351,27 @@ public class AihrSopSeedServiceTest {
}
String code = Files.readString(source);
assertTrue(code.contains("join sys_oss o on o.oss_id = a.oss_id and o.tenant_id = a.tenant_id"));
assertTrue(code.contains("left join sys_oss o on o.oss_id = a.oss_id and o.tenant_id = a.tenant_id"));
assertTrue(code.contains("join sys_oss o on o.oss_id = a.oss_id and binary o.tenant_id = binary a.tenant_id"));
assertTrue(code.contains("left join sys_oss o on o.oss_id = a.oss_id and binary o.tenant_id = binary a.tenant_id"));
assertTrue(code.contains("left join aihr_knowledge_info k on k.id = a.knowledge_id and k.tenant_id = a.tenant_id"));
assertTrue(code.contains("where tenant_id = ? and oss_id = ? limit 1"));
assertTrue(code.contains("where tenant_id = ? and oss_id = ?\", objectMapper.writeValueAsString(node), tenantId(), ossId"));
}
@Test
@Tag("dev")
@SuppressWarnings({"rawtypes", "unchecked"})
public void processingOverviewPropagatesDatabaseFailures() {
JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
when(jdbcTemplate.query(anyString(), any(RowMapper.class), any(Object[].class)))
.thenThrow(new DataAccessResourceFailureException("collation mismatch"));
AihrModelSeedService modelService = mock(AihrModelSeedService.class);
when(modelService.visionAllowed()).thenReturn(false);
AihrSopSeedService service = new AihrSopSeedService(new ObjectMapper(), jdbcTemplate, null, "", null, null, modelService);
assertThrows(DataAccessResourceFailureException.class, service::processingOverview);
}
@Test
@Tag("dev")
public void qdrantRebuildKeepsOtherTenantsVectors() throws Exception {