Files
openhuman/app/src/utils/__tests__/tauriCommands.test.ts
T
Steven EnamakelandGitHub e925e8a319 Fix local reset flow and Accessibility permission handling (#324)
* refactor: clean up imports and improve code structure in skills_cli and registry_ops

- Removed unused imports in `skills_cli.rs` and `registry_ops.rs` to enhance code clarity.
- Streamlined import statements for better organization and readability.
- Minor adjustments in `engine.rs` to maintain consistency in import usage.

* fix: update UI text and styles for MemoryWorkspace and SkillSetupWizard components

- Changed the title in MemoryWorkspace to "Memory (EverMind)" for clarity.
- Updated text colors in SkillSetupWizard for better visibility and consistency.
- Enhanced button styles and loading indicators for improved user experience.

* feat: implement reset functionality for OpenHuman data and enhance app data clearing process

- Added a new utility function `resetOpenHumanDataAndRestartCore` to reset local OpenHuman data and restart the core process.
- Updated `clearAllAppData` in `SettingsHome` to utilize the new reset function, improving the app's data clearing process.
- Enhanced error handling during the data reset and session clearing operations to ensure robustness.
- Introduced tests for the new reset functionality to validate its behavior and integration.

* refactor: remove screen recording permission from AccessibilityPanel

- Eliminated the screen recording permission check and associated UI elements from the AccessibilityPanel component.
- Updated tests to ensure the screen recording option is no longer present in the rendered output, improving clarity and focus on relevant permissions.

* chore: update package.json files to integrate Husky for Git hooks

- Added Husky as a dev dependency in both package.json files to manage Git hooks.
- Included "prepare" and "postinstall" scripts in the main package.json to ensure Husky is set up correctly.
- Cleaned up the app's package.json by removing the "prepare" script, as it is now handled in the main package.json.
- Enhanced logging in tauriCommands.ts for better debugging during the reset process.

* fix: update variable name for clarity in ops.rs test assertions

- Changed the variable name from `data` to `value` in the test assertions to enhance clarity and better reflect its purpose.
- Ensured that the assertions remain functional and maintain the integrity of the test logic.

* feat: enhance skill selection logic in skills_debug_e2e.rs

- Introduced a new function `select_skill_id` to improve skill selection based on environment variables and preferred skills.
- Updated the skill ID retrieval process to prioritize user-defined skills while maintaining a fallback to the default skill.
- Enhanced documentation to clarify the usage of environment variables for skill testing.

* format
2026-04-04 20:26:08 -07:00

72 lines
3.0 KiB
TypeScript

import { invoke, isTauri } from '@tauri-apps/api/core';
import { beforeEach, describe, expect, type Mock, test, vi } from 'vitest';
import { callCoreRpc } from '../../services/coreRpcClient';
vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn(), isTauri: vi.fn() }));
vi.mock('../../services/coreRpcClient', () => ({ callCoreRpc: vi.fn() }));
describe('tauriCommands', () => {
const mockIsTauri = isTauri as Mock;
const mockInvoke = invoke as Mock;
const mockCallCoreRpc = callCoreRpc as Mock;
let getAuthState: typeof import('../tauriCommands').getAuthState;
let resetOpenHumanDataAndRestartCore: typeof import('../tauriCommands').resetOpenHumanDataAndRestartCore;
let storeSession: typeof import('../tauriCommands').storeSession;
let openhumanLocalAiStatus: typeof import('../tauriCommands').openhumanLocalAiStatus;
let openhumanServiceStatus: typeof import('../tauriCommands').openhumanServiceStatus;
beforeEach(async () => {
vi.clearAllMocks();
mockIsTauri.mockReturnValue(true);
const actual = await vi.importActual<typeof import('../tauriCommands')>('../tauriCommands');
getAuthState = actual.getAuthState;
resetOpenHumanDataAndRestartCore = actual.resetOpenHumanDataAndRestartCore;
storeSession = actual.storeSession;
openhumanLocalAiStatus = actual.openhumanLocalAiStatus;
openhumanServiceStatus = actual.openhumanServiceStatus;
});
test('getAuthState maps result shape from core response', async () => {
mockCallCoreRpc.mockResolvedValueOnce({
result: { isAuthenticated: true, user: { id: 'u1' } },
});
const response = await getAuthState();
expect(mockCallCoreRpc).toHaveBeenCalledWith({ method: 'openhuman.auth.get_state' });
expect(response).toEqual({ is_authenticated: true, user: { id: 'u1' } });
});
test('storeSession calls expected RPC method and params', async () => {
await storeSession('jwt-token', { id: 'u1' });
expect(mockCallCoreRpc).toHaveBeenCalledWith({
method: 'openhuman.auth.store_session',
params: { token: 'jwt-token', user: { id: 'u1' } },
});
});
test('resetOpenHumanDataAndRestartCore invokes the destructive Tauri command', async () => {
await resetOpenHumanDataAndRestartCore();
expect(mockCallCoreRpc).toHaveBeenCalledWith({ method: 'openhuman.config_reset_local_data' });
expect(mockInvoke).toHaveBeenCalledWith('restart_core_process');
});
test('openhumanLocalAiStatus returns upgrade hint on unknown method', async () => {
mockCallCoreRpc.mockRejectedValueOnce(new Error('unknown method: openhuman.local_ai_status'));
await expect(openhumanLocalAiStatus()).rejects.toThrow(
'Local model runtime is unavailable in this core build. Restart app after updating to the latest build.'
);
});
test('openhumanServiceStatus throws when not running in Tauri', async () => {
mockIsTauri.mockReturnValue(false);
await expect(openhumanServiceStatus()).rejects.toThrow('Not running in Tauri');
expect(mockCallCoreRpc).not.toHaveBeenCalled();
});
});