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 
 
 
 
 
 
 
 
 
 
 
 
 
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
import json
import pytest
from yeogibrain_mcp.server import (
    search_documents,
    get_document,
    get_related,
    list_documents,
    get_statistics,
    full_text_search,
    get_documents_batch,
)


# ------------------------------------------------------------------
# search_documents 기존 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_search_documents_basic():
    result = await search_documents(query="패키지")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert len(parsed["results"]) > 0


@pytest.mark.asyncio
async def test_search_documents_with_category():
    result = await search_documents(query="검색", category="prd")
    parsed = json.loads(result)
    assert all(r["category"] == "prd" for r in parsed["results"])


# ------------------------------------------------------------------
# search_documents 확장 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_search_with_author():
    result = await search_documents(query="", author="욘두", category="research")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_search_with_date_range():
    result = await search_documents(query="검색", date_from="2024-01-01", date_to="2024-12-31")
    parsed = json.loads(result)
    assert "results" in parsed


@pytest.mark.asyncio
async def test_search_with_methodology():
    result = await search_documents(query="", category="research", methodology="UT")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_search_with_experiment_no():
    result = await search_documents(query="", category="ab", experiment_no="190")
    parsed = json.loads(result)
    assert "results" in parsed


@pytest.mark.asyncio
async def test_search_sort_by_date():
    result = await search_documents(query="", category="research", sort_by="date_desc", limit=10)
    parsed = json.loads(result)
    assert parsed["total"] <= 10


# ------------------------------------------------------------------
# get_document 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_get_document_by_id():
    result = await get_document(doc_id="PRD-001")
    parsed = json.loads(result)
    assert parsed["id"] == "PRD-001"
    assert "content" in parsed


@pytest.mark.asyncio
async def test_get_document_not_found():
    result = await get_document(doc_id="FAKE-999")
    parsed = json.loads(result)
    assert "error" in parsed


@pytest.mark.asyncio
async def test_get_document_research_fields():
    result = await get_document(doc_id="RES-001")
    parsed = json.loads(result)
    assert "methodology" in parsed
    assert "researcher" in parsed


# ------------------------------------------------------------------
# get_related 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_get_related_prd():
    result = await get_related(doc_id="PRD-001")
    parsed = json.loads(result)
    assert "ac" in parsed
    assert "ab" in parsed
    assert "research" in parsed


@pytest.mark.asyncio
async def test_get_related_not_found():
    result = await get_related(doc_id="FAKE-999")
    parsed = json.loads(result)
    assert "error" in parsed


# ------------------------------------------------------------------
# list_documents 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_list_documents_all():
    result = await list_documents()
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_list_documents_filter_category():
    result = await list_documents(category="research")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "research" for r in parsed["results"])


@pytest.mark.asyncio
async def test_list_documents_filter_domain():
    result = await list_documents(category="prd", domain="search")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r.get("domain") == "search" for r in parsed["results"])


@pytest.mark.asyncio
async def test_list_with_author():
    result = await list_documents(category="research", author="욘두")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_list_with_date_range():
    result = await list_documents(category="research", date_from="2023-01-01", date_to="2023-12-31")
    parsed = json.loads(result)
    assert "results" in parsed


@pytest.mark.asyncio
async def test_list_with_sort():
    result = await list_documents(category="research", sort_by="date_desc")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_list_with_limit_offset():
    result = await list_documents(category="research", limit=5, offset=10)
    parsed = json.loads(result)
    assert parsed["total"] <= 5


@pytest.mark.asyncio
async def test_list_with_methodology():
    result = await list_documents(category="research", methodology="UT")
    parsed = json.loads(result)
    assert parsed["total"] > 0


# ------------------------------------------------------------------
# get_statistics 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_statistics_by_category():
    result = await get_statistics(group_by="category")
    parsed = json.loads(result)
    assert parsed["total_documents"] > 800
    groups = {g["key"]: g["count"] for g in parsed["groups"]}
    assert "prd" in groups
    assert "research" in groups


@pytest.mark.asyncio
async def test_statistics_by_author():
    result = await get_statistics(group_by="author", category="research")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0
    assert all("key" in g and "count" in g for g in parsed["groups"])


@pytest.mark.asyncio
async def test_statistics_by_domain():
    result = await get_statistics(group_by="domain", category="prd")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0


@pytest.mark.asyncio
async def test_statistics_by_methodology():
    result = await get_statistics(group_by="methodology", category="research")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0


@pytest.mark.asyncio
async def test_statistics_by_year_month():
    result = await get_statistics(group_by="year_month", category="research")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0


# ------------------------------------------------------------------
# full_text_search 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_full_text_search_basic():
    result = await full_text_search(query="파트너센터")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all("snippet" in r for r in parsed["results"])


@pytest.mark.asyncio
async def test_full_text_search_with_category():
    result = await full_text_search(query="파트너센터", category="prd")
    parsed = json.loads(result)
    assert all(r["category"] == "prd" for r in parsed["results"])


@pytest.mark.asyncio
async def test_full_text_search_limit():
    result = await full_text_search(query="검색", limit=3)
    parsed = json.loads(result)
    assert parsed["total"] <= 3


# ------------------------------------------------------------------
# get_documents_batch 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_batch_summary_mode():
    result = await get_documents_batch(doc_ids=["PRD-001", "RES-001"], fields="summary")
    parsed = json.loads(result)
    assert parsed["total"] == 2
    assert len(parsed["errors"]) == 0
    assert all("summary" in r for r in parsed["results"])
    assert all("author" in r for r in parsed["results"])
    assert all("date" in r for r in parsed["results"])


@pytest.mark.asyncio
async def test_batch_meta_mode():
    result = await get_documents_batch(doc_ids=["PRD-001", "AB-001"], fields="meta")
    parsed = json.loads(result)
    assert parsed["total"] == 2
    for r in parsed["results"]:
        assert "id" in r
        assert "title" in r
        assert "summary" not in r


@pytest.mark.asyncio
async def test_batch_full_mode():
    result = await get_documents_batch(doc_ids=["PRD-001"], fields="full")
    parsed = json.loads(result)
    assert parsed["total"] == 1
    assert "content" in parsed["results"][0]
    assert len(parsed["results"][0]["content"]) > 0


@pytest.mark.asyncio
async def test_batch_with_errors():
    result = await get_documents_batch(doc_ids=["PRD-001", "FAKE-999"], fields="summary")
    parsed = json.loads(result)
    assert parsed["total"] == 1
    assert len(parsed["errors"]) == 1


@pytest.mark.asyncio
async def test_batch_ab_has_summary():
    """AB 문서가 마크다운에서 추출된 summary를 갖는지 확인."""
    result = await get_documents_batch(doc_ids=["AB-158", "AB-130", "AB-133"], fields="summary")
    parsed = json.loads(result)
    assert parsed["total"] == 3
    # 최소 1개 이상의 AB 문서가 비어있지 않은 summary를 가져야 함
    summaries = [r["summary"] for r in parsed["results"]]
    assert any(len(s) > 10 for s in summaries)


@pytest.mark.asyncio
async def test_batch_ab_has_experiment_no():
    result = await get_documents_batch(doc_ids=["AB-158"], fields="summary")
    parsed = json.loads(result)
    assert parsed["results"][0].get("experiment_no") == "232"


# ------------------------------------------------------------------
# NNg 문서 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_search_nng_documents():
    result = await search_documents(query="heuristic", category="nng")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "nng" for r in parsed["results"])


@pytest.mark.asyncio
async def test_get_nng_document():
    result = await get_document(doc_id="NNG-001")
    parsed = json.loads(result)
    assert parsed["id"] == "NNG-001"
    assert parsed["category"] == "nng"
    assert "topics" in parsed


@pytest.mark.asyncio
async def test_list_nng_documents():
    result = await list_documents(category="nng")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "nng" for r in parsed["results"])


@pytest.mark.asyncio
async def test_statistics_nng():
    result = await get_statistics(group_by="category")
    parsed = json.loads(result)
    groups = {g["key"]: g["count"] for g in parsed["groups"]}
    assert "nng" in groups
    assert groups["nng"] == 439


@pytest.mark.asyncio
async def test_statistics_by_topics():
    result = await get_statistics(group_by="topics", category="nng")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0


@pytest.mark.asyncio
async def test_batch_nng():
    result = await get_documents_batch(doc_ids=["NNG-001", "NNG-002"], fields="summary")
    parsed = json.loads(result)
    assert parsed["total"] == 2
    assert all(r["category"] == "nng" for r in parsed["results"])


# ------------------------------------------------------------------
# Baymard 문서 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_search_baymard():
    result = await search_documents(query="homepage", category="baymard")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "baymard" for r in parsed["results"])


@pytest.mark.asyncio
async def test_get_baymard_document():
    result = await get_document(doc_id="BMD-001")
    parsed = json.loads(result)
    assert parsed["id"] == "BMD-001"
    assert parsed["category"] == "baymard"
    assert "issue" in parsed
    assert "advice" in parsed
    assert "content" in parsed
    assert len(parsed["content"]) > 0


@pytest.mark.asyncio
async def test_list_baymard():
    result = await list_documents(category="baymard")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "baymard" for r in parsed["results"])


@pytest.mark.asyncio
async def test_statistics_baymard():
    result = await get_statistics(group_by="category")
    parsed = json.loads(result)
    groups = {g["key"]: g["count"] for g in parsed["groups"]}
    assert "baymard" in groups
    assert groups["baymard"] == 520


@pytest.mark.asyncio
async def test_full_text_search_baymard():
    result = await full_text_search(query="checkout", category="baymard")
    parsed = json.loads(result)
    assert parsed["total"] > 0


# ------------------------------------------------------------------
# Dovetail 문서 테스트
# ------------------------------------------------------------------

@pytest.mark.asyncio
async def test_search_dovetail():
    result = await search_documents(query="검색", category="dovetail")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "dovetail" for r in parsed["results"])


@pytest.mark.asyncio
async def test_get_dovetail_document():
    result = await get_document(doc_id="TRS-001")
    parsed = json.loads(result)
    assert parsed["id"] == "TRS-001"
    assert parsed["category"] == "dovetail"
    assert "content" in parsed
    assert len(parsed["content"]) > 0


@pytest.mark.asyncio
async def test_list_dovetail():
    result = await list_documents(category="dovetail")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert all(r["category"] == "dovetail" for r in parsed["results"])


@pytest.mark.asyncio
async def test_statistics_dovetail():
    result = await get_statistics(group_by="category")
    parsed = json.loads(result)
    groups = {g["key"]: g["count"] for g in parsed["groups"]}
    assert "dovetail" in groups
    assert groups["dovetail"] == 647


@pytest.mark.asyncio
async def test_batch_mixed_sources():
    """사내 + 외부 문서를 한번에 조회."""
    result = await get_documents_batch(
        doc_ids=["PRD-001", "NNG-001", "BMD-001", "TRS-001"],
        fields="summary",
    )
    parsed = json.loads(result)
    assert parsed["total"] == 4
    categories = {r["category"] for r in parsed["results"]}
    assert categories == {"prd", "nng", "baymard", "dovetail"}


@pytest.mark.asyncio
async def test_full_text_search_dovetail():
    """Dovetail 발화 전문검색."""
    result = await full_text_search(query="부킹닷컴", category="dovetail")
    parsed = json.loads(result)
    assert parsed["total"] > 0
    assert any(r["snippet"] for r in parsed["results"])


@pytest.mark.asyncio
async def test_search_with_project_filter():
    """Dovetail project 필터."""
    result = await search_documents(query="", category="dovetail", project="[FGI]통합검색")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_list_with_project_filter():
    """list_documents에서 project 필터."""
    result = await list_documents(category="dovetail", project="[FGI]통합검색")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_search_with_theme_filter():
    """Baymard theme 필터."""
    result = await search_documents(query="", category="baymard", theme="Cart & Checkout")
    parsed = json.loads(result)
    assert parsed["total"] > 0


@pytest.mark.asyncio
async def test_list_with_theme_filter():
    """list_documents에서 theme 필터."""
    result = await list_documents(category="baymard", theme="Product Page", limit=200)
    parsed = json.loads(result)
    assert parsed["total"] == 117


@pytest.mark.asyncio
async def test_statistics_by_project():
    result = await get_statistics(group_by="project", category="dovetail")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0


@pytest.mark.asyncio
async def test_statistics_by_theme():
    result = await get_statistics(group_by="theme", category="baymard")
    parsed = json.loads(result)
    assert len(parsed["groups"]) > 0