using System.Reflection; using System.Text.Json; namespace UCVL.VPNPlus; internal static class SingleNodeClientSelfTest { internal static int Run() { var checks = new Dictionary(); string? error = null; try { var selection = ConnectionSelection.Create(false, "aliyun-tokyo-002", ["aliyun-tokyo-002", "aliyun-siliconvalley-003", "racknerd-newyork-004"]); checks["connection_is_fixed_to_vpn004"] = selection.NodeSlug == "racknerd-newyork-004" && !selection.Manual && selection.Attempts(99) == 1; using var form = new MainForm(preview: true, uiOnly: true) { Opacity = 0, ShowInTaskbar = false }; foreach (var check in form.CheckSingleNodeUi()) checks.Add(check.Key, check.Value); var policy = typeof(MainForm).Assembly.GetType("UCVL.VPNPlus.SingleNodeClientPolicy"); var policySelfTest = policy?.GetMethod("SelfTest", BindingFlags.Static | BindingFlags.NonPublic); checks["single_node_public_policy_rejects_other_nodes_and_tailnet"] = policySelfTest?.Invoke(null, null) as bool? == true; var switcher = typeof(MainForm).Assembly.GetType("UCVL.VPNPlus.LiveProxyModeSwitch"); var switchSelfTest = switcher?.GetMethod("SelfTest", BindingFlags.Static | BindingFlags.NonPublic); checks["live_mode_switch_is_atomic_and_rolls_back"] = switchSelfTest?.Invoke(null, null) as bool? == true; } catch (Exception exception) { error = exception.ToString(); } var passed = error is null && checks.Count >= 10 && checks.Values.All(value => value); File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "single-node-client-self-test.json"), JsonSerializer.Serialize(new { passed, checks, error, fixed_node = "racknerd-newyork-004", public_gateway = "47.104.134.190:11084", network_modified = false, installed_client_modified = false, credentials_loaded = false, }, new JsonSerializerOptions { WriteIndented = true })); return passed ? 0 : 34; } } internal sealed partial class MainForm { internal Dictionary CheckSingleNodeUi() { var checks = new Dictionary(); var profile = new Profile { DisplayName = "单节点测试", Email = "fixture@example.invalid", CanViewNodeTraffic = true, Nodes = [ new NodeInfo { Slug = "aliyun-tokyo-002", Name = "VPN002", Status = "online" }, new NodeInfo { Slug = "racknerd-newyork-004", Name = "VPN004", Status = "online" }, ], RouteModes = [ new RouteModeInfo { Id = "smart", Name = "AI 智能代理" }, new RouteModeInfo { Id = "global", Name = "全局代理" }, new RouteModeInfo { Id = "direct", Name = "直接连接" }, ], }; Show(); ShowDashboard(profile); _refreshTimer.Stop(); PerformLayout(); LayoutDashboard(); Application.DoEvents(); checks["scheduler_selector_hidden"] = !_connectionModeCombo.Visible; checks["node_selector_hidden"] = !_manualNodeCombo.Visible; checks["node_identity_hidden"] = !_nodeHeading.Visible && !_currentNodeLabel.Visible; checks["only_smart_and_global_modes"] = _routeCombo.Items.Cast() .Select(item => item.Id).SequenceEqual(["smart", "global"]); checks["server_traffic_sampling_disabled"] = !_canViewNodeTraffic && !_nodeTrafficPanel.Visible && !_nodeTrafficTimer.Enabled; checks["tailnet_presentation_removed"] = !_tailnetTrafficVisible && !_tailnetTrafficCard.Visible && !_trendHeading.Text.Contains("Tailscale", StringComparison.OrdinalIgnoreCase); _wantConnected = true; _currentNodeSlug = "racknerd-newyork-004"; SetConnectionState(true, "已安全连接", "AI 智能代理"); RefreshSelectionControls(); checks["route_mode_remains_editable_while_connected"] = _routeCombo.Enabled; checks["dashboard_remains_fixed_without_scroll"] = !_dashboardScrollBar.Visible && _dashboardBody.Location == Point.Empty && DashboardControlsFit(); var previous = _routeCombo.Items.Cast().Single(item => item.Id == "smart"); _activeRouteModeId = previous.Id; ShowRouteModeRollbackFailure(previous); checks["rollback_failure_is_not_reported_as_preserved"] = !_selectionUiConnected && !_wantConnected && _activeRouteModeId is null && _connectButton.Text == "连接" && _statusDetail.Text.Contains("已安全断开") && !_statusDetail.Text.Contains("已保留原模式"); RequestExit(); return checks; } }