Skip to content

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

test(memory): cover brain tab, synced sources, and helpers

Steven Enamakel12deb584de03
diff --git a/app/src/components/memory/MemoryBrainTab.test.tsx b/app/src/components/memory/MemoryBrainTab.test.tsx
index c39e83fc1b..35fa5e682e 100644
--- a/app/src/components/memory/MemoryBrainTab.test.tsx
+++ b/app/src/components/memory/MemoryBrainTab.test.tsx
@@ -1,126 +1,60 @@
-import { fireEvent, screen, waitFor, within } from '@testing-library/react';
+import { fireEvent, screen, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { renderWithProviders } from '../../test/test-utils';
import MemoryBrainTab from './MemoryBrainTab';
-const hoisted = vi.hoisted(() => ({
- sources: vi.fn(),
- search: vi.fn(),
- ingest: vi.fn(),
- forget: vi.fn(),
-}));
+const hoisted = vi.hoisted(() => ({ ingest: vi.fn() }));
vi.mock('../../services/api/memoryApi', async importOriginal => ({
...(await importOriginal<typeof import('../../services/api/memoryApi')>()),
- memoryBrainSources: (...a: unknown[]) => hoisted.sources(...a),
- memoryBrainSearch: (...a: unknown[]) => hoisted.search(...a),
memoryBrainIngest: (...a: unknown[]) => hoisted.ingest(...a),
- memoryBrainForget: (...a: unknown[]) => hoisted.forget(...a),
}));
-// The synced-sources registry has its own suite.
+// The synced-sources registry, the import flow and the announcement have their own suites.
vi.mock('./MemorySyncedSources', () => ({
default: () => <div data-testid="stub-synced-sources" />,
}));
-
-const BRAIN = {
- root: 'user:me',
- sources: [
- { source: 'pdf', documents: 4 },
- { source: 'gmail', documents: 2 },
- ],
- unfiled: 1,
-};
+vi.mock('./MemoryImportBanner', () => ({
+ default: ({ engineLabel }: { engineLabel: string }) => (
+ <div data-testid="stub-import">{engineLabel}</div>
+ ),
+}));
+vi.mock('./MemoryCortexAnnouncement', () => ({
+ default: () => <div data-testid="stub-announcement" />,
+}));
beforeEach(() => {
- hoisted.sources.mockReset().mockResolvedValue(BRAIN);
- hoisted.search.mockReset();
hoisted.ingest.mockReset();
- hoisted.forget.mockReset();
});
-describe('MemoryBrainTab', () => {
- it('lists per-source counts, the unfiled count and the synced sources', async () => {
- renderWithProviders(<MemoryBrainTab />);
- const pdf = await screen.findByTestId('memory-brain-source-pdf');
- expect(pdf).toHaveTextContent('PDF');
- expect(pdf).toHaveTextContent('4 documents');
- // An unknown source id shows verbatim.
- expect(screen.getByTestId('memory-brain-source-gmail')).toHaveTextContent('gmail');
- expect(screen.getByTestId('memory-brain-unfiled')).toHaveTextContent('1 documents');
+describe('MemoryBrainTab (Files)', () => {
+ it('shows the announcement and import banner on top, then upload and synced sources', () => {
+ renderWithProviders(<MemoryBrainTab engineLabel="TinyHumans" />);
+ expect(screen.getByTestId('stub-announcement')).toBeInTheDocument();
+ expect(screen.getByTestId('stub-import')).toHaveTextContent('TinyHumans');
+ expect(screen.getByTestId('memory-brain-add')).toBeInTheDocument();
expect(screen.getByTestId('stub-synced-sources')).toBeInTheDocument();
+ // The per-source counts, search and forget-source block are gone.
+ expect(screen.queryByTestId('memory-brain-sources')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('memory-brain-search-input')).not.toBeInTheDocument();
});
- it('shows the empty state', async () => {
- hoisted.sources.mockResolvedValue({ root: 'user:me', sources: [], unfiled: 0 });
- renderWithProviders(<MemoryBrainTab />);
- expect(await screen.findByTestId('memory-brain-empty')).toBeInTheDocument();
- });
-
- it('forgets a source only after confirming', async () => {
- hoisted.forget.mockResolvedValue({ forgotten: 4 });
- renderWithProviders(<MemoryBrainTab />);
- fireEvent.click(await screen.findByTestId('memory-brain-source-pdf-forget'));
- expect(await screen.findByTestId('memory-brain-forget')).toHaveTextContent(
- 'Every PDF document will be removed'
- );
- expect(hoisted.forget).not.toHaveBeenCalled();
-
- hoisted.sources.mockResolvedValue({ ...BRAIN, sources: [BRAIN.sources[1]] });
- fireEvent.click(screen.getByTestId('memory-brain-forget-confirm'));
- await waitFor(() => expect(hoisted.forget).toHaveBeenCalledWith('pdf'));
- expect(await screen.findByTestId('memory-brain-notice')).toHaveTextContent(
- 'Forgot 4 PDF documents.'
- );
- await waitFor(() =>
- expect(screen.queryByTestId('memory-brain-source-pdf')).not.toBeInTheDocument()
- );
- });
-
- it('shows a forget failure', async () => {
- hoisted.forget.mockRejectedValue(new Error('ENGINE: down'));
- renderWithProviders(<MemoryBrainTab />);
- fireEvent.click(await screen.findByTestId('memory-brain-source-gmail-forget'));
- fireEvent.click(await screen.findByTestId('memory-brain-forget-confirm'));
- expect(await screen.findByTestId('memory-brain-error')).toHaveTextContent('ENGINE: down');
- });
-
- it('searches the brain within one source', async () => {
- hoisted.search.mockResolvedValue({
- hits: [{ id: 'd1', kind: 'document', text: 'Q3 plan', meta: {}, score: 0.7 }],
- });
- renderWithProviders(<MemoryBrainTab />);
- const source = await screen.findByTestId('memory-brain-search-source');
- fireEvent.change(source, { target: { value: 'pdf' } });
- fireEvent.change(screen.getByTestId('memory-brain-search-input'), {
- target: { value: 'planning' },
- });
- fireEvent.click(screen.getByTestId('memory-brain-search-submit'));
- await waitFor(() =>
- expect(hoisted.search).toHaveBeenCalledWith({ query: 'planning', source: 'pdf', limit: 20 })
+ it('replaces the import flow, upload and sources with the off state while memory is off', () => {
+ renderWithProviders(
+ <MemoryBrainTab engineLabel="TinyHumans" offState={<div data-testid="off" />} />
);
- const hits = await screen.findByTestId('memory-brain-search-hits');
- expect(within(hits).getByTestId('memory-hit-d1')).toHaveTextContent('Q3 plan');
- });
-
- it('says when a search finds nothing, and shows a search failure', async () => {
- hoisted.search.mockResolvedValueOnce({ hits: [] }).mockRejectedValueOnce(new Error('boom'));
- renderWithProviders(<MemoryBrainTab />);
- const input = await screen.findByTestId('memory-brain-search-input');
- fireEvent.change(input, { target: { value: 'nothing' } });
- fireEvent.click(screen.getByTestId('memory-brain-search-submit'));
- expect(await screen.findByTestId('memory-brain-search-empty')).toBeInTheDocument();
- expect(hoisted.search).toHaveBeenCalledWith({ query: 'nothing', limit: 20 });
-
- fireEvent.click(screen.getByTestId('memory-brain-search-submit'));
- expect(await screen.findByTestId('memory-brain-search-error')).toHaveTextContent('boom');
+ expect(screen.getByTestId('stub-announcement')).toBeInTheDocument();
+ expect(screen.getByTestId('off')).toBeInTheDocument();
+ expect(screen.queryByTestId('stub-import')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('memory-brain-add')).not.toBeInTheDocument();
+ expect(screen.queryByTestId('stub-synced-sources')).not.toBeInTheDocument();
});
it('adds pasted text with a title and source', async () => {
hoisted.ingest.mockResolvedValue({ id: 'doc-1', source: 'markdown', replayed: false });
- renderWithProviders(<MemoryBrainTab />);
- fireEvent.click(await screen.findByTestId('memory-brain-add'));
+ renderWithProviders(<MemoryBrainTab engineLabel="TinyHumans" />);
+ fireEvent.click(screen.getByTestId('memory-brain-add'));
const submit = screen.getByTestId('memory-brain-ingest-submit');
expect(submit).toBeDisabled();
@@ -146,13 +80,12 @@ describe('MemoryBrainTab', () => {
'Added to the brain under Markdown.'
);
expect(screen.queryByTestId('memory-brain-ingest')).not.toBeInTheDocument();
- expect(hoisted.sources).toHaveBeenCalledTimes(2);
});
it('adds a file by path and reports a replayed document', async () => {
hoisted.ingest.mockResolvedValue({ id: 'doc-1', source: 'pdf', replayed: true });
- renderWithProviders(<MemoryBrainTab />);
- fireEvent.click(await screen.findByTestId('memory-brain-add'));
+ renderWithProviders(<MemoryBrainTab engineLabel="TinyHumans" />);
+ fireEvent.click(screen.getByTestId('memory-brain-add'));
fireEvent.click(screen.getByTestId('memory-brain-ingest-from-path'));
fireEvent.change(screen.getByTestId('memory-brain-ingest-path'), {
target: { value: '/docs/plan.pdf' },
@@ -166,8 +99,8 @@ describe('MemoryBrainTab', () => {
it('keeps the dialog open with the error when ingest fails', async () => {
hoisted.ingest.mockRejectedValue(new Error('INVALID_REQUEST: unreadable'));
- renderWithProviders(<MemoryBrainTab />);
- fireEvent.click(await screen.findByTestId('memory-brain-add'));
+ renderWithProviders(<MemoryBrainTab engineLabel="TinyHumans" />);
+ fireEvent.click(screen.getByTestId('memory-brain-add'));
fireEvent.change(screen.getByTestId('memory-brain-ingest-text'), { target: { value: 'x' } });
fireEvent.click(screen.getByTestId('memory-brain-ingest-submit'));
expect(await screen.findByTestId('memory-brain-ingest-error')).toHaveTextContent('unreadable');
@@ -176,19 +109,12 @@ describe('MemoryBrainTab', () => {
it('prompts a top-up in the ingest dialog when the account is out of credits', async () => {
hoisted.ingest.mockRejectedValue(new Error('INSUFFICIENT_CREDITS: HTTP 402'));
- renderWithProviders(<MemoryBrainTab />);
- fireEvent.click(await screen.findByTestId('memory-brain-add'));
+ renderWithProviders(<MemoryBrainTab engineLabel="TinyHumans" />);
+ fireEvent.click(screen.getByTestId('memory-brain-add'));
fireEvent.change(screen.getByTestId('memory-brain-ingest-text'), { target: { value: 'x' } });
fireEvent.click(screen.getByTestId('memory-brain-ingest-submit'));
const prompt = await screen.findByTestId('memory-brain-ingest-error');
expect(prompt).toHaveAttribute('data-kind', 'out-of-credits');
expect(screen.getByTestId('memory-top-up')).toBeInTheDocument();
});
-
- it('shows a load error', async () => {
- hoisted.sources.mockRejectedValue(new Error('MEMORY_OFF'));
- renderWithProviders(<MemoryBrainTab />);
- expect(await screen.findByTestId('memory-brain-error')).toHaveTextContent('MEMORY_OFF');
- expect(screen.getByTestId('memory-brain-empty')).toBeInTheDocument();
- });
});
diff --git a/app/src/components/memory/MemorySyncedSources.test.tsx b/app/src/components/memory/MemorySyncedSources.test.tsx
index 4ff0214527..0201816615 100644
--- a/app/src/components/memory/MemorySyncedSources.test.tsx
+++ b/app/src/components/memory/MemorySyncedSources.test.tsx
@@ -27,11 +27,11 @@ const NOTES: Source = {
};
const FEED: Source = {
id: 's2',
- kind: 'rss',
- target: 'https://example.com/feed.xml',
+ kind: 'file',
+ target: '/Users/me/missing.md',
label: '',
status: 'error',
- error: 'feed returned 404',
+ error: 'file not found',
items: 0,
};
@@ -52,7 +52,7 @@ describe('MemorySyncedSources', () => {
expect(notes).toHaveTextContent('Every 60 min');
expect(notes).toHaveTextContent('Last synced');
expect(screen.getByTestId('memory-source-s2-status')).toHaveTextContent('Error');
- expect(screen.getByTestId('memory-source-s2-error')).toHaveTextContent('feed returned 404');
+ expect(screen.getByTestId('memory-source-s2-error')).toHaveTextContent('file not found');
expect(screen.getByTestId('memory-source-s2')).toHaveTextContent('Never synced');
});
@@ -88,23 +88,35 @@ describe('MemorySyncedSources', () => {
await waitFor(() => expect(screen.queryByTestId('memory-add-source')).not.toBeInTheDocument());
});
- it('adds a GitHub source and keeps the dialog open on failure', async () => {
- hoisted.add.mockRejectedValue(new Error('INVALID_REQUEST: repo not found'));
+ it('offers only folder and file as source types', async () => {
renderWithProviders(<MemorySyncedSources />);
fireEvent.click(await screen.findByTestId('memory-sources-add'));
- fireEvent.change(screen.getByTestId('memory-add-source-kind'), { target: { value: 'github' } });
+ const kind = screen.getByTestId('memory-add-source-kind');
+ const options = Array.from(kind.querySelectorAll('option')).map(o => o.getAttribute('value'));
+ expect(options).toEqual(['folder', 'file']);
expect(screen.getByTestId('memory-add-source-target')).toHaveAttribute(
'placeholder',
- 'owner/repo'
+ '/path/to/folder'
+ );
+ });
+
+ it('adds a file source and keeps the dialog open on failure', async () => {
+ hoisted.add.mockRejectedValue(new Error('INVALID_REQUEST: file not found'));
+ renderWithProviders(<MemorySyncedSources />);
+ fireEvent.click(await screen.findByTestId('memory-sources-add'));
+ fireEvent.change(screen.getByTestId('memory-add-source-kind'), { target: { value: 'file' } });
+ expect(screen.getByTestId('memory-add-source-target')).toHaveAttribute(
+ 'placeholder',
+ '/path/to/file.md'
);
fireEvent.change(screen.getByTestId('memory-add-source-target'), {
- target: { value: 'acme/missing' },
+ target: { value: '/docs/missing.md' },
});
fireEvent.click(screen.getByTestId('memory-add-source-submit'));
expect(await screen.findByTestId('memory-add-source-error')).toHaveTextContent(
- 'repo not found'
+ 'file not found'
);
- expect(hoisted.add).toHaveBeenCalledWith({ kind: 'github', target: 'acme/missing' });
+ expect(hoisted.add).toHaveBeenCalledWith({ kind: 'file', target: '/docs/missing.md' });
});
it('prompts a top-up in the add dialog when the account is out of credits', async () => {
diff --git a/app/src/components/memory/memoryHelpers.test.ts b/app/src/components/memory/memoryHelpers.test.ts
index 4c3b15b128..900886c822 100644
--- a/app/src/components/memory/memoryHelpers.test.ts
+++ b/app/src/components/memory/memoryHelpers.test.ts
@@ -1,6 +1,5 @@
import { describe, expect, it } from 'vitest';
-import { MEMORY_CHIPS, resolveMemoryChip } from './memoryChips';
import {
fill,
formatScore,
@@ -12,31 +11,6 @@ import {
const t = (key: string) => key;
-describe('resolveMemoryChip', () => {
- it('passes every v2 chip through', () => {
- for (const chip of MEMORY_CHIPS) expect(resolveMemoryChip(chip)).toBe(chip);
- });
-
- it('maps v1 sub-tabs', () => {
- expect(resolveMemoryChip('graph')).toBe('ask');
- expect(resolveMemoryChip('goals')).toBe('ask');
- expect(resolveMemoryChip('sources')).toBe('brain');
- expect(resolveMemoryChip('sync')).toBe('brain');
- expect(resolveMemoryChip('history')).toBe('brain');
- });
-
- it('maps retired v2 chips', () => {
- expect(resolveMemoryChip('documents')).toBe('brain');
- expect(resolveMemoryChip('context')).toBe('ask');
- });
-
- it('returns null for nothing or an unknown value', () => {
- expect(resolveMemoryChip(null)).toBeNull();
- expect(resolveMemoryChip('')).toBeNull();
- expect(resolveMemoryChip('welcome')).toBeNull();
- });
-});
-
describe('memoryFormat', () => {
it('fills every placeholder occurrence', () => {
expect(fill('{a} and {b} and {a}', { a: 1, b: 'x' })).toBe('1 and x and 1');
diff --git a/vendor/tinyconnectors b/vendor/tinyconnectors
index 381ff1a6fb..2897f27db4 160000
--- a/vendor/tinyconnectors
+++ b/vendor/tinyconnectors
@@ -1 +1 @@
-Subproject commit 381ff1a6fb9aff17e030225f625d391d308c44b5
+Subproject commit 2897f27db4b4466871b6a768b3da187712fdf3a5
diff --git a/vendor/tinymemory b/vendor/tinymemory
index 95f29433bf..aa48fc6c19 160000
--- a/vendor/tinymemory
+++ b/vendor/tinymemory
@@ -1 +1 @@
-Subproject commit 95f29433bfcd21493033978868255668e374d082
+Subproject commit aa48fc6c19131332ac04dd96c277ea9fd126635c