feat: Phase 3 J/K/L (Sell Decision, Trade Execution, Portfolio Reconciliation) + fix pre-existing build/boot breakage
Completes VS-10/VS-12/VS-14 and makes the solution and Host actually
build and boot for the first time on this branch (main did not build
before this commit).
Root-cause fixes required to reach a green build/boot (not scoped to
J/K/L but blocking any verification of it):
- Restore Polly PackageVersion accidentally deleted from
Directory.Packages.props (broke KArtSell.Host).
- Remove MediatR dependency from Compliance/VS-04 (package was never
installed; ICommand/ICommandHandler/IMediator never existed) and
wire Endpoint -> Handler directly per this repo's convention.
- Migrate FastEndpoints v5 API calls (SendOkAsync/SendAsync/
SendCreatedAtAsync/SendNotFoundAsync, Description().WithName()) to
the v7 Send.* fluent API across ~10 endpoint files.
- Fix migrations 0036/0038/0039/0040: rewritten from invalid T-SQL
(`IF NOT EXISTS ... BEGIN ... END`) to idiomatic Postgres
(`CREATE TABLE/INDEX IF NOT EXISTS`) — these could not apply to any
fresh database before this fix.
- Collapse 3 duplicate cross-cutting abstractions that shadowed the
BuildingBlocks versions and caused type-mismatch compile errors:
IKrxDataService, IOutboxWriter (ReconcileTradeHandler), IClock
(ApprovalWorkflow/ApprovalPolicy).
- Inject IClock (BuildingBlocks.Time) in place of direct
DateTime.Now/UtcNow across 19 files to satisfy the architecture
test AGENTS.md#DateTime-abstraction rule (13/13 architecture tests
now pass, was 12/13).
- Register all new and previously-unregistered slices in
Program.cs DI (SellDecision, TradeExecution, PortfolioReconciliation,
Compliance, Features/ApprovalWorkflow) — the Host had never
successfully completed a boot with this code present.
- Disable ("[DontRegister]") the older, route-colliding
ApprovalWorkflow/ (Workstream H) endpoint set in favor of
Features/ApprovalWorkflow/ (Workstream G, matches the documented
Features/<Slice>/ convention); kept for its existing test coverage.
See TECH_DEBT-017 for the follow-up decision needed.
Verified: dotnet build 0 errors/0 warnings; architecture tests 13/13;
unit tests 54/54 + 18/18; integration tests 34/36 (2 failures are a
local test-DB migration-journal/schema mismatch, not a code defect);
Host boots cleanly and registers all 34 endpoints.
New tech debt recorded: DEBT-017 (duplicate VS-03 implementation),
DEBT-018 (outbox write not co-transactional with entity write in
TradeExecution/PortfolioReconciliation), DEBT-019 (duplicate
BuildingBlocks-shadowing abstractions, partially resolved).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FastEndpoints;
|
||||
using KArtSell.BuildingBlocks.Time;
|
||||
|
||||
/// <summary>
|
||||
/// Superseded by Features.ApprovalWorkflow.CreateApprovalEndpoint (same route). Kept for
|
||||
/// ApprovalWorkflowTests.cs coverage of ApprovalSql/ApprovalPolicy; excluded from route
|
||||
/// registration to avoid a duplicate-route conflict at Host startup. See TECH_DEBT_REGISTER.md.
|
||||
/// </summary>
|
||||
[DontRegister]
|
||||
public class CreateApprovalEndpoint : Endpoint<CreateApprovalProposalRequest, ApprovalProposalResponse>
|
||||
{
|
||||
private readonly CreateApprovalProposalHandler _handler;
|
||||
@@ -26,17 +33,21 @@ public class CreateApprovalEndpoint : Endpoint<CreateApprovalProposalRequest, Ap
|
||||
var userRole = User?.FindFirst("role")?.Value;
|
||||
|
||||
var response = await _handler.Handle(req, userEmail, userRole);
|
||||
await SendCreatedAtAsync<GetApprovalEndpoint>(new { id = response.Id }, response, cancellation: ct);
|
||||
await Send.CreatedAtAsync<GetApprovalEndpoint>(new { id = response.Id }, response, cancellation: ct);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Superseded by Features.ApprovalWorkflow (same route). See CreateApprovalEndpoint remarks.</summary>
|
||||
[DontRegister]
|
||||
public class ListApprovalsEndpoint : Endpoint<EmptyRequest, List<ApprovalProposalResponse>>
|
||||
{
|
||||
private readonly ApprovalSql _sql;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public ListApprovalsEndpoint(ApprovalSql sql)
|
||||
public ListApprovalsEndpoint(ApprovalSql sql, IClock clock)
|
||||
{
|
||||
_sql = sql;
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
@@ -48,7 +59,7 @@ public class ListApprovalsEndpoint : Endpoint<EmptyRequest, List<ApprovalProposa
|
||||
public override async Task HandleAsync(EmptyRequest req, CancellationToken ct)
|
||||
{
|
||||
var status = Query<string?>("status");
|
||||
var cutoff = DateTimeOffset.UtcNow;
|
||||
var cutoff = _clock.UtcNow;
|
||||
|
||||
List<ApprovalProposal> proposals;
|
||||
|
||||
@@ -75,17 +86,21 @@ public class ListApprovalsEndpoint : Endpoint<EmptyRequest, List<ApprovalProposa
|
||||
ApprovalNotes = p.ApprovalNotes
|
||||
});
|
||||
|
||||
await SendOkAsync(responses, cancellation: ct);
|
||||
await Send.OkAsync(responses, ct);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Superseded by Features.ApprovalWorkflow (same route). See CreateApprovalEndpoint remarks.</summary>
|
||||
[DontRegister]
|
||||
public class GetApprovalEndpoint : Endpoint<EmptyRequest, ApprovalProposalResponse>
|
||||
{
|
||||
private readonly ApprovalSql _sql;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public GetApprovalEndpoint(ApprovalSql sql)
|
||||
public GetApprovalEndpoint(ApprovalSql sql, IClock clock)
|
||||
{
|
||||
_sql = sql;
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
@@ -97,12 +112,12 @@ public class GetApprovalEndpoint : Endpoint<EmptyRequest, ApprovalProposalRespon
|
||||
public override async Task HandleAsync(EmptyRequest req, CancellationToken ct)
|
||||
{
|
||||
var id = Route<Guid>("id");
|
||||
var cutoff = DateTimeOffset.UtcNow;
|
||||
var cutoff = _clock.UtcNow;
|
||||
|
||||
var proposal = await _sql.GetProposalByIdAsync(id, cutoff);
|
||||
if (proposal == null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,17 +142,21 @@ public class GetApprovalEndpoint : Endpoint<EmptyRequest, ApprovalProposalRespon
|
||||
})
|
||||
};
|
||||
|
||||
await SendOkAsync(response, cancellation: ct);
|
||||
await Send.OkAsync(response, ct);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Superseded by Features.ApprovalWorkflow (same route). See CreateApprovalEndpoint remarks.</summary>
|
||||
[DontRegister]
|
||||
public class ApproveApprovalEndpoint : Endpoint<ApproveApprovalRequest, ApprovalProposalResponse>
|
||||
{
|
||||
private readonly ApproveApprovalHandler _handler;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public ApproveApprovalEndpoint(ApproveApprovalHandler handler)
|
||||
public ApproveApprovalEndpoint(ApproveApprovalHandler handler, IClock clock)
|
||||
{
|
||||
_handler = handler;
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
public override void Configure()
|
||||
@@ -150,9 +169,9 @@ public class ApproveApprovalEndpoint : Endpoint<ApproveApprovalRequest, Approval
|
||||
{
|
||||
var id = Route<Guid>("id");
|
||||
var checkerEmail = User?.FindFirst("email")?.Value ?? "system@kartsell.local";
|
||||
var cutoff = DateTimeOffset.UtcNow;
|
||||
var cutoff = _clock.UtcNow;
|
||||
|
||||
var response = await _handler.Handle(id, req, checkerEmail, cutoff);
|
||||
await SendOkAsync(response, cancellation: ct);
|
||||
await Send.OkAsync(response, ct);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class ActivateApprovalHandler
|
||||
|
||||
public async Task Handle(Guid proposalId, string sreEmail, string? userRole, DateTimeOffset cutoff)
|
||||
{
|
||||
if (!_policy.CanActivateApproval(new ApprovalProposal(), userRole))
|
||||
if (!_policy.CanActivateApproval(new ApprovalProposal { CreatedBy = string.Empty, Justification = string.Empty }, userRole ?? string.Empty))
|
||||
throw new UnauthorizedAccessException("Only SRE can activate approvals");
|
||||
|
||||
var proposal = await _sql.GetProposalByIdAsync(proposalId, cutoff)
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace KArtSell.Modules.ModelOperations.ApprovalWorkflow;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KArtSell.BuildingBlocks.Time;
|
||||
|
||||
public class ApprovalPolicy
|
||||
{
|
||||
@@ -57,10 +58,10 @@ public class ApprovalPolicy
|
||||
ModelId = modelId,
|
||||
Status = ApprovalStatus.Draft,
|
||||
CreatedBy = createdBy,
|
||||
CreatedAt = _clock.Now,
|
||||
CreatedAt = _clock.UtcNow,
|
||||
Justification = justification,
|
||||
EffectiveAt = effectiveAt,
|
||||
PublishedAt = _clock.Now,
|
||||
PublishedAt = _clock.UtcNow,
|
||||
Revision = 1,
|
||||
CorrelationId = Guid.NewGuid()
|
||||
};
|
||||
@@ -72,9 +73,9 @@ public class ApprovalPolicy
|
||||
throw new InvalidOperationException("Only the creator can propose their own approval");
|
||||
|
||||
proposal.Status = ApprovalStatus.Proposed;
|
||||
proposal.ProposedAt = _clock.Now;
|
||||
proposal.ProposedAt = _clock.UtcNow;
|
||||
proposal.Revision++;
|
||||
proposal.PublishedAt = _clock.Now;
|
||||
proposal.PublishedAt = _clock.UtcNow;
|
||||
|
||||
return proposal;
|
||||
}
|
||||
@@ -90,10 +91,10 @@ public class ApprovalPolicy
|
||||
|
||||
proposal.Status = ApprovalStatus.Approved;
|
||||
proposal.ApprovedBy = checkerEmail;
|
||||
proposal.ApprovedAt = _clock.Now;
|
||||
proposal.ApprovedAt = _clock.UtcNow;
|
||||
proposal.ApprovalNotes = approvalNotes;
|
||||
proposal.Revision++;
|
||||
proposal.PublishedAt = _clock.Now;
|
||||
proposal.PublishedAt = _clock.UtcNow;
|
||||
|
||||
// Add evidence
|
||||
foreach (var evt in evidence)
|
||||
@@ -105,7 +106,7 @@ public class ApprovalPolicy
|
||||
EvidenceType = evt.Type,
|
||||
EvidenceUrl = evt.Url,
|
||||
ReviewerComment = evt.Comment,
|
||||
PublishedAt = _clock.Now,
|
||||
PublishedAt = _clock.UtcNow,
|
||||
CorrelationId = proposal.CorrelationId
|
||||
});
|
||||
}
|
||||
@@ -120,9 +121,9 @@ public class ApprovalPolicy
|
||||
|
||||
proposal.Status = ApprovalStatus.Active;
|
||||
proposal.ActivatedBy = sreEmail;
|
||||
proposal.ActivatedAt = _clock.Now;
|
||||
proposal.ActivatedAt = _clock.UtcNow;
|
||||
proposal.Revision++;
|
||||
proposal.PublishedAt = _clock.Now;
|
||||
proposal.PublishedAt = _clock.UtcNow;
|
||||
|
||||
return proposal;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ public class ApprovalPolicy
|
||||
proposal.Status = ApprovalStatus.Rejected;
|
||||
proposal.ApprovalNotes = $"Rejected: {rejectionReason}";
|
||||
proposal.Revision++;
|
||||
proposal.PublishedAt = _clock.Now;
|
||||
proposal.PublishedAt = _clock.UtcNow;
|
||||
|
||||
return proposal;
|
||||
}
|
||||
@@ -152,20 +153,10 @@ public class ApprovalPolicy
|
||||
ApprovalProposalId = proposal.Id,
|
||||
EventType = eventType,
|
||||
ActorEmail = actorEmail,
|
||||
EventAt = _clock.Now,
|
||||
EventAt = _clock.UtcNow,
|
||||
Details = details,
|
||||
PublishedAt = _clock.Now,
|
||||
PublishedAt = _clock.UtcNow,
|
||||
CorrelationId = proposal.CorrelationId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public interface IClock
|
||||
{
|
||||
DateTimeOffset Now { get; }
|
||||
}
|
||||
|
||||
public class SystemClock : IClock
|
||||
{
|
||||
public DateTimeOffset Now => DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
@@ -7,15 +7,18 @@ using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using KArtSell.BuildingBlocks.Time;
|
||||
using Npgsql;
|
||||
|
||||
public class ApprovalSql
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
private readonly IClock _clock;
|
||||
|
||||
public ApprovalSql(string connectionString)
|
||||
public ApprovalSql(string connectionString, IClock clock)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_clock = clock;
|
||||
}
|
||||
|
||||
public async Task<ApprovalProposal?> GetProposalByIdAsync(Guid id, DateTimeOffset cutoff)
|
||||
@@ -75,7 +78,7 @@ public class ApprovalSql
|
||||
modelId,
|
||||
status,
|
||||
createdBy,
|
||||
createdAt = DateTimeOffset.UtcNow,
|
||||
createdAt = _clock.UtcNow,
|
||||
justification,
|
||||
effectiveAt,
|
||||
publishedAt,
|
||||
@@ -102,7 +105,7 @@ public class ApprovalSql
|
||||
id,
|
||||
newStatus,
|
||||
approvedBy,
|
||||
approvedAt = DateTimeOffset.UtcNow,
|
||||
approvedAt = _clock.UtcNow,
|
||||
approvalNotes,
|
||||
publishedAt
|
||||
});
|
||||
@@ -124,7 +127,7 @@ public class ApprovalSql
|
||||
evidenceType,
|
||||
evidenceUrl,
|
||||
comment,
|
||||
publishedAt = DateTimeOffset.UtcNow,
|
||||
publishedAt = _clock.UtcNow,
|
||||
correlationId
|
||||
});
|
||||
}
|
||||
@@ -146,9 +149,9 @@ public class ApprovalSql
|
||||
proposalId,
|
||||
eventType,
|
||||
actorEmail,
|
||||
eventAt = DateTimeOffset.UtcNow,
|
||||
eventAt = _clock.UtcNow,
|
||||
details = detailsJson,
|
||||
publishedAt = DateTimeOffset.UtcNow,
|
||||
publishedAt = _clock.UtcNow,
|
||||
correlationId
|
||||
});
|
||||
}
|
||||
@@ -191,7 +194,7 @@ public class ApprovalSql
|
||||
};
|
||||
}
|
||||
|
||||
private class ApprovalProposalRaw
|
||||
private sealed class ApprovalProposalRaw
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid ModelId { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user