Skip to content

Add Invariant to Aggregate (#374) - #384

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

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 (3d31b17) to head (ab35ff8).

Additional details and impacted files
@@                        Coverage Diff                        @@
##             feature/372-not-responsible-for    #384   +/-   ##
=================================================================
  Coverage                               91.8%   91.8%           
  Complexity                              2234    2234           
=================================================================
  Files                                    211     211           
  Lines                                   5949    5950    +1     
  Branches                                 808     808           
=================================================================
+ Hits                                    5466    5467    +1     
  Misses                                   230     230           
  Partials                                 253     253           

☔ 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 ed67baf to 3d31b17 Compare October 20, 2026 21:55
@stefan-ka
stefan-ka force-pushed the feature/374-aggregate-invariants branch from 1bf8a4f to ab35ff8 Compare October 20, 2026 21:55
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