"""Local/remote pure protocol tests; no Brian, Torch, GPU or network execution. Run with the already-provisioned Python and ``-B test_protocol.py``. The sidecar process is mocked with in-memory stdin and an anonymous stdout pipe. These tests validate transport and declared arithmetic/input contracts, not the scientific trajectory or independent correctness of the Torch component. """ from __future__ import annotations import hashlib import io import json import math import os from pathlib import Path import struct import sys import threading import types import unittest from unittest import mock import numpy as np HERE = Path(__file__).resolve().parent def load_no_cache(path, name): module = types.ModuleType(name) module.__file__ = str(path) exec(compile(path.read_bytes(), str(path), "exec"), module.__dict__) return module ORACLE = load_no_cache(HERE / "oracle_apl.py", "phase4ag_protocol_oracle") def handshake(**updates): result = {"ok": True, "protocol": "phase4ag-apl-v1", "n_neurons": 166700, "n_apl": 2, "n_kc": 4064, "dt_ms": .1, "files_sha256": {name: "frozen-test-hash" for name in ORACLE.BUNDLE_FILES}, "decay_f32_bits": f"{int(np.float32(math.exp(-.1 / 20.)).view(np.uint32)):08x}", "gain_f32_bits": f"{int(np.float32(.01).view(np.uint32)):08x}"} result.update(updates) return (json.dumps(result) + "\n").encode("utf-8") def frame(tick=0, values=None, byte_count=None): values = np.arange(4068, dtype="