mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 23:31:15 +00:00
[AZ-484] Fix multi-source tile reads: drop Dapper enum handler
Two integration-test failures uncovered after the initial commit: 1) GetTilesByRegionAsync outer ORDER BY referenced 'updated_at' but the inner DISTINCT ON subquery aliased it to 'UpdatedAt' (Postgres folds to 'updatedat'). DISTINCT ON already guarantees one row per (latitude, longitude, ...) so the third tiebreak was unreachable; removed it. 2) Dapper 2.1.35 silently bypasses SqlMapper.TypeHandler<T> for enum types during read deserialization (Dapper issue #259). The TileSourceTypeHandler worked for writes but reads fell through to Enum.TryParse, which cannot map 'google_maps' to GoogleMaps. Pivoted: TileEntity.Source is now a string (the wire value). TileSource enum stays as the public producer surface in Common.Enums; TileSourceConverter (Common.Enums) provides ToWireValue / FromWireValue / IsValidWireValue at the boundary. TileSourceTypeHandler deleted; registration removed from DapperEnumTypeHandlers.RegisterAll. tile-storage.md Inv-5 amended to document the storage choice. _docs/LESSONS.md L-001 records the Dapper bypass for future cycles. Full suite passes (213 unit + integration suite incl. AZ-484 AC-1..AC-5, security SEC-01..SEC-04, AZ-356/362/357). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -137,107 +137,4 @@ public class EnumStringTypeHandlerTests
|
||||
DapperEnumTypeHandlers.RegisterAll();
|
||||
DapperEnumTypeHandlers.RegisterAll();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TileSource.GoogleMaps, "google_maps")]
|
||||
[InlineData(TileSource.Uav, "uav")]
|
||||
public void TileSourceHandler_SetValue_WritesContractWireValue_AZ484(TileSource value, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var handler = new TileSourceTypeHandler();
|
||||
var param = new NpgsqlParameter();
|
||||
|
||||
// Act
|
||||
handler.SetValue(param, value);
|
||||
|
||||
// Assert
|
||||
param.Value.Should().Be(expected);
|
||||
param.DbType.Should().Be(DbType.String);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("google_maps", TileSource.GoogleMaps)]
|
||||
[InlineData("GOOGLE_MAPS", TileSource.GoogleMaps)]
|
||||
[InlineData("uav", TileSource.Uav)]
|
||||
[InlineData("UAV", TileSource.Uav)]
|
||||
public void TileSourceHandler_Parse_AcceptsContractWireValue_AZ484(string raw, TileSource expected)
|
||||
{
|
||||
// Arrange
|
||||
var handler = new TileSourceTypeHandler();
|
||||
|
||||
// Act
|
||||
var result = handler.Parse(raw);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TileSource.GoogleMaps)]
|
||||
[InlineData(TileSource.Uav)]
|
||||
public void TileSourceHandler_RoundTrip_PreservesValue_AZ484(TileSource value)
|
||||
{
|
||||
// Arrange
|
||||
var handler = new TileSourceTypeHandler();
|
||||
var param = new NpgsqlParameter();
|
||||
handler.SetValue(param, value);
|
||||
|
||||
// Act
|
||||
var roundTripped = handler.Parse(param.Value!);
|
||||
|
||||
// Assert
|
||||
roundTripped.Should().Be(value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TileSourceHandler_Parse_UnknownString_ThrowsDataException_AZ484()
|
||||
{
|
||||
// Arrange
|
||||
var handler = new TileSourceTypeHandler();
|
||||
|
||||
// Act
|
||||
Action act = () => handler.Parse("satar");
|
||||
|
||||
// Assert — Inv-1: unknown sources surface, not silently coerce (coderule.mdc: never suppress errors).
|
||||
act.Should().Throw<DataException>().WithMessage("*satar*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TileSourceHandler_Parse_NullValue_ThrowsDataException_AZ484()
|
||||
{
|
||||
// Arrange
|
||||
var handler = new TileSourceTypeHandler();
|
||||
|
||||
// Act
|
||||
Action act = () => handler.Parse(null!);
|
||||
|
||||
// Assert
|
||||
act.Should().Throw<DataException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TileSourceHandler_Parse_DbNullValue_ThrowsDataException_AZ484()
|
||||
{
|
||||
// Arrange
|
||||
var handler = new TileSourceTypeHandler();
|
||||
|
||||
// Act
|
||||
Action act = () => handler.Parse(DBNull.Value);
|
||||
|
||||
// Assert
|
||||
act.Should().Throw<DataException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegisterAll_RegistersTileSourceHandler_AZ484()
|
||||
{
|
||||
// Arrange / Act
|
||||
DapperEnumTypeHandlers.RegisterAll();
|
||||
|
||||
// Assert — registration is idempotent and the handler emits the contract wire value.
|
||||
var probe = new TileSourceTypeHandler();
|
||||
var param = new NpgsqlParameter();
|
||||
probe.SetValue(param, TileSource.GoogleMaps);
|
||||
param.Value.Should().Be("google_maps");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class TileServiceTests
|
||||
FilePath = "tiles/18/0/0/cached.jpg",
|
||||
TileSizePixels = 256,
|
||||
ImageType = "jpg",
|
||||
Source = TileSource.GoogleMaps,
|
||||
Source = TileSourceConverter.ToWireValue(TileSource.GoogleMaps),
|
||||
CapturedAt = DateTime.UtcNow,
|
||||
},
|
||||
};
|
||||
@@ -151,7 +151,7 @@ public class TileServiceTests
|
||||
FilePath = "tiles/18/0/0/cached_prior_year.jpg",
|
||||
TileSizePixels = 256,
|
||||
ImageType = "jpg",
|
||||
Source = TileSource.GoogleMaps,
|
||||
Source = TileSourceConverter.ToWireValue(TileSource.GoogleMaps),
|
||||
CapturedAt = DateTime.UtcNow.AddYears(-1),
|
||||
},
|
||||
};
|
||||
@@ -276,7 +276,7 @@ public class TileServiceTests
|
||||
ImageType = "jpg",
|
||||
FilePath = "tiles/18/0/0/x.jpg",
|
||||
Version = 2026,
|
||||
Source = TileSource.GoogleMaps,
|
||||
Source = TileSourceConverter.ToWireValue(TileSource.GoogleMaps),
|
||||
CapturedAt = DateTime.UtcNow,
|
||||
};
|
||||
var tileRepo = new Mock<ITileRepository>();
|
||||
@@ -353,7 +353,7 @@ public class TileServiceTests
|
||||
TileX = x,
|
||||
TileY = y,
|
||||
FilePath = tempPath,
|
||||
Source = TileSource.GoogleMaps,
|
||||
Source = TileSourceConverter.ToWireValue(TileSource.GoogleMaps),
|
||||
CapturedAt = DateTime.UtcNow,
|
||||
});
|
||||
|
||||
@@ -484,8 +484,8 @@ public class TileServiceTests
|
||||
// Assert
|
||||
var after = DateTime.UtcNow;
|
||||
captured.Should().NotBeNull();
|
||||
captured!.Source.Should().Be(TileSource.GoogleMaps,
|
||||
"AZ-484 AC-5: the Google Maps download path stamps Source=GoogleMaps");
|
||||
captured!.Source.Should().Be(TileSourceConverter.ToWireValue(TileSource.GoogleMaps),
|
||||
"AZ-484 AC-5: the Google Maps download path stamps Source='google_maps' (contract wire value)");
|
||||
captured.CapturedAt.Kind.Should().NotBe(DateTimeKind.Local,
|
||||
"captured_at must be UTC per the v1.0.0 storage contract");
|
||||
captured.CapturedAt.Should().BeOnOrAfter(before).And.BeOnOrBefore(after,
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using FluentAssertions;
|
||||
using SatelliteProvider.Common.Enums;
|
||||
|
||||
namespace SatelliteProvider.Tests;
|
||||
|
||||
public class TileSourceConverterTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(TileSource.GoogleMaps, "google_maps")]
|
||||
[InlineData(TileSource.Uav, "uav")]
|
||||
public void ToWireValue_EmitsContractWireValue_AZ484(TileSource value, string expected)
|
||||
{
|
||||
// Act
|
||||
var result = TileSourceConverter.ToWireValue(value);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("google_maps", TileSource.GoogleMaps)]
|
||||
[InlineData("GOOGLE_MAPS", TileSource.GoogleMaps)]
|
||||
[InlineData("uav", TileSource.Uav)]
|
||||
[InlineData("UAV", TileSource.Uav)]
|
||||
public void FromWireValue_AcceptsContractWireValue_AZ484(string raw, TileSource expected)
|
||||
{
|
||||
// Act
|
||||
var result = TileSourceConverter.FromWireValue(raw);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TileSource.GoogleMaps)]
|
||||
[InlineData(TileSource.Uav)]
|
||||
public void RoundTrip_PreservesValue_AZ484(TileSource value)
|
||||
{
|
||||
// Act
|
||||
var roundTripped = TileSourceConverter.FromWireValue(TileSourceConverter.ToWireValue(value));
|
||||
|
||||
// Assert
|
||||
roundTripped.Should().Be(value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromWireValue_UnknownString_ThrowsArgumentException_AZ484()
|
||||
{
|
||||
// Act
|
||||
Action act = () => TileSourceConverter.FromWireValue("satar");
|
||||
|
||||
// Assert — Inv-1: unknown sources surface, not silently coerce (coderule.mdc: never suppress errors).
|
||||
act.Should().Throw<ArgumentException>().WithMessage("*satar*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromWireValue_NullValue_ThrowsArgumentNullException_AZ484()
|
||||
{
|
||||
// Act
|
||||
Action act = () => TileSourceConverter.FromWireValue(null!);
|
||||
|
||||
// Assert
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("google_maps", true)]
|
||||
[InlineData("uav", true)]
|
||||
[InlineData("GoogleMaps", false)]
|
||||
[InlineData("satar", false)]
|
||||
[InlineData("", false)]
|
||||
[InlineData(null, false)]
|
||||
public void IsValidWireValue_OnlyExactWireValuesPass_AZ484(string? raw, bool expected)
|
||||
{
|
||||
// Act
|
||||
var result = TileSourceConverter.IsValidWireValue(raw);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user