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: notify clients on app creation and update to refresh navigation

[._.]/ Adam Eivy0414c537f998
diff --git a/client/src/components/Layout.test.jsx b/client/src/components/Layout.test.jsx
index 0d23f92f94..3364a20658 100644
--- a/client/src/components/Layout.test.jsx
+++ b/client/src/components/Layout.test.jsx
@@ -3,6 +3,7 @@ import { render, screen, within, act, fireEvent, waitFor } from '@testing-librar
import { MemoryRouter, useLocation } from 'react-router';
import { PINNED_KEY } from '../utils/navWorkingSet.js';
import * as api from '../services/api';
+import socket from '../services/socket';
import { INSTANCE_FEATURES_CHANGED } from '../constants/events.js';
import { CMD_K_SEARCH_OPEN_EVENT } from '../hooks/useCmdKSearch.js';
@@ -562,7 +563,24 @@ describe('Layout — dynamic third-level navigation', () => {
fireEvent.click(screen.getByRole('button', { name: 'Expand Universes' }));
expect(screen.getByRole('link', { name: 'Example Series' })).toBeTruthy();
expect(screen.getByRole('link', { name: 'Example Universe' })).toBeTruthy();
+ });
+
+ it('updates dynamic apps navigation when apps:changed is emitted', async () => {
+ let appsChangedHandler;
+ socket.on.mockImplementation((event, handler) => {
+ if (event === 'apps:changed') appsChangedHandler = handler;
+ });
+ api.getApps.mockResolvedValueOnce([]);
+ await renderLayout('/apps');
+
+ expect(screen.queryByRole('link', { name: 'Super New App' })).not.toBeInTheDocument();
+
+ api.getApps.mockResolvedValueOnce([{ id: 'super-new-app', name: 'Super New App' }]);
+ await act(async () => {
+ appsChangedHandler?.();
+ });
+ expect(await screen.findByRole('link', { name: 'Super New App' })).toBeInTheDocument();
});
});
diff --git a/client/src/hooks/useSidebarApps.js b/client/src/hooks/useSidebarApps.js
index 995ac78e89..b9fe45000f 100644
--- a/client/src/hooks/useSidebarApps.js
+++ b/client/src/hooks/useSidebarApps.js
@@ -27,9 +27,11 @@ export function useSidebarApps({ includeDetails = false } = {}) {
};
fetchApps();
socket.on('apps:changed', fetchApps);
+ socket.on('connect', fetchApps);
return () => {
cancelled = true;
socket.off('apps:changed', fetchApps);
+ socket.off('connect', fetchApps);
};
}, [includeDetails]);
return apps;
diff --git a/client/src/hooks/useSidebarApps.test.jsx b/client/src/hooks/useSidebarApps.test.jsx
new file mode 100644
index 0000000000..2c83c30f3e
--- /dev/null
+++ b/client/src/hooks/useSidebarApps.test.jsx
@@ -0,0 +1,112 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { renderHook, act, waitFor } from '@testing-library/react';
+import * as api from '../services/api';
+import socket from '../services/socket';
+import { useSidebarApps } from './useSidebarApps.js';
+
+vi.mock('../services/api', () => ({
+ getApps: vi.fn(),
+}));
+
+vi.mock('../services/socket', () => {
+ const handlers = new Map();
+ return {
+ default: {
+ on: vi.fn((event, handler) => {
+ if (!handlers.has(event)) handlers.set(event, []);
+ handlers.get(event).push(handler);
+ }),
+ off: vi.fn((event, handler) => {
+ if (!handlers.has(event)) return;
+ const list = handlers.get(event).filter((h) => h !== handler);
+ handlers.set(event, list);
+ }),
+ emitMockEvent: (event, data) => {
+ (handlers.get(event) || []).forEach((h) => h(data));
+ },
+ clearHandlers: () => handlers.clear(),
+ },
+ };
+});
+
+describe('useSidebarApps', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ socket.clearHandlers();
+ });
+
+ it('fetches on mount, filters archived apps, and sorts active apps by name', async () => {
+ api.getApps.mockResolvedValue([
+ { id: 'app-z', name: 'Zeta App', archived: false },
+ { id: 'app-a', name: 'Alpha App', archived: false },
+ { id: 'app-archived', name: 'Archived App', archived: true },
+ ]);
+
+ const { result } = renderHook(() => useSidebarApps());
+
+ await waitFor(() => expect(result.current.length).toBe(2));
+ expect(api.getApps).toHaveBeenCalledWith({ silent: true, view: 'nav' });
+ expect(result.current.map((a) => a.id)).toEqual(['app-a', 'app-z']);
+ });
+
+ it('passes includeDetails to api.getApps when requested', async () => {
+ api.getApps.mockResolvedValue([{ id: 'app-1', name: 'App One' }]);
+
+ const { result } = renderHook(() => useSidebarApps({ includeDetails: true }));
+
+ await waitFor(() => expect(result.current.length).toBe(1));
+ expect(api.getApps).toHaveBeenCalledWith({ silent: true });
+ });
+
+ it('refetches and updates when apps:changed is emitted', async () => {
+ api.getApps
+ .mockResolvedValueOnce([{ id: 'app-1', name: 'App One' }])
+ .mockResolvedValueOnce([
+ { id: 'app-1', name: 'App One' },
+ { id: 'app-2', name: 'App Two' },
+ ]);
+
+ const { result } = renderHook(() => useSidebarApps());
+
+ await waitFor(() => expect(result.current.length).toBe(1));
+
+ act(() => {
+ socket.emitMockEvent('apps:changed', { action: 'create', appId: 'app-2' });
+ });
+
+ await waitFor(() => expect(result.current.length).toBe(2));
+ expect(result.current.map((a) => a.id)).toEqual(['app-1', 'app-2']);
+ });
+
+ it('refetches when connect is emitted', async () => {
+ api.getApps
+ .mockResolvedValueOnce([{ id: 'app-1', name: 'App One' }])
+ .mockResolvedValueOnce([
+ { id: 'app-1', name: 'App One' },
+ { id: 'app-2', name: 'App Two' },
+ ]);
+
+ const { result } = renderHook(() => useSidebarApps());
+
+ await waitFor(() => expect(result.current.length).toBe(1));
+
+ act(() => {
+ socket.emitMockEvent('connect');
+ });
+
+ await waitFor(() => expect(result.current.length).toBe(2));
+ });
+
+ it('cleans up socket listeners on unmount', async () => {
+ api.getApps.mockResolvedValue([]);
+
+ const { unmount } = renderHook(() => useSidebarApps());
+ expect(socket.on).toHaveBeenCalledWith('apps:changed', expect.any(Function));
+ expect(socket.on).toHaveBeenCalledWith('connect', expect.any(Function));
+
+ unmount();
+
+ expect(socket.off).toHaveBeenCalledWith('apps:changed', expect.any(Function));
+ expect(socket.off).toHaveBeenCalledWith('connect', expect.any(Function));
+ });
+});
diff --git a/server/routes/apps/crud.js b/server/routes/apps/crud.js
index 68179f0a27..74508bb76c 100644
--- a/server/routes/apps/crud.js
+++ b/server/routes/apps/crud.js
@@ -151,6 +151,7 @@ router.post('/', asyncHandler(async (req, res, next) => {
}
const app = await appsService.createApp(data);
+ notifyAppsChanged('create', app.id);
res.status(201).json(app);
}));
@@ -220,10 +221,12 @@ router.put('/:id', asyncHandler(async (req, res, next) => {
if (liUpdate !== undefined) {
const merged = await appsService.updateAppLayeredIntelligence(req.params.id, liUpdate);
+ notifyAppsChanged('update', req.params.id);
res.json(merged || app);
return;
}
+ notifyAppsChanged('update', req.params.id);
res.json(app);
}));
@@ -259,7 +262,7 @@ router.post('/:id/archive', asyncHandler(async (req, res) => {
}
console.log(`📦 Archived app: ${app.name}`);
- notifyAppsChanged('archive');
+ notifyAppsChanged('archive', app.id);
res.json(app);
}));
@@ -272,7 +275,7 @@ router.post('/:id/unarchive', asyncHandler(async (req, res) => {
}
console.log(`📤 Unarchived app: ${app.name}`);
- notifyAppsChanged('unarchive');
+ notifyAppsChanged('unarchive', app.id);
res.json(app);
}));
diff --git a/server/routes/apps/crud.test.js b/server/routes/apps/crud.test.js
index f0490f3631..9fae3f95e4 100644
--- a/server/routes/apps/crud.test.js
+++ b/server/routes/apps/crud.test.js
@@ -299,6 +299,7 @@ describe('Apps CRUD Routes', () => {
expect(response.status).toBe(201);
expect(response.body.id).toBe('app-001');
expect(appsService.createApp).toHaveBeenCalledWith(expect.objectContaining({ name: 'New App' }));
+ expect(appsService.notifyAppsChanged).toHaveBeenCalledWith('create', 'app-001');
});
it('should return 400 if validation fails', async () => {
@@ -322,6 +323,7 @@ describe('Apps CRUD Routes', () => {
expect(response.status).toBe(200);
expect(appsService.updateApp).toHaveBeenCalledWith('app-001', expect.objectContaining({ name: 'Updated Name' }));
+ expect(appsService.notifyAppsChanged).toHaveBeenCalledWith('update', 'app-001');
});
it('should return 404 if app not found', async () => {
diff --git a/server/routes/scaffold.js b/server/routes/scaffold.js
index 2e8f532ea6..b32c616cfe 100644
--- a/server/routes/scaffold.js
+++ b/server/routes/scaffold.js
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'url';
import { exec, spawn } from '../lib/childProcess.js';
import { promisify } from 'util';
import { platform } from 'os';
-import { createApp, getReservedPorts } from '../services/apps.js';
+import { createApp, getReservedPorts, notifyAppsChanged } from '../services/apps.js';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { validateRequest, scaffoldSchema } from '../lib/validation.js';
import { ensureDir, expandHome } from '../lib/fileUtils.js';
@@ -586,6 +586,8 @@ Thumbs.db
envFile: '.env'
});
+ notifyAppsChanged('create', app.id);
+
addStep('Register in PortOS', 'done');
res.json({
diff --git a/server/routes/scaffold.test.js b/server/routes/scaffold.test.js
index 00ae5efa17..a1e05f19f2 100644
--- a/server/routes/scaffold.test.js
+++ b/server/routes/scaffold.test.js
@@ -42,7 +42,8 @@ vi.mock('../lib/childProcess.js', () => ({
vi.mock('../services/apps.js', () => ({
createApp: vi.fn().mockResolvedValue({ id: 'app-001', name: 'Test' }),
- getReservedPorts: vi.fn().mockResolvedValue([])
+ getReservedPorts: vi.fn().mockResolvedValue([]),
+ notifyAppsChanged: vi.fn()
}));
vi.mock('../lib/workspaceRoots.js', () => ({