fix(node): SetCredential reports DUPLICATE/OCCUPIED instead of Failure - #4381
Open
Luligu wants to merge 2 commits into
Open
fix(node): SetCredential reports DUPLICATE/OCCUPIED instead of Failure#4381Luligu wants to merge 2 commits into
Luligu wants to merge 2 commits into
Conversation
Per Matter 1.6.0 § 5.2.10.21.1, a duplicate CredentialData or an Add targeting an occupied CredentialIndex must report the DUPLICATE/OCCUPIED status codes, not a generic Failure.
Contributor
There was a problem hiding this comment.
Pull request overview
Corrects Door Lock credential responses to use specification-defined duplicate and occupied status codes.
Changes:
- Returns
DUPLICATEandOCCUPIEDfor applicable credential conflicts. - Adds focused Door Lock server tests.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/node/src/behaviors/door-lock/DoorLockServer.ts |
Updates credential conflict statuses. |
packages/node/test/behaviors/door-lock/DoorLockServerTest.ts |
Tests duplicate and occupied cases. |
Suppressed comments (4)
packages/node/src/behaviors/door-lock/DoorLockServer.ts:323
- The
as unknown as Statusescape hides that the generatedSetCredentialResponse.statusAPI cannot represent the cluster-specific codes its own contract permits. Repository TypeScript rules prohibit type casts; update the Door Lock model/override so this field includes both globalStatusandDoorLock.StatusCode, regenerate@matter/types, and return the enum directly.
return { status: DoorLock.StatusCode.Duplicate as unknown as Status, userIndex: null, nextCredentialIndex: null };
packages/node/src/behaviors/door-lock/DoorLockServer.ts:337
- This second
as unknown as Statuscast has the same public-type mismatch: callers and implementations should be able to useDoorLock.StatusCode.Occupiedwithout bypassing type safety. Correct and regenerate the response status type rather than casting the cluster code.
return { status: DoorLock.StatusCode.Occupied as unknown as Status, userIndex: null, nextCredentialIndex };
packages/node/test/behaviors/door-lock/DoorLockServerTest.ts:31
- The parenthetical records an unrelated defect and temporary test-construction history rather than a final-code invariant. Repository comment rules require issue context to stay in the PR/commit; retain only why this fixture uses an existing user.
// A pre-existing user avoids the Add branch's new-user creation path (which has its own,
// unrelated userUniqueId bug) so the test can focus on the credential status codes.
packages/node/test/behaviors/door-lock/DoorLockServerTest.ts:114
- The test plan documents only the build, these focused tests, and the CHIP run. The repository's mandatory gate also requires recorded output for formatting, lint, and the full test suite (
npm run format,npm run lint, andnpm test); please run and document those results before approval.
await node.close();
});
});
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+15
to
+16
| async function createLock() { | ||
| const node = await MockServerNode.createOnline(undefined, { device: undefined }); |
Comment on lines
+335
to
+337
| // Per § 5.2.10.21.1, an Add operation targeting an occupied CredentialIndex reports OCCUPIED, not a | ||
| // generic Failure. | ||
| return { status: DoorLock.StatusCode.Occupied as unknown as Status, userIndex: null, nextCredentialIndex }; |
Fixes the format-verify CI failure on PR matter-js#4381.
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.
Per Matter 1.6.0 § 5.2.10.21.1, a duplicate CredentialData or an Add targeting an occupied CredentialIndex must report the DUPLICATE/OCCUPIED status codes, not a generic Failure.
Summary
DoorLockBaseServer.setCredentialreturned the genericStatus.Failure(1) in two cases where Matter 1.6.0 § 5.2.10.21.1 requires a specific status: a duplicateCredentialDatashould reportDUPLICATE(2), and anAddoperation targeting an already-occupiedCredentialIndexshould reportOCCUPIED(3).DoorLockServer/setCredentialat all, so the regression wasn't caught. Addedpackages/node/test/behaviors/door-lock/DoorLockServerTest.tscovering both cases.Test plan
expected 1 to equal 2/3) and pass with the fixnpm run build(type check + transpile) clean across the monorepoCHIP test run with the Matterbridge CHIP test engine: