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: address review — scope autonomy revert + pin rollback/eval tests (#2519)
Adam Eivy173ecf097c23
diff --git a/client/src/components/cos/tabs/ConfigTab.jsx b/client/src/components/cos/tabs/ConfigTab.jsxindex edb3a8a09f..bcfc9a2f56 100644--- a/client/src/components/cos/tabs/ConfigTab.jsx+++ b/client/src/components/cos/tabs/ConfigTab.jsx@@ -280,17 +280,19 @@ export default function ConfigTab({ config, onUpdate, onEvaluate, avatarStyle, s});const handleLevelChange = async (params, label) => {- // Optimistically reflect the new params, but revert if the PUT fails so the- // form doesn't lie about the persisted config. Success toast / refresh only- // fire after the request resolves.- const previousData = formData;- setFormData({ ...formData, ...params });+ // Optimistically reflect the new params via a functional update, but revert+ // ONLY the keys we set if the PUT fails — snapshotting and restoring the whole+ // formData would clobber unrelated edits (or a later level pick) the user made+ // while this request was in flight. Success toast / refresh only fire after the+ // request resolves.+ const revertKeys = Object.fromEntries(Object.keys(params).map(k => [k, formData[k]]));+ setFormData(prev => ({ ...prev, ...params }));try {await api.updateCosConfig(params, { silent: true });if (label) toast.success(`Autonomy level set to ${label}`);onUpdate();} catch (err) {- setFormData(previousData);+ setFormData(prev => ({ ...prev, ...revertKeys }));toast.error(err.message);}};diff --git a/client/src/components/cos/tabs/ConfigTab.test.jsx b/client/src/components/cos/tabs/ConfigTab.test.jsxindex e534fcee93..8a64befbd7 100644--- a/client/src/components/cos/tabs/ConfigTab.test.jsx+++ b/client/src/components/cos/tabs/ConfigTab.test.jsx@@ -1,5 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';-import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';// Regression coverage for #2519 — failed CoS config calls must NOT flash a// success toast, must keep the user in edit mode, and must revert optimistic@@ -76,6 +76,9 @@ describe('ConfigTab handleSave', () => {});describe('ConfigTab handleLevelChange', () => {+ // Reads the non-editing value span rendered next to a ConfigRow label.+ const rowValue = (label) => within(screen.getByText(label).closest('div')).getByText;+it('does not toast success when the autonomy level change fails', async () => {api.updateCosConfig.mockRejectedValue(new Error('boom'));render(<ConfigTab config={config} onUpdate={vi.fn()} onEvaluate={vi.fn()} avatarStyle="svg" setAvatarStyle={vi.fn()} />);@@ -86,12 +89,29 @@ describe('ConfigTab handleLevelChange', () => {expect(toast.success).not.toHaveBeenCalled();});- it('toasts the level label only after the change resolves', async () => {+ it('reverts the optimistic form params when the level change fails', async () => {+ api.updateCosConfig.mockRejectedValue(new Error('boom'));+ render(<ConfigTab config={config} onUpdate={vi.fn()} onEvaluate={vi.fn()} avatarStyle="svg" setAvatarStyle={vi.fn()} />);++ // Baseline: Max Concurrent Agents shows the config value (3).+ expect(rowValue('Max Concurrent Agents')('3')).toBeInTheDocument();++ // Standby sets maxConcurrentAgents: 1 optimistically; on failure it must revert+ // back to 3 (without the revert this row would be stuck showing 1).+ fireEvent.click(screen.getByRole('button', { name: 'Standby' }));++ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('boom'));+ expect(rowValue('Max Concurrent Agents')('3')).toBeInTheDocument();+ });++ it('keeps the optimistic params and toasts the label after the change resolves', async () => {api.updateCosConfig.mockResolvedValue({ success: true });render(<ConfigTab config={config} onUpdate={vi.fn()} onEvaluate={vi.fn()} avatarStyle="svg" setAvatarStyle={vi.fn()} />);fireEvent.click(screen.getByRole('button', { name: 'Standby' }));await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Autonomy level set to Standby'));+ // Optimistic value persisted (Standby → maxConcurrentAgents: 1).+ expect(rowValue('Max Concurrent Agents')('1')).toBeInTheDocument();});});diff --git a/client/src/pages/ChiefOfStaff.test.jsx b/client/src/pages/ChiefOfStaff.test.jsxnew file mode 100644index 0000000000..d2228f1c8f--- /dev/null+++ b/client/src/pages/ChiefOfStaff.test.jsx@@ -0,0 +1,95 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, waitFor, fireEvent } from '@testing-library/react';+import { MemoryRouter, Routes, Route } from 'react-router-dom';++// Regression coverage for #2519 — the page-level Force Evaluate handler must+// only toast success after the request resolves, and must toast the error+// (not a success) when it rejects.+const api = vi.hoisted(() => ({+ getCosStatus: vi.fn(),+ getCosTasks: vi.fn(),+ getCosAgents: vi.fn(),+ getCosHealth: vi.fn(),+ getProviders: vi.fn(),+ getApps: vi.fn(),+ getCosLearningSummary: vi.fn(),+ getCosBudgetUsage: vi.fn(),+ forceCosEvaluate: vi.fn(),+ updateCosConfig: vi.fn(),+}));+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn() }));+const socketStub = vi.hoisted(() => ({ connected: false, on: vi.fn(), off: vi.fn(), emit: vi.fn() }));++vi.mock('../services/api', () => api);+vi.mock('../components/ui/Toast', () => ({ default: toast }));+vi.mock('../services/socket', () => ({ default: socketStub }));+// ConfigTab's provider/model hook fetches over the network — stub it.+vi.mock('../hooks/useProviderModels', () => ({+ default: () => ({+ providers: [],+ availableModels: [],+ setSelectedProviderId: vi.fn(),+ setSelectedModel: vi.fn(),+ selectedProviderId: '',+ selectedModel: '',+ }),+}));++const ChiefOfStaff = (await import('./ChiefOfStaff')).default;++const config = {+ avatarStyle: 'svg',+ healthCheckIntervalMs: 900000,+ maxConcurrentAgents: 3,+ maxConcurrentAgentsPerProject: 2,+ maxProcessMemoryMb: 2048,+ autoStart: false,+ improvementEnabled: true,+ proactiveMode: true,+ idleReviewEnabled: true,+ immediateExecution: true,+};++beforeEach(() => {+ vi.clearAllMocks();+ api.getCosStatus.mockResolvedValue({ running: false, config, stats: {} });+ api.getCosTasks.mockResolvedValue({ user: null, cos: null });+ api.getCosAgents.mockResolvedValue([]);+ api.getCosHealth.mockResolvedValue(null);+ api.getProviders.mockResolvedValue({ providers: [] });+ api.getApps.mockResolvedValue([]);+ api.getCosLearningSummary.mockResolvedValue(null);+ api.getCosBudgetUsage.mockResolvedValue({ usage: {} });+});++const renderConfigTab = () => render(+ <MemoryRouter initialEntries={['/cos/config']}>+ <Routes>+ <Route path="/cos/:tab" element={<ChiefOfStaff />} />+ </Routes>+ </MemoryRouter>,+);++describe('ChiefOfStaff handleForceEvaluate', () => {+ it('does not toast success when the evaluate request fails', async () => {+ api.forceCosEvaluate.mockRejectedValue(new Error('evaluate failed'));+ renderConfigTab();++ const button = await screen.findByRole('button', { name: /Force Evaluate/i });+ fireEvent.click(button);++ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('evaluate failed'));+ expect(toast.success).not.toHaveBeenCalled();+ });++ it('toasts success only after the evaluate request resolves', async () => {+ api.forceCosEvaluate.mockResolvedValue({ success: true });+ renderConfigTab();++ const button = await screen.findByRole('button', { name: /Force Evaluate/i });+ fireEvent.click(button);++ await waitFor(() => expect(toast.success).toHaveBeenCalledWith('Evaluation triggered'));+ expect(toast.error).not.toHaveBeenCalled();+ });+});