fix: Release build breakage + Dapper mapping bugs in VS-03/VS-04/Phase3-K

- KArtSell.Host.csproj: FrontendFiles glob was evaluated at project-load
  time, before pnpm build ran, so it copied stale/missing Vite-hashed
  filenames every Release build. Move the glob inside the target, after
  the build Exec.
- ApprovalSql/AuditSql/TradeSql: fix live-DB integration failures never
  caught by unit tests: DateOnly and inet columns can't be bound/read
  directly through Dapper without conversion; kis_response (jsonb) read
  as JsonElement threw InvalidCastException; GdprRetention.RetentionEndsAt
  was typed DateTime against a DATE column.
- TradeSql: UpdateTradeStatusAsync only ever persisted status/kis_response
  /error_message, silently dropping kis_order_id, executed_quantity,
  unit_price, total_amount, commission, net_proceeds and the execution/
  settlement timestamps on every call. Changed it to take the Trade
  aggregate so the full state transition persists.
- TradeSql: add a static ctor setting Dapper.DefaultTypeMap.
  MatchNamesWithUnderscores = true. The repo's [ModuleInitializer] in
  KArtSell.BuildingBlocks only fires once that assembly is actually
  loaded; TradeSql/Trade never reference a BuildingBlocks type, so under
  test isolation (or any host that queries a trade before touching
  BuildingBlocks) every snake_case column silently mapped to null/default.
- Test fixes: seed the FK prerequisites (model_operations.models,
  sell_decisions) that ApprovalWorkflowTests/TradeExecutionTests were
  missing, correct a SellPriorityRanker test input to match the approved
  VS-10-SLICE_SPEC age-boost threshold, and fix a GDPR redaction
  assertion that called ToString() on a Dictionary instead of inspecting
  its values.

12 DbUpMigrationTests failures remain and are unrelated to this fix: the
kartsell DB user isn't the owner of kartsell_migration_test, so DbUp's
fresh-database rehearsal can't DROP/CREATE it. Needs a DBA grant.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-08-07 23:21:04 +09:00
parent 54b7922167
commit 2ccf74c410
11 changed files with 119 additions and 92 deletions
@@ -57,14 +57,7 @@ public class SubmitTradeHandler
);
trade.MarkSubmitted(orderId, response);
await _sql.UpdateTradeStatusAsync(
trade.Id,
TradeStatus.Submitted,
response,
null,
command.CorrelationId,
ct
);
await _sql.UpdateTradeStatusAsync(trade, response, null, ct);
await PublishEventAsync(
"TradeSubmitted",
@@ -84,14 +77,7 @@ public class SubmitTradeHandler
catch (KisTradeExecutionException ex)
{
trade.MarkErrored(ex);
await _sql.UpdateTradeStatusAsync(
trade.Id,
trade.Status,
ex.KisResponse,
ex.Message,
command.CorrelationId,
ct
);
await _sql.UpdateTradeStatusAsync(trade, ex.KisResponse, ex.Message, ct);
_logger.LogError(
"Trade submission failed: {TradeId} {Classification}",
@@ -163,14 +149,7 @@ public class PollTradeStatusHandler
trade.MarkFilled(executedQty, unitPrice, response, _clock.UtcNow.UtcDateTime);
}
await _sql.UpdateTradeStatusAsync(
trade.Id,
trade.Status,
response,
null,
command.CorrelationId,
ct
);
await _sql.UpdateTradeStatusAsync(trade, response, null, ct);
if (trade.Status is TradeStatus.FullyFilled)
{
@@ -195,14 +174,7 @@ public class PollTradeStatusHandler
}
catch (KisTradeExecutionException ex)
{
await _sql.UpdateTradeStatusAsync(
trade.Id,
trade.Status,
ex.KisResponse,
ex.Message,
command.CorrelationId,
ct
);
await _sql.UpdateTradeStatusAsync(trade, ex.KisResponse, ex.Message, ct);
_logger.LogError("Failed to poll trade status: {TradeId}", trade.Id);
}
@@ -262,14 +234,7 @@ public class ConfirmSettlementHandler
if (success)
{
trade.MarkConfirmed(_clock.UtcNow.UtcDateTime, command.Commission);
await _sql.UpdateTradeStatusAsync(
trade.Id,
TradeStatus.Confirmed,
response,
null,
command.CorrelationId,
ct
);
await _sql.UpdateTradeStatusAsync(trade, response, null, ct);
await TradeOutboxPublisher.PublishAsync(
_connectionFactory,
@@ -290,14 +255,7 @@ public class ConfirmSettlementHandler
}
catch (KisTradeExecutionException ex)
{
await _sql.UpdateTradeStatusAsync(
trade.Id,
trade.Status,
ex.KisResponse,
ex.Message,
command.CorrelationId,
ct
);
await _sql.UpdateTradeStatusAsync(trade, ex.KisResponse, ex.Message, ct);
_logger.LogError("Failed to confirm settlement: {TradeId}", trade.Id);
}