Skip to content

feat: KeyedNormalizer + AsyncPollingConsumer.PollOnceAsync + OutboxStoreExtensions#335

Merged
JerrettDavis merged 4 commits into
mainfrom
feat/keyed-normalizer-poll-once-outbox-ext
May 23, 2026
Merged

feat: KeyedNormalizer + AsyncPollingConsumer.PollOnceAsync + OutboxStoreExtensions#335
JerrettDavis merged 4 commits into
mainfrom
feat/keyed-normalizer-poll-once-outbox-ext

Conversation

@JerrettDavis
Copy link
Copy Markdown
Owner

Summary

Ships PatternKit v0.113.0 with three new primitives targeting the WorkflowFramework adoption plan (Phase 1 of patternkit-iteration-2.md).

Deliverable 1 — KeyedNormalizer<TKey,TRaw,TCanonical>

  • File: src/PatternKit.Core/Messaging/Transformation/KeyedNormalizer.cs
  • O(1) dictionary-based dispatch variant of Normalizer<TRaw,TCanonical> (predicate-first)
  • Builder throws ArgumentException on duplicate key registration (safer than last-writer-wins)
  • Falls back to a registered Default handler; throws KeyNotFoundException if neither key nor default matches (error message format matches predicate-based Normalizer)
  • Dictionary snapshot taken at Build() — fully immutable after construction
  • 8 test scenarios in KeyedNormalizerTests.cs

Deliverable 2 — AsyncPollingConsumer<T>.PollOnceAsync

  • File: src/PatternKit.Core/Messaging/Consumers/AsyncPollingConsumer.cs (edited)
  • Single-shot poll cycle skipping loop, interval, jitter, and back-off
  • Returns the raw Message<TPayload>? from the source — caller owns what to do with it
  • No handler argument — run-loop handler is never invoked
  • Designed for caller-driven polling: cron jobs, Lambda/Functions, workflow step-based polling
  • 4 new test scenarios appended to AsyncPollingConsumerTests.cs

Deliverable 3 — OutboxStoreExtensions.EnqueueObjectAsync

  • File: src/PatternKit.Core/Messaging/Reliability/OutboxStoreExtensions.cs
  • Extension on IOutboxStore<object> for callers without compile-time payload type knowledge
  • Accepts object payload + IReadOnlyDictionary<string,string>? headers
  • Null/empty headers map to MessageHeaders.Empty (no allocation)
  • 3 test scenarios in OutboxStoreExtensionsTests.cs

Test plan

  • All new [Scenario] / [Fact] tests pass on net8, net9, net10 TFMs
  • No regressions in existing NormalizerTests, AsyncPollingConsumerTests, IOutboxStoreTests
  • PatternKit.Core builds clean across all target frameworks (netstandard2.0/2.1, net8/9/10)

🤖 Generated with Claude Code

JerrettDavis and others added 3 commits May 22, 2026 22:28
…cal>

Key-based O(1) dispatch variant of Normalizer. Builder throws on duplicate
key registration (safer than last-writer-wins). Dictionary snapshot taken at
Build() so the built instance is fully immutable after construction.
8 test scenarios cover: happy path, multiple keys, default fallback,
missing-key-throws, async handler, cancellation, duplicate-key guard,
and build-twice semantics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Single-shot poll cycle that skips the run loop, interval, jitter, and
back-off — designed for caller-driven polling (workflow steps, cron jobs,
AWS Lambda, Azure Functions). Returns the raw message from the source
or null on empty poll. Does not invoke any run-loop handler.
4 new test scenarios: returns item, returns null on empty, respects
cancellation, confirms handler is not invoked.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sync

Convenience extension on IOutboxStore<object> for callers without
compile-time payload type knowledge (e.g., generic workflow orchestrators).
Accepts an untyped payload + IReadOnlyDictionary<string,string> headers,
projects to MessageHeaders, and delegates to EnqueueAsync. Null or
empty headers map to MessageHeaders.Empty (no allocation).
3 test scenarios: with payload+headers, null headers, cancellation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 23, 2026 03:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 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

This PR introduces three new messaging primitives in PatternKit.Core to support the WorkflowFramework adoption plan (Phase 1): a keyed normalizer for O(1) dispatch, a single-shot polling API for AsyncPollingConsumer<T>, and an outbox convenience extension for untyped payloads.

Changes:

  • Added KeyedNormalizer<TKey,TRaw,TCanonical> with a fluent builder, default handler support, and duplicate-key validation.
  • Added AsyncPollingConsumer<T>.PollOnceAsync for caller-driven single-iteration polling.
  • Added OutboxStoreExtensions.EnqueueObjectAsync to enqueue object payloads with optional string headers, plus new tests for all three deliverables.

Reviewed changes

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

Show a summary per file
File Description
src/PatternKit.Core/Messaging/Transformation/KeyedNormalizer.cs Adds dictionary-dispatch normalizer with builder, default handler, and snapshot immutability.
src/PatternKit.Core/Messaging/Consumers/AsyncPollingConsumer.cs Adds PollOnceAsync single-shot polling API.
src/PatternKit.Core/Messaging/Reliability/OutboxStoreExtensions.cs Adds EnqueueObjectAsync convenience overload for IOutboxStore<object>.
test/PatternKit.Tests/Messaging/Transformation/KeyedNormalizerTests.cs Adds scenario-based test coverage for keyed normalizer behavior and builder semantics.
test/PatternKit.Tests/Messaging/Consumers/AsyncPollingConsumerTests.cs Adds tests for PollOnceAsync behavior and cancellation.
test/PatternKit.Tests/Messaging/Reliability/OutboxStoreExtensionsTests.cs Adds tests for EnqueueObjectAsync payload/headers behavior and cancellation.

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

Comment on lines +219 to +233
[Scenario("PollOnceAsync DoesNotInvokeRunLoopHandler")]
[Fact]
public async Task PollOnceAsync_DoesNotInvokeRunLoopHandler()
{
var handlerInvoked = false;

var consumer = AsyncPollingConsumer<string>.Create()
.WithSource(async (_, _) => { await Task.CompletedTask; return Message<string>.Create("msg"); })
.Build();

// PollOnceAsync takes no handler argument — the run-loop handler is never called.
var result = await consumer.PollOnceAsync();

ScenarioExpect.False(handlerInvoked);
ScenarioExpect.NotNull(result); // the source did produce a message
Comment on lines +42 to +44
ScenarioExpect.Equal(0, record.Message.Headers.Count);
}

Comment on lines +124 to +132
/// <param name="ct">Cancellation token propagated directly to the poll source.</param>
/// <returns>
/// The message returned by the source, or <see langword="null"/> when the source
/// returned an empty poll.
/// </returns>
public ValueTask<Message<TPayload>?> PollOnceAsync(CancellationToken ct = default)
{
ct.ThrowIfCancellationRequested();
return _source(MessageContext.Empty, ct);
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 23, 2026

Test Results

799 tests   799 ✅  28s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 71c1e4a.

♻️ This comment has been updated with latest results.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2026

Codecov Report

❌ Patch coverage is 90.19608% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.64%. Comparing base (0157494) to head (71c1e4a).

Files with missing lines Patch % Lines
...t.Core/Messaging/Transformation/KeyedNormalizer.cs 92.30% 3 Missing ⚠️
...ore/Messaging/Reliability/OutboxStoreExtensions.cs 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #335      +/-   ##
==========================================
+ Coverage   89.66%   95.64%   +5.97%     
==========================================
  Files         484      486       +2     
  Lines       39951    40002      +51     
  Branches     5744     5756      +12     
==========================================
+ Hits        35824    38261    +2437     
+ Misses       1873     1741     -132     
+ Partials     2254        0    -2254     
Flag Coverage Δ
unittests 95.64% <90.19%> (+5.97%) ⬆️

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 May 23, 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.

- PollOnceAsync: add optional context parameter so callers can supply
  MessageContext instead of always using Empty; cancellation flows via
  the explicit ct parameter as before
- PollOnceAsync test DoesNotInvokeRunLoopHandler: rewrite to count
  source invocations (observable) instead of checking an unused flag
- OutboxStoreExtensionsTests: assert ReferenceEquals(MessageHeaders.Empty)
  for null headers; add empty-dictionary scenario to verify same guarantee

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Code Coverage

Summary
  Generated on: 05/23/2026 - 03:46:33
  Coverage date: 05/23/2026 - 03:45:26 - 05/23/2026 - 03:46:22
  Parser: MultiReport (9x Cobertura)
  Assemblies: 4
  Classes: 1450
  Files: 592
  Line coverage: 94.5%
  Covered lines: 39259
  Uncovered lines: 2242
  Coverable lines: 41501
  Total lines: 91252
  Branch coverage: 75.5% (11566 of 15299)
  Covered branches: 11566
  Total branches: 15299
  Method coverage: 96.1% (7805 of 8116)
  Full method coverage: 88.2% (7163 of 8116)
  Covered methods: 7805
  Fully covered methods: 7163
  Total methods: 8116

PatternKit.Core                                                                                                     95.5%
  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.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.EventSourcing.EventStoreAppendResult                                                        100%
  PatternKit.Application.EventSourcing.InMemoryEventStore<T1, T2>                                                   97.9%
  PatternKit.Application.EventSourcing.StoredEvent<T1, T2>                                                            80%
  PatternKit.Application.FeatureToggles.FeatureToggleDecision                                                       87.5%
  PatternKit.Application.FeatureToggles.FeatureToggleRule<T>                                                         100%
  PatternKit.Application.FeatureToggles.FeatureToggleSet<T>                                                         96.9%
  PatternKit.Application.IdentityMap.IdentityMap<T1, T2>                                                             100%
  PatternKit.Application.IdentityMap.IdentityMapResult<T>                                                           92.8%
  PatternKit.Application.MaterializedViews.MaterializedView<T1, T2>                                                 98.4%
  PatternKit.Application.Repository.InMemoryRepository<T1, T2>                                                      92.8%
  PatternKit.Application.Repository.RepositoryResult<T>                                                             93.3%
  PatternKit.Application.ServiceLayer.ServiceLayerOperation<T1, T2>                                                 96.7%
  PatternKit.Application.ServiceLayer.ServiceLayerResult<T>                                                         94.7%
  PatternKit.Application.ServiceLayer.ServiceLayerRule<T>                                                            100%
  PatternKit.Application.Specification.Specification<T>                                                              100%
  PatternKit.Application.Specification.SpecificationRegistry<T>                                                     93.3%
  PatternKit.Application.TableDataGateway.InMemoryTableDataGateway<T1, T2>                                            86%
  PatternKit.Application.TableDataGateway.TableGatewayResult<T>                                                     82.3%
  PatternKit.Application.TransactionScript.TransactionScript<T1, T2>                                                  97%
  PatternKit.Application.TransactionScript.TransactionScriptError                                                     90%
  PatternKit.Application.TransactionScript.TransactionScriptResult<T>                                                100%
  PatternKit.Application.UnitOfWork.UnitOfWork                                                                      90.9%
  PatternKit.Application.UnitOfWork.UnitOfWorkResult                                                                94.7%
  PatternKit.Application.UnitOfWork.UnitOfWorkRollbackResult                                                         100%
  PatternKit.Application.UnitOfWork.UnitOfWorkStep                                                                   100%
  PatternKit.Behavioral.Chain.ActionChain<T>                                                                         100%
  PatternKit.Behavioral.Chain.AsyncActionChain<T>                                                                    100%
  PatternKit.Behavioral.Chain.AsyncResultChain<T1, T2>                                                              97.7%
  PatternKit.Behavioral.Chain.ResultChain<T1, T2>                                                                    100%

@JerrettDavis JerrettDavis merged commit 851f33d into main May 23, 2026
12 checks passed
@JerrettDavis JerrettDavis deleted the feat/keyed-normalizer-poll-once-outbox-ext branch May 23, 2026 03:53
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.

2 participants