using System.Diagnostics; using System.IO; using Xunit; namespace Paca.Tests.Platform; /// /// Paca.Cli 파이프라인 회귀 방지 게이트 테스트 (Phase 5). /// CLI 옵션 파싱(--help, --dashparse, --dash, HLS), 프로세스 종료 코드 검증. /// public class CliPipelineGateTests { private static string GetSolutionRoot() { var dir = AppContext.BaseDirectory; while (!string.IsNullOrEmpty(dir) && !File.Exists(Path.Combine(dir, "Paca.slnx")) && !File.Exists(Path.Combine(dir, "Paca.sln"))) { var parent = Directory.GetParent(dir); if (parent == null) break; dir = parent.FullName; } return dir ?? AppContext.BaseDirectory; } private static string CliProjectDir => Path.Combine(GetSolutionRoot(), "src", "Paca.Cli"); [Fact] public void Gate_Cli_Program_Source_Contains_All_Required_Pipelines() { var programPath = Path.Combine(CliProjectDir, "Program.cs"); Assert.True(File.Exists(programPath), $"Program.cs must exist at {programPath}"); var content = File.ReadAllText(programPath); // 핵심 CLI 옵션 검증 Assert.Contains("--help", content); Assert.Contains("-h", content); Assert.Contains("--dashparse", content); Assert.Contains("--dash", content); Assert.Contains("HlsDownloader", content); Assert.Contains("DashDownloader", content); } [Fact] public async Task Gate_Cli_Help_Command_Exits_With_Code_Zero() { var root = GetSolutionRoot(); var psi = new ProcessStartInfo { FileName = "dotnet", Arguments = "run --project src/Paca.Cli --no-build -- -h", WorkingDirectory = root, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; using var process = new Process { StartInfo = psi }; process.Start(); var outputTask = process.StandardOutput.ReadToEndAsync(); var errorTask = process.StandardError.ReadToEndAsync(); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await process.WaitForExitAsync(cts.Token); var stdout = await outputTask; var stderr = await errorTask; Assert.Equal(0, process.ExitCode); Assert.Contains("Usage: dotnet run", stdout); } [Fact] public async Task Gate_Cli_NoArgs_Prints_Usage_And_Exits_Zero() { var root = GetSolutionRoot(); var psi = new ProcessStartInfo { FileName = "dotnet", Arguments = "run --project src/Paca.Cli --no-build", WorkingDirectory = root, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; using var process = new Process { StartInfo = psi }; process.Start(); var outputTask = process.StandardOutput.ReadToEndAsync(); using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); await process.WaitForExitAsync(cts.Token); var stdout = await outputTask; Assert.Equal(0, process.ExitCode); Assert.Contains("Usage: dotnet run", stdout); } }