Skip to content

Add the shared building blocks of the domain model - #4888

Merged
Mpdreamz merged 4 commits into
mainfrom
split/01-foundation
Nov 17, 2026
Merged

Mpdreamz merged 4 commits into
mainfrom
split/01-foundation

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Adds the shared types the per-aggregate pull requests of #4530 build on: a loader declaration, a load result, the violation-to-diagnostic mapping, the equality comparers and a compile-time ban on writing rules outside the domain. Nothing here changes what a loader accepts, reports or writes.

Affects: Internals only

Stack: 1 of N, the foundation of #4530, which this series splits. Later pull requests add one aggregate each on top of this one.

Prompt summary: Split the large domain-model pull request (#4530) into reviewable pieces. This first piece takes only the shared building blocks, as a pure addition on top of main, so each later piece depends on it and nothing else. Review of the first version changed the design: rules are static per type, loaders are declared once, and the load result is a union.

Why

#4530 changes about 700 files. The types every aggregate needs are easy to review on their own, and the later pull requests cannot start without them. The shape they set is copied by every area, so it has to be right before any area depends on it.

What

Rules resolve from the type, and the ban

A record implements IHaveConstraints<T> with one static Constraints declared in a *Constraints class. There is no override and no composing of sets in loader code. BannedSymbols.txt (Microsoft.CodeAnalysis.BannedApiAnalyzers 3.3.4, analyzer only, RS0030) makes Constraints<T>, Relation, Tree, the static ConstraintSet and running a set by hand (Report, Validate, Validated, Ensure, Check) a compile error in every src project except Elastic.Documentation. Tests are exempt, and Loader.cs suppresses the rule once because it is the one place that runs a set.

Loaders declared once

Loader<TDto,T>, created with Loader.For(parse: (text, file) => ..., map: (dto, context) => ...), has one entry, Load(text, file). The map step reports to a MapContext that the loader owns, so findings are kept, in order, even when a later step throws. errorsAreFatal and describe (the error text for a step that threw; the default is the message, so area pull requests keep today's diagnostics) belong to the declaration. Cancellation and out-of-memory propagate. value.Check(file) checks a record built elsewhere. UnknownYamlKeys and BufferingDiagnosticsCollector (base lifecycle) stay.

LoadResult

LoadResult<T> is a union of Loaded<T> (value and findings, a tolerant load may still hold errors) and Unreadable<T> (findings only), replacing Result<T>, which clashed with Nullean.Entities.Result<T>. Report, EmitTo, EmitErrorsTo, OrThrow and OrThrowIfMissing keep their behaviour. ConfigurationException stops the process with every error.

Operations and stages

Operations are public methods on the record returning the record, checked by T.Constraints.Apply, and verified by AutoTest (Nullean.Entities.CsCheck) in WidgetAutoTests. ApplyOutcome.ToDiagnostics(file) maps the outcome to findings, including the warnings Apply drops. A rule that holds at one stage is a stage type with its own Constraints, joined in a union so a switch must cover every stage (WidgetStage). DomainOperation is removed.

Equality, packages and docs

FileSystemInfoLocationComparer and StringListEntryComparer give Generator.Equals a way to compare files and string-list dictionaries. Nullean.Entities 0.2.0 is referenced by Elastic.Documentation; the test project adds Nullean.Entities.CsCheck. Constraints-Conventions.md says where rules live, how loaders, operations and stages are written, and what the ban prevents. Diagnostic gains an unread RuleId.

Deviations from the plan. [Constraints<T>] on a static class does not make the record implement IHaveConstraints<T>, so each record declares the one-line Constraints property by hand. Apply and ApplyDetailed are not banned, because they are the checked form of an operation. CS8509 (a missing union case) is a warning in test projects and an error in src. The old FileOf option has no replacement yet.

Not in this PR. The DiagnosticsCollector de-duplication by RuleId, every *Constraints class of an area, the area loaders, DTO renames, the link-registry and floating-alias comparers, DomainOperation.ParseLifecycle, the guard, ledger and golden tests, and any change in consuming code.

Needed by later PRs. SourcePosition (documentation sets), UnknownYamlKeys, Loader, MapContext, LoadResult and ConfigurationException (every loader), StringListEntryComparer (changelog and products configuration), FileSystemInfoLocationComparer (documentation sets), ApplyOutcome.ToDiagnostics (operations in links and release notes). The rest is exercised by the tests added here.

Verify

mise run build
mise run test
mise run lint

Every new piece has a test, and I broke each on purpose (finding order, cancellation, fatality, describe, the EmitErrorsTo and OrThrow contracts, the outcome adapter, a stage case, an operation that breaks a rule) and saw it fail. A deliberate Constraints<T>, ConstraintSet.From and Validate in Elastic.Documentation.Configuration fails the build with RS0030. The earlier golden build of the isolated, assembler and codex sites against the base commit differed in 0 of 23103 isolated files and 0 of 57053 assembler files. In the codex site 4 of 23248 files differ, the same 4 that differ between two runs of the base commit itself. No build path changed since.

Result, ViolationDiagnostics, ConfigurationException, LoaderPipeline, DomainOperation and the equality comparers are the foundation the per-aggregate changes of #4530 build on. Nothing here changes what a loader accepts, reports or writes: the only edit to existing code is an unused RuleId property on Diagnostic.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Mpdreamz
Mpdreamz requested a review from a team as a code owner November 17, 2026 11:23
@Mpdreamz Mpdreamz added the chore label Nov 17, 2026
@Mpdreamz
Mpdreamz requested a review from technige November 17, 2026 11:23
Comment on lines +52 to +55
catch (Exception e) when (e is not OutOfMemoryException)
{
return Failed<T>(file, e.Message);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Build turns any thrown exception into a diagnostic that holds only e.Message. It drops the inner exception and the stack trace. YamlDotNet wraps converter and constructor failures as YamlException("...: Exception during deserialization") and puts the real cause in InnerException, so loaders moved onto this pipeline will report a generic message. Existing EmitError(file, message, e) includes the exception and its inner exception. Bugs in map, such as a NullReferenceException, also lose the stack needed to find them.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the default message on purpose: area pull requests must reproduce today's diagnostics byte for byte, and that text differs per loader. A new LoadOptions.Describe lets a loader opt in to richer text (message, exception, inner). OperationCanceledException now propagates alongside OutOfMemoryException. Both are tested.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default message is still the exception's message. Loader.For(..., describe:) is declared with the loader, so an area can opt in to richer text. OperationCanceledException and OutOfMemoryException propagate; both are tested.

@github-actions

Copy link
Copy Markdown
Contributor

Mpdreamz and others added 3 commits November 17, 2026 12:54
…line

LoaderPipeline now looks the rules up through IHaveConstraints and takes a LoadOptions record instead of seven optional parameters. It also keeps findings made before a failed map, lets a loader shape the error text, and lets cancellation propagate. Review follow-ups: BufferingDiagnosticsCollector uses the base lifecycle, DomainOperation takes a required file, and the unused ParseLifecycle and Props generators are gone.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…en rules

Rules resolve from the type (T.Constraints) and nothing in src outside the domain can author or run one: BannedSymbols.txt makes that a compile error. LoaderPipeline, LoadOptions and DomainOperation give way to Loader<TDto,T> with a MapContext, LoadResult<T> (a union of Loaded and Unreadable, no longer clashing with Nullean.Entities.Result), operations as methods on the record verified by AutoTest, and stages as types in a union.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Props.cs fixed one seed for all property tests. A fixed seed hides what another seed would find, so the tests now use CsCheck's random default, print the seed on failure and replay it from CsCheck_Seed. AutoTest defaults to a fixed seed, so Widget passes RunSeed explicitly. The conventions require a pinned example test for each bug a property test finds.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Mpdreamz
Mpdreamz merged commit a01a289 into main Nov 17, 2026
48 of 49 checks passed
@Mpdreamz
Mpdreamz deleted the split/01-foundation branch November 17, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant