File size: 1,995 Bytes
2e818da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import uuid

from app.services import student_interaction_log


def test_append_student_interaction_returns_populated_record(tmp_path, monkeypatch):
    monkeypatch.setattr(student_interaction_log, "_ROOT", tmp_path)

    interaction = student_interaction_log.append_student_interaction(
        project_id="project-a", source="chat_turn", agent_id="tutor", text="Call me Anshuman.",
    )

    assert interaction.actor == "student"
    assert interaction.text == "Call me Anshuman."
    uuid.UUID(interaction.interaction_id)  # does not raise


def test_read_pending_returns_appended_interactions(tmp_path, monkeypatch):
    monkeypatch.setattr(student_interaction_log, "_ROOT", tmp_path)

    student_interaction_log.append_student_interaction(
        project_id="project-a", source="chat_turn", agent_id="tutor", text="First message.",
    )
    student_interaction_log.append_student_interaction(
        project_id="project-a", source="chat_turn", agent_id="tutor", text="Second message.",
    )

    interactions, from_offset, through_offset = student_interaction_log.read_pending("project-a")

    assert [i.text for i in interactions] == ["First message.", "Second message."]
    assert from_offset == 0
    assert through_offset > 0


def test_advance_cursor_excludes_reviewed_interactions(tmp_path, monkeypatch):
    monkeypatch.setattr(student_interaction_log, "_ROOT", tmp_path)

    student_interaction_log.append_student_interaction(
        project_id="project-a", source="chat_turn", agent_id="tutor", text="First message.",
    )
    _, _, through_offset = student_interaction_log.read_pending("project-a")
    student_interaction_log.advance_cursor("project-a", through_offset)

    student_interaction_log.append_student_interaction(
        project_id="project-a", source="chat_turn", agent_id="tutor", text="Second message.",
    )
    interactions, _, _ = student_interaction_log.read_pending("project-a")

    assert [i.text for i in interactions] == ["Second message."]