[feat] solution/backend: 에이전트가 페이지 구성을 바꾼다 — 섹션 on/off·순서

"문구 변경밖에 안 된다" 는 지적에서 시작했다. 페이지 구성은 sites.theme.sections
배열 하나이고 배열 순서가 곧 발행본의 순서라, 그 JSON 을 만지는 도구 셋을 붙였다.

- list_sections(READ) · toggle_section(REVERSIBLE) · move_section(REVERSIBLE)
- 목록은 site_payload._sections 를 그대로 쓴다 — 발행본이 쓰는 그 함수다.
  표를 따로 만들면 에디터·발행본·대화 셋이 갈라지고 "껐는데 나온다" 가 된다
- 잠긴 섹션은 못 끈다. _sections 가 어차피 켜서 내보내므로 끌 수 있게 두면
  화면만 거짓말한다
- 이름이 둘 이상 걸리면 고르지 않는다 — 추측으로 고르면 발행하고 나서야 안다
- sections 만 갈아끼운다 — theme 을 통째로 쓰면 고른 색·서체가 말없이 사라진다

★ 템플릿·색은 넣지 않았다. templatesFor() 가 색·look·기본 섹션·배리에이션을 함께
계산해서, 백엔드가 template_id 만 바꾸면 "레이아웃은 새것, 색은 옛것" 이 된다 —
레지스트리를 공유 단일 출처로 옮기는 작업이 먼저다(docs/AGENT.md).

test_agent_runtime 26 passed(구성 7건 추가).
전체 864 passed / 53 failed — 53 은 이번 변경 전과 동일. npm run lint 통과

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
HyeongBaeYangandClaude Opus 5 committed 2026-09-28 11:50:38 +09:00
1 parent e35ce311d3
commit ea9ae1ac2a
6 files changed
+276 -6

No files matched your search

@@ -248,3 +248,98 @@ async def test_닫아_두면_대화_요청은_거절된다(client, auth_headers,
assert res.status_code == 409
assert res.json()["detail"] == "AGENT_NOT_CONFIGURED"
assert (await client.get("/v1/agent/status", headers=h)).json()["enabled"] is False
# ── 페이지 구성 (섹션 on/off · 순서) ─────────────────────────────────────
async def _sections(client, headers, place_id):
"""대화가 보는 것과 같은 목록 — 도구가 쓰는 함수를 그대로 쓴다."""
from services.agent.tools import ToolContext, sections_of
from router.v1.validator.dependencies import DecodeAccessToken
from crud.place_crud import PlaceCRUD
from common.database.db_session_manager import DB_SESSION_MNG
from common.database.model.models import places
from common.enums import DBWRType
user = DecodeAccessToken(headers["Authorization"].split(" ", 1)[1])
_err, place = await DB_SESSION_MNG.execute_lambda(
places.DBType(), DBWRType.DB_READ.value,
lambda s: PlaceCRUD().get_place(s, uuid.UUID(user.user_id), uuid.UUID(place_id)),
)
rows, theme = await sections_of(ToolContext(user=user, place_id=place_id, place=place))
return rows, theme
async def test_저장값이_없어도_업종_기본_구성이_보인다(client, auth_headers, choose, db_engine):
"""★ 아직 디자인을 한 번도 안 만진 사업장에서도 대화가 바로 통해야 한다."""
h, pid = await seed(client, auth_headers)
rows, _theme = await _sections(client, h, pid)
names = {r["name"] for r in rows}
assert "히어로" in names and "객실 안내" in names
async def test_섹션을_끄면_순서는_그대로고_그_칸만_꺼진다(client, auth_headers, choose, db_engine):
h, pid = await seed(client, auth_headers)
before, _t = await _sections(client, h, pid)
order_before = [r["id"] for r in before]
choose({"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"]
assert "발행" in body["reply"] # 재발행 안내가 따라붙는다
after, _t = await _sections(client, h, pid)
assert [r["id"] for r in after] == order_before
assert next(r for r in after if r["name"] == "사진 갤러리")["enabled"] is False
async def test_꼭_있어야_하는_부분은_끌_수_없다(client, auth_headers, choose, db_engine):
"""★ 잠긴 섹션은 발행본이 어차피 켜서 내보낸다 — 끌 수 있게 두면 화면만 거짓말한다."""
h, pid = await seed(client, auth_headers)
choose({"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 True
assert "끌 수 없" in body["reply"]
after, _t = await _sections(client, h, pid)
assert next(r for r in after if r["name"] == "히어로")["enabled"] is True
async def test_순서를_옮기면_배열_순서가_바뀐다(client, auth_headers, choose, db_engine):
"""★ 배열 순서가 곧 발행본의 섹션 순서다(site_payload._sections)."""
h, pid = await seed(client, auth_headers)
choose({"tool": "move_section", "args": {"name": "사진 갤러리", "to": "맨 위"}, "message": ""})
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "사진 갤러리 맨 위로"})).json()
assert body.get("rejected") is not True, body["reply"]
after, _t = await _sections(client, h, pid)
assert after[0]["name"] == "사진 갤러리"
async def test_어느_것인지_모호하면_고르지_않는다(client, auth_headers, choose, db_engine):
"""★ 추측으로 고르면 엉뚱한 부분을 끄고, 사장님은 발행하고 나서야 안다."""
h, pid = await seed(client, auth_headers)
choose({"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 True
assert "못 찾았" in body["reply"]
async def test_색과_서체는_손대지_않는다(client, auth_headers, choose, db_engine):
"""★ sections 만 갈아끼운다 — 통째로 새로 쓰면 사장님이 고른 색이 말없이 사라진다."""
h, pid = await seed(client, auth_headers)
await client.post(f"/v1/place/{pid}/site/theme", headers=h, json={
"theme": {"colors": {"accent": "#123456"}, "fontStyle": "고딕"},
})
choose({"tool": "toggle_section", "args": {"name": "사진 갤러리", "enabled": "false"}, "message": ""})
await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "사진 갤러리 빼줘"})
_rows, theme = await _sections(client, h, pid)
assert theme["colors"]["accent"] == "#123456"
assert theme["fontStyle"] == "고딕"
def test_구성_도구의_등급(client=None):
assert tools.REGISTRY["list_sections"].grade == ToolGrade.READ
assert tools.REGISTRY["toggle_section"].grade == ToolGrade.REVERSIBLE
assert tools.REGISTRY["move_section"].grade == ToolGrade.REVERSIBLE