Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(memory-family-gate): add test file for MemoryFamilyGate component

Steven Enamakel52747fcb564a
diff --git a/app/src/components/intelligence/MemoryFamilyGate.test.tsx b/app/src/components/intelligence/MemoryFamilyGate.test.tsx
new file mode 100644
index 0000000000..9286c18766
--- /dev/null
+++ b/app/src/components/intelligence/MemoryFamilyGate.test.tsx
@@ -0,0 +1,68 @@
+/**
+ * MemoryFamilyGate: shows children when the bound engine has the family (or
+ * when that is unknown), and a friendly "Not available" state when it does not.
+ */
+import { screen, waitFor } from '@testing-library/react';
+import { beforeEach, describe, expect, test, vi } from 'vitest';
+
+import { renderWithProviders } from '../../test/test-utils';
+import MemoryFamilyGate from './MemoryFamilyGate';
+
+const hoisted = vi.hoisted(() => ({ list: vi.fn(), get: vi.fn() }));
+
+vi.mock('../../utils/tauriCommands/memoryEngine', () => ({
+ memoryEnginesList: (...a: unknown[]) => hoisted.list(...a),
+ memoryEngineGet: (...a: unknown[]) => hoisted.get(...a),
+}));
+
+function bind(driver: string, label: string, capabilities: string[]) {
+ hoisted.get.mockResolvedValue({ driver });
+ hoisted.list.mockResolvedValue({
+ active: driver,
+ engines: [{ id: driver, label, capabilities }],
+ });
+}
+
+describe('MemoryFamilyGate', () => {
+ beforeEach(() => {
+ hoisted.list.mockReset();
+ hoisted.get.mockReset();
+ });
+
+ test('shows the empty state naming the engine when the family is missing', async () => {
+ bind('mem0', 'Mem0', ['core', 'recall', 'portability']);
+ renderWithProviders(
+ <MemoryFamilyGate family="goals">
+ <div>goals body</div>
+ </MemoryFamilyGate>
+ );
+ await waitFor(() => expect(screen.getByTestId('memory-family-unavailable')).toBeTruthy());
+ expect(screen.getByText(/Not available with/)).toBeTruthy();
+ expect(screen.queryByText('goals body')).toBeNull();
+ });
+
+ test('renders children when the engine has the family', async () => {
+ bind('tinymemory', 'Local', ['core', 'recall', 'goals']);
+ renderWithProviders(
+ <MemoryFamilyGate family="goals">
+ <div>goals body</div>
+ </MemoryFamilyGate>
+ );
+ await waitFor(() => expect(hoisted.list).toHaveBeenCalled());
+ expect(screen.getByText('goals body')).toBeTruthy();
+ expect(screen.queryByTestId('memory-family-unavailable')).toBeNull();
+ });
+
+ test('fails open when the core cannot report the engine', async () => {
+ hoisted.get.mockRejectedValue(new Error('offline'));
+ hoisted.list.mockRejectedValue(new Error('offline'));
+ renderWithProviders(
+ <MemoryFamilyGate family="goals">
+ <div>goals body</div>
+ </MemoryFamilyGate>
+ );
+ await waitFor(() => expect(hoisted.get).toHaveBeenCalled());
+ expect(screen.getByText('goals body')).toBeTruthy();
+ expect(screen.queryByTestId('memory-family-unavailable')).toBeNull();
+ });
+});