The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(memory): combined banner review round and step-2 tests
M3gA-Mindf646dce752c6
diff --git a/app/src/components/memory/MemoryImportBanner.test.tsx b/app/src/components/memory/MemoryImportBanner.test.tsxindex b0fdfed009..528164bc66 100644--- a/app/src/components/memory/MemoryImportBanner.test.tsx+++ b/app/src/components/memory/MemoryImportBanner.test.tsx@@ -2,7 +2,11 @@ import { act, fireEvent, screen, waitFor } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { renderWithProviders } from '../../test/test-utils';-import MemoryImportBanner, { IMPORT_POLL_MS } from './MemoryImportBanner';+import MemoryImportBanner, {+ IMPORT_POLL_MS,+ MIGRATION_IDLE_POLL_MS,+ MIGRATION_POLL_MS,+} from './MemoryImportBanner';const hoisted = vi.hoisted(() => ({scan: vi.fn(),@@ -213,6 +217,16 @@ describe('MemoryImportBanner', () => {expect(hoisted.mStart).not.toHaveBeenCalled();});+ it('keeps the retry for refused items beside the move', async () => {+ hoisted.status.mockResolvedValue({+ state: { phase: 'done', imported: 7, total: 9, failed: 2 },+ });+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-banner')).toBeInTheDocument();+ expect(screen.getByTestId('memory-import-retry-failed')).toBeInTheDocument();+ });+it('takes a shared tree only after the takeover is confirmed', async () => {hoisted.scan.mockResolvedValue({ found: false });hoisted.mScan.mockResolvedValue({ needed: true, shared: true });@@ -223,4 +237,143 @@ describe('MemoryImportBanner', () => {fireEvent.click(screen.getByTestId('memory-migration-takeover-confirm'));await waitFor(() => expect(hoisted.mStart).toHaveBeenCalledWith(true));});++ describe('organizing (step 2)', () => {+ beforeEach(() => {+ hoisted.scan.mockResolvedValue({ found: false });+ });++ it('migrates now without a dialog when the tree is the account’s own', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ fireEvent.click(await screen.findByTestId('memory-migration-start'));+ await waitFor(() => expect(hoisted.mStart).toHaveBeenCalledWith(false));+ expect(screen.queryByTestId('memory-migration-takeover')).not.toBeInTheDocument();+ expect(await screen.findByTestId('memory-migration-running')).toHaveTextContent('4');+ });++ it('shows a failed start', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ hoisted.mStart.mockRejectedValue(new Error('boom'));+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ fireEvent.click(await screen.findByTestId('memory-migration-start'));+ expect(await screen.findByTestId('memory-import-error')).toBeInTheDocument();+ });++ it('cancels the takeover without starting anything', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: true });+ renderWithProviders(<MemoryImportBanner engineLabel="CortexDB" />);+ fireEvent.click(await screen.findByTestId('memory-migration-start'));+ fireEvent.click(await screen.findByTestId('memory-migration-takeover-cancel'));+ expect(screen.queryByTestId('memory-migration-takeover')).not.toBeInTheDocument();+ expect(hoisted.mStart).not.toHaveBeenCalled();+ });++ it('shows why a move paused and resumes it', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ hoisted.mStatus.mockResolvedValue({+ state: { phase: 'paused', copied: 3, error: 'not enough credits' },+ running: false,+ interrupted: false,+ });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-paused')).toHaveTextContent(+ 'not enough credits'+ );+ fireEvent.click(screen.getByTestId('memory-migration-start'));+ await waitFor(() => expect(hoisted.mStart).toHaveBeenCalledWith(false));+ });++ it('offers to try again what could not be moved', async () => {+ hoisted.mStatus.mockResolvedValue({+ state: {+ phase: 'cleaned',+ copied: 5,+ failures: [{ id: 'a', reason: 'too_large' }],+ incomplete: ['b'],+ },+ running: false,+ interrupted: false,+ });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-left')).toHaveTextContent('2');+ fireEvent.click(screen.getByTestId('memory-migration-retry'));+ await waitFor(() => expect(hoisted.mRetry).toHaveBeenCalled());+ await waitFor(() => expect(hoisted.mStart).toHaveBeenCalledWith(false));+ // The scan says nothing is needed, but the retry's run stays in view.+ expect(await screen.findByTestId('memory-migration-running')).toBeInTheDocument();+ });++ it('shows a failed retry', async () => {+ hoisted.mStatus.mockResolvedValue({+ state: { phase: 'cleaned', copied: 5, failures: [{ id: 'a', reason: 'x' }] },+ running: false,+ interrupted: false,+ });+ hoisted.mRetry.mockRejectedValue(new Error('boom'));+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-left')).toHaveTextContent('1');+ fireEvent.click(screen.getByTestId('memory-migration-retry'));+ expect(await screen.findByTestId('memory-import-error')).toBeInTheDocument();+ });++ it('polls a running move and scans again when it ends', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ hoisted.mStatus.mockResolvedValue(moving(1));+ vi.useFakeTimers({ shouldAdvanceTime: true });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-running')).toHaveTextContent('1');++ hoisted.mStatus.mockResolvedValue({+ state: { phase: 'cleaned', copied: 3 },+ running: false,+ interrupted: false,+ });+ hoisted.mScan.mockResolvedValue({ needed: false, shared: false });+ await act(async () => {+ await vi.advanceTimersByTimeAsync(MIGRATION_POLL_MS + 10);+ });+ await waitFor(() =>+ expect(screen.queryByTestId('memory-migration-banner')).not.toBeInTheDocument()+ );+ });++ it('notices a move the background job starts while it is offered', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ vi.useFakeTimers({ shouldAdvanceTime: true });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-offer')).toBeInTheDocument();+ hoisted.mStatus.mockResolvedValue(moving(2));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(MIGRATION_IDLE_POLL_MS + 10);+ });+ expect(await screen.findByTestId('memory-migration-running')).toHaveTextContent('2');+ });++ it('shows a failed status poll', async () => {+ hoisted.mScan.mockResolvedValue({ needed: true, shared: false });+ hoisted.mStatus.mockResolvedValueOnce(moving(1)).mockRejectedValue(new Error('boom'));+ vi.useFakeTimers({ shouldAdvanceTime: true });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ expect(await screen.findByTestId('memory-migration-running')).toBeInTheDocument();+ await act(async () => {+ await vi.advanceTimersByTimeAsync(MIGRATION_POLL_MS + 10);+ });+ expect(await screen.findByTestId('memory-import-error')).toBeInTheDocument();+ });++ it('scans again after a failed scan', async () => {+ hoisted.mScan+ .mockRejectedValueOnce(new Error('not ready'))+ .mockResolvedValue({ needed: true, shared: false });+ vi.useFakeTimers({ shouldAdvanceTime: true });+ renderWithProviders(<MemoryImportBanner engineLabel="TinyHumans" />);+ await waitFor(() => expect(hoisted.mScan).toHaveBeenCalledTimes(1));+ expect(screen.queryByTestId('memory-migration-banner')).not.toBeInTheDocument();+ await act(async () => {+ await vi.advanceTimersByTimeAsync(MIGRATION_IDLE_POLL_MS + 10);+ });+ expect(await screen.findByTestId('memory-migration-offer')).toBeInTheDocument();+ });+ });});diff --git a/app/src/components/memory/MemoryImportBanner.tsx b/app/src/components/memory/MemoryImportBanner.tsxindex 20c5f1064c..717590d563 100644--- a/app/src/components/memory/MemoryImportBanner.tsx+++ b/app/src/components/memory/MemoryImportBanner.tsx@@ -138,8 +138,11 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPrconst [takeoverOpen, setTakeoverOpen] = useState(false);const [mBusy, setMBusy] = useState(false);+ // Bumped to scan again after a failed scan.+ const [mScanAttempt, setMScanAttempt] = useState(0);useEffect(() => {let cancelled = false;+ let retry: ReturnType<typeof setTimeout> | undefined;Promise.all([memoryMigrationScan(), memoryMigrationStatus().catch(() => null)]).then(([found, current]) => {if (cancelled) return;@@ -147,14 +150,26 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPrsetMScan(found ?? null);setMStatus(current ?? null);})- .catch(err => mlog('scan failed: %o', err));+ .catch(err => {+ // A transient failure must not hide the move for good: try again.+ mlog('scan failed: %o', err);+ if (!cancelled) {+ retry = setTimeout(() => setMScanAttempt(n => n + 1), MIGRATION_IDLE_POLL_MS);+ }+ });return () => {cancelled = true;+ if (retry) clearTimeout(retry);};- }, []);+ }, [mScanAttempt]);const wasMoving = useRef(false);+ // One status request at a time: a slow answer must not land after, and+ // overwrite, a newer one.+ const mPolling = useRef(false);const mPoll = useCallback(async () => {+ if (mPolling.current) return;+ mPolling.current = true;try {const next = await memoryMigrationStatus();setMStatus(next);@@ -164,6 +179,8 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPr} catch (err) {mlog('status failed: %o', err);setError(memoryErrorMessage(err, t));+ } finally {+ mPolling.current = false;}}, [t]);@@ -279,67 +296,71 @@ export default function MemoryImportBanner({ engineLabel }: MemoryImportBannerPr</Alert>)}- {state && state.phase !== 'idle' && !(importDone && showMove) && (- <Alert- variant={- state.phase === 'error' ? 'destructive' : state.phase === 'done' ? 'success' : 'info'- }- data-testid={`memory-import-${state.phase}`}>- <div className="w-full space-y-2">- <AlertTitle>- {state.phase === 'running'- ? t('memoryPage.import.running')- : state.phase === 'done'- ? t('memoryPage.import.done')- : t('memoryPage.import.failed')}- </AlertTitle>- {state.phase === 'running' && (- <Progress- value={state.total > 0 ? Math.round((state.imported / state.total) * 100) : 0}- aria-label={t('memoryPage.import.running')}- />- )}- <AlertDescription>- {state.phase === 'error' && state.error- ? state.error- : fill(t('memoryPage.import.progress'), {- imported: state.imported,- total: state.total,- })}- </AlertDescription>- {state.phase === 'done' && (state.failed ?? 0) > 0 && (- <div className="flex flex-wrap items-center gap-3">- <span className="text-sm" data-testid="memory-import-failed-items">- {fill(t('memoryPage.import.failedItems'), { count: state.failed ?? 0 })}- {/* A retry the engine or account stopped says why; Retry again works. */}- {state.error ? ` ${state.error}` : ''}- </span>+ {state &&+ state.phase !== 'idle' &&+ // A clean import gives way to step 2; one with refused items keeps+ // its count and Retry beside it.+ !(importDone && showMove && !(state.failed ?? 0)) && (+ <Alert+ variant={+ state.phase === 'error' ? 'destructive' : state.phase === 'done' ? 'success' : 'info'+ }+ data-testid={`memory-import-${state.phase}`}>+ <div className="w-full space-y-2">+ <AlertTitle>+ {state.phase === 'running'+ ? t('memoryPage.import.running')+ : state.phase === 'done'+ ? t('memoryPage.import.done')+ : t('memoryPage.import.failed')}+ </AlertTitle>+ {state.phase === 'running' && (+ <Progress+ value={state.total > 0 ? Math.round((state.imported / state.total) * 100) : 0}+ aria-label={t('memoryPage.import.running')}+ />+ )}+ <AlertDescription>+ {state.phase === 'error' && state.error+ ? state.error+ : fill(t('memoryPage.import.progress'), {+ imported: state.imported,+ total: state.total,+ })}+ </AlertDescription>+ {state.phase === 'done' && (state.failed ?? 0) > 0 && (+ <div className="flex flex-wrap items-center gap-3">+ <span className="text-sm" data-testid="memory-import-failed-items">+ {fill(t('memoryPage.import.failedItems'), { count: state.failed ?? 0 })}+ {/* A retry the engine or account stopped says why; Retry again works. */}+ {state.error ? ` ${state.error}` : ''}+ </span>+ <Button+ type="button"+ size="sm"+ variant="secondary"+ disabled={starting}+ data-testid="memory-import-retry-failed"+ onClick={() => void retryFailed()}>+ {t('memoryPage.import.retryFailed')}+ </Button>+ </div>+ )}+ {state.phase === 'error' && (+ // The core keeps the checkpoint, so starting again resumes where+ // the import stopped; it still goes through the consent dialog.<Buttontype="button"size="sm"- variant="secondary"- disabled={starting}- data-testid="memory-import-retry-failed"- onClick={() => void retryFailed()}>- {t('memoryPage.import.retryFailed')}+ variant="primary"+ data-testid="memory-import-resume"+ onClick={() => setConsentOpen(true)}>+ {t('memoryPage.import.resume')}</Button>- </div>- )}- {state.phase === 'error' && (- // The core keeps the checkpoint, so starting again resumes where- // the import stopped; it still goes through the consent dialog.- <Button- type="button"- size="sm"- variant="primary"- data-testid="memory-import-resume"- onClick={() => setConsentOpen(true)}>- {t('memoryPage.import.resume')}- </Button>- )}- </div>- </Alert>- )}+ )}+ </div>+ </Alert>+ )}{showMove && (<div data-testid="memory-migration-banner">