Merge pull request 'fix(sources): resolve arXiv IDs via arXiv DOI (OpenAlex /works/arxiv: 404s)' (#5) from fix/openalex-arxiv-doi into main

fix(sources): resolve arXiv IDs via arXiv DOI (OpenAlex /works/arxiv: 404s)
This commit is contained in:
2026-06-14 12:31:33 +00:00
2 changed files with 23 additions and 9 deletions

View File

@@ -45,7 +45,18 @@ def test_resolve_doi() -> None:
def test_resolve_arxiv() -> None:
assert _resolve_id("2301.07041") == "arxiv:2301.07041"
# arXiv IDs resolve to their arXiv DOI (the arxiv: path 404s on OpenAlex).
assert _resolve_id("2301.07041") == "doi:10.48550/arXiv.2301.07041"
def test_resolve_arxiv_legacy() -> None:
# Legacy category/number IDs (pre-2007) resolve the same way.
assert _resolve_id("math/0603097") == "doi:10.48550/arXiv.math/0603097"
def test_resolve_arxiv_prefix_stripped() -> None:
# An explicit arxiv: prefix is stripped before building the arXiv DOI.
assert _resolve_id("arxiv:2301.07041") == "doi:10.48550/arXiv.2301.07041"
def test_resolve_w_id_unchanged() -> None:
@@ -54,7 +65,6 @@ def test_resolve_w_id_unchanged() -> None:
def test_resolve_prefixed_unchanged() -> None:
assert _resolve_id("doi:10.1145/x") == "doi:10.1145/x"
assert _resolve_id("arxiv:2301.07041") == "arxiv:2301.07041"
# ---------------------------------------------------------------------------
@@ -83,7 +93,7 @@ def test_fetch_paper_success(monkeypatch: pytest.MonkeyPatch) -> None:
def test_fetch_paper_arxiv_id_prefixed(monkeypatch: pytest.MonkeyPatch) -> None:
"""Bare arXiv IDs are prefixed with 'arxiv:' in the URL."""
"""Bare arXiv IDs are resolved to their arXiv DOI in the URL."""
called_url: list[str] = []
def mock_get(url: str, params: dict[str, str] | None = None) -> httpx.Response:
@@ -93,7 +103,7 @@ def test_fetch_paper_arxiv_id_prefixed(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(openalex, "_get", mock_get)
openalex.fetch_paper("2301.07041")
assert called_url and "arxiv:2301.07041" in called_url[0]
assert called_url and "doi:10.48550/arXiv.2301.07041" in called_url[0]
# ---------------------------------------------------------------------------