Skip to content

fix(model): reject invalid conformance choice/optionality constructs#3991

Merged
mergify[bot] merged 5 commits into
mainfrom
fix/conformance-reject-invalid-choice
Jun 26, 2026
Merged

fix(model): reject invalid conformance choice/optionality constructs#3991
mergify[bot] merged 5 commits into
mainfrom
fix/conformance-reject-invalid-choice

Conversation

@Apollon77

Copy link
Copy Markdown
Collaborator

Summary

The conformance DSL parser silently mis-parsed three constructs that are invalid per the Matter spec grammar. It now rejects them via conformance.error(...) instead of producing a wrong AST, so any future spec/model authoring bug surfaces loudly.

Input Before After
O.a2-4 (range-form choice, §7.3.14) "O.a2-, 4" silently INVALID_CHOICE
AB.a2+- (mixed +/-, §7.3.14) "AB.a2" silently INVALID_CHOICE
[AA] & BB (partial optionality, §7.3.4) "[AA], BB" + misleading token error INVALID_OPTIONALITY

These forms are latent in the 1.6 model (zero occurrences); the change reverses the prior lenient-parser stance for these specific invalid forms only.

Implementation

  • Choice suffix: +/- are now mutually exclusive; a repeated/second sign emits a mixed-modifier error and is drained. A bare value token trailing a choice is flagged as an unsupported range form.
  • Optional bracket: a binary operator following a top-level [...] group is flagged as partial optionality and drained to the next separator.

Valid forms still parse and round-trip: AB.a, AB.a+, AB.a-, AB.a2, AB.a2+, AB.a2-, [AB].a, [X | Y].a+, O, qualified names.

Verification

  • New tests: 7 reject cases + 2 valid round-trips. 114/114 Conformance, 464/464 @matter/model suite green.
  • Full 1.6 standard model via ValidateModel: 0 total errors, 0 new-error hits — confirms latent, no real strings affected.
  • format-verify, lint (oxlint), build --clean all clean.

🤖 Generated with Claude Code

The conformance DSL parser silently mis-parsed three constructs that are
invalid per the spec grammar: range-form choice (§7.3.14, e.g. "a2-4"),
mixed "+"/"-" choice modifiers (§7.3.14), and partial optionality
(§7.3.4, e.g. "[AA] & BB"). The parser now emits INVALID_CHOICE /
INVALID_OPTIONALITY errors for these instead of producing a wrong AST,
so any future spec/model authoring bug surfaces loudly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 26, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens the @matter/model conformance DSL parser to explicitly reject a few invalid Matter-spec grammar constructs that were previously being mis-parsed into an incorrect AST, ensuring spec/model authoring errors surface via conformance.error(...). It adds targeted tests for the newly rejected forms and documents the change in the changelog.

Changes:

  • Update conformance parsing to reject (and drain) invalid choice suffix patterns (mixed/repeated +/-, and unsupported “range-form” trailing numbers).
  • Detect and reject “partial optionality” where a top-level [...] group is combined with a binary operator (e.g. [AA] & BB).
  • Add test coverage for the reject cases and add a @matter/model changelog entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/model/src/aspects/Conformance.ts Adds explicit erroring and recovery logic for invalid choice/range and partial-optional constructs.
packages/model/test/aspects/ConformanceTest.ts Adds tests for invalid constructs and expands valid round-trip definitions for - choice suffix.
CHANGELOG.md Notes the conformance parser behavior change (and also contains an unrelated edit needing confirmation).

Comment thread packages/model/src/aspects/Conformance.ts Outdated
Comment thread CHANGELOG.md
Apollon77 and others added 2 commits June 26, 2026 16:22
…ty error

The partial-optionality recovery drained to the next comma, but whitespace
also separates top-level conformance terms, so "[AA] & BB CC" discarded the
valid "CC". Drain only the offending binary expression (operator + operands)
so following terms still parse.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread packages/model/src/aspects/Conformance.ts Outdated
Comment thread packages/model/src/aspects/Conformance.ts Outdated
Comment thread CHANGELOG.md
The modifier error fires for repeated modifiers too (e.g. "a2++"), so
"but not both" was misleading; reword to "at most one modifier". Reword
the range-form error from "not supported" to "invalid" and mention both
"a2-4" and "a2+4" forms.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Apollon77 Apollon77 requested a review from Copilot June 26, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread CHANGELOG.md
@Apollon77 Apollon77 added the automerge Set this label if the PR is ready to automatically merged after approval label Jun 26, 2026
@mergify

mergify Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@mergify mergify Bot merged commit 5f12036 into main Jun 26, 2026
44 checks passed
@mergify mergify Bot deleted the fix/conformance-reject-invalid-choice branch June 26, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Set this label if the PR is ready to automatically merged after approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants