using System.Diagnostics; namespace Azaion.Missions.E2E.Fixtures; /// /// Collection-scoped fixture for scenarios that assert startup-time behavior /// (migrator side-effects, JWKS bootstrap, env-var presence). Re-creates the /// compose stack between scenarios via docker compose down -v && up -d. /// /// /// The fixture only runs when COMPOSE_RESTART_ENABLED=1 in the consumer /// container. CI sets this; per-developer runs leave it unset to keep the /// inner-loop fast. Tests that depend on the fixture must skip with a clear /// reason when it is disabled. /// public sealed class ComposeRestartFixture { public bool Enabled => Environment.GetEnvironmentVariable("COMPOSE_RESTART_ENABLED") == "1"; public string ComposeFile => Environment.GetEnvironmentVariable("COMPOSE_FILE_PATH") ?? "/workspace/docker-compose.test.yml"; public void RestartStack() { if (!Enabled) throw new InvalidOperationException( "ComposeRestartFixture is disabled; set COMPOSE_RESTART_ENABLED=1 to use it."); Run("docker", $"compose -f {ComposeFile} down -v"); Run("docker", $"compose -f {ComposeFile} up -d postgres-test missions jwks-mock"); } private static void Run(string file, string args) { var psi = new ProcessStartInfo(file, args) { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false }; using var p = Process.Start(psi) ?? throw new InvalidOperationException($"Failed to launch {file} {args}"); p.WaitForExit(); if (p.ExitCode != 0) { var err = p.StandardError.ReadToEnd(); throw new InvalidOperationException($"`{file} {args}` exited {p.ExitCode}: {err}"); } } }