DocUA commited on
Commit
34caac9
·
1 Parent(s): ded6460

Fix conversation verification export record id

Browse files
src/interface/simplified_gradio_app.py CHANGED
@@ -880,7 +880,10 @@ Changes apply only to your current session.
880
  "start_time": verification_session.start_time.isoformat() if hasattr(verification_session, "start_time") else None,
881
  "verification_records": [
882
  {
883
- "record_id": r.record_id,
 
 
 
884
  "timestamp": r.timestamp.isoformat() if hasattr(r, "timestamp") else None,
885
  "user_message": r.user_message,
886
  "assistant_response": r.assistant_response,
@@ -2066,7 +2069,8 @@ To revert, use "Reset to Default" button.
2066
  # If we already have dicts, build a lightweight VerificationRecord
2067
  if isinstance(r, dict):
2068
  rec = VerificationRecord(
2069
- record_id=r.get("record_id", ""),
 
2070
  user_message=r.get("user_message", ""),
2071
  assistant_response=r.get("assistant_response", ""),
2072
  original_classification=r.get("original_classification", ""),
@@ -2099,7 +2103,9 @@ To revert, use "Reset to Default" button.
2099
 
2100
  records_as_dicts = [
2101
  {
2102
- "record_id": r.record_id,
 
 
2103
  "timestamp": r.timestamp,
2104
  "user_message": r.user_message,
2105
  "assistant_response": r.assistant_response,
 
880
  "start_time": verification_session.start_time.isoformat() if hasattr(verification_session, "start_time") else None,
881
  "verification_records": [
882
  {
883
+ # Conversation verification records use `exchange_id`.
884
+ # Keep a `record_id` alias for backward compatibility with older exports.
885
+ "exchange_id": getattr(r, "exchange_id", None),
886
+ "record_id": getattr(r, "exchange_id", None),
887
  "timestamp": r.timestamp.isoformat() if hasattr(r, "timestamp") else None,
888
  "user_message": r.user_message,
889
  "assistant_response": r.assistant_response,
 
2069
  # If we already have dicts, build a lightweight VerificationRecord
2070
  if isinstance(r, dict):
2071
  rec = VerificationRecord(
2072
+ exchange_id=r.get("exchange_id") or r.get("record_id", ""),
2073
+ exchange_number=r.get("exchange_number", 0),
2074
  user_message=r.get("user_message", ""),
2075
  assistant_response=r.get("assistant_response", ""),
2076
  original_classification=r.get("original_classification", ""),
 
2103
 
2104
  records_as_dicts = [
2105
  {
2106
+ "exchange_id": r.exchange_id,
2107
+ "exchange_number": r.exchange_number,
2108
+ "record_id": r.exchange_id,
2109
  "timestamp": r.timestamp,
2110
  "user_message": r.user_message,
2111
  "assistant_response": r.assistant_response,
tests/test_conversation_verification_export.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from datetime import datetime
4
+
5
+
6
+ def test_conversation_verification_export_serializes_without_record_id(tmp_path, monkeypatch):
7
+ """Regression test: conversation verification records use exchange_id, not record_id."""
8
+
9
+ # Minimal stand-in objects (match the attributes used by open_verification_window export code)
10
+ class _Record:
11
+ def __init__(self):
12
+ self.exchange_id = "sess_1"
13
+ self.exchange_number = 1
14
+ self.timestamp = datetime(2025, 12, 12, 0, 0, 0)
15
+ self.user_message = "hi"
16
+ self.assistant_response = "hello"
17
+ self.original_classification = "YELLOW"
18
+ self.original_confidence = 0.9
19
+ self.original_indicators = ["stress"]
20
+ self.original_reasoning = "reason"
21
+ self.is_correct = None
22
+ self.correct_classification = None
23
+ self.correction_reason = None
24
+ self.verifier_notes = None
25
+
26
+ class _Session:
27
+ def __init__(self):
28
+ self.session_id = "verification_test"
29
+ self.patient_name = "Test"
30
+ self.verifier_name = "Verifier"
31
+ self.start_time = datetime(2025, 12, 12, 0, 0, 0)
32
+ self.verification_records = [_Record()]
33
+
34
+ vs = _Session()
35
+
36
+ # This mirrors the payload schema in simplified_gradio_app.open_verification_window
37
+ payload = {
38
+ "session_id": vs.session_id,
39
+ "patient_name": vs.patient_name,
40
+ "verifier_name": vs.verifier_name,
41
+ "start_time": vs.start_time.isoformat(),
42
+ "verification_records": [
43
+ {
44
+ "exchange_id": getattr(r, "exchange_id", None),
45
+ "record_id": getattr(r, "exchange_id", None),
46
+ "timestamp": r.timestamp.isoformat(),
47
+ "user_message": r.user_message,
48
+ "assistant_response": r.assistant_response,
49
+ "original_classification": r.original_classification,
50
+ "original_confidence": r.original_confidence,
51
+ "original_indicators": r.original_indicators,
52
+ "original_reasoning": r.original_reasoning,
53
+ "is_correct": r.is_correct,
54
+ "correct_classification": r.correct_classification,
55
+ "correction_reason": r.correction_reason,
56
+ "verifier_notes": r.verifier_notes,
57
+ }
58
+ for r in vs.verification_records
59
+ ],
60
+ }
61
+
62
+ out = tmp_path / "export.json"
63
+ out.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
64
+
65
+ loaded = json.loads(out.read_text(encoding="utf-8"))
66
+ assert loaded["verification_records"][0]["exchange_id"] == "sess_1"
67
+ assert loaded["verification_records"][0]["record_id"] == "sess_1"