[fix] solution/backend,docs: LLM 이 쓴 문장은 승인 없이 나간다 — 소개문이 생성되고도 영영 빈칸이던 것
실측(2026-09-10, 힐튼 가든 인 서울 강남): 로그는 `[copy] 소개문 O` 이고 DB 에도 문장이
있는데 발행본의 소개는 빈칸이었다. status=1(UNVERIFIED) 이라 스냅샷이 담지 않았고,
그 자리를 fact 로 조립한 한 줄("서초구에 있는 …입니다. 체크인 15:00.")이 대신 채워
화면만 보면 생성이 실패한 것처럼 보이지도 않았다.
승인이 안 된 이유는 승인할 화면이 없어서다 — 수집 확인은 07:29 에 끝나는데 소개문은
07:31 에 도착한다. 사장님은 그 화면을 이미 지나간 뒤다.
게이트는 뒤가 아니라 앞에 둔다: 입력이 확인된 fact 뿐이고(근거가 없으면 유료 호출조차
하지 않는다), 근거 없는 FAQ 는 저장되지 않는다. 이미 승인된 사실로 쓴 문장을 한 번 더
승인받는 것은 같은 사실을 두 번 승인하는 일이다.
- fact_service: LLM 출처는 후보가 아니라 노출값으로 앉힌다. API·CRAWL 은 그대로 후보다
- fact_service: 사장님이 고친 문장(CORRECTED)은 LLM 이 못 덮게 잠금을 **명시적으로** 건다.
지금까지 이 보호는 "자동 출처는 노출값 경로로 못 간다" 는 경로가 대신 해 주고 있었다 —
LLM 만 경로를 바꾸면 그 보호가 조용히 사라진다(절대규칙 6)
- copy_service: 생성 FAQ 를 VERIFIED 로 저장
- faq_crud: 재생성 대상을 status 가 아니라 generated_by 로 가른다. 생성분이 VERIFIED 로
들어가면 status 로는 사람이 손댔는지 알 수 없다 — 그대로 뒀다면 재생성이 옛 FAQ 를
못 내려 같은 질문이 쌓인다. 반려(REJECTED)한 것은 그대로 둔다
- tests: 잡을 하나만 처리하면 지역 이야기 잡에 밀린다 — process_one → drain
- DECISIONS 7절 신설, 6-2 의 "FAQ 에는 넓히지 않는다" 를 결론과 함께 고침. DEVLOG 추가
검증: fact·copy·faq 35 passed(신규 2건 — LLM 문장이 승인 없이 노출값이 되는지 ·
CORRECTED 를 못 덮는지). 전체 577 passed / 8 failed, 8건은 전부 컨테이너 환경변수 유입
(.env 키 · 프론트 소스 부재 · SITE_PUBLIC_HOST)이고 코드 회귀가 아니다.
운영 재기동 후 힐튼으로 재생성: intro status=3 · FAQ 6건 VERIFIED · 옛 7건 EXPIRED 확인
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fc67962efc
commit
4d5a77453b
8 files changed
+198
-32
No files matched your search
@@ -3,8 +3,10 @@
|
||||
이 잡이 절대 하면 안 되는 것:
|
||||
- 미검증 fact 를 근거로 문장을 쓰는 것 (그 문장도 미검증이 된다)
|
||||
- 근거 없이 생성하는 것 (그게 환각이다)
|
||||
- 생성물을 바로 사이트에 노출하는 것 (사람 승인이 있어야 한다)
|
||||
- 사람이 확인한 FAQ 를 재생성이 덮어쓰는 것
|
||||
- 사람이 정정한 FAQ·소개문(CORRECTED)을 재생성이 덮어쓰는 것
|
||||
|
||||
★ 반대로 '생성물을 바로 노출하는 것' 은 이제 금지가 아니다(2026-09-10 결정).
|
||||
게이트는 입력 쪽에 있다 — 확인된 fact 로만 쓰고, 근거 없는 FAQ 는 저장되지 않는다.
|
||||
"""
|
||||
import uuid
|
||||
|
||||
@@ -55,9 +57,10 @@ async def _faq_rows(db_engine, pid):
|
||||
)).all()
|
||||
|
||||
|
||||
async def test_copy_generates_intro_and_faq_as_candidates(auth_headers, client, db_engine, monkeypatch):
|
||||
async def test_copy_generates_intro_and_faq_as_published(auth_headers, client, db_engine, monkeypatch):
|
||||
"""검증: 소개문·FAQ 를 생성한다.
|
||||
기대결과: 생성되지만 ★ 전부 미검증 — 사람이 승인해야 사이트에 나간다."""
|
||||
기대결과: ★ 바로 노출값(VERIFIED) — 승인 단계를 두지 않는다(2026-09-10 결정).
|
||||
게이트는 앞에 있다: 입력이 확인된 fact 뿐이고 근거 없는 FAQ 는 저장되지 않는다."""
|
||||
_patch(monkeypatch, _copy())
|
||||
h = await auth_headers("u1")
|
||||
pid = await _place_with_facts(client, h)
|
||||
@@ -66,20 +69,20 @@ async def test_copy_generates_intro_and_faq_as_candidates(auth_headers, client,
|
||||
assert body["result"]["success"] is True
|
||||
assert body["grounded_facts"] == 5
|
||||
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).process_one()
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).drain()
|
||||
job = (await client.get(f"/v1/job/{body['job_id']}", headers=h)).json()["job"]
|
||||
assert job["status"] == JobStatus.DONE.value, job.get("last_error")
|
||||
assert job["result"]["intro"] is True
|
||||
assert job["result"]["faqs"] == 1
|
||||
|
||||
rows = await _faq_rows(db_engine, pid)
|
||||
assert rows[0][3] == FactStatus.UNVERIFIED.value, "★ 생성된 FAQ 가 바로 노출 상태면 안 된다"
|
||||
assert rows[0][3] == FactStatus.VERIFIED.value, "★ 생성된 FAQ 는 바로 노출값이어야 한다"
|
||||
assert rows[0][2] == ["check_in_time"], "근거 fact 가 기록돼야 한다"
|
||||
|
||||
# 소개문도 fact 로 들어가되 미검증 후보다
|
||||
# 소개문도 fact 로 들어가고, 승인 없이 바로 노출값이다
|
||||
facts = (await client.get(f"/v1/place/{pid}/fact/list", headers=h)).json()
|
||||
intro = [f for f in facts["facts"] if f["key"] == "intro"]
|
||||
assert intro and intro[0]["status"] == FactStatus.UNVERIFIED.value
|
||||
assert intro and intro[0]["status"] == FactStatus.VERIFIED.value
|
||||
assert intro[0]["source_type"] == SourceType.LLM.value
|
||||
|
||||
|
||||
@@ -120,7 +123,7 @@ async def test_faq_without_grounding_is_dropped(auth_headers, client, db_engine,
|
||||
h = await auth_headers("u1")
|
||||
pid = await _place_with_facts(client, h)
|
||||
job_id = (await client.post(f"/v1/place/{pid}/copy", headers=h, json={})).json()["job_id"]
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).process_one()
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).drain()
|
||||
|
||||
job = (await client.get(f"/v1/job/{job_id}", headers=h)).json()["job"]
|
||||
assert job["result"]["faqs"] == 1
|
||||
@@ -135,36 +138,43 @@ async def test_rejected_sentences_are_reported(auth_headers, client, monkeypatch
|
||||
h = await auth_headers("u1")
|
||||
pid = await _place_with_facts(client, h)
|
||||
job_id = (await client.post(f"/v1/place/{pid}/copy", headers=h, json={})).json()["job_id"]
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).process_one()
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).drain()
|
||||
|
||||
job = (await client.get(f"/v1/job/{job_id}", headers=h)).json()["job"]
|
||||
assert job["result"]["intro"] is False
|
||||
assert any("수영장" in str(r) for r in job["result"]["rejected"])
|
||||
|
||||
|
||||
async def test_regeneration_keeps_human_approved_faq(auth_headers, client, db_engine, monkeypatch):
|
||||
"""검증: 사람이 승인한 FAQ 가 있는 상태에서 재생성한다.
|
||||
기대결과: ★ 승인된 FAQ 는 남는다 — 재생성이 사람의 판단을 덮어쓰면 안 된다."""
|
||||
async def test_regeneration_keeps_faq_the_owner_corrected(auth_headers, client, db_engine, monkeypatch):
|
||||
"""검증: 사장님이 고친 FAQ 가 있는 상태에서 재생성한다.
|
||||
기대결과: ★ 고친 FAQ 는 남는다 — 재생성이 사람의 판단을 덮어쓰면 안 된다.
|
||||
|
||||
★ '승인' 이 아니라 '정정' 으로 검증한다(2026-09-10). 생성분이 곧바로 VERIFIED 로 들어가면서
|
||||
status 만으로는 사람이 손댔는지 알 수 없게 됐다. 책임 주체를 적어 두는 자리는
|
||||
generated_by 이고, 사장님이 정정하면 faq_service 가 그 값을 OWNER 로 바꾼다."""
|
||||
_patch(monkeypatch, _copy())
|
||||
h = await auth_headers("u1")
|
||||
pid = await _place_with_facts(client, h)
|
||||
await client.post(f"/v1/place/{pid}/copy", headers=h, json={})
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).process_one()
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).drain()
|
||||
|
||||
# 사람이 승인
|
||||
# 사장님이 문구를 고쳐 승인 — 잠긴 상태(CORRECTED)가 되고 책임 주체가 사람으로 넘어온다.
|
||||
async with db_engine.begin() as c:
|
||||
await c.execute(
|
||||
text("UPDATE place_faqs SET status = :s WHERE place_id = :p"),
|
||||
{"s": FactStatus.VERIFIED.value, "p": uuid.UUID(pid)},
|
||||
text("UPDATE place_faqs SET status = :s, generated_by = :g, question = :q WHERE place_id = :p"),
|
||||
{"s": FactStatus.CORRECTED.value, "g": SourceType.OWNER.value,
|
||||
"q": "체크인 시간이 어떻게 되나요?", "p": uuid.UUID(pid)},
|
||||
)
|
||||
|
||||
_patch(monkeypatch, _copy(faqs=[gemini_text.GeneratedFaq("새 질문?", "새 답변", ["check_in_time"])]))
|
||||
await client.post(f"/v1/place/{pid}/copy", headers=h, json={})
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).process_one()
|
||||
await Worker("w", JobQueue(), build_handler(), job_deadline_sec=30).drain()
|
||||
|
||||
rows = await _faq_rows(db_engine, pid)
|
||||
approved = [r for r in rows if r[3] == FactStatus.VERIFIED.value]
|
||||
assert approved and approved[0][0] == "체크인은 몇 시인가요?", "★ 승인된 FAQ 가 재생성에 밀려났다"
|
||||
kept = [r for r in rows if r[3] == FactStatus.CORRECTED.value]
|
||||
assert kept and kept[0][0] == "체크인 시간이 어떻게 되나요?", "★ 사장님이 고친 FAQ 가 재생성에 밀려났다"
|
||||
# 새로 생성된 것은 바로 노출값으로 함께 선다.
|
||||
assert any(r[0] == "새 질문?" and r[3] == FactStatus.VERIFIED.value for r in rows)
|
||||
|
||||
|
||||
async def test_copy_requires_api_key(auth_headers, client, monkeypatch):
|
||||
|
||||
@@ -82,6 +82,48 @@ async def test_llm_cannot_write_non_sentence_fields(auth_headers, client):
|
||||
assert body["result"]["success"] is True
|
||||
|
||||
|
||||
async def test_llm_sentence_is_published_without_approval(auth_headers, client):
|
||||
"""검증: LLM 이 소개문(allow_llm)을 기록한다.
|
||||
기대결과: ★ 후보가 아니라 바로 노출값(VERIFIED) — 2026-09-10 결정.
|
||||
소개문은 사실이 아니라 이미 승인된 사실로 쓴 문장이라 승인을 두 번 받을 이유가 없다."""
|
||||
h = await auth_headers("u1")
|
||||
pid = await _verified_place(client, h, kakao="l2")
|
||||
|
||||
body = await _crawl(client, h, pid, "intro", "조용한 숙소입니다.", SourceType.LLM)
|
||||
assert body["fact"]["status"] == FactStatus.VERIFIED.value
|
||||
assert body["outcome"] != FactWriteOutcome.CANDIDATE_CREATED.value
|
||||
|
||||
# 사이트 빌드가 보는 집합에 바로 들어간다.
|
||||
facts = (await client.get(f"/v1/place/{pid}/fact/list", headers=h)).json()
|
||||
assert facts["publishable"] >= 1
|
||||
|
||||
|
||||
async def test_llm_cannot_overwrite_corrected_sentence(auth_headers, client):
|
||||
"""검증: 사장님이 고친 소개문(CORRECTED)을 LLM 이 다시 쓴다.
|
||||
기대결과: 노출값은 사장님 문장 그대로 — ★ 절대규칙 6. 새 문장은 후보로만 남는다.
|
||||
|
||||
★ 이 잠금은 지금까지 '자동 출처는 노출값 경로로 못 간다'는 구조가 대신 지켜 줬다.
|
||||
LLM 만 그 경로를 지나가게 되면서 잠금을 명시적으로 다시 걸어야 했다."""
|
||||
h = await auth_headers("u1")
|
||||
pid = await _verified_place(client, h, kakao="l3")
|
||||
|
||||
await _crawl(client, h, pid, "intro", "생성된 첫 문장입니다.", SourceType.LLM)
|
||||
facts = (await client.get(f"/v1/place/{pid}/fact/list", headers=h)).json()
|
||||
fact_id = next(f["fact_id"] for f in facts["facts"] if f["key"] == "intro")
|
||||
|
||||
r = await client.post(f"/v1/place/{pid}/fact/{fact_id}/transition", headers=h, json={
|
||||
"status": FactStatus.CORRECTED.value, "value": "사장님이 고친 문장입니다."})
|
||||
assert r.json()["result"]["success"] is True
|
||||
|
||||
body = await _crawl(client, h, pid, "intro", "생성기가 다시 쓴 문장입니다.", SourceType.LLM)
|
||||
assert body["outcome"] == FactWriteOutcome.CANDIDATE_CREATED.value
|
||||
|
||||
facts = (await client.get(f"/v1/place/{pid}/fact/list", headers=h)).json()
|
||||
published = [f for f in facts["facts"]
|
||||
if f["key"] == "intro" and f["status"] == FactStatus.CORRECTED.value]
|
||||
assert published and published[0]["value"] == "사장님이 고친 문장입니다."
|
||||
|
||||
|
||||
# ── 생성 프로세스 ─────────────────────────────────────────────────────────
|
||||
async def test_crawled_fact_starts_as_candidate_and_is_not_published(auth_headers, client):
|
||||
"""검증: 크롤링으로 처음 들어온 값.
|
||||
|
||||
@@ -19,7 +19,10 @@ async def _place(client, headers, name="FAQ펜션"):
|
||||
|
||||
|
||||
async def _seed_generated_faq(db_engine, pid, question="체크인은 몇 시인가요?", answer="15시입니다.", order=0):
|
||||
"""COPY 잡이 남기고 간 상태를 그대로 만든다 — LLM 출처 · UNVERIFIED."""
|
||||
"""LLM 출처 · UNVERIFIED 인 FAQ 한 건.
|
||||
|
||||
★ 2026-09-10 부터 COPY 잡은 VERIFIED 로 넣는다. 이 상태는 그 전에 생성된 행과
|
||||
사장님이 반려·정정을 거치며 지나가는 자리다 — 상태 의미는 그대로 지켜져야 하므로 남긴다."""
|
||||
fid = uuid.uuid4()
|
||||
async with db_engine.begin() as conn:
|
||||
await conn.execute(
|
||||
|
||||
Reference in new issue
Block a user