docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)

Comment/XML-doc changes only:
- add summaries to ~10k test methods, fixtures, fakes and helpers
  (+ <param> on theories, <returns> on async Task methods,
  <inheritdoc/> on interface implementations the checker can resolve)
- strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N,
  #NN, Component-0NN) from comments, keeping the explanatory text;
  reword false positives in comments only
- real docs on fakes implementing BCL/library interfaces
  (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime)
- reword the last 5 src/ false positives (CWE-1236, failures-1,
  year-0001, M365)

Only non-comment edits: four one-line nested classes split across lines
so members can carry docs. Build 0 errors / 0 warnings.
This commit is contained in:
Joseph Doherty
2026-10-07 15:05:49 -04:00
parent 0ffd4bdbea
commit 513fa1aa16
998 changed files with 17896 additions and 2395 deletions
@@ -63,12 +63,12 @@ public sealed class EndpointExtensionsTests : IDisposable
private const string TokenPrefix = "sbk";
private const string ApiKeyStoreSection = "ScadaBridge:InboundApi:ApiKeyStore";
// Review #1: the EXACT canonical 403 body shared by the "method not found" and
// The EXACT canonical 403 body shared by the "method not found" and
// "key not in scope" branches. Asserting against this literal (not just that the
// two bodies are equal-to-each-other) catches a single-branch divergence where
// BOTH branches change in lockstep but away from the agreed enumeration-safe
// body — the equal-to-each-other check alone would still pass in that case.
// Pinned to EndpointExtensions.NotApprovedMessage's JSON shape. Task 5 (C3): the
// Pinned to EndpointExtensions.NotApprovedMessage's JSON shape. The
// error body now additionally carries the machine-readable "code" field; both 403
// branches still emit this identical body, preserving enumeration-safety.
private const string NotApprovedBodyJson =
@@ -87,6 +87,7 @@ public sealed class EndpointExtensionsTests : IDisposable
/// </summary>
private sealed class AuditActorCapture
{
/// <summary>Gets or sets the actor captured from the request.</summary>
public string? CapturedActor { get; set; }
}
@@ -101,6 +102,8 @@ public sealed class EndpointExtensionsTests : IDisposable
};
}
/// <summary>Verifies that a valid bearer token in scope returns 200 with the script result as JSON.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task HappyPath_ValidBearerInScope_Returns200WithScriptResultJson()
{
@@ -121,6 +124,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("7", body);
}
/// <summary>Verifies that a valid X-API-Key header in scope returns 200 with the script result as JSON.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task HappyPath_ValidXApiKeyInScope_Returns200WithScriptResultJson()
{
@@ -144,6 +149,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("7", body);
}
/// <summary>Verifies that when both headers are present the Authorization header wins, so a valid bearer beats a garbage X-API-Key.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task BothHeadersPresent_AuthorizationWins_ValidBearerBeatsGarbageXApiKey()
{
@@ -172,6 +179,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("7", body);
}
/// <summary>Verifies that when both headers are present the Authorization header wins, so a garbage bearer beats a valid X-API-Key and returns 401.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task BothHeadersPresent_AuthorizationWins_GarbageBearerBeatsValidXApiKey_Returns401()
{
@@ -199,6 +208,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
/// <summary>Verifies that a request with neither header returns 401.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task NeitherHeader_Returns401()
{
@@ -220,6 +231,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
/// <summary>Verifies that a whitespace Authorization header with a valid X-API-Key returns 200.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task WhitespaceAuthorization_ValidXApiKey_Returns200()
{
@@ -245,6 +258,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("7", body);
}
/// <summary>Verifies that a garbage bearer token returns 401.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task GarbageBearer_Returns401()
{
@@ -266,6 +281,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
/// <summary>Verifies that a revoked key returns 401.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task RevokedKey_Returns401()
{
@@ -285,6 +302,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
/// <summary>Verifies that a valid key without the method in scope returns 403.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task ValidKey_MethodNotInScope_Returns403()
{
@@ -302,12 +321,14 @@ public sealed class EndpointExtensionsTests : IDisposable
var body = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
// Review #1: pin the not-in-scope body to the exact canonical literal so a
// Pin the not-in-scope body to the exact canonical literal so a
// single-branch divergence is caught here too (not only in the
// identical-bodies comparison test).
Assert.Equal(NotApprovedBodyJson, body);
}
/// <summary>Verifies that an unknown method returns 403 with a body identical to the not-in-scope body.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task UnknownMethod_Returns403_WithIdenticalBodyToNotInScope()
{
@@ -337,7 +358,7 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(HttpStatusCode.Forbidden, notInScopeResponse.StatusCode);
// The crux of the enumeration-safety invariant: identical bodies.
Assert.Equal(notInScopeBody, unknownBody);
// Review #1: pin BOTH bodies to the exact canonical literal, so a future
// Pin BOTH bodies to the exact canonical literal, so a future
// change that diverges either branch from the agreed body is caught even if
// the two branches change together (the equal-to-each-other check above
// would not catch that on its own).
@@ -345,10 +366,12 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(NotApprovedBodyJson, notInScopeBody);
}
/// <summary>Verifies that error bodies carry a machine-readable code.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task ErrorBodies_CarryMachineReadableCode()
{
// Task 5 (C3): every error body carries a machine-readable "code" field for
// Every error body carries a machine-readable "code" field for
// external integrators — UNAUTHORIZED (401), INVALID_JSON (400),
// VALIDATION_FAILED (400).
var method = SeedMethod(1, "needsParam", "return Parameters[\"value\"];",
@@ -384,6 +407,8 @@ public sealed class EndpointExtensionsTests : IDisposable
return doc.RootElement.TryGetProperty("code", out var code) ? code.GetString() : null;
}
/// <summary>Verifies that an invalid JSON body returns 400.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task InvalidJsonBody_Returns400()
{
@@ -401,6 +426,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("Invalid JSON", body);
}
/// <summary>Verifies that a missing required parameter returns 400 from the parameter validator.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task MissingRequiredParameter_Returns400_FromParameterValidator()
{
@@ -421,6 +448,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("value", body);
}
/// <summary>Verifies that a throwing script returns 500 with a sanitized error body.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task ScriptThrows_Returns500_WithSanitizedErrorBody()
{
@@ -467,6 +496,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("boom-msg", capturedDetail);
}
/// <summary>Verifies that successful authentication stashes the verified key display name on the HTTP context items.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task SuccessfulAuth_StashesVerifiedKeyDisplayNameOnHttpContextItems()
{
@@ -505,6 +536,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal("audit-actor-name", capture.CapturedActor);
}
/// <summary>Verifies that a valid request emits the inbound API request counter tagged with the resolved method name.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task ValidRequest_EmitsInboundApiRequestCounter_TaggedWithResolvedMethodName()
{
@@ -532,6 +565,8 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Equal(1, echoTotal);
}
/// <summary>Verifies that an unknown method emits the inbound API request counter with the bounded forbidden sentinel.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task UnknownMethod_EmitsInboundApiRequestCounter_WithBoundedForbiddenSentinel()
{
@@ -569,6 +604,7 @@ public sealed class EndpointExtensionsTests : IDisposable
private readonly List<(long Value, string? Method)> _measurements = new();
private readonly object _gate = new();
/// <summary>Initializes the collector and starts listening for the inbound API request counter.</summary>
public InboundApiRequestCounterCollector()
{
_listener = new MeterListener
@@ -601,6 +637,7 @@ public sealed class EndpointExtensionsTests : IDisposable
_listener.Start();
}
/// <summary>Gets a snapshot of the recorded counter measurements.</summary>
public IReadOnlyList<(long Value, string? Method)> Measurements
{
get
@@ -612,19 +649,22 @@ public sealed class EndpointExtensionsTests : IDisposable
}
}
/// <summary>Releases the resources held by the test fixture.</summary>
public void Dispose() => _listener.Dispose();
}
// --- InboundAPI-028: drive the new script-facing capabilities (Database +
// --- Drive the new script-facing capabilities (Database +
// WaitForAttribute) end-to-end through the real POST /api/{methodName} flow,
// so a wiring regression in executor→context→helper / RouteHelper is caught. ---
/// <summary>Verifies that a script using the database helper runs end to end through the endpoint.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task Script_UsingDatabase_RunsEndToEndThroughEndpoint()
{
// A method whose script reads through Database.QueryAsync — proving the executor
// builds the Database helper, resolves IDatabaseGateway from the per-execution
// DI scope, and the parameterized read reaches the body. (InboundAPI-028)
// DI scope, and the parameterized read reaches the body.
var method = SeedMethod(1, "movein",
"return await Database.QuerySingleAsync<string>(\"BTDB\", \"SELECT Code FROM Machine WHERE SAPID=@s\", new { s = (string)Parameters[\"sap\"] });",
"""[{"name":"sap","type":"String","required":true}]""");
@@ -644,12 +684,14 @@ public sealed class EndpointExtensionsTests : IDisposable
Assert.Contains("Z28061A", body);
}
/// <summary>Verifies that a script using WaitForAttribute runs end to end through the endpoint.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task Script_UsingWaitForAttribute_RunsEndToEndThroughEndpoint()
{
// A method whose script awaits Route.To(...).WaitForAttribute(...) — proving the
// executor binds the RouteHelper and the wait routes through IInstanceRouter and
// returns its result through the endpoint. (InboundAPI-028)
// returns its result through the endpoint.
var method = SeedMethod(2, "waitmethod",
"return await Route.To(\"inst-1\").WaitForAttribute(\"Flag\", true, System.TimeSpan.FromSeconds(1));");
@@ -690,6 +732,8 @@ public sealed class EndpointExtensionsTests : IDisposable
{
private readonly string _cs;
private readonly SqliteConnection _keepAlive;
/// <summary>Initializes the gateway with an in-memory SQLite connection string and seeds the machine table.</summary>
/// <param name="cs">The SQLite connection string.</param>
public SqliteGateway(string cs)
{
_cs = cs;
@@ -699,12 +743,15 @@ public sealed class EndpointExtensionsTests : IDisposable
cmd.CommandText = "CREATE TABLE IF NOT EXISTS Machine(Code TEXT, SAPID TEXT); DELETE FROM Machine; INSERT INTO Machine VALUES('Z28061A','131453');";
cmd.ExecuteNonQuery();
}
/// <inheritdoc />
public async Task<DbConnection> GetConnectionAsync(string name, CancellationToken ct = default)
{ var c = new SqliteConnection(_cs); await c.OpenAsync(ct); return c; }
/// <inheritdoc />
public Task<ExternalCallResult> CachedWriteAsync(string c, string s,
IReadOnlyDictionary<string, object?>? p = null, string? o = null, CancellationToken ct = default,
TrackedOperationId? t = null, Guid? e = null, string? src = null, Guid? pe = null)
=> throw new NotImplementedException();
/// <summary>Releases the resources held by the test fixture.</summary>
public void Dispose() => _keepAlive.Dispose();
}
@@ -836,6 +883,7 @@ public sealed class EndpointExtensionsTests : IDisposable
return await hostBuilder.StartAsync();
}
/// <summary>Releases the resources held by the test fixture.</summary>
public void Dispose()
{
try