headroom/tests/test_ccr_mcp_server.py
JerrettDavis 5884f7fb41 fix: restore Windows mypy compatibility
Make Unix-only file locking imports type-safe on Windows, tighten beacon lock cleanup, and fix the remaining exposed typing issues so the repository's mypy check passes cleanly on Windows again.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-11 18:40:53 -05:00

24 lines
1,005 B
Python

from __future__ import annotations
import json
from headroom.ccr import mcp_server
def test_shared_stats_work_without_fcntl(monkeypatch, tmp_path) -> None:
monkeypatch.setattr(mcp_server, "_HAS_FCNTL", False)
monkeypatch.setattr(mcp_server, "fcntl", None)
monkeypatch.setattr(mcp_server, "SHARED_STATS_DIR", tmp_path)
monkeypatch.setattr(mcp_server, "SHARED_STATS_FILE", tmp_path / "session_stats.jsonl")
monkeypatch.setattr(mcp_server.os, "getpid", lambda: 4242)
monkeypatch.setattr(mcp_server.time, "time", lambda: 1001.0)
event = {"type": "compress", "timestamp": 1000.0}
mcp_server._append_shared_event(event)
raw_lines = mcp_server.SHARED_STATS_FILE.read_text(encoding="utf-8").splitlines()
assert len(raw_lines) == 1
assert json.loads(raw_lines[0]) == {"type": "compress", "timestamp": 1000.0, "pid": 4242}
events = mcp_server._read_shared_events(window_seconds=60)
assert events == [{"type": "compress", "timestamp": 1000.0, "pid": 4242}]