zapret-kvn/tests/test_runtime_map_lines.py
loop-uh 64c7818b1c
Some checks failed
Windows project source guards / test (push) Has been cancelled
Diagnostics: a big server list no longer floods the log
A 2026-11-17 archive (Titiru outage) held 1928 [runtime-map] lines out of
2000: one line per outbound (1100+ servers), front and sidecar, on every
switch. Only the last 80 s of real events were left. Above 40 outbounds the
map is now one summary line with the selected server (each core line already
carries its node, and runtime_redacted.json has the full map); the archive
exports the whole 5000-line buffer; the slot helper start line names its
server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 08:56:36 -05:00

44 lines
1.5 KiB
Python

"""[runtime-map] stays small so a big server list cannot push real events out of the diagnostics archive."""
from __future__ import annotations
import unittest
from xray_fluent.diagnostics.runtime_logging import (
RUNTIME_MAP_FULL_LIMIT,
RuntimeLogContext,
RuntimeNodeIdentity,
runtime_mapping_lines,
)
def _identity(index: int) -> RuntimeNodeIdentity:
return RuntimeNodeIdentity(ref=f"{index:012x}", name=f"Server {index}", protocol="vless")
def _context(count: int) -> RuntimeLogContext:
nodes = {f"__app_proxy_{index:04d}": _identity(index) for index in range(count)}
return RuntimeLogContext(engine="xray", role="sidecar", mode="proxy", generation=4, selected=_identity(7),
outbound_nodes=nodes)
class RuntimeMapLinesTests(unittest.TestCase):
def test_small_map_lists_every_outbound(self):
lines = runtime_mapping_lines(_context(3))
self.assertEqual(3, len(lines))
self.assertIn("outbound=__app_proxy_0000", lines[0])
self.assertIn('node="Server 0"', lines[0])
def test_big_map_is_one_summary_line_with_the_selected_server(self):
lines = runtime_mapping_lines(_context(1112))
self.assertEqual(1, len(lines))
self.assertIn("outbounds=1112", lines[0])
self.assertIn("generation=4", lines[0])
self.assertIn('node="Server 7"', lines[0])
def test_limit_is_inclusive(self):
self.assertEqual(RUNTIME_MAP_FULL_LIMIT, len(runtime_mapping_lines(_context(RUNTIME_MAP_FULL_LIMIT))))
if __name__ == "__main__":
unittest.main()