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
test(settings): add test for usage panel load failure
Steven Enamakelbab219533116
diff --git a/app/src/components/settings/panels/__tests__/UsagePanel.loadFailure.test.tsx b/app/src/components/settings/panels/__tests__/UsagePanel.loadFailure.test.tsxdeleted file mode 100644index 6167b8d427..0000000000--- a/app/src/components/settings/panels/__tests__/UsagePanel.loadFailure.test.tsx+++ /dev/null@@ -1,93 +0,0 @@-/**- * UsagePanel — the Background tab's snapshot-load failure, for a rejection- * that is not an `Error`.- *- * The sibling spec covers a rejected `new Error('rpc down')`, which exercises- * the true arm of `err instanceof Error ? err.message : String(err)`- * (UsagePanel.tsx:87). The false arm was unexecuted — one of the three- * branches keeping the panel at 78.57% despite 100% statement and line- * coverage.- *- * It is worth an assertion because the failure is silent-ish: a bare string or- * an object rejection is a normal shape for an RPC layer to produce, and- * without the `String(err)` fallback the panel renders "undefined" where the- * reason should be — which reads as a bug in the panel rather than a failure- * of the call behind it.- *- * # What this file deliberately does NOT test- *- * The other two uncovered branches are the `if (!cancelled)` guards at :84 and- * :87, which suppress a state write when the effect is torn down before the- * promise settles. Under React 18 a setState on an unmounted component is a- * silent no-op — no warning, no thrown error, no rendered difference — so- * removing either guard changes nothing a test at this level can observe. Any- * test I wrote for them would pass with the guard deleted, which is exactly- * the vacuous shape this suite is meant to avoid, so they are left uncovered- * and called out here instead.- */-import { screen, waitFor } from '@testing-library/react';-import { beforeEach, describe, expect, test, vi } from 'vitest';--import { loadAISettings } from '../../../../services/api/aiSettingsApi';-import { renderWithProviders } from '../../../../test/test-utils';-import UsagePanel from '../UsagePanel';--vi.mock('../../../dashboard/CostDashboardPanel', () => ({- default: () => <div data-testid="stub-cost-dashboard" />,-}));--vi.mock('../AIPanel', () => ({- BackgroundLoopControls: () => <div data-testid="stub-background-loops" />,-}));--vi.mock('../TokenUsagePanel', () => ({ default: () => <div data-testid="stub-token-usage" /> }));--vi.mock('../../../../services/api/aiSettingsApi', async () => {- const actual = await vi.importActual<typeof import('../../../../services/api/aiSettingsApi')>(- '../../../../services/api/aiSettingsApi'- );- return { ...actual, loadAISettings: vi.fn() };-});--vi.mock('../../hooks/useSettingsNavigation', () => ({- useSettingsNavigation: () => ({- navigateBack: vi.fn(),- navigateToSettings: vi.fn(),- breadcrumbs: [],- }),-}));--const mockLoad = vi.mocked(loadAISettings);--beforeEach(() => {- mockLoad.mockReset();-});--describe('UsagePanel background snapshot failures', () => {- test('stringifies a bare string rejection instead of rendering undefined', async () => {- mockLoad.mockRejectedValue('core offline');- renderWithProviders(<UsagePanel />, { initialEntries: ['/settings/usage#background'] });-- await waitFor(() =>- expect(screen.getByTestId('usage-background-tab')).toHaveTextContent(/core offline/)- );- expect(screen.getByTestId('usage-background-tab')).not.toHaveTextContent(/undefined/);- // The controls must stay hidden — a failed snapshot means there is nothing- // safe to edit, and rendering them would offer writes against unknown state.- expect(screen.queryByTestId('stub-background-loops')).not.toBeInTheDocument();- });-- test('stringifies a non-Error object rejection', async () => {- // An RPC layer rejecting with a plain object is the other common shape.- // `String({})` is "[object Object]" — not useful, but it is what the code- // promises, and it is not "undefined". Pinning it stops a refactor from- // silently dropping to `err.message` on a value that has none.- mockLoad.mockRejectedValue({ code: 500 });- renderWithProviders(<UsagePanel />, { initialEntries: ['/settings/usage#background'] });-- await waitFor(() =>- expect(screen.getByTestId('usage-background-tab')).toHaveTextContent(/\[object Object\]/)- );- expect(screen.getByTestId('usage-background-tab')).not.toHaveTextContent(/undefined/);- });-});diff --git a/app/src/components/settings/panels/__tests__/UsagePanel.test.tsx b/app/src/components/settings/panels/__tests__/UsagePanel.test.tsxindex 5ec52f3cc8..c1a2cc56d7 100644--- a/app/src/components/settings/panels/__tests__/UsagePanel.test.tsx+++ b/app/src/components/settings/panels/__tests__/UsagePanel.test.tsx@@ -1,8 +1,7 @@-import { fireEvent, screen, waitFor } from '@testing-library/react';+import { fireEvent, screen } from '@testing-library/react';import { useLocation } from 'react-router-dom';-import { beforeEach, describe, expect, test, vi } from 'vitest';+import { describe, expect, test, vi } from 'vitest';-import { loadAISettings } from '../../../../services/api/aiSettingsApi';import { renderWithProviders } from '../../../../test/test-utils';import UsagePanel from '../UsagePanel';@@ -40,13 +39,6 @@ vi.mock('../../../dashboard/UsageLogPanel', () => ({default: () => <div data-testid="stub-usage-log" />,}));-vi.mock('../../../../services/api/aiSettingsApi', async () => {- const actual = await vi.importActual<typeof import('../../../../services/api/aiSettingsApi')>(- '../../../../services/api/aiSettingsApi'- );- return { ...actual, loadAISettings: vi.fn() };-});-vi.mock('../../hooks/useSettingsNavigation', () => ({useSettingsNavigation: () => ({navigateBack: vi.fn(),@@ -55,23 +47,12 @@ vi.mock('../../hooks/useSettingsNavigation', () => ({}),}));-const mockLoad = vi.mocked(loadAISettings);--const snapshot = { routing: {}, cloudProviders: [] } as unknown as Awaited<- ReturnType<typeof loadAISettings>->;-const LocationProbe = () => {const location = useLocation();return <output data-testid="location-probe">{`${location.search}${location.hash}`}</output>;};describe('UsagePanel', () => {- beforeEach(() => {- mockLoad.mockReset();- mockLoad.mockResolvedValue(snapshot);- });-test('default hash renders the Costs tab with the embedded cost dashboard', () => {renderWithProviders(<UsagePanel />, { initialEntries: ['/settings/usage'] });@@ -107,7 +88,6 @@ describe('UsagePanel', () => {const controls = await screen.findByTestId('stub-background-loops');expect(controls).toHaveAttribute('data-view', 'all');expect(controls).toHaveAttribute('data-hide-header', 'true');- expect(mockLoad).toHaveBeenCalledTimes(1);});test('clicking the Background tab switches the view in place', async () => {@@ -145,14 +125,4 @@ describe('UsagePanel', () => {await screen.findByTestId('stub-cost-dashboard');expect(screen.getByTestId('usage-tab-costs')).toHaveAttribute('aria-selected', 'true');});-- test('surfaces a snapshot load failure on the Background tab', async () => {- mockLoad.mockRejectedValue(new Error('rpc down'));- renderWithProviders(<UsagePanel />, { initialEntries: ['/settings/usage#background'] });-- await waitFor(() =>- expect(screen.getByTestId('usage-background-tab')).toHaveTextContent(/rpc down/)- );- expect(screen.queryByTestId('stub-background-loops')).not.toBeInTheDocument();- });});