Skip to content

Add Invariant to Aggregate (#374) - #384

Open
stefan-ka wants to merge 1 commit into
feature/372-not-responsible-forfrom
feature/374-aggregate-invariants
Open

stefan-ka wants to merge 1 commit into
feature/372-not-responsible-forfrom
feature/374-aggregate-invariants

Conversation

@stefan-ka

@stefan-ka stefan-ka commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Closes #374

Stacked on #383 (contains the build fix); the base branch is feature/372-not-responsible-for, so the diff only shows this feature.

Changes

  • Grammar: new Invariant element inside Aggregate, with an optional name and a description string:
    Aggregate Tickets {
      Entity Ticket { aggregateRoot }
      Invariant "The sum of refunds never exceeds the price paid"
      Invariant ValidatedTicketsAreNotRefundable "A validated ticket cannot be refunded"
    }
    
    Unnamed and named both work, which covers both options discussed in the issue.
  • Formatter: each Invariant starts on a new line.
  • Merge Aggregates refactoring: keeps the invariants of both aggregates.
  • Tests for parsing and merging.

Notes

  • Invariant becomes a keyword. Models that use Invariant as a name for another element would have to escape it (^Invariant). No such usage in the repo's test and sample files.
  • Not included: PlantUML output (e.g. as a note in the class diagram), uniqueness validation of invariant names.
  • Docs: Document invariants on Aggregates contextmapper.github.io#105

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.8%. Comparing base (c06b609) to head (22d2766).

Additional details and impacted files
@@                         Coverage Diff                         @@
##             feature/372-not-responsible-for    #384     +/-   ##
===================================================================
- Coverage                               91.8%   91.8%   -0.1%     
+ Complexity                              2237    2236      -1     
===================================================================
  Files                                    211     211             
  Lines                                   5960    5961      +1     
  Branches                                 811     811             
===================================================================
  Hits                                    5473    5473             
  Misses                                   232     232             
- Partials                                 255     256      +1     

☔ View full report in Codecov by Harness.
📢 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.

Aggregates can declare the invariants they protect, as a description
string with an optional name:

  Invariant "The sum of refunds never exceeds the price paid"
  Invariant RefundsNeverExceedPrice "..."

The Merge Aggregates refactoring keeps the invariants of both aggregates.
@stefan-ka
stefan-ka force-pushed the feature/372-not-responsible-for branch from 3d31b17 to c06b609 Compare November 19, 2026 16:33
@stefan-ka
stefan-ka force-pushed the feature/374-aggregate-invariants branch from ab35ff8 to 22d2766 Compare November 19, 2026 16:33
@stefan-ka
stefan-ka marked this pull request as ready for review November 19, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant