Skip to content

♻️ (device-management-kit) [NO-ISSUE]: Use WaitForAppAndVersionDeviceAction in GetDeviceStatusDeviceAction#1540

Open
benruseau wants to merge 1 commit into
developfrom
refactor/no-issue-get-device-status-da
Open

♻️ (device-management-kit) [NO-ISSUE]: Use WaitForAppAndVersionDeviceAction in GetDeviceStatusDeviceAction#1540
benruseau wants to merge 1 commit into
developfrom
refactor/no-issue-get-device-status-da

Conversation

@benruseau

@benruseau benruseau commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

📝 Description

This PR refactors GetDeviceStatusDeviceAction to reuse the existing WaitForAppAndVersionDeviceAction instead of duplicating its logic (see merged PR).

Previously, GetDeviceStatusDeviceAction implemented its own app/version retrieval and device-unlock handling: a getAppAndVersion command call, a waitForDeviceUnlock observable that polled every second with a timeout, and a dedicated UserActionUnlockDevice state with all the related error/locked-state handling (5515 locked device, 6e00 CLA not supported, etc.).

All of that logic now lives in WaitForAppAndVersionDeviceAction, so this DA simply invokes it as a child state machine, forwarding the unlockTimeout input and propagating the requiredUserInteraction via onSnapshot. The result is handled with a clean Left/Right caseOf, delegating locked-device and old-firmware edge cases to the shared action.

This removes ~270 lines of duplicated state-machine logic and centralizes the "wait for app and version (handling unlock)" behavior in a single place.

Key changes:

  • Replaced the getAppAndVersion actor and waitForDeviceUnlock observable with a single waitForAppAndVersion child machine.
  • Removed the UserActionUnlockDevice state, the locked internal state, the isDeviceLocked guard, and the unlock-related actions/errors.
  • Renamed states AppAndVersionCheckWaitForAppAndVersion and ApplicationAvailableResultCheckWaitForAppAndVersionResultCheck.
  • Updated GetDeviceStatusDAError to reuse WaitForAppAndVersionDAError (dropping DeviceLockedError, UnknownDAError, and the raw command error).
  • Updated step constants (WAIT_FOR_APP_AND_VERSION added, UNLOCK_DEVICE removed).
  • Added a setupWaitForAppAndVersionMock test helper and reworked the test suite accordingly.

❓ Context

  • JIRA or GitHub link: NO-ISSUE

  • Feature: Internal refactor of GetDeviceStatusDeviceAction to delegate app/version + unlock handling to WaitForAppAndVersionDeviceAction, reducing duplication.

✅ Checklist

Pull Requests must pass CI checks and undergo code review. Set the PR as Draft if it is not yet ready for review.

  • Covered by automatic tests
  • Changeset is provided
  • Documentation is up-to-date
  • Impact of the changes:
    • GetDeviceStatusDeviceAction now depends on WaitForAppAndVersionDeviceAction; QA should verify the full GetDeviceStatus flow on dashboard (BOLOS) and inside apps.
    • Locked-device behavior: confirm the unlock prompt still appears and that unlocking within the timeout resumes correctly, and that timing out surfaces the expected error.
    • Old-firmware / CLA-not-supported (6e00) and locked (5515) edge cases still behave as before.
    • Onboarding detection and OS-version reading remain unaffected.

🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.

@benruseau benruseau requested a review from a team as a code owner June 8, 2026 13:28
Copilot AI review requested due to automatic review settings June 8, 2026 13:28
@vercel

vercel Bot commented Jun 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
device-sdk-ts-sample Error Error Jun 9, 2026 1:33pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
doc-device-management-kit Ignored Ignored Jun 9, 2026 1:33pm

Request Review

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Danger Check Results

Messages

Danger: All checks passed successfully! 🎉

Generated by 🚫 dangerJS against 9d5b303

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 refactors GetDeviceStatusDeviceAction to delegate “get app + version (including unlock handling)” to the existing WaitForAppAndVersionDeviceAction, reducing duplicated state-machine logic and adjusting tests accordingly.

Changes:

  • Replaced the inlined app/version + unlock flow in GetDeviceStatusDeviceAction with an invoked WaitForAppAndVersion child machine.
  • Simplified GetDeviceStatus error typing to reuse WaitForAppAndVersionDAError and updated step constants.
  • Reworked the GetDeviceStatusDeviceAction test suite and added a reusable setupWaitForAppAndVersionMock helper.

Reviewed changes

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

Show a summary per file
File Description
packages/device-management-kit/src/api/device-action/os/GetDeviceStatus/types.ts Updates steps and error unions to align with WaitForAppAndVersion.
packages/device-management-kit/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.ts Refactors the state machine to invoke WaitForAppAndVersion as a child action.
packages/device-management-kit/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.ts Updates expectations and mocking strategy to match the refactor.
packages/device-management-kit/src/api/device-action/test-utils/setupTestMachine.ts Adds setupWaitForAppAndVersionMock helper for tests.
.changeset/spicy-snails-eat.md Patch changeset documenting the refactor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@benruseau benruseau changed the title ♻️ (device-management-kit) [NO-ISSUE]: use WaitForAppAndVersionDeviceAction in GetDeviceStatusDeviceAction ♻️ (device-management-kit) [NO-ISSUE]: Use WaitForAppAndVersionDeviceAction in GetDeviceStatusDeviceAction Jun 8, 2026
@sonarqubecloud

sonarqubecloud Bot commented Jun 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
13.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

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