Repository navigation
Expand file tree
/
Copy pathtest_config.py
More file actions
49 lines (39 loc) · 1.83 KB
/
Copy pathtest_config.py
File metadata and controls
49 lines (39 loc) · 1.83 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
49
from __future__ import annotations
from pathlib import Path
import re
import unittest
REPO = Path(__file__).resolve().parents[1]
def restore_settings(path: Path) -> dict[str, object]:
text = path.read_text(encoding="utf-8")
modes = re.findall(r"(?m)^session_restore_mode\s*=\s*(.+?)\s*$", text)
if len(modes) != 1:
raise ValueError(f"{path}: expected one session_restore_mode assignment")
values: dict[str, object] = {"mode": modes[0]}
for name, pattern in {
"output_spool_lines": r"(?m)^output_spool_lines\s*=\s*([0-9]+)\s*$",
"vt100_output_spool_width": (
r"(?m)^vt100_output_spool_width\s*=\s*([0-9]+)\s*$"
),
}.items():
matches = re.findall(pattern, text)
if len(matches) != 1:
raise ValueError(f"{path}: expected one {name} assignment")
values[name] = int(matches[0])
return values
class ShpoolExampleConfigTests(unittest.TestCase):
def test_simple_restore_contract(self) -> None:
"""Reattach must never replay spooled TUI frames.
Replaying the vt100 spool interleaves cells from different frames of
a cell-diffing TUI (Claude Code, Codex) — the braided corruption seen
live on 2026-08-12. "simple" emits nothing and lets the program
redraw itself; clean reading lives in `sp history`. The spool bounds
stay finite so daemon memory is bounded.
"""
for relative in ("config/shpool.example.toml", "shpool/config.toml"):
with self.subTest(relative=relative):
config = restore_settings(REPO / relative)
self.assertEqual('"simple"', config["mode"])
self.assertEqual(1000, config["output_spool_lines"])
self.assertEqual(200, config["vt100_output_spool_width"])
if __name__ == "__main__":
unittest.main()