Merge branch 'feat/social-caption-keywords-v2'
This commit is contained in:
commit
f1d0f765d1
5 files changed
+183
-7
No files matched your search
@@ -641,3 +641,76 @@ async def test_publish_reused_text_inserts_approved_post_with_link_and_enqueues_
|
||||
assert (
|
||||
await c.execute(text("SELECT count(*) FROM place_social_posts WHERE place_id=:p"), {"p": pid})
|
||||
).scalar_one() == 1
|
||||
|
||||
|
||||
# ── 캡션에 지역·업종·상호 (2026-09-30) ──────────────────────────────────
|
||||
|
||||
def test_캡션_업종말은_홈페이지_본문_말과_다르다():
|
||||
"""★ 쓰이는 자리가 다르다 — "숙박업소에서 쉬어 가세요" 는 사람이 쓰는 말이 아니다."""
|
||||
from common.enums import PlaceCategory
|
||||
from services.prompts import copy as copy_prompt, social as social_prompt
|
||||
|
||||
assert social_prompt.caption_category(PlaceCategory.LODGING.value) == "숙소"
|
||||
assert copy_prompt._CATEGORY_LABEL[PlaceCategory.LODGING] == "숙박업소"
|
||||
# 모르는 값이면 그 말만 빠진다 — 캡션 생성이 통째로 막히지 않는다.
|
||||
assert social_prompt.caption_category(999) == ""
|
||||
assert social_prompt.caption_category(None) == ""
|
||||
|
||||
|
||||
def test_캡션_지역말은_행정표기를_줄인다():
|
||||
"""★ region_label 은 쇼케이스 목록용이라 "전북특별자치도 군산시" 가 맞다. 캡션은 다르다 —
|
||||
사람이 검색하는 말은 "군산 숙소" 이고 AI 가 인용할 때 잡는 말도 그쪽이다."""
|
||||
from services.prompts import social as social_prompt
|
||||
|
||||
assert social_prompt.caption_region("전북특별자치도 군산시") == "전북 군산"
|
||||
assert social_prompt.caption_region("서울특별시 종로구") == "서울 종로"
|
||||
assert social_prompt.caption_region("제주특별자치도 제주시") == "제주" # 겹치면 한 번만
|
||||
assert social_prompt.caption_region("") == ""
|
||||
# ★ 표에 없는 시·도는 그대로 둔다(시·군·구 접미사만 뗀다).
|
||||
assert social_prompt.caption_region("어느도 어디시") == "어느도 어디"
|
||||
|
||||
|
||||
def test_프롬프트가_지역_업종_상호를_문장으로_넣게_시킨다():
|
||||
"""★ 해시태그가 아니다. AI 는 태그가 아니라 문장을 읽고, 이 글은 사장님 명의다."""
|
||||
from services.prompts import social as social_prompt
|
||||
|
||||
prompt = social_prompt.build_prompt(
|
||||
"스테이,머뭄", [], 400, region="전북 군산", category="숙소")
|
||||
assert "전북 군산의 숙소 스테이,머뭄" in prompt
|
||||
assert "태그로 나열하지 말고" in prompt
|
||||
assert "해시태그" in prompt # 기존 금지는 그대로 남는다
|
||||
|
||||
# 값이 없으면 그 말만 빠진다.
|
||||
plain = social_prompt.build_prompt("스테이,머뭄", [], 400)
|
||||
assert '"스테이,머뭄" 를 자연스럽게' in plain
|
||||
|
||||
|
||||
async def test_지역과_업종은_근거에_얹힌다(monkeypatch):
|
||||
"""★ 얹지 않으면 본문에 쓴 순간 '근거 없는 주장' 으로 반려되고 3회 재시도를 태우고 실패한다."""
|
||||
from types import SimpleNamespace
|
||||
|
||||
from services.external import gemini_text
|
||||
from services.llm import provider as llm_provider
|
||||
|
||||
seen = {}
|
||||
|
||||
def fake_ground_check(body, grounds):
|
||||
seen["keys"] = {g.key for g in grounds}
|
||||
return True, []
|
||||
|
||||
async def fake_generate(client, model, **kw):
|
||||
return SimpleNamespace(
|
||||
json={"body": "전북 군산의 숙소 스테이,머뭄에서 조용한 하루를 보내세요.",
|
||||
"fact_keys": ["check_in_time"]},
|
||||
text="", usage=None,
|
||||
)
|
||||
|
||||
monkeypatch.setattr(gemini_text, "ground_check", fake_ground_check)
|
||||
active = llm_provider.active()
|
||||
monkeypatch.setattr(active, "is_configured", lambda: True)
|
||||
monkeypatch.setattr(active, "generate", fake_generate)
|
||||
|
||||
facts = [gemini_text.FactInput(key="check_in_time", label="체크인", value="15:00")]
|
||||
await gemini_text.generate_social_post(
|
||||
"스테이,머뭄", facts, "https://example.com/s/x", 2, region="전북 군산", category="숙소")
|
||||
assert {"name", "region", "category", "check_in_time"} <= seen["keys"]
|
||||
Reference in new issue
Block a user