From f1b60e4b51184c57a95a487319786b8910e72a9a Mon Sep 17 00:00:00 2001 From: Steven Enamakel <31011319+senamakel@users.noreply.github.com> Date: Sat, 9 May 2026 14:03:31 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20expand?= =?UTF-8?q?=20coverage=20for=20normalizeRpcMethod=20(#1413)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/services/__tests__/rpcMethods.test.ts | 44 ++++++++++++++++--- app/src/services/rpcMethods.ts | 16 ++++--- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app/src/services/__tests__/rpcMethods.test.ts b/app/src/services/__tests__/rpcMethods.test.ts index 8d2c725ea..75056c0a8 100644 --- a/app/src/services/__tests__/rpcMethods.test.ts +++ b/app/src/services/__tests__/rpcMethods.test.ts @@ -5,13 +5,43 @@ import { describe, expect, test } from 'vitest'; import { CORE_RPC_METHODS, LEGACY_METHOD_ALIASES, normalizeRpcMethod } from '../rpcMethods'; describe('rpcMethods catalog', () => { - test('normalizes legacy aliases and prefixes', () => { - expect(normalizeRpcMethod('openhuman.get_config')).toBe(CORE_RPC_METHODS.configGet); - expect(normalizeRpcMethod('openhuman.auth.get_state')).toBe('openhuman.auth_get_state'); - expect(normalizeRpcMethod('openhuman.accessibility_status')).toBe( - CORE_RPC_METHODS.screenIntelligenceStatus - ); - expect(normalizeRpcMethod('openhuman.threads_list')).toBe('openhuman.threads_list'); + describe('normalizeRpcMethod', () => { + test('resolves all legacy aliases to their canonical core method', () => { + for (const [legacyMethod, coreMethod] of Object.entries(LEGACY_METHOD_ALIASES)) { + expect(normalizeRpcMethod(legacyMethod)).toBe(coreMethod); + } + }); + + test('transforms auth methods by replacing dots with underscores', () => { + expect(normalizeRpcMethod('openhuman.auth.login')).toBe('openhuman.auth_login'); + expect(normalizeRpcMethod('openhuman.auth.get.state')).toBe('openhuman.auth_get_state'); + expect(normalizeRpcMethod('openhuman.auth.a.b.c')).toBe('openhuman.auth_a_b_c'); + }); + + test('transforms accessibility prefix to screen_intelligence prefix', () => { + expect(normalizeRpcMethod('openhuman.accessibility_status')).toBe( + 'openhuman.screen_intelligence_status' + ); + expect(normalizeRpcMethod('openhuman.accessibility_enable')).toBe( + 'openhuman.screen_intelligence_enable' + ); + }); + + test('returns unmapped or unrecognized methods unchanged', () => { + expect(normalizeRpcMethod('openhuman.threads_list')).toBe('openhuman.threads_list'); + expect(normalizeRpcMethod('openhuman.unknown_method')).toBe('openhuman.unknown_method'); + expect(normalizeRpcMethod('')).toBe(''); + expect(normalizeRpcMethod('random_string')).toBe('random_string'); + }); + + test('trims whitespace and converts to lower case', () => { + expect(normalizeRpcMethod(' OpenHuman.Auth.Login ')).toBe('openhuman.auth_login'); + expect(normalizeRpcMethod(' OPENHUMAN.GET_CONFIG ')).toBe(CORE_RPC_METHODS.configGet); + expect(normalizeRpcMethod('OpenHuman.Accessibility_Status ')).toBe( + 'openhuman.screen_intelligence_status' + ); + expect(normalizeRpcMethod(' some_RANDOM_method ')).toBe('some_random_method'); + }); }); test('legacy aliases point at canonical method values', () => { diff --git a/app/src/services/rpcMethods.ts b/app/src/services/rpcMethods.ts index f3f361577..4a76d93b7 100644 --- a/app/src/services/rpcMethods.ts +++ b/app/src/services/rpcMethods.ts @@ -30,17 +30,19 @@ export const LEGACY_METHOD_ALIASES: Record = { }; export function normalizeRpcMethod(method: string): string { - if (method in LEGACY_METHOD_ALIASES) { - return LEGACY_METHOD_ALIASES[method]; + const normalized = method.trim().toLowerCase(); + + if (normalized in LEGACY_METHOD_ALIASES) { + return LEGACY_METHOD_ALIASES[normalized]; } - if (method.startsWith('openhuman.auth.')) { - return `openhuman.auth_${method.slice('openhuman.auth.'.length).split('.').join('_')}`; + if (normalized.startsWith('openhuman.auth.')) { + return `openhuman.auth_${normalized.slice('openhuman.auth.'.length).split('.').join('_')}`; } - if (method.startsWith('openhuman.accessibility_')) { - return method.replace('openhuman.accessibility_', 'openhuman.screen_intelligence_'); + if (normalized.startsWith('openhuman.accessibility_')) { + return normalized.replace('openhuman.accessibility_', 'openhuman.screen_intelligence_'); } - return method; + return normalized; }