DNS, TCP, platform TLS and the stock naive.exe (real config builder helper_config, dummy credentials, no own ClientHello) per saved server host, one full log (text and JSONL, hosts masked unless ticked, also in the diagnostic archive). By button, one selected server by default; all servers only on a tick, one at a time with 10-20 s pauses, cancel on the same button, gate journal; egress allowlist entries with reasons. Work of the KVN session c_9doawlxyy2 (branch feat/path-test), squashed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
76 lines
3.2 KiB
Python
76 lines
3.2 KiB
Python
"""Кнопка «Проверить соединение» на странице логов и вложение журнала в архив диагностики (настоящая страница, настоящий экспорт)."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import tempfile
|
|
import unittest
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
|
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
from xray_fluent.diagnostics.export import export_diagnostics
|
|
from xray_fluent.diagnostics.path_test import service
|
|
from xray_fluent.ui.logs_page import LogsPage
|
|
|
|
|
|
class _State:
|
|
nodes: list = []
|
|
|
|
def to_dict(self):
|
|
return {}
|
|
|
|
|
|
class PathTestUiTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.app = QApplication.instance() or QApplication([])
|
|
|
|
def test_button_emits_the_ticks_and_shows_progress(self):
|
|
page = LogsPage()
|
|
seen = []
|
|
page.path_test_requested.connect(lambda names, every: seen.append((names, every)))
|
|
page.path_test_btn.click()
|
|
page.path_test_names.setChecked(True)
|
|
page.path_test_all.setChecked(True)
|
|
page.path_test_btn.click()
|
|
self.assertEqual(seen, [(False, False), (True, True)])
|
|
self.assertTrue(page.path_test_all.isChecked())
|
|
|
|
def test_while_running_the_same_button_stops_the_run(self):
|
|
page = LogsPage()
|
|
requested, cancelled = [], []
|
|
page.path_test_requested.connect(lambda *_: requested.append(1))
|
|
page.path_test_cancel_requested.connect(lambda: cancelled.append(1))
|
|
page.set_path_test_state(True, "2 из 6")
|
|
self.assertTrue(page.path_test_btn.isEnabled())
|
|
self.assertIn("Остановить", page.path_test_btn.text())
|
|
self.assertIn("2 из 6", page.path_test_btn.text())
|
|
self.assertFalse(page.path_test_names.isEnabled() or page.path_test_all.isEnabled())
|
|
page.path_test_btn.click()
|
|
self.assertEqual((requested, cancelled), ([], [1]))
|
|
page.set_path_test_state(False)
|
|
self.assertEqual(page.path_test_btn.text(), "Проверить соединение")
|
|
self.assertTrue(page.path_test_names.isEnabled() and page.path_test_all.isEnabled())
|
|
|
|
def test_last_log_rides_inside_the_diagnostic_archive(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
directory = Path(tmp) / "path-test"
|
|
directory.mkdir()
|
|
(directory / service.LAST_TEXT).write_text("# Path test (Check connection)\n", encoding="utf-8")
|
|
(directory / service.LAST_JSONL).write_text('{"type":"environment"}', encoding="utf-8")
|
|
out = export_diagnostics(Path(tmp) / "d.zip", _State(), [], extra_files=service.last_entries(directory))
|
|
with zipfile.ZipFile(out) as archive:
|
|
names = set(archive.namelist())
|
|
self.assertTrue({"path-test/last.txt", "path-test/last.jsonl", "state_redacted.json"} <= names)
|
|
self.assertTrue(archive.read("path-test/last.txt").startswith(b"# Path test"))
|
|
|
|
def test_no_last_log_means_no_extra_entries(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
self.assertEqual(service.last_entries(Path(tmp) / "nothing"), {})
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|