v0.7.10: events tab rework, quieter logs, known hosts, dropdown theme fixes

This commit is contained in:
Reditus committed 2026-09-26 11:54:08 +01:00
1 parent 97cdbd3027
commit 91c7abc771
24 files changed
+740 -103

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
"""Tests for game event summaries and solaris log parsing."""
from app.utils.events import (
clean_name,
event_label,
parse_solaris_meta,
summarize_game_event,
)
class TestLabels:
def test_known_types(self):
assert event_label(0) == 'Death'
assert event_label(97) == 'Permission change'
def test_unknown_type_falls_back(self):
assert event_label(12345) == 'Event 12345'
assert event_label('xyz') == 'Event xyz'
class TestCleanName:
def test_strips_hashes(self):
assert clean_name('##MediumOrnithopter') == 'MediumOrnithopter'
assert clean_name('#Totem') == 'Totem'
def test_blanks(self):
assert clean_name(None) == ''
assert clean_name('None') == ''
assert clean_name('!!act#0') == ''
class TestSummaries:
def test_death(self):
msg = summarize_game_event(0, {'m_KillerType': 'NPC', 'm_DamageType': 'None'})
assert 'NPC' in msg
def test_build(self):
msg = summarize_game_event(10, {'m_CauserType': 'Player',
'm_BuildableName': 'Totem_Small_Placeable'})
assert 'Totem_Small_Placeable' in msg
def test_permission(self):
msg = summarize_game_event(97, {'m_PermissionActorName': '##MediumOrnithopter',
'm_OldPermissionRank': 'Associate',
'm_NewPermissionRank': 'CoOwner'})
assert 'Associate -> CoOwner' in msg
def test_power_hours(self):
msg = summarize_game_event(95, {'m_BuildableName': 'Totem_Placeable',
'm_PowerTimeLeftSeconds': 35959})
assert '9h' in msg
def test_never_raises(self):
assert summarize_game_event(0, 'not json {{{') == '' or True
assert summarize_game_event(999, None) == ''
assert summarize_game_event(97, {'m_OldPermissionRank': 'x'}) != '' or True
class TestSolarisMeta:
def test_python_repr_format(self):
parsed = parse_solaris_meta(
"{'event': 'adjust_player_virtual_currency_balance', "
"'fls_id': 'ABC123', 'solaris_delta': -27562, 'solaris_balance': 23135}")
assert parsed == {'fls_id': 'ABC123', 'delta': -27562, 'balance': 23135}
def test_json_format(self):
parsed = parse_solaris_meta(
'{"fls_id": "ABC", "solaris_delta": 6000, "solaris_balance": 100}')
assert parsed['delta'] == 6000
def test_garbage_returns_none(self):
assert parse_solaris_meta(None) is None
assert parse_solaris_meta('just a string') is None
assert parse_solaris_meta('[1, 2]') is None
+20
View File
@@ -20,6 +20,26 @@ class TestHandshakeFilter:
assert any('handshake dropped' in r.message for r in caplog.records)
assert all(r.levelno == logging.DEBUG for r in caplog.records)
def test_plain_http_and_dead_socket_go_to_debug_only(self, caplog):
calls = []
def orig(msg='', level=20, traceback=False):
calls.append((msg, level))
noises = [
"Client ('1.2.3.4', 123) attempted to speak plain HTTP into a "
"TCP connection configured for TLS-only traffic",
'[SSL: HTTP_REQUEST] http request (_ssl.c:1081)',
'OSError: [WinError 10038] An operation was attempted on '
'something that is not a socket',
]
with caplog.at_level(logging.DEBUG, logger='app.utils.http_server'):
for noise in noises:
cheroot_error_filter(orig, noise)
assert calls == []
assert len([r for r in caplog.records
if r.levelno == logging.DEBUG]) == len(noises)
def test_real_errors_pass_through(self):
calls = []
+76
View File
@@ -0,0 +1,76 @@
"""Tests for SSH known-hosts persistence (kills the unknown-key warning)."""
import os
from app.services import ssh as ssh_module
from app.services.ssh import SSHService
class _FakeTransport:
def is_active(self):
return True
def set_keepalive(self, interval):
pass
class _FakeClient:
instances = []
def __init__(self):
self.loaded = []
self.saved = []
self.connected = False
_FakeClient.instances.append(self)
def load_host_keys(self, path):
self.loaded.append(path)
if not os.path.exists(path):
raise FileNotFoundError(path)
def set_missing_host_key_policy(self, policy):
pass
def connect(self, **kwargs):
self.connected = True
def get_transport(self):
return _FakeTransport()
def save_host_keys(self, path):
self.saved.append(path)
with open(path, 'w') as f:
f.write('# test known hosts\n')
def close(self):
pass
def _service(monkeypatch, tmp_path):
monkeypatch.setattr(ssh_module.paramiko, 'SSHClient', _FakeClient)
monkeypatch.setenv('DUNE_KNOWN_HOSTS', str(tmp_path / 'known_hosts'))
_FakeClient.instances.clear()
return SSHService('example.com', 'dune', ssh_key=None)
class TestKnownHosts:
def test_saves_after_connect(self, tmp_path, monkeypatch):
svc = _service(monkeypatch, tmp_path)
client = svc._get_client()
assert client.connected is True
assert client.saved == [str(tmp_path / 'known_hosts')]
assert os.path.exists(str(tmp_path / 'known_hosts'))
def test_loads_existing_file(self, tmp_path, monkeypatch):
hosts = tmp_path / 'known_hosts'
hosts.write_text('# existing\n')
svc = _service(monkeypatch, tmp_path)
client = svc._get_client()
assert client.loaded == [str(hosts)]
def test_reuses_live_client(self, tmp_path, monkeypatch):
svc = _service(monkeypatch, tmp_path)
first = svc._get_client()
second = svc._get_client()
assert first is second
assert len(_FakeClient.instances) == 1