[chore] solution,admin,ontology: 코드 주석을 한 줄로 — 히스토리 주석 삭제

여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다.

- ts·tsx·js·mjs·css·py 478개: 여러 줄 주석은 첫 문장 한 줄로, 과거형·날짜 문장은 삭제
- 주석 위치는 TypeScript 파서·파이썬 tokenize/ast 로 찾는다 — 문자열 안의 # · /* 는 건드리지 않는다
- eslint·ts·noqa·type: ignore 같은 지시 주석은 그대로 둔다

파이썬 275개 정리 전후 AST 동일, TS 298개 주석 뺀 토큰 동일(빈 JSX 주석 10곳만 차이).
site·frontend·admin tsc, site vitest 105 passed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-09-28 16:05:19 +09:00
1 parent c6908629f3
commit 11d30bb3d1
479 files changed
+3337 -13091

No files matched your search

+26 -67
View File
@@ -1,16 +1,10 @@
"""Perplexity 채널 발견 클라이언트 — 계약 검증(실제 API 호출 없음).
★ 이 모듈의 계약은 하나다: **URL 만 돌려준다.**
Perplexity 답변에는 동명 업소와 환각이 섞이므로, 상호명·주소·전화 같은 "사실"이
반환 구조에 새어나오면 그게 그대로 사이트에 실린다. 그걸 막는 게 여기 테스트의 목적이다.
"""
"""Perplexity 채널 발견 클라이언트 — 계약 검증(실제 API 호출 없음)."""
import httpx
import pytest
from common.enums import LinkChannel
# ★ 겹마다 사는 곳이 다르다(services/llm/__init__.py 의 설명 참조).
# 채널 판정·필터 규칙 → grounding, HTTP 호출 → llm, 조립 → external.
# 겹마다 사는 곳이 다르다(services/llm/__init__.py 의 설명 참조).
from services.grounding.channels import (
MAX_LINKS,
MAX_LINKS_PER_CHANNEL,
@@ -34,7 +28,7 @@ def _api_key(monkeypatch):
def _client(handler) -> httpx.AsyncClient:
"""MockTransport 로 네트워크를 끊은 클라이언트. 실제 API 를 절대 때리지 않는다."""
"""MockTransport 로 네트워크를 끊은 클라이언트."""
return httpx.AsyncClient(transport=httpx.MockTransport(handler))
@@ -48,8 +42,7 @@ def _ok_payload(content: str, search_results=None, usage=None) -> dict:
# ── 정상 파싱 ────────────────────────────────────────────────────────────
async def test_discover_returns_links_raw_and_search_count():
"""검증: 정상 응답을 파싱한다.
기대결과: links·raw·search_count 가 모두 채워지고, raw 는 응답 원문 그대로다."""
"""검증: 정상 응답을 파싱한다."""
payload = _ok_payload(
'{"links": [{"url": "https://www.yanolja.com/pension/1", "title": "하조대펜션"}]}',
search_results=[{"url": "https://place.naver.com/restaurant/123", "title": "하조대펜션"}],
@@ -72,9 +65,7 @@ async def test_discover_returns_links_raw_and_search_count():
async def test_request_pins_schema_and_domain_filter():
"""검증: 실제로 나가는 요청 본문.
기대결과: response_format(JSON Schema)로 출력이 고정되고, 도메인이 야놀자·여기어때·
**네이버 플레이스**로 한정된다. naver.com 으로 넓히면 blog.naver.com 후기가 딸려온다(실측)."""
"""검증: 실제로 나가는 요청 본문."""
seen = {}
async def handler(request):
@@ -92,10 +83,7 @@ async def test_request_pins_schema_and_domain_filter():
assert seen["auth"] == "Bearer pplx-test-key"
assert body["model"] == "sonar"
assert body["response_format"]["type"] == "json_schema", "구조화 출력으로 파싱 실패를 줄여야 한다"
# ★ 네이버는 호스트가 셋으로 나뉜다. place.naver.com 하나만 두면 실측상 네이버 링크가
# **한 건도 안 들어온다**(2026-08-27 '도플로'·'버터브루'): 사람이 공유하는 주소는
# map.naver.com/p/entry/place/... 이거나 naver.me 단축주소이고, place.naver.com 은
# 그 뒤 리다이렉트로만 나타난다.
# 네이버는 호스트가 셋으로 나뉜다.
assert set(body["search_domain_filter"]) == {
"yanolja.com", "goodchoice.kr", "place.naver.com", "map.naver.com", "naver.me",
}
@@ -104,8 +92,7 @@ async def test_request_pins_schema_and_domain_filter():
async def test_duplicate_urls_are_collapsed():
"""검증: 모델 답변과 search_results 에 같은 URL 이 중복으로 들어온다.
기대결과: 1건으로 합쳐진다(place_links 유니크와 충돌하지 않게)."""
"""검증: 모델 답변과 search_results 에 같은 URL 이 중복으로 들어온다."""
url = "https://www.yanolja.com/pension/7"
async def handler(request):
@@ -121,8 +108,7 @@ async def test_duplicate_urls_are_collapsed():
async def test_non_http_urls_are_dropped():
"""검증: 모델이 http(s) 가 아닌 문자열을 URL 자리에 넣는다.
기대결과: 버려진다 — 크롤러에 쓰레기가 흘러가면 안 된다."""
"""검증: 모델이 http(s) 가 아닌 문자열을 URL 자리에 넣는다."""
async def handler(request):
return httpx.Response(200, json=_ok_payload(
'{"links": [{"url": "야놀자에서 검색하세요"}, {"url": "javascript:alert(1)"},'
@@ -154,15 +140,12 @@ async def test_non_http_urls_are_dropped():
],
)
def test_classify_url(url, expected):
"""검증: URL 호스트로 채널을 판정한다.
기대결과: 야놀자·여기어때·네이버플레이스·인스타는 정확히, 네이버 블로그/카페는 BLOG,
모르는 도메인은 ETC 로 떨어진다(버리지 않는다)."""
"""검증: URL 호스트로 채널을 판정한다."""
assert classify_url(url) is expected
async def test_links_carry_channel_code():
"""검증: 발견된 링크에 채널 코드가 붙는지.
기대결과: place_links.channel 에 그대로 넣을 수 있는 LinkChannel 값이 실린다."""
"""검증: 발견된 링크에 채널 코드가 붙는지."""
async def handler(request):
return httpx.Response(200, json=_ok_payload(
'{"links": [{"url": "https://www.yanolja.com/pension/1"},'
@@ -182,9 +165,7 @@ async def test_links_carry_channel_code():
# ── ★ URL 발견 전용 계약 ─────────────────────────────────────────────────
async def test_facts_in_answer_do_not_leak_into_result():
"""검증: 응답 본문에 주소·전화·체크인시간 같은 '사실'이 섞여 들어온다.
기대결과: 반환 구조(links)에는 url·channel·title 만 있고 사실은 하나도 새어나오지 않는다.
★ Perplexity 답변을 사실로 쓰면 동명 업소·환각이 그대로 사이트에 실린다."""
"""검증: 응답 본문에 주소·전화·체크인시간 같은 '사실'이 섞여 들어온다."""
async def handler(request):
return httpx.Response(200, json=_ok_payload(
'{"links": [{"url": "https://www.yanolja.com/pension/1", "title": "하조대펜션"}],'
@@ -210,8 +191,7 @@ async def test_facts_in_answer_do_not_leak_into_result():
async def test_prompt_does_not_ask_for_facts():
"""검증: 프롬프트가 무엇을 요구하는지.
기대결과: URL 만 요구하고, 정보를 쓰지 말라고 명시한다 — 물어보면 모델이 지어낸다."""
"""검증: 프롬프트가 무엇을 요구하는지."""
seen = {}
async def handler(request):
@@ -233,8 +213,7 @@ async def test_prompt_does_not_ask_for_facts():
# ── 실패 처리 ────────────────────────────────────────────────────────────
async def test_missing_api_key_raises_not_configured(monkeypatch):
"""검증: PERPLEXITY_API_KEY 가 비어 있다.
기대결과: PerplexityNotConfigured — 이 어댑터만 비활성되고 서버 부팅은 막지 않는다."""
"""검증: PERPLEXITY_API_KEY 가 비어 있다."""
monkeypatch.setattr(llm_perplexity.external_api_config, "perplexity_api_key", "")
with pytest.raises(PerplexityNotConfigured):
@@ -244,15 +223,13 @@ async def test_missing_api_key_raises_not_configured(monkeypatch):
async def test_blank_name_is_rejected():
"""검증: 상호명 없이 호출한다.
기대결과: PerplexityError — 검색 요금이 나가기 전에 막는다."""
"""검증: 상호명 없이 호출한다."""
with pytest.raises(PerplexityError):
await discover_channels(" ")
async def test_timeout_raises_domain_error():
"""검증: 호출이 타임아웃된다.
기대결과: PerplexityError(→ COLLECT_FETCH_FAILED) — httpx 예외가 그대로 새어나오지 않는다."""
"""검증: 호출이 타임아웃된다."""
async def handler(request):
raise httpx.ReadTimeout("too slow", request=request)
@@ -262,8 +239,7 @@ async def test_timeout_raises_domain_error():
async def test_server_error_raises_domain_error():
"""검증: 5xx 응답.
기대결과: PerplexityError(→ COLLECT_FETCH_FAILED). 잡은 재시도로 흘러간다."""
"""검증: 5xx 응답."""
async def handler(request):
return httpx.Response(503, text="service unavailable")
@@ -273,8 +249,7 @@ async def test_server_error_raises_domain_error():
async def test_broken_structured_output_falls_back_to_search_results():
"""검증: 구조화 출력이 깨진 JSON 으로 온다.
기대결과: 예외 없이 search_results 의 URL 로 폴백한다 — 검색 요금을 이미 냈으니 버리지 않는다."""
"""검증: 구조화 출력이 깨진 JSON 으로 온다."""
async def handler(request):
return httpx.Response(200, json=_ok_payload(
"이건 JSON 이 아닙니다",
@@ -288,8 +263,6 @@ async def test_broken_structured_output_falls_back_to_search_results():
async def test_empty_result_is_not_an_error():
"""검증: 아무 채널도 못 찾았다.
기대결과: 빈 목록 + 예외 없음 — '못 찾음'은 정상 결과다(사장님 직접 입력으로 폴백)."""
async def handler(request):
return httpx.Response(200, json=_ok_payload('{"links": []}', usage={"num_search_queries": 2}))
@@ -301,8 +274,7 @@ async def test_empty_result_is_not_an_error():
async def test_search_count_falls_back_to_search_results_length():
"""검증: usage 에 검색 횟수가 없다.
기대결과: search_results 개수로 대체한다 — 검색 요금 추적이 0 으로 비면 안 된다."""
"""검증: usage 에 검색 횟수가 없다."""
async def handler(request):
return httpx.Response(200, json=_ok_payload(
'{"links": []}',
@@ -316,8 +288,6 @@ async def test_search_count_falls_back_to_search_results_length():
assert result.search_count == 2
# ── ★ URL 품질 필터 ──────────────────────────────────────────────────────
# 아래 URL 은 2026-08-27 '핑크비치펜션' 실호출에서 실제로 돌아온 것들이다.
_REAL_JUNK = {
"https://nol.yanolja.com/": REASON_ROOT,
"https://www.goodchoice.kr/": REASON_ROOT,
@@ -348,8 +318,7 @@ async def _discover_with(urls, **kwargs):
@pytest.mark.parametrize("url,reason", sorted(_REAL_JUNK.items()))
async def test_junk_urls_are_filtered_with_reason(url, reason):
"""검증: 실호출에서 나온 쓰레기 URL(루트·카테고리·블로그)을 넣는다.
기대결과: 후보에서 빠지고 filtered_out 에 사유가 남는다 — 조용히 버리지 않는다."""
"""검증: 실호출에서 나온 쓰레기 URL(루트·카테고리·블로그)을 넣는다."""
result = await _discover_with([url])
assert result.links == [], f"{url} 이 후보로 남았다"
@@ -358,8 +327,7 @@ async def test_junk_urls_are_filtered_with_reason(url, reason):
@pytest.mark.parametrize("url", _REAL_DETAIL)
async def test_real_detail_urls_pass(url):
"""검증: 실호출에서 나온 진짜 상세 페이지 URL.
기대결과: 통과한다 — 필터가 과해서 진짜 채널을 버리면 필터가 없느니만 못하다."""
"""검증: 실호출에서 나온 진짜 상세 페이지 URL."""
result = await _discover_with([url])
assert [x.url for x in result.links] == [url]
@@ -367,8 +335,7 @@ async def test_real_detail_urls_pass(url):
async def test_blogs_pass_when_explicitly_included():
"""검증: include_blogs=True 로 호출한다.
기대결과: 블로그도 후보로 남는다 — 기본은 제외지만 필요하면 열 수 있어야 한다."""
"""검증: include_blogs=True 로 호출한다."""
url = "https://blog.naver.com/sodam0526/223364495517"
default = await _discover_with([url])
@@ -379,8 +346,7 @@ async def test_blogs_pass_when_explicitly_included():
async def test_all_filtered_returns_empty_not_forced_pick():
"""검증: 발견된 URL 이 전부 쓰레기다.
기대결과: 빈 목록 — ★ 억지로 하나 남기지 않는다. '못 찾음'은 정상 결과다."""
"""검증: 발견된 URL 이 전부 쓰레기다."""
result = await _discover_with(list(_REAL_JUNK))
assert result.links == []
@@ -388,8 +354,7 @@ async def test_all_filtered_returns_empty_not_forced_pick():
async def test_filtered_out_reason_counts():
"""검증: 탈락 사유 집계.
기대결과: 사유별 건수가 나온다 — 로그 한 줄로 '왜 얼마나 빠졌나'가 보여야 한다."""
"""검증: 탈락 사유 집계."""
result = await _discover_with(list(_REAL_JUNK))
counts = result.reason_counts()
@@ -399,9 +364,6 @@ async def test_filtered_out_reason_counts():
async def test_too_many_same_channel_urls_are_capped():
"""검증: 같은 채널 상세 URL 이 우수수 들어온다(실측: 야놀자 12건, 전부 다른 숙소).
기대결과: 채널당 상한까지만 남고 나머지는 overflow 로 기록된다 —
사람이 12건을 하나씩 열어보게 만들면 안 된다."""
urls = [f"https://place-site.yanolja.com/places/100{i:04d}" for i in range(10)]
result = await _discover_with(urls)
@@ -413,8 +375,7 @@ async def test_too_many_same_channel_urls_are_capped():
async def test_total_cap_across_channels():
"""검증: 여러 채널에서 상세 URL 이 많이 들어온다.
기대결과: 전체 상한(MAX_LINKS)을 넘지 않는다."""
"""검증: 여러 채널에서 상세 URL 이 많이 들어온다."""
urls = (
[f"https://place-site.yanolja.com/places/1{i}" for i in range(4)]
+ [f"https://place.goodchoice.kr/product/detail/{i}" for i in range(4)]
@@ -427,8 +388,7 @@ async def test_total_cap_across_channels():
async def test_prompt_forbids_root_and_listing_pages():
"""검증: 프롬프트가 무엇을 금지하는지.
기대결과: 첫 화면·목록·블로그를 넣지 말라고 명시한다 — 필터 이전에 애초에 덜 받는 게 싸다."""
"""검증: 프롬프트가 무엇을 금지하는지."""
seen = {}
async def handler(request):
@@ -446,8 +406,7 @@ async def test_prompt_forbids_root_and_listing_pages():
async def test_high_search_count_is_warned(caplog):
"""검증: 검색 횟수가 기준을 넘는다.
기대결과: 경고가 남는다 — 검색이 과하면 지연과 오탐 후보가 늘 수 있다."""
"""검증: 검색 횟수가 기준을 넘는다."""
from services.external.perplexity import SEARCH_COUNT_WARN_THRESHOLD
async def handler(request):