7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
164 lines
5.4 KiB
Python
164 lines
5.4 KiB
Python
"""Integration tests for Chat with Research system.
|
|
|
|
These tests verify the end-to-end flow from chat messages to research.
|
|
"""
|
|
|
|
|
|
class TestResearchIntegration:
|
|
"""Tests for chat-research integration."""
|
|
|
|
def test_research_context_built_from_conversation_history(self):
|
|
"""Test that research context reflects the conversation turns."""
|
|
from src.local_deep_research.chat.context import ChatContextManager
|
|
|
|
messages = [
|
|
{
|
|
"id": "msg-1",
|
|
"role": "user",
|
|
"content": "What is quantum computing?",
|
|
"message_type": "query",
|
|
},
|
|
{
|
|
"id": "msg-2",
|
|
"role": "assistant",
|
|
"content": "Quantum computing uses quantum mechanics...",
|
|
"message_type": "response",
|
|
"research_id": "research-1",
|
|
},
|
|
{
|
|
"id": "msg-3",
|
|
"role": "user",
|
|
"content": "What about practical applications?",
|
|
"message_type": "query",
|
|
},
|
|
]
|
|
|
|
accumulated_context = {
|
|
"key_entities": ["quantum computing", "qubits"],
|
|
"topics": ["physics", "computing"],
|
|
"summary": "Discussion about quantum computing basics.",
|
|
}
|
|
|
|
manager = ChatContextManager(
|
|
session_id="test-session",
|
|
messages=messages,
|
|
accumulated_context=accumulated_context,
|
|
)
|
|
|
|
context = manager.build_research_context()
|
|
|
|
# Should reflect the multi-turn conversation
|
|
assert context["is_multi_turn"] is True
|
|
assert context["turn_count"] == 3
|
|
# Should include accumulated data
|
|
assert "quantum computing" in context["key_entities"]
|
|
assert "physics" in context["topics"]
|
|
|
|
def test_context_includes_previous_research_findings(self):
|
|
"""Test that context includes findings from previous research."""
|
|
from src.local_deep_research.chat.context import ChatContextManager
|
|
|
|
messages = [
|
|
{
|
|
"id": "msg-1",
|
|
"role": "user",
|
|
"content": "What is quantum computing?",
|
|
"message_type": "query",
|
|
},
|
|
{
|
|
"id": "msg-2",
|
|
"role": "assistant",
|
|
"content": "Quantum computing is a type of computing that uses quantum bits (qubits) instead of classical bits. It leverages quantum mechanical phenomena like superposition and entanglement.",
|
|
"message_type": "response",
|
|
"research_id": "research-1",
|
|
},
|
|
]
|
|
|
|
manager = ChatContextManager(
|
|
session_id="test-session",
|
|
messages=messages,
|
|
accumulated_context={},
|
|
)
|
|
|
|
findings = manager._extract_findings_from_history()
|
|
|
|
# Should extract content from assistant messages with research_id
|
|
assert "quantum" in findings.lower()
|
|
assert (
|
|
"qubits" in findings.lower() or "superposition" in findings.lower()
|
|
)
|
|
|
|
def test_multi_turn_flag_correct_for_first_message(self):
|
|
"""Test that is_multi_turn is False for first message."""
|
|
from src.local_deep_research.chat.context import ChatContextManager
|
|
|
|
manager = ChatContextManager(
|
|
session_id="test-session",
|
|
messages=[], # No previous messages
|
|
accumulated_context={},
|
|
)
|
|
|
|
context = manager.build_research_context()
|
|
|
|
assert context["is_multi_turn"] is False
|
|
assert context["turn_count"] == 0
|
|
|
|
def test_multi_turn_flag_correct_for_followup(self):
|
|
"""Test that is_multi_turn is True for follow-up messages."""
|
|
from src.local_deep_research.chat.context import ChatContextManager
|
|
|
|
messages = [
|
|
{
|
|
"id": "msg-1",
|
|
"role": "user",
|
|
"content": "Initial question",
|
|
"message_type": "query",
|
|
},
|
|
{
|
|
"id": "msg-2",
|
|
"role": "assistant",
|
|
"content": "Initial response",
|
|
"message_type": "response",
|
|
"research_id": "research-1",
|
|
},
|
|
]
|
|
|
|
manager = ChatContextManager(
|
|
session_id="test-session",
|
|
messages=messages,
|
|
accumulated_context={},
|
|
)
|
|
|
|
context = manager.build_research_context()
|
|
|
|
assert context["is_multi_turn"] is True
|
|
assert context["turn_count"] == 2
|
|
|
|
|
|
class TestContextExtraction:
|
|
"""Tests for context extraction from research results."""
|
|
|
|
def test_extract_context_updates_from_new_research(self):
|
|
"""Test extracting context updates from new research content."""
|
|
from src.local_deep_research.chat.context import ChatContextManager
|
|
|
|
manager = ChatContextManager(
|
|
session_id="test-session",
|
|
messages=[],
|
|
accumulated_context={},
|
|
)
|
|
|
|
new_content = """
|
|
Quantum computing represents a fundamental shift in computing paradigms.
|
|
|
|
Key findings:
|
|
- Qubits can exist in multiple states simultaneously
|
|
- Quantum entanglement enables faster processing
|
|
- Applications include cryptography and drug discovery
|
|
"""
|
|
|
|
updates = manager.extract_context_updates(new_content)
|
|
|
|
# Should have summary
|
|
assert len(updates["summary_addition"]) > 0
|