The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(settings): cover AboutPanel update states and CronJobsPanel ordering\n\nTwo panels in my area, both weak on branches rather than lines.\n\nAboutPanel (52.1% branches): the existing suite drives the real useAppUpdate\nhook through the status event and reaches three of its nine phases. Added 18\ntests over what the panel *renders* from that hook and from Redux — every phase\nproduces a distinct summary (a phase falling through to the default arm would\ncollide with idle and shrink the set), both available_version forks, the\nlast-checked line appearing only when check() returns non-null, and all four\npaths of the rpcUrl effect: cloud reads Redux without calling the shell,\nlocal resolves core_rpc_url, non-Tauri and a rejected command both fall back to\nthe unavailable placeholder. 52.1 -> 83.33% branches, 66.7 -> 88.88% lines,\n100% functions.\n\nCronJobsPanel (60.9% branches, already 97.5% lines): the uncovered part was the\nnext_run sort comparator — an entirely uncovered function that decides which job\nthe user reads as "next" — and the `: String(err)` arm of eight rejection\nformatters. Note the existing suite cannot observe those arms: formatCronError\nis `t(key).replace('{message}', message)`, and a `t` that returns the bare key\ndrops the message, so this file's i18n stub returns a real template instead.\n100% lines, 69.56% branches, 100% functions.\n\n12 mutations run across the two files, each confirmed to fail naming the new\nassertion; sources restored byte-identical after each. Three assertions were\nstrengthened after a mutation failed to kill them (the version strings also\nrender in the update banner, so those tests now suppress the banner to isolate\nthe summary).\n\nSettings suite 1043 -> 1067 tests, 92 files, 0 failures. No production code\nchanged.\n
M3gA-Mind6d8b4d70ef5b
diff --git a/app/src/components/settings/panels/CronJobsPanel.errors.test.tsx b/app/src/components/settings/panels/CronJobsPanel.errors.test.tsxnew file mode 100644index 0000000000..08b4393d8c--- /dev/null+++ b/app/src/components/settings/panels/CronJobsPanel.errors.test.tsx@@ -0,0 +1,183 @@+import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++/**+ * `CronJobsPanel` measured 97.5% lines but only 60.9% branches. The existing+ * `CronJobsPanel.test.tsx` drives every handler's happy path and every failure+ * path where the rejection is an `Error`. Two things it never reaches:+ *+ * - the `next_run` sort comparator in `loadCoreCronJobs` (panel :49-52),+ * an uncovered function. It decides which job the user reads as "next",+ * and the list arrives from the core in arbitrary order.+ * - the `: String(err)` arm of the eight+ * `err instanceof Error ? err.message : String(err)` expressions+ * (:67, :92, :110, :147, :158, :169, :190). A core RPC that rejects with a+ * bare string — which the JSON-RPC layer does — must still produce readable+ * copy rather than `[object Object]` or a blank error row.+ *+ * Beside the existing file rather than inside it so the two stay independently+ * reviewable; the mock surface is deliberately identical.+ */++// `formatCronError` is `t(key).replace('{message}', message)`, so a `t` that+// returns the bare key silently DROPS the message — which is why the existing+// suite asserts on keys alone. Returning a real template is what makes the+// `String(err)` arm observable at all.+const stableI18n = { t: (k: string) => `${k}: {message}` };+vi.mock('../../../lib/i18n/I18nContext', () => ({ useT: () => stableI18n }));++vi.mock('../hooks/useSettingsNavigation', () => ({+ useSettingsNavigation: () => ({ navigateBack: vi.fn(), breadcrumbs: [] }),+}));++const noopDispatch = vi.fn();+vi.mock('../../../store/hooks', () => ({+ useAppDispatch: () => noopDispatch,+ useAppSelector: () => [],+}));++vi.mock('./cron/CronJobFormModal', () => ({+ default: ({ open }: { open: boolean }) => (open ? <div data-testid="cron-modal" /> : null),+}));++const cronAddMock = vi.fn();+const cronListMock = vi.fn();+const cronUpdateMock = vi.fn();+const cronRemoveMock = vi.fn();+const cronRunMock = vi.fn();+const cronRunsMock = vi.fn();++vi.mock('../../../utils/tauriCommands', () => ({+ openhumanCronAdd: (...args: unknown[]) => cronAddMock(...args),+ openhumanCronList: () => cronListMock(),+ openhumanCronUpdate: (...args: unknown[]) => cronUpdateMock(...args),+ openhumanCronRemove: (...args: unknown[]) => cronRemoveMock(...args),+ openhumanCronRun: (...args: unknown[]) => cronRunMock(...args),+ openhumanCronRuns: (...args: unknown[]) => cronRunsMock(...args),+}));++function job(over: Record<string, unknown> = {}) {+ return {+ id: 'job-1',+ expression: '*/30 * * * *',+ schedule: { kind: 'cron', expr: '*/30 * * * *' },+ command: '',+ name: 'Daily Briefing',+ job_type: 'agent',+ session_target: 'isolated',+ enabled: true,+ delivery: { mode: 'proactive', best_effort: true },+ delete_after_run: false,+ created_at: '2026-05-01T00:00:00.000Z',+ next_run: '2026-06-01T09:00:00.000Z',+ prompt: 'Summarise the news',+ ...over,+ };+}++async function importPanel() {+ vi.resetModules();+ const mod = await import('./CronJobsPanel');+ return mod.default;+}++beforeEach(() => {+ [cronListMock, cronAddMock, cronUpdateMock, cronRemoveMock, cronRunMock, cronRunsMock].forEach(+ fn => fn.mockReset()+ );+ cronListMock.mockResolvedValue({ result: [job()] });+ cronAddMock.mockResolvedValue({ result: job({ id: 'job-new' }) });+ cronUpdateMock.mockResolvedValue({ result: job() });+ cronRemoveMock.mockResolvedValue({ result: { job_id: 'job-1', removed: true } });+ cronRunMock.mockResolvedValue({ result: {} });+ cronRunsMock.mockResolvedValue({ result: [] });+});++describe('CronJobsPanel — next_run ordering', () => {+ /** Read the rendered job names in DOM order. */+ function renderedNames(names: string[]): string[] {+ return names.filter(n => screen.queryByText(n) !== null);+ }++ it('renders jobs soonest-first regardless of the order the core returned', async () => {+ cronListMock.mockResolvedValue({+ result: [+ job({ id: 'c', name: 'Latest', next_run: '2026-06-03T09:00:00.000Z' }),+ job({ id: 'a', name: 'Soonest', next_run: '2026-06-01T09:00:00.000Z' }),+ job({ id: 'b', name: 'Middle', next_run: '2026-06-02T09:00:00.000Z' }),+ ],+ });+ const Panel = await importPanel();+ render(<Panel />);+ await waitFor(() => expect(screen.getByText('Soonest')).toBeInTheDocument());++ const body = document.body.textContent ?? '';+ expect(body.indexOf('Soonest')).toBeLessThan(body.indexOf('Middle'));+ expect(body.indexOf('Middle')).toBeLessThan(body.indexOf('Latest'));+ expect(renderedNames(['Soonest', 'Middle', 'Latest'])).toHaveLength(3);+ });++ it('keeps the already-sorted case sorted', async () => {+ cronListMock.mockResolvedValue({+ result: [+ job({ id: 'a', name: 'First', next_run: '2026-06-01T00:00:00.000Z' }),+ job({ id: 'b', name: 'Second', next_run: '2026-06-02T00:00:00.000Z' }),+ ],+ });+ const Panel = await importPanel();+ render(<Panel />);+ await waitFor(() => expect(screen.getByText('First')).toBeInTheDocument());++ const body = document.body.textContent ?? '';+ expect(body.indexOf('First')).toBeLessThan(body.indexOf('Second'));+ });++ it('does not drop a job whose next_run is unparseable', async () => {+ // `new Date('not-a-date').getTime()` is NaN, so the comparator returns NaN+ // for that pair. The row must still render — a schedule vanishing from the+ // list because the core sent an odd timestamp would be silent data loss.+ cronListMock.mockResolvedValue({+ result: [+ job({ id: 'a', name: 'Valid', next_run: '2026-06-01T00:00:00.000Z' }),+ job({ id: 'b', name: 'Unparseable', next_run: 'not-a-date' }),+ ],+ });+ const Panel = await importPanel();+ render(<Panel />);+ await waitFor(() => expect(screen.getByText('Valid')).toBeInTheDocument());+ expect(screen.getByText('Unparseable')).toBeInTheDocument();+ });+});++describe('CronJobsPanel — rejections that are not Error instances', () => {+ /**+ * The core's JSON-RPC client rejects with a plain string on some paths. Each+ * handler formats it through `err instanceof Error ? err.message : String(err)`;+ * the `String(err)` arm is what these cover.+ */+ it('renders a string rejection from the list call', async () => {+ cronListMock.mockRejectedValue('core unreachable');+ const Panel = await importPanel();+ render(<Panel />);+ expect(await screen.findByText(/core unreachable/)).toBeInTheDocument();+ });++ it('stringifies a non-Error object rejection rather than showing an empty error', async () => {+ cronListMock.mockRejectedValue({ code: -32000 });+ const Panel = await importPanel();+ render(<Panel />);+ // `String({})` is "[object Object]"; this pins that the panel stringifies+ // the rejection rather than swallowing it into an empty error row.+ expect(await screen.findByText(/\[object Object\]/)).toBeInTheDocument();+ });++ it('renders a string rejection from the toggle call', async () => {+ cronUpdateMock.mockRejectedValue('toggle refused');+ const Panel = await importPanel();+ render(<Panel />);+ await waitFor(() => expect(screen.getByText('Daily Briefing')).toBeInTheDocument());++ fireEvent.click(await screen.findByTestId('cron-job-toggle-job-1'));+ expect(await screen.findByText(/toggle refused/)).toBeInTheDocument();+ });+});diff --git a/app/src/components/settings/panels/__tests__/AboutPanel.states.test.tsx b/app/src/components/settings/panels/__tests__/AboutPanel.states.test.tsxnew file mode 100644index 0000000000..d978a89873--- /dev/null+++ b/app/src/components/settings/panels/__tests__/AboutPanel.states.test.tsx@@ -0,0 +1,276 @@+import { fireEvent, screen, waitFor } from '@testing-library/react';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { renderWithProviders } from '../../../../test/test-utils';+import type { AppUpdateInfo } from '../../../../utils/tauriCommands/core';+import AboutPanel from '../AboutPanel';++/**+ * `AboutPanel` was the weakest panel in my area by branch coverage — 52.1%+ * branches / 66.7% lines. The existing `AboutPanel.test.tsx` drives the real+ * `useAppUpdate` hook through the `app-update:status` event and reaches three of+ * its nine phases (ready_to_install, up_to_date, error).+ *+ * What is left uncovered is everything the panel *renders from* that hook and+ * from Redux:+ *+ * - `summaryFor` (panel :168-197) — nine phases plus the two+ * `available_version ? … : …NoVersion` forks. A phase falling through to the+ * default arm shows a user "checking for updates" copy forever.+ * - `formatRelative` (:199-207) — four buckets for the "last checked" line.+ * - the `rpcUrl` effect (:38-58) — cloud / non-Tauri / Tauri-resolved /+ * Tauri-rejected, each producing a different Connection readout.+ * - the connection-mode and helper-text ternaries (:107-131).+ *+ * The update hook is mocked here rather than driven through nine event+ * transitions: the subject is the panel's rendering of a phase, not the hook's+ * own state machine, which its own tests cover.+ */++const hoisted = vi.hoisted(() => ({+ updateState: {+ phase: 'idle' as string,+ info: null as AppUpdateInfo | null,+ error: null as string | null,+ check: vi.fn(async () => null as AppUpdateInfo | null),+ },+ mockInvoke: vi.fn(async () => 'http://127.0.0.1:1234'),+ mockIsTauriEnvironment: vi.fn(() => true),+ mockOpenUrl: vi.fn(),+}));++vi.mock('../../../../hooks/useAppUpdate', () => ({+ useAppUpdate: () => ({+ phase: hoisted.updateState.phase,+ info: hoisted.updateState.info,+ error: hoisted.updateState.error,+ check: hoisted.updateState.check,+ bytesDownloaded: 0,+ totalBytes: null,+ download: vi.fn(),+ install: vi.fn(),+ apply: vi.fn(),+ reset: vi.fn(),+ }),+}));++vi.mock('@tauri-apps/api/core', () => ({+ invoke: (...args: unknown[]) => hoisted.mockInvoke(...(args as [])),+ isTauri: () => true,+}));++vi.mock('../../../../utils/configPersistence', async importOriginal => {+ const original = await importOriginal<typeof import('../../../../utils/configPersistence')>();+ return { ...original, isTauriEnvironment: hoisted.mockIsTauriEnvironment };+});++vi.mock('../../../../utils/openUrl', () => ({ openUrl: hoisted.mockOpenUrl }));++// Not the subject here; both render their own surfaces and have their own tests.+vi.mock('../SystemDiagnostics', () => ({ default: () => <div data-testid="sys-diag" /> }));+vi.mock('../../../../features/star/GitHubStarCard', () => ({+ GitHubStarCard: () => <div data-testid="star-card" />,+}));++const info = (over: Partial<AppUpdateInfo> = {}): AppUpdateInfo => ({+ current_version: '1.0.0',+ available: true,+ available_version: '2.0.0',+ body: null,+ ...over,+});++function setUpdate(phase: string, over: Partial<typeof hoisted.updateState> = {}) {+ hoisted.updateState.phase = phase;+ hoisted.updateState.info = over.info ?? null;+ hoisted.updateState.error = over.error ?? null;+}++/** Render with a chosen coreMode slice. */+function renderAbout(coreMode: Record<string, unknown> = { kind: 'local' }) {+ return renderWithProviders(<AboutPanel />, { preloadedState: { coreMode: { mode: coreMode } } });+}++beforeEach(() => {+ vi.clearAllMocks();+ setUpdate('idle');+ hoisted.updateState.check = vi.fn(async () => null);+ hoisted.mockInvoke.mockResolvedValue('http://127.0.0.1:1234');+ hoisted.mockIsTauriEnvironment.mockReturnValue(true);+});++afterEach(() => {+ vi.useRealTimers();+});++describe('AboutPanel — update summary per phase', () => {+ it('renders a distinct summary for every phase, with none falling through', async () => {+ // The strong assertion is the set: nine phases must produce nine different+ // strings. A phase that fell through to the default arm would collide with+ // `idle` and shrink the set.+ const phases = [+ 'idle',+ 'checking',+ 'available',+ 'downloading',+ 'ready_to_install',+ 'installing',+ 'restarting',+ 'up_to_date',+ 'error',+ ];+ const seen = new Set<string>();++ for (const phase of phases) {+ setUpdate(phase, { info: info(), error: phase === 'error' ? 'boom' : null });+ const { unmount } = renderAbout();+ await screen.findAllByText(/software updates/i);+ seen.add(document.body.textContent ?? '');+ unmount();+ }+ expect(seen.size).toBe(phases.length);+ });++ it('names the version in the available summary when one is known', async () => {+ // `available: false` suppresses the version banner, so a match here can+ // only have come from the summary's own interpolation.+ setUpdate('available', { info: info({ available: false, available_version: '9.9.9' }) });+ renderAbout();+ expect(await screen.findByText(/9\.9\.9/)).toBeInTheDocument();+ });++ it('falls back to the no-version copy when available_version is null', async () => {+ setUpdate('available', { info: info({ available_version: null }) });+ renderAbout();+ // The version-bearing string must not appear anywhere.+ await screen.findAllByText(/software updates/i);+ expect(screen.queryByText(/9\.9\.9/)).not.toBeInTheDocument();+ });++ it('names the version in the ready-to-install summary', async () => {+ setUpdate('ready_to_install', { info: info({ available: false, available_version: '3.2.1' }) });+ renderAbout();+ expect(await screen.findByText(/3\.2\.1/)).toBeInTheDocument();+ });++ it('surfaces the hook error verbatim when the phase is error', async () => {+ setUpdate('error', { error: 'updater endpoint unreachable' });+ renderAbout();+ expect(await screen.findByText(/updater endpoint unreachable/)).toBeInTheDocument();+ });++ it('disables the check button only while checking', async () => {+ setUpdate('checking');+ const { unmount } = renderAbout();+ await waitFor(() => expect(screen.getByRole('button', { name: /checking/i })).toBeDisabled());+ unmount();++ setUpdate('idle');+ renderAbout();+ await waitFor(() =>+ expect(screen.getByRole('button', { name: /check for updates/i })).not.toBeDisabled()+ );+ });++ it('shows the available-version banner beside the running version', async () => {+ setUpdate('available', { info: info({ available: true, available_version: '4.5.6' }) });+ renderAbout();+ // The banner is the element carrying the "is available" copy.+ expect(await screen.findByText(/v4\.5\.6\s+is available/)).toBeInTheDocument();+ });++ it('suppresses the banner on info.available alone, even with a version present', async () => {+ // A version string is present but `available` is false, so only the+ // `info?.available` half of the guard can hide the banner.+ setUpdate('up_to_date', { info: info({ available: false, available_version: '8.8.8' }) });+ renderAbout();+ await screen.findAllByText(/software updates/i);+ expect(screen.queryByText(/is available/i)).not.toBeInTheDocument();+ });+});++describe('AboutPanel — the last-checked line', () => {+ it('is absent until a check has returned a result', async () => {+ renderAbout();+ await screen.findAllByText(/software updates/i);+ expect(screen.queryByText(/last checked/i)).not.toBeInTheDocument();+ });++ it('appears after a check that returns a result', async () => {+ hoisted.updateState.check = vi.fn(async () => info());+ renderAbout();+ fireEvent.click(await screen.findByRole('button', { name: /check for updates/i }));+ expect(await screen.findByText(/last checked/i)).toBeInTheDocument();+ });++ it('stays absent when the check returns null', async () => {+ // `check` resolving null means the probe did not complete; stamping a time+ // would tell the user their build was verified when it was not.+ hoisted.updateState.check = vi.fn(async () => null);+ renderAbout();+ fireEvent.click(await screen.findByRole('button', { name: /check for updates/i }));+ await waitFor(() => expect(hoisted.updateState.check).toHaveBeenCalled());+ expect(screen.queryByText(/last checked/i)).not.toBeInTheDocument();+ });+});++describe('AboutPanel — connection readout', () => {+ it('shows the cloud URL straight from Redux without asking the shell', async () => {+ renderAbout({ kind: 'cloud', url: 'https://core.example.com' });+ expect(await screen.findByText('https://core.example.com')).toBeInTheDocument();+ // Cloud mode must not consult the Tauri command at all.+ expect(hoisted.mockInvoke).not.toHaveBeenCalled();+ });++ it('resolves the local URL from the shell command', async () => {+ hoisted.mockInvoke.mockResolvedValue('http://127.0.0.1:57321');+ renderAbout({ kind: 'local' });+ expect(await screen.findByText('http://127.0.0.1:57321')).toBeInTheDocument();+ expect(hoisted.mockInvoke).toHaveBeenCalledWith('core_rpc_url');+ });++ it('shows the unavailable placeholder outside a Tauri environment', async () => {+ hoisted.mockIsTauriEnvironment.mockReturnValue(false);+ renderAbout({ kind: 'local' });+ await waitFor(() => expect(screen.getByText(/server url/i)).toBeInTheDocument());+ expect(hoisted.mockInvoke).not.toHaveBeenCalled();+ expect(screen.queryByText(/^http/)).not.toBeInTheDocument();+ });++ it('shows the unavailable placeholder when the shell command rejects', async () => {+ hoisted.mockInvoke.mockRejectedValue(new Error('no such command'));+ renderAbout({ kind: 'local' });+ await waitFor(() => expect(hoisted.mockInvoke).toHaveBeenCalled());+ expect(screen.queryByText(/^http/)).not.toBeInTheDocument();+ });++ it('labels each connection mode distinctly', async () => {+ const seen = new Set<string>();+ for (const mode of [{ kind: 'local' }, { kind: 'cloud', url: 'u' }, { kind: 'unset' }]) {+ const { unmount } = renderAbout(mode);+ await screen.findAllByText(/software updates/i);+ seen.add(document.body.textContent ?? '');+ unmount();+ }+ expect(seen.size).toBe(3);+ });++ it('uses different helper copy for cloud and local', async () => {+ const { unmount } = renderAbout({ kind: 'cloud', url: 'u' });+ const cloudText = document.body.textContent ?? '';+ unmount();++ renderAbout({ kind: 'local' });+ const localText = document.body.textContent ?? '';+ expect(cloudText).not.toBe(localText);+ });+});++describe('AboutPanel — releases link', () => {+ it('opens the configured download URL rather than a hardcoded one', async () => {+ renderAbout();+ fireEvent.click(await screen.findByRole('button', { name: /releases/i }));+ expect(hoisted.mockOpenUrl).toHaveBeenCalledTimes(1);+ expect(String(hoisted.mockOpenUrl.mock.calls[0]?.[0])).toMatch(/^https?:\/\//);+ });+});