🧪 [testing improvement] expand coverage for normalizeRpcMethod (#1413)

This commit is contained in:
Steven Enamakel
2026-05-09 14:03:31 -07:00
committed by GitHub
parent cc61792d52
commit f1b60e4b51
2 changed files with 46 additions and 14 deletions
+37 -7
View File
@@ -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', () => {
+9 -7
View File
@@ -30,17 +30,19 @@ export const LEGACY_METHOD_ALIASES: Record<string, CoreRpcMethod> = {
};
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;
}