Skip to content

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

test(memory): e2e for the Engine tab connect flows

M3gA-Mind73ab86ee503e
diff --git a/app/test/playwright/specs/memory-v2.spec.ts b/app/test/playwright/specs/memory-v2.spec.ts
index d4d77ebe54..d29ea5ff22 100644
--- a/app/test/playwright/specs/memory-v2.spec.ts
+++ b/app/test/playwright/specs/memory-v2.spec.ts
@@ -2,6 +2,8 @@ import { expect, type Page, type Request, type Route, test } from '@playwright/t
import {
bootAuthenticatedPage,
+ bootRuntimeReadyGuestPage,
+ callCoreRpc,
dismissWalkthroughIfPresent,
waitForAppReady,
} from '../helpers/core-rpc';
@@ -139,9 +141,12 @@ async function installMemoryFake(page: Page, opts: FakeOptions): Promise<MemoryF
case 'memory_engine_get':
return engineState();
case 'memory_engine_set':
+ // Echo what was set, so the tab marks the option it maps to as active
+ // (a loopback endpoint is Self-host, none is the API-key option).
return {
engine: params.engine,
- has_key: false,
+ ...(params.endpoint ? { endpoint: params.endpoint } : {}),
+ has_key: Boolean(params.api_key),
status: 'ok',
fetch_modes: ['keyword', 'vector'],
};
@@ -521,3 +526,112 @@ test.describe('Memory v2 — memory off', () => {
expect(fake.paramsOf('memory_sources_list')).toEqual([]);
});
});
+
+/**
+ * A session token as the core stores it. The `local` signature marks the
+ * offline "Set it up myself" session (`isLocalSessionToken`), which has no
+ * TinyHumans account, so Built-in memory must not be selectable for it.
+ */
+function sessionToken(userId: string, signature: string): string {
+ const payload = Buffer.from(
+ JSON.stringify({ sub: userId, userId, exp: Math.floor(Date.now() / 1000) + 3600 })
+ ).toString('base64url');
+ return `eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.${payload}.${signature}`;
+}
+
+test.describe('Memory v2 — Engine tab connect flows', () => {
+ test('Built-in connects with one click when signed in', async ({ page }) => {
+ const fake = await installMemoryFake(page, { engineOn: false });
+ await bootAuthenticatedPage(page, 'pw-memory-engine-builtin');
+ // Stay on Engine: with no `?brain=` the page moves to Ask once memory is on.
+ await openMemory(page, '&brain=engine');
+
+ // Nothing connected: Built-in is open and selectable.
+ const use = page.getByTestId('memory-engine-builtin-use');
+ await expect(use).toBeEnabled({ timeout: 20_000 });
+ await use.click();
+ await expect.poll(() => fake.paramsOf('memory_engine_set')).toEqual([{ engine: 'tinyhumans' }]);
+ await expect(page.getByTestId('memory-engine-builtin-active')).toHaveText('Active');
+ });
+
+ test('API key connects CortexDB cloud with only a key', async ({ page }) => {
+ const fake = await installMemoryFake(page, { engineOn: false });
+ await bootAuthenticatedPage(page, 'pw-memory-engine-apikey');
+ // Stay on Engine: with no `?brain=` the page moves to Ask once memory is on.
+ await openMemory(page, '&brain=engine');
+
+ await page.getByTestId('memory-engine-apikey-trigger').click();
+ await expect(page.getByTestId('memory-engine-apikey-trigger')).toContainText(
+ 'https://api-v1.cortexdb.ai'
+ );
+ const submit = page.getByTestId('memory-engine-apikey-submit');
+ await expect(submit).toBeDisabled(); // a key is required
+ await page.getByTestId('memory-engine-apikey-key').fill('pw-cortex-key');
+ await submit.click();
+ // A blank endpoint clears any custom one, so the managed API is used.
+ await expect
+ .poll(() => fake.paramsOf('memory_engine_set'))
+ .toEqual([{ engine: 'cortexdb', endpoint: '', api_key: 'pw-cortex-key' }]);
+ await expect(page.getByTestId('memory-engine-apikey-active')).toHaveText('Active');
+ });
+
+ test('Self-host refuses a non-local endpoint and connects a local one', async ({ page }) => {
+ const fake = await installMemoryFake(page, { engineOn: false });
+ await bootAuthenticatedPage(page, 'pw-memory-engine-selfhost');
+ // Stay on Engine: with no `?brain=` the page moves to Ask once memory is on.
+ await openMemory(page, '&brain=engine');
+
+ await page.getByTestId('memory-engine-selfhost-trigger').click();
+ await expect(page.getByTestId('memory-engine-selfhost-docs')).toBeVisible();
+ await page.getByTestId('memory-engine-selfhost-key').fill('pw-local-key');
+
+ // Not on this computer: refused before any RPC.
+ await page.getByTestId('memory-engine-selfhost-endpoint').fill('http://192.168.1.10:3141');
+ await expect(page.getByTestId('memory-engine-selfhost-endpoint-error')).toContainText(
+ 'Self-hosting is local only'
+ );
+ await expect(page.getByTestId('memory-engine-selfhost-submit')).toBeDisabled();
+ expect(fake.paramsOf('memory_engine_set')).toEqual([]);
+
+ // Loopback: accepted and sent with the key.
+ await page.getByTestId('memory-engine-selfhost-endpoint').fill('http://localhost:3141');
+ await expect(page.getByTestId('memory-engine-selfhost-endpoint-error')).toHaveCount(0);
+ await page.getByTestId('memory-engine-selfhost-submit').click();
+ await expect
+ .poll(() => fake.paramsOf('memory_engine_set'))
+ .toEqual([
+ { engine: 'cortexdb', endpoint: 'http://localhost:3141', api_key: 'pw-local-key' },
+ ]);
+ await expect(page.getByTestId('memory-engine-selfhost-active')).toHaveText('Active');
+ });
+
+ test('Built-in is not selectable without a TinyHumans account', async ({ page }) => {
+ const fake = await installMemoryFake(page, { engineOn: false });
+ // A "Set it up myself" (local) session that finished onboarding.
+ await bootRuntimeReadyGuestPage(page);
+ // The core requires the local user payload, as Welcome's "Set it up
+ // myself" stores it (utils/localSession.ts LOCAL_SESSION_USER).
+ await callCoreRpc('openhuman.auth_store_session', {
+ token: sessionToken('local', 'local'),
+ user: { _id: 'local', id: 'local', name: 'Local User', email: '[email protected]' },
+ });
+ await callCoreRpc('openhuman.config_set_onboarding_completed', { value: true });
+ await page.goto(`${MEMORY_URL}&brain=engine`);
+ await page.reload();
+ await waitForAppReady(page);
+ // The shell restores its persisted chat route once ready; reapply the
+ // Memory route afterwards, as bootAuthenticatedPage does.
+ await page.goto(`${MEMORY_URL}&brain=engine`);
+ await waitForAppReady(page);
+ await dismissWalkthroughIfPresent(page);
+ await expect(page.getByTestId('memory-page')).toBeVisible({ timeout: 30_000 });
+
+ await expect(page.getByTestId('memory-engine-builtin-trigger')).toContainText(
+ 'Sign in to use',
+ { timeout: 20_000 }
+ );
+ await expect(page.getByTestId('memory-engine-builtin-sign-in')).toBeVisible();
+ await expect(page.getByTestId('memory-engine-builtin-use')).toBeDisabled();
+ expect(fake.paramsOf('memory_engine_set')).toEqual([]);
+ });
+});