using System.Diagnostics.CodeAnalysis;
using System.Net;
using Akka.Actor;
using Akka.Hosting;
using Grpc.Core;
using Grpc.Net.Client;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Cluster;
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Mesh;
using ZB.MOM.WW.OtOpcUa.Commons.Protos.MeshTransport.V1;
using ZB.MOM.WW.OtOpcUa.Commons.Protos.Telemetry.V1;
using ZB.MOM.WW.OtOpcUa.ControlPlane.Communication;
using ZB.MOM.WW.OtOpcUa.Host.Configuration;
using ZB.MOM.WW.OtOpcUa.Runtime;
using ZB.MOM.WW.OtOpcUa.Runtime.Telemetry;
namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;
///
/// R3-01 T6 — pins the report's "driver-only nodes are structurally unaffected" finding
/// (archreview 03/S14): a node with no admin role never registers
/// AddOtOpcUaAuth/UseAuthentication/UseAuthorization at all, so it has no
/// cookie FallbackPolicy to opt out of in the first place — the PSK interceptors were
/// always the ONLY gate on this shape, with or without .AllowAnonymous().
///
///
/// A future "register auth everywhere for consistency" change would silently reintroduce 03/S14
/// for every site node in the fleet. This class is what turns that into a failing test instead of
/// a live outage: it asserts BOTH that the driver-only mesh endpoints behave identically to the
/// fused shape's (T4) AND that the reason they do — no
/// registered at all — actually holds, so a change that adds auth services here fails on the
/// second assertion even if it somehow left the first passing.
///
public sealed class MeshGrpcDriverOnlyPipelineTests : IAsyncLifetime
{
private const string NodeCommandKey = "test-driveronly-node-psk";
private const string TelemetryKey = "test-driveronly-telemetry-key";
private WebApplication _app = null!;
private ActorSystem _system = null!;
private int _port;
private ITelemetryLocalHub _hub = null!;
private TaskCompletionSource