feat(lps): 최저가 오퍼의 신뢰 신호(평점·리뷰) 수집 — 네이버·쿠팡 공통
'가장 싼 값'과 '실제로 살 수 있는 가장 싼 값'은 다르다. 리뷰·평점이 전혀 없는 오퍼는 재고 없는 미끼가격일 수 있고, 그걸 최저가로 보고하면 사용자는 그 가격에 살 수 없다 — 조금 비싼 정답보다 나쁘다. 판단 근거를 수집해 둔다. - NormalizedProduct.rating / review_count 추가. 두 소스 모두 카드에 노출하는 값만 담아 교차 비교가 되게 했다. **없으면 None 유지** — '리뷰 0개'와 '리뷰 정보 없음'은 다른 뜻이다 - 네이버: product_grade 의 <strong>평점</strong><em>리뷰수</em>. 텍스트를 통째로 정규식 돌리면 '평점4.7473' 이 4.74/73 인지 4.7/473 인지 못 가르므로 노드로 분리해 읽는다. '1.7만' 같은 축약은 parse_ko_count 로 푼다(그대로 int() 하면 1 이 된다) - 쿠팡: 별점은 채워진 별 개수가 아니라 컨테이너 aria-label 에, 리뷰 수는 괄호 텍스트에 있다 - price_history.final_rating/final_review_count 추가(+마이그레이션) → "리뷰 0인 최저가가 몇 %인가"를 SQL 로 물을 수 있다. NULL 과 0 을 구분해야 해서 기본값을 두지 않았다 정렬 점검(사용자 제기): 두 소스 다 정렬 파라미터 없이 **랭킹/추천순**이다(픽스처 가격이 오름차순이 아님으로 확인). 가격순(sort=price_asc)은 차단 없이 동작하고 실측상 더 싼 후보를 찾지만(15,400→10,900), 리뷰·평점 없는 유령상품을 위로 끌어올려 미채택 — 추천순 유지. 신뢰 신호가 쌓이면 "리뷰 N 이상" 가드를 걸고 가격순을 켜는 선택지가 열린다. e2e: TR-1/TR-2 최저가에 평점 4.89·리뷰 7,314/102,000 이 함께 기록됨. 테스트 5건 추가, 228 passed.
This commit is contained in:
1 parent
5c9567919f
commit
6c7ff5af51
13 files changed
+142
-4
No files matched your search
@@ -92,3 +92,12 @@ def test_detect_block_genuine_empty_large_page_not_blocked():
|
||||
# 정상 '검색결과 없음'(전체 chrome 포함, 큰 HTML)은 차단 아님 → not_found 로 흘러야 함
|
||||
big = "<html><body>검색결과가 없습니다" + "x" * 20000 + "</body></html>"
|
||||
assert detect_block(big, 0) is None
|
||||
|
||||
|
||||
def test_trust_signals_are_captured():
|
||||
"""쿠팡은 별점이 채워진 별 개수가 아니라 컨테이너 aria-label 에, 리뷰 수는 괄호 텍스트에 있다."""
|
||||
ps = parse_search_html(FIXTURE.read_text())
|
||||
rated = [p for p in ps if p.review_count]
|
||||
assert rated
|
||||
assert all(0 < p.rating <= 5 for p in rated)
|
||||
assert max(p.review_count for p in rated) > 1000 # '41,448' 처럼 콤마가 섞여도 파싱된다
|
||||
@@ -143,3 +143,35 @@ def test_detect_block_flags_captcha_and_short_html():
|
||||
|
||||
def test_detect_block_passes_real_page():
|
||||
assert detect_block(_fixture(), 12) is None
|
||||
|
||||
|
||||
# ── 신뢰 신호 ────────────────────────────────────────────────────────────
|
||||
def test_trust_signals_are_captured():
|
||||
"""최저가는 '살 수 있는 가장 싼 값'이어야 한다 — 평점·리뷰가 그 판단 근거다."""
|
||||
ps = parse_search_html(_fixture())
|
||||
rated = [p for p in ps if p.review_count]
|
||||
assert rated, "리뷰가 있는 오퍼가 하나도 안 잡히면 셀렉터가 드리프트한 것"
|
||||
assert all(0 < p.rating <= 5 for p in rated)
|
||||
|
||||
|
||||
def test_missing_trust_stays_none_not_zero():
|
||||
"""리뷰 정보가 없는 것과 '리뷰 0개'는 다른 뜻이다 — 0 으로 채우면 구분이 사라진다."""
|
||||
ps = parse_search_html(_fixture())
|
||||
ghost = [p for p in ps if p.review_count is None]
|
||||
assert ghost, "픽스처에 미검증 오퍼가 있어야 이 계약을 지킬 수 있다"
|
||||
assert all(p.rating is None for p in ghost)
|
||||
|
||||
|
||||
def test_korean_abbreviated_review_count():
|
||||
"""'1.7만' 을 그대로 int() 하면 1 이 된다 — 만/천 단위를 풀어야 한다."""
|
||||
html = _card("""
|
||||
<div class="product_info_tit__UOCqq">테스트 상품</div>
|
||||
<span class="product_price__O3ZGH">
|
||||
<span class="product_immediate_price__m3YQU">10,000<span class="product_unit__seYZk">원</span></span>
|
||||
</span>
|
||||
<div class="product_info_count__J6ElA">
|
||||
<span class="product_grade__eU8gY"><span class="blind">평점</span><strong>4.88</strong><em>1.7만</em></span>
|
||||
</div>
|
||||
<a class="product_btn_link__AhZaM" href="https://x.test/9">상품 바로가기</a>""")
|
||||
(p,) = parse_search_html(html)
|
||||
assert p.rating == 4.88 and p.review_count == 17000
|
||||
@@ -100,3 +100,16 @@ async def test_handler_records_on_negative_cache_hit():
|
||||
e = rec.events[0]
|
||||
assert e["product_code"] == "PC1" and e["outcome"] == "not_found"
|
||||
assert e["final_lowest"] is None and e["matched_count"] == 0 # 검색을 안 했으니 가격도 없다
|
||||
|
||||
|
||||
async def test_snapshot_carries_trust_of_the_lowest_offer():
|
||||
"""최저가 오퍼의 평점·리뷰가 이력에 함께 남아야 '살 수 있는 가격이었나'를 사후에 물을 수 있다."""
|
||||
rec = _Rec()
|
||||
cheap_ghost = _np("naver", 900) # 가장 싸지만 리뷰·평점 없음
|
||||
trusted = _np("coupang", 1800)
|
||||
trusted.rating, trusted.review_count = 4.8, 1200
|
||||
adapters = {"naver": _FakeAdapter("naver", [cheap_ghost]), "coupang": _FakeAdapter("coupang", [trusted])}
|
||||
await build_search_handler(adapters, history=rec)(_job())
|
||||
e = rec.events[0]
|
||||
assert e["final_lowest"] == 900 and e["final_source"] == "naver"
|
||||
assert e["final_rating"] is None and e["final_review_count"] is None # 미검증 오퍼임이 드러난다
|
||||
Reference in new issue
Block a user