Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

85 lines
2.7 KiB
Python

"""Unit tests for the summarization module.
Covers BaseSummarizer machinery (input cap, truncation, think-tag stripping,
error handling) and the FocusedSummarizer prompt via a concrete summarizer.
"""
from unittest.mock import Mock
from local_deep_research.advanced_search_system.summarization import (
FocusedSummarizer,
)
def _fake_model(content: str) -> Mock:
model = Mock()
model.invoke.return_value = Mock(content=content)
return model
class TestFocusedSummarizer:
def test_returns_llm_output_when_under_limit(self):
model = _fake_model("Short summary.")
result = FocusedSummarizer(model, focus_query="q").summarize(
"some long content here"
)
assert result == "Short summary."
model.invoke.assert_called_once()
def test_empty_content_skips_llm_call(self):
model = _fake_model("never used")
result = FocusedSummarizer(model, focus_query="q").summarize("")
assert result == ""
model.invoke.assert_not_called()
def test_truncates_summary_above_max_chars(self):
long_text = "X" * 500
model = _fake_model(long_text)
result = FocusedSummarizer(
model, focus_query="q", max_chars=100
).summarize("input")
assert len(result) == 103 # 100 chars + "..."
assert result.endswith("...")
def test_strips_think_tags_from_response(self):
model = _fake_model(
"<think>internal reasoning</think>Actual summary content."
)
result = FocusedSummarizer(model, focus_query="q").summarize("input")
assert "internal reasoning" not in result
assert "Actual summary content." in result
def test_returns_empty_string_on_llm_exception(self):
model = Mock()
model.invoke.side_effect = RuntimeError("rate limited")
result = FocusedSummarizer(model, focus_query="q").summarize(
"some content"
)
assert result == ""
def test_truncates_oversized_input_before_prompting(self):
model = _fake_model("ok")
oversize_input = "A" * 50000
FocusedSummarizer(model, focus_query="q").summarize(oversize_input)
prompt = model.invoke.call_args.args[0]
# The base class caps input at INPUT_TRUNCATE_CHARS so the LLM call
# stays bounded rather than carrying the entire 50k input.
assert len(prompt) < 50000
def test_focus_query_and_max_sentences_in_prompt(self):
model = _fake_model("ok")
FocusedSummarizer(
model, focus_query="What about cost?", max_sentences=7
).summarize("hello")
prompt = model.invoke.call_args.args[0]
assert "7 sentence" in prompt
assert "What about cost?" in prompt