using ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Cluster;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.PlaywrightTests.Deployment;
///
/// fixture for the Flow Debugger E2E tests: provisions ONE ephemeral
/// inbound API method through the CLI and deletes it on dispose, so the tests never depend on
/// rig-seeded methods (the FlowOutboundDemo / DelmiaRecipeDownload stand-ins) and
/// never need the login-disabled override — the Playwright fixture logs in through
/// /auth/login like every other page test.
///
///
/// The method takes one Text parameter and echoes it. Its script also carries a
/// Route.To(...).Call(...) on a branch that never executes (the target instance does not
/// exist): the Flow Debugger's prediction walks that branch anyway and resolves the route
/// target through the repository, which is exactly the path that used to deadlock the Blazor
/// circuit (sync-over-async in FlowDebugService.PredictMethodAsync, fixed 2026-09-06) — a
/// method with no route target would not exercise it.
///
///
///
/// Gated on : when the dev cluster is down,
/// is , nothing is provisioned and the consuming
/// tests skip.
///
///
public sealed class FlowDebuggerFixture : IAsyncLifetime
{
/// The parameter-definitions JSON of the ephemeral method (one required string).
private const string ParametersJson =
"""{"type":"object","properties":{"Text":{"type":"string"}},"required":["Text"]}""";
/// Whether the cluster was reachable at setup and the method exists.
public bool Available { get; private set; }
/// Id of the ephemeral inbound method (0 when unavailable).
public int MethodId { get; private set; }
/// Name of the ephemeral inbound method (its POST /api/{name} segment).
public string MethodName { get; private set; } = string.Empty;
/// Probes cluster availability and, when available, creates the ephemeral inbound method used by the tests.
/// A task that represents the asynchronous operation.
public async Task InitializeAsync()
{
Available = await ClusterAvailability.IsAvailableAsync();
if (!Available)
{
return;
}
MethodName = CliRunner.UniqueName("flow");
const string script =
"""
var text = Parameters.ContainsKey("Text") ? Parameters["Text"]?.ToString() : null;
if (text == "route-me")
{
return await Route.To("zztest-no-such-instance").Call("Process", new { });
}
return new { ok = true, echo = text };
""";
try
{
MethodId = await CliRunner.CreateApiMethodAsync(MethodName, script, ParametersJson);
}
catch
{
Available = false;
throw;
}
}
/// Deletes the ephemeral inbound method if one was created.
/// A task that represents the asynchronous operation.
public Task DisposeAsync() =>
MethodId > 0 ? CliRunner.DeleteApiMethodAsync(MethodId) : Task.CompletedTask;
}