2026-09-14 16:29:25 +08:00
|
|
|
"""Tests for EOT/INT DeepSeek suggestion validation without network calls."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import unittest
|
2026-09-14 18:43:58 +08:00
|
|
|
from pathlib import Path
|
|
|
|
|
import json
|
|
|
|
|
import tempfile
|
2026-09-14 16:29:25 +08:00
|
|
|
|
2026-09-14 18:43:58 +08:00
|
|
|
from adjudicate_easycom_eot_int_candidates import (
|
2026-09-14 23:04:21 +08:00
|
|
|
PROMPT_VERSION, SYSTEM_PROMPT, _progress_line, _transport_rows, build_user_prompt, read_candidates,
|
|
|
|
|
requires_semantic_adjudication, validate_decisions,
|
2026-09-14 18:43:58 +08:00
|
|
|
)
|
2026-09-14 16:29:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class EOTINTAdjudicationTests(unittest.TestCase):
|
2026-09-14 23:04:21 +08:00
|
|
|
def test_progress_line_reports_items_percent_pass_and_elapsed_time(self) -> None:
|
|
|
|
|
line = _progress_line(25, 100, label="pass 1/2 · batch 4/13", elapsed_seconds=65)
|
|
|
|
|
self.assertIn("25/100 ( 25.0%)", line)
|
|
|
|
|
self.assertIn("pass 1/2 · batch 4/13", line)
|
|
|
|
|
self.assertTrue(line.endswith("01:05"))
|
|
|
|
|
|
2026-09-14 16:29:25 +08:00
|
|
|
def test_prompt_contains_task_and_context(self) -> None:
|
|
|
|
|
prompt = build_user_prompt(
|
2026-09-14 18:43:58 +08:00
|
|
|
[{"uid": "u1", "candidate_source": "WEARER_ONSET", "task": "eot_response",
|
|
|
|
|
"temporal_evidence": {"wearer_duration": 2.0},
|
|
|
|
|
"context": [{"transcription": "Yes."}]}],
|
2026-09-14 16:29:25 +08:00
|
|
|
0,
|
|
|
|
|
)
|
2026-09-14 18:43:58 +08:00
|
|
|
self.assertIn("WEARER_ONSET", prompt)
|
|
|
|
|
self.assertIn("wearer_duration", prompt)
|
2026-09-14 16:29:25 +08:00
|
|
|
self.assertIn("Yes.", prompt)
|
|
|
|
|
|
2026-09-14 23:04:21 +08:00
|
|
|
def test_system_prompt_treats_laughter_as_nonlexical_floor_feedback(self) -> None:
|
|
|
|
|
self.assertEqual(PROMPT_VERSION, "easycom-wearer-centric-eot-int-prelabel-v6")
|
|
|
|
|
self.assertIn("two immutable anchors", SYSTEM_PROMPT)
|
|
|
|
|
self.assertIn("t_w < t_o < t_y", SYSTEM_PROMPT)
|
|
|
|
|
self.assertIn("a transcription consisting of [L] denotes laughter-only vocalization", SYSTEM_PROMPT)
|
|
|
|
|
self.assertIn("EOT_WEARER_BACKCHANNEL", SYSTEM_PROMPT)
|
|
|
|
|
self.assertIn("INT_OTHER_BACKCHANNEL", SYSTEM_PROMPT)
|
|
|
|
|
self.assertIn("do not infer that a visible smile occurred", SYSTEM_PROMPT)
|
|
|
|
|
self.assertNotIn('"needs_human_review"', SYSTEM_PROMPT)
|
|
|
|
|
|
2026-09-14 16:29:25 +08:00
|
|
|
def test_decisions_require_exact_uid_and_vocabulary(self) -> None:
|
|
|
|
|
payload = {
|
|
|
|
|
"items": [
|
|
|
|
|
{
|
|
|
|
|
"uid": "u1",
|
2026-09-14 18:43:58 +08:00
|
|
|
"verdict": "HARD_NEGATIVE",
|
|
|
|
|
"event_type": None,
|
|
|
|
|
"subtype": "INT_OTHER_BACKCHANNEL",
|
|
|
|
|
"confidence": 0.91,
|
|
|
|
|
"reason": "Brief feedback while the wearer continues.",
|
|
|
|
|
"needs_human_review": False,
|
2026-09-14 16:29:25 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
decisions = validate_decisions(payload, ["u1"])
|
2026-09-14 18:43:58 +08:00
|
|
|
self.assertEqual(decisions[0]["subtype"], "INT_OTHER_BACKCHANNEL")
|
2026-09-14 23:04:21 +08:00
|
|
|
self.assertTrue(decisions[0]["needs_human_review"])
|
2026-09-14 16:29:25 +08:00
|
|
|
with self.assertRaisesRegex(ValueError, "mismatch"):
|
|
|
|
|
validate_decisions({"items": []}, ["u1"])
|
|
|
|
|
|
2026-09-14 23:04:21 +08:00
|
|
|
def test_model_needs_human_review_type_drift_is_ignored(self) -> None:
|
|
|
|
|
payload = {
|
|
|
|
|
"items": [{
|
|
|
|
|
"uid": "u1", "verdict": "UNSURE", "event_type": None,
|
|
|
|
|
"subtype": None, "confidence": 0.4, "reason": "Ambiguous context.",
|
|
|
|
|
"needs_human_review": "true",
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
decision = validate_decisions(payload, ["u1"])[0]
|
|
|
|
|
self.assertTrue(decision["needs_human_review"])
|
|
|
|
|
|
2026-09-14 18:43:58 +08:00
|
|
|
def test_markdown_escaped_uid_is_normalized_but_still_unique(self) -> None:
|
|
|
|
|
item = {
|
|
|
|
|
"uid": "Session\\_4/wearer\\_onset/00000024",
|
|
|
|
|
"verdict": "POSITIVE",
|
|
|
|
|
"event_type": "EOT_RESPONSE",
|
|
|
|
|
"subtype": None,
|
|
|
|
|
"confidence": 0.9,
|
|
|
|
|
"reason": "Sustained wearer response after the other speaker stops.",
|
|
|
|
|
"needs_human_review": False,
|
|
|
|
|
}
|
|
|
|
|
expected = "Session_4/wearer_onset/00000024"
|
|
|
|
|
decision = validate_decisions({"items": [item]}, [expected])[0]
|
|
|
|
|
self.assertEqual(decision["uid"], expected)
|
|
|
|
|
with self.assertRaisesRegex(ValueError, "duplicate"):
|
|
|
|
|
validate_decisions({"items": [item, {**item, "uid": expected}]}, [expected])
|
|
|
|
|
|
|
|
|
|
def test_duplicate_rule_uids_are_disambiguated_with_provenance(self) -> None:
|
|
|
|
|
with tempfile.TemporaryDirectory() as temporary:
|
|
|
|
|
path = Path(temporary) / "candidates.jsonl"
|
|
|
|
|
base = {"uid": "Session_4/other_to_other/00003600", "task": "eot_response"}
|
|
|
|
|
rows = [
|
|
|
|
|
{**base, "previous_other_participant_ids": [6], "incoming_other_participant_ids": [4]},
|
|
|
|
|
{**base, "previous_other_participant_ids": [3], "incoming_other_participant_ids": [6]},
|
|
|
|
|
]
|
|
|
|
|
path.write_text("".join(json.dumps(row) + "\n" for row in rows), encoding="utf-8")
|
|
|
|
|
loaded = read_candidates(path)
|
|
|
|
|
self.assertEqual(len({row["uid"] for row in loaded}), 2)
|
|
|
|
|
self.assertTrue(all(row["uid_disambiguated_from"] == base["uid"] for row in loaded))
|
|
|
|
|
|
|
|
|
|
def test_transport_ids_are_short_unique_and_reversible(self) -> None:
|
|
|
|
|
rows = [{"uid": "Session_4/other_to_other/00003600/a"},
|
|
|
|
|
{"uid": "Session_4/other_to_other/00003600/b"}]
|
|
|
|
|
transported, mapping = _transport_rows(rows)
|
|
|
|
|
self.assertEqual([row["uid"] for row in transported], ["item-0000", "item-0001"])
|
|
|
|
|
self.assertEqual(mapping["item-0001"], rows[1]["uid"])
|
|
|
|
|
|
2026-09-14 23:04:21 +08:00
|
|
|
def test_old_nonoverlap_wearer_offset_is_not_sent_for_adjudication(self) -> None:
|
|
|
|
|
control = {
|
|
|
|
|
"candidate_source": "WEARER_OFFSET",
|
|
|
|
|
"temporal_evidence": {
|
|
|
|
|
"active_other_ids_before_offset": [],
|
|
|
|
|
"active_other_ids_after_offset": [],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
crossing = {
|
|
|
|
|
"candidate_source": "WEARER_OFFSET",
|
|
|
|
|
"temporal_evidence": {
|
|
|
|
|
"active_other_ids_before_offset": [4],
|
|
|
|
|
"active_other_ids_after_offset": [4],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
speaker_change = {
|
|
|
|
|
"candidate_source": "WEARER_OFFSET",
|
|
|
|
|
"temporal_evidence": {
|
|
|
|
|
"active_other_ids_before_offset": [3],
|
|
|
|
|
"active_other_ids_after_offset": [4],
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
self.assertFalse(requires_semantic_adjudication(control))
|
|
|
|
|
self.assertTrue(requires_semantic_adjudication(crossing))
|
|
|
|
|
self.assertFalse(requires_semantic_adjudication(speaker_change))
|
|
|
|
|
self.assertFalse(requires_semantic_adjudication({"candidate_source": "WEARER_OFFSET_CONTROL"}))
|
|
|
|
|
self.assertFalse(requires_semantic_adjudication({"candidate_source": "WEARER_ONSET_CONTROL"}))
|
|
|
|
|
self.assertFalse(requires_semantic_adjudication({"candidate_source": "WEARER_RESUME"}))
|
|
|
|
|
|
2026-09-14 16:29:25 +08:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|