Skip to content

fix(node): SetCredential reports DUPLICATE/OCCUPIED instead of Failure - #4381

Open
Luligu wants to merge 2 commits into
matter-js:mainfrom
Luligu:fix/door-lock-set-credential-status-codes
Open

fix(node): SetCredential reports DUPLICATE/OCCUPIED instead of Failure#4381
Luligu wants to merge 2 commits into
matter-js:mainfrom
Luligu:fix/door-lock-set-credential-status-codes

Conversation

@Luligu

@Luligu Luligu commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

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.setCredential returned the generic Status.Failure (1) in two cases where Matter 1.6.0 § 5.2.10.21.1 requires a specific status: a duplicate CredentialData should report DUPLICATE (2), and an Add operation targeting an already-occupied CredentialIndex should report OCCUPIED (3).
  • No existing test coverage exercised DoorLockServer/setCredential at all, so the regression wasn't caught. Added packages/node/test/behaviors/door-lock/DoorLockServerTest.ts covering both cases.

Test plan

  • New unit tests fail against the unfixed code (expected 1 to equal 2/3) and pass with the fix
  • npm run build (type check + transpile) clean across the monorepo

CHIP test run with the Matterbridge CHIP test engine:

Chip tests run started at 2026-08-31T08:49:03.419Z

✅ DoorLock attributes on DoorLock (Test_TC_DRLK_2_1)
✅ DoorLock LockDoor command on DoorLock (TC_DRLK_2_2.py)
✅ DoorLock UnlockDoor command on DoorLock (TC_DRLK_2_3.py)
✅ DoorLock UnlockWithTimeout command on DoorLock (Test_TC_DRLK_2_4)
✅ DoorLock week day schedule commands on DoorLock (TC_DRLK_2_5.py)
✅ DoorLock holiday schedule commands on DoorLock (Test_TC_DRLK_2_6)
✅ DoorLock year day schedule commands on DoorLock (Test_TC_DRLK_2_7)
✅ DoorLock user commands on DoorLock (Test_TC_DRLK_2_8)
✅ DoorLock credential commands on DoorLock (TC_DRLK_2_9.py)
✅ DoorLock events on DoorLock (Test_TC_DRLK_2_10)
✅ DoorLock multiple credential types on DoorLock (Test_TC_DRLK_2_11)
⏭️ DoorLock UnboltDoor command on DoorLock (TC_DRLK_2_12.py)
   ↳ Requires the Unbolting feature and UnboltDoor command; endpoint 801 has neither. The Python test asserts the command PICS instead of skipping when DRLK.S.F0c=0.
⏭️ DoorLock Aliro functionality on DoorLock (TC_DRLK_2_13.py)
   ↳ Requires the Aliro Provisioning feature; endpoint 801 does not implement it. The Python test still sends an unconditional ClearUser command when DRLK.S.F0d=0 and fails with UNSUPPORTED_COMMAND.
✅ DoorLock client commands on DoorLock (Test_TC_DRLK_3_2)
✅ DoorLock User, PIN, and schedule attributes on DoorLockUserPINSchedules (Test_TC_DRLK_2_1)
✅ DoorLock LockDoor with PIN on DoorLockUserPINSchedules (TC_DRLK_2_2.py)
✅ DoorLock UnlockDoor with PIN on DoorLockUserPINSchedules (TC_DRLK_2_3.py)
✅ DoorLock UnlockWithTimeout with PIN on DoorLockUserPINSchedules (Test_TC_DRLK_2_4)
✅ DoorLock week day schedule commands on DoorLockUserPINSchedules (TC_DRLK_2_5.py)
✅ DoorLock holiday schedule commands on DoorLockUserPINSchedules (Test_TC_DRLK_2_6)
✅ DoorLock year day schedule commands on DoorLockUserPINSchedules (Test_TC_DRLK_2_7)
✅ DoorLock user commands on DoorLockUserPINSchedules (Test_TC_DRLK_2_8)
✅ DoorLock PIN credential commands on DoorLockUserPINSchedules (TC_DRLK_2_9.py)
✅ DoorLock events on DoorLockUserPINSchedules (Test_TC_DRLK_2_10)
✅ DoorLock PIN credential type on DoorLockUserPINSchedules (Test_TC_DRLK_2_11)
⏭️ DoorLock UnboltDoor command on DoorLockUserPINSchedules (TC_DRLK_2_12.py)
   ↳ Requires the Unbolting feature and UnboltDoor command; endpoint 8012 has neither. The Python test asserts the command PICS instead of skipping when DRLK.S.F0c=0.
⏭️ DoorLock Aliro functionality on DoorLockUserPINSchedules (TC_DRLK_2_13.py)
   ↳ Requires the Aliro Provisioning feature; endpoint 8012 does not implement it. The Python test unconditionally sends ClearAliroReaderConfig when ClearCredential is supported, even when DRLK.S.F0d=0.
✅ DoorLock client commands on DoorLockUserPINSchedules (Test_TC_DRLK_3_2)

Summary: 24/24 tests passed (4 skipped).

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.
Copilot AI balanced review requested due to automatic review settings August 31, 2026 08:52
@Luligu
Luligu requested a review from Apollon77 as a code owner August 31, 2026 08:52

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

Corrects Door Lock credential responses to use specification-defined duplicate and occupied status codes.

Changes:

  • Returns DUPLICATE and OCCUPIED for 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 Status escape hides that the generated SetCredentialResponse.status API 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 global Status and DoorLock.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 Status cast has the same public-type mismatch: callers and implementations should be able to use DoorLock.StatusCode.Occupied without 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, and npm 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 thread packages/node/src/behaviors/door-lock/DoorLockServer.ts Outdated
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants