feat: add Ambassador pattern#325
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results787 tests 787 ✅ 32s ⏱️ Results for commit 69d33fd. |
There was a problem hiding this comment.
Pull request overview
Adds a new Ambassador pattern to PatternKit, including a fluent runtime API for wrapping outbound calls, a Roslyn incremental generator for strongly-typed factory creation, and a production-shaped example wired into the Pattern/Example catalogs and docs.
Changes:
- Introduces
Ambassador<TRequest,TResponse>runtime with transforms, connection policy, telemetry steps, outbound call, and fallback handling. - Adds
[GenerateAmbassador]+ related member attributes and anAmbassadorGeneratorwith diagnostics and generator tests. - Adds an Inventory Ambassador example (DI + ASP.NET Core minimal API mapping), documentation, and catalog wiring/coverage updates.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Cloud/Ambassador/AmbassadorTests.cs | Adds runtime behavior coverage for transforms/telemetry/fallback/guard clauses. |
| test/PatternKit.Generators.Tests/AmbassadorGeneratorTests.cs | Adds generator tests for emitted factory source and diagnostics. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute surface coverage to include Ambassador attributes. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates catalog expectations to include Ambassador and adjusts family counts. |
| test/PatternKit.Examples.Tests/AmbassadorDemo/InventoryAmbassadorDemoTests.cs | Adds example-level verification (fluent + generated + DI + catalogs). |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new analyzer diagnostic IDs for the Ambassador generator. |
| src/PatternKit.Generators/Ambassador/AmbassadorGenerator.cs | Implements the Ambassador incremental generator and diagnostics. |
| src/PatternKit.Generators.Abstractions/Cloud/AmbassadorAttributes.cs | Adds public generator attributes for ambassador host + steps. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Wires Ambassador pattern into the production pattern catalog. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds the Inventory Ambassador entry to the production example catalog. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Adds DI registration for the new example and aggregates it into AddPatternKitExamples(). |
| src/PatternKit.Examples/AmbassadorDemo/InventoryAmbassadorDemo.cs | Implements the Inventory Ambassador demo (runtime + generated + DI + endpoint mapping). |
| src/PatternKit.Core/Cloud/Ambassador/Ambassador.cs | Adds the core Ambassador runtime types (Ambassador, context, result). |
| docs/patterns/toc.yml | Adds Ambassador to the patterns TOC. |
| docs/patterns/cloud/ambassador.md | Adds Ambassador pattern documentation and quick example. |
| docs/guides/pattern-coverage.md | Adds Ambassador to the pattern coverage guide table. |
| docs/generators/toc.yml | Adds Ambassador to the generators TOC. |
| docs/generators/index.md | Adds Ambassador to the generator index table. |
| docs/generators/ambassador.md | Adds generator documentation and diagnostic list. |
| docs/examples/toc.yml | Adds Inventory Ambassador to examples TOC. |
| docs/examples/inventory-ambassador.md | Adds Inventory Ambassador example documentation. |
| docs/examples/index.md | Adds Inventory Ambassador to examples index summary list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| context.Request = transform(context.Request); | ||
| if (context.Request is null) | ||
| return AmbassadorResult<TResponse>.Failure(Name, new InvalidOperationException("Ambassador transform returned null."), context.Events.ToArray()); |
| private static readonly DiagnosticDescriptor MissingMembers = new( | ||
| "PKAMB002", "Ambassador members are missing", | ||
| "Ambassador type '{0}' must declare exactly one outbound call handler", | ||
| "PatternKit.Generators.Ambassador", DiagnosticSeverity.Error, true); | ||
|
|
||
| private static readonly DiagnosticDescriptor InvalidMember = new( | ||
| "PKAMB003", "Ambassador method signature is invalid", | ||
| "Ambassador method '{0}' has an invalid static signature for the configured request or response type", | ||
| "PatternKit.Generators.Ambassador", DiagnosticSeverity.Error, true); |
| .Select(static item => new TelemetryMember((string)item.Attribute!.ConstructorArguments[0].Value!, item.Method)) | ||
| .ToArray(); | ||
|
|
| Diagnostics: | ||
|
|
||
| - `PKAMB001`: host type must be partial. | ||
| - `PKAMB002`: exactly one outbound call handler is required. |
Code Coverage |
🔍 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. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #325 +/- ##
==========================================
+ Coverage 89.83% 95.74% +5.90%
==========================================
Files 464 468 +4
Lines 38355 38681 +326
Branches 5468 5524 +56
==========================================
+ Hits 34458 37034 +2576
+ Misses 1742 1647 -95
+ Partials 2155 0 -2155
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:
|
Summary
Closes #320.
Validation
AmbassadorGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseAmbassadorGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseAmbassadorGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseNote: the local full examples build still hits the existing analyzer/compiler mismatch (CS9057 with generated demo types); hosted CI validates the full examples/docs surface.