o2o-site-AEO/solution/backend/tests/test_category_schema.py
Mina Choi 11d30bb3d1 [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>
2026-09-28 16:05:19 +09:00

68 lines
3.1 KiB
Python

"""업종 스키마 — 4개 업종 파일이 규약대로 로드되는지."""
import pytest
from common.category_schema import CategorySchemaError, all_schemas, get_schema, is_valid_key
from common.enums import PlaceCategory
def test_all_categories_have_schema():
"""검증: PlaceCategory 의 모든 업종에 스키마 파일이 있는지."""
schemas = all_schemas()
assert set(schemas) == {c.value for c in PlaceCategory}
for code, schema in schemas.items():
assert schema.code == code
assert schema.category == PlaceCategory(code)
assert schema.fields, f"{schema.name}: 필드가 비었다"
def test_keys_unique_within_category():
"""검증: 업종 안에서 fact key 가 유일한지."""
for schema in all_schemas().values():
keys = list(schema.fields)
assert len(keys) == len(set(keys)), f"{schema.name}: key 중복"
def test_place_and_unit_scopes_exist():
"""검증: 업종마다 place 스코프 필드가 있는지."""
for schema in all_schemas().values():
assert schema.keys_by_scope("place"), f"{schema.name}: place 스코프 필드가 없다"
def test_lodging_has_claim_critical_fields():
"""검증: 숙박 업종에 예약 클레임 직결 항목이 critical 로 잡혀 있는지."""
schema = get_schema(PlaceCategory.LODGING)
for key in ("check_in_time", "check_out_time", "cooking_allowed", "pet_allowed", "cancel_policy"):
spec = schema.get(key)
assert spec is not None, f"숙박 스키마에 {key} 가 없다"
assert spec.critical is True, f"{key} 는 critical 이어야 한다"
assert spec.allow_llm is False, f"{key} 는 LLM 이 값을 만들면 안 된다"
def test_llm_writable_fields_are_sentences_only():
"""검증: LLM 이 값을 만들 수 있는 필드가 '문장' 필드뿐인지 (절대규칙 7 — LLM 은 사실을 만들지 않는다)."""
for schema in all_schemas().values():
for key in schema.llm_writable_keys():
spec = schema.get(key)
assert spec.type == "text", f"{schema.name}.{key}: LLM 이 쓸 수 있는 필드는 text 여야 한다"
assert spec.critical is False, f"{schema.name}.{key}: critical 필드를 LLM 이 쓰면 안 된다"
def test_required_fields_are_never_llm_written():
"""검증: 발행 필수 항목을 LLM 이 채우지 못하는지."""
for schema in all_schemas().values():
for key in schema.required_keys():
assert schema.get(key).allow_llm is False, f"{schema.name}.{key}: 필수 항목을 LLM 이 채우면 안 된다"
def test_is_valid_key_rejects_cross_category_key():
"""검증: 업종에 없는 key 를 걸러내는지 (facts 쓰기 전 FACT_INVALID_KEY 판정)."""
assert is_valid_key(PlaceCategory.LODGING, "check_in_time") is True
assert is_valid_key(PlaceCategory.CAFE, "check_in_time") is False
assert is_valid_key(PlaceCategory.CAFE, "break_time") is True
def test_unknown_category_raises():
"""검증: 지원하지 않는 업종 코드 조회."""
with pytest.raises(CategorySchemaError):
get_schema(99)