Skip to content

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

fix(settings): correct agent activity panel test assertion

Steven Enamakele53964cf5ff0
diff --git a/app/src/components/settings/panels/AgentActivityPanel.test.tsx b/app/src/components/settings/panels/AgentActivityPanel.test.tsx
deleted file mode 100644
index 3590e9872b..0000000000
--- a/app/src/components/settings/panels/AgentActivityPanel.test.tsx
+++ /dev/null
@@ -1,106 +0,0 @@
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
-
-import AgentActivityPanel from './AgentActivityPanel';
-
-const navigateBack = vi.fn();
-
-vi.mock('../hooks/useSettingsNavigation', () => ({
- useSettingsNavigation: () => ({
- navigateBack,
- breadcrumbs: [{ label: 'Settings' }, { label: 'Agents' }],
- }),
-}));
-
-// Mock SettingsBackButton so the test does not depend on the route-aware
-// visibility rules of the shared back button. We assert the panel wiring
-// instead: that the back button renders and drives `navigateBack`, and that the
-// level options drive the RPC.
-vi.mock('../components/SettingsBackButton', () => ({
- default: ({ onBack }: { onBack?: () => void }) => (
- <button type="button" data-testid="settings-header-back" onClick={onBack}>
- back
- </button>
- ),
-}));
-
-const callCoreRpc = vi.fn();
-vi.mock('../../../services/coreRpcClient', () => ({
- callCoreRpc: (arg: { method: string; params: unknown }) => callCoreRpc(arg),
-}));
-
-function settingsResult(level = 2) {
- return {
- result: {
- level,
- level_label: 'moderate',
- sync_interval_secs: 3600,
- heartbeat_enabled: true,
- subconscious_enabled: true,
- token_budget_per_cycle: null,
- estimated_monthly_cost_min_usd: 1,
- estimated_monthly_cost_max_usd: 5,
- },
- };
-}
-
-const costResult = { result: { month: '2026-06', total_cost_usd: 0, total_syncs: 0 } };
-
-/** All buttons except the mocked SettingsHeader back button = the level options. */
-function levelButtons() {
- return screen
- .getAllByRole('button')
- .filter(b => b.getAttribute('data-testid') !== 'settings-header-back');
-}
-
-beforeEach(() => {
- vi.clearAllMocks();
- callCoreRpc.mockImplementation((arg: { method: string }) => {
- switch (arg.method) {
- case 'openhuman.config_get_activity_level_settings':
- return Promise.resolve(settingsResult());
- case 'openhuman.memory_sources_monthly_cost_summary':
- return Promise.resolve(costResult);
- case 'openhuman.config_update_activity_level_settings':
- return Promise.resolve(settingsResult(4));
- default:
- return Promise.reject(new Error(`unexpected method ${arg.method}`));
- }
- });
-});
-
-describe('<AgentActivityPanel />', () => {
- it('renders the back button and the five level options once loaded', async () => {
- render(<AgentActivityPanel />);
-
- // The level options only render after the initial load resolves (the loading
- // state has none), so this also asserts the panel left the loading state.
- await waitFor(() => expect(levelButtons()).toHaveLength(5));
- });
-
- it('invokes the back handler from the back button', async () => {
- render(<AgentActivityPanel />);
- await screen.findByTestId('settings-header-back');
-
- fireEvent.click(screen.getByTestId('settings-header-back'));
- expect(navigateBack).toHaveBeenCalledTimes(1);
- });
-
- it('persists a new level selection via the update RPC', async () => {
- render(<AgentActivityPanel />);
- await waitFor(() => expect(levelButtons()).toHaveLength(5));
-
- // The last option is "Always-on" (level 4 -> api key "always_on").
- const options = levelButtons();
- fireEvent.click(options[options.length - 1]);
-
- await waitFor(() => {
- expect(callCoreRpc).toHaveBeenCalledWith(
- expect.objectContaining({
- method: 'openhuman.config_update_activity_level_settings',
- params: { level: 'always_on' },
- })
- );
- });
- });
-});
diff --git a/app/src/components/settings/panels/AgentActivityPanel.tsx b/app/src/components/settings/panels/AgentActivityPanel.tsx
deleted file mode 100644
index 2d6a3cfbca..0000000000
--- a/app/src/components/settings/panels/AgentActivityPanel.tsx
+++ /dev/null
@@ -1,172 +0,0 @@
-import { useCallback, useEffect, useState } from 'react';
-
-import { useT } from '../../../lib/i18n/I18nContext';
-import { callCoreRpc } from '../../../services/coreRpcClient';
-import Badge from '../../ui/Badge';
-import Button from '../../ui/Button';
-import { CenteredLoadingState } from '../../ui/LoadingState';
-import { SettingsStatusLine } from '../controls';
-import SettingsPanel from '../layout/SettingsPanel';
-
-interface ActivityLevelSettings {
- level: number;
- level_label: string;
- sync_interval_secs: number | null;
- heartbeat_enabled: boolean;
- subconscious_enabled: boolean;
- token_budget_per_cycle: number | null;
- estimated_monthly_cost_min_usd: number;
- estimated_monthly_cost_max_usd: number;
-}
-
-interface MonthlyCostSummary {
- month: string;
- total_cost_usd: number;
- total_syncs: number;
-}
-
-const LEVELS = [
- { key: 'off', value: 0 },
- { key: 'minimal', value: 1 },
- { key: 'moderate', value: 2 },
- { key: 'active', value: 3 },
- { key: 'alwaysOn', value: 4 },
-] as const;
-
-type LevelKey = (typeof LEVELS)[number]['key'];
-
-type Status = 'idle' | 'loading' | 'saving' | 'saved' | 'error';
-
-// These tables intentionally duplicate the backend constants in
-// AgentActivityLevel::estimated_monthly_cost_range (config/schema/activity_level.rs).
-// The backend only returns cost ranges for the *current* level, so we need a
-// static lookup to render cost estimates for all levels simultaneously.
-// A future RPC that returns ranges for all levels would allow removing these.
-function getCostMin(level: number): number {
- return [0, 0.1, 1, 5, 20][level] ?? 0;
-}
-
-function getCostMax(level: number): number {
- return [0, 0.5, 5, 20, 100][level] ?? 0;
-}
-
-export default function AgentActivityPanel() {
- const { t } = useT();
- const [settings, setSettings] = useState<ActivityLevelSettings | null>(null);
- const [monthlyCost, setMonthlyCost] = useState<MonthlyCostSummary | null>(null);
- const [status, setStatus] = useState<Status>('loading');
- const [error, setError] = useState<string | null>(null);
-
- const loadSettings = useCallback(async () => {
- try {
- setStatus('loading');
- const [settingsResp, costResp] = await Promise.all([
- callCoreRpc<{ result: ActivityLevelSettings }>({
- method: 'openhuman.config_get_activity_level_settings',
- params: {},
- }),
- callCoreRpc<{ result: MonthlyCostSummary }>({
- method: 'openhuman.memory_sources_monthly_cost_summary',
- params: {},
- }),
- ]);
- setSettings(settingsResp.result);
- setMonthlyCost(costResp.result);
- setStatus('idle');
- } catch (e) {
- setError(e instanceof Error ? e.message : String(e));
- setStatus('error');
- }
- }, []);
-
- useEffect(() => {
- loadSettings();
- }, [loadSettings]);
-
- const handleLevelChange = useCallback(async (levelKey: string) => {
- try {
- setStatus('saving');
- setError(null);
- const resp = await callCoreRpc<{ result: ActivityLevelSettings }>({
- method: 'openhuman.config_update_activity_level_settings',
- params: { level: levelKey },
- });
- setSettings(resp.result);
- setStatus('saved');
- setTimeout(() => setStatus('idle'), 2000);
- } catch (e) {
- setError(e instanceof Error ? e.message : String(e));
- setStatus('error');
- }
- }, []);
-
- return (
- <SettingsPanel description={t('activityLevel.description')}>
- {status === 'loading' && !settings ? (
- <CenteredLoadingState label={t('common.loading')} className="py-12" />
- ) : (
- <div className="flex flex-col gap-4">
- {monthlyCost && monthlyCost.total_cost_usd > 0 && (
- <div className="px-3 py-2 rounded-md bg-surface-subtle text-sm">
- <span className="font-medium text-content">
- {t('activityLevel.currentMonth').replace(
- '{amount}',
- monthlyCost.total_cost_usd.toFixed(2)
- )}
- </span>
- </div>
- )}
-
- {/* Level selection cards — intentional bespoke card UI; kept as-is. */}
- <div className="flex flex-col gap-2">
- {LEVELS.map(({ key, value }) => {
- const isSelected = settings?.level === value;
- const apiKey = key === 'alwaysOn' ? 'always_on' : (key as string);
- const costMin = getCostMin(value);
- const costMax = getCostMax(value);
- return (
- <Button
- key={key}
- variant="secondary"
- onClick={() => handleLevelChange(apiKey)}
- disabled={status === 'saving'}
- data-testid={`activity-level-${key}`}
- className={`h-auto w-full items-center justify-between rounded-lg px-4 py-3 text-left font-normal ${
- isSelected
- ? 'border-primary-500 bg-primary-50 dark:bg-primary-900/20'
- : 'border-line bg-surface hover:border-line-strong dark:hover:border-line-strong'
- }`}>
- <div>
- <div className="flex items-center gap-2">
- <span className="text-sm font-semibold text-content">
- {t(`activityLevel.${key as LevelKey}`)}
- </span>
- {value === 2 && <Badge variant="neutral">{t('activityLevel.default')}</Badge>}
- </div>
- <p className="text-xs text-content-muted mt-0.5">
- {t(`activityLevel.${key as LevelKey}Desc`)}
- </p>
- </div>
- <div className="text-xs font-mono text-content-muted shrink-0 ml-4">
- {costMin === 0 && costMax === 0
- ? t('activityLevel.costFree')
- : t('activityLevel.costRange')
- .replace('{min}', String(costMin))
- .replace('{max}', String(costMax))}
- </div>
- </Button>
- );
- })}
- </div>
-
- <SettingsStatusLine
- saving={status === 'saving'}
- savedNote={status === 'saved' ? t('activityLevel.saved') : null}
- error={error}
- savingLabel={t('autonomy.statusSaving')}
- />
- </div>
- )}
- </SettingsPanel>
- );
-}