Files
2026-09-02 14:57:29 +09:00

109 lines
4.7 KiB
Python

"""Markdown rendering: sections, DOI link resolution, degraded and empty-week modes."""
from __future__ import annotations
from _fakes import make_digest, make_paper, make_payload, make_summary
from sebrief.render import render_markdown
def test_full_digest_renders_all_sections_with_links():
payload = make_payload()
md = render_markdown(payload, make_digest(), "fake-model")
assert md.startswith("# 📚 SE 주간 브리핑 — 2026-W36 (2026-08-31 ~ 2026-09-06)")
assert "수집 논문 1편" in md
for section in ("## 이번 주 흐름", "## 하이라이트", "## 주제별 훑어보기", "## 읽어볼 논문", "## 이번 주 수집 논문"):
assert section in md
# DOI resolves through the payload's oa_url, not a bare doi.org link
assert "[Test-Driven Digest Generation](https://dl.acm.org/doi/10.1145/1234567)" in md
assert "- **문제**:" in md and "- **시사점**:" in md
assert "축소 모드" not in md
def test_doi_mixup_is_rescued_by_title_match():
# The LLM shuffled DOIs but kept the title: the link must follow the (visible) title.
other = make_paper("10.1/other", title="A Different Paper", oa_url="https://x.example/other")
payload = make_payload(papers=[make_paper(), other])
digest = make_digest(doi="10.1/other") # wrong DOI, correct title "Test-Driven Digest Generation"
md = render_markdown(payload, digest, None)
assert "[Test-Driven Digest Generation](https://dl.acm.org/doi/10.1145/1234567)" in md
assert "[Test-Driven Digest Generation](https://x.example/other)" not in md
def test_unknown_doi_and_title_render_plain_text():
digest = make_digest(doi="10.9999/unknown")
for h in digest.highlights:
h.title = "Invented Paper Title"
md = render_markdown(make_payload(), digest, None)
assert "### Invented Paper Title" in md # highlight title without a link
assert "[Invented Paper Title]" not in md
def test_title_collision_falls_back_to_doi():
twin_a = make_paper("10.1/a", title="Same Title", oa_url="https://x.example/a")
twin_b = make_paper("10.1/b", title="Same Title", oa_url="https://x.example/b")
payload = make_payload(papers=[twin_a, twin_b])
digest = make_digest(doi="10.1/b")
for h in digest.highlights:
h.title = "Same Title"
md = render_markdown(payload, digest, None)
assert "[Same Title](https://x.example/b)" in md # ambiguous title -> trust the DOI
def test_doi_without_oa_url_falls_back_to_doi_org():
paper = make_paper(oa_url=None)
md = render_markdown(make_payload(papers=[paper]), make_digest(), None)
assert "(https://doi.org/10.1145/1234567)" in md
def test_degraded_mode_paper_table_only():
payload = make_payload(gaps=["openalex: down"])
md = render_markdown(payload, None, None)
assert "🧩 축소 모드(LLM 요약 없음)" in md
assert "## 이번 주 수집 논문" in md
assert "| 제목 | 저널 | 발행일 |" in md
assert "## 하이라이트" not in md
assert "- openalex: down" in md
def test_empty_week():
md = render_markdown(make_payload(papers=[]), None, None)
assert "이번 주 수집된 OA 논문이 없습니다." in md
assert "축소 모드" not in md
assert "## 이번 주 수집 논문" not in md
def test_paper_summary_section_renders_cards():
with_summary = make_paper(summary=make_summary(tldr="한 줄 요약입니다."))
without = make_paper("10.1/nosummary", title="No Summary Yet")
md = render_markdown(make_payload(papers=[with_summary, without]), make_digest(), None)
assert "## 논문별 요약" in md
assert "**한 줄 요약입니다.**" in md
assert "- **문제**: 주간 다이제스트 생성이 느립니다." in md
# summary-less papers appear only in the table, not as a summary card
section = md.split("## 논문별 요약")[1].split("## 이번 주 수집 논문")[0]
assert "No Summary Yet" not in section
def test_paper_summaries_render_even_without_digest():
md = render_markdown(make_payload(papers=[make_paper(summary=make_summary())]), None, None)
assert "## 논문별 요약" in md and "축소 모드" in md
def test_no_summary_section_when_no_paper_has_one():
md = render_markdown(make_payload(), make_digest(), None)
assert "## 논문별 요약" not in md
def test_table_cells_and_link_text_are_escaped():
paper = make_paper(title="Pipes | and [brackets]", venue="Ven|ue")
md = render_markdown(make_payload(papers=[paper]), None, None)
assert "Pipes \\| and (brackets)" in md
assert "Ven\\|ue" in md
def test_url_with_parentheses_is_encoded():
paper = make_paper(oa_url="https://example.org/paper(1)")
md = render_markdown(make_payload(papers=[paper]), None, None)
assert "https://example.org/paper%281%29" in md