Windows 0.3.5 traffic trends UI source delta; connection fixes retained; no private history or other platform changes

This commit is contained in:
2026-11-06 10:54:33 +00:00
parent 991b029b37
commit 7f7d4f6d35
19 changed files with 923 additions and 304 deletions
+28 -9
View File
@@ -4,6 +4,7 @@ namespace UCVL.VPNPlus;
internal static class NodeTrafficSelfTest
{
private const string SecondFixtureSlug="aliyun-siliconvalley-003";
internal static int Run()
{
var checks = new Dictionary<string, bool>();
@@ -18,11 +19,13 @@ internal static class NodeTrafficSelfTest
NodeTrafficSnapshot Snapshot(List<NodeTrafficReading>? rows = null, string scope = "server_host_interface",
string source = "linux_host_interface", DateTimeOffset? generated = null, string direction = "interface_perspective") => new()
{ Contract = 1, Scope = scope, Source = source, Direction = direction, CounterSince = "boot_or_interface_reset",
GeneratedAt = generated ?? now, Nodes = rows ?? [Row(), Row(NodeTrafficPresentation.Slugs[1])] };
GeneratedAt = generated ?? now, Nodes = rows ?? [Row(), Row(SecondFixtureSlug)] };
bool Valid(NodeTrafficSnapshot value) => NodeTrafficPresentation.Valid(value, now);
checks["exact_two_authorized_server_contract"] = Valid(Snapshot());
checks["four_authorized_nodes_supported_without_static_whitelist"] = Valid(Snapshot([Row(), Row("aliyun-siliconvalley-003"), Row("jinan-phone"), Row("racknerd-newyork-004")]));
checks["empty_authorized_set_is_not_fake_servers"] = Valid(Snapshot([]));
checks["other_nodes_rejected"] = !Valid(Snapshot([Row("phone")]));
checks["additional_authorized_nodes_accepted"] = Valid(Snapshot([Row("phone")]));
checks["unsafe_node_slug_rejected"] = !Valid(Snapshot([Row("../phone")]));
checks["duplicate_node_rejected"] = !Valid(Snapshot([Row(), Row()]));
checks["too_many_rows_rejected"] = !Valid(Snapshot([Row(), Row(), Row()]));
checks["proxy_accounting_cannot_be_mislabelled_host"] = !Valid(Snapshot(scope: "server_proxy_aggregate"));
@@ -52,7 +55,7 @@ internal static class NodeTrafficSelfTest
checks["expired_envelope_hides_live_bars"] = NodeTrafficPresentation.BarRates(Snapshot(generated: now.AddSeconds(-16)), Row(), now) == new NodeTrafficBarRates(null, null);
checks["unavailable_sampling_hides_live_bars"] = NodeTrafficPresentation.BarRates(Snapshot(), Row(), now, false) == new NodeTrafficBarRates(null, null);
checks["measured_zero_bars_remain_available"] = NodeTrafficPresentation.BarRates(Snapshot(), Row(up: 0, down: 0), now) == new NodeTrafficBarRates(0, 0);
checks["individual_missing_rate_is_not_fabricated"] = NodeTrafficPresentation.BarRates(Snapshot(), Row(up: null, down: 20), now) == new NodeTrafficBarRates(20, null);
checks["individual_missing_rate_is_not_fabricated"] = NodeTrafficPresentation.BarRates(Snapshot(), Row(up: null, down: 20), now) == new NodeTrafficBarRates(null, null);
var commonMaximum = NodeTrafficPresentation.BarMaximum([new(100 * 1024, 200 * 1024), new(20 * 1024, null)]);
checks["two_servers_share_one_common_scale"] = commonMaximum > 200 * 1024
&& NodeTrafficPresentation.BarWidth(100 * 1024, commonMaximum, 100) < NodeTrafficPresentation.BarWidth(200 * 1024, commonMaximum, 100);
@@ -104,12 +107,12 @@ internal static class NodeTrafficSelfTest
using (var panel = new NodeTrafficPanel(() => now) { BackColor = Color.White })
{
panel.CreateControl();
panel.Size = new Size(464 * panel.DeviceDpi / 96, 38 * panel.DeviceDpi / 96);
panel.Size = new Size(464 * panel.DeviceDpi / 96, 100 * panel.DeviceDpi / 96);
using var preview = new Bitmap(panel.Width, panel.Height);
panel.SetSnapshot(Snapshot([Row(up: 100 * 1024, down: 200 * 1024, totalUp: 2_000_000_000, totalDown: 3_000_000_000),
Row(NodeTrafficPresentation.Slugs[1], up: 20 * 1024, down: 40 * 1024, totalUp: 5_000_000_000, totalDown: 6_000_000_000)]));
Row(SecondFixtureSlug, up: 20 * 1024, down: 40 * 1024, totalUp: 5_000_000_000, totalDown: 6_000_000_000)]));
panel.DrawToBitmap(preview, panel.ClientRectangle);
checks["actual_panel_describes_ingress_egress_order"] = panel.AccessibleDescription?.Contains("上方为流入,下方为流出") == true;
checks["actual_panel_describes_distinct_server_curves"] = panel.AccessibleDescription?.Contains("每台服务器各自一张流入、流出趋势图") == true;
checks["actual_panel_retains_rates_totals_and_sample_time"] = panel.AccessibleDescription?.Contains("200.0 KB/s") == true
&& panel.AccessibleDescription.Contains("累计入") && panel.AccessibleDescription.Contains(now.LocalDateTime.ToString("HH:mm:ss"));
preview.Save(Path.Combine(AppContext.BaseDirectory, "node-traffic-bars-preview.png"));
@@ -117,19 +120,34 @@ internal static class NodeTrafficSelfTest
panel.DrawToBitmap(preview, panel.ClientRectangle);
checks["actual_unavailable_panel_preserves_totals_and_time_without_live_rate"] = panel.AccessibleDescription?.Contains("入— 出—") == true
&& panel.AccessibleDescription.Contains("累计入2.79 GB") && panel.AccessibleDescription.Contains(now.LocalDateTime.ToString("HH:mm:ss"));
checks["unavailable_never_fabricates_history_zero"] = panel.HistoryCount("aliyun-tokyo-002")==1;
panel.SetSnapshot(Snapshot());
checks["duplicate_backend_timestamp_not_added_twice"] = panel.HistoryCount("aliyun-tokyo-002")==1;
var next=now.AddSeconds(5);
panel.SetSnapshot(Snapshot([Row(sampled:next,epoch:"new-counter"), Row(SecondFixtureSlug,sampled:next)]));
var history=panel.History("aliyun-tokyo-002");
checks["counter_epoch_change_breaks_curve_segment"] = history.Length==2 && history[0].Segment!=history[1].Segment;
panel.SetPeriodMinutes(1);
checks["server_time_range_does_not_recreate_samples"] = panel.HistoryCount("aliyun-tokyo-002")==2;
panel.SetSnapshot(Snapshot([Row(), Row("aliyun-siliconvalley-003"), Row("jinan-phone"), Row("racknerd-newyork-004")]));
checks["four_distinct_servers_receive_separate_histories"] = panel.ServerCount==4 && panel.HistoryCount("racknerd-newyork-004")==1;
panel.SetSnapshot(Snapshot([]));
checks["revoked_server_rows_clear_old_history"] = panel.ServerCount==0 && panel.HistoryCount("racknerd-newyork-004")==0;
}
foreach (var tailnet in new[] { false, true })
{
var view = new Size(960, 612);
var layout = DashboardLayout.Calculate(view, 96, tailnet, true);
checks["server_rows_below_real_speed_" + tailnet] = layout.ServerTrafficCard.Top > layout.DailyCard.Bottom
&& layout.ServerTrafficCard.Top > layout.TrafficCard.Bottom
&& (!tailnet || layout.ServerTrafficCard.Top > layout.TailnetTrafficCard.Bottom);
checks["server_rows_below_real_speed_" + tailnet] = layout.ServerTrafficCard.Top > layout.SpeedTrendCard.Bottom
&& layout.DailyCard.Top > layout.ServerTrafficCard.Bottom
&& layout.TrafficCard.IsEmpty && layout.TailnetTrafficCard.IsEmpty;
checks["no_extra_window_height_or_scroll_" + tailnet] = layout.Footer.Bottom <= view.Height
&& layout.ContentHeight <= view.Height && layout.ServerTrafficCard.Bottom < layout.Footer.Top;
}
var oldProfile = JsonSerializer.Deserialize<Profile>("{\"email\":\"fixture@example.invalid\"}")!;
checks["older_backend_omission_does_not_enable_monitor"] = !oldProfile.CanViewNodeTraffic;
foreach(var check in NodeTrafficOneSecondSelfTest.Check(now))checks[check.Key]=check.Value;
foreach(var check in NodeTrafficRepaintSelfTest.Check())checks[check.Key]=check.Value;
}
catch (Exception exception) { error = exception.GetType().Name; }
var passed = error is null && checks.Count >= 30 && checks.Values.All(value => value);
@@ -139,4 +157,5 @@ internal static class NodeTrafficSelfTest
new JsonSerializerOptions { WriteIndented = true }));
return passed ? 0 : 84;
}
}