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>
74 lines
3.7 KiB
Python
74 lines
3.7 KiB
Python
"""Один полный журнал, который владелец передаёт целиком: текст для людей и ИИ и JSONL с теми же фактами.
|
||
|
||
В журнале нет учётных данных, ключей, ссылок подписок и адресов. Хосты видны как стабильная маска; настоящие имена только
|
||
если владелец отметил это для данного запуска. Формат строк совпадает с Android-версией: один читатель на оба приложения.
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
from datetime import datetime, timezone
|
||
|
||
from .model import Environment, HostVerdict, Target, TargetResult
|
||
|
||
|
||
def _label(target: Target, include_names: bool) -> str:
|
||
return f"{target.ref} {target.host}:{target.port}" if include_names else target.ref
|
||
|
||
|
||
def _ratio(answered: int, total: int) -> str:
|
||
return "n/a" if answered < 0 or total == 0 else f"{answered}/{total}"
|
||
|
||
|
||
def _iso(epoch: float) -> str:
|
||
return datetime.fromtimestamp(epoch, timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
||
|
||
|
||
def render_text(env: Environment, results, verdicts, include_names: bool) -> str:
|
||
lines = [
|
||
"# Path test (Check connection)",
|
||
f"app={env.app_name} {env.app_version} started={_iso(env.started_at)} tz={env.timezone} "
|
||
f"network={env.network_type} vpn={'on' if env.vpn_active else 'off'} client={env.client_binary}",
|
||
"rule: the real_client step runs the stock naive client (Chromium network stack) with the real config builder and "
|
||
"DUMMY credentials; this test builds no hello of its own. platform_tls is only a control (a different real stack).",
|
||
*(f"note: {note}" for note in env.notes),
|
||
"",
|
||
]
|
||
for result in results:
|
||
lines.append(f"== {_label(result.target, include_names)}{' (control)' if result.target.control else ''}")
|
||
for a in result.attempts:
|
||
offset = max(0.0, a.at - env.started_at)
|
||
lines.append(
|
||
f"t=+{offset:.2f}s step={a.step.value} result={a.outcome.ident} ms={a.millis}"
|
||
+ (f" detail={a.detail}" if a.detail else "")
|
||
)
|
||
lines.append("")
|
||
lines.append("-- summary")
|
||
for v in verdicts:
|
||
lines.append(
|
||
f"{_label(v.target, include_names)} real_client={_ratio(v.real_answered, v.real_total)} "
|
||
f"platform_tls={_ratio(v.platform_answered, v.platform_total)} verdict={v.verdict.ident}"
|
||
)
|
||
lines.append(f" {v.verdict.plain}")
|
||
return "\n".join(lines) + "\n"
|
||
|
||
|
||
def render_jsonl(env: Environment, results, verdicts, include_names: bool) -> list[str]:
|
||
rows: list[dict] = [{
|
||
"type": "environment", "app": env.app_name, "version": env.app_version, "started": _iso(env.started_at),
|
||
"tz": env.timezone, "network": env.network_type, "vpn": env.vpn_active, "client": env.client_binary,
|
||
}]
|
||
for result in results:
|
||
label = _label(result.target, include_names)
|
||
for a in result.attempts:
|
||
row = {"type": "attempt", "host": label, "control": result.target.control, "step": a.step.value,
|
||
"result": a.outcome.ident, "ms": a.millis, "at_ms": int(max(0.0, a.at - env.started_at) * 1000)}
|
||
if a.detail:
|
||
row["detail"] = a.detail
|
||
rows.append(row)
|
||
for v in verdicts:
|
||
rows.append({
|
||
"type": "verdict", "host": _label(v.target, include_names), "verdict": v.verdict.ident,
|
||
"real_answered": v.real_answered, "real_total": v.real_total,
|
||
"platform_answered": v.platform_answered, "platform_total": v.platform_total,
|
||
})
|
||
return [json.dumps(r, ensure_ascii=False, separators=(",", ":")) for r in rows]
|