Skip to content

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

wip(e2e): brain embedding-truthfulness and notifications feed specs

M3gA-Mind6dbb06a994f9
diff --git a/app/test/playwright/specs/brain-embedding-truthfulness.spec.ts b/app/test/playwright/specs/brain-embedding-truthfulness.spec.ts
new file mode 100644
index 0000000000..f666621394
--- /dev/null
+++ b/app/test/playwright/specs/brain-embedding-truthfulness.spec.ts
@@ -0,0 +1,199 @@
+import { expect, type Page, test } from '@playwright/test';
+import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+import {
+ bootAuthenticatedPage,
+ callCoreRpc,
+ dismissWalkthroughIfPresent,
+ waitForAppReady,
+} from '../helpers/core-rpc';
+
+/**
+ * `/brain` must tell the truth about embedding state, in a real browser.
+ *
+ * The incident: a workspace sat with 2,581 chunks synced and 0 embedded, and no
+ * degraded indicator appeared anywhere. Semantic search silently returned
+ * nothing findable while every surface reported a healthy sync.
+ *
+ * There is already a jsdom spec proving `MemorySourceRow` *renders* the warning
+ * when handed `chunks_pending > 0`
+ * (`app/src/components/intelligence/MemorySourceRow.pipelineWarning.test.tsx`).
+ * That proves the component. It cannot prove the thing that actually failed:
+ * that a user, on the real page, against a real core, with real chunks that
+ * were never embedded, SEES it. Between the component and the user sit
+ * `memory_sources_status_list`, `memory_tree_pipeline_status`, the registry's
+ * polling, the Brain tab routing and the row's `settled` suppression — none of
+ * which jsdom exercises.
+ *
+ * So this spec deliberately asserts nothing about props. It seeds a folder
+ * source through core RPC, syncs it for real, reads the core's own
+ * `chunks_pending` to establish the incident's precondition actually holds, and
+ * then asserts on rendered text.
+ *
+ * NOTE ON PATHS — the trap this lane is known for: a relative source path
+ * resolves against the core's working directory (the build dir) and fails
+ * forever with no error a user can act on. Everything here uses an absolute
+ * `mkdtempSync` root, which is also what the existing
+ * `intelligence-memory-ui-functional.spec.ts` does.
+ */
+
+interface SourceStatus {
+ source_id: string;
+ chunks_synced: number;
+ chunks_pending: number;
+}
+
+async function seedDeveloperMode(page: Page): Promise<void> {
+ await page.addInitScript(() => {
+ try {
+ const raw = localStorage.getItem('persist:theme');
+ const parsed: Record<string, string> = raw ? (JSON.parse(raw) as Record<string, string>) : {};
+ parsed.developerMode = JSON.stringify(true);
+ localStorage.setItem('persist:theme', JSON.stringify(parsed));
+ } catch {}
+ });
+}
+
+async function openSources(page: Page, user: string): Promise<void> {
+ await seedDeveloperMode(page);
+ await bootAuthenticatedPage(page, user, '/brain?tab=sources');
+ await waitForAppReady(page);
+ await dismissWalkthroughIfPresent(page);
+ await expect(page.getByTestId('memory-sources')).toBeVisible({ timeout: 20_000 });
+}
+
+/** Absolute path on purpose — see the note above. */
+function makeCorpus(files: number): string {
+ const root = mkdtempSync(join(tmpdir(), 'openhuman-pw-brain-'));
+ mkdirSync(join(root, 'notes'), { recursive: true });
+ for (let i = 0; i < files; i += 1) {
+ writeFileSync(
+ join(root, 'notes', `note-${i}.md`),
+ `# Note ${i}\n\nPlaywright brain canary paragraph ${i}. ${'filler '.repeat(40)}\n`
+ );
+ }
+ return root;
+}
+
+async function addAndSync(label: string, files = 3): Promise<{ id: string; root: string }> {
+ const root = makeCorpus(files);
+ const added = await callCoreRpc<{ id?: string } | null>('openhuman.memory_sources_add', {
+ kind: 'folder',
+ label,
+ enabled: true,
+ path: root,
+ glob: '**/*.md',
+ });
+ const list = await callCoreRpc<{ sources: Array<{ id: string; label: string }> }>(
+ 'openhuman.memory_sources_list',
+ {}
+ );
+ const id = added?.id ?? list.sources.find(s => s.label === label)?.id;
+ if (!id) throw new Error(`source ${label} was not created`);
+ await callCoreRpc('openhuman.memory_sources_sync', { id });
+ return { id, root };
+}
+
+async function statusFor(id: string): Promise<SourceStatus | undefined> {
+ const res = await callCoreRpc<{ statuses: SourceStatus[] }>(
+ 'openhuman.memory_sources_status_list',
+ {}
+ );
+ return res.statuses.find(s => s.source_id === id);
+}
+
+test.describe('Brain — the UI tells the truth about embedding state', () => {
+ test('a source whose chunks were never embedded is visibly flagged, not shown as healthy', async ({
+ page,
+ }) => {
+ const label = `PW Brain Unembedded ${Date.now()}`;
+ const { id } = await addAndSync(label);
+
+ // Establish the incident's precondition from the CORE, not from the UI.
+ // If this workspace happens to have a working embeddings provider there is
+ // nothing to warn about and the assertion below would be meaningless — so
+ // the precondition is checked explicitly rather than assumed.
+ let status: SourceStatus | undefined;
+ await expect
+ .poll(
+ async () => {
+ status = await statusFor(id);
+ return status?.chunks_synced ?? 0;
+ },
+ { timeout: 60_000, message: 'the folder source never produced chunks' }
+ )
+ .toBeGreaterThan(0);
+
+ test.skip(
+ (status?.chunks_pending ?? 0) === 0,
+ 'this core embedded every chunk, so there is no degraded state to surface'
+ );
+
+ await openSources(page, 'pw-brain-unembedded');
+
+ const row = page.getByTestId('memory-source-row-folder').filter({ hasText: label });
+ await expect(row).toBeVisible({ timeout: 30_000 });
+
+ // The whole point: rendered text a user can read, on the real page.
+ await expect(row.getByTestId(`memory-source-pipeline-warning-${id}`)).toBeVisible({
+ timeout: 30_000,
+ });
+ await expect(row).toContainText('Stored without vectors. Semantic search unavailable.');
+ await expect(row).toContainText('Ingested only');
+ });
+
+ test('the warning survives a reload rather than being a first-paint artefact', async ({
+ page,
+ }) => {
+ // A degraded state that only renders on the first poll is worse than none:
+ // the user refreshes to check and the app tells them everything is fine.
+ const label = `PW Brain Reload ${Date.now()}`;
+ const { id } = await addAndSync(label);
+
+ let status: SourceStatus | undefined;
+ await expect
+ .poll(async () => {
+ status = await statusFor(id);
+ return status?.chunks_synced ?? 0;
+ }, { timeout: 60_000 })
+ .toBeGreaterThan(0);
+ test.skip((status?.chunks_pending ?? 0) === 0, 'no degraded state on this core');
+
+ await openSources(page, 'pw-brain-reload');
+ const warning = page.getByTestId(`memory-source-pipeline-warning-${id}`);
+ await expect(warning).toBeVisible({ timeout: 30_000 });
+
+ await page.reload();
+ await waitForAppReady(page);
+ await dismissWalkthroughIfPresent(page);
+
+ await expect(page.getByTestId(`memory-source-pipeline-warning-${id}`)).toBeVisible({
+ timeout: 30_000,
+ });
+ });
+
+ test('offers a route to memory health from the flagged row', async ({ page }) => {
+ // The warning is only actionable if it leads somewhere. Without this the
+ // user is told semantic search is broken and given nothing to do about it.
+ const label = `PW Brain Health ${Date.now()}`;
+ const { id } = await addAndSync(label);
+
+ let status: SourceStatus | undefined;
+ await expect
+ .poll(async () => {
+ status = await statusFor(id);
+ return status?.chunks_synced ?? 0;
+ }, { timeout: 60_000 })
+ .toBeGreaterThan(0);
+ test.skip((status?.chunks_pending ?? 0) === 0, 'no degraded state on this core');
+
+ await openSources(page, 'pw-brain-health');
+ await expect(page.getByTestId(`memory-source-pipeline-warning-${id}`)).toBeVisible({
+ timeout: 30_000,
+ });
+
+ await expect(page.getByTestId(`memory-source-view-health-${id}`)).toBeVisible();
+ });
+});
diff --git a/app/test/playwright/specs/notifications-feed-interaction.spec.ts b/app/test/playwright/specs/notifications-feed-interaction.spec.ts
new file mode 100644
index 0000000000..32a8cf9f18
--- /dev/null
+++ b/app/test/playwright/specs/notifications-feed-interaction.spec.ts
@@ -0,0 +1,198 @@
+import { expect, type Page, test } from '@playwright/test';
+
+import { bootAuthenticatedPage, dismissWalkthroughIfPresent, waitForAppReady } from '../helpers/core-rpc';
+
+/**
+ * The system-events notification feed: filtering, mark-as-read, clear.
+ *
+ * `notifications.spec.ts` already covers the *integration* half — the core RPCs
+ * (`notification_ingest` / `_list` / `_mark_read` / `_stats`) and that the page
+ * renders both sections. It never touches the system-events feed's controls,
+ * which are a different data path entirely: those items arrive over socket.io
+ * from the Rust core and live in a redux-persist slice, so no core RPC can put
+ * one on screen.
+ *
+ * Seeding therefore goes through the app's own persistence, not a mock: the
+ * slice is persisted under `${activeUserId}:persist:notifications`
+ * (`store/index.ts:144-149`, `store/userScopedStorage.ts:177-180`), and
+ * `OPENHUMAN_ACTIVE_USER_ID` selects the namespace. Writing those two keys
+ * before navigation is exactly what a returning user's browser already holds —
+ * the real reducer rehydrates them, the real page renders them, and every
+ * assertion below is on what the user can see and click.
+ *
+ * What this pins is the part that is invisible to a component test: that the
+ * chips are a single-select tablist over the categories actually present, that
+ * clicking an item marks it read, and that "Mark all read" empties the unread
+ * count rather than only the badge.
+ */
+
+const USER = 'pw-notif-feed';
+
+interface SeedItem {
+ id: string;
+ category: string;
+ title: string;
+ body: string;
+ timestamp: number;
+ read: boolean;
+}
+
+function item(id: string, category: string, title: string, read = false): SeedItem {
+ return { id, category, title, body: `${title} body`, timestamp: Date.now(), read };
+}
+
+/**
+ * Seed the persisted notification slice for `USER`.
+ *
+ * redux-persist stores each whitelisted field as its own JSON string inside the
+ * blob, which is why `items` is double-encoded here.
+ */
+async function seedFeed(page: Page, items: SeedItem[]): Promise<void> {
+ await page.addInitScript(
+ ({ user, payload }) => {
+ window.localStorage.setItem('OPENHUMAN_ACTIVE_USER_ID', user);
+ window.localStorage.setItem(
+ `${user}:persist:notifications`,
+ JSON.stringify({ items: JSON.stringify(payload), _persist: '{"version":-1,"rehydrated":true}' })
+ );
+ },
+ { user: USER, payload: items }
+ );
+}
+
+async function openFeed(page: Page): Promise<void> {
+ await bootAuthenticatedPage(page, USER, '/notifications');
+ await waitForAppReady(page);
+ await dismissWalkthroughIfPresent(page);
+ await expect(page.getByTestId('system-events-section')).toBeVisible({ timeout: 20_000 });
+}
+
+const feed = (page: Page) => page.getByTestId('system-events-section');
+const rows = (page: Page) => feed(page).getByTestId('notification-item');
+
+test.describe('Notifications — the system-events feed renders what was stored', () => {
+ test('shows every seeded item', async ({ page }) => {
+ await seedFeed(page, [
+ item('n-agents-1', 'agents', 'Agent finished a task'),
+ item('n-system-1', 'system', 'Core restarted'),
+ ]);
+ await openFeed(page);
+
+ await expect(rows(page)).toHaveCount(2, { timeout: 20_000 });
+ await expect(feed(page)).toContainText('Agent finished a task');
+ await expect(feed(page)).toContainText('Core restarted');
+ });
+
+ test('offers a filter chip only for categories that are present', async ({ page }) => {
+ // The chip row is built from the categories actually in the feed. Offering
+ // a filter that can only ever show nothing is a dead control.
+ await seedFeed(page, [item('n-agents-1', 'agents', 'Agent finished a task')]);
+ await openFeed(page);
+
+ await expect(page.getByTestId('notif-filter-chip-all')).toBeVisible({ timeout: 20_000 });
+ await expect(page.getByTestId('notif-filter-chip-agents')).toBeVisible();
+ await expect(page.getByTestId('notif-filter-chip-system')).toHaveCount(0);
+ });
+});
+
+test.describe('Notifications — filtering is single-select and actually filters', () => {
+ test('narrows the feed to one category and back', async ({ page }) => {
+ await seedFeed(page, [
+ item('n-agents-1', 'agents', 'Agent finished a task'),
+ item('n-system-1', 'system', 'Core restarted'),
+ ]);
+ await openFeed(page);
+ await expect(rows(page)).toHaveCount(2, { timeout: 20_000 });
+
+ await page.getByTestId('notif-filter-chip-system').click();
+
+ await expect(rows(page)).toHaveCount(1);
+ await expect(feed(page)).toContainText('Core restarted');
+ await expect(feed(page)).not.toContainText('Agent finished a task');
+
+ await page.getByTestId('notif-filter-chip-all').click();
+ await expect(rows(page)).toHaveCount(2);
+ });
+
+ test('marks the active chip selected and deselects the previous one', async ({ page }) => {
+ // A tablist, not a set of toggles: exactly one selected at a time. Two
+ // chips reading `aria-selected="true"` is the bug this pins.
+ await seedFeed(page, [
+ item('n-agents-1', 'agents', 'Agent finished a task'),
+ item('n-system-1', 'system', 'Core restarted'),
+ ]);
+ await openFeed(page);
+
+ const all = page.getByTestId('notif-filter-chip-all');
+ const system = page.getByTestId('notif-filter-chip-system');
+
+ await expect(all).toHaveAttribute('aria-selected', 'true', { timeout: 20_000 });
+
+ await system.click();
+ await expect(system).toHaveAttribute('aria-selected', 'true');
+ await expect(all).toHaveAttribute('aria-selected', 'false');
+ });
+});
+
+test.describe('Notifications — read state', () => {
+ test('clicking an unread item marks it read and drops the unread count', async ({ page }) => {
+ await seedFeed(page, [
+ item('n-agents-1', 'agents', 'Agent finished a task'),
+ item('n-system-1', 'system', 'Core restarted'),
+ ]);
+ await openFeed(page);
+ await expect(rows(page)).toHaveCount(2, { timeout: 20_000 });
+
+ // The header reports the unread count; it is the user-visible signal that
+ // the click did anything.
+ await expect(page.getByText(/2 unread/i)).toBeVisible();
+
+ await rows(page).first().click();
+
+ await expect(page.getByText(/1 unread/i)).toBeVisible({ timeout: 10_000 });
+ });
+
+ test('Mark all read clears the count and disables itself', async ({ page }) => {
+ await seedFeed(page, [
+ item('n-agents-1', 'agents', 'Agent finished a task'),
+ item('n-system-1', 'system', 'Core restarted'),
+ ]);
+ await openFeed(page);
+
+ const markAll = page.getByRole('button', { name: /mark all read/i });
+ await expect(markAll).toBeEnabled({ timeout: 20_000 });
+
+ await markAll.click();
+
+ await expect(page.getByText(/unread/i)).toHaveCount(0, { timeout: 10_000 });
+ await expect(markAll).toBeDisabled();
+ });
+
+ test('Mark all read is already disabled when nothing is unread', async ({ page }) => {
+ await seedFeed(page, [item('n-agents-1', 'agents', 'Agent finished a task', true)]);
+ await openFeed(page);
+
+ await expect(rows(page)).toHaveCount(1, { timeout: 20_000 });
+ await expect(page.getByRole('button', { name: /mark all read/i })).toBeDisabled();
+ });
+
+ test('read state survives a reload', async ({ page }) => {
+ // The slice is persisted, so marking read must outlive the page. If it does
+ // not, the feed re-accuses the user of everything they just dismissed.
+ await seedFeed(page, [item('n-agents-1', 'agents', 'Agent finished a task')]);
+ await openFeed(page);
+
+ await page.getByRole('button', { name: /mark all read/i }).click();
+ await expect(page.getByRole('button', { name: /mark all read/i })).toBeDisabled({
+ timeout: 10_000,
+ });
+
+ await page.reload();
+ await waitForAppReady(page);
+ await dismissWalkthroughIfPresent(page);
+
+ await expect(page.getByRole('button', { name: /mark all read/i })).toBeDisabled({
+ timeout: 20_000,
+ });
+ });
+});