MR !1114

Draft: feat(commissions): wallets and calulcation pipelines @marsav · 2026-06-21

REQUEST CHANGES

Merge Request Info

Field Value
Title Draft: feat(commissions): wallets and calulcation pipelines
Author @marsav
Reviewers @blaskom
Branch feature/3912-wallets -> main
Labels none
Created 2026-06-16
Pipeline Passed (45614)
Conflicts No
State opened, draft
URL https://gitlab.allrisk.cz/core/core/-/merge_requests/1114

Summary

This MR adds commission wallets, calculation pipelines, input commission import, expected/stored commission calculation, QA seed endpoints, k6 coverage, regenerated API clients, and broker hierarchy event plumbing. The contract/client regeneration is present and the command/event shapes are mostly aligned, but the new endpoints currently miss authorization metadata while the new k6 tests assert 401, and one calculation service leaks parser/evaluator details to clients.

Review Verdict

REQUEST CHANGES

Please fix the missing authorization metadata and the confirmed backend API contract/security issues before merge.

Existing Review Threads

  • general (@coderabbitai): "Review skipped. Draft detected." - open. No human inline review threads were present in the discussions API page fetched for this SHA.

Changed Files Overview

File Change Type Lines +/- Risk
backend/src/Allrisk.Core.Commissions/Api/WalletEndpoints/WalletEndpoints.cs Added +114 / -0 High
backend/src/Allrisk.Core.Commissions/Api/CalculationPipelineEndpoints/CalculationPipelineEndpoints.cs Added +133 / -0 High
backend/src/Allrisk.Core.Commissions/Api/CommissionCalculationEndpoints/CommissionCalculationEndpoints.cs Added +87 / -0 High
backend/src/Allrisk.Core.Commissions/Api/InputCommissionEndpoints/InputCommissionEndpoints.cs Added +57 / -0 High
backend/src/Allrisk.Core.Commissions/Api/QaAutomationEndpoints.cs Modified +128 / -0 High
backend/src/Allrisk.Core.Commissions/Application/Commands/Commissions/CalculateCommissionsCommand.cs Added +266 / -0 High
backend/src/Allrisk.Core.Commissions/Infrastructure/Services/CommissionCalculationService.cs Added +62 / -0 High
backend/tests/k6Tests/Allrisk.Core.Commissions/** Added/Modified +1177 / -27 Medium
backend/tests/k6Tests/utils/codegen/** Generated +3865 / -2044 Medium
frontend/packages/api/src/client/** Generated +6239 / -2025 Medium

Critical Issues

Issue 1: New commission endpoints do not require authorization, but the tests expect 401

// Current
[WolverineGet("/wallets")]
public static async Task<Result<IEnumerable<Wallet>>> GetAllWallets(IMessageBus bus)

// Suggested shape
[Authorize]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[WolverineGet("/wallets")]
public static async Task<Result<IEnumerable<Wallet>>> GetAllWallets(IMessageBus bus)

Issue 2: QA automation endpoints are tenant-allowlisted but still unauthenticated

// Current
[WolverineDelete("/qa-automation/tenants/{tenant}/test-input-commissions")]
public static async Task<Result> DeleteTestInputCommissions([FromRoute] string tenant, IMessageBus bus)

// Suggested shape
[Authorize]
[WolverineDelete("/qa-automation/tenants/{tenant}/test-input-commissions")]
public static async Task<Result> DeleteTestInputCommissions([FromRoute] string tenant, IMessageBus bus)

Warnings

Issue 1: Expected commissions endpoint bypasses the CleanResult endpoint contract

  • File: backend/src/Allrisk.Core.Commissions/Api/CommissionCalculationEndpoints/CommissionCalculationEndpoints.cs:47
  • Severity: Warning
  • Category: API Contract
  • Description: ExpectedCommissions returns Task<IResult> and manually serializes errors through Results.Json(...) at line 53. The backend convention for Wolverine endpoints is to return Result / Result<T> and let the endpoint layer keep a consistent CleanResult contract, including file responses.
  • Suggestion: Wrap the file payload in the same project-sanctioned CleanResult/file response pattern used by existing file endpoints, or introduce a typed response wrapper instead of returning raw IResult.
// Current
public static async Task<IResult> ExpectedCommissions(...)

// Target
public static async Task<Result<...>> ExpectedCommissions(...)

Issue 2: NCalc parser/evaluator exception messages are returned to API clients

catch (NCalcParserException exception)
{
    ContextLog.Warning(exception, "Failed to parse commission expression");
    return Result.Error(localizer[LocalizationKeys.CalculationExpressionInvalid], HttpStatusCode.BadRequest);
}

Suggestions

Positive Highlights

  • Generated frontend and k6 clients are included with the backend contract changes.
  • Marten documents for new commission aggregates are registered in DependencyInjection.cs.
  • The k6 suite covers happy path, validation, unauthorized, and delete-conflict flows for the new commission endpoints.

Testing Assessment

Aspect Status
New tests added? Yes
k6 for new endpoints? Yes
Existing tests passing? Pipeline passed; local tests not run
Edge cases covered? Partially
Test quality Adequate, but unauthorized cases appear inconsistent with endpoint metadata

Checklist

Backend

  • No NEW IQuerySession / DB access in API endpoints
  • No manual session.SaveChangesAsync in command/event handlers
  • No try/catch outside Service / ACL
  • Endpoints return Result<T> / CleanResult, not raw IResult
  • Commands return domain events instead of response DTOs
  • Query handlers return raw data; endpoint owns 404 + localization
  • Command/query record + handler in one .cs file; endpoint methods static + XML summaries
  • Guid.CreateVersion7() used for new IDs
  • New Marten classes registered in DependencyInjection.cs
  • Every endpoint has auth metadata + 401/403 response coverage
  • No leaked ex.Message

Testing

  • k6 added for new endpoint surfaces
  • k6 reuses shared generated client/provider infrastructure
  • Tests assert real status codes and selected response values
  • Unauthorized tests line up with actual endpoint authorization metadata

Infra / cross-cutting

  • Generated FE Kubb client regenerated
  • k6 generated client regenerated
  • QA endpoints protected by auth in addition to tenant allowlisting