Skip to content

GH-1287 part 3: opt-in JFXEVT018 for a natural key no event sets; one diagnostic for a mistyped mapped key; 3.15.0 - #1289

Merged
jeremydmiller merged 2 commits into
mainfrom
gh-1287-unset-natural-key-diagnostic
Nov 24, 2026
Merged

jeremydmiller merged 2 commits into
mainfrom
gh-1287-unset-natural-key-diagnostic

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Closes #1287 (part 3; parts 1 and 2 shipped in #1288, in 3.14.0). Also bumps the version to 3.15.0.

JFXEVT018: a natural key that no event sets (opt-in)

A new warning for an owned [NaturalKey] that nothing in the project sets. "Nothing" means no [NaturalKeySource] method on the aggregate, its base types or any projection of it, and no NaturalKeyFor() call for it. Today the runtime refuses this with the InvalidProjectionException in assertNaturalKeyValidity.

It is off by default, because it can't be free of false positives when it's on by default. A mapping can be registered where no analyzer can see it:

  • in another assembly that declares the projection (with [NaturalKeySource] methods) or calls NaturalKeyFor(), the usual Domain/Infrastructure split;
  • in a referenced library's generic helper, called with the aggregate as a type argument;
  • through IAggregateProjection.NaturalKeyDefinition.AddOrReplaceMapping(), which any code holding the projection can call without naming the aggregate.

A project that holds every registration for its aggregates turns it on with dotnet_diagnostic.JFXEVT018.severity = warning. Turning it on is the explicit assertion the analyzer can't make for itself. Even then it stays silent whenever the project might set the key in a way it can't attribute to one aggregate:

  • NaturalKeyFor() in generic code;
  • a [NaturalKeySource] method on a generic projection base;
  • any AddOrReplaceMapping() call;
  • a NaturalKeyFor/AddOrReplaceMapping name that doesn't resolve.

A non-public [NaturalKeySource] also keeps it silent, because the runtime already names that problem better. When the diagnostic is off, the pipeline returns before it looks at the compilation, so the IDE pays nothing.

One diagnostic, not JFXEVT011 and JFXEVT015

A mapped key with the wrong type for its source, whose type is also the aggregate's own key type, used to draw both diagnostics. Now it draws only JFXEVT015, because fixing the type fixes both. Two other keys that really do share a type still get JFXEVT011.

Tests

  • UnsetNaturalKeyDiagnosticTests (16 tests): off by default; on through compilation options and through a global config; a suppressed global config leaves it off; plus each silence rule above, and the negative cases (a source or NaturalKeyFor() for an unrelated aggregate doesn't count).
  • Three NaturalKeyDiagnosticTests for the 011/015 dedupe: the mapped key declared after the owned key, declared before it, and a genuine clash beside a mistyped key.
  • docs/codegen/diagnostics.md documents JFXEVT018 and the dedupe.

Gate

The full local gate (stoat gate exec critter-stack-net11-rc/gate-slot-jasperfx -- ./build.sh Test, with --root on this nested worktree) is green on this commit. The first run hit the known DescribeCommandTests.write_file_smoke_test console-recorder flake, which is unrelated and passed on the re-run.

🤖 Generated with Claude Code

jeremydmiller and others added 2 commits November 23, 2026 19:21
…iagnostic, not 011 and 015, for a mistyped mapped key

JFXEVT018 is off by default. A NaturalKeyFor() call or a projection with
[NaturalKeySource] methods can live in another assembly, a referenced
library's generic helper, or reach the definition through
IAggregateProjection, so no analyzer can rule a registration out on its
own. A project that holds every registration turns it on with
dotnet_diagnostic.JFXEVT018.severity, and even then any registration
it cannot attribute to one aggregate keeps it silent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Natural keys: a null from an inferred key source should not retire the key; clearer refusal messages; a diagnostic for unset keys (marten#6153)

1 participant