feat: add compensating transaction pattern#499
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
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.
| 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. | |
| 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); |
Code Coverage |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Test Results 12 files 12 suites 11m 30s ⏱️ Results for commit 004a220. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Closes #482
Summary
Validation