Spaces:
Sleeping
Sleeping
| 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."] | |