test(emotion-e3): add deterministic replay matrix
这个提交存在于:
父节点
3c72be6800
当前提交
e9872cc4dd
共有 2 个文件被更改,包括 96 次插入 和 0 次删除
58
tests/emotion_eval_cases.py
普通文件
58
tests/emotion_eval_cases.py
普通文件
|
|
@ -0,0 +1,58 @@
|
|||
"""Deterministic synthetic emotion-evaluation matrix shared by both repositories."""
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
|
||||
EMOTION_EVAL_SCHEMA_VERSION = "emotion_eval_case.v1"
|
||||
EVENT_TEMPLATES = (
|
||||
{"key": "hurt", "event_type": "hurt", "intensity": 90, "confidence": 0.92, "target": "bot"},
|
||||
{"key": "apology", "event_type": "apology", "intensity": 68, "confidence": 0.86, "target": "bot"},
|
||||
{"key": "comfort", "event_type": "comfort", "intensity": 48, "confidence": 0.82, "target": "bot"},
|
||||
{"key": "praise", "event_type": "praise", "intensity": 38, "confidence": 0.78, "target": "bot"},
|
||||
{"key": "self_low", "event_type": "comfort_need", "intensity": 62, "confidence": 0.88, "target": "self"},
|
||||
{"key": "third_party", "event_type": "external_negative", "intensity": 54, "confidence": 0.80, "target": "other"},
|
||||
{"key": "play", "event_type": "play", "intensity": 35, "confidence": 0.75, "target": "bot"},
|
||||
{"key": "intimacy", "event_type": "intimacy", "intensity": 55, "confidence": 0.80, "target": "bot"},
|
||||
{"key": "boundary", "event_type": "boundary", "intensity": 80, "confidence": 0.90, "target": "bot"},
|
||||
{"key": "neutral", "event_type": "neutral", "intensity": 0, "confidence": 0.95, "target": "none"},
|
||||
)
|
||||
STATE_VARIANTS = (
|
||||
{"key": "friend_normal", "role": "friend", "mode": "normal", "score": 100, "energy": 70, "mood": "平稳", "busy": False, "boundary": False},
|
||||
{"key": "friend_tired", "role": "friend", "mode": "normal", "score": 300, "energy": 20, "mood": "疲惫", "busy": False, "boundary": False},
|
||||
{"key": "friend_close", "role": "friend", "mode": "normal", "score": 800, "energy": 75, "mood": "轻快", "busy": False, "boundary": False},
|
||||
{"key": "owner", "role": "owner", "mode": "owner_exclusive", "score": 1200, "energy": 80, "mood": "温柔", "busy": False, "boundary": False},
|
||||
{"key": "contact_boundary", "role": "friend", "mode": "normal", "score": 600, "energy": 70, "mood": "平稳", "busy": False, "boundary": True},
|
||||
{"key": "busy", "role": "friend", "mode": "normal", "score": 600, "energy": 65, "mood": "平稳", "busy": True, "boundary": False},
|
||||
)
|
||||
|
||||
|
||||
def build_emotion_eval_cases() -> list[dict[str, Any]]:
|
||||
cases: list[dict[str, Any]] = []
|
||||
for event in EVENT_TEMPLATES:
|
||||
for state in STATE_VARIANTS:
|
||||
cases.append({
|
||||
"schema_version": EMOTION_EVAL_SCHEMA_VERSION,
|
||||
"case_id": f"{event['key']}__{state['key']}",
|
||||
"event": dict(event),
|
||||
"state": dict(state),
|
||||
"clock": "2026-08-04T12:00:00+08:00",
|
||||
})
|
||||
return cases
|
||||
|
||||
|
||||
def emotion_eval_fingerprint() -> str:
|
||||
payload = json.dumps(build_emotion_eval_cases(), ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
||||
return hashlib.sha256(payload.encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
__all__ = [
|
||||
"EMOTION_EVAL_SCHEMA_VERSION",
|
||||
"EVENT_TEMPLATES",
|
||||
"STATE_VARIANTS",
|
||||
"build_emotion_eval_cases",
|
||||
"emotion_eval_fingerprint",
|
||||
]
|
||||
|
||||
38
tests/test_emotion_e3_replay.py
普通文件
38
tests/test_emotion_e3_replay.py
普通文件
|
|
@ -0,0 +1,38 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from core.emotion_event_contract import normalize_emotion_event # noqa: E402
|
||||
from tests.emotion_eval_cases import build_emotion_eval_cases, emotion_eval_fingerprint # noqa: E402
|
||||
|
||||
|
||||
class EmotionE3ReplayTests(unittest.TestCase):
|
||||
def test_sixty_case_matrix_normalizes_identically(self) -> None:
|
||||
cases = build_emotion_eval_cases()
|
||||
self.assertEqual(60, len(cases))
|
||||
self.assertEqual(emotion_eval_fingerprint(), emotion_eval_fingerprint())
|
||||
ids: set[str] = set()
|
||||
for case in cases:
|
||||
source = case["event"]
|
||||
event = normalize_emotion_event({
|
||||
"event_type": source["event_type"],
|
||||
"intensity": source["intensity"],
|
||||
"confidence": source["confidence"],
|
||||
"session_id": "qq:FriendMessage:u1",
|
||||
"dedupe_key": case["case_id"],
|
||||
"occurred_at": case["clock"],
|
||||
}, producer_plugin="emotion_eval")
|
||||
self.assertNotIn(event["event_id"], ids)
|
||||
ids.add(event["event_id"])
|
||||
self.assertEqual(source["event_type"], event["event_type"])
|
||||
self.assertEqual(source["intensity"], event["intensity"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
正在加载…
添加表格
在新工单中引用