Cyberpunk 2077 look for the server view, refreshed every second

Rajdhani font (OFL), chamfered/glitch drawing kit, Docker list every 5 s and process
ranking over 3 s windows so the 1 s refresh stays cheap and calm.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Sonnet 5.5 committed 2026-10-22 14:40:06 +02:00
1 parent edba341f30
commit 5e64bfb64e
15 files changed
+524 -95

No files matched your search

+51
View File
@@ -80,12 +80,14 @@ class FakeDocker:
def __init__(self, path: str, body: bytes = b"[]", hang: bool = False):
self.release = threading.Event()
self.requests = 0
outer = self
class Handler(socketserver.StreamRequestHandler):
def handle(self):
while self.rfile.readline() not in (b"\r\n", b""):
pass
outer.requests += 1
if hang:
outer.release.wait(5)
return
@@ -111,6 +113,7 @@ def docker_in(tmp_path, monkeypatch):
def make(body=b"[]", hang=False):
s = FakeDocker("d.sock", body, hang)
servers.append(s)
make.server = s
return "d.sock"
yield make
@@ -159,6 +162,8 @@ def thermal(sys_root: Path, zones: dict[str, tuple[str, int]]):
def make_reader(tmp_path, docker_sock="missing.sock", **kw):
kw.setdefault("docker_every", 0.0)
kw.setdefault("proc_every", 0.0)
proc, sys_root = tmp_path / "proc", tmp_path / "sys"
thermal(sys_root, {"thermal_zone0": ("acpitz", 30000), "thermal_zone1": ("x86_pkg_temp", 41000)})
write_proc(proc, "cpu 100 0 50 800 50 0 0 0 0 0", {10: pid_line(10, "postgres", 0), 11: pid_line(11, "postgres", 0),
@@ -239,3 +244,49 @@ def test_reader_missing_proc_files_give_none_not_error(tmp_path):
s = reader.read()
assert (s.cpu_pct, s.mem_pct, s.disk_pct, s.load, s.temp_c, s.uptime_s, s.containers) == (None,) * 7
assert s.procs == ()
class FakeClock:
def __init__(self):
self.t = 0.0
def __call__(self):
return self.t
def test_reader_asks_docker_only_every_docker_every_seconds(tmp_path, docker_in):
sock = docker_in((FIXTURES / "docker_containers.json").read_bytes())
clock = FakeClock()
reader, _ = make_reader(tmp_path, docker_sock=sock, docker_every=5.0, clock=clock)
first = reader.read()
clock.t = 1.0
second = reader.read()
assert docker_in.server.requests == 1
assert second.containers == first.containers and second.containers is not None
clock.t = 5.5
reader.read()
assert docker_in.server.requests == 2
def test_reader_caches_a_docker_failure_for_the_interval_too(tmp_path):
clock = FakeClock()
reader, _ = make_reader(tmp_path, docker_sock=str(tmp_path / "nope.sock"), docker_every=5.0, clock=clock)
assert reader.read().containers is None
clock.t = 1.0
assert reader.read().containers is None # no new attempt, still reported as unavailable
def test_reader_ranks_processes_over_a_longer_window(tmp_path):
clock = FakeClock()
reader, proc = make_reader(tmp_path, proc_every=3.0, clock=clock)
assert reader.read().procs == () # first snapshot
clock.t = 1.0
write_proc(proc, "cpu 600 0 300 2400 100 0 0 0 0 0", {10: pid_line(10, "postgres", 10)})
assert reader.read().procs == () # window not over yet: nothing new to rank
clock.t = 3.5
write_proc(proc, "cpu 900 0 450 3600 150 0 0 0 0 0", {10: pid_line(10, "postgres", 60)})
s = reader.read()
# 60 ticks over a jiffy window of 5100 - 1000 = 4100 -> 1.46 %
assert [(p.name, round(p.cpu_pct, 2)) for p in s.procs] == [("postgres", 1.46)]
clock.t = 4.0
assert reader.read().procs == s.procs # between windows the last ranking stays on screen