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): move our TokenUsagePanel cases to a per-concern file\n\n#5925 merged its own `TokenUsagePanel.test.tsx` covering the new\ndisabled-while-settings-unavailable semantics. Both files legitimately exist —\ntheirs pins the disabled/enabled contract, ours covers formatters, patch paths,\nthe CCR min-tokens field, refresh/reset and the chrome variants (29 cases).\n\nRenaming rather than merging: the two use different harnesses (ours a\n`renderPanel()` helper, theirs a direct `render`), and folding one into the\nother unverified would risk silently dropping coverage. The repo already splits\nby concern this way — `AgentsPanel.removal`, `CoreConnectionPanel.urlValidation`,\n`DevicesPanel.formatting`.\n\nChecked for contradiction: our savings-failure case rejects BOTH loads, so under\n#5925's decoupling it still holds (settings fails, controls disable, placeholders\nrender). Theirs covers the savings-only path, which is the new behaviour.\n
M3gA-Mindb91db23d6a41
diff --git a/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx b/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsxdeleted file mode 100644index b195d72f77..0000000000--- a/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx+++ /dev/null@@ -1,157 +0,0 @@-import { render, screen, waitFor } from '@testing-library/react';-import userEvent from '@testing-library/user-event';-import { beforeEach, describe, expect, it, vi } from 'vitest';--import * as tokenjuice from '../../../../utils/tauriCommands/tokenjuice';-import TokenUsagePanel from '../TokenUsagePanel';--vi.mock('../../../../lib/i18n/I18nContext', () => ({ useT: () => ({ t: (k: string) => k }) }));--vi.mock('../../../../utils/tauriCommands/tokenjuice', async () => {- const actual = await vi.importActual<typeof import('../../../../utils/tauriCommands/tokenjuice')>(- '../../../../utils/tauriCommands/tokenjuice'- );- return {- ...actual,- getTokenjuiceSettings: vi.fn(),- getTokenjuiceSavings: vi.fn(),- updateTokenjuiceSettings: vi.fn(),- resetTokenjuiceSavings: vi.fn(),- };-});--const mockGetSettings = vi.mocked(tokenjuice.getTokenjuiceSettings);-const mockGetSavings = vi.mocked(tokenjuice.getTokenjuiceSavings);-const mockUpdate = vi.mocked(tokenjuice.updateTokenjuiceSettings);--const stubSettings: tokenjuice.TokenjuiceSettings = {- router_enabled: true,- ccr_enabled: false,- ccr_disk_enabled: true,- max_cache_entries: 100,- max_cache_bytes: 1024,- ccr_ttl_secs: null,- min_bytes_to_compress: 512,- ccr_min_tokens: 1000,- search_enabled: true,- code_enabled: false,- html_enabled: true,- ml_compression_enabled: false,- ml_model_id: 'model',- ml_target_ratio: 0.5,- ml_sidecar_idle_timeout_secs: 30,- ml_max_input_chars: 4096,- ml_device: 'cpu',-};--const stubSavings: tokenjuice.SavingsStats = {- attributionModel: 'gpt-4',- total: { events: 0, originalTokens: 0, compactedTokens: 0, tokensSaved: 0, costSavedUsd: 0 },- byModel: {},- byCompressor: {},- cache: { entries: 0, bytes: 0 },-};--describe('TokenUsagePanel', () => {- beforeEach(() => {- mockGetSettings.mockReset();- mockGetSavings.mockReset();- mockUpdate.mockReset();- mockGetSavings.mockResolvedValue(stubSavings);- });-- describe('when settings load succeeds', () => {- beforeEach(() => {- mockGetSettings.mockResolvedValue(stubSettings);- });-- it('enables all switches and the CCR min-tokens field once settings load', async () => {- render(<TokenUsagePanel embedded />);-- // waitFor retries until switches transition from disabled (initial null state)- // to enabled (after async settings load), proving the load actually settled.- await waitFor(() => {- const switches = screen.getAllByRole('switch');- expect(switches).toHaveLength(7);- for (const sw of switches) expect(sw).not.toBeDisabled();- });- expect(- screen.getByRole('spinbutton', { name: 'settings.tokenUsage.ccrMinTokens' })- ).not.toBeDisabled();- });-- it('reflects the loaded toggle values', async () => {- render(<TokenUsagePanel embedded />);-- // router_enabled=true, search_enabled=true, code_enabled=false in stubSettings.- await waitFor(() =>- expect(- screen.getByRole('switch', { name: 'settings.tokenUsage.routerEnabled' })- ).toBeChecked()- );- expect(screen.getByRole('switch', { name: 'settings.tokenUsage.search' })).toBeChecked();- expect(screen.getByRole('switch', { name: 'settings.tokenUsage.code' })).not.toBeChecked();- });-- it('calls patch when a switch is toggled', async () => {- const user = userEvent.setup();- mockUpdate.mockResolvedValue({ ...stubSettings, router_enabled: false });- render(<TokenUsagePanel embedded />);-- const sw = await screen.findByRole('switch', { name: 'settings.tokenUsage.routerEnabled' });- await user.click(sw);- expect(mockUpdate).toHaveBeenCalledWith({ router_enabled: false });- });-- it('keeps controls enabled and shows error when only savings fails', async () => {- mockGetSavings.mockRejectedValue(new Error('savings rpc down'));- render(<TokenUsagePanel embedded />);-- // Wait for the rendered savings error — proves the rejection settled and- // React re-rendered (not just the initial settings === null disabled state).- await screen.findByText('savings rpc down');-- // Controls remain interactive despite the savings failure.- const switches = screen.getAllByRole('switch');- expect(switches).toHaveLength(7);- for (const sw of switches) expect(sw).not.toBeDisabled();- expect(- screen.getByRole('spinbutton', { name: 'settings.tokenUsage.ccrMinTokens' })- ).not.toBeDisabled();- });- });-- describe('when settings load fails', () => {- beforeEach(() => {- mockGetSettings.mockRejectedValue(new Error('rpc down'));- });-- it('disables all switches and the CCR min-tokens field while settings are unavailable', async () => {- render(<TokenUsagePanel embedded />);-- // Wait for the rendered error — proves the settings rejection settled and- // React re-rendered, ruling out the initial settings === null disabled state.- await screen.findByText('rpc down');-- const switches = screen.getAllByRole('switch');- expect(switches).toHaveLength(7);- for (const sw of switches) expect(sw).toBeDisabled();- expect(- screen.getByRole('spinbutton', { name: 'settings.tokenUsage.ccrMinTokens' })- ).toBeDisabled();- });-- it('does not call patch when a disabled switch is clicked', async () => {- const user = userEvent.setup();- render(<TokenUsagePanel embedded />);-- // Wait for the rendered error before interacting.- await screen.findByText('rpc down');-- const sw = screen.getByRole('switch', { name: 'settings.tokenUsage.routerEnabled' });- expect(sw).toBeDisabled();- await user.click(sw);- expect(mockUpdate).not.toHaveBeenCalled();- });- });-});