using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.FileProviders; using OverviewUiCanary.Components; using ZB.MOM.WW.Overview.Components; using System.Text.Json; using ZB.MOM.WW.Overview.Polling; // Actual Overview App/Routes/layout/cards, synthetic immutable snapshots only. // No polling, HTTP client, authentication or fleet service is registered. var builder = WebApplication.CreateBuilder(args); builder.WebHost.UseStaticWebAssets(); builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider(); builder.Services.AddRazorComponents().AddInteractiveServerComponents(); var clock = new FixtureClock(); var store = new OverviewSnapshotStore(); store.Publish(Scenes.Create("mixed", clock.GetUtcNow())); builder.Services.AddSingleton(store); builder.Services.AddSingleton(clock); var app = builder.Build(); var sourceRoot = builder.Configuration["Canary:OverviewRoot"] ?? Path.GetFullPath(Path.Combine( builder.Environment.ContentRootPath, "../../../../../ZB.MOM.WW.Overview/src/ZB.MOM.WW.Overview")); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(sourceRoot, "wwwroot")) }); app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents().AddInteractiveServerRenderMode().AddAdditionalAssemblies(typeof(App).Assembly); app.MapGet("/canary-provenance", () => new { purpose = "Actual Overview components with synthetic frozen snapshots; no production registry or probes", themeAssembly = typeof(ZB.MOM.WW.Theme.ThemeShell).Assembly.GetName().Version?.ToString(), generatedUtc = clock.GetUtcNow(), sourceRoot, }); app.MapPost("/canary/scene/{scene}", (string scene) => { if (scene is not ("mixed" or "empty" or "stale" or "long-error" or "split" or "pending" or "large")) return Results.NotFound(); store.Publish(Scenes.Create(scene, clock.GetUtcNow())); return Results.Ok(new { scene, fixtureOnly = true }); }); app.MapPost("/canary/advance/{seconds:int}", (int seconds) => { if (seconds < 0 || seconds > 600) return Results.BadRequest(); clock.Advance(TimeSpan.FromSeconds(seconds)); return Results.Ok(new { fixtureUtc = clock.GetUtcNow() }); }); app.Run(); internal sealed class FixtureClock : TimeProvider { private readonly object _gate = new(); private DateTimeOffset _now = new(2026, 11, 13, 20, 0, 0, TimeSpan.Zero); public override DateTimeOffset GetUtcNow() { lock (_gate) return _now; } public void Advance(TimeSpan amount) { lock (_gate) _now += amount; } } internal static class Scenes { public static OverviewSnapshot Create(string scene, DateTimeOffset now) { if (scene == "empty") return OverviewSnapshot.Empty; var rows = scene switch { "stale" => new[] { Row("Five-minute stale healthy", InstanceStatus.Up, now.AddMinutes(-5)) }, "pending" => new[] { Row("Pending fixture", null, null) }, "large" => Enumerable.Range(0, 500).Select(i => Row($"Synthetic instance {i:D3}", i % 10 == 0 ? InstanceStatus.Degraded : InstanceStatus.Up, now)).ToArray(), "split" => new[] { LeaderRow("a", "a", now), LeaderRow("b", "b", now) }, "long-error" => new[] { Row("Unreachable long diagnostic", InstanceStatus.Unreachable, now, "Synthetic probe failure: " + new string('x', 2000) + " diagnostic end") with { BaseUrl = "http://" + new string('h', 120) + ".invalid:5200", Report = EvidenceReport("unresolved-" + new string('q', 1200)) } }, _ => new[] { Row("Healthy fixture", InstanceStatus.Up, now), Row("Degraded fixture", InstanceStatus.Degraded, now), Row("Down fixture", InstanceStatus.Down, now), Row("Unreachable fixture", InstanceStatus.Unreachable, now, "Synthetic loopback probe failure"), Row("Five-minute stale healthy", InstanceStatus.Up, now.AddMinutes(-5)), Row("Five-minute stale unreachable", InstanceStatus.Unreachable, now.AddMinutes(-5)), Row("Pending fixture", null, null), }, }; return new OverviewSnapshot(now, new[] { new ApplicationSnapshot("Synthetic local SCADA", rows, LeaderResolver.Resolve(rows)), }); } private static InstanceSnapshot LeaderRow(string name, string leader, DateTimeOffset now) => Row(name, InstanceStatus.Up, now) with { BaseUrl = $"http://{name}:8084", HasActiveRole = true, Report = EvidenceReport($"akka.tcp://scadabridge@{leader}:8082"), }; private static ZbHealthReport EvidenceReport(string leader) => new() { Status = "Healthy", Entries = new Dictionary { ["synthetic-cluster"] = new() { Status = "Healthy", Description = "Synthetic cluster evidence, not a fleet probe", Data = new Dictionary { [LeaderResolver.LeaderDataKey] = JsonSerializer.SerializeToElement(leader), ["memberCount"] = JsonSerializer.SerializeToElement(2), }, }, }, }; private static InstanceSnapshot Row(string name, InstanceStatus? status, DateTimeOffset? at, string? error = null) => new() { Application = "Synthetic local SCADA", Instance = name, Group = "Local fixtures", BaseUrl = "http://127.0.0.1:5200", Status = status, LastPolledUtc = at, LastReachableUtc = at, Latency = TimeSpan.FromMilliseconds(12), StaleAfter = TimeSpan.FromSeconds(45), Error = error, Report = status == InstanceStatus.Unreachable || status is null ? null : new ZbHealthReport { Status = status == InstanceStatus.Up ? "Healthy" : status == InstanceStatus.Degraded ? "Degraded" : "Unhealthy", Entries = new Dictionary { ["synthetic-check"] = new() { Status = status == InstanceStatus.Up ? "Healthy" : status == InstanceStatus.Degraded ? "Degraded" : "Unhealthy", Description = "Local fixture observation" }, }, }, }; }