관리자 빈 화면 진단 로그 추가

This commit is contained in:
Yun Chan 2026-07-03 23:24:09 +09:00
parent 85608b41ee
commit 64e06a1185
6 changed files with 224 additions and 5 deletions

View file

@ -0,0 +1,56 @@
"""Client diagnostics telemetry tests."""
from __future__ import annotations
import unittest
from types import SimpleNamespace
from .routes import client_diagnostics
class ClientDiagnosticsTest(unittest.IsolatedAsyncioTestCase):
async def test_client_diagnostic_logs_safe_structural_payload(self) -> None:
payload = client_diagnostics.ClientDiagnosticRequest(
reason="watchdog",
path="/admin/users",
href="https://vignette.chanpaca.net/admin/users",
asset="index-R5KK7hZI.js",
elapsed_ms=3510,
body_text_length=0,
root_text_length=0,
root_child_count=1,
visible_nodes=0,
document_ready_state="complete",
viewport="1920x1080",
user_agent="Playwright",
errors=[
client_diagnostics.ClientDiagnosticError(
kind="unhandledrejection",
detail="Cannot read properties of null",
at="2026-07-03T00:00:00.000Z",
)
],
)
request = SimpleNamespace(
client=SimpleNamespace(host="127.0.0.1"),
headers={
"origin": "https://vignette.chanpaca.net",
"referer": "https://vignette.chanpaca.net/admin/users",
"cf-ray": "test-ray",
},
)
with self.assertLogs("vignette.client_diagnostics", level="WARNING") as logs:
result = await client_diagnostics.record_client_diagnostic(payload, request)
joined = "\n".join(logs.output)
self.assertEqual(result, {"ok": True})
self.assertIn("client_diagnostic", joined)
self.assertIn("/admin/users", joined)
self.assertIn("body_text_length", joined)
self.assertIn("Cannot read properties of null", joined)
self.assertNotIn("body_text=", joined)
if __name__ == "__main__":
unittest.main()