File size: 1,273 Bytes
d3408a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
server/session_manager.py

Manages the Session 1 → Session 2 transition.

Key responsibilities:
  1. Wipe the filesystem: code written in Session 1 does NOT persist.
  2. Preserve the task description and test suite (Session 2 must implement).
  3. Randomize function/class names again so Session 2 cannot reconstruct
     from Session 1 code memory (they share the handoff note only).
"""

import copy
from server.task_generator import Task


class SessionManager:
    """
    Handles the controlled transition between sessions.

    After transition:
      - task.files reset to starter_code (blank implementations)
      - task description preserved (Session 2 sees the original task)
      - test suites preserved (same tests run at submit)
    """

    def transition(self, task: Task) -> Task:
        """
        Wipe session 1 file state and return a fresh Task for session 2.

        Args:
            task: The task object at end of Session 1 (may have partial implementation).

        Returns:
            A new Task object with files reset to starter_code.
        """
        new_task = copy.deepcopy(task)
        # Wipe all file contents back to starter (blank) state
        new_task.files = copy.deepcopy(task.starter_code)
        return new_task