[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:
1 parent
c6908629f3
commit
11d30bb3d1
479 files changed
+3337
-13091
No files matched your search
@@ -1,13 +1,4 @@
|
||||
"""수집 어댑터 계약 — 어디서 긁어오든 결과 모양이 같은지, 그리고 법무 게이트가 코드로 지켜지는지.
|
||||
|
||||
가장 중요한 것 두 개:
|
||||
1. 목데이터의 fact key 가 전부 업종 스키마에 있는가
|
||||
— 없는 key 는 FACT_INVALID_KEY 로 전부 거부되므로, 어긋나면 목데이터가 파이프라인을 하나도 검증하지 못한다
|
||||
2. Phase 1 에 실제 크롤 어댑터가 등록돼 있지 않은가
|
||||
— 법적 검토 결론 전까지 크롤이 돌면 안 된다(docs/DECISIONS.md 1-1)
|
||||
|
||||
DB 를 쓰지 않는 순수 단위 테스트다.
|
||||
"""
|
||||
"""수집 어댑터 계약 — 어디서 긁어오든 결과 모양이 같은지, 그리고 법무 게이트가 코드로 지켜지는지."""
|
||||
import pytest
|
||||
|
||||
from common.category_schema import get_schema
|
||||
@@ -27,13 +18,6 @@ from services.collector import (
|
||||
from services.collector.registry import REGISTRY
|
||||
|
||||
# 어떤 어댑터도 처리하면 안 되는 URL — 조용히 빈 결과를 주지 않고 AdapterNotFound 로 끊어야 한다.
|
||||
# ★ 네이버 플레이스는 2026-08-27 부터 naver_place 어댑터가 처리하므로 여기서 뺐다.
|
||||
# ★ 일반 도메인(example.co.kr)도 2026-08-28 부터 static_html 이 처리하므로 뺐다.
|
||||
# 여기 남은 것은 **수집 불가 결론이 난 곳**이다(docs/DATA_SOURCE_RESEARCH.md):
|
||||
# 야놀자·여기어때는 403 + Cloudflare 로 막혀 있고 민사 10억 선례가 있다.
|
||||
# 카카오맵은 내부 API 406. 인스타는 Graph API(사장님 OAuth)로만 간다.
|
||||
# ★ NOL 전용 어댑터(2026-09-14)가 받는 것은 `nol.yanolja.com/stay/domestic/<id>` 한 패턴뿐이다.
|
||||
# 아래 야놀자 주소가 여전히 막혀야 전용 경로를 연 것과 범용 수집을 푼 것이 갈린다.
|
||||
_REAL_URLS = (
|
||||
"https://www.yanolja.com/pension/1000",
|
||||
"https://www.goodchoice.kr/product/detail/1000",
|
||||
@@ -45,8 +29,7 @@ _REAL_URLS = (
|
||||
# ── 목데이터 ↔ 업종 스키마 정합성 (제일 중요) ────────────────────────────
|
||||
@pytest.mark.parametrize("category", list(PlaceCategory))
|
||||
async def test_mock_fact_keys_exist_in_category_schema(category):
|
||||
"""검증: MockAdapter 가 뱉는 fact key 를 업종 스키마와 대조한다.
|
||||
기대결과: 전부 스키마에 존재한다 — 없는 key 는 fact 기록에서 전부 거부돼 목데이터가 무의미해진다."""
|
||||
"""검증: MockAdapter 가 뱉는 fact key 를 업종 스키마와 대조한다."""
|
||||
schema = get_schema(category)
|
||||
source = await MockAdapter().fetch(MockAdapter.url_for(category))
|
||||
|
||||
@@ -58,9 +41,7 @@ async def test_mock_fact_keys_exist_in_category_schema(category):
|
||||
|
||||
@pytest.mark.parametrize("category", list(PlaceCategory))
|
||||
async def test_mock_fact_scope_matches_schema(category):
|
||||
"""검증: fact 의 scope 가 스키마 정의와 같은지.
|
||||
기대결과: place 필드는 place 로, unit 필드는 unit(+단위 이름)으로 수집된다.
|
||||
scope 가 어긋나면 객실별 값이 사업장 값으로 뭉개진다."""
|
||||
"""검증: fact 의 scope 가 스키마 정의와 같은지."""
|
||||
schema = get_schema(category)
|
||||
source = await MockAdapter().fetch(MockAdapter.url_for(category))
|
||||
|
||||
@@ -72,8 +53,7 @@ async def test_mock_fact_scope_matches_schema(category):
|
||||
|
||||
@pytest.mark.parametrize("category", list(PlaceCategory))
|
||||
async def test_mock_does_not_collect_llm_written_fields(category):
|
||||
"""검증: 수집물에 소개문 계열(allow_llm=True) 필드가 섞이는지.
|
||||
기대결과: 없다 — 소개문은 수집하는 사실이 아니라 generator 가 쓰는 문장이다(절대규칙 7)."""
|
||||
"""검증: 수집물에 소개문 계열(allow_llm=True) 필드가 섞이는지."""
|
||||
schema = get_schema(category)
|
||||
source = await MockAdapter().fetch(MockAdapter.url_for(category))
|
||||
|
||||
@@ -84,8 +64,7 @@ async def test_mock_does_not_collect_llm_written_fields(category):
|
||||
|
||||
@pytest.mark.parametrize("category", list(PlaceCategory))
|
||||
async def test_mock_returns_three_to_five_photos(category):
|
||||
"""검증: 사진 수집 결과.
|
||||
기대결과: 3~5장. Gemini Vision 배치 처리를 물려볼 수 있는 최소량이다."""
|
||||
"""검증: 사진 수집 결과."""
|
||||
source = await MockAdapter().fetch(MockAdapter.url_for(category))
|
||||
assert 3 <= len(source.media) <= 5, f"사진 {len(source.media)}장"
|
||||
for item in source.media:
|
||||
@@ -93,8 +72,7 @@ async def test_mock_returns_three_to_five_photos(category):
|
||||
|
||||
|
||||
async def test_mock_is_deterministic():
|
||||
"""검증: 같은 URL 로 두 번 수집한다.
|
||||
기대결과: fact·사진이 동일하다 — 목데이터가 흔들리면 파이프라인 테스트가 못 믿을 게 된다."""
|
||||
"""검증: 같은 URL 로 두 번 수집한다."""
|
||||
adapter = MockAdapter()
|
||||
url = MockAdapter.url_for(PlaceCategory.LODGING)
|
||||
first, second = await adapter.fetch(url), await adapter.fetch(url)
|
||||
@@ -104,8 +82,7 @@ async def test_mock_is_deterministic():
|
||||
|
||||
|
||||
async def test_mock_reads_category_and_channel_from_url():
|
||||
"""검증: URL 에서 업종·채널을 읽는지.
|
||||
기대결과: 업종별로 다른 목데이터가 나오고, ?channel= 로 채널이 지정된다."""
|
||||
"""검증: URL 에서 업종·채널을 읽는지."""
|
||||
adapter = MockAdapter()
|
||||
lodging = await adapter.fetch("mock://lodging/p1")
|
||||
cafe = await adapter.fetch("mock://cafe/c1?channel=naver_place")
|
||||
@@ -117,8 +94,7 @@ async def test_mock_reads_category_and_channel_from_url():
|
||||
|
||||
|
||||
async def test_mock_unknown_category_fails_softly():
|
||||
"""검증: 업종을 못 읽는 mock URL.
|
||||
기대결과: 예외가 아니라 ok=False 결과 — 채널 하나가 이상해도 나머지 수집이 멈추면 안 된다."""
|
||||
"""검증: 업종을 못 읽는 mock URL."""
|
||||
source = await MockAdapter().fetch("mock://unknown/x1")
|
||||
assert source.ok is False
|
||||
assert source.error and "업종" in source.error
|
||||
@@ -127,8 +103,7 @@ async def test_mock_unknown_category_fails_softly():
|
||||
|
||||
# ── can_handle / 레지스트리 ──────────────────────────────────────────────
|
||||
def test_can_handle_accepts_mock_urls_only():
|
||||
"""검증: MockAdapter 의 처리 범위.
|
||||
기대결과: mock:// 와 mock.test 만 받고 실제 사이트 URL 은 거부한다."""
|
||||
"""검증: MockAdapter 의 처리 범위."""
|
||||
adapter = MockAdapter()
|
||||
assert adapter.can_handle("mock://lodging/1") is True
|
||||
assert adapter.can_handle("https://mock.test/cafe/1") is True
|
||||
@@ -138,22 +113,19 @@ def test_can_handle_accepts_mock_urls_only():
|
||||
|
||||
|
||||
def test_registry_resolves_mock_url():
|
||||
"""검증: 레지스트리로 어댑터를 찾는다.
|
||||
기대결과: mock URL 은 MockAdapter 로 해결된다."""
|
||||
"""검증: 레지스트리로 어댑터를 찾는다."""
|
||||
assert get_adapter("mock://lodging/1").id == "mock"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("url", _REAL_URLS)
|
||||
def test_registry_raises_for_unhandled_url(url):
|
||||
"""검증: 등록된 어댑터가 처리 못 하는 URL 을 조회한다.
|
||||
기대결과: AdapterNotFound — 조용히 빈 결과를 돌려주지 않는다."""
|
||||
"""검증: 등록된 어댑터가 처리 못 하는 URL 을 조회한다."""
|
||||
with pytest.raises(AdapterNotFound):
|
||||
get_adapter(url)
|
||||
|
||||
|
||||
def test_registry_rejects_duplicate_adapter_id():
|
||||
"""검증: 같은 id 의 어댑터를 두 번 등록한다.
|
||||
기대결과: ValueError — 어느 쪽이 쓰이는지 모르는 상태를 만들지 않는다."""
|
||||
"""검증: 같은 id 의 어댑터를 두 번 등록한다."""
|
||||
registry = AdapterRegistry()
|
||||
registry.register(MockAdapter())
|
||||
with pytest.raises(ValueError):
|
||||
@@ -161,8 +133,7 @@ def test_registry_rejects_duplicate_adapter_id():
|
||||
|
||||
|
||||
def test_disabled_adapter_is_blocked():
|
||||
"""검증: 등록은 됐지만 ENABLED 목록에 없는 어댑터를 조회한다.
|
||||
기대결과: AdapterDisabled — 등록과 사용 허가를 분리해 실수로 켜지지 않게 한다."""
|
||||
"""검증: 등록은 됐지만 ENABLED 목록에 없는 어댑터를 조회한다."""
|
||||
registry = AdapterRegistry(enabled=frozenset())
|
||||
registry.register(MockAdapter())
|
||||
with pytest.raises(AdapterDisabled):
|
||||
@@ -172,31 +143,21 @@ def test_disabled_adapter_is_blocked():
|
||||
|
||||
# ── 법무 게이트 (Phase 1) ────────────────────────────────────────────────
|
||||
def test_registers_only_reviewed_adapters():
|
||||
"""검증: 기본 레지스트리에 등록된 어댑터 목록.
|
||||
|
||||
기대결과: 검토를 거쳐 명시적으로 승인한 것만 있다. 이 목록이 늘어나는 것은
|
||||
**의도된 결정이어야** 하므로, 코드가 몰래 늘어나면 여기서 깨진다."""
|
||||
"""검증: 기본 레지스트리에 등록된 어댑터 목록."""
|
||||
assert adapter_ids() == ["naver_place", "tour_api", "yanolja", "mock", "static_html"], (
|
||||
f"예상 밖 어댑터가 등록됐다: {adapter_ids()} — 승인 없이 수집 대상을 늘리지 않는다"
|
||||
)
|
||||
|
||||
|
||||
def test_static_html_is_registered_last():
|
||||
"""검증: 넓은 어댑터(static_html)가 좁은 어댑터보다 뒤에 있는가.
|
||||
|
||||
기대결과: 목록의 맨 끝. 앞에 있으면 http(s) 를 통째로 받는 static_html 이
|
||||
네이버 플레이스 URL 까지 가로채 naver_place 가 영영 안 불린다."""
|
||||
"""검증: 넓은 어댑터(static_html)가 좁은 어댑터보다 뒤에 있는가."""
|
||||
assert adapter_ids()[-1] == "static_html", (
|
||||
f"static_html 은 맨 뒤여야 한다: {adapter_ids()}"
|
||||
)
|
||||
|
||||
|
||||
def test_static_html_never_touches_blocked_platforms():
|
||||
"""검증: 수집 불가 결론이 난 플랫폼 URL 을 static_html 에 직접 물어본다.
|
||||
|
||||
기대결과: 전부 False. static_html 의 정당성은 '사장님이 확정한 자기 홈페이지만 본다' 에서
|
||||
나오므로, 플랫폼 URL 이 흘러들어오면 정당성이 통째로 깨진다. 운영자가 실수로 넣어도
|
||||
구조적으로 막혀야 한다(docs/DATA_SOURCE_RESEARCH.md)."""
|
||||
"""검증: 수집 불가 결론이 난 플랫폼 URL 을 static_html 에 직접 물어본다."""
|
||||
from services.collector.static_html_adapter import StaticHtmlAdapter
|
||||
|
||||
adapter = StaticHtmlAdapter()
|
||||
@@ -214,26 +175,13 @@ def test_static_html_never_touches_blocked_platforms():
|
||||
|
||||
|
||||
def test_static_html_takes_owner_domains():
|
||||
"""검증: 사장님 자체 홈페이지로 보이는 평범한 도메인.
|
||||
|
||||
기대결과: static_html 이 받는다. 숙박 표본의 76%가 자체 도메인을 쓰므로
|
||||
여기서 놓치면 숙박 수집이 통째로 비어버린다."""
|
||||
"""검증: 사장님 자체 홈페이지로 보이는 평범한 도메인."""
|
||||
for url in ("https://gangmunstay.kr/rooms", "https://offinghouse.com/", "https://www.mulhoe.co.kr/"):
|
||||
assert get_adapter(url).id == "static_html", f"static_html 이 받지 않는다: {url}"
|
||||
|
||||
|
||||
def test_adapters_do_not_collect_llm_written_fields():
|
||||
"""검증: **등록된 모든 어댑터**가 만드는 fact key 에 allow_llm=True 필드가 섞이는지.
|
||||
|
||||
기대결과: 없다. 소개문 계열은 수집하는 사실이 아니라 generator 가 쓰는 문장이다(절대규칙 7).
|
||||
|
||||
★ 실측 사고 (2026-08-31) — 이 테스트가 MockAdapter 만 보고 있어서 놓쳤다.
|
||||
tour_api·naver_place 가 `intro` 를 수집했고, TourAPI overview 457자가 그대로
|
||||
VERIFIED 로 들어가 사장님 사이트의 '숙소 소개' 를 차지했다. Gemini 가 쓴 162자
|
||||
소개문은 PENDING_OWNER 로 뒤에 밀려 영영 안 보였다.
|
||||
원문 그대로 싣는 것은 GEO 에서도 복제 콘텐츠라 손해다.
|
||||
|
||||
그래서 소스를 훑어 확인한다 — 어댑터가 늘어나도 같은 실수를 반복할 수 없게."""
|
||||
"""검증: **등록된 모든 어댑터**가 만드는 fact key 에 allow_llm=True 필드가 섞이는지."""
|
||||
from pathlib import Path
|
||||
|
||||
banned = set()
|
||||
@@ -256,16 +204,12 @@ def test_adapters_do_not_collect_llm_written_fields():
|
||||
|
||||
@pytest.mark.parametrize("url", _REAL_URLS)
|
||||
def test_unregistered_sites_are_not_reachable(url):
|
||||
"""검증: 어댑터가 없는 사이트 URL 로 수집을 시도한다.
|
||||
기대결과: can_handle 이 False — 확정 링크 거르기 단계에서 크롤링 대상에 오르지 않는다."""
|
||||
"""검증: 어댑터가 없는 사이트 URL 로 수집을 시도한다."""
|
||||
assert REGISTRY.can_handle(url) is False
|
||||
|
||||
|
||||
def test_naver_place_hosts_are_handled():
|
||||
"""검증: 사람이 실제로 공유하는 네이버 플레이스 주소들.
|
||||
|
||||
기대결과: 전부 naver_place 가 받는다. 하나라도 빠지면 사장님이 붙여넣은 주소가
|
||||
'어댑터없음' 으로 조용히 버려진다 — 실제로 map.naver.com 이 빠져서 그랬다."""
|
||||
"""검증: 사람이 실제로 공유하는 네이버 플레이스 주소들."""
|
||||
for url in (
|
||||
"https://map.naver.com/p/entry/place/1133638931",
|
||||
"https://m.place.naver.com/accommodation/1133638931/home",
|
||||
@@ -276,8 +220,7 @@ def test_naver_place_hosts_are_handled():
|
||||
|
||||
|
||||
def test_no_evasion_code_in_collector_package():
|
||||
"""검증: 수집 패키지에 우회 코드가 들어왔는지 소스를 훑는다.
|
||||
기대결과: 캡차 우회·봇 탐지 우회·IP 회전 흔적이 없다(영구 금지, 검토 결과와 무관)."""
|
||||
"""검증: 수집 패키지에 우회 코드가 들어왔는지 소스를 훑는다."""
|
||||
from pathlib import Path
|
||||
|
||||
banned = ("captcha", "solve_captcha", "rotate_ip", "proxy_rotate", "stealth", "undetected")
|
||||
@@ -294,8 +237,7 @@ def test_no_evasion_code_in_collector_package():
|
||||
|
||||
# ── 출처 강제 ────────────────────────────────────────────────────────────
|
||||
async def test_every_fact_and_media_carries_source_url():
|
||||
"""검증: 수집 결과의 모든 fact·사진이 출처를 들고 있는지.
|
||||
기대결과: 전부 RawSource.url 과 같다 — 출처 없는 값은 fact 기록에서 거부된다."""
|
||||
"""검증: 수집 결과의 모든 fact·사진이 출처를 들고 있는지."""
|
||||
url = MockAdapter.url_for(PlaceCategory.LODGING, "pension-9")
|
||||
source = await MockAdapter().fetch(url)
|
||||
|
||||
@@ -305,8 +247,7 @@ async def test_every_fact_and_media_carries_source_url():
|
||||
|
||||
|
||||
def test_raw_source_stamps_source_url_on_bare_items():
|
||||
"""검증: source_url 을 비운 채 항목을 넣어 RawSource 를 만든다.
|
||||
기대결과: 생성 시점에 출처가 찍힌다 — 어댑터가 깜빡해도 구조가 막는다."""
|
||||
"""검증: source_url 을 비운 채 항목을 넣어 RawSource 를 만든다."""
|
||||
source = RawSource(
|
||||
url="mock://lodging/x",
|
||||
adapter_id="mock",
|
||||
@@ -318,36 +259,31 @@ def test_raw_source_stamps_source_url_on_bare_items():
|
||||
|
||||
|
||||
def test_raw_source_requires_url():
|
||||
"""검증: url 없이 RawSource 를 만든다.
|
||||
기대결과: CollectError — 출처 없는 수집 결과는 존재할 수 없다."""
|
||||
"""검증: url 없이 RawSource 를 만든다."""
|
||||
with pytest.raises(CollectError):
|
||||
RawSource(url="", adapter_id="mock")
|
||||
|
||||
|
||||
def test_collected_media_requires_origin_url():
|
||||
"""검증: origin_url 없이 사진을 담는다.
|
||||
기대결과: CollectError — 재게시 권리 판단(docs/DECISIONS.md 1-2)에 원본 URL 이 필요하다."""
|
||||
"""검증: origin_url 없이 사진을 담는다."""
|
||||
with pytest.raises(CollectError):
|
||||
CollectedMedia(origin_url=" ")
|
||||
|
||||
|
||||
def test_unit_scoped_fact_requires_unit_name():
|
||||
"""검증: 단위 이름 없이 unit 스코프 fact 를 만든다.
|
||||
기대결과: CollectError — 어느 객실 값인지 모르면 저장할 수 없다."""
|
||||
"""검증: 단위 이름 없이 unit 스코프 fact 를 만든다."""
|
||||
with pytest.raises(CollectError):
|
||||
CollectedFact(key="standard_capacity", value="2", scope="unit")
|
||||
|
||||
|
||||
async def test_unit_names_are_listed_in_order():
|
||||
"""검증: 수집된 단위 이름 목록.
|
||||
기대결과: 등록 순서대로 중복 없이 나온다 — place.units 시드에 그대로 쓴다."""
|
||||
"""검증: 수집된 단위 이름 목록."""
|
||||
source = await MockAdapter().fetch(MockAdapter.url_for(PlaceCategory.LODGING))
|
||||
assert source.unit_names() == ["A동 스탠다드", "B동 복층"]
|
||||
|
||||
|
||||
async def test_failure_result_has_no_facts():
|
||||
"""검증: 실패 결과(RawSource.failure)의 모양.
|
||||
기대결과: ok=False, error 존재, fact·사진 없음 — 실패를 성공으로 오인할 수 없다."""
|
||||
"""검증: 실패 결과(RawSource.failure)의 모양."""
|
||||
source = RawSource.failure("mock://lodging/1", "mock", "타임아웃")
|
||||
assert source.ok is False and source.error == "타임아웃"
|
||||
assert source.facts == [] and source.media == []
|
||||
|
||||
Reference in new issue
Block a user