Skip to content

feat: add compensating transaction pattern#499

Merged
JerrettDavis merged 1 commit into
mainfrom
feature/compensating-transaction-pattern-482
Jun 1, 2026
Merged

feat: add compensating transaction pattern#499
JerrettDavis merged 1 commit into
mainfrom
feature/compensating-transaction-pattern-482

Conversation

@JerrettDavis
Copy link
Copy Markdown
Owner

Closes #482

Summary

  • adds the Compensating Transaction runtime API with ordered reversible steps and reverse compensation on failure
  • adds source-generator attributes, generator diagnostics, and TinyBDD generator coverage
  • adds a checkout compensation example with IServiceCollection import, docs, catalog entries, and BenchmarkDotNet routes

Validation

  • dotnet build PatternKit.slnx --configuration Release --no-restore -p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj --configuration Release --no-build --framework net8.0
  • dotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj --configuration Release --no-build --framework net8.0
  • dotnet test test\PatternKit.Examples.Tests\PatternKit.Examples.Tests.csproj --configuration Release --no-build --framework net8.0
  • dotnet test test\PatternKit.Hosting.Extensions.Tests\PatternKit.Hosting.Extensions.Tests.csproj --configuration Release --no-build --framework net8.0
  • dotnet format PatternKit.slnx --verify-no-changes --verbosity minimal
  • git diff --check
  • docfx metadata docs\docfx.json; docfx build docs\docfx.json

Copilot AI review requested due to automatic review settings June 1, 2026 13:59
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the Compensating Transaction pattern across the core runtime, source generator, examples, benchmarks, and production-readiness catalogs/docs so it’s treated as a first-class PatternKit pattern.

Changes:

  • Introduces CompensatingTransaction<TContext> runtime API with ordered steps, conditional execution, and reverse-order compensation on failure.
  • Adds [GenerateCompensatingTransaction] / [CompensatingTransactionStep] attributes plus an incremental generator and diagnostics (PKCOMP001–PKCOMP005).
  • Adds a DI-importable checkout example, benchmark routes, and updates catalogs/docs/tests to include the new pattern.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/PatternKit.Tests/Application/CompensatingTransactions/CompensatingTransactionTests.cs Runtime behavior coverage (ordering, compensation, cancellation, validation).
test/PatternKit.Generators.Tests/CompensatingTransactionGeneratorTests.cs Generator output/diagnostics coverage for the new generator.
test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs Adds attribute coverage assertions for new abstractions.
test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs Updates expected catalog contents/counts to include the new pattern.
test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitBenchmarkCoverageTests.cs Updates expected published route totals and humanization for new benchmark class.
test/PatternKit.Examples.Tests/CompensatingTransactionDemo/CheckoutCompensatingTransactionDemoTests.cs Validates fluent vs generated demo behavior and DI import.
src/PatternKit.Generators/CompensatingTransactions/CompensatingTransactionGenerator.cs New incremental generator and diagnostics for compensating transactions.
src/PatternKit.Generators/AnalyzerReleases.Unshipped.md Registers new diagnostic IDs for analyzer release tracking.
src/PatternKit.Generators.Abstractions/CompensatingTransactions/CompensatingTransactionAttributes.cs New public attributes for source-generation.
src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs Adds the new pattern to the production-readiness pattern catalog manifest.
src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs Adds the checkout compensating transaction example to the example catalog.
src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs Adds DI registration entry point for the new example.
src/PatternKit.Examples/CompensatingTransactionDemo/CheckoutCompensatingTransactionDemo.cs New checkout demo (fluent + generated paths) and DI import surface.
src/PatternKit.Core/Application/CompensatingTransactions/CompensatingTransaction.cs New runtime implementation of compensating transactions.
README.md Updates pattern counts/table and adds benchmark rows for the new pattern.
docs/patterns/toc.yml Adds the new pattern to the patterns TOC.
docs/patterns/application/compensating-transaction.md New pattern documentation page.
docs/index.md Updates pattern counts/table to include the new pattern.
docs/guides/benchmark-results.md Updates published benchmark matrix totals and adds scenario rows for the new benchmark.
docs/generators/toc.yml Adds generator docs entry to the generators TOC.
docs/generators/index.md Adds generator docs index entry for the new generator.
docs/generators/compensating-transaction.md New generator documentation page (usage + diagnostics).
docs/examples/toc.yml Adds the new example to the examples TOC.
docs/examples/index.md Adds the new example to the examples index page.
docs/examples/checkout-compensating-transaction-pattern.md New example documentation page.
benchmarks/PatternKit.Benchmarks/Application/CompensatingTransactionBenchmarks.cs Adds benchmark routes for fluent vs generated construction/execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +43 to +46
private static readonly DiagnosticDescriptor InvalidConfiguration = new(
"PKCOMP005", "Compensating transaction configuration is invalid",
"Compensating transaction '{0}' must have valid FactoryMethodName, TransactionName, and Compensation values",
"PatternKit.Generators.CompensatingTransactions", DiagnosticSeverity.Error, true);
| `PKCOMP002` | At least one `[CompensatingTransactionStep]` method is required. |
| `PKCOMP003` | Step, compensation, or condition method signature is invalid. |
| `PKCOMP004` | Step names and orders must be unique. |
| `PKCOMP005` | Factory method, transaction name, or compensation configuration is invalid. |
Comment on lines +16 to +21
public static async ValueTask<CheckoutCompensatingTransactionSummary> RunFluentAsync(bool shipmentAvailable = false)
{
var context = new CheckoutCompensatingTransactionContext("order-1001", shipmentAvailable);
var transaction = CreateFluent();
var execution = await transaction.ExecuteAsync(context);
return CreateSummary(execution);
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Code Coverage

Summary
  Generated on: 06/01/2026 - 14:06:47
  Coverage date: 06/01/2026 - 14:05:03 - 06/01/2026 - 14:06:35
  Parser: MultiReport (8x Cobertura)
  Assemblies: 5
  Classes: 1817
  Files: 611
  Line coverage: 97.4%
  Covered lines: 48631
  Uncovered lines: 1295
  Coverable lines: 49926
  Total lines: 105800
  Branch coverage: 84.3% (15597 of 18483)
  Covered branches: 15597
  Total branches: 18483
  Method coverage: 97.3% (9510 of 9772)
  Full method coverage: 91.6% (8956 of 9772)
  Covered methods: 9510
  Fully covered methods: 8956
  Total methods: 9772

PatternKit.Core                                                                                                     96.2%
  PatternKit.Application.ActivityTracking.ActivityGateState                                                          100%
  PatternKit.Application.ActivityTracking.ActivityLease                                                              100%
  PatternKit.Application.ActivityTracking.ActivityRecord                                                             100%
  PatternKit.Application.ActivityTracking.ActivityTracker                                                            100%
  PatternKit.Application.Aggregates.AggregateCommandHandler<T1, T2, T3>                                              100%
  PatternKit.Application.Aggregates.AggregateCommandResult<T>                                                        100%
  PatternKit.Application.Aggregates.AggregateRoot<T1, T2>                                                            100%
  PatternKit.Application.AntiCorruption.AntiCorruptionLayer<T1, T2>                                                 90.4%
  PatternKit.Application.AntiCorruption.AntiCorruptionResult<T>                                                      100%
  PatternKit.Application.AuditLog.AuditLogAppendResult<T>                                                           85.7%
  PatternKit.Application.AuditLog.InMemoryAuditLog<T1, T2>                                                          95.4%
  PatternKit.Application.BoundedContexts.BoundedContextAdapter                                                       100%
  PatternKit.Application.BoundedContexts.BoundedContextCapability                                                   83.3%
  PatternKit.Application.BoundedContexts.BoundedContextDescriptor                                                   95.4%
  PatternKit.Application.CompensatingTransactions.CompensatingTransaction<T>                                        96.9%
  PatternKit.Application.CompensatingTransactions.CompensatingTransactionExecution<T>                                100%
  PatternKit.Application.CompensatingTransactions.CompensatingTransactionRecord                                      100%
  PatternKit.Application.CompensatingTransactions.CompensatingTransactionStep<T>                                     100%
  PatternKit.Application.CompensatingTransactions.CompensatingTransactionStepBuilder<T>                              100%
  PatternKit.Application.ContextMaps.ContextMapDescriptor                                                           96.8%
  PatternKit.Application.ContextMaps.ContextMapRelationship                                                          100%
  PatternKit.Application.DataMapping.DataMapper<T1, T2>                                                             94.6%
  PatternKit.Application.DataMapping.DataMapperError                                                                  90%
  PatternKit.Application.DataMapping.DataMapperResult<T>                                                            84.6%
  PatternKit.Application.DomainEvents.DomainEventDispatcher<T>                                                      95.4%
  PatternKit.Application.DomainEvents.DomainEventDispatchResult                                                      100%
  PatternKit.Application.DomainServices.DomainServiceOperation<T1, T2>                                               100%
  PatternKit.Application.DomainServices.DomainServiceRegistry<T1, T2>                                                100%
  PatternKit.Application.EventSourcing.EventStoreAppendResult                                                        100%
  PatternKit.Application.EventSourcing.InMemoryEventStore<T1, T2>                                                   97.9%
  PatternKit.Application.EventSourcing.StoredEvent<T1, T2>                                                            80%
  PatternKit.Application.EventualConsistency.EventualConsistencyEvaluation<T>                                       92.3%
  PatternKit.Application.EventualConsistency.EventualConsistencyMonitor<T>                                          97.2%
  PatternKit.Application.EventualConsistency.EventualConsistencyMonitorState<T>                                      100%
  PatternKit.Application.EventualConsistency.EventualConsistencyWatermarks<T>                                       96.7%
  PatternKit.Application.FeatureToggles.FeatureToggleDecision                                                       87.5%
  PatternKit.Application.FeatureToggles.FeatureToggleRule<T>                                                         100%
  PatternKit.Application.FeatureToggles.FeatureToggleSet<T>                                                         96.9%

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 96.11399% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.41%. Comparing base (881c33f) to head (004a220).

Files with missing lines Patch % Lines
...ngTransactions/CompensatingTransactionGenerator.cs 94.51% 9 Missing ⚠️
...sactionDemo/CheckoutCompensatingTransactionDemo.cs 93.33% 4 Missing ⚠️
...ompensatingTransactions/CompensatingTransaction.cs 98.40% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #499      +/-   ##
==========================================
- Coverage   97.42%   97.41%   -0.02%     
==========================================
  Files         607      611       +4     
  Lines       49540    49926     +386     
  Branches     3212       34    -3178     
==========================================
+ Hits        48263    48633     +370     
- Misses       1277     1293      +16     
Flag Coverage Δ
unittests 97.41% <96.11%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Test Results

    12 files      12 suites   11m 30s ⏱️
 4 195 tests  4 195 ✅ 0 💤 0 ❌
13 034 runs  13 034 ✅ 0 💤 0 ❌

Results for commit 004a220.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

🔍 PR Validation Results

Version: ``

✅ Validation Steps

  • Build solution
  • Run tests
  • Build documentation
  • Dry-run NuGet packaging

📊 Artifacts

Dry-run artifacts have been uploaded and will be available for 7 days.


This comment was automatically generated by the PR validation workflow.

@JerrettDavis JerrettDavis merged commit 6852e8b into main Jun 1, 2026
13 checks passed
@JerrettDavis JerrettDavis deleted the feature/compensating-transaction-pattern-482 branch June 1, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Compensating Transaction pattern

2 participants