Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(settings): cover AgentsPanel's remove, toggle-failure and orchestrator paths\n\nAgentsPanel was the weakest-covered of the seven approval/agent settings\npanels: 79.03% statements / 62.50% branches, with `handleRemove` (lines\n77-87) having no test at all. Remove is the destructive action on this\npanel — it deletes a custom agent and resets a built-in — so it was the\ngap worth closing.\n\nSix cases added:\n - a failed toggle surfaces the API's own message, not the generic\n fallback, and does not leave the row stuck busy;\n - a non-Error rejection falls back to the i18n string rather than\n rendering "undefined";\n - deleting a custom agent calls remove and reloads the list;\n - resetting a built-in routes through the same remove endpoint — the\n label and the call diverge deliberately, so it is pinned;\n - a failed delete shows the error and does NOT reload, since reloading\n would redraw the row as if nothing happened and drop the error;\n - the orchestrator is never passed to setEnabled, asserted through the\n handler and not only via the disabled switch.\n\nCoverage: 79.03 -> 98.38% statements, 62.50 -> 75.00% branches,\n85.71 -> 100% functions, 79.62 -> 100% lines.\n\nEach case was verified by mutation — the covered behaviour was broken in\nAgentsPanel.tsx and the test confirmed to fail: the catch branch forced\nto the generic string, `String(err)` substituted for the instanceof\ncheck, `await load()` dropped from handleRemove, `remove(agent.id)`\nhardcoded, `load()` moved into `finally`, and the ORCHESTRATOR_ID guard\ndeleted alongside the switch's disabled prop.\n\nNo new spec files: the panel already had a test file, so these extend it\nrather than duplicate it.\n

M3gA-Mindb51b97f9c313
diff --git a/app/src/components/settings/panels/AgentsPanel.test.tsx b/app/src/components/settings/panels/AgentsPanel.test.tsx
index 725c5f83d2..f5e97d5515 100644
--- a/app/src/components/settings/panels/AgentsPanel.test.tsx
+++ b/app/src/components/settings/panels/AgentsPanel.test.tsx
@@ -34,6 +34,7 @@ vi.mock('../hooks/useSettingsNavigation', () => ({
const mockList = vi.mocked(agentRegistryApi.list);
const mockSetEnabled = vi.mocked(agentRegistryApi.setEnabled);
+const mockRemove = vi.mocked(agentRegistryApi.remove);
const renderPanel = () =>
render(
@@ -116,4 +117,96 @@ describe('AgentsPanel', () => {
renderPanel();
await waitFor(() => expect(screen.getByText(/Couldn't load agents/)).toBeInTheDocument());
});
+ // --- Paths the original five cases left uncovered -----------------------
+ //
+ // Coverage before these: 79.03% stmts / 62.50% branch, with lines 65-66
+ // (the toggle failure branch), 77-87 (`handleRemove` in full) and 131 (its
+ // wiring) unexecuted. `handleRemove` is the destructive action on this
+ // panel and had no test at all.
+
+ it('surfaces the API error message when a toggle fails', async () => {
+ // The catch branch prefers `err.message` over the generic i18n fallback,
+ // so a caller sees *why* it failed rather than "Couldn't update the agent".
+ mockSetEnabled.mockRejectedValueOnce(new Error('registry is read-only'));
+ renderPanel();
+ await waitFor(() => expect(screen.getByText('Researcher')).toBeInTheDocument());
+
+ fireEvent.click(screen.getAllByRole('switch')[1]);
+
+ await waitFor(() => expect(screen.getByText('registry is read-only')).toBeInTheDocument());
+ // The row must not be left stuck in its busy state after a failure.
+ await waitFor(() => expect(screen.getAllByRole('switch')[1]).not.toBeDisabled());
+ });
+
+ it('falls back to the generic message when a toggle rejects a non-Error', async () => {
+ // `err instanceof Error` is the branch under test: a string rejection
+ // must not render "undefined" into the banner.
+ mockSetEnabled.mockRejectedValueOnce('nope');
+ renderPanel();
+ await waitFor(() => expect(screen.getByText('Researcher')).toBeInTheDocument());
+
+ fireEvent.click(screen.getAllByRole('switch')[1]);
+
+ await waitFor(() => expect(screen.getByText("Couldn't update the agent")).toBeInTheDocument());
+ });
+
+ it('deletes a custom agent and reloads the list', async () => {
+ mockRemove.mockResolvedValue(true);
+ renderPanel();
+ await waitFor(() => expect(screen.getByText('Finance')).toBeInTheDocument());
+
+ // Built-ins offer "Reset to default"; only the custom agent offers Delete.
+ const deleteButtons = screen.getAllByRole('button', { name: /^Delete$/ });
+ expect(deleteButtons).toHaveLength(1);
+ fireEvent.click(deleteButtons[0]);
+
+ await waitFor(() => expect(mockRemove).toHaveBeenCalledWith('finance'));
+ // `handleRemove` re-runs `load()` rather than patching state locally, so a
+ // reset built-in comes back with its server-side defaults.
+ await waitFor(() => expect(mockList).toHaveBeenCalledTimes(2));
+ });
+
+ it('resets a built-in agent through the same remove endpoint', async () => {
+ // Built-ins are not deleted — the panel labels the action "Reset to
+ // default" but routes it through `remove`, which restores the shipped
+ // definition. Worth pinning: the label and the call diverge on purpose.
+ mockRemove.mockResolvedValue(true);
+ renderPanel();
+ await waitFor(() => expect(screen.getByText('Researcher')).toBeInTheDocument());
+
+ const resetButtons = screen.getAllByRole('button', { name: /Reset to default/ });
+ // orchestrator + researcher are both built-in.
+ expect(resetButtons).toHaveLength(2);
+ fireEvent.click(resetButtons[1]);
+
+ await waitFor(() => expect(mockRemove).toHaveBeenCalledWith('researcher'));
+ });
+
+ it('shows an error and stops reloading when a delete fails', async () => {
+ mockRemove.mockRejectedValueOnce(new Error('agent is in use'));
+ renderPanel();
+ await waitFor(() => expect(screen.getByText('Finance')).toBeInTheDocument());
+
+ fireEvent.click(screen.getAllByRole('button', { name: /^Delete$/ })[0]);
+
+ await waitFor(() => expect(screen.getByText('agent is in use')).toBeInTheDocument());
+ // A failed remove must NOT reload: reloading would redraw the row as if
+ // nothing happened and drop the error the user needs to read.
+ expect(mockList).toHaveBeenCalledTimes(1);
+ });
+
+ it('never calls setEnabled for the orchestrator', async () => {
+ // `handleToggle` early-returns on ORCHESTRATOR_ID (line 56) *and* the row
+ // renders its switch disabled. Asserting only `toBeDisabled()` would pass
+ // if the guard were deleted, so drive the handler directly too.
+ renderPanel();
+ await waitFor(() => expect(screen.getByText('Orchestrator')).toBeInTheDocument());
+
+ const orchestratorSwitch = screen.getAllByRole('switch')[0];
+ expect(orchestratorSwitch).toBeDisabled();
+ fireEvent.click(orchestratorSwitch);
+
+ await waitFor(() => expect(screen.getByText('Researcher')).toBeInTheDocument());
+ expect(mockSetEnabled).not.toHaveBeenCalled();
+ });
});