learningcircuit--local-deep-research
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
137 行
4.7 KiB
Python
137 行
4.7 KiB
Python
"""API contract tests for the news feed report shape (#3665 Fix B).
|
|
|
|
After the chat-mode-v2 refactor, ``report_content`` stores only the
|
|
synthesized answer. The news feed must therefore expose:
|
|
|
|
* ``findings`` — the answer-only ``report_content`` verbatim (no embedded
|
|
``## Sources`` block), and
|
|
* ``links`` — the structured top-N source URLs read from the
|
|
``research_resources`` table (not parsed out of ``report_content``).
|
|
|
|
These exercise the real ``get_news_feed`` research-history path against a
|
|
seeded DB; only the per-user-DB session is patched.
|
|
"""
|
|
|
|
from contextlib import contextmanager
|
|
from datetime import datetime, UTC
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from local_deep_research.database.models import Base
|
|
from local_deep_research.database.models.research import (
|
|
ResearchHistory,
|
|
ResearchResource,
|
|
)
|
|
|
|
RESEARCH_ID = "news-contract-research-1"
|
|
# "latest news" in the query makes get_news_feed treat the row as a news item.
|
|
QUERY = "latest news on quantum computing breakthroughs"
|
|
# Answer-only report content — inline [N](url) citations, NO ## Sources block.
|
|
ANSWER_ONLY = (
|
|
"Quantum error correction crossed a threshold this year, "
|
|
"citing [1](https://q1.example) and [2](https://q2.example)."
|
|
)
|
|
N_SOURCES = 4 # > the feed's top-N (3): links must be capped, not unbounded.
|
|
|
|
|
|
@pytest.fixture
|
|
def seeded_news_db(tmp_path):
|
|
"""Real temp-file SQLite seeded with one completed news-style research."""
|
|
engine = create_engine(f"sqlite:///{tmp_path / 'news_contract.db'}")
|
|
Base.metadata.create_all(engine)
|
|
SessionLocal = sessionmaker(bind=engine)
|
|
|
|
seed = SessionLocal()
|
|
seed.add(
|
|
ResearchHistory(
|
|
id=RESEARCH_ID,
|
|
query=QUERY,
|
|
title="Quantum Computing Breakthroughs",
|
|
mode="quick",
|
|
status="completed",
|
|
created_at="2026-04-25T12:00:00+00:00",
|
|
completed_at="2026-04-25T12:05:00+00:00",
|
|
report_content=ANSWER_ONLY,
|
|
research_meta={"is_news_search": True},
|
|
)
|
|
)
|
|
for i in range(1, N_SOURCES + 1):
|
|
url = f"https://q{i}.example"
|
|
seed.add(
|
|
ResearchResource(
|
|
research_id=RESEARCH_ID,
|
|
title=f"Quantum Source {i}",
|
|
url=url,
|
|
source_type="web",
|
|
resource_metadata={
|
|
"original_data": {
|
|
"index": str(i),
|
|
"url": url,
|
|
"title": f"Quantum Source {i}",
|
|
}
|
|
},
|
|
created_at=datetime.now(UTC).isoformat(),
|
|
)
|
|
)
|
|
seed.commit()
|
|
seed.close()
|
|
|
|
@contextmanager
|
|
def _fake_user_db(username=None, password=None):
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
# get_news_feed imports get_user_db_session from session_context at call
|
|
# time, so patch it at the source module.
|
|
with patch(
|
|
"local_deep_research.database.session_context.get_user_db_session",
|
|
_fake_user_db,
|
|
):
|
|
yield
|
|
|
|
engine.dispose()
|
|
|
|
|
|
def _feed_item(seeded_news_db):
|
|
from local_deep_research.news.api import get_news_feed
|
|
|
|
result = get_news_feed(user_id="testuser", limit=10, use_cache=False)
|
|
items = result["news_items"]
|
|
matches = [it for it in items if it.get("research_id") == RESEARCH_ID]
|
|
assert matches, f"seeded research not surfaced in feed: {items}"
|
|
return matches[0]
|
|
|
|
|
|
def test_news_feed_findings_is_answer_only(seeded_news_db):
|
|
item = _feed_item(seeded_news_db)
|
|
findings = item["findings"]
|
|
assert findings == ANSWER_ONLY
|
|
# The post-refactor contract: no assembled ## Sources blob in findings.
|
|
assert "## Sources" not in findings
|
|
|
|
|
|
def test_news_feed_links_array_populated_from_research_resources(
|
|
seeded_news_db,
|
|
):
|
|
item = _feed_item(seeded_news_db)
|
|
links = item["links"]
|
|
assert isinstance(links, list)
|
|
# Exactly the top-N cap: the feed passes limit=3 (news/api.py), so 3 of
|
|
# the 4 seeded resources come back. == 3 (not <= 3) fences the cap AND
|
|
# the source: report_content only cites [1]/[2] inline, so a regression
|
|
# that parsed links out of report_content could yield at most 2.
|
|
assert len(links) == 3
|
|
urls = {link.get("url") for link in links}
|
|
# At least one link is a research_resources-only source (q3/q4), absent
|
|
# from the two inline citations in report_content — proves the links are
|
|
# read FROM the table, not parsed out of the answer text.
|
|
assert urls - {"https://q1.example", "https://q2.example"}, urls
|
|
for link in links:
|
|
assert link.get("url")
|