- GET /v1/nego/cards: 일반 카드 9종(정본 nego_card.json) + 와일드카드 2종, 테스트 추가(15 통과)
- 엔진 판단 패널 '전체 카드' 버튼 → 모달: ID·이름·스크립트, 현재 발동 카드 하이라이트,
변수 {…} 안내, 로딩·실패 상태, X/배경/ESC 닫기
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UFZ7JWdwCaQAwNYJErL8pP
132 lines
4.7 KiB
Python
132 lines
4.7 KiB
Python
"""서버 스모크 테스트 — 엔진 기동, 고정/동적 스텝, 계측 응답."""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from router.router import app
|
|
|
|
client = TestClient(app)
|
|
|
|
# 04 bench와 동일 형태의 가격협상 진입 요청
|
|
HEAVY_BODY = {
|
|
"rq_type": "재협상", "session_id": "TEST-01", "step": "가격협상_확인", "index": 5,
|
|
"user_input": "예", "item_price": 163600, "revenue": 163600, "dist": "R",
|
|
"partners_yn": "없음", "partners": 0, "anchor": 8099, "target": 8180,
|
|
"initial": 9000, "input": 9000, "iteration": 0, "is_new_quote": True,
|
|
"profiling": False,
|
|
}
|
|
|
|
|
|
def test_health():
|
|
res = client.get("/health")
|
|
assert res.status_code == 200
|
|
assert res.json()["status"] == "OK"
|
|
|
|
|
|
def test_config_endpoint():
|
|
res = client.get("/v1/nego/config")
|
|
assert res.status_code == 200
|
|
body = res.json()
|
|
assert body["server"] == "NEGO_AGENT"
|
|
assert body["cards"] > 0
|
|
|
|
|
|
def test_fixed_step_start():
|
|
res = client.post("/v1/nego/chat", json={
|
|
"rq_type": "재협상", "session_id": "TEST-00", "step": "시작", "index": 0,
|
|
})
|
|
assert res.status_code == 200
|
|
body = res.json()
|
|
assert body["step"] == "서비스안내"
|
|
assert body["script"]
|
|
# KT 지칭이 응답에 없어야 한다
|
|
assert "kt" not in body["script"].lower()
|
|
|
|
|
|
def test_dynamic_step_price_negotiation():
|
|
"""가격협상_확인 [예] + 입력가 ≤ 앵커 → 와일드카드(1% 추가 네고) 진입."""
|
|
body = dict(HEAVY_BODY, user_input="8000", step="가격협상_재입력", index=4)
|
|
res = client.post("/v1/nego/chat", json=body)
|
|
assert res.status_code == 200
|
|
assert res.json()["step"] == "가격협상_확인"
|
|
|
|
res2 = client.post("/v1/nego/chat", json=dict(HEAVY_BODY, input=8000))
|
|
assert res2.status_code == 200
|
|
out = res2.json()
|
|
# 입력가(8000) ≤ 앵커(8099) + 유형 A → wild_card_1pct 스텝으로 전이
|
|
assert out["step"] == "wild_card_1pct"
|
|
assert out["script"]
|
|
|
|
|
|
def test_dynamic_step_card_selection():
|
|
"""입력가 > 앵커 상태의 가격협상_확인 [예] → '가격협상' 동적 스텝 — 카드 선택 + 지표 계산."""
|
|
res = client.post("/v1/nego/chat", json=HEAVY_BODY)
|
|
assert res.status_code == 200
|
|
out = res.json()
|
|
assert out["chat_metadata"]["card_id"]
|
|
assert out["script"]
|
|
assert out["chat_metadata"]["indicator_value"] is not None
|
|
|
|
|
|
def test_response_time_header():
|
|
res = client.get("/health")
|
|
assert "x-response-time-ms" in res.headers
|
|
|
|
|
|
def test_cards_are_plain_text():
|
|
"""카드 정본은 평문 script만 갖는다 — Slate(editor_script)·KT 종속 변수 없음."""
|
|
import json
|
|
from common.paths import RESOURCES_DIR
|
|
|
|
nego = json.load(open(RESOURCES_DIR / "cards" / "nego_card.json", encoding="utf-8"))
|
|
for card in nego["cards"]:
|
|
assert set(card.keys()) == {"card_id", "card_name", "script"}
|
|
assert "dss_count" not in card["script"]
|
|
assert "kt" not in card["script"].lower()
|
|
assert "그룹사" not in card["script"]
|
|
|
|
wild = json.load(open(RESOURCES_DIR / "cards" / "wild_card.json", encoding="utf-8"))
|
|
for config in wild.values():
|
|
assert "editor_script" not in config
|
|
|
|
|
|
def test_card_variable_substitution_and_hidden():
|
|
"""card_data 값은 치환되고, 값이 없는 변수 문장은 숨겨진다."""
|
|
from services.cards.completer import CardScriptCompleter
|
|
from services.cards.repository import CardScriptRepository
|
|
from router.v1.nego.protocol import NegotiationCardData
|
|
|
|
completer = CardScriptCompleter(CardScriptRepository())
|
|
|
|
# 값이 있으면 치환
|
|
out = completer.execute("NC26-007", NegotiationCardData(payment_terms="입고 후 30일 이내 현금 지급"))
|
|
assert "입고 후 30일 이내 현금 지급" in out
|
|
assert "{payment_terms}" not in out
|
|
|
|
# 값이 없으면 해당 문장 Hidden — 나머지 문장은 유지
|
|
out2 = completer.execute("NC26-007", None)
|
|
assert "payment_terms" not in out2
|
|
assert "공급 가능한 가격" in out2
|
|
|
|
|
|
def test_session_invalidate():
|
|
res = client.post("/v1/nego/session/invalidate",
|
|
json={"session_id": "TEST-01", "reason": "테스트"})
|
|
assert res.status_code == 200
|
|
assert res.json()["status"] == "ok"
|
|
|
|
|
|
def test_cards_endpoint():
|
|
"""카드 목록 — 데모 카드 팝업용. 일반 9종 + 와일드 2종, 이름 필수."""
|
|
res = client.get("/v1/nego/cards")
|
|
assert res.status_code == 200
|
|
body = res.json()
|
|
assert len(body["cards"]) == 9
|
|
assert all(c["card_id"] and c["card_name"] and c["script"] for c in body["cards"])
|
|
assert {w["card_id"] for w in body["wild_cards"]} == {"wild_card_1pct", "wild_card_budget"}
|