fix: get_gear uses numeric userProfilePk, complete_mfa resets state on timeout
This commit is contained in:
@@ -97,7 +97,8 @@ def complete_mfa(code: str) -> str:
|
||||
return "MFA accepted. Authenticated successfully."
|
||||
return f"Authentication failed after MFA: {err}"
|
||||
except queue.Empty:
|
||||
return "Timed out waiting for authentication to complete."
|
||||
_auth_state = "unauthenticated"
|
||||
return "Timed out waiting for authentication to complete. Call authenticate() again."
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
@@ -288,7 +289,11 @@ def get_gear() -> str:
|
||||
if err := _check_auth():
|
||||
return err
|
||||
try:
|
||||
result = _client.get_gear(_client.display_name)
|
||||
profile = _client.get_user_profile()
|
||||
user_id = profile.get("userId") or profile.get("id")
|
||||
if not user_id:
|
||||
return "Could not determine user profile ID required for gear lookup."
|
||||
result = _client.get_gear(str(user_id))
|
||||
if not result:
|
||||
return "No gear found."
|
||||
return json.dumps(result, indent=2)
|
||||
|
||||
@@ -270,13 +270,14 @@ def test_get_devices_empty():
|
||||
def test_get_gear_success():
|
||||
server._auth_state = "authenticated"
|
||||
server._client = MagicMock()
|
||||
server._client.display_name = "john.doe"
|
||||
server._client.get_user_profile.return_value = {"userId": 12345}
|
||||
server._client.get_gear.return_value = [
|
||||
{"gearPk": "shoe1", "customMakeModel": "Nike Pegasus", "totalDistance": 320000.0}
|
||||
]
|
||||
data = json.loads(server.get_gear())
|
||||
assert data[0]["customMakeModel"] == "Nike Pegasus"
|
||||
server._client.get_gear.assert_called_once_with("john.doe")
|
||||
server._client.get_user_profile.assert_called_once()
|
||||
server._client.get_gear.assert_called_once_with("12345")
|
||||
|
||||
|
||||
def test_get_user_profile_success():
|
||||
|
||||
Reference in New Issue
Block a user