Files
민헌andClaude Fable 5 dfb9ad6e66 초기 커밋 — 협상 AI 에이전트 정본: 엔진·데모 콘솔·측정 인프라·증빙
- server/: FastAPI 협상 엔진 (5라운드, Q-Table/UCB, 페르소나 계측, :53117)
- frontend/: 데모 콘솔 (React+Tailwind → nginx, /api 프록시)
- eval/·testdata/: 지표 8종 측정 하네스 + 재현 가능 테스트셋
- results/: 측정 증빙 (지표별 result+provenance, raw 원본 동결+SHA256)
  ① 86.0 · ② 76.0 · ③ 5.99% · ⑥ p95 3.61ms · ⑦ 611만/년 · ⑧ 91/100 · ⑨ 99.71 · ⑩ 97.99
- docker-compose.yml + run.sh: backend+frontend 일괄 기동

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0112XUWF4bc3gGrEt8vsYCzy
2026-08-31 13:09:52 +09:00

77 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""계측 기능 테스트 — ⑩ 긴장도·페르소나, ⑦ 계약 데이터화."""
import json
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from config.config_models import AppConfig, InstrumentConfig, ProfilingConfig
from router.v1.nego.protocol import NegotiationRequest
from services.negotiation.engine import ChatEngine
from services.negotiation.tension import estimate_tension, select_persona
SNAP = {"rq_type": "재협상", "session_id": "T-1", "index": 5, "user_input": "예",
"item_price": 163600.0, "revenue": 163600.0, "dist": "R", "partners_yn": "없음",
"partners": 0, "anchor": 8099.0, "target": 8180.0, "initial": 9000.0,
"input": 9000.0, "iteration": 0, "is_new_quote": True, "profiling": False}
def make_engine(tmp_path):
config = AppConfig(
profiling=ProfilingConfig(enabled=False),
instrument=InstrumentConfig(
tension_log=str(tmp_path / "tension.jsonl"),
response_time_log="",
contracts_log=str(tmp_path / "contracts.jsonl"),
),
)
return ChatEngine(config), tmp_path
def test_persona_bands():
assert select_persona(0.9)["name"] == "단호한 압박형"
assert select_persona(0.5)["name"] == "균형 협상형"
assert select_persona(0.1)["name"] == "우호적 마무리형"
def test_estimate_tension_zones():
# PZ1/PZ2(지표 ≥ 80) → 0, 초기제안가 = 최대 긴장 근사
assert estimate_tension(99, 8180, 9000) == 0.0
assert estimate_tension(34, 8180, 9000) > 0.5
def test_tension_log_has_persona(tmp_path):
engine, tmp = make_engine(tmp_path)
req = NegotiationRequest(**dict(SNAP, step="가격협상_확인"))
res = engine.process_request(req)
assert res.step == "가격협상"
rows = [json.loads(x) for x in (tmp / "tension.jsonl").read_text().splitlines()]
assert rows, "긴장도 로그 미기록"
row = rows[-1]
assert 0.0 <= row["predicted"] <= 1.0
assert row["persona"] in ("단호한 압박형", "균형 협상형", "우호적 마무리형")
assert isinstance(row["indicator"], int)
def test_contract_logged_on_completion(tmp_path):
engine, tmp = make_engine(tmp_path)
# 1% 와일드카드 수락 → 협상완료 (입력가 8000 ≤ 앵커 8099로 진입)
req = NegotiationRequest(**dict(SNAP, step="wild_card_1pct", user_input="예",
input=8000.0))
res = engine.process_request(req)
assert res.step == "협상완료"
rows = [json.loads(x) for x in (tmp / "contracts.jsonl").read_text().splitlines()]
assert len(rows) == 1
rec = rows[0]
assert rec["final_price"] == 7920 # 8000 × 0.99
assert rec["reduction_pct"] is not None
assert rec["rq_type"] == "재협상"
def test_contract_not_logged_midway(tmp_path):
engine, tmp = make_engine(tmp_path)
engine.process_request(NegotiationRequest(**dict(SNAP, step="시작", index=0)))
assert not (tmp / "contracts.jsonl").exists() or \
not (tmp / "contracts.jsonl").read_text().strip()