* feat(worldapi): authoritative registered and online regions plus read-only service health * feat(worldapi): connect GridStore and AssetService to public and authenticated statistics * docs(openapi): declare registered regions, grid and asset service health * fix(worldapi): stable region ordering and honest partial service health * test(worldapi): verify GridStore regions and read-only service probes * docs(worldapi): explain full region inventory and service read-only diagnostics * docs(openapi): include partial statistics detail-level state * test(worldapi): expect combined GridUser, GridStore and AssetService quality metrics
87 lines
4.4 KiB
Python
87 lines
4.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Regression guard: statistics must keep safe public aggregates during GridUser failure."""
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[2]
|
|
stats = (root / "NexVerse/Server/Api/NexStatisticsApi.cs").read_text(encoding="utf-8")
|
|
ui = (root / "NexVerse/Server/Api/NexApiDocsPage.cs").read_text(encoding="utf-8")
|
|
routes = (root / "NexVerse/Server/Api/NexVerseWorldApiConnector.cs").read_text(encoding="utf-8")
|
|
|
|
for marker in (
|
|
'"statistics_data_unavailable"',
|
|
'if (m_UserAccounts == null)',
|
|
'bool gridUserAvailable = m_GridUsers != null;',
|
|
'm_GridUsers.GetAll(string.Empty)',
|
|
'catch (Exception e)',
|
|
'gridUserAvailable = false;',
|
|
'if (!gridUserAvailable && !completeAccountEnumeration)',
|
|
'"Both GridUser history and complete UserAccount enumeration are unavailable."',
|
|
'active_last_7_days = gridUserAvailable',
|
|
'online_now = gridUserAvailable ? hypergridOnline.Count : (int?)null',
|
|
'total = gridUserAvailable ? allOnline.Count : (int?)null',
|
|
'missing_metrics = (gridUserAvailable',
|
|
'griduser_source = gridUserAvailable ? "available" : "unavailable"',
|
|
'complete = gridUserAvailable && completeAccountEnumeration',
|
|
):
|
|
assert marker in stats, "Statistics fallback contract missing: " + marker
|
|
|
|
assert "m_UserAccounts == null || m_GridUsers == null" not in stats
|
|
assert stats.index('if (m_UserAccounts == null)') < stats.index('BuildSummary(response, includeProtectedDetails);')
|
|
assert '"/api/v1/statistics/summary"' in routes
|
|
assert routes.count('"/api/v1/statistics/summary"') == 1, "One early statistics route must serve both auth modes"
|
|
assert routes.index('"/api/v1/statistics/summary"') < routes.index('bool privilegedEndpoints ='), "Statistics must register before privileged service initialization"
|
|
assert 'statisticsRoute.AttachPrivileged(statisticsApi);' in routes, "Protected statistics must preserve scope-enforcing authenticator"
|
|
assert 'System.Threading.Volatile.Read(ref m_PrivilegedApi)' in routes
|
|
assert 'LoadOptionalService<IUserAccountService>(m_Config, "UserAccountService")' in routes
|
|
assert 'new NexStatisticsApi(null, null, null, null, null, true)' in routes, "Provider errors must result in JSON 503, not HTML 404"
|
|
|
|
start = ui.split("async function loadStatistics(){", 1)[1].split("\nfunction ", 1)[0]
|
|
assert "const bearer=$('statsBearer').value.trim()||adminAuthToken();" in start
|
|
assert "const key=$('statsApiKey').value.trim();" in start
|
|
assert "$('bearer').value.trim()" not in start, "Unrelated explorer bearer must never break public stats"
|
|
assert "$('apiKey').value.trim()" not in start, "Unrelated explorer API key must never break public stats"
|
|
assert "Teilweise (Datenquelle fehlt)" in start
|
|
assert "feh" in ui
|
|
|
|
# The public region inventory must enumerate GridStore rows even with no online
|
|
# avatars; do not fall back to the avatar-derived region breakdown.
|
|
for marker in (
|
|
"IRegionData m_RegionData",
|
|
"IAssetService m_Assets",
|
|
'm_RegionData.Get("%", UUID.Zero)',
|
|
"GroupBy(x => x.RegionID)",
|
|
"RegionFlags.Hyperlink",
|
|
"RegionFlags.Reservation",
|
|
"RegionFlags.RegionOnline",
|
|
"region_summary = new",
|
|
"registered_total = regions.Registered",
|
|
"online_total = regions.Online",
|
|
"offline_total = regions.Offline",
|
|
"regions = regions.Rows",
|
|
"services = new",
|
|
"ReadAssetServiceStatus()",
|
|
"m_Assets.AssetsExist(",
|
|
"region_source = regions.Available",
|
|
"asset_service_probe = assetStatus",
|
|
"region_online_users = includeProtectedDetails",
|
|
):
|
|
assert marker in stats, "World regions and service health contract missing: " + marker
|
|
|
|
for marker in (
|
|
"LoadRegionData(m_Config)",
|
|
"LoadRegionData(config)",
|
|
'LoadOptionalService<IAssetService>(m_Config, "AssetService")',
|
|
"return ServerUtils.LoadPlugin<IRegionData>(",
|
|
'grid?.GetString("Realm", "regions")',
|
|
):
|
|
assert marker in routes, "GridStore/AssetService load contract missing: " + marker
|
|
|
|
# Verify public region detail does not accidentally publish simulator internal
|
|
# endpoints, database connection strings, owner data, tokens or secrets.
|
|
public_regions = stats.split("private RegionSnapshot ReadRegions()", 1)[1].split("private string ReadAssetServiceStatus()", 1)[0]
|
|
for disallowed in ("ServerURI", "ExternalHostName", "RegionSecret", ".Token", "connectionString", "EstateOwner"):
|
|
assert disallowed not in public_regions, "Sensitive region field exposed: " + disallowed
|
|
|
|
|
|
print("OGL statistics partial-data and public aggregate routing: PASS")
|