[feat] solution/backend: 에이전트가 사진을 내리고 대표를 지정한다
사진 쪽은 MediaService 에 list_media 하나뿐이었다 — 쓰기 경로가 아예 없었고
빌더 화면에서도 보기만 됐다. 서비스·라우터부터 열고 도구를 붙였다.
- crud: set_sort_order / service: hide_media · set_primary
- POST .../media/{id}/hide · /primary — ★ 에이전트 전용 뒷문을 만들지 않는다.
그러면 빌더 화면이 그 기능을 못 쓰고 나중에 붙일 때 로직이 두 벌이 된다
- 도구 셋: list_photos(READ) · hide_photo · set_primary_photo(REVERSIBLE)
★ 대표 사진에 별도 칸을 두지 않았다. primary_media 가 '첫 장' 을 쓰고 목록이
ORDER BY sort_order 라, 지정은 sort_order 를 가장 작게 내리는 일이다 —
칸을 따로 두면 규칙이 둘이 되어 검색 결과의 그림과 화면 첫 장이 갈린다.
★ 내려도 지우지 않는다(REJECTED). origin_url·source_type 이 남아야 재게시
권리(DECISIONS 1-2) 결론이 났을 때 되짚을 수 있다.
★★ 업로드·교체는 만들지 않았다 — 미결 사항을 코드가 먼저 푸는 자리다.
테스트가 레지스트리에 upload·replace 가 없는지 실제로 검사한다.
test_agent_runtime 32 passed(사진 6건 추가).
전체 871 passed / 53 failed — 53 은 이번 변경 전과 동일. npm run lint 통과
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ea9ae1ac2a
commit
af6e3799eb
9 files changed
+394
-6
No files matched your search
@@ -343,3 +343,123 @@ 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
|
||||
|
||||
|
||||
# ── 사진 (내리기 · 대표 지정) ────────────────────────────────────────────
|
||||
|
||||
async def _seed_photos(db_engine, place_id, rows):
|
||||
"""(label, unit_id, sort_order) 로 사진을 심는다. alt 는 채운다 — 빈 alt 는 발행본이 안 그린다."""
|
||||
from common.enums import MediaStatus, SourceType
|
||||
|
||||
async with db_engine.begin() as c:
|
||||
for label, unit_id, order in rows:
|
||||
await c.execute(
|
||||
text("""INSERT INTO place_photos
|
||||
(media_id, place_id, unit_id, url, source_type, label, alt_text, status, sort_order)
|
||||
VALUES (:m, :p, :u, :url, :st, :l, :alt, :status, :o)"""),
|
||||
{"m": uuid.uuid4(), "p": uuid.UUID(place_id), "u": unit_id,
|
||||
"url": f"https://example.com/{label}.jpg", "st": SourceType.CRAWL.value,
|
||||
"l": label, "alt": f"{label} 사진", "status": MediaStatus.APPROVED.value, "o": order},
|
||||
)
|
||||
|
||||
|
||||
async def _photo_rows(db_engine, place_id):
|
||||
async with db_engine.begin() as c:
|
||||
result = await c.execute(
|
||||
text("""SELECT label, status, sort_order FROM place_photos
|
||||
WHERE place_id=:p AND deleted=false
|
||||
ORDER BY sort_order ASC, created_at ASC"""),
|
||||
{"p": uuid.UUID(place_id)},
|
||||
)
|
||||
return result.all()
|
||||
|
||||
|
||||
async def test_사진을_내리면_지우지_않고_내려간다(client, auth_headers, choose, db_engine):
|
||||
"""★ 지우면 origin_url·source_type 이 사라져 재게시 권리 결론이 났을 때 되짚을 수 없다."""
|
||||
from common.enums import MediaStatus
|
||||
|
||||
h, pid = await seed(client, auth_headers)
|
||||
await _seed_photos(db_engine, pid, [("외관", None, 0), ("객실", None, 1)])
|
||||
|
||||
choose({"tool": "hide_photo", "args": {"name": "객실"}, "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"]
|
||||
|
||||
rows = await _photo_rows(db_engine, pid)
|
||||
hidden = next(r for r in rows if r.label == "객실")
|
||||
assert hidden.status == MediaStatus.REJECTED.value
|
||||
assert len(rows) == 2 # 행은 남는다
|
||||
|
||||
|
||||
async def test_대표_사진은_목록의_첫_장이_된다(client, auth_headers, choose, db_engine):
|
||||
"""★ 별도 칸을 두지 않는다 — site_payload.primary_media 가 '첫 장' 을 쓴다."""
|
||||
h, pid = await seed(client, auth_headers)
|
||||
await _seed_photos(db_engine, pid, [("외관", None, 0), ("수영장", None, 1)])
|
||||
|
||||
choose({"tool": "set_primary_photo", "args": {"name": "수영장"}, "message": ""})
|
||||
body = (await client.post(f"/v1/agent/chat/{pid}", headers=h, json={"message": "대표 사진 수영장으로"})).json()
|
||||
assert body.get("rejected") is not True, body["reply"]
|
||||
|
||||
rows = await _photo_rows(db_engine, pid)
|
||||
assert rows[0].label == "수영장"
|
||||
|
||||
|
||||
async def test_객실_전용_사진은_대표가_될_수_없다(client, auth_headers, choose, db_engine):
|
||||
"""★ primary_media 가 unit_id 있는 사진을 건너뛴다 — 지정하게 두면 화면만 거짓말한다."""
|
||||
h, pid = await seed(client, auth_headers)
|
||||
await _seed_photos(db_engine, pid, [("외관", None, 0), ("침대", uuid.uuid4(), 1)])
|
||||
|
||||
choose({"tool": "set_primary_photo", "args": {"name": "침대"}, "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"]
|
||||
|
||||
rows = await _photo_rows(db_engine, pid)
|
||||
assert rows[0].label == "외관"
|
||||
|
||||
|
||||
async def test_어느_사진인지_모호하면_고르지_않는다(client, auth_headers, choose, db_engine):
|
||||
h, pid = await seed(client, auth_headers)
|
||||
await _seed_photos(db_engine, pid, [("객실 A", None, 0), ("객실 B", None, 1)])
|
||||
|
||||
choose({"tool": "hide_photo", "args": {"name": "객실"}, "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"]
|
||||
|
||||
rows = await _photo_rows(db_engine, pid)
|
||||
assert all(r.status != 3 for r in rows) # 아무것도 안 내려갔다
|
||||
|
||||
|
||||
async def test_남의_가게_사진에는_닿지_못한다(client, auth_headers, db_engine):
|
||||
"""서비스가 사업장 스코프를 먼저 건다 — 없는 것과 남의 것을 똑같이 답한다."""
|
||||
from crud.media_crud import MediaCRUD
|
||||
from crud.place_crud import PlaceCRUD
|
||||
from router.v1.validator.dependencies import DecodeAccessToken
|
||||
from services.media_service import MediaService
|
||||
|
||||
h, pid = await seed(client, auth_headers, "내가게")
|
||||
await _seed_photos(db_engine, pid, [("외관", None, 0)])
|
||||
async with db_engine.begin() as c:
|
||||
media_id = (
|
||||
await c.execute(text("SELECT media_id FROM place_photos WHERE place_id=:p"), {"p": uuid.UUID(pid)})
|
||||
).scalar_one()
|
||||
|
||||
other = await auth_headers("photo-outsider")
|
||||
outsider = DecodeAccessToken(other["Authorization"].split(" ", 1)[1])
|
||||
res = await MediaService(MediaCRUD(), PlaceCRUD()).hide_media(outsider, pid, str(media_id))
|
||||
assert res.result.success is False
|
||||
|
||||
rows = await _photo_rows(db_engine, pid)
|
||||
assert rows[0].status != 3
|
||||
|
||||
|
||||
async def test_업로드_도구는_만들지_않았다():
|
||||
"""★ 이미지 재게시 권리가 미결이라 저장 경로를 일부러 안 만들어 뒀다(DECISIONS 1-2·5-3).
|
||||
도구가 생기면 그 결정을 코드가 먼저 풀어 버린다."""
|
||||
names = set(tools.REGISTRY)
|
||||
assert not {n for n in names if "upload" in n or "replace" in n}
|
||||
assert tools.REGISTRY["list_photos"].grade == ToolGrade.READ
|
||||
assert tools.REGISTRY["hide_photo"].grade == ToolGrade.REVERSIBLE
|
||||
assert tools.REGISTRY["set_primary_photo"].grade == ToolGrade.REVERSIBLE
|
||||
Reference in new issue
Block a user