여러 줄 주석이 설명보다 경위(예전·실측·지적)를 적고 있어 읽는 사람이 결론을 찾기 어려웠다. - 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>
114 lines
4.2 KiB
Python
114 lines
4.2 KiB
Python
"""발행 검수 게이트 — 절대규칙 1~3 이 실제로 막는가."""
|
|
import pytest
|
|
|
|
from common.enums import FactStatus, PlaceCategory, PublishRejectReason
|
|
from services.publish_gate import (
|
|
GateResult,
|
|
check_facts_verified,
|
|
check_jsonld_matches,
|
|
check_required_fields,
|
|
check_unique_content,
|
|
evaluate,
|
|
)
|
|
|
|
|
|
def _f(key, value="x", status=FactStatus.VERIFIED):
|
|
return {"key": key, "value": value, "status": status.value}
|
|
|
|
|
|
def _lodging_required():
|
|
"""숙박 필수 항목을 전부 채운 fact 목록."""
|
|
return [
|
|
_f("check_in_time", "15:00"), _f("check_out_time", "11:00"),
|
|
_f("cancel_policy", "7일 전 100% 환불"), _f("cooking_allowed", "true"),
|
|
_f("pet_allowed", "false"),
|
|
]
|
|
|
|
|
|
def test_unverified_fact_blocks_publish():
|
|
"""검증: 미검증 fact 가 노출 대상에 섞여 있다."""
|
|
facts = _lodging_required() + [_f("wifi", "true", FactStatus.UNVERIFIED)]
|
|
r = check_facts_verified(facts)
|
|
assert r.passed is False
|
|
assert r.reason == PublishRejectReason.UNVERIFIED_FACT
|
|
assert r.detail["unverified"][0]["key"] == "wifi"
|
|
|
|
|
|
@pytest.mark.parametrize("status", [FactStatus.PENDING_OWNER, FactStatus.REJECTED, FactStatus.EXPIRED])
|
|
def test_every_non_publishable_status_blocks(status):
|
|
"""검증: 노출 불가 상태 전부(확인대기·반려·만료)."""
|
|
assert check_facts_verified([_f("wifi", "true", status)]).passed is False
|
|
|
|
|
|
def test_corrected_fact_is_publishable():
|
|
"""검증: 사람이 정정한 값(CORRECTED)."""
|
|
assert check_facts_verified([_f("wifi", "true", FactStatus.CORRECTED)]).passed is True
|
|
|
|
|
|
def test_missing_required_field_blocks_publish():
|
|
"""검증: 숙박인데 취소 규정이 없다."""
|
|
facts = [f for f in _lodging_required() if f["key"] != "cancel_policy"]
|
|
r = check_required_fields(PlaceCategory.LODGING, facts)
|
|
assert r.passed is False
|
|
assert r.reason == PublishRejectReason.REQUIRED_FACT_MISSING
|
|
assert "cancel_policy" in r.detail["missing"]
|
|
assert "취소·환불 규정" in r.detail["labels"]
|
|
|
|
|
|
def test_blank_value_counts_as_missing():
|
|
"""검증: 필수 fact 가 있긴 한데 값이 빈 문자열이다."""
|
|
facts = _lodging_required()
|
|
facts[0]["value"] = " "
|
|
assert check_required_fields(PlaceCategory.LODGING, facts).passed is False
|
|
|
|
|
|
def test_zero_unique_content_blocks_publish():
|
|
"""검증: 고유 콘텐츠가 0건이다."""
|
|
r = check_unique_content(0)
|
|
assert r.passed is False
|
|
assert r.reason == PublishRejectReason.NO_UNIQUE_CONTENT
|
|
assert check_unique_content(1).passed is True
|
|
|
|
|
|
def test_unmeasured_unique_content_is_not_zero():
|
|
assert check_unique_content(None).passed is True
|
|
|
|
|
|
def test_jsonld_mismatch_blocks_publish():
|
|
"""검증: 구조화 데이터 값이 화면 값과 다르다."""
|
|
r = check_jsonld_matches(["checkinTime: jsonld=14:00 / html=15:00"])
|
|
assert r.passed is False
|
|
assert r.reason == PublishRejectReason.JSONLD_MISMATCH
|
|
assert "14:00" in r.detail["mismatches"][0]
|
|
assert check_jsonld_matches([]).passed is True
|
|
|
|
|
|
def test_evaluate_passes_a_complete_site():
|
|
"""검증: 모든 조건을 만족하는 사이트."""
|
|
r = evaluate(PlaceCategory.LODGING, _lodging_required(), unique_content_count=5, mismatches=[])
|
|
assert r.passed is True
|
|
assert r.reason is None
|
|
|
|
|
|
def test_evaluate_reports_most_severe_first():
|
|
"""검증: 여러 규칙을 동시에 위반한다."""
|
|
facts = _lodging_required() + [_f("wifi", "true", FactStatus.UNVERIFIED)]
|
|
r = evaluate(PlaceCategory.LODGING, facts, unique_content_count=0, mismatches=["x"])
|
|
assert r.reason == PublishRejectReason.UNVERIFIED_FACT
|
|
|
|
|
|
def test_evaluate_does_not_block_thin_content():
|
|
"""검증: 고유 문장이 없어도 발행 게이트는 통과한다."""
|
|
r = evaluate(PlaceCategory.LODGING, _lodging_required(), unique_content_count=0, mismatches=[])
|
|
log = r.as_log()
|
|
assert r.passed is True
|
|
assert log["reason"] is None
|
|
|
|
|
|
@pytest.mark.parametrize("category", list(PlaceCategory))
|
|
def test_required_check_works_for_every_category(category):
|
|
"""검증: 업종 4종 전부에서 필수 검사가 동작하는가."""
|
|
r = check_required_fields(category, [])
|
|
assert r.passed is False
|
|
assert r.detail["missing"]
|