|
|
@@ -30,12 +30,13 @@ import static org.mockito.Mockito.when;
|
|
|
* {@link WorkspaceSchemaCatalog} 的离线契约测试:<b>不连真 PG / 不连 DuckDB</b>。
|
|
|
*
|
|
|
* <p>目录是 Agent {@code list_tables} 与 {@code search_table_schema} 的唯一事实来源,
|
|
|
- * 事实来源只有两套模板元数据。这里钉住五件事:
|
|
|
+ * 事实来源是三套元数据(两套模板库 + 取证表结构文件)。这里钉住六件事:
|
|
|
* <ol>
|
|
|
* <li>既有模板({@code table_info}/{@code table_field})与 AI 模板({@code ai_clean_template}/{@code ai_clean_field})
|
|
|
* 都在清单里,<b>AI 模板不按 status 过滤</b>;</li>
|
|
|
* <li>列名用<b>物理列名</b>:既有模板取 {@code field_name_en},AI 动态表取 {@code column_name}(c0..cN);</li>
|
|
|
* <li>type / comment / required 的映射口径(类型空则 TEXT、必填按 required==1);</li>
|
|
|
+ * <li>取证表来自 {@link WaForensicsSchemaCatalog#usable()},类型用原始 SQL 类型;</li>
|
|
|
* <li>无字段的表跳过、输出按表名排序、列按 {@code field_sort} 稳定排序;</li>
|
|
|
* <li>元数据查询失败直接上抛,不静默返回空列表(空列表会被误读成「模板库里没有表」)。</li>
|
|
|
* </ol>
|
|
|
@@ -49,6 +50,7 @@ class WorkspaceSchemaCatalogTest {
|
|
|
private TableFieldMapper tableFieldMapper;
|
|
|
private AiCleanTemplateMapper aiCleanTemplateMapper;
|
|
|
private AiCleanFieldMapper aiCleanFieldMapper;
|
|
|
+ private WaForensicsSchemaCatalog waForensicsSchemaCatalog;
|
|
|
private WorkspaceSchemaCatalog catalog;
|
|
|
|
|
|
@BeforeEach
|
|
|
@@ -57,8 +59,11 @@ class WorkspaceSchemaCatalogTest {
|
|
|
tableFieldMapper = mock(TableFieldMapper.class);
|
|
|
aiCleanTemplateMapper = mock(AiCleanTemplateMapper.class);
|
|
|
aiCleanFieldMapper = mock(AiCleanFieldMapper.class);
|
|
|
+ waForensicsSchemaCatalog = mock(WaForensicsSchemaCatalog.class);
|
|
|
+ // 默认无取证表:不关心取证目录的用例保持原有断言
|
|
|
+ when(waForensicsSchemaCatalog.usable()).thenReturn(List.of());
|
|
|
catalog = new WorkspaceSchemaCatalog(tableInfoMapper, tableFieldMapper,
|
|
|
- aiCleanTemplateMapper, aiCleanFieldMapper);
|
|
|
+ aiCleanTemplateMapper, aiCleanFieldMapper, waForensicsSchemaCatalog);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -180,6 +185,43 @@ class WorkspaceSchemaCatalogTest {
|
|
|
assertEquals(List.of("field_en"), tables.get(0).columns().stream().map(ColumnSchema::name).toList());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ @DisplayName("取证表也在清单里:类型用原始 SQL 类型、只认 usable()(ext 表不进)、同名以模板库为准")
|
|
|
+ void includesForensicsTables() {
|
|
|
+ when(tableInfoMapper.selectList(any())).thenReturn(List.of(
|
|
|
+ tableInfo(1, "call_record", "通话记录")));
|
|
|
+ when(tableFieldMapper.selectList(any())).thenReturn(List.of(
|
|
|
+ tableField(1, "call_time", "通话时间", FieldTypeEnum.TEXT, 1, 0)));
|
|
|
+ when(aiCleanTemplateMapper.selectList(any())).thenReturn(List.of());
|
|
|
+ when(aiCleanFieldMapper.selectList(any())).thenReturn(List.of());
|
|
|
+ // ext 表(vectorize=false)由 WaForensicsSchemaCatalog 在 usable() 里排除,本类只消费 usable();
|
|
|
+ // 这里再放一张与模板同名的取证表,验证「模板库优先」
|
|
|
+ when(waForensicsSchemaCatalog.usable()).thenReturn(List.of(
|
|
|
+ forensicsTable("wa_mforensics_010100", "基本信息",
|
|
|
+ forensicsColumn("id", "id", "BIGINT", "NUMBER", true),
|
|
|
+ forensicsColumn("amount", "交易金额", "DECIMAL(18,2)", "NUMBER", false),
|
|
|
+ forensicsColumn("remark", "备注", null, "TEXT", false)),
|
|
|
+ forensicsTable("call_record", "取证同名表",
|
|
|
+ forensicsColumn("x", "x", "VARCHAR", "TEXT", false))));
|
|
|
+
|
|
|
+ List<TableSchema> tables = catalog.allTables();
|
|
|
+
|
|
|
+ assertEquals(List.of("call_record", "wa_mforensics_010100"),
|
|
|
+ tables.stream().map(TableSchema::tableName).toList());
|
|
|
+ assertEquals("通话记录", tables.get(0).tableComment(), "同名表以模板库为准");
|
|
|
+
|
|
|
+ TableSchema forensics = tables.get(1);
|
|
|
+ assertEquals("基本信息", forensics.tableComment());
|
|
|
+ assertEquals(List.of("id", "amount", "remark"),
|
|
|
+ forensics.columns().stream().map(ColumnSchema::name).toList());
|
|
|
+ assertEquals("BIGINT", column(forensics, "id").type(), "取证表类型用原始 SQL 类型而不是 NUMBER");
|
|
|
+ assertEquals("DECIMAL(18,2)", column(forensics, "amount").type());
|
|
|
+ assertEquals("TEXT", column(forensics, "remark").type(), "sqlType 缺失时退回平台类型");
|
|
|
+ assertEquals("交易金额", column(forensics, "amount").comment());
|
|
|
+ assertTrue(column(forensics, "id").required());
|
|
|
+ assertFalse(column(forensics, "amount").required());
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
@DisplayName("查询失败直接上抛:不静默返回空列表(空列表会被当成「模板库里没有表」)")
|
|
|
void queryFailurePropagates() {
|
|
|
@@ -253,4 +295,15 @@ class WorkspaceSchemaCatalogTest {
|
|
|
field.setRequired(required);
|
|
|
return field;
|
|
|
}
|
|
|
+
|
|
|
+ private static WaForensicsSchemaCatalog.TableSchema forensicsTable(
|
|
|
+ String nameEn, String nameCn, WaForensicsSchemaCatalog.ColumnSchema... columns) {
|
|
|
+ return new WaForensicsSchemaCatalog.TableSchema(
|
|
|
+ nameEn, nameCn, "取证数据库", "", true, List.of(columns));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static WaForensicsSchemaCatalog.ColumnSchema forensicsColumn(
|
|
|
+ String name, String comment, String sqlType, String fieldType, boolean required) {
|
|
|
+ return new WaForensicsSchemaCatalog.ColumnSchema(name, comment, sqlType, fieldType, required);
|
|
|
+ }
|
|
|
}
|