Skip to content

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

fix(settings): remove duplicate test file and update notification routing panel

Steven Enamakelce9867d8db48
diff --git a/app/src/components/settings/panels/KeyboardShortcutsPanel.tsx b/app/src/components/settings/panels/KeyboardShortcutsPanel.tsx
deleted file mode 100644
index 54eb2b63e0..0000000000
--- a/app/src/components/settings/panels/KeyboardShortcutsPanel.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * Settings → Keyboard Shortcuts.
- *
- * A discoverable home for the app-wide shortcut map. Renders the same live,
- * registry-driven list as the `?` help overlay (see `shortcutsView`), so the
- * two surfaces can never disagree.
- */
-import { useT } from '../../../lib/i18n/I18nContext';
-import { ShortcutsList } from '../../shortcuts/shortcutsView';
-import SettingsPanel from '../layout/SettingsPanel';
-
-const KeyboardShortcutsPanel = () => {
- const { t } = useT();
- return (
- <SettingsPanel description={t('shortcuts.subtitle')} testId="settings-keyboard-shortcuts">
- <ShortcutsList variant="panel" />
- </SettingsPanel>
- );
-};
-
-export default KeyboardShortcutsPanel;
diff --git a/app/src/components/settings/panels/NotificationRoutingPanel.test.tsx b/app/src/components/settings/panels/NotificationRoutingPanel.test.tsx
deleted file mode 100644
index b0e6243c9c..0000000000
--- a/app/src/components/settings/panels/NotificationRoutingPanel.test.tsx
+++ /dev/null
@@ -1,154 +0,0 @@
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
-import { MemoryRouter } from 'react-router-dom';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
-
-const navigateBack = vi.fn();
-
-vi.mock('../hooks/useSettingsNavigation', () => ({
- useSettingsNavigation: () => ({
- navigateBack,
- navigateToSettings: vi.fn(),
- navigateToTeamManagement: vi.fn(),
- breadcrumbs: [],
- }),
-}));
-
-const fetchStatsMock = vi.fn();
-const getSettingsMock = vi.fn();
-const setSettingsMock = vi.fn();
-vi.mock('../../../services/notificationService', () => ({
- fetchNotificationStats: () => fetchStatsMock(),
- getNotificationSettings: (provider: string) => getSettingsMock(provider),
- setNotificationSettings: (payload: unknown) => setSettingsMock(payload),
-}));
-
-const PROVIDERS = ['gmail', 'slack', 'discord', 'whatsapp'];
-
-async function importPanel() {
- vi.resetModules();
- const mod = await import('./NotificationRoutingPanel');
- return mod.default;
-}
-
-function renderPanel(Panel: React.ComponentType) {
- return render(
- <MemoryRouter>
- <Panel />
- </MemoryRouter>
- );
-}
-
-function defaultSettings() {
- return { enabled: true, importance_threshold: 0.3, route_to_orchestrator: true };
-}
-
-describe('<NotificationRoutingPanel />', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- fetchStatsMock.mockResolvedValue({ total: 12, unread: 5, unscored: 2 });
- getSettingsMock.mockImplementation((provider: string) =>
- Promise.resolve({ provider, ...defaultSettings() })
- );
- setSettingsMock.mockResolvedValue(undefined);
- });
-
- it('renders the pipeline stats card once fetchNotificationStats resolves', async () => {
- const Panel = await importPanel();
- renderPanel(Panel);
-
- await waitFor(() => expect(screen.getByText('Pipeline stats')).toBeInTheDocument());
- // total / unread / unscored values appear as separate stat tiles
- expect(screen.getByText('12')).toBeInTheDocument();
- expect(screen.getByText('5')).toBeInTheDocument();
- expect(screen.getByText('2')).toBeInTheDocument();
- });
-
- it('omits the pipeline stats card when fetchNotificationStats rejects', async () => {
- fetchStatsMock.mockRejectedValueOnce(new Error('stats down'));
- const Panel = await importPanel();
- renderPanel(Panel);
-
- // Settings still load for each provider so the per-provider section
- // renders, but the stats card is absent.
- await waitFor(() => expect(getSettingsMock).toHaveBeenCalledTimes(PROVIDERS.length));
- expect(screen.queryByText('Pipeline stats')).not.toBeInTheDocument();
- });
-
- it('renders one row per provider with persisted threshold values', async () => {
- getSettingsMock.mockImplementation((provider: string) =>
- Promise.resolve({
- provider,
- enabled: true,
- importance_threshold: 0.45,
- route_to_orchestrator: true,
- })
- );
- const Panel = await importPanel();
- renderPanel(Panel);
-
- await waitFor(() => expect(getSettingsMock).toHaveBeenCalledTimes(PROVIDERS.length));
- // Provider headings render capitalized via CSS but the underlying text
- // is lowercased; assert against the rendered text directly.
- for (const provider of PROVIDERS) {
- expect(screen.getByText(provider)).toBeInTheDocument();
- }
- // Each row formats the threshold to 2 decimals — four rows × 0.45.
- expect(screen.getAllByText('0.45')).toHaveLength(PROVIDERS.length);
- });
-
- it('toggling enabled for a provider fires setNotificationSettings', async () => {
- const Panel = await importPanel();
- renderPanel(Panel);
-
- await waitFor(() => expect(getSettingsMock).toHaveBeenCalledTimes(PROVIDERS.length));
-
- // Each provider exposes an "Enabled" checkbox; the first one is gmail's.
- const enabledCheckboxes = screen.getAllByRole('checkbox', { name: 'Enabled' });
- expect(enabledCheckboxes).toHaveLength(PROVIDERS.length);
- fireEvent.click(enabledCheckboxes[0]);
-
- await waitFor(() =>
- expect(setSettingsMock).toHaveBeenCalledWith({
- provider: 'gmail',
- enabled: false,
- importance_threshold: 0.3,
- route_to_orchestrator: true,
- })
- );
- });
-
- it('disables the controls and surfaces a retry hint for providers that fail to load', async () => {
- getSettingsMock.mockImplementation((provider: string) => {
- if (provider === 'gmail') return Promise.reject(new Error('boom'));
- return Promise.resolve({ provider, ...defaultSettings() });
- });
- const Panel = await importPanel();
- renderPanel(Panel);
-
- await waitFor(() =>
- expect(
- screen.getByText('Failed to load settings. Reopen this panel to retry.')
- ).toBeInTheDocument()
- );
-
- // The four `Enabled` checkboxes still render, but the first row (gmail)
- // is disabled because its settings never loaded.
- const enabledCheckboxes = screen.getAllByRole('checkbox', { name: 'Enabled' });
- expect(enabledCheckboxes[0]).toBeDisabled();
- // The slack row should still be interactive.
- expect(enabledCheckboxes[1]).not.toBeDisabled();
- });
-
- it('renders the static "How it works" explainer rows', async () => {
- const Panel = await importPanel();
- renderPanel(Panel);
-
- await waitFor(() => expect(getSettingsMock).toHaveBeenCalled());
- // The four routing tiers are part of the static explainer and should
- // render regardless of network state.
- expect(screen.getByText('Drop')).toBeInTheDocument();
- expect(screen.getByText('Acknowledge')).toBeInTheDocument();
- expect(screen.getByText('React')).toBeInTheDocument();
- expect(screen.getByText('Escalate')).toBeInTheDocument();
- });
-});
diff --git a/app/src/components/settings/panels/NotificationRoutingPanel.tsx b/app/src/components/settings/panels/NotificationRoutingPanel.tsx
deleted file mode 100644
index c28843f3fb..0000000000
--- a/app/src/components/settings/panels/NotificationRoutingPanel.tsx
+++ /dev/null
@@ -1,270 +0,0 @@
-import { useEffect, useState } from 'react';
-
-import { useT } from '../../../lib/i18n/I18nContext';
-import {
- fetchNotificationStats,
- getNotificationSettings,
- setNotificationSettings,
-} from '../../../services/notificationService';
-import type { NotificationStats } from '../../../types/notifications';
-import Alert, { AlertDescription, AlertTitle } from '../../ui/Alert';
-import Badge, { type BadgeVariant } from '../../ui/Badge';
-import Slider from '../../ui/Slider';
-import { SettingsCheckbox, SettingsSection } from '../controls';
-import SettingsPanel from '../layout/SettingsPanel';
-
-const PROVIDERS = ['gmail', 'slack', 'discord', 'whatsapp'];
-
-interface NotificationRoutingPanelProps {
- /** When embedded inside the tabbed Notifications page, the parent owns the
- `<SettingsHeader>` chrome and we render only the body. */
- embedded?: boolean;
-}
-
-/**
- * Settings panel for the notification intelligence / routing pipeline.
- *
- * Currently exposes a global explanation card. Per-provider threshold
- * controls will populate here as providers are connected.
- */
-const NotificationRoutingPanel = ({ embedded = false }: NotificationRoutingPanelProps = {}) => {
- const { t } = useT();
- const providers = PROVIDERS;
- const [stats, setStats] = useState<NotificationStats | null>(null);
- const [settings, setSettings] = useState<
- Record<
- string,
- { enabled: boolean; importance_threshold: number; route_to_orchestrator: boolean }
- >
- >({});
- const [loadedProviders, setLoadedProviders] = useState<Record<string, boolean>>({});
- const [loadErrors, setLoadErrors] = useState<Record<string, string>>({});
-
- useEffect(() => {
- void fetchNotificationStats()
- .then(s => setStats(s))
- .catch(err => console.warn('[settings][notification-routing] stats load failed', err));
- }, []);
-
- useEffect(() => {
- void Promise.allSettled(
- providers.map(async provider => {
- const s = await getNotificationSettings(provider);
- return [provider, s] as const;
- })
- ).then(results => {
- const next: Record<
- string,
- { enabled: boolean; importance_threshold: number; route_to_orchestrator: boolean }
- > = {};
- const nextLoadedProviders: Record<string, boolean> = {};
- const nextLoadErrors: Record<string, string> = {};
- results.forEach((result, index) => {
- const provider = providers[index];
- if (result.status === 'fulfilled') {
- const [, s] = result.value;
- next[provider] = {
- enabled: s.enabled,
- importance_threshold: s.importance_threshold,
- route_to_orchestrator: s.route_to_orchestrator,
- };
- nextLoadedProviders[provider] = true;
- } else {
- const message =
- result.reason instanceof Error ? result.reason.message : String(result.reason);
- nextLoadErrors[provider] = message;
- console.warn(`[settings][notification-routing] failed to load provider=${provider}`, {
- error: message,
- });
- }
- });
- setSettings(prev => ({ ...prev, ...next }));
- setLoadedProviders(nextLoadedProviders);
- setLoadErrors(nextLoadErrors);
- });
- }, [providers]);
-
- const updateSetting = async (
- provider: string,
- patch: Partial<{
- enabled: boolean;
- importance_threshold: number;
- route_to_orchestrator: boolean;
- }>
- ) => {
- if (!loadedProviders[provider] || loadErrors[provider]) {
- return;
- }
- const current = settings[provider] ?? {
- enabled: true,
- importance_threshold: 0,
- route_to_orchestrator: true,
- };
- const next = { ...current, ...patch };
- setSettings(prev => ({ ...prev, [provider]: next }));
- try {
- await setNotificationSettings({ provider, ...next });
- } catch (err) {
- setSettings(prev => ({ ...prev, [provider]: current }));
- throw err;
- }
- };
-
- const body = (
- <>
- {stats && (
- <SettingsSection title={t('notifications.routing.pipelineStats')}>
- <div className="grid grid-cols-3 divide-x divide-line-subtle">
- {[
- { label: t('notifications.routing.total'), value: stats.total },
- { label: t('notifications.routing.unread'), value: stats.unread },
- { label: t('notifications.routing.unscored'), value: stats.unscored },
- ].map(({ label, value }) => (
- <div key={label} className="px-4 py-3 text-center">
- <p className="text-lg font-semibold text-content">{value}</p>
- <p className="text-xs text-content-muted">{label}</p>
- </div>
- ))}
- </div>
- </SettingsSection>
- )}
-
- {/* Info card */}
- <Alert variant="info" className="items-start">
- <svg
- className="w-5 h-5 shrink-0 mt-0.5"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- aria-hidden="true">
- <path
- strokeLinecap="round"
- strokeLinejoin="round"
- strokeWidth={2}
- d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"
- />
- </svg>
- <div>
- <AlertTitle>{t('notifications.routing.intelligenceTitle')}</AlertTitle>
- <AlertDescription className="mt-1">
- {t('notifications.routing.intelligenceDesc')}
- </AlertDescription>
- </div>
- </Alert>
-
- {/* How it works */}
- <SettingsSection title={t('notifications.routing.howItWorks')}>
- {(
- [
- {
- label: t('notifications.routing.level.drop'),
- desc: t('notifications.routing.level.dropDesc'),
- variant: 'neutral',
- },
- {
- label: t('notifications.routing.level.acknowledge'),
- desc: t('notifications.routing.level.acknowledgeDesc'),
- variant: 'primary',
- },
- {
- label: t('notifications.routing.level.react'),
- desc: t('notifications.routing.level.reactDesc'),
- variant: 'warning',
- },
- {
- label: t('notifications.routing.level.escalate'),
- desc: t('notifications.routing.level.escalateDesc'),
- variant: 'danger',
- },
- ] as { label: string; desc: string; variant: BadgeVariant }[]
- ).map(row => (
- <div key={row.label} className="flex items-center gap-3 px-4 py-3">
- <Badge variant={row.variant} className="shrink-0">
- {row.label}
- </Badge>
- <span className="text-xs text-content-secondary">{row.desc}</span>
- </div>
- ))}
- </SettingsSection>
-
- {/* Per-provider routing */}
- <SettingsSection title={t('notifications.routing.perProvider')}>
- {providers.map(provider => {
- const hasLoadError = Boolean(loadErrors[provider]);
- const isLoaded = Boolean(loadedProviders[provider]);
- const s = settings[provider] ?? {
- enabled: true,
- importance_threshold: 0,
- route_to_orchestrator: true,
- };
- const controlsDisabled = !isLoaded || hasLoadError;
- return (
- <div key={provider} className="px-4 py-3 space-y-2">
- <div className="flex items-center justify-between">
- <p className="text-sm font-medium text-content capitalize">{provider}</p>
- <div className="flex items-center gap-2">
- <label
- htmlFor={`notification-enabled-${provider}`}
- className="text-xs text-content-secondary">
- {t('common.enabled')}
- </label>
- <SettingsCheckbox
- id={`notification-enabled-${provider}`}
- checked={s.enabled}
- disabled={controlsDisabled}
- onCheckedChange={next => {
- void updateSetting(provider, { enabled: next });
- }}
- />
- </div>
- </div>
- <div className="flex items-center gap-2 text-xs text-content-secondary">
- <span className="shrink-0">{t('notifications.routing.threshold')}</span>
- <Slider
- className="flex-1"
- min={0}
- max={1}
- step={0.05}
- value={[s.importance_threshold]}
- disabled={controlsDisabled}
- thumbLabels={[t('notifications.routing.threshold')]}
- data-testid={`notification-threshold-${provider}`}
- onValueChange={value => {
- void updateSetting(provider, { importance_threshold: value[0] });
- }}
- />
- <span>{s.importance_threshold.toFixed(2)}</span>
- </div>
- <label
- htmlFor={`notification-orchestrator-${provider}`}
- className="text-xs text-content-secondary flex items-center gap-2">
- {t('notifications.routing.routeToOrchestrator')}
- <SettingsCheckbox
- id={`notification-orchestrator-${provider}`}
- checked={s.route_to_orchestrator}
- disabled={controlsDisabled}
- onCheckedChange={next => {
- void updateSetting(provider, { route_to_orchestrator: next });
- }}
- />
- </label>
- {hasLoadError ? (
- <p className="text-xs text-coral-600 dark:text-coral-300">
- {t('notifications.routing.loadSettingsError')}
- </p>
- ) : null}
- </div>
- );
- })}
- </SettingsSection>
- </>
- );
-
- // Embedded inside the tabbed Notifications page: the parent owns the header,
- // so render just the padded body.
- if (embedded) return <div className="space-y-5">{body}</div>;
-
- return <SettingsPanel>{body}</SettingsPanel>;
-};
-
-export default NotificationRoutingPanel;
diff --git a/app/src/components/settings/panels/NotificationsTabbedPanel.tsx b/app/src/components/settings/panels/NotificationsTabbedPanel.tsx
deleted file mode 100644
index 4175fe2969..0000000000
--- a/app/src/components/settings/panels/NotificationsTabbedPanel.tsx
+++ /dev/null
@@ -1,55 +0,0 @@
-import { useLocation, useNavigate } from 'react-router-dom';
-
-import { useT } from '../../../lib/i18n/I18nContext';
-import SettingsPanel from '../layout/SettingsPanel';
-import NotificationRoutingPanel from './NotificationRoutingPanel';
-import NotificationsPanel from './NotificationsPanel';
-
-type TabId = 'preferences' | 'routing';
-
-const TAB_HASH: Record<TabId, string> = { preferences: '', routing: '#routing' };
-
-const hashToTab = (hash: string): TabId => (hash === '#routing' ? 'routing' : 'preferences');
-
-/**
- * Single Settings entry for notifications. Combines the user-facing
- * preferences (NotificationsPanel) and the routing/intelligence pipeline
- * controls (NotificationRoutingPanel) as two tabs under one header. The
- * active tab is reflected in the URL hash (`#routing`) so deep links from
- * Developer Options still land on the right view.
- */
-const NotificationsTabbedPanel = () => {
- const { t } = useT();
- const location = useLocation();
- const navigate = useNavigate();
- // The router is the single source of truth for the active tab — hash is the
- // only signal needed, so derive directly instead of mirroring it in state.
- const tab: TabId = hashToTab(location.hash);
-
- const selectTab = (next: TabId) => {
- navigate(`${location.pathname}${TAB_HASH[next]}`, { replace: true });
- };
-
- return (
- <SettingsPanel<TabId>
- description={t('settings.notifications.menuDesc')}
- tabsAriaLabel={t('settings.notifications')}
- value={tab}
- onChange={selectTab}
- tabs={[
- {
- id: 'preferences',
- label: t('settings.notifications.tabs.preferences'),
- content: <NotificationsPanel embedded />,
- },
- {
- id: 'routing',
- label: t('settings.notifications.tabs.routing'),
- content: <NotificationRoutingPanel embedded />,
- },
- ]}
- />
- );
-};
-
-export default NotificationsTabbedPanel;
diff --git a/app/src/components/settings/panels/__tests__/NotificationRoutingPanel.test.tsx b/app/src/components/settings/panels/__tests__/NotificationRoutingPanel.test.tsx
deleted file mode 100644
index 21c8a67d55..0000000000
--- a/app/src/components/settings/panels/__tests__/NotificationRoutingPanel.test.tsx
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Tests for the Settings → Notification routing panel.
- *
- * Verifies the per-provider controls become interactive once settings load,
- * and that toggling the "route to orchestrator" checkbox persists the change
- * via setNotificationSettings.
- */
-import { fireEvent, waitFor } from '@testing-library/react';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
-
-import { renderWithProviders } from '../../../../test/test-utils';
-import NotificationRoutingPanel from '../NotificationRoutingPanel';
-
-const hoisted = vi.hoisted(() => ({
- fetchNotificationStats: vi.fn(),
- getNotificationSettings: vi.fn(),
- setNotificationSettings: vi.fn(),
-}));
-
-vi.mock('../../../../services/notificationService', () => ({
- fetchNotificationStats: hoisted.fetchNotificationStats,
- getNotificationSettings: hoisted.getNotificationSettings,
- setNotificationSettings: hoisted.setNotificationSettings,
-}));
-
-const providerSettings = { enabled: true, importance_threshold: 0.4, route_to_orchestrator: true };
-
-describe('NotificationRoutingPanel', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- hoisted.fetchNotificationStats.mockResolvedValue(null);
- hoisted.getNotificationSettings.mockResolvedValue(providerSettings);
- hoisted.setNotificationSettings.mockResolvedValue(undefined);
- });
-
- it('persists a route-to-orchestrator toggle once provider settings load', async () => {
- renderWithProviders(<NotificationRoutingPanel embedded />);
-
- // The gmail orchestrator checkbox becomes enabled after settings load.
- const orchestratorToggle = await waitFor(() => {
- const el = document.getElementById('notification-orchestrator-gmail') as HTMLInputElement;
- expect(el).not.toBeNull();
- expect(el).not.toBeDisabled();
- return el;
- });
-
- // It starts checked (route_to_orchestrator: true); toggle it off.
- expect(orchestratorToggle.checked).toBe(true);
- fireEvent.click(orchestratorToggle);
-
- await waitFor(() =>
- expect(hoisted.setNotificationSettings).toHaveBeenCalledWith(
- expect.objectContaining({ provider: 'gmail', route_to_orchestrator: false })
- )
- );
- });
-});