|
|
@@ -0,0 +1,145 @@
|
|
|
+package com.etotem.cfc.unit;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.Arrays;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+import static org.junit.jupiter.api.Assertions.fail;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 契约级单测(TDD-RED 阶段,S-cfc-255):能力键 {@code butler.ai.collaborate} 的闭环后半段补充契约。
|
|
|
+ *
|
|
|
+ * <p>同批已有 {@code ButlerAiCollaborationContractTest} 覆盖「闭环标记 → 反哺提交/审核 → 反馈家长 →
|
|
|
+ * 隐私/审计」主链路;本测试补齐其未覆盖的三条 TC-H-06 条款:</p>
|
|
|
+ * <ul>
|
|
|
+ * <li>TC-H-06 正常流步骤 4/5:审核通过后知识库可检索、AI 回答能命中新知识;</li>
|
|
|
+ * <li>TC-H-06「审核未通过可退回修改」:退回后允许修改后的反哺重提;</li>
|
|
|
+ * <li>TC-H-06-E 步骤 4:闭环后原家长再次追问,可重新开启工单并关联历史,不丢上下文。</li>
|
|
|
+ * </ul>
|
|
|
+ *
|
|
|
+ * <p>契约宿主与同批测试一致:服务 {@code com.etotem.cfc.service.ButlerAiCollaborationService}、
|
|
|
+ * 实体 {@code com.etotem.cfc.entity.ButlerAiFeedback}(表 {@code butler_ai_feedbacks})。当前 src/main
|
|
|
+ * 未落地,以下用例在反射探测处失败(红);GREEN 阶段实现宿主后自动转绿。</p>
|
|
|
+ *
|
|
|
+ * <p>测试风格:纯反射,无 Spring / 无 DB / 无外部服务。</p>
|
|
|
+ */
|
|
|
+class ButlerAiCollaborateLoopContractTest {
|
|
|
+
|
|
|
+ private static final String SERVICE_CLASS = "com.etotem.cfc.service.ButlerAiCollaborationService";
|
|
|
+ private static final String ENTITY_CLASS = "com.etotem.cfc.entity.ButlerAiFeedback";
|
|
|
+
|
|
|
+ /** 工单历史关联字段候选名(重开后不丢上下文,TC-H-06-E)。 */
|
|
|
+ private static final String[] HISTORY_LINK_FIELDS = {
|
|
|
+ "previousWorkorderId", "sourceWorkorderId", "parentWorkorderId", "relatedWorkorderId"
|
|
|
+ };
|
|
|
+
|
|
|
+ // ==================== 正常流:审核后知识命中 / 退回重提 ====================
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("正常流-补充1:verifyKnowledgeHit(...) 应存在并验证反哺条目可被 AI 命中")
|
|
|
+ void knowledgeHitMethod_exists() {
|
|
|
+ Class<?> svc = loadClass(SERVICE_CLASS);
|
|
|
+ if (svc == null) {
|
|
|
+ fail("[butler.ai.collaborate] ButlerAiCollaborationService 不存在,无法验证 verifyKnowledgeHit()(知识命中)。");
|
|
|
+ }
|
|
|
+ assertTrue(hasMethodNamed(svc, "verifyKnowledgeHit", "knowledgeHit", "searchFeedback"),
|
|
|
+ "[butler.ai.collaborate] 宿主服务应提供审核通过后验证知识库可检索、AI 回答命中新知识的方法"
|
|
|
+ + "(verifyKnowledgeHit / knowledgeHit / searchFeedback),对应 TC-H-06 步骤 4/5。"
|
|
|
+ + "当前未实现。");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("正常流-补充2:resubmitFeedback(...) 应存在并支持退回修改后重提")
|
|
|
+ void resubmitAfterRejectMethod_exists() {
|
|
|
+ Class<?> svc = loadClass(SERVICE_CLASS);
|
|
|
+ if (svc == null) {
|
|
|
+ fail("[butler.ai.collaborate] ButlerAiCollaborationService 不存在,无法验证 resubmitFeedback()(退回重提)。");
|
|
|
+ }
|
|
|
+ assertTrue(hasMethodNamed(svc, "resubmitFeedback", "updateFeedback", "reviseFeedback"),
|
|
|
+ "[butler.ai.collaborate] 宿主服务应提供反哺审核未通过(REJECTED)后修改并重提的方法"
|
|
|
+ + "(resubmitFeedback / updateFeedback / reviseFeedback),对应 TC-H-06「未通过可退回修改」。"
|
|
|
+ + "当前未实现。");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 异常流:闭环后重开并关联历史 ====================
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("异常流-补充1:reopenWorkorder(...) 应存在并关联历史工单(不丢上下文)")
|
|
|
+ void reopenWithHistoryMethod_exists() {
|
|
|
+ Class<?> svc = loadClass(SERVICE_CLASS);
|
|
|
+ if (svc == null) {
|
|
|
+ fail("[butler.ai.collaborate] ButlerAiCollaborationService 不存在,无法验证 reopenWorkorder()(闭环后重开)。");
|
|
|
+ }
|
|
|
+ assertTrue(hasMethodNamed(svc, "reopenWorkorder", "reopen", "reopenEscalation"),
|
|
|
+ "[butler.ai.collaborate] 宿主服务应提供闭环后原家长再次追问时重新开启工单并关联历史的方法"
|
|
|
+ + "(reopenWorkorder / reopen / reopenEscalation),对应 TC-H-06-E 步骤 4「不丢上下文」。"
|
|
|
+ + "当前未实现。");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("异常流-补充2:反哺实体应含历史工单关联字段(重开可追溯)")
|
|
|
+ void feedbackEntity_hasHistoryLinkField() {
|
|
|
+ Class<?> entity = loadClass(ENTITY_CLASS);
|
|
|
+ if (entity == null) {
|
|
|
+ fail("[butler.ai.collaborate] ButlerAiFeedback 实体不存在,无法验证历史关联字段(TC-H-06-E)。");
|
|
|
+ }
|
|
|
+ String found = null;
|
|
|
+ for (String candidate : HISTORY_LINK_FIELDS) {
|
|
|
+ if (findField(entity, candidate) != null) {
|
|
|
+ found = candidate;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertNotNull(found,
|
|
|
+ "[butler.ai.collaborate] ButlerAiFeedback 应含历史工单关联字段("
|
|
|
+ + Arrays.toString(HISTORY_LINK_FIELDS) + " 之一),使闭环后重开工单可关联历史、不丢上下文"
|
|
|
+ + "(TC-H-06-E)。当前未实现。");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("异常流-补充3:三流覆盖说明(本补充文件聚焦 TC-H-06 主链路遗漏条款)")
|
|
|
+ void coverageNote() {
|
|
|
+ assertTrue(true,
|
|
|
+ "覆盖说明:闭环标记/反哺提交审核/反馈家长/隐私/审计由 ButlerAiCollaborationContractTest 覆盖;"
|
|
|
+ + "本文件补充知识命中、退回重提、闭环后重开并关联历史三条条款。");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 反射辅助 ====================
|
|
|
+
|
|
|
+ private Class<?> loadClass(String name) {
|
|
|
+ try {
|
|
|
+ return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Field findField(Class<?> clazz, String name) {
|
|
|
+ Class<?> c = clazz;
|
|
|
+ while (c != null && c != Object.class) {
|
|
|
+ for (Field f : c.getDeclaredFields()) {
|
|
|
+ if (f.getName().equals(name)) {
|
|
|
+ return f;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c = c.getSuperclass();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean hasMethodNamed(Class<?> clazz, String... candidates) {
|
|
|
+ for (Method m : clazz.getDeclaredMethods()) {
|
|
|
+ for (String candidate : candidates) {
|
|
|
+ if (m.getName().equals(candidate)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|