세션 평가·라이브코치·교수자 분석 라운드 마감 + 문서 정리 + 코드품질 리팩터
- 누적 작업트리 커밋: 회기 평가 복구·durable 저장, 라이브 코치 이력/근거, 교수자 학생분석, 음성 비언어 메타, PII 마스킹, 운영 티켓/헬스 등 - 문서: 완료 기록 docs/archive/ 냉동 보관, docs/ 단일 인덱스(docs/README.md)+통합 TODO(docs/TODO.md)로 정리 - 리팩터(행위 보존): Stage enum SSOT(taxonomy 소유·state_machine re-export), store recent/masked_turns 중복 제거, speaker_ko_label 단일 헬퍼, _list_sessions N+1 제거(state/turns 배치 + 턴평가 하이드레이션 배치) - 검증: 백엔드 pytest 352 passed, _list_sessions E2E chromium-single-run 2 passed
This commit is contained in:
parent
7c41c3ce79
commit
778e8526d4
108 changed files with 6457 additions and 455 deletions
103
apps/api/app/test_live_coach_privacy.py
Normal file
103
apps/api/app/test_live_coach_privacy.py
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
import unittest
|
||||
|
||||
from . import turn_runtime
|
||||
from .services import guardrail, live_coach
|
||||
from .services import state_machine
|
||||
|
||||
|
||||
class LiveCoachPromptPrivacyTest(unittest.TestCase):
|
||||
def tearDown(self) -> None:
|
||||
guardrail.set_ko_pii_recognizer(None)
|
||||
|
||||
def test_messages_remask_recent_turns_and_evaluation_payload(self) -> None:
|
||||
class FakeKoRecognizer:
|
||||
def analyze(self, text: str):
|
||||
spans = []
|
||||
for entity_type, value in (
|
||||
("NAME", "보라별"),
|
||||
("ORG", "미래학교상담연구랩"),
|
||||
):
|
||||
start = text.find(value)
|
||||
if start >= 0:
|
||||
spans.append(guardrail.PiiEntitySpan(entity_type, start, start + len(value)))
|
||||
return spans
|
||||
|
||||
guardrail.set_ko_pii_recognizer(FakeKoRecognizer())
|
||||
item = live_coach.LiveCoachInput(
|
||||
session_id="privacy-live-coach",
|
||||
turn_seq=3,
|
||||
stage="exploration",
|
||||
effective_openness=0.42,
|
||||
theory_mode="humanistic",
|
||||
persona_code="P1",
|
||||
persona_name="서연",
|
||||
learner_text="별명은 보라별이고 기관은 미래학교상담연구랩입니다.",
|
||||
client_reply="전화는 010-1234-5678입니다.",
|
||||
recent_turns=[
|
||||
{
|
||||
"speaker": "counselor",
|
||||
"text": "보라별이 미래학교상담연구랩에서 힘들다고 했죠.",
|
||||
},
|
||||
{
|
||||
"speaker": "client",
|
||||
"text": "010-1234-5678로 연락하지 말아주세요.",
|
||||
},
|
||||
],
|
||||
evaluation={
|
||||
"appropriateness": "warn",
|
||||
"appropriateness_note": "보라별 연락처 010-1234-5678을 되물었다.",
|
||||
"nested": {"rationale": "기관 미래학교상담연구랩 언급"},
|
||||
},
|
||||
)
|
||||
|
||||
messages = live_coach._messages(item, [])
|
||||
user_prompt = messages[1].content
|
||||
|
||||
for raw in ("보라별", "미래학교상담연구랩", "010-1234-5678"):
|
||||
self.assertNotIn(raw, user_prompt)
|
||||
for masked in ("[NAME]", "[ORG]", "[PHONE]"):
|
||||
self.assertIn(masked, user_prompt)
|
||||
|
||||
|
||||
class LiveCoachQuotaRechargeTest(unittest.TestCase):
|
||||
def test_recharge_requires_positive_score_and_client_change(self) -> None:
|
||||
before = state_machine.SessionState(
|
||||
stage=state_machine.Stage.RAPPORT,
|
||||
turn_seq=2,
|
||||
effective_openness=0.15,
|
||||
)
|
||||
after = state_machine.SessionState(
|
||||
stage=state_machine.Stage.RAPPORT,
|
||||
turn_seq=3,
|
||||
effective_openness=0.19,
|
||||
)
|
||||
|
||||
should_recharge, reason = turn_runtime.should_recharge_live_coach_credit(
|
||||
{"appropriateness": "pos", "rapport_signal": 0.45},
|
||||
before,
|
||||
after,
|
||||
)
|
||||
self.assertTrue(should_recharge)
|
||||
self.assertIn("개방도", reason)
|
||||
|
||||
should_recharge, _ = turn_runtime.should_recharge_live_coach_credit(
|
||||
{"appropriateness": "pos", "rapport_signal": 0.45},
|
||||
before,
|
||||
state_machine.SessionState(
|
||||
stage=state_machine.Stage.RAPPORT,
|
||||
turn_seq=3,
|
||||
effective_openness=0.16,
|
||||
),
|
||||
)
|
||||
self.assertFalse(should_recharge)
|
||||
|
||||
should_recharge, _ = turn_runtime.should_recharge_live_coach_credit(
|
||||
{"appropriateness": "neutral", "rapport_signal": 0.8},
|
||||
before,
|
||||
after,
|
||||
)
|
||||
self.assertFalse(should_recharge)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue