refactor(harness): freeze single-agent contracts

This commit is contained in:
zhuyongxin
2026-07-21 17:33:25 +08:00
parent 30d3296043
commit 58c39107c5
47 changed files with 2607 additions and 24 deletions
@@ -0,0 +1,96 @@
package com.superbiz.agent.harness.contract;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class HarnessContractTest {
private final ObjectMapper objectMapper = new ObjectMapper();
@Test
void diagnosisDraftUsesStableBoundedShape() throws Exception {
DiagnosisDraft draft = new DiagnosisDraft(
new DiagnosisDraft.Conclusion("Pool exhausted", List.of("a1")),
List.of(new DiagnosisDraft.AnalysisItem(
"a1",
AnalysisKind.NORMAL,
"active=50 max=50",
List.of("call-1"))),
List.of(new DiagnosisDraft.ActionPlanItem(
"Inspect long transactions",
List.of("a1"),
false)),
List.of(new DiagnosisDraft.Recommendation(
"Add pool wait alerts",
List.of("a1"))),
new DiagnosisDraft.Limitations("order-service, last 30 minutes", List.of("No slow SQL data")));
JsonNode json = objectMapper.valueToTree(draft);
assertEquals("call-1", json.path("analysis").get(0).path("tool_call_ids").get(0).asText());
assertEquals("NORMAL", json.path("analysis").get(0).path("kind").asText());
assertTrue(json.has("action_plan"));
assertFalse(json.toString().contains("raw_response"));
assertFalse(json.toString().contains("thought"));
}
@Test
void evidenceStatusRemainsSeparateFromInvocationStatus() {
assertTrue(AnalysisKind.NORMAL.accepts(EvidenceStatus.EVIDENCE_FOUND));
assertFalse(AnalysisKind.NORMAL.accepts(EvidenceStatus.NO_EVIDENCE));
assertTrue(AnalysisKind.NEGATIVE_OBSERVATION.accepts(EvidenceStatus.NO_EVIDENCE));
assertFalse(AnalysisKind.NEGATIVE_OBSERVATION.accepts(EvidenceStatus.ERROR));
assertEquals(InvocationStatus.READY, InvocationStatus.valueOf("READY"));
}
@Test
void knowledgeAnswerBindsExactToolAndDocuments() throws Exception {
KnowledgeAnswerDraft draft = new KnowledgeAnswerDraft(
List.of(new KnowledgeAnswerDraft.AnswerItem(
"Check the timeout code first.",
"call-rag-1",
List.of("payment-timeout-guide"))),
List.of("Runtime state was not queried"));
JsonNode json = objectMapper.valueToTree(draft);
assertEquals("call-rag-1", json.path("answer_items").get(0).path("tool_call_id").asText());
assertEquals("payment-timeout-guide",
json.path("answer_items").get(0).path("document_ids").get(0).asText());
}
@Test
void fallbackAndPreviousTurnExcludeInternalEvidence() throws Exception {
SafeFallback fallback = new SafeFallback(
FallbackType.SEMANTIC_UNSUPPORTED,
null,
"Current evidence is insufficient",
List.of(new SafeFallback.VerifiedSource("LOG", "APPLICATION", "last 30 minutes")),
List.of("Semantic validation did not pass"),
List.of("Collect the missing data and retry"));
PublishedResult result = new PublishedResult(
"Check payment timeout",
"Connection pool exhaustion",
"order-service, last 30 minutes",
List.of("No slow SQL data"),
List.of(new SourceDocument("payment-timeout-guide", "Payment timeout guide")));
JsonNode fallbackJson = objectMapper.valueToTree(fallback);
JsonNode previousJson = objectMapper.valueToTree(PreviousTurn.from(result));
assertNull(fallback.conclusion());
assertEquals("SEMANTIC_UNSUPPORTED", fallbackJson.path("type").asText());
assertEquals("payment-timeout-guide",
previousJson.path("source_documents").get(0).path("document_id").asText());
assertFalse(previousJson.toString().contains("tool_call_id"));
assertFalse(previousJson.toString().contains("raw_response"));
}
}
@@ -4,6 +4,7 @@ import io.milvus.client.MilvusServiceClient;
import io.milvus.param.ConnectParam;
import io.milvus.param.R;
import io.milvus.param.collection.HasCollectionParam;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;
/**
@@ -13,9 +14,12 @@ public class SimpleMilvusTest {
@Test
public void testConnection() {
String host = "in03-4a578da0f27ce9d.serverless.aws-eu-central-1.cloud.zilliz.com";
int port = 443;
String token = "d246a77f43a109685596e3c68ecfd359e1cd8b29d35c41d708160f02b97ae623d2ab392738df740d0c77b58ca1bbadfa7c412140";
String host = System.getenv().getOrDefault(
"MILVUS_HOST",
"in03-4a578da0f27ce9d.serverless.aws-eu-central-1.cloud.zilliz.com");
int port = Integer.parseInt(System.getenv().getOrDefault("MILVUS_PORT", "443"));
String token = System.getenv("MILVUS_TOKEN");
Assumptions.assumeTrue(token != null && !token.isBlank(), "MILVUS_TOKEN is required");
System.out.println("尝试连接 Milvus...");
System.out.println("Host: " + host);
@@ -4,6 +4,7 @@ import com.superbiz.agent.domain.model.SessionContext;
import com.superbiz.agent.domain.model.ToolCall;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
@@ -20,10 +21,11 @@ import static org.junit.jupiter.api.Assertions.*;
* RedisSessionManager 单元测试
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@EnabledIfEnvironmentVariable(named = "SUPERBIZ_REDIS_PASSWORD", matches = ".+")
@TestPropertySource(properties = {
"spring.redis.host=119.29.78.52",
"spring.redis.port=6379",
"spring.redis.password=!Fucker123.."
"spring.data.redis.host=${SUPERBIZ_REDIS_HOST:119.29.78.52}",
"spring.data.redis.port=${SUPERBIZ_REDIS_PORT:33308}",
"spring.data.redis.password=${SUPERBIZ_REDIS_PASSWORD}"
})
class RedisSessionManagerTest {