11"""Unit tests for QueryResponse model."""
22
3- from models .responses import QueryResponse
3+ from models .responses import QueryResponse , RAGChunk , ToolCall , ReferencedDocument
44
55
66class TestQueryResponse :
@@ -20,3 +20,110 @@ def test_optional_conversation_id(self) -> None:
2020 qr = QueryResponse (response = "LLM answer" )
2121 assert qr .conversation_id is None
2222 assert qr .response == "LLM answer"
23+
24+ def test_rag_chunks_empty_by_default (self ) -> None :
25+ """Test that rag_chunks is empty by default."""
26+ qr = QueryResponse (response = "LLM answer" )
27+ assert not qr .rag_chunks
28+
29+ def test_rag_chunks_with_data (self ) -> None :
30+ """Test QueryResponse with RAG chunks."""
31+ rag_chunks = [
32+ RAGChunk (
33+ content = "Kubernetes is an open-source container orchestration system" ,
34+ source = "kubernetes-docs/overview.md" ,
35+ score = 0.95 ,
36+ ),
37+ RAGChunk (
38+ content = "Container orchestration automates deployment and management" ,
39+ source = "kubernetes-docs/concepts.md" ,
40+ score = 0.87 ,
41+ ),
42+ ]
43+
44+ qr = QueryResponse (
45+ conversation_id = "123e4567-e89b-12d3-a456-426614174000" ,
46+ response = "LLM answer with RAG context" ,
47+ rag_chunks = rag_chunks ,
48+ )
49+
50+ assert len (qr .rag_chunks ) == 2
51+ assert (
52+ qr .rag_chunks [0 ].content
53+ == "Kubernetes is an open-source container orchestration system"
54+ )
55+ assert qr .rag_chunks [0 ].source == "kubernetes-docs/overview.md"
56+ assert qr .rag_chunks [0 ].score == 0.95
57+ assert (
58+ qr .rag_chunks [1 ].content
59+ == "Container orchestration automates deployment and management"
60+ )
61+ assert qr .rag_chunks [1 ].source == "kubernetes-docs/concepts.md"
62+ assert qr .rag_chunks [1 ].score == 0.87
63+
64+ def test_rag_chunks_with_optional_fields (self ) -> None :
65+ """Test RAG chunks with optional source and score fields."""
66+ rag_chunks = [
67+ RAGChunk (content = "Some content without source or score" ),
68+ RAGChunk (content = "Content with source only" , source = "docs/guide.md" ),
69+ RAGChunk (content = "Content with score only" , score = 0.75 ),
70+ ]
71+
72+ qr = QueryResponse (response = "LLM answer" , rag_chunks = rag_chunks )
73+
74+ assert len (qr .rag_chunks ) == 3
75+ assert qr .rag_chunks [0 ].source is None
76+ assert qr .rag_chunks [0 ].score is None
77+ assert qr .rag_chunks [1 ].source == "docs/guide.md"
78+ assert qr .rag_chunks [1 ].score is None
79+ assert qr .rag_chunks [2 ].source is None
80+ assert qr .rag_chunks [2 ].score == 0.75
81+
82+ def test_complete_query_response_with_all_fields (self ) -> None :
83+ """Test QueryResponse with all fields including RAG chunks, tool calls, and docs."""
84+ rag_chunks = [
85+ RAGChunk (
86+ content = "OLM is a component of the Operator Framework toolkit" ,
87+ source = "kubernetes-docs/operators.md" ,
88+ score = 0.95 ,
89+ )
90+ ]
91+
92+ tool_calls = [
93+ ToolCall (
94+ tool_name = "knowledge_search" ,
95+ arguments = {"query" : "operator lifecycle manager" },
96+ result = {"chunks_found" : 5 },
97+ )
98+ ]
99+
100+ referenced_documents = [
101+ ReferencedDocument (
102+ doc_url = (
103+ "https://docs.openshift.com/container-platform/4.15/operators/olm/index.html"
104+ ),
105+ doc_title = "Operator Lifecycle Manager (OLM)" ,
106+ )
107+ ]
108+
109+ qr = QueryResponse (
110+ conversation_id = "123e4567-e89b-12d3-a456-426614174000" ,
111+ response = "Operator Lifecycle Manager (OLM) helps users install..." ,
112+ rag_chunks = rag_chunks ,
113+ tool_calls = tool_calls ,
114+ referenced_documents = referenced_documents ,
115+ )
116+
117+ assert qr .conversation_id == "123e4567-e89b-12d3-a456-426614174000"
118+ assert qr .response == "Operator Lifecycle Manager (OLM) helps users install..."
119+ assert len (qr .rag_chunks ) == 1
120+ assert (
121+ qr .rag_chunks [0 ].content
122+ == "OLM is a component of the Operator Framework toolkit"
123+ )
124+ assert len (qr .tool_calls ) == 1
125+ assert qr .tool_calls [0 ].tool_name == "knowledge_search"
126+ assert len (qr .referenced_documents ) == 1
127+ assert (
128+ qr .referenced_documents [0 ].doc_title == "Operator Lifecycle Manager (OLM)"
129+ )
0 commit comments