upload: server/session_manager.py
Browse files- server/session_manager.py +40 -0
server/session_manager.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
server/session_manager.py
|
| 3 |
+
|
| 4 |
+
Manages the Session 1 → Session 2 transition.
|
| 5 |
+
|
| 6 |
+
Key responsibilities:
|
| 7 |
+
1. Wipe the filesystem: code written in Session 1 does NOT persist.
|
| 8 |
+
2. Preserve the task description and test suite (Session 2 must implement).
|
| 9 |
+
3. Randomize function/class names again so Session 2 cannot reconstruct
|
| 10 |
+
from Session 1 code memory (they share the handoff note only).
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import copy
|
| 14 |
+
from server.task_generator import Task
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class SessionManager:
|
| 18 |
+
"""
|
| 19 |
+
Handles the controlled transition between sessions.
|
| 20 |
+
|
| 21 |
+
After transition:
|
| 22 |
+
- task.files reset to starter_code (blank implementations)
|
| 23 |
+
- task description preserved (Session 2 sees the original task)
|
| 24 |
+
- test suites preserved (same tests run at submit)
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
def transition(self, task: Task) -> Task:
|
| 28 |
+
"""
|
| 29 |
+
Wipe session 1 file state and return a fresh Task for session 2.
|
| 30 |
+
|
| 31 |
+
Args:
|
| 32 |
+
task: The task object at end of Session 1 (may have partial implementation).
|
| 33 |
+
|
| 34 |
+
Returns:
|
| 35 |
+
A new Task object with files reset to starter_code.
|
| 36 |
+
"""
|
| 37 |
+
new_task = copy.deepcopy(task)
|
| 38 |
+
# Wipe all file contents back to starter (blank) state
|
| 39 |
+
new_task.files = copy.deepcopy(task.starter_code)
|
| 40 |
+
return new_task
|