카드 재설계("멘트 카드 → 전술 카드"):
- tactics.py 신설: 카드번호→전술(카운터 산식) 레지스트리, min(counter,target) 클램프
- 카운터 수락=즉시 타결(pending_counter_price 일반화, 구 offer_1pct 흡수)
- 목표가 초과 타결 금지(성공스텝 진입 가드) + "카드 소진=실패" 폐지→종결 국면
- 선택형 와일드카드(WC-*) 발동 + card.wild_cards 멘트 DB 어댑터
LLM 계층:
- Phase 2 표현층 ScriptNaturalizer(카드 멘트 자연화, 마커·치환자·숫자 보존 검증)
- Phase 3 이해층 InputInterpreter(자유발화 NLU→기대입력, 한국어 가격 파서)
- OPENAI_API_KEY env override(server_configs) + 전역 자격증명 게이트
결정 스택(Phase 1):
- 협상 규칙 데이터화(negotiation.wildcard_*_ratio/max_counter_rounds)
- 선택카드 우선순위 prior(UCB 방문수 감쇠, Q-table 오염 없음)
버그픽스:
- 인하율 음수 표기 제거 + 인상/동일/인하 구분(discount_phrase)
- 자연화 강조마커 보존(볼드/색 소실 시 원본 폴백)
- 카드 시드 가격변수(prev_partner_price·target_mid_price·middle_price 등) 치환
정리:
- ktcommerce 테넌트 삭제 + 테스트 21파일 imarketkorea/_base 로 마이그레이션
- 실 LLM 호출 차단 conftest 가드
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
"""P0 스캐폴딩 검증 (계획서 P0 _검증_).
|
|
|
|
1. 앱이 순환 import 없이 로드된다 (`import router.router`).
|
|
2. N-profiling→profiling 개명: 정식 패키지 import 가 동작한다 (동적 import 해킹 제거).
|
|
3. 테넌트 미들웨어: 헤더 부재 시 400, 화이트리스트(healthz/health)는 통과.
|
|
"""
|
|
|
|
import importlib
|
|
|
|
import pytest
|
|
|
|
|
|
def test_app_imports_without_circular():
|
|
# 순환 import 없이 FastAPI app 로드.
|
|
mod = importlib.import_module("router.router")
|
|
assert mod.app is not None
|
|
|
|
|
|
def test_profiling_is_proper_package():
|
|
# 동적 import 해킹 없이 정식 패키지로 import 된다.
|
|
from negotiation.profiling.script_verifier import ScriptVerifier
|
|
from negotiation.profiling.config import LlmCredentials
|
|
|
|
verifier = ScriptVerifier()
|
|
original = [{"type": "p", "children": [{"text": "가격은 {price} 입니다"}]}]
|
|
# 파라미터 보존 검증: 동일 스크립트는 통과.
|
|
assert verifier.verify_script(original, original) is True
|
|
# 파라미터 누락 검증: {price} 가 사라지면 실패.
|
|
modified = [{"type": "p", "children": [{"text": "가격 안내"}]}]
|
|
assert verifier.verify_script(original, modified) is False
|
|
|
|
# config 는 toml(OpenAIConfig) 주입 구조 (.env 트리 탐색 해킹 제거).
|
|
creds = LlmCredentials.from_config()
|
|
assert isinstance(creds, LlmCredentials)
|
|
|
|
|
|
def test_no_dynamic_import_hack_in_profiling():
|
|
# script_modifier 가 _load_dynamic_module/spec_from_file_location 해킹 없이 import 된다.
|
|
import negotiation.profiling.script_modifier as sm
|
|
|
|
src = importlib.util.find_spec("negotiation.profiling.script_modifier")
|
|
assert src is not None
|
|
assert "n_profiling" not in __import__("sys").modules # 수동 등록한 가짜 패키지가 없어야 함
|
|
assert hasattr(sm, "ScriptModifier")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_healthz_and_health(client):
|
|
r = await client.get("/healthz")
|
|
assert r.status_code == 200
|
|
|
|
r = await client.get("/v1/health")
|
|
assert r.status_code == 200
|
|
assert r.json()["status"] == "ok"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_tenant_header_required(client):
|
|
# 화이트리스트가 아닌 경로는 X-Tenant-ID 부재 시 400.
|
|
r = await client.get("/v1/some-protected-path")
|
|
assert r.status_code == 400
|
|
assert r.json()["result"]["desc"] == "TENANT_HEADER_MISSING"
|
|
|
|
# 헤더가 있으면 미들웨어 통과 (라우트 미존재라 404).
|
|
r = await client.get("/v1/some-protected-path", headers={"X-Tenant-ID": "imarketkorea"})
|
|
assert r.status_code == 404
|