Merged
Conversation
Signed-off-by: Kenny Pflug <[email protected]>
Signed-off-by: Kenny Pflug <[email protected]>
Signed-off-by: Kenny Pflug <[email protected]>
…onErrorDefinitionCache explaining the internal design Signed-off-by: Kenny Pflug <[email protected]>
Closed
9 tasks
There was a problem hiding this comment.
Pull request overview
This PR introduces a reusable “validation error definition” layer (on top of message templates) to enable caching and reuse of rule identity/defaults across validation runs, and adds built-in assertions (IsNotNull, IsGreaterThan, IsLessThan, IsIn) that consume this infrastructure.
Changes:
- Added
ValidationErrorDefinitionabstractions plus a thread-safeIValidationErrorDefinitionCache/ValidationErrorDefinitionCacheand a built-in catalog (BuiltInValidationErrorDefinitions) for reusable fixed/parameterized definitions. - Extended validation context/options/state to expose a shared definition cache and expanded
ValidationErrorTemplateswith comparable/range templates. - Added new built-in
Check<T>assertion extensions and comprehensive tests + documentation updates describing the new model.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Light.PortableResults.Validation.Tests/ValidationErrorDefinitionTests.cs | Tests for definition defaults, override behavior, cache reuse, and custom definition authoring. |
| tests/Light.PortableResults.Validation.Tests/BuiltInAssertionTests.cs | Tests for new built-in assertions, null handling, short-circuiting, metadata, and target composition. |
| src/Light.PortableResults.Validation/ValidationState.cs | Exposes shared ErrorDefinitionCache via validation state. |
| src/Light.PortableResults.Validation/ValidationRange.cs | Adds immutable range value used for parameterized cache keys. |
| src/Light.PortableResults.Validation/ValidationErrorTemplates.cs | Adds default templates for comparisons and ranges (GreaterThan, LessThan, IsIn). |
| src/Light.PortableResults.Validation/ValidationErrorMetadataKeys.cs | Defines standard metadata keys for boundary/range rules. |
| src/Light.PortableResults.Validation/ValidationErrorDefinitionCache.cs | Implements thread-safe typed-bucket cache for reusable definitions. |
| src/Light.PortableResults.Validation/ValidationErrorDefinition.cs | Introduces base definition abstractions (+ template-backed implementations). |
| src/Light.PortableResults.Validation/ValidationContextOptions.cs | Adds configurable ErrorDefinitionCache with default singleton. |
| src/Light.PortableResults.Validation/ValidationContext.cs | Exposes ErrorDefinitionCache from the active context. |
| src/Light.PortableResults.Validation/ReadOnlyValidationContext.cs | Exposes ErrorDefinitionCache from readonly context view. |
| src/Light.PortableResults.Validation/IValidationErrorDefinitionCache.cs | Adds public cache contract for definition reuse. |
| src/Light.PortableResults.Validation/IRangeValidationErrorMessageTemplate.cs | Adds template contract for range-based messages. |
| src/Light.PortableResults.Validation/IComparableValidationErrorMessageTemplate.cs | Adds template contract for single-boundary comparison messages. |
| src/Light.PortableResults.Validation/DisplayNameWithRangeValidationErrorMessageTemplate.cs | Implements range message formatting with boundary formatting. |
| src/Light.PortableResults.Validation/DisplayNameWithComparableValidationErrorMessageTemplate.cs | Implements comparison message formatting with parameter formatting. |
| src/Light.PortableResults.Validation/DefaultAutomaticNullErrorProvider.cs | Switches automatic null error creation to use the built-in NotNull definition. |
| src/Light.PortableResults.Validation/Check.cs | Adds definition-based AddError overloads and a ShortCircuitOnErrorIfRequested helper; adds category support to message-based AddError. |
| src/Light.PortableResults.Validation/BuiltInValidationErrorDefinitions.cs | Adds built-in reusable definitions and cache-key strategy for parameterized rules. |
| src/Light.PortableResults.Validation/Assertions/Checks.IsNotNull.cs | Adds IsNotNull assertion (default short-circuits). |
| src/Light.PortableResults.Validation/Assertions/Checks.IsLessThan.cs | Adds IsLessThan assertion using cached definitions and templates. |
| src/Light.PortableResults.Validation/Assertions/Checks.IsIn.cs | Adds IsIn assertion using cached range definitions and templates. |
| src/Light.PortableResults.Validation/Assertions/Checks.IsGreaterThan.cs | Adds IsGreaterThan assertion using cached definitions and templates. |
| ai-plans/0026-error-definitions.md | Adds design/acceptance criteria and detailed rationale for the new infrastructure. |
| AGENTS.md | Updates contributor guidance and documents validation semantics (target composition and Check<string?> null normalization). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
…rmalized when calling Check<T>.AddError Signed-off-by: Kenny Pflug <[email protected]>
Minimum allowed line rate is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new infrastructure for reusable validation error definitions and implements several new built-in assertion methods for the validation library. The main goal is to allow both built-in and custom validation rules to reuse error definitions with clear defaults, ergonomic APIs, and efficient caching, especially for parameterized rules. The changes also provide new assertion methods for common validation scenarios and update documentation to reflect these new capabilities.
Validation Error Definitions Infrastructure:
New Built-in Assertion Methods:
Light.PortableResults.Validation.Assertionsnamespace:IsNotNullchecks for null values and supports short-circuiting by default.IsGreaterThanandIsLessThancheck for comparative boundaries and use the new error-definition infrastructure, with optional short-circuiting. [1] [2]IsInchecks for inclusive range boundaries using cached parameterized definitions.Documentation and Guidance Updates:
ai-plans/0026-error-definitions.md) explaining the rationale, acceptance criteria, technical details, and usage examples for the new validation error definition model and built-in assertions.AGENTS.mdto clarify API design guidance and document new validation behaviors, such as howCheck<string?>normalizes nulls and how target composition is handled. [1] [2]These changes make it easier to implement, reuse, and customize validation rules, and they lay the groundwork for more advanced and maintainable validation flows in the library.