CLI entry trace warning capture and sprint status sync

This commit is contained in:
master
2025-11-06 19:18:34 +00:00
parent b190563d80
commit e5ffcd6535
8 changed files with 157 additions and 70 deletions

View File

@@ -19,7 +19,8 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Spectre.Console;
using Spectre.Console;
using Spectre.Console.Rendering;
using StellaOps.Auth.Client;
using StellaOps.Cli.Configuration;
using StellaOps.Cli.Prompts;
@@ -217,10 +218,12 @@ internal static class CommandHandlers
private static void RenderEntryTrace(EntryTraceResponseModel result, bool includeNdjson)
{
AnsiConsole.MarkupLine($"[bold]Scan[/]: {result.ScanId}");
AnsiConsole.MarkupLine($"Image: {result.ImageDigest}");
AnsiConsole.MarkupLine($"Generated: {result.GeneratedAt:O}");
AnsiConsole.MarkupLine($"Outcome: {result.Graph.Outcome}");
var console = AnsiConsole.Console;
console.MarkupLine($"[bold]Scan[/]: {result.ScanId}");
console.MarkupLine($"Image: {result.ImageDigest}");
console.MarkupLine($"Generated: {result.GeneratedAt:O}");
console.MarkupLine($"Outcome: {result.Graph.Outcome}");
var planTable = new Table()
.AddColumn("Terminal")
@@ -243,14 +246,14 @@ internal static class CommandHandlers
if (planTable.Rows.Count > 0)
{
AnsiConsole.Write(planTable);
}
else
{
AnsiConsole.MarkupLine("[italic]No entry trace plans recorded.[/]");
}
if (result.Graph.Diagnostics.Length > 0)
console.Write(planTable);
}
else
{
console.MarkupLine("[italic]No entry trace plans recorded.[/]");
}
if (result.Graph.Diagnostics.Length > 0)
{
var diagTable = new Table()
.AddColumn("Severity")
@@ -265,17 +268,17 @@ internal static class CommandHandlers
diagnostic.Message);
}
AnsiConsole.Write(diagTable);
}
if (includeNdjson && result.Ndjson.Count > 0)
{
AnsiConsole.MarkupLine("[bold]NDJSON Output[/]");
foreach (var line in result.Ndjson)
{
AnsiConsole.WriteLine(line);
}
}
console.Write(diagTable);
}
if (includeNdjson && result.Ndjson.Count > 0)
{
console.MarkupLine("[bold]NDJSON Output[/]");
foreach (var line in result.Ndjson)
{
console.WriteLine(line);
}
}
}
public static async Task HandleScannerRunAsync(
@@ -399,13 +402,17 @@ internal static class CommandHandlers
try
{
var result = await client.GetEntryTraceAsync(scanId, cancellationToken).ConfigureAwait(false);
if (result is null)
{
logger.LogWarning("No EntryTrace data available for scan {ScanId}.", scanId);
Environment.ExitCode = 1;
return;
}
var result = await client.GetEntryTraceAsync(scanId, cancellationToken).ConfigureAwait(false);
if (result is null)
{
logger.LogWarning("No EntryTrace data available for scan {ScanId}.", scanId);
var console = AnsiConsole.Console;
console.MarkupLine("[yellow]No EntryTrace data available for scan {0}.[/]", Markup.Escape(scanId));
console.Write(new Text($"No EntryTrace data available for scan {scanId}.{Environment.NewLine}"));
Console.WriteLine($"No EntryTrace data available for scan {scanId}.");
Environment.ExitCode = 1;
return;
}
RenderEntryTrace(result, includeNdjson);
Environment.ExitCode = 0;
@@ -4167,10 +4174,10 @@ internal static class CommandHandlers
};
}
if (!string.IsNullOrWhiteSpace(outputPath) || Console.IsOutputRedirected)
{
return TaskRunnerSimulationOutputFormat.Json;
}
if (!string.IsNullOrWhiteSpace(outputPath))
{
return TaskRunnerSimulationOutputFormat.Json;
}
return TaskRunnerSimulationOutputFormat.Table;
}
@@ -4192,10 +4199,12 @@ internal static class CommandHandlers
private static void RenderTaskRunnerSimulationResult(TaskRunnerSimulationResult result)
{
var table = new Table
{
Border = TableBorder.Rounded
};
var console = AnsiConsole.Console;
var table = new Table
{
Border = TableBorder.Rounded
};
table.AddColumn("Step");
table.AddColumn("Kind");
table.AddColumn("Status");
@@ -4217,10 +4226,10 @@ internal static class CommandHandlers
Markup.Escape(string.IsNullOrWhiteSpace(step.ApprovalId) ? "-" : step.ApprovalId!));
}
AnsiConsole.Write(table);
if (result.Outputs.Count > 0)
{
console.Write(table);
if (result.Outputs.Count > 0)
{
var outputsTable = new Table
{
Border = TableBorder.Rounded
@@ -4241,13 +4250,15 @@ internal static class CommandHandlers
Markup.Escape(string.IsNullOrWhiteSpace(output.ValueExpression) ? "-" : output.ValueExpression!));
}
AnsiConsole.WriteLine();
AnsiConsole.Write(outputsTable);
}
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine($"[grey]Plan Hash:[/] {Markup.Escape(result.PlanHash)}");
AnsiConsole.MarkupLine($"[grey]Pending Approvals:[/] {(result.HasPendingApprovals ? "yes" : "no")}");
console.WriteLine();
console.Write(outputsTable);
}
console.WriteLine();
console.MarkupLine($"[grey]Plan Hash:[/] {Markup.Escape(result.PlanHash)}");
console.MarkupLine($"[grey]Pending Approvals:[/] {(result.HasPendingApprovals ? "yes" : "no")}");
console.Write(new Text($"Plan Hash: {result.PlanHash}{Environment.NewLine}"));
console.Write(new Text($"Pending Approvals: {(result.HasPendingApprovals ? "yes" : "no")}{Environment.NewLine}"));
}
private static IEnumerable<(TaskRunnerSimulationStep Step, int Depth)> FlattenTaskRunnerSimulationSteps(