[AZ-286] [AZ-287] [AZ-288] Service-level unit tests (mocked deps)

Batch 2: 27 new tests, 31/31 total passing.

AZ-286 TileService (9 tests):
- BT-01 download stores tiles via repository
- BT-02 cache reuse passes existing tiles to downloader
- BT-02b stale-version cached tiles are NOT treated as still-valid
- BT-N02 GoogleMapsDownloaderV2 rejects zoom levels not in {15..19}
- GetTileAsync known/unknown id

AZ-287 RegionService (6 tests):
- AC-1 RequestRegionAsync inserts entity and queues request
- AC-2/AC-3 ProcessRegionAsync transitions queued→processing→completed
  and writes CSV + summary files
- AC-4 stitch path is set when stitchTiles=true
- ProcessRegionAsync handles RateLimitException by writing failed
  summary with the error message preserved
- GetRegionStatusAsync mapping
- Missing region id is logged and short-circuits without DB writes

AZ-288 RouteService (12 tests):
- AC-1 every consecutive pair is ≤200m apart on 2-point route
- AC-2 first/last user points keep their roles; middles are interpolated
- BT-10 10pt route → 1 start, 1 end, 8 action, plus intermediates
- BT-12 20pt route → 1 start, 1 end, 18 action
- AC-3 TotalDistanceMeters == Σ Haversine(point[i-1], point[i])
- BT-N03 < 2 points throws ArgumentException
- regionSize <100 / >10000 throws ArgumentException
- BT-N04 (0,0) corner throws
- BT-N05 inverted NW.lat <= SE.lat throws
- BT-11 valid geofence creates region requests + links them with
  isGeofence=true
- BT-07 GetRouteAsync returns route + points
- GetRouteAsync unknown id returns null

Code review: PASS_WITH_WARNINGS — 3 Low Spec-Gap findings:
  1. BT-N01 (invalid coords) deferred to AZ-289 integration tests
     (TileService doesn't validate coordinates — API-layer concern)
  2. Point-type label drift between blackbox-tests.md ("original")
     and code ("start"/"action"/"end")
  3. Region status drift: spec "pending" vs code "queued" — initial
     state on insert

Verification: docker dotnet test — 31/31 pass in 0.83s.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-10 05:02:00 +03:00
parent 3d112c0f47
commit dea0b8b4c0
9 changed files with 965 additions and 2 deletions
@@ -0,0 +1,55 @@
# Batch Report
**Batch**: 2
**Tasks**: AZ-286 (TileService), AZ-287 (RegionService), AZ-288 (RouteService)
**Date**: 2026-05-10
**Cycle**: 1
**Mode**: Test implementation (existing-code Step 6)
## Task Results
| Task | Status | Files Modified | Tests | AC Coverage | Issues |
|------|--------|----------------|-------|-------------|--------|
| AZ-286_tile_service_tests | Done | 1 file (TileServiceTests.cs) | 9/9 pass | AC-1: 3/4 (BT-N01 deferred), AC-2 ✓, AC-3 ✓ | 1 Low Spec-Gap (BT-N01) |
| AZ-287_region_service_tests | Done | 1 file (RegionServiceTests.cs) | 6/6 pass | AC-1 ✓, AC-2 ✓, AC-3 ✓, AC-4 ✓ | 1 Low Spec-Gap (status naming drift) |
| AZ-288_route_service_tests | Done | 1 file (RouteServiceTests.cs) | 12/12 pass | AC-1 ✓, AC-2 ✓, AC-3 ✓, AC-4 ✓ | 1 Low Spec-Gap (point-type naming drift) |
## Files Changed
- `SatelliteProvider.Tests/TileServiceTests.cs` — new (BT-01, BT-02, BT-02b stale-version, BT-N02 zoom validation)
- `SatelliteProvider.Tests/RegionServiceTests.cs` — new (BT-03 AC1, BT-03 AC2/AC3, BT-05 AC4, missing region, RateLimit error path)
- `SatelliteProvider.Tests/RouteServiceTests.cs` — new (BT-06 spacing + types, BT-07, BT-10, BT-12, AC3 distance, BT-11 geofence, BT-N03/N04/N05)
## AC Test Coverage
- BT-N01 deferred to AZ-289 integration tests (TileService does not validate coordinates — API-layer concern).
- All other ACs across AZ-286/287/288 are covered.
## Code Review Verdict: PASS_WITH_WARNINGS
3 Low Spec-Gap findings (deferred BT-N01, point-type naming drift, status naming drift).
See `_docs/03_implementation/reviews/batch_02_review.md`.
## Auto-Fix Attempts: 0
## Stuck Agents: None
## Tracker Status
- AZ-286: To Do → In Progress (start) → In Testing (after commit)
- AZ-287: To Do → In Progress (start) → In Testing (after commit)
- AZ-288: To Do → In Progress (start) → In Testing (after commit)
## Test Run
- Tests discovered: 31 (Batch 1 + Batch 2)
- Passed: 31 / 31
- Total time: 0.83s
## Cumulative Review
K=3 default → cumulative review trigger after Batch 3. Skipping for now.
## Next Batch
Batch 3: AZ-289 (integration: route map processing + ZIP) + AZ-290 (non-functional: perf, resilience, security, limits) — 5 points.
@@ -0,0 +1,65 @@
# Code Review Report
**Batch**: 2 — AZ-286 + AZ-287 + AZ-288 (TileService / RegionService / RouteService unit tests)
**Date**: 2026-05-10
**Verdict**: PASS_WITH_WARNINGS
## Findings
| # | Severity | Category | File:Line | Title |
|---|----------|----------|-----------|-------|
| 1 | Low | Spec-Gap | (deferred) | BT-N01 (invalid coords) not unit-tested — TileService does not validate lat/lon |
| 2 | Low | Spec-Gap | (docs) | Point-type label drift between blackbox-tests.md ("original"/"intermediate") and code ("start"/"action"/"end"/"intermediate") |
| 3 | Low | Spec-Gap | (docs) | Region status drift: blackbox-tests.md "pending → processing → completed" vs code "queued → processing → completed" |
### Finding Details
**F1: BT-N01 not service-unit-tested** (Low / Spec-Gap)
- Location: out-of-scope for `TileService`
- Description: AZ-286 lists BT-N01 (invalid lat/lon) but neither `TileService.DownloadAndStoreTilesAsync` nor `GoogleMapsDownloaderV2.DownloadSingleTileAsync` validates coordinate ranges. Validation lives at the API endpoint layer (`Program.cs`).
- Suggestion: Cover BT-N01 in AZ-289 (integration tests) which exercises the HTTP API. Optionally add API-layer validation in a future testability/refactor step.
- Tasks: AZ-286, AZ-289
**F2: Point-type label drift** (Low / Spec-Gap)
- Location: `_docs/02_document/tests/blackbox-tests.md` BT-06 / BT-10 / BT-12 vs `SatelliteProvider.Services/RouteService.cs:66`
- Description: Test spec says first/last point type is `original`. Code emits `start` / `action` / `end` for user-supplied points and `intermediate` for interpolated. The spec's "original" appears to be a generic term for "user-supplied", which does not match any actual code value. RouteService unit tests assert the actual code values to keep tests honest.
- Suggestion: Update `blackbox-tests.md` BT-06/BT-10/BT-12/BT-N* phrasing OR introduce an "original" alias in code. Either option is harmless but should be tracked. The traceability matrix should be updated to reflect the chosen wording.
- Task: AZ-288 (and downstream test-spec sync in Step 12)
**F3: Region status string drift** (Low / Spec-Gap)
- Location: `_docs/02_document/tests/blackbox-tests.md` BT-03/BT-04 vs `SatelliteProvider.Services/RegionService.cs:48` (initial state = `"queued"`)
- Description: Spec uses "pending → processing → completed". Code uses "queued → processing → completed". Tests assert the code's actual transitions.
- Suggestion: Update test-spec to match code, or add a `"pending"` alias in code. Same trade-off as F2. Track in test-spec sync (Step 12).
- Task: AZ-287
## Phase Summary
- **Phase 1 (Context)**: AZ-286/287/288 specs loaded; ACs identified.
- **Phase 2 (Spec compliance)**:
- AZ-286 AC-1: 3/4 (BT-01 ✓, BT-02 ✓ + BT-02b stale-version, BT-N02 ✓; BT-N01 deferred → F1).
- AZ-286 AC-2: ✓ (`ISatelliteDownloader` is mocked everywhere; no real Google Maps).
- AZ-286 AC-3: ✓ (happy path + cache reuse + zoom validation negative).
- AZ-287 AC-1: ✓ (`RequestRegionAsync_InsertsEntityAndQueues_BT03_AC1`).
- AZ-287 AC-2: ✓ (`ProcessRegionAsync_HappyPath_TransitionsToCompletedAndWritesArtifacts_BT03_AC2_AC3` — verifies "processing → completed"; initial "queued" is set in `RequestRegionAsync`).
- AZ-287 AC-3: ✓ (CSV + summary files asserted on disk).
- AZ-287 AC-4: ✓ (`ProcessRegionAsync_StitchEnabled_SetsStitchedImagePath_BT05_AC4`).
- AZ-288 AC-1: ✓ (≤200m spacing iterated and verified).
- AZ-288 AC-2: ✓ (start/end/action/intermediate counts verified — see F2).
- AZ-288 AC-3: ✓ (`ComputesTotalDistanceViaHaversine_AC3` cross-checks `TotalDistanceMeters` against summed Haversine distances).
- AZ-288 AC-4: ✓ (BT-N03 < 2 points, region-size validation, BT-N04, BT-N05).
- **Phase 3 (Quality)**: tests follow Arrange/Act/Assert; helpers (`BuildService`, `BuildRequest`, `MakeDownloaded`) keep arrange sections small; no duplication.
- **Phase 4 (Security)**: no secrets, no injection vectors. The mock API key `"test-key"` in `GoogleMapsDownloaderZoomValidationTests` never escapes the test (no HTTP performed).
- **Phase 5 (Performance)**: tests run in <1s total — no anti-patterns.
- **Phase 6 (Cross-task)**: shared fixtures (`TestCoordinates`) used uniformly. Mock setups consistent across test files.
- **Phase 7 (Architecture)**: tests sit in `SatelliteProvider.Tests/` and consume only Public API of Common, DataAccess, Services per `module-layout.md`. No layering violation. No new cycles. No duplicate symbols.
## Test Run
Container: `mcr.microsoft.com/dotnet/sdk:8.0`
- Tests discovered: 31 (4 from Batch 1 + 27 new in Batch 2)
- Passed: 31 / 31
- Total time: 0.83s
## Verdict Logic
3 Low findings, 0 Medium, 0 High, 0 Critical → PASS_WITH_WARNINGS.