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
fix(tokenjuice): decouple savings load from settings; harden tests\n\nA savings failure should not disable the compression controls.\nReplace the Promise.all with sequential loads so settings success\nkeeps all switches interactive even when getTokenjuiceSavings rejects.\n\nTests: add spinbutton (CCR min-tokens field) coverage, add the\nsavings-only-fails case, and wait directly on the rendered disabled\nstate in failure tests rather than on mock call count (more robust\nagainst async timing).\n
shanuc61db02d4aae
diff --git a/app/src/components/settings/panels/TokenUsagePanel.tsx b/app/src/components/settings/panels/TokenUsagePanel.tsxindex 142e08c5cb..92ca7657ab 100644--- a/app/src/components/settings/panels/TokenUsagePanel.tsx+++ b/app/src/components/settings/panels/TokenUsagePanel.tsx@@ -80,14 +80,23 @@ const TokenUsagePanel = ({ embedded = false }: TokenUsagePanelProps = {}) => {let cancelled = false;const load = async () => {try {- const [s, v] = await Promise.all([getTokenjuiceSettings(), getTokenjuiceSavings()]);+ const s = await getTokenjuiceSettings();if (cancelled) return;setSettings(s);- setSavings(v);setMinTokensInput(String(s.ccr_min_tokens));savedMinTokensRef.current = s.ccr_min_tokens;} catch (e) {if (!cancelled) setError(e instanceof Error ? e.message : String(e));+ // Settings failure disables all controls — don't bother loading savings.+ return;+ }+ // Load savings independently: a savings failure must not prevent the+ // configuration controls from becoming interactive.+ try {+ const v = await getTokenjuiceSavings();+ if (!cancelled) setSavings(v);+ } catch {+ // Non-fatal: savings stats stay blank; user can refresh manually.}};void load();diff --git a/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx b/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsxindex f4e49a7ac3..cf299c9fe5 100644--- a/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx+++ b/app/src/components/settings/panels/__tests__/TokenUsagePanel.test.tsx@@ -65,7 +65,7 @@ describe('TokenUsagePanel', () => {mockGetSettings.mockResolvedValue(stubSettings);});- it('enables all switches once settings load', async () => {+ it('enables all switches and the CCR min-tokens field once settings load', async () => {render(<TokenUsagePanel embedded />);// Wait for the async load to complete — all 7 switches must be enabled.@@ -74,6 +74,9 @@ describe('TokenUsagePanel', () => {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 () => {@@ -98,6 +101,21 @@ describe('TokenUsagePanel', () => {await user.click(sw);expect(mockUpdate).toHaveBeenCalledWith({ router_enabled: false });});++ it('keeps controls enabled when only savings fails', async () => {+ mockGetSavings.mockRejectedValue(new Error('savings rpc down'));+ render(<TokenUsagePanel embedded />);++ // Settings loaded OK — all 7 switches and the number field must still become enabled.+ 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();+ });});describe('when settings load fails', () => {@@ -105,25 +123,30 @@ describe('TokenUsagePanel', () => {mockGetSettings.mockRejectedValue(new Error('rpc down'));});- it('disables all switches while settings are unavailable', async () => {+ it('disables all switches and the CCR min-tokens field while settings are unavailable', async () => {render(<TokenUsagePanel embedded />);- // After the rejection settles, settings stays null — every switch must be disabled.- await waitFor(() => expect(mockGetSettings).toHaveBeenCalled());-- const switches = screen.getAllByRole('switch');- expect(switches).toHaveLength(7);- for (const sw of switches) expect(sw).toBeDisabled();+ // Wait directly for the disabled state — this proves the rejection has+ // settled and React has re-rendered with settings === null.+ await waitFor(() => {+ 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 />);- await waitFor(() => expect(mockGetSettings).toHaveBeenCalled());-- const sw = screen.getByRole('switch', { name: 'settings.tokenUsage.routerEnabled' });- expect(sw).toBeDisabled();+ const sw = await waitFor(() => {+ const el = screen.getByRole('switch', { name: 'settings.tokenUsage.routerEnabled' });+ expect(el).toBeDisabled();+ return el;+ });await user.click(sw);expect(mockUpdate).not.toHaveBeenCalled();});