[feat] solution/backend: 대화로 섹션 옮기기·숨기기 확장 — 앞·한 칸·N번째·자리 바꾸기 · 여러 개 끄기 · 꺼진 목록

"맨 위 · 맨 아래 · X 다음으로" 만 되고 "X 앞으로" "한 칸 위로" "세 번째로" "자리 바꿔줘" 는
거절됐다. 발행본(HomePage.tsx)은 히어로를 늘 맨 위, SNS 를 늘 맨 아래에 그리는데 대화는
그 둘을 옮기고 "옮겼습니다" 라고 답했다 — 화면은 그대로였다.

- tools: move_section 에 where(맨 위·맨 아래·앞·뒤·위로·아래로·번째·바꾸기)·count —
  where 가 비면 예전 to 표기로 읽는다. 한 칸·N번째는 보이는 순서로 센다(꺼진 부분과 자리만
  바꾸는 헛이동 방지). 없는 순번·꺼진 부분의 칸 이동은 거절, 이미 그 자리면 Unchanged
- tools: PINNED(히어로 맨 위 · SNS 맨 아래) — 옮기기와 그 둘을 기준으로 한 앞·뒤·바꾸기를 막는다.
  히어로 다음은 맨 위, SNS 앞은 맨 아래로 읽는다
- tools: toggle_section 이 쉼표로 여럿을 받는다 — 하나라도 못 찾거나 잠겼으면 아무것도 안 바꾼다
- tools: list_sections 는 보이는 순서에 번호(= N번째 기준)를 붙이고 꺼진 것을 모은다, only=꺼진
- prompts/runtime: 스키마에 where·count·only, 섹션 줄에 [항상 맨 위]·[항상 맨 아래] —
  목록은 tools.PINNED 하나를 runtime 이 넘긴다(prompts 는 services 를 import 하지 않는다)
- docs/AGENT.md: 옮기기·숨기기 표와 근거. 동작하지 않던 예시("후기 빼줘") 교체 —
  이용 후기는 섹션 목록에 없고 발행본이 늘 그린다

테스트 21건 추가, 에이전트·카카오 174 passed. pyflakes 새 경고 없음

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Opus 5.5 committed 2026-09-29 15:49:20 +09:00
1 parent 4b48be7e81
commit 36b818eda3
5 files changed
+413 -33

No files matched your search

@@ -879,3 +879,185 @@ def test_응답_스키마에_못_한_요청_칸이_있다():
assert "skipped" in prompt.RESPONSE_SCHEMA["properties"]
assert "skipped" in prompt.RESPONSE_SCHEMA["required"]
# ── 섹션 옮기기 — 앞·한 칸·N번째·자리 바꾸기 ────────────────────────────
#
# 숙박 기본 순서에서 **화면에 보이는 것**(켜짐 · 히어로·SNS 제외):
# 소개 · 객실 안내 · 소식 · 기본 정보 · 예약 안내 · 영상 · 사진 갤러리 · 오시는 길 · …
async def _visible(client, headers, place_id) -> list[str]:
"""손님 화면의 순서 — 발행본(HomePage)은 히어로를 맨 위, SNS 를 맨 아래에 고정해 그린다."""
rows, _t = await _sections(client, headers, place_id)
return [r["name"] for r in rows if r["enabled"] and r["id"] not in ("hero", "social")]
async def _move(client, h, pid, choose, **args):
choose({"actions": [{"tool": "move_section", "args": args}], "message": ""})
return (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "옮겨줘"})).json()
async def test_어느_부분_앞으로_옮긴다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
body = await _move(client, h, pid, choose, name="사진 갤러리", where="앞", to="소개")
assert body.get("rejected") is not True, body["reply"]
assert "소개 앞으로" in body["reply"]
assert (await _visible(client, h, pid))[:2] == ["사진 갤러리", "소개"]
async def test_한_칸_위로_옮긴다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
await _move(client, h, pid, choose, name="사진 갤러리", where="위로", count="1")
order = await _visible(client, h, pid)
assert order.index("사진 갤러리") == order.index("영상") - 1
async def test_두_칸_아래로_옮긴다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
await _move(client, h, pid, choose, name="소개", where="아래로", count="두")
assert (await _visible(client, h, pid))[:3] == ["객실 안내", "소식", "소개"]
async def test_한_칸은_보이는_순서로_센다(client, auth_headers, choose, db_engine):
"""★ 꺼진 부분은 화면에 없다. 배열로 세면 꺼진 '영상' 과 자리만 바꾸고 화면은 그대로다 —
"옮겼습니다" 라고 말하는데 사장님 눈에는 아무 일도 없다."""
h, pid = await seed(client, auth_headers)
choose({"actions": [{"tool": "toggle_section", "args": {"name": "영상", "enabled": "false"}}], "message": ""})
await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "영상 빼줘"})
before = await _visible(client, h, pid)
await _move(client, h, pid, choose, name="사진 갤러리", where="위로", count="1")
after = await _visible(client, h, pid)
at = before.index("사진 갤러리")
assert after[at - 1] == "사진 갤러리" and after[at] == before[at - 1]
async def test_이미_맨_위면_그렇다고_말하고_재발행을_권하지_않는다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
body = await _move(client, h, pid, choose, name="소개", where="위로", count="1")
assert "이미" in body["reply"]
assert body["done"] is False
async def test_N번째로_옮긴다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
body = await _move(client, h, pid, choose, name="날씨", where="번째", count="3")
assert body.get("rejected") is not True, body["reply"]
assert (await _visible(client, h, pid))[2] == "날씨"
async def test_없는_순번이면_추측하지_않는다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
before = await _visible(client, h, pid)
body = await _move(client, h, pid, choose, name="날씨", where="번째", count="99")
assert body["rejected"] is True
assert await _visible(client, h, pid) == before
async def test_두_부분의_자리를_바꾼다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
before = await _visible(client, h, pid)
await _move(client, h, pid, choose, name="소개", where="바꾸기", to="사진 갤러리")
after = await _visible(client, h, pid)
assert after[before.index("소개")] == "사진 갤러리"
assert after[before.index("사진 갤러리")] == "소개"
@pytest.mark.parametrize("name, where, to", [
("히어로", "아래", ""), # 발행본이 늘 맨 위에 그린다
("SNS 게시글", "위", ""), # 발행본이 늘 맨 아래에 그린다
("소개", "앞", "히어로"), # 히어로 앞은 없다
("소개", "바꾸기", "히어로"),
])
async def test_자리가_고정된_부분은_옮기지_않는다(name, where, to, client, auth_headers, choose, db_engine):
"""★ HomePage 가 히어로·SNS 를 배열과 상관없이 그린다 — 옮기게 두면 화면만 거짓말한다."""
h, pid = await seed(client, auth_headers)
rows_before, _t = await _sections(client, h, pid)
body = await _move(client, h, pid, choose, name=name, where=where, to=to)
assert body["rejected"] is True
assert "항상" in body["reply"]
rows_after, _t = await _sections(client, h, pid)
assert [r["id"] for r in rows_after] == [r["id"] for r in rows_before]
async def test_히어로_다음은_맨_위다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
await _move(client, h, pid, choose, name="날씨", where="뒤", to="히어로")
assert (await _visible(client, h, pid))[0] == "날씨"
async def test_꺼진_부분은_한_칸씩_옮기지_않는다(client, auth_headers, choose, db_engine):
"""화면에 없는 부분은 '한 칸 위' 가 어디인지 없다."""
h, pid = await seed(client, auth_headers)
choose({"actions": [{"tool": "toggle_section", "args": {"name": "영상", "enabled": "false"}}], "message": ""})
await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "영상 빼줘"})
body = await _move(client, h, pid, choose, name="영상", where="위로", count="1")
assert body["rejected"] is True
assert "꺼져" in body["reply"]
async def test_예전처럼_to_만_와도_옮긴다(client, auth_headers, choose, db_engine):
"""where 가 비면 to 로 읽는다 — '맨 위' · '맨 아래' · 이름(그 다음으로)."""
h, pid = await seed(client, auth_headers)
await _move(client, h, pid, choose, name="날씨", where="", count="", to="소개")
order = await _visible(client, h, pid)
assert order[order.index("소개") + 1] == "날씨"
# ── 섹션 숨기기 — 여러 개 · 숨긴 목록 ────────────────────────────────────
async def test_여러_부분을_한꺼번에_끈다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"actions": [{"tool": "toggle_section", "args": {"name": "사진 갤러리, 날씨", "enabled": "false"}}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "갤러리랑 날씨 숨겨줘"})).json()
assert body.get("rejected") is not True, body["reply"]
order = await _visible(client, h, pid)
assert "사진 갤러리" not in order and "날씨" not in order
assert body["reply"].count(runtime.REPUBLISH_NOTICE) == 1
@pytest.mark.parametrize("names, bad", [("사진 갤러리, 없는섹션", "없는섹션"), ("사진 갤러리, 히어로", "히어로")])
async def test_여럿_중_하나라도_안_되면_아무것도_바꾸지_않는다(names, bad, client, auth_headers, choose, db_engine):
"""★ 일부만 끄면 사장님은 무엇이 꺼졌는지 다시 확인해야 한다. 한 요청은 한꺼번에 되거나 안 된다."""
h, pid = await seed(client, auth_headers)
before = await _visible(client, h, pid)
choose({"actions": [{"tool": "toggle_section", "args": {"name": names, "enabled": "false"}}], "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "숨겨줘"})).json()
assert body["rejected"] is True
assert bad in body["reply"]
assert await _visible(client, h, pid) == before
async def test_구성_목록은_보이는_순서에_번호를_붙이고_꺼진_것을_따로_모은다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
choose({"actions": [{"tool": "toggle_section", "args": {"name": "날씨", "enabled": "false"}}], "message": ""})
await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "날씨 빼줘"})
choose({"actions": [{"tool": "list_sections", "args": {}}], "message": ""})
reply = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "구성 보여줘"})).json()["reply"]
assert "1. 소개" in reply
assert "꺼져 있는 부분: 날씨" in reply
choose({"actions": [{"tool": "list_sections", "args": {"only": "꺼진"}}], "message": ""})
reply = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "숨긴 거 뭐 있어"})).json()["reply"]
assert "날씨" in reply
assert "1. 소개" not in reply
def test_옮기기_인자는_응답_스키마에_있다():
from services.prompts import agent as prompt
args = prompt.RESPONSE_SCHEMA["properties"]["actions"]["items"]["properties"]["args"]
for name in ("where", "count", "only"):
assert name in args["properties"] and name in args["required"]
def test_프롬프트는_고정된_부분을_알려준다():
from services.prompts import agent as prompt
sections = [{"id": "hero", "name": "히어로", "enabled": True, "locked": True},
{"id": "social", "name": "SNS 게시글", "enabled": True, "locked": False}]
text_ = prompt.build_prompt(place_name="가게", tools=tools.describe(), fields=[], facts=[],
sections=sections, photos=[], message="안녕", pinned=tools.PINNED)
assert "히어로 [끄기 불가] [항상 맨 위]" in text_
assert "SNS 게시글 [항상 맨 아래]" in text_