Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(journal_quality): cover first-pass DOAJ cross-reference in build (#4865)

LearningCircuit9721c78cb5f2
diff --git a/tests/journal_quality/test_db.py b/tests/journal_quality/test_db.py
index d2ed9befc2..ba4507fdd3 100644
--- a/tests/journal_quality/test_db.py
+++ b/tests/journal_quality/test_db.py
@@ -465,6 +465,77 @@ class TestPopulateSources:
finally:
engine.dispose()
+ def test_doaj_crossref_flags_existing_openalex_source(self):
+ """First-pass DOAJ cross-reference, both directions.
+
+ Against a single non-empty DOAJ dump, an OpenAlex source whose
+ normalized ISSN IS in the dump must be flagged ``is_in_doaj=True``,
+ and one whose ISSN is NOT must stay ``is_in_doaj=False`` — both keeping
+ ``score_source='openalex'`` (they came from OpenAlex; DOAJ only adds
+ the flag). Testing both sides against the same dump pins the actual
+ per-ISSN match: a regression that flagged every source whenever the
+ dump is non-empty (``is_in_doaj = bool(doaj_data)``) passes a
+ positive-only test but fails the negative assertion here. Partner to
+ ``test_doaj_only_journal_inserted`` (second pass, DOAJ-only venues).
+ Guards the ``doaj_data.get(issn)`` cross-ref at
+ ``db.py::_populate_sources``.
+ """
+ from sqlalchemy import select
+ from sqlalchemy.orm import sessionmaker
+
+ from local_deep_research.journal_quality.models import Source
+ from local_deep_research.utilities.citation_normalizer import (
+ normalize_issn,
+ )
+
+ # S1's ISSN is hyphenated while the DOAJ dump is keyed by the
+ # normalized (no-dash) form, so the match exercises normalize_issn on
+ # both sides. S2 is a real OpenAlex source whose ISSN is absent from
+ # the dump — the negative control.
+ sources = {
+ "S1": {"n": "PLoS ONE", "i": "1932-6203", "h": 200, "p": "PLOS"},
+ "S2": {"n": "Obscure Closed Journal", "i": "0000-0019", "h": 40},
+ }
+ doaj = {
+ normalize_issn("1932-6203"): {
+ "name": "PLoS ONE",
+ "publisher": "PLOS",
+ }
+ }
+ pred = {
+ "journals": set(),
+ "publishers": set(),
+ "hijacked": set(),
+ "long_pubs": [],
+ }
+ engine = self._build_in_memory(sources, doaj, pred)
+ try:
+ with sessionmaker(bind=engine)() as s:
+ hit = s.scalars(
+ select(Source).where(
+ Source.issn == normalize_issn("1932-6203")
+ )
+ ).first()
+ assert hit is not None
+ assert hit.is_in_doaj is True
+ # Came from OpenAlex, so the score source stays "openalex";
+ # DOAJ only contributes the is_in_doaj flag on this pass.
+ assert hit.score_source == "openalex"
+ assert hit.openalex_source_id == "S1"
+
+ # Negative control: in OpenAlex, not in the (non-empty) dump.
+ miss = s.scalars(
+ select(Source).where(
+ Source.issn == normalize_issn("0000-0019")
+ )
+ ).first()
+ assert miss is not None
+ assert miss.is_in_doaj is False
+ assert miss.score_source == "openalex"
+ assert miss.openalex_source_id == "S2"
+ finally:
+ engine.dispose()
+
def test_quartile_derivation_global_per_type(self):
"""Sources are bucketed Q1–Q4 by cited_by_count percentile within
each source_type. Display-only signal — quality stays h-index-driven.