fix(model): enforce §7.7.9 scene-quality datatype restriction and compare revisions numerically#3990
Merged
Conversation
…pare revisions numerically
Add AttributeValidator check that a Scene ("S") quality attribute resolves to an unsigned
integer or boolean type of at most 4 bytes (enum8/map8 derived types allowed), emitting
INVALID_SCENE_TYPE otherwise.
Replace raw string comparison in Model.appliesTo() with Specification.compareRevisions(),
which compares dotted-numeric revisions segment-by-segment (missing trailing segments treated
as zero). Fixes the trap where a trimmed generation revision ("1.6.0" -> "1.6") made
asOf "1.6.0" silently fail. Generated model output is byte-identical, so existing overrides
resolve unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the @matter/model layer to (1) enforce Matter spec §7.7.9’s datatype restriction for attributes with Scene (“S”) quality, and (2) fix revision applicability checks by comparing specification revisions numerically instead of lexically.
Changes:
- Add
AttributeValidatorvalidation that Scene quality only applies to bool/unsigned int ≤ 4 bytes (including derived types like enums/bitmaps viaprimitiveBase). - Introduce
Specification.compareRevisions()for segment-by-segment numeric revision comparison and use it inModel.appliesTo(). - Add targeted unit tests covering the new scene-type validation and revision comparison/appliesTo regressions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/model/src/logic/definition-validation/AttributeValidator.ts | Enforces Scene-quality datatype constraints per spec via primitiveBase + Metatype. |
| packages/model/src/common/Specification.ts | Adds numeric dotted-revision comparison helper. |
| packages/model/src/models/Model.ts | Switches appliesTo() to use numeric revision comparison. |
| packages/model/test/logic/definition-validation/AttributeValidatorTest.ts | Adds tests for allowed/blocked Scene-quality datatypes (including derived types). |
| packages/model/test/common/SpecificationTest.ts | Adds tests for compareRevisions() and appliesTo() trimming regression. |
…size Require byteSize to be present for integer types rather than defaulting a missing size to 0 (which would have allowed it). Addresses PR review. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
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.
Summary
Two model-layer fixes (from todo backlog).
1. §7.7.9 scene-quality datatype restriction
AttributeValidatornow validates that an attribute carrying the Scene (S) quality resolves to an unsigned integer or boolean type of at most 4 bytes (derived types such asenum8/map8resolve throughprimitiveBaseto their underlyinguintand pass). Violations emitINVALID_SCENE_TYPE.Per spec §7.7.9: "This quality SHALL only apply to attributes having unsigned integer or boolean data types of size at most 4 bytes from the Base Data Types list (e.g. bool, uint8, uint16, uint32), or derived types thereof (e.g. enum8, map8)."
The current standard model already satisfies this — codegen
generate-modelvalidation reports zeroINVALID_SCENE_TYPE, so this is a guard for future/custom definitions.2. Numeric (semver-style) revision comparison
Model.appliesTo()previously compared spec revisions with raw string comparison. Because the generation revision is trimmed ("1.6.0"→"1.6"), a naturalasOf: "1.6.0"evaluated"1.6" >= "1.6.0"===falseand silently disabled the override. AddedSpecification.compareRevisions(a, b)— segment-by-segment numeric compare, missing trailing segments treated as zero — and switchedappliesTo()to use it.Verified safe: re-running
generate-modelproduces byte-identical generated output, so all existingasOf/untiloverrides resolve unchanged; only the patch-length-mismatch trap is fixed.Tests
AttributeValidatorTest.ts— 5 accept (bool, uint8, uint32, enum8, map8) / 3 reject (uint64, int8, string).SpecificationTest.ts—compareRevisionsordering/equality +appliesToregression cases.🤖 Generated with Claude Code