File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515.DS_Store
1616dist /
1717.pytest_cache /
18+ .tmp /
Original file line number Diff line number Diff line change 77import json
88import re
99import time
10+ import uuid
1011from pathlib import Path
1112
1213SESSIONS_DIR = Path .home () / ".corecoder" / "sessions"
1516
1617def _normalize_session_id (session_id : str | None ) -> str :
1718 if not session_id :
18- return f"session_ { int ( time . time ()) } "
19+ return _new_session_id ()
1920
2021 name = session_id .strip ().replace ("\\ " , "/" ).split ("/" )[- 1 ]
2122 name = _SAFE_SESSION_RE .sub ("-" , name ).strip (".-_" )
22- return name or f"session_{ int (time .time ())} "
23+ return name or _new_session_id ()
24+
25+
26+ def _new_session_id () -> str :
27+ return f"session_{ time .strftime ('%Y%m%d_%H%M%S' )} _{ uuid .uuid4 ().hex [:8 ]} "
2328
2429
2530def _session_path (session_id : str ) -> Path :
Original file line number Diff line number Diff line change 1+ from corecoder import session as session_module
2+ from corecoder .session import load_session , save_session
3+
4+
5+ def test_default_session_ids_do_not_collide (tmp_path , monkeypatch ):
6+ monkeypatch .setattr (session_module , "SESSIONS_DIR" , tmp_path )
7+
8+ first_id = save_session ([{"role" : "user" , "content" : "first" }], "model-a" )
9+ second_id = save_session ([{"role" : "user" , "content" : "second" }], "model-b" )
10+
11+ assert first_id != second_id
12+ assert load_session (first_id ) == (
13+ [{"role" : "user" , "content" : "first" }],
14+ "model-a" ,
15+ )
16+ assert load_session (second_id ) == (
17+ [{"role" : "user" , "content" : "second" }],
18+ "model-b" ,
19+ )
You can’t perform that action at this time.
0 commit comments