forked from SeemSeam/claude_codex_bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_session_utils.py
More file actions
48 lines (34 loc) · 1.52 KB
/
test_session_utils.py
File metadata and controls
48 lines (34 loc) · 1.52 KB
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
from __future__ import annotations
from pathlib import Path
from session_utils import find_project_session_file, safe_write_session
def test_find_project_session_file_walks_upward(tmp_path: Path) -> None:
root = tmp_path / "repo"
leaf = root / "a" / "b" / "c"
leaf.mkdir(parents=True)
session = root / ".codex-session"
session.write_text("{}", encoding="utf-8")
found = find_project_session_file(leaf, ".codex-session")
assert found == session
assert find_project_session_file(root, ".codex-session") == session
def test_find_project_session_file_prefers_ccb_config(tmp_path: Path) -> None:
root = tmp_path / "repo"
root.mkdir(parents=True)
cfg = root / ".ccb"
cfg.mkdir(parents=True)
primary = cfg / ".codex-session"
primary.write_text("{}", encoding="utf-8")
legacy = root / ".codex-session"
legacy.write_text("{}", encoding="utf-8")
assert find_project_session_file(root, ".codex-session") == primary
def test_safe_write_session_atomic_write(tmp_path: Path) -> None:
target = tmp_path / "state.json"
ok, err = safe_write_session(target, '{"hello":"world"}\n')
assert ok is True
assert err is None
assert target.read_text(encoding="utf-8") == '{"hello":"world"}\n'
assert not target.with_suffix(".tmp").exists()
ok2, err2 = safe_write_session(target, '{"hello":"again"}\n')
assert ok2 is True
assert err2 is None
assert target.read_text(encoding="utf-8") == '{"hello":"again"}\n'
assert not target.with_suffix(".tmp").exists()