feat(cli): scadalink audit verify-chain subcommand v1 no-op (#23 M8)
This commit is contained in:
@@ -25,15 +25,38 @@ internal static class AuditCommandTestHarness
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses and invokes the command tree, capturing output from both channels the CLI
|
||||||
|
/// uses: System.CommandLine's parser diagnostics flow through the
|
||||||
|
/// <see cref="InvocationConfiguration"/> writers, while command actions write through
|
||||||
|
/// <see cref="Console"/> (consistent with the rest of the CLI). Both are merged into
|
||||||
|
/// the returned <c>Out</c>/<c>Err</c> strings. Callers must be in the <c>Console</c>
|
||||||
|
/// xUnit collection so the global <see cref="Console"/> redirect is not racy.
|
||||||
|
/// </summary>
|
||||||
public static (int Exit, string Out, string Err) Invoke(RootCommand root, params string[] args)
|
public static (int Exit, string Out, string Err) Invoke(RootCommand root, params string[] args)
|
||||||
{
|
{
|
||||||
var output = new StringWriter();
|
var output = new StringWriter();
|
||||||
var error = new StringWriter();
|
var error = new StringWriter();
|
||||||
var exit = root.Parse(args).Invoke(new InvocationConfiguration
|
|
||||||
|
var originalOut = Console.Out;
|
||||||
|
var originalErr = Console.Error;
|
||||||
|
Console.SetOut(output);
|
||||||
|
Console.SetError(error);
|
||||||
|
int exit;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Output = output,
|
exit = root.Parse(args).Invoke(new InvocationConfiguration
|
||||||
Error = error,
|
{
|
||||||
});
|
Output = output,
|
||||||
|
Error = error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Console.SetOut(originalOut);
|
||||||
|
Console.SetError(originalErr);
|
||||||
|
}
|
||||||
|
|
||||||
return (exit, output.ToString(), error.ToString());
|
return (exit, output.ToString(), error.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace ScadaLink.CLI.Tests.Commands;
|
|||||||
/// required-flag enforcement, query-string construction, streaming the response body
|
/// required-flag enforcement, query-string construction, streaming the response body
|
||||||
/// to the output file, and the parquet-not-implemented (501) path.
|
/// to the output file, and the parquet-not-implemented (501) path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Collection("Console")]
|
||||||
public class AuditExportCommandTests
|
public class AuditExportCommandTests
|
||||||
{
|
{
|
||||||
// ---- CLI parsing: required flags --------------------------------------
|
// ---- CLI parsing: required flags --------------------------------------
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace ScadaLink.CLI.Tests.Commands;
|
|||||||
/// time-spec resolution, query-string construction, formatter selection, error
|
/// time-spec resolution, query-string construction, formatter selection, error
|
||||||
/// handling, and keyset-cursor paging via <c>--all</c>.
|
/// handling, and keyset-cursor paging via <c>--all</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Collection("Console")]
|
||||||
public class AuditQueryCommandTests
|
public class AuditQueryCommandTests
|
||||||
{
|
{
|
||||||
// ---- Time-spec parsing -------------------------------------------------
|
// ---- Time-spec parsing -------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using ScadaLink.CLI.Commands;
|
||||||
|
|
||||||
|
namespace ScadaLink.CLI.Tests.Commands;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests for the <c>scadalink audit verify-chain</c> subcommand (Audit Log #23 M8-T4).
|
||||||
|
/// v1 is a no-op stub: a valid <c>--month</c> prints the documented "not enabled"
|
||||||
|
/// message and exits 0; a malformed month or a missing <c>--month</c> exits non-zero.
|
||||||
|
/// </summary>
|
||||||
|
[Collection("Console")]
|
||||||
|
public class AuditVerifyChainCommandTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void VerifyChain_ValidMonth_ExitsZeroWithDocumentedMessage()
|
||||||
|
{
|
||||||
|
var root = AuditCommandTestHarness.BuildRoot();
|
||||||
|
var (exit, output, _) = AuditCommandTestHarness.Invoke(
|
||||||
|
root, "audit", "verify-chain", "--month", "2026-05");
|
||||||
|
|
||||||
|
Assert.Equal(0, exit);
|
||||||
|
Assert.Contains("Hash-chain tamper-evidence is not enabled", output);
|
||||||
|
Assert.Contains("Component-AuditLog.md", output);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void VerifyChain_MalformedMonth_ExitsNonZero()
|
||||||
|
{
|
||||||
|
var root = AuditCommandTestHarness.BuildRoot();
|
||||||
|
var (exit, _, _) = AuditCommandTestHarness.Invoke(
|
||||||
|
root, "audit", "verify-chain", "--month", "2026-13");
|
||||||
|
|
||||||
|
Assert.NotEqual(0, exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void VerifyChain_MissingMonth_ProducesRequiredFlagError()
|
||||||
|
{
|
||||||
|
var root = AuditCommandTestHarness.BuildRoot();
|
||||||
|
var (exit, _, err) = AuditCommandTestHarness.Invoke(root, "audit", "verify-chain");
|
||||||
|
|
||||||
|
Assert.NotEqual(0, exit);
|
||||||
|
Assert.Contains("--month", err);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("2026-05", true)]
|
||||||
|
[InlineData("2026-01", true)]
|
||||||
|
[InlineData("2026-12", true)]
|
||||||
|
[InlineData("2026-13", false)]
|
||||||
|
[InlineData("2026-00", false)]
|
||||||
|
[InlineData("2026-5", false)]
|
||||||
|
[InlineData("not-a-month", false)]
|
||||||
|
[InlineData("", false)]
|
||||||
|
public void IsValidMonth_ValidatesYyyyMm(string month, bool expected)
|
||||||
|
{
|
||||||
|
Assert.Equal(expected, AuditVerifyChainHelpers.IsValidMonth(month));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user