- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称 - 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配 - 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配 - 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名 - 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试 - 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token - 调整系统角色授权用户页面的表单布局和表格样式类名 - 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
108 lines
7.3 KiB
Java
108 lines
7.3 KiB
Java
package com.ruoyi.projectdev;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.ruoyi.web.service.assistant.AssistantPermissionGuard;
|
|
import com.ruoyi.web.service.assistant.BusinessActionRegistry;
|
|
import jakarta.validation.Validator;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Map;
|
|
import java.util.List;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
/** Optional SELECT-only verification against the guarded development schema; no fixture inserts or migration. */
|
|
@EnabledIfSystemProperty(named = "assistantReadOnlyDbTests", matches = "true")
|
|
class AssistantReferenceSchemaDatabaseTest {
|
|
@Test void everyFixedReferenceProjectionCompilesAgainstExistingSchema() throws Exception {
|
|
var registry = new BusinessActionRegistry(mock(ApplicationContext.class), new ObjectMapper().findAndRegisterModules(),
|
|
mock(JdbcTemplate.class), mock(Validator.class), mock(AssistantPermissionGuard.class));
|
|
Map<?, ?> references = (Map<?, ?>) ReflectionTestUtils.getField(registry, "references");
|
|
assertNotNull(references);
|
|
try (var connection = AuthorizedDatabaseTestSupport.connection()) {
|
|
connection.setReadOnly(true);
|
|
var checks=new java.util.ArrayList<org.junit.jupiter.api.function.Executable>();
|
|
for (var entry : references.entrySet()) checks.add(()->{
|
|
Method accessor = entry.getValue().getClass().getDeclaredMethod("sql"); accessor.setAccessible(true);
|
|
String sql = (String) accessor.invoke(entry.getValue());
|
|
if(sql.isBlank())return; // System references use scoped native services, not SQL projections.
|
|
assertTrue(sql.stripLeading().toLowerCase().startsWith("select "));
|
|
try (var statement = connection.prepareStatement("select * from (" + sql + ") assistant_reference_schema where 1=0")) {
|
|
try (var rows = statement.executeQuery()) {
|
|
assertFalse(rows.next());
|
|
assertTrue(rows.getMetaData().getColumnCount() >= 2);
|
|
}
|
|
} catch (Exception failure) {
|
|
fail("Assistant reference projection is invalid: " + entry.getKey(), failure);
|
|
}
|
|
});
|
|
try {assertAll("All assistant reference SQL projections",checks);} finally {connection.rollback();}
|
|
}
|
|
}
|
|
|
|
@Test void allBusinessCandidateSearchesCompileIncludingExactRankingAndLiteralWildcards() throws Exception {
|
|
try(var connection=AuthorizedDatabaseTestSupport.connection()) {
|
|
connection.setReadOnly(true);
|
|
var jdbc=new JdbcTemplate(new org.springframework.jdbc.datasource.SingleConnectionDataSource(connection,true));
|
|
var registry=new BusinessActionRegistry(mock(ApplicationContext.class),new ObjectMapper().findAndRegisterModules(),jdbc,mock(Validator.class),mock(AssistantPermissionGuard.class));
|
|
Map<?,?> references=(Map<?,?>)ReflectionTestUtils.getField(registry,"references");assertNotNull(references);
|
|
var checks=new java.util.ArrayList<org.junit.jupiter.api.function.Executable>();
|
|
for(Object key:references.keySet())if(!key.toString().startsWith("sys"))checks.add(()->{
|
|
List<?> rows=ReflectionTestUtils.invokeMethod(registry,"candidates",key.toString(),"AI-LOOKUP-NOT-EXIST_%'",null);
|
|
assertNotNull(rows,key.toString());assertTrue(rows.size()<=50,key.toString());
|
|
});
|
|
try{assertAll("Every business candidate search uses valid bounded SELECTs",checks);}finally{connection.rollback();}
|
|
}
|
|
}
|
|
|
|
@Test void exactSupplierAndItemNamesOlderThanFiftyFuzzyNamesRemainResolvable() throws Exception {
|
|
try(var connection=AuthorizedDatabaseTestSupport.connection()) {
|
|
var jdbc=new JdbcTemplate(new org.springframework.jdbc.datasource.SingleConnectionDataSource(connection,true));
|
|
var registry=new BusinessActionRegistry(mock(ApplicationContext.class),new ObjectMapper().findAndRegisterModules(),jdbc,mock(Validator.class),mock(AssistantPermissionGuard.class));
|
|
String name="AI-EXACT-"+java.util.UUID.randomUUID();
|
|
try {
|
|
jdbc.update("insert into supplier_info(name,active) values(?,1)",name);
|
|
jdbc.update("insert into product_info(product_code,product_name,unit) values(?,?,'个')",name,name);
|
|
for(int i=0;i<65;i++) {
|
|
jdbc.update("insert into supplier_info(name,active) values(?,1)",name+"-相近"+i);
|
|
jdbc.update("insert into product_info(product_code,product_name,unit) values(?,?,'个')",name+"-"+i,name+"-相近"+i);
|
|
}
|
|
for(String ref:List.of("supplier","item")) {
|
|
List<Map<String,Object>> found=ReflectionTestUtils.invokeMethod(registry,"resolveReference",ref,name,Map.of());
|
|
assertNotNull(found);assertEquals(1,found.size(),ref);assertEquals(name,found.get(0).get("name"));
|
|
}
|
|
} finally {connection.rollback();}
|
|
}
|
|
}
|
|
|
|
@Test void editPrefillAndBomLinesAreSelectOnlyAndMatchExistingSchema() throws Exception {
|
|
var registry = new BusinessActionRegistry(mock(ApplicationContext.class), new ObjectMapper().findAndRegisterModules(),
|
|
mock(JdbcTemplate.class), mock(Validator.class), mock(AssistantPermissionGuard.class));
|
|
Method query = BusinessActionRegistry.class.getDeclaredMethod("existingRecordQuery", String.class); query.setAccessible(true);
|
|
Map<?, ?> actions=(Map<?, ?>)ReflectionTestUtils.getField(registry,"actions");assertNotNull(actions);
|
|
var statements=new java.util.LinkedHashMap<String,String>();
|
|
for(Object action:actions.keySet()) {
|
|
String sql=(String)query.invoke(registry,action.toString());
|
|
if(sql!=null)statements.put(action.toString(),sql);
|
|
}
|
|
statements.put("bom.lines",(String)ReflectionTestUtils.getField(BusinessActionRegistry.class,"BOM_LINES_QUERY"));
|
|
assertTrue(statements.keySet().containsAll(List.of("project.update","purchase.update","supplier.save","bom.save","production.save")));
|
|
try(var connection=AuthorizedDatabaseTestSupport.connection()) {
|
|
connection.setReadOnly(true);
|
|
var checks=new java.util.ArrayList<org.junit.jupiter.api.function.Executable>();
|
|
for(var entry:statements.entrySet()) checks.add(()->{
|
|
assertTrue(entry.getValue().stripLeading().toLowerCase().startsWith("select "));
|
|
try(var statement=connection.prepareStatement("select * from ("+entry.getValue()+") assistant_edit_schema where 1=0")) {
|
|
statement.setLong(1,-1L);
|
|
try(var rows=statement.executeQuery()){assertFalse(rows.next());assertTrue(rows.getMetaData().getColumnCount()>0);}
|
|
} catch(Exception failure){fail("Assistant edit projection is invalid: "+entry.getKey(),failure);}
|
|
});
|
|
try {assertAll("All assistant edit SQL projections",checks);} finally {connection.rollback();}
|
|
}
|
|
}
|
|
}
|