Repository navigation
Hold data to member and semantic-type ranges [patch] - #359
Merged
Merged
Conversation
SchemaDataValidator checked a value against its type and never read a range, so a non-wrapping [0, 100] Int member accepted 500 and -7. A number outside a non-wrapping range is now an error at the value's path that names the range and its owner. Vectors and vector quantities are checked per component, a wrapping range accepts any number, and the range of a semantic type applies wherever a value of it appears, alongside the member's own. The migrator asks the validator through ConformsTo, which now takes the member's range, so a value the new range refuses is reported and takes the default instead of being carried into data that no longer validates. Fixes #349 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3VYgr52Mw1KS9otcE
Contributor
Author
|
CI is red on #353 has the fix and is mergeable. I haven't copied that refactor in here, since it would duplicate #353 across three open PRs and they would then conflict with it. Once #353 merges I'll bring Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
…r-range-on-data # Conflicts: # Schema.Test/SchemaDataValidatorTypeTests.cs
|
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.



Fixes #349
What changed
SchemaDataValidatornow appliesrangeto data values, whichdocs/schema-format.mdalready called for:500 is outside the range [0, 100] of member 'Health'.data.Value[1]), matching howrangeis validated on the schema side.ValidateSemanticValue, so it applies wherever a value of that type appears: a member, an array element, a map value or an optional. The ranges of the types it refines apply too.docs/schema-format.md.The paths that go through the validator:
kschema validateand the generated data editors'Issues/IsValidpick the check up automatically, since the editors callSchemaDataValidator.SchemaDataMigrator:ConformsTonow takes the member's range. A carried-over value the new range refuses follows the migrator's existing non-conforming rule (report it and use the default), with a message that says it is out of range rather than the wrong type. Without this, migrated data would no longer validate clean.Tests
SchemaDataValidatorTypeTests: in range, on both bounds, out of range (the message names the range and the member), just past a float bound, a wrapping range, a vector checked per component, a wrong-type value reported once, a semantic-type range on a member and in an array, and a member range combined with a semantic range.GeneratedDataEditorTests:Countnow has a[0, 100]range. An out-of-range payload is added to the editor-vs-validator parity set, plusTestTheEditorRefusesAValueOutsideAMembersRange.SchemaMigrationTests.AValueOutsideTheCurrentRangeIsReportedAndTakesTheDefault: the out-of-range value is replaced with the default and reported, the in-range one is kept, and the result validates clean.With the fix reverted, the 9 new cases fail. With it, the full
Schema.Testsuite passes on net10.0 (733/733).Main currently fails CA1506 on
Schema/Models/Schema.cs(#353 fixes that). I ran the tests locally with that one rule suppressed, and the suppression isn't part of this PR. CI here will stay red on CA1506 until #353 lands.Not covered: a vector whose
ElementTypeis a ranged semantic type doesn't get that semantic type's range per component. The validator reduces component semantics inExpectNumberwithout going throughValidateSemanticValue. Easy follow-up if wanted.Generated by Claude Code