Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: confirm Calendar credential clears before reporting success (#9702)
Adam Eivy5b2a96af4d9c
diff --git a/client/src/components/calendar/ConfigTab.jsx b/client/src/components/calendar/ConfigTab.jsxindex fa903bb3b6..f8288fbafa 100644--- a/client/src/components/calendar/ConfigTab.jsx+++ b/client/src/components/calendar/ConfigTab.jsx@@ -27,6 +27,7 @@ export default function ConfigTab({ accounts, setAccounts }) {const [savingSubcals, setSavingSubcals] = useState(null);const [discovering, setDiscovering] = useState(null);const [googleAuth, setGoogleAuth] = useState(null);+ const [clearingGoogleAuth, setClearingGoogleAuth] = useState(false);const [oauthForm, setOauthForm] = useState({ clientId: '', clientSecret: '' });const [savingOAuth, setSavingOAuth] = useState(false);const [autoConfigStep, setAutoConfigStep] = useState(null); // null | 'launching' | 'login' | 'project' | 'api' | 'consent' | 'credentials' | 'capturing' | 'done'@@ -79,7 +80,11 @@ export default function ConfigTab({ accounts, setAccounts }) {};const handleClearGoogleAuth = async () => {- await api.clearGoogleAuth().catch(() => null);+ if (clearingGoogleAuth) return;+ setClearingGoogleAuth(true);+ const cleared = await api.clearGoogleAuth().then(() => true).catch(() => false);+ setClearingGoogleAuth(false);+ if (!cleared) return;toast.success('Google auth cleared');fetchGoogleAuth();};@@ -402,6 +407,7 @@ export default function ConfigTab({ accounts, setAccounts }) {</div><buttononClick={handleClearGoogleAuth}+ disabled={clearingGoogleAuth}className="px-2 py-0.5 text-xs rounded text-gray-600 hover:text-port-error hover:bg-gray-800">Cleardiff --git a/client/src/components/calendar/ConfigTab.test.jsx b/client/src/components/calendar/ConfigTab.test.jsxnew file mode 100644index 0000000000..7395e5c7e2--- /dev/null+++ b/client/src/components/calendar/ConfigTab.test.jsx@@ -0,0 +1,62 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { MemoryRouter } from 'react-router';+import ConfigTab from './ConfigTab';++const api = vi.hoisted(() => ({+ getGoogleAuthStatus: vi.fn(),+ clearGoogleAuth: vi.fn(),+}));+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }));+vi.mock('../../services/api', () => api);+vi.mock('../ui/Toast', () => ({ default: toast }));++const account = { id: 'google-1', name: 'Example Calendar', enabled: true, type: 'google-calendar', syncMethod: 'google-api' };++beforeEach(() => {+ vi.resetAllMocks();+ api.getGoogleAuthStatus.mockResolvedValue({ hasCredentials: true, hasTokens: true });+});++const openAuth = async () => {+ render(<MemoryRouter><ConfigTab accounts={[account]} setAccounts={vi.fn()} /></MemoryRouter>);+ fireEvent.click(screen.getByRole('button', { name: 'Expand calendars for Example Calendar' }));+ await screen.findByText('Google API authenticated');+ return screen.getByRole('button', { name: 'Clear' });+};++describe('Google credential clearing', () => {+ it('blocks duplicate clears and confirms a bodyless success before refreshing auth', async () => {+ let resolve;+ api.clearGoogleAuth.mockImplementation(() => new Promise(done => { resolve = done; }));+ const button = await openAuth();+ api.getGoogleAuthStatus.mockResolvedValue({ hasCredentials: true, hasTokens: false });+ fireEvent.click(button);+ expect(button).toBeDisabled();+ fireEvent.click(button);+ expect(api.clearGoogleAuth).toHaveBeenCalledTimes(1);+ expect(toast.success).not.toHaveBeenCalled();+ expect(api.getGoogleAuthStatus).toHaveBeenCalledTimes(1);++ await act(async () => resolve(undefined));+ await screen.findByText('Credentials saved but not authorized yet.');+ expect(toast.success).toHaveBeenCalledExactlyOnceWith('Google auth cleared');+ expect(api.getGoogleAuthStatus).toHaveBeenCalledTimes(2);+ });++ it('preserves authenticated status on rejection and releases Clear for retry', async () => {+ api.clearGoogleAuth.mockRejectedValueOnce(new Error('Synthetic clear failure')).mockResolvedValueOnce(undefined);+ const button = await openAuth();+ fireEvent.click(button);+ await waitFor(() => expect(button).toBeEnabled());+ expect(screen.getByText('Google API authenticated')).toBeTruthy();+ expect(api.getGoogleAuthStatus).toHaveBeenCalledTimes(1);+ expect(toast.success).not.toHaveBeenCalled();+ expect(toast.error).not.toHaveBeenCalled(); // API request owns the error notice.++ fireEvent.click(button);+ await waitFor(() => expect(toast.success).toHaveBeenCalledExactlyOnceWith('Google auth cleared'));+ expect(api.clearGoogleAuth).toHaveBeenCalledTimes(2);+ expect(api.getGoogleAuthStatus).toHaveBeenCalledTimes(2);+ });+});diff --git a/client/src/components/calendar/SyncTab.jsx b/client/src/components/calendar/SyncTab.jsxindex 64dfeb029f..2b196e1353 100644--- a/client/src/components/calendar/SyncTab.jsx+++ b/client/src/components/calendar/SyncTab.jsx@@ -10,6 +10,7 @@ import EmptyState from '../EmptyState';export default function SyncTab({ accounts, onRefresh }) {const [tokenStatus, setTokenStatus] = useState(null);const [tokenLoading, setTokenLoading] = useState(true);+ const [clearingTokens, setClearingTokens] = useState({});const [mcpProgress, setMcpProgress] = useState({});const fetchTokenStatus = useCallback(async () => {@@ -63,7 +64,11 @@ export default function SyncTab({ accounts, onRefresh }) {};const handleClearToken = async (provider) => {- await api.clearCalendarToken(provider).catch(() => null);+ if (clearingTokens[provider]) return;+ setClearingTokens(prev => ({ ...prev, [provider]: true }));+ const cleared = await api.clearCalendarToken(provider).then(() => true).catch(() => false);+ setClearingTokens(prev => ({ ...prev, [provider]: false }));+ if (!cleared) return;toast.success(`${provider} token cleared`);fetchTokenStatus();};@@ -178,6 +183,7 @@ export default function SyncTab({ accounts, onRefresh }) {{status.hasToken && (<buttononClick={() => handleClearToken(status.provider)}+ disabled={clearingTokens[status.provider]}className="flex items-center gap-1 px-2 py-1 text-xs text-gray-400 hover:text-port-error bg-port-border rounded transition-colors"title="Clear token">diff --git a/client/src/components/calendar/SyncTab.test.jsx b/client/src/components/calendar/SyncTab.test.jsxindex 14f302f7c3..65803d200c 100644--- a/client/src/components/calendar/SyncTab.test.jsx+++ b/client/src/components/calendar/SyncTab.test.jsx@@ -6,6 +6,7 @@ import { awaitEnabled } from '../../test/enabledBarrier.js';const api = vi.hoisted(() => ({getCalendarTokenStatus: vi.fn(),+ clearCalendarToken: vi.fn(),syncCalendarAccount: vi.fn(),apiSyncGoogleCalendar: vi.fn(),mcpSyncGoogleCalendar: vi.fn(),@@ -141,3 +142,45 @@ describe('Calendar sync lifecycle', () => {expect(onRefresh).not.toHaveBeenCalled();});});++describe('Calendar token clearing', () => {+ const present = { providers: [{ provider: 'outlook', hasToken: true }] };++ it('blocks duplicate clears and refreshes only after a bodyless success', async () => {+ let resolve;+ api.getCalendarTokenStatus.mockResolvedValue(present);+ api.clearCalendarToken.mockImplementation(() => new Promise(done => { resolve = done; }));+ render(<SyncTab accounts={[account]} onRefresh={vi.fn()} />);+ const button = await screen.findByRole('button', { name: 'Clear' });+ api.getCalendarTokenStatus.mockResolvedValue({ providers: [{ provider: 'outlook', hasToken: false }] });+ fireEvent.click(button);+ expect(button).toBeDisabled();+ fireEvent.click(button);+ expect(api.clearCalendarToken).toHaveBeenCalledExactlyOnceWith('outlook');+ expect(toast.success).not.toHaveBeenCalled();+ expect(api.getCalendarTokenStatus).toHaveBeenCalledTimes(1);++ await act(async () => resolve(undefined));+ await screen.findByText('No token');+ expect(toast.success).toHaveBeenCalledExactlyOnceWith('outlook token cleared');+ expect(api.getCalendarTokenStatus).toHaveBeenCalledTimes(2);+ });++ it('preserves the token on rejection without a component error toast and permits retry', async () => {+ api.getCalendarTokenStatus.mockResolvedValue(present);+ api.clearCalendarToken.mockRejectedValueOnce(new Error('Synthetic clear failure')).mockResolvedValueOnce(undefined);+ render(<SyncTab accounts={[account]} onRefresh={vi.fn()} />);+ const button = await screen.findByRole('button', { name: 'Clear' });+ fireEvent.click(button);+ await waitFor(() => expect(button).toBeEnabled());+ expect(screen.getByText('Token present')).toBeTruthy();+ expect(api.getCalendarTokenStatus).toHaveBeenCalledTimes(1);+ expect(toast.success).not.toHaveBeenCalled();+ expect(toast.error).not.toHaveBeenCalled();++ fireEvent.click(button);+ await waitFor(() => expect(toast.success).toHaveBeenCalledExactlyOnceWith('outlook token cleared'));+ expect(api.clearCalendarToken).toHaveBeenCalledTimes(2);+ expect(api.getCalendarTokenStatus).toHaveBeenCalledTimes(2);+ });+});