Spaces:
Paused
Paused
File size: 9,148 Bytes
49b9dd9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | import pytest
from yeogibrain_mcp.data_loader import DataStore
@pytest.fixture
def store():
return DataStore()
def test_loads_all_categories(store):
assert len(store.documents) > 0
categories = {d["category"] for d in store.documents.values()}
assert categories == {"prd", "ac", "ab", "research", "nng", "baymard", "dovetail"}
def test_document_has_required_fields(store):
for doc_id, doc in store.documents.items():
assert "id" in doc
assert "title" in doc
assert "category" in doc
# dovetail은 utterances 기반이라 md_path 없음
if doc["category"] != "dovetail":
assert "md_path" in doc
def test_document_count(store):
by_cat = {}
for doc in store.documents.values():
by_cat[doc["category"]] = by_cat.get(doc["category"], 0) + 1
# 원본 prd_articles.json에 중복 ID가 1건 존재하여 고유 문서는 424건
assert by_cat["prd"] == 424
assert by_cat["ac"] == 176
assert by_cat["ab"] == 259
assert by_cat["research"] == 145
def test_get_by_id(store):
doc = store.get("PRD-001")
assert doc is not None
assert doc["category"] == "prd"
def test_get_by_id_case_insensitive(store):
assert store.get("prd-001") is not None
assert store.get("res-001") is not None
assert store.get("AC-001") is not None
assert store.get("ab-001") is not None
def test_get_nonexistent_returns_none(store):
assert store.get("FAKE-999") is None
def test_relationships_loaded(store):
assert len(store.relationships) > 0
def test_get_related_prd(store):
related = store.get_related("PRD-001")
assert isinstance(related, dict)
assert "ac" in related
assert "ab" in related
assert "research" in related
assert "prd" in related
def test_get_related_nonexistent(store):
related = store.get_related("FAKE-999")
assert related == {"ac": [], "ab": [], "research": [], "prd": []}
def test_read_content(store):
content = store.read_content("PRD-001")
assert content is not None
assert len(content) > 0
def test_read_content_nonexistent(store):
assert store.read_content("FAKE-999") is None
def test_get_date_prd(store):
doc = store.get("PRD-001")
date = store.get_date(doc)
assert date is None or isinstance(date, str)
def test_get_date_research(store):
doc = store.get("RES-001")
date = store.get_date(doc)
assert date is not None
def test_get_author_research(store):
doc = store.get("RES-001")
author = store.get_author(doc)
assert author is not None
def test_get_author_ac(store):
docs = [d for d in store.documents.values() if d["category"] == "ac" and d.get("author")]
if docs:
author = store.get_author(docs[0])
assert author is not None
def test_content_cache(store):
content1 = store.read_content_cached("PRD-001")
content2 = store.read_content_cached("PRD-001")
assert content1 == content2
assert content1 is not None
def test_filter_by_category(store):
results = store.filter_documents(category="research")
assert len(results) == 145
assert all(d["category"] == "research" for d in results)
def test_filter_by_author(store):
results = store.filter_documents(category="research", author="욘두")
assert len(results) > 0
assert all(store.get_author(d) == "욘두" for d in results)
def test_filter_by_date_range(store):
results = store.filter_documents(category="research", date_from="2024-01-01", date_to="2024-12-31")
for d in results:
date = store.get_date(d)
assert date is not None
assert "2024" in date
def test_filter_by_methodology(store):
results = store.filter_documents(category="research", methodology="UT")
assert len(results) > 0
assert all(d.get("methodology") == "UT" for d in results)
def test_filter_by_domain(store):
results = store.filter_documents(domain="search")
assert len(results) > 0
assert all(d.get("domain") == "search" for d in results)
def test_filter_by_space(store):
results = store.filter_documents(space="FIN")
assert len(results) > 0
assert all(d.get("space") == "FIN" for d in results)
def test_filter_sort_date_desc(store):
results = store.filter_documents(category="research", sort_by="date_desc")
dates = [store.get_date(d) for d in results if store.get_date(d)]
assert dates == sorted(dates, reverse=True)
def test_filter_sort_date_asc(store):
results = store.filter_documents(category="research", sort_by="date_asc")
dates = [store.get_date(d) for d in results if store.get_date(d)]
assert dates == sorted(dates)
def test_filter_with_limit_and_offset(store):
all_results = store.filter_documents(category="research")
page = store.filter_documents(category="research", limit=10, offset=5)
assert len(page) == 10
assert page[0]["id"] == all_results[5]["id"]
def test_filter_combined(store):
results = store.filter_documents(
category="research",
author="욘두",
date_from="2022-01-01",
)
for d in results:
assert d["category"] == "research"
assert store.get_author(d) == "욘두"
date = store.get_date(d)
assert date is not None and date >= "2022-01-01"
def test_ab_summary_enrichment(store):
"""AB 문서에 마크다운 기반 summary가 보강되었는지 확인."""
ab_docs = [d for d in store.documents.values() if d["category"] == "ab"]
with_summary = [d for d in ab_docs if d.get("summary")]
# 마크다운이 있는 AB 문서 중 상당수가 summary를 가져야 함
assert len(with_summary) > 50, f"AB summary 보강: {len(with_summary)}/{len(ab_docs)}"
def test_ab_summary_content(store):
"""AB-158 (Launch 결정 문서)의 summary에 의미 있는 내용이 있는지 확인."""
doc = store.get("AB-158")
assert doc is not None
summary = doc.get("summary", "")
assert len(summary) > 20
# ------------------------------------------------------------------
# NNg 문서 테스트
# ------------------------------------------------------------------
def test_nng_document_count(store):
nng_docs = [d for d in store.documents.values() if d["category"] == "nng"]
assert len(nng_docs) == 439
def test_nng_id_format(store):
doc = store.get("NNG-001")
assert doc is not None
assert doc["category"] == "nng"
assert doc["title"] != ""
def test_nng_has_required_fields(store):
doc = store.get("NNG-001")
assert "slug" in doc
assert "url" in doc
assert "topics" in doc
assert "date" in doc
def test_nng_date_normalized(store):
"""NNg 날짜가 YYYY-MM-DD 형태로 정규화되었는지 확인."""
doc = store.get("NNG-001")
date = store.get_date(doc)
assert date is not None
assert len(date) == 10 # YYYY-MM-DD
assert date[4] == "-"
def test_nng_author(store):
doc = store.get("NNG-001")
author = store.get_author(doc)
assert author is not None and len(author) > 0
def test_nng_filter_by_category(store):
results = store.filter_documents(category="nng")
assert len(results) == 439
assert all(d["category"] == "nng" for d in results)
# ------------------------------------------------------------------
# Baymard 문서 테스트
# ------------------------------------------------------------------
def test_baymard_document_count(store):
docs = [d for d in store.documents.values() if d["category"] == "baymard"]
assert len(docs) == 520
def test_baymard_id_format(store):
doc = store.get("BMD-001")
assert doc is not None
assert doc["category"] == "baymard"
def test_baymard_has_required_fields(store):
doc = store.get("BMD-001")
assert "theme" in doc
assert "issue" in doc
assert "advice" in doc
assert "importance" in doc
assert "platforms" in doc
def test_baymard_read_content(store):
doc = store.get("BMD-001")
assert doc.get("md_path") != ""
content = store.read_content("BMD-001")
assert content is not None
assert len(content) > 100
def test_baymard_filter_by_category(store):
results = store.filter_documents(category="baymard")
assert len(results) == 520
# ------------------------------------------------------------------
# Dovetail 문서 테스트
# ------------------------------------------------------------------
def test_dovetail_document_count(store):
docs = [d for d in store.documents.values() if d["category"] == "dovetail"]
assert len(docs) == 647
def test_dovetail_id_format(store):
doc = store.get("TRS-001")
assert doc is not None
assert doc["category"] == "dovetail"
def test_dovetail_has_required_fields(store):
doc = store.get("TRS-001")
assert "project" in doc
assert "date" in doc
assert "utterance_count" in doc
def test_dovetail_transcript(store):
transcript = store.get_dovetail_transcript("TRS-001")
assert len(transcript) > 0
assert ":" in transcript # "화자: 발화" 형태
def test_dovetail_filter_by_category(store):
results = store.filter_documents(category="dovetail")
assert len(results) == 647
|