Files
Oleksandr Bezdieniezhnykh ccd85a09df
ci/woodpecker/push/build-arm Pipeline failed
[AZ-576] Add e2e test infrastructure (xUnit + jwks-mock + reporting)
Scaffold the blackbox test project the rest of epic AZ-575 (AZ-577..AZ-586)
will build on. Two new csprojs under tests/, plus the TLS materials and
TRX->CSV reporting hand-off the existing docker-compose.test.yml already
calls for.

JWKS mock (tests/Azaion.Missions.JwksMock/):
- ASP.NET Core minimal API on .NET 10, no NuGet deps; JWS is hand-rolled
  to keep the surface tight and avoid version drift with the SUT
- KeyStore with one in-memory ECDSA P-256 keypair + retired-key grace
  window for NFT-RES-07 / NFT-SEC-11 rotation observability
- Endpoints: GET /.well-known/jwks.json, POST /sign, POST /rotate-key
- Mock-only alg_override / kid_override switches drive NFT-SEC-09/10/11
- TLS keypair committed under tls/; tests/jwks-mock-ca.crt is a copy
  mounted into both missions and e2e-consumer per docker-compose.test.yml

E2E consumer (tests/Azaion.Missions.E2E.Tests/):
- xUnit 2.9.2 + Bogus 35.6.1 + Npgsql 10.0.2 + Xunit.SkippableFact 1.4.13
- TestBase / TokenMinter scaffolding for downstream tasks
- Fixtures/ for DbReset, DbSeed, ComposeRestart, JwksRotate, JwksMockReverse
- Helpers/ for DbAssertions (side-channel), HttpAssertions, FixtureSql
- 8 Tests/<category>/Sanity.cs discovery smoke tests (AC-3)
- Tests/InfrastructureSanity.cs SkippableFacts for AC-1/2/5/6
- Tests/AaaPatternEnforcement.cs greps source files for AC-7
- Tests/Reporting/TrxToCsvPostProcessorTests.cs covers AC-4
- Reporting/TrxToCsvPostProcessor.cs handles VSTest TRX -> environment.md
  CSV; xUnit traits are not propagated by the TRX logger so the converter
  reflects them out of the test DLL via GetCustomAttributesData
- Reporting.Cli/ is a separate console csproj that links the converter
  source files (test project excludes Reporting.Cli/** from compile)
- Dockerfile + entrypoint.sh wire dotnet test -> trx -> csv inside the
  e2e-consumer container the compose file already references

Local verification: 13 pass, 3 skip (with explicit reasons), 0 fail.
End-to-end TRX->CSV manually verified against environment.md header spec.
Docker stack build is handed off to autodev Step 7 (test-run skill).

Reports under _docs/03_implementation/.
AZ-576 task spec moved to _docs/tasks/done/.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-15 06:57:40 +03:00

82 lines
3.2 KiB
C#

using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Xunit;
namespace Azaion.Missions.E2E.Tests;
/// <summary>
/// Enforces AC-7 of AZ-576 — every <c>[Fact]</c> / <c>[Theory]</c> method
/// under <c>tests/Azaion.Missions.E2E.Tests/Tests/</c> contains the literal
/// AAA marker comments in order.
/// </summary>
/// <remarks>
/// The check uses regex over source files rather than Roslyn — it is meant
/// to be a cheap sentinel test, not a full analyzer. Empty &quot;Arrange&quot;
/// blocks may be omitted (the spec allows it); &quot;Act&quot; and &quot;Assert&quot;
/// are mandatory and must appear in that order.
/// </remarks>
public sealed partial class AaaPatternEnforcement
{
[Fact]
[Trait("Category", "Blackbox")]
[Trait("Traces", "AC-7")]
public void Every_test_method_under_Tests_uses_AAA_markers()
{
// Arrange
var testsDir = LocateTestsDir();
var sourceFiles = Directory.GetFiles(testsDir, "*.cs", SearchOption.AllDirectories);
Assert.NotEmpty(sourceFiles);
var failures = new List<string>();
// Act
foreach (var file in sourceFiles)
{
var src = File.ReadAllText(file);
foreach (Match match in TestMethodRegex().Matches(src))
{
var methodName = match.Groups["name"].Value;
var body = match.Groups["body"].Value;
var actIdx = body.IndexOf("// Act", StringComparison.Ordinal);
var assertIdx = body.IndexOf("// Assert", StringComparison.Ordinal);
var arrangeIdx = body.IndexOf("// Arrange", StringComparison.Ordinal);
if (actIdx < 0 || assertIdx < 0)
{
failures.Add($"{Path.GetFileName(file)}::{methodName} missing // Act and/or // Assert");
continue;
}
if (assertIdx < actIdx)
{
failures.Add($"{Path.GetFileName(file)}::{methodName} // Assert appears before // Act");
continue;
}
if (arrangeIdx >= 0 && arrangeIdx > actIdx)
{
failures.Add($"{Path.GetFileName(file)}::{methodName} // Arrange appears after // Act");
}
}
}
// Assert
Assert.True(failures.Count == 0,
"AAA markers missing or out-of-order:\n " + string.Join("\n ", failures));
}
[GeneratedRegex(
@"\[(?:Fact|Theory)(?:\s*,\s*\w+(?:\([^)]*\))?)*\][^{}]*?(?:\[[^\]]*\][^{}]*?)*public\s+(?:async\s+)?(?:void|Task)\s+(?<name>\w+)\s*\([^)]*\)\s*(?<body>\{(?:[^{}]|(?<o>\{)|(?<-o>\}))*(?(o)(?!))\})",
RegexOptions.Singleline | RegexOptions.CultureInvariant)]
private static partial Regex TestMethodRegex();
private static string LocateTestsDir([CallerFilePath] string thisFile = "")
{
// thisFile is .../tests/Azaion.Missions.E2E.Tests/Tests/AaaPatternEnforcement.cs
var dir = Path.GetDirectoryName(thisFile);
if (dir is null || !Directory.Exists(dir))
throw new DirectoryNotFoundException(
$"Could not locate Tests/ directory from CallerFilePath '{thisFile}'");
return dir;
}
}