Skip to content

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

fix([issue-1149]): address claude review — callback logging, instanceof guard, service-level status tests

[._.]/ Adam Eivy02afec80e674
diff --git a/client/src/components/calendar/ConfigTab.jsx b/client/src/components/calendar/ConfigTab.jsx
index 567b38c9d6..eeb9b48e59 100644
--- a/client/src/components/calendar/ConfigTab.jsx
+++ b/client/src/components/calendar/ConfigTab.jsx
@@ -180,15 +180,9 @@ export default function ConfigTab({ accounts, setAccounts }) {
? await api.apiDiscoverCalendars(account.id).catch(() => null)
: await api.mcpDiscoverCalendars(account.id).catch(() => null);
setDiscovering(null);
- if (!result || result.error) {
- if (result?.error?.includes('Failed to spawn') || result?.error?.includes('No enabled CLI provider')) {
- return toast.error(`${result.error}. Check the provider configured for calendar sync above.`);
- }
- if (result?.error?.includes('OAuth')) {
- return toast.error('Google OAuth not configured. Set up credentials below.');
- }
- return;
- }
+ // Failures arrive as throws (the API helper already toasted the server's
+ // error message) — the .catch above turns them into null.
+ if (!result) return;
toast.success(`Discovered ${result.calendars?.length || 0} calendars`);
setAccounts(prev => prev.map(a => a.id === account.id ? { ...a, subcalendars: result.calendars } : a));
};
diff --git a/server/routes/calendar.js b/server/routes/calendar.js
index 583559f02d..c553bc3f62 100644
--- a/server/routes/calendar.js
+++ b/server/routes/calendar.js
@@ -248,7 +248,12 @@ router.get('/google/oauth/callback', asyncHandler(async (req, res) => {
const code = req.query.code;
if (!code) return res.redirect(configUrl('Missing authorization code'));
const error = await googleAuth.handleCallback(code).then(() => null)
- .catch((err) => err.message || 'Google OAuth callback failed');
+ .catch((err) => {
+ // This catch replaces asyncHandler's logging (the redirect swallows the
+ // throw), so keep the failure visible in server logs.
+ console.error(`❌ Google OAuth callback failed: ${err.message}`);
+ return err.message || 'Google OAuth callback failed';
+ });
res.redirect(configUrl(error));
}));
diff --git a/server/services/calendarSync.js b/server/services/calendarSync.js
index 169d081dba..f2d65365be 100644
--- a/server/services/calendarSync.js
+++ b/server/services/calendarSync.js
@@ -221,7 +221,7 @@ export async function syncAccount(accountId, io, options = {}) {
console.error(`📅 Sync failed for ${account.name} (${account.type}): ${error.message}`);
await updateSyncStatus(accountId, 'error').catch(() => {});
io?.emit('calendar:sync:failed', { accountId, error: error.message });
- throw new ServerError(error.message, { status: 502 });
+ throw error instanceof ServerError ? error : new ServerError(error.message, { status: 502 });
}).finally(() => {
syncLocks.delete(accountId);
});
diff --git a/server/services/calendarSync.test.js b/server/services/calendarSync.test.js
new file mode 100644
index 0000000000..7d410cd411
--- /dev/null
+++ b/server/services/calendarSync.test.js
@@ -0,0 +1,73 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+vi.mock('./calendarAccounts.js', () => ({
+ getAccount: vi.fn(),
+ updateSyncStatus: vi.fn(),
+ updateSubcalendars: vi.fn(),
+ mergeDiscoveredSubcalendars: vi.fn()
+}));
+
+import { syncAccount } from './calendarSync.js';
+import { mcpSyncAccount, mcpDiscoverCalendars } from './calendarGoogleSync.js';
+import { apiSyncAccount, apiDiscoverCalendars } from './calendarGoogleApiSync.js';
+import { getAccount } from './calendarAccounts.js';
+
+const ACCOUNT_ID = '11111111-1111-1111-1111-111111111111';
+
+// Pins the service-level ServerError statuses the calendar routes rely on —
+// routes/calendar.test.js covers the route↔envelope mapping with mocked
+// services, so without these a service status regression wouldn't fail CI.
+describe('calendar sync services throw ServerError with the documented statuses', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ describe('calendarSync.syncAccount', () => {
+ it('throws 404 for an unknown account', async () => {
+ getAccount.mockResolvedValue(null);
+ await expect(syncAccount(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 404, message: 'Account not found' });
+ });
+
+ it('throws 400 for a disabled account', async () => {
+ getAccount.mockResolvedValue({ id: ACCOUNT_ID, enabled: false });
+ await expect(syncAccount(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 400, message: 'Account is disabled' });
+ });
+ });
+
+ describe('calendarGoogleSync.mcpSyncAccount', () => {
+ it('throws 404 for an unknown account', async () => {
+ getAccount.mockResolvedValue(null);
+ await expect(mcpSyncAccount(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 404 });
+ });
+
+ it('throws 400 for a non-Google account', async () => {
+ getAccount.mockResolvedValue({ id: ACCOUNT_ID, type: 'outlook-calendar' });
+ await expect(mcpSyncAccount(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 400, message: 'Not a Google Calendar account' });
+ });
+
+ it('throws 400 when no subcalendars are enabled', async () => {
+ getAccount.mockResolvedValue({ id: ACCOUNT_ID, type: 'google-calendar', subcalendars: [{ calendarId: 'a', enabled: false }] });
+ await expect(mcpSyncAccount(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 400, message: 'No enabled subcalendars' });
+ });
+ });
+
+ describe('calendarGoogleSync.mcpDiscoverCalendars', () => {
+ it('throws 404 for an unknown account', async () => {
+ getAccount.mockResolvedValue(null);
+ await expect(mcpDiscoverCalendars(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 404 });
+ });
+ });
+
+ describe('calendarGoogleApiSync', () => {
+ it('apiSyncAccount throws 401 when Google OAuth is not configured', async () => {
+ // No credentials/tokens on disk in the test env → getAuthenticatedClient() is null.
+ getAccount.mockResolvedValue({ id: ACCOUNT_ID, type: 'google-calendar', subcalendars: [{ calendarId: 'a', enabled: true }] });
+ await expect(apiSyncAccount(ACCOUNT_ID, null)).rejects.toMatchObject({ status: 401 });
+ });
+
+ it('apiDiscoverCalendars throws 404 for an unknown account', async () => {
+ getAccount.mockResolvedValue(null);
+ await expect(apiDiscoverCalendars(ACCOUNT_ID)).rejects.toMatchObject({ status: 404 });
+ });
+ });
+});