feat(audit): 补齐摄取管道入口并沉淀完成度审计
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package com.bruce.rag.controller;
|
||||
|
||||
import com.bruce.common.handler.GlobalExceptionHandler;
|
||||
import com.bruce.rag.service.IIngestionRunService;
|
||||
import com.bruce.rag.vo.IngestionRunVO;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* 验证文件解析管道聚合接口的请求绑定与响应结构。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class IngestionRunControllerTests {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Mock
|
||||
private IIngestionRunService ingestionRunService;
|
||||
|
||||
@InjectMocks
|
||||
private IngestionRunController ingestionRunController;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(ingestionRunController)
|
||||
.setControllerAdvice(new GlobalExceptionHandler())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createShouldReturnStructuredRunView() throws Exception {
|
||||
IngestionRunVO run = new IngestionRunVO();
|
||||
run.setRunId("ingestion-1001-11");
|
||||
run.setStoreId(1001L);
|
||||
run.setDocumentId(11L);
|
||||
|
||||
when(ingestionRunService.createRun(any())).thenReturn(run);
|
||||
|
||||
mockMvc.perform(post("/api/knowledge/ingestion-runs")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("""
|
||||
{
|
||||
"storeId": 1001,
|
||||
"documentId": 11
|
||||
}
|
||||
"""))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.resultcode").value("0"))
|
||||
.andExpect(jsonPath("$.data.runId").value("ingestion-1001-11"))
|
||||
.andExpect(jsonPath("$.data.storeId").value("1001"))
|
||||
.andExpect(jsonPath("$.data.documentId").value("11"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void detailShouldReturnStructuredRunView() throws Exception {
|
||||
IngestionRunVO run = new IngestionRunVO();
|
||||
run.setRunId("run-20260601");
|
||||
run.setStoreId(1001L);
|
||||
run.setDocumentId(11L);
|
||||
|
||||
when(ingestionRunService.getRun(1001L, 11L)).thenReturn(run);
|
||||
|
||||
mockMvc.perform(get("/api/knowledge/ingestion-runs/run-20260601")
|
||||
.param("storeId", "1001")
|
||||
.param("documentId", "11"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.resultcode").value("0"))
|
||||
.andExpect(jsonPath("$.data.runId").value("run-20260601"))
|
||||
.andExpect(jsonPath("$.data.storeId").value("1001"))
|
||||
.andExpect(jsonPath("$.data.documentId").value("11"));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.bruce.rag.ingestion;
|
||||
|
||||
import com.bruce.modelprovider.dto.response.RagStoreModelConfigResponse;
|
||||
import com.bruce.modelprovider.service.IRagStoreModelConfigService;
|
||||
import com.bruce.rag.dto.request.IngestionRunCreateRequest;
|
||||
import com.bruce.rag.dto.response.RagDocumentResponse;
|
||||
import com.bruce.rag.dto.response.RagStoreResponse;
|
||||
import com.bruce.rag.entity.RagChunk;
|
||||
@@ -51,6 +52,43 @@ class IngestionRunServiceTests {
|
||||
@InjectMocks
|
||||
private IngestionRunServiceImpl ingestionRunService;
|
||||
|
||||
@Test
|
||||
void createRunShouldGenerateStableRunId() {
|
||||
RagStoreResponse store = new RagStoreResponse();
|
||||
store.setId(1001L);
|
||||
store.setStoreCode("PROD_DOC");
|
||||
store.setStoreName("产品制度库");
|
||||
|
||||
RagDocumentResponse document = new RagDocumentResponse();
|
||||
document.setId(11L);
|
||||
document.setStoreId(1001L);
|
||||
document.setDocumentTitle("售前方案模板.pdf");
|
||||
document.setParseStatus("PARSED");
|
||||
document.setIndexStatus("INDEXED");
|
||||
document.setCreateTime(new Date(1748780000000L));
|
||||
document.setUpdateTime(new Date(1748780300000L));
|
||||
|
||||
when(ragStoreService.getResponseById(1001L)).thenReturn(store);
|
||||
when(ragDocumentService.getResponseById(11L)).thenReturn(document);
|
||||
when(ragDocumentParseResultService.getByDocumentId(11L)).thenReturn(null);
|
||||
when(ragChunkService.list(org.mockito.ArgumentMatchers.<com.baomidou.mybatisplus.core.conditions.Wrapper<RagChunk>>any()))
|
||||
.thenReturn(List.of());
|
||||
when(ragChunkEmbeddingService.list(org.mockito.ArgumentMatchers.<com.baomidou.mybatisplus.core.conditions.Wrapper<RagChunkEmbedding>>any()))
|
||||
.thenReturn(List.of());
|
||||
when(ragStoreModelConfigService.getByStoreId(1001L)).thenReturn(null);
|
||||
|
||||
IngestionRunCreateRequest request = new IngestionRunCreateRequest();
|
||||
request.setStoreId(1001L);
|
||||
request.setDocumentId(11L);
|
||||
|
||||
IngestionRunVO view = ingestionRunService.createRun(request);
|
||||
|
||||
assertNotNull(view);
|
||||
assertEquals("ingestion-1001-11", view.getRunId());
|
||||
assertEquals(1001L, view.getStoreId());
|
||||
assertEquals(11L, view.getDocumentId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getRunShouldAggregatePipelinePreviewAndLogs() {
|
||||
RagStoreResponse store = new RagStoreResponse();
|
||||
|
||||
Reference in New Issue
Block a user