[AZ-488] UAV tile batch upload + 5-rule quality gate

Replaces the 501 stub at POST /api/satellite/upload with a multipart
batch endpoint that ingests UAV-captured tiles, runs each item through
a 5-rule quality gate, and persists accepted tiles via the AZ-484
multi-source storage path with source='uav'.

Quality gate (in fixed order, first failure wins): JPEG format
(content-type + magic), size band 5 KiB-5 MiB, exact 256x256
dimensions, captured-at age (no future >30 s skew, no older than
7 days), luminance variance on 32x32 downsample. Closed reject-reason
enumeration in v1.0.0 contract.

Authorization: custom PermissionsRequirement / PermissionsAuthorization
Handler that reads the JWT `permissions` claim (tolerates both
repeated-string and JSON-array shapes). Endpoint protected by
RequiresGpsPermission policy; 401 without token, 403 without GPS perm.

Persistence: file-first to ./tiles/uav/{z}/{x}/{y}.jpg, then
ITileRepository.InsertAsync UPSERT (per-source UPSERT contract from
AZ-484). Per-item failures reported in response without aborting the
batch. Kestrel MaxRequestBodySize and FormOptions limits set to
MaxBatchSize x MaxBytes (default 100 x 5 MiB = 500 MiB).

New frozen contract: _docs/02_document/contracts/api/uav-tile-upload.md
v1.0.0. PT-08 NFR added to performance-tests.md as Deferred (harness
work tracked in PT-07 leftover, per AZ-488 § Risk 4).

Tests: 11 quality-gate unit tests, 5 handler unit tests, 3 file-path
unit tests, 12 permission-handler unit tests, 7 integration tests
(AC-1..AC-6, AC-8). All 253 unit tests + smoke integration suite
green.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-11 23:50:49 +03:00
parent 11b7074485
commit 1802d32107
35 changed files with 2280 additions and 107 deletions
@@ -7,10 +7,12 @@ public static class StubAndErrorContractTests
{
public static async Task RunAll(HttpClient httpClient)
{
// AZ-488 retired `StubUpload_Returns501` because `/api/satellite/upload`
// now serves the real UAV-batch endpoint. The 501 contract for `/mgrs`
// and the typed-error contract for `/route` still apply.
RouteTestHelpers.PrintTestHeader("Test: Stub endpoints + error contracts (AZ-356 / AZ-353)");
await StubMgrs_Returns501(httpClient);
await StubUpload_Returns501(httpClient);
await CreateRoute_InvalidPayload_Returns400_AZ353_AC3(httpClient);
Console.WriteLine("✓ Stub + error-contract tests: PASSED");
@@ -38,36 +40,6 @@ public static class StubAndErrorContractTests
Console.WriteLine($" ✓ /api/satellite/tiles/mgrs returns HTTP 501 with ProblemDetails");
}
private static async Task StubUpload_Returns501(HttpClient httpClient)
{
Console.WriteLine();
Console.WriteLine("AZ-356 AC-1: POST /api/satellite/upload returns 501");
using var multipart = new MultipartFormDataContent
{
{ new StringContent(DateTime.UtcNow.ToString("o")), "Timestamp" },
{ new StringContent("47.461747"), "Lat" },
{ new StringContent("37.647063"), "Lon" },
{ new StringContent("100"), "Height" },
{ new StringContent("35"), "FocalLength" },
{ new StringContent("23"), "SensorWidth" },
{ new StringContent("15.6"), "SensorHeight" },
};
var fakeImage = new ByteArrayContent(new byte[] { 0xFF, 0xD8, 0xFF, 0xD9 });
fakeImage.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
multipart.Add(fakeImage, "Image", "test.jpg");
var response = await httpClient.PostAsync("/api/satellite/upload", multipart);
var status = (int)response.StatusCode;
if (status != 501)
{
throw new Exception($"Expected 501 from /api/satellite/upload, got {status}");
}
Console.WriteLine($" ✓ /api/satellite/upload returns HTTP 501");
}
private static async Task CreateRoute_InvalidPayload_Returns400_AZ353_AC3(HttpClient httpClient)
{
Console.WriteLine();