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(app): pin route auth guards and the iOS re-pairing escape hatch\n\nTwo more new specs, no existing file touched.\n\nAppRoutes.guards.test.tsx — which desktop routes require authentication and\nwhich deliberately do not. A route losing <ProtectedRoute> exposes its surface\nand its on-mount RPC to an unauthenticated session; a route gaining one locks\nout the OAuth callback that establishes the session in the first place. Both\nare one-line edits in a 260-line JSX table and nothing asserted either:\nauth-access-control.spec.ts covers the session lifecycle, never the per-route\nclassification, and the existing vitest specs mock the guards to passthroughs.\n\n Two layers. Render assertions for the routes this file owns, plus a\n source-level classifier over the WHOLE table so a route added or re-guarded\n anywhere fails here even when its page is another spec's business. The\n classifier separates `protected` from `protected-but-open`\n (`requireAuth={false}`) — the wrapper is still present, so the route reads as\n guarded in review while the check is off.\n\n It deliberately does NOT assert `requireAuth={true}` is spelled out:\n ProtectedRoute.tsx:18 defaults it to true, so that would fail on a harmless\n tidy-up and catch no real defect. Verified — dropping the prop from /invites\n changed no behaviour and correctly failed nothing.\n\nAppRoutesIOS.pairing.test.tsx — /pair must stay reachable from an ALREADY\nPAIRED phone. openhuman#5479 ("Cannot Pair iPhone") is a Rust wire-contract\nfailure and is not fixed here; what this protects is what turns it from "retry"\ninto "bricked". `isPaired()` is `listProfiles().length > 0` and never asks\nwhether the core answers, so a phone holding a profile for a desktop that is\ngone reads as paired — and is exactly the phone that must reach a QR scan.\nAppRoutesIOS.test.tsx covers /pair while UNPAIRED; the paired case regresses\nsilently. PairScreen's own behaviour is already covered by PairScreen.test.tsx\nand is not repeated.\n\nProven by reverting the behaviour each covers:\n - /rewards loses ProtectedRoute -> 3 fail\n - /callback/:kind gains ProtectedRoute -> 2 fail\n - /callback/:kind/:status deleted -> 3 fail\n - requireAuth={false} on /invites -> table names "protected-but-open"\n - requireAuth={false} on /rewards -> 2 fail\n - an unclassified route added -> table fails\n - /pair removed from the mobile table -> 4 of 5 fail\n - /pair wrapped in RequirePairing / MobileShell -> 2 / 1 fail\n - /chat/:threadId? loses its optional segment -> 1 fail\n
M3gA-Mind6aaef9213efc
diff --git a/app/src/AppRoutes.guards.test.tsx b/app/src/AppRoutes.guards.test.tsxnew file mode 100644index 0000000000..92238ae4dc--- /dev/null+++ b/app/src/AppRoutes.guards.test.tsx@@ -0,0 +1,236 @@+/**+ * Which desktop routes require authentication, and which deliberately do not.+ *+ * A route silently losing its `<ProtectedRoute>` wrapper exposes a surface — and+ * the RPC calls it makes on mount — to an unauthenticated session. A route+ * gaining one locks out a flow that has to work signed-out: the OAuth callback+ * that *establishes* the session, and the push-to-talk overlay window.+ * Both directions are one-line edits in a 260-line JSX table, and nothing+ * asserted either.+ *+ * `test/playwright/specs/auth-access-control.spec.ts` covers the session+ * *lifecycle* (sign-in, logout, expiry) with a booted authenticated page; it+ * never varies the guard on a route. This is the complementary half: the+ * classification itself.+ *+ * Two layers, deliberately:+ * 1. Render assertions for the routes this file owns — the page renders AND+ * the expected guard wrapped it.+ * 2. A source-level classification guard over the WHOLE route table, so a+ * route added or re-guarded anywhere in `AppRoutes.tsx` fails here even+ * though its page is another spec's business.+ */+import { render, screen } from '@testing-library/react';+import type React from 'react';+import { MemoryRouter, useParams } from 'react-router-dom';+import { describe, expect, it, vi } from 'vitest';++vi.mock('./lib/platform', () => ({ getIsMobile: () => false }));++// The guards are replaced by markers that record that they wrapped something,+// rather than being stubbed away as passthroughs. That is the whole point here.+vi.mock('./components/PublicRoute', () => ({+ default: ({ children }: { children: React.ReactNode }) => (+ <div data-testid="guard-public">{children}</div>+ ),+}));+vi.mock('./components/ProtectedRoute', () => ({+ default: ({ children, requireAuth }: { children: React.ReactNode; requireAuth?: boolean }) => (+ <div data-testid="guard-protected" data-require-auth={String(requireAuth)}>+ {children}+ </div>+ ),+}));+vi.mock('./components/DefaultRedirect', () => ({+ default: () => <div data-testid="default-redirect" />,+}));++// Echo the route params so the `:kind` / `:status` plumbing is observable.+vi.mock('./pages/WebCallbackPage', () => {+ const WebCallbackProbe = ({ callbackKind }: { callbackKind?: string }) => {+ const { kind, status } = useParams();+ return (+ <div data-testid="page-web-callback">+ <span data-testid="callback-kind">{callbackKind ?? kind ?? ''}</span>+ <span data-testid="callback-status">{status ?? ''}</span>+ </div>+ );+ };+ return { default: WebCallbackProbe };+});++vi.mock('./AppRoutesIOS', () => ({ default: () => <div /> }));+vi.mock('./features/human/HumanPage', () => ({ default: () => <div /> }));+vi.mock('./pages/Accounts', () => ({ default: () => <div /> }));+vi.mock('./pages/Brain', () => ({ default: () => <div /> }));+vi.mock('./pages/dev/AgentInsightsPreview', () => ({ default: () => <div /> }));+vi.mock('./pages/dev/UiGallery', () => ({ default: () => <div data-testid="page-ui-gallery" /> }));+vi.mock('./pages/Invites', () => ({ default: () => <div data-testid="page-invites" /> }));+vi.mock('./pages/Notifications', () => ({+ default: () => <div data-testid="page-notifications" />,+}));+vi.mock('./pages/onboarding/Onboarding', () => ({+ default: () => <div data-testid="page-onboarding" />,+}));+vi.mock('./pages/PttOverlayPage', () => ({+ PttOverlayPage: () => <div data-testid="page-ptt-overlay" />,+}));+vi.mock('./pages/Rewards', () => ({ default: () => <div data-testid="page-rewards" /> }));+vi.mock('./pages/Settings', () => ({ default: () => <div /> }));+vi.mock('./pages/Skills', () => ({ default: () => <div /> }));+vi.mock('./pages/Welcome', () => ({ default: () => <div data-testid="page-welcome" /> }));+vi.mock('./pages/WorkflowsRun', () => ({ default: () => <div /> }));++const AppRoutes = (await import('./AppRoutes')).default;++function visit(entry: string) {+ render(+ <MemoryRouter initialEntries={[entry]}>+ <AppRoutes />+ </MemoryRouter>+ );+}++type Guard = 'protected' | 'public' | 'none';+/** `protected-but-open` = wrapped in ProtectedRoute but with the check disabled. */+type TableGuard = Guard | 'redirect' | 'protected-but-open';++/** The route, the page it must render, and the guard that must wrap it. */+const OWNED: Array<{ path: string; page: string; guard: Guard }> = [+ { path: '/', page: 'page-welcome', guard: 'public' },+ { path: '/onboarding/profile', page: 'page-onboarding', guard: 'protected' },+ { path: '/invites', page: 'page-invites', guard: 'protected' },+ { path: '/notifications', page: 'page-notifications', guard: 'protected' },+ { path: '/rewards', page: 'page-rewards', guard: 'protected' },+ { path: '/ptt-overlay', page: 'page-ptt-overlay', guard: 'none' },+ { path: '/dev/ui', page: 'page-ui-gallery', guard: 'none' },+];++describe('AppRoutes — each route renders its page behind the right guard', () => {+ for (const { path, page, guard } of OWNED) {+ it(`${path} renders ${page} with guard=${guard}`, () => {+ visit(path);++ expect(screen.getByTestId(page)).toBeInTheDocument();+ // The catch-all must not have swallowed the route.+ expect(screen.queryByTestId('default-redirect')).not.toBeInTheDocument();++ expect(!!screen.queryByTestId('guard-protected')).toBe(guard === 'protected');+ expect(!!screen.queryByTestId('guard-public')).toBe(guard === 'public');+ });+ }++ it('never disables the check on a route it wraps', () => {+ // `requireAuth` DEFAULTS to true (ProtectedRoute.tsx:18), so omitting it is+ // harmless and this deliberately does not assert the prop is spelled out —+ // that would fail on a harmless tidy-up and catch no real defect. What is+ // dangerous is `requireAuth={false}`: the wrapper is still there, so the+ // route reads as protected in review while the check is off. The route+ // table below classifies that separately, so it cannot pass unnoticed.+ visit('/rewards');+ expect(screen.getByTestId('guard-protected')).not.toHaveAttribute('data-require-auth', 'false');+ });+});++describe('AppRoutes — the OAuth callback family is reachable signed-out', () => {+ // These routes ESTABLISH the session. Wrapping them in ProtectedRoute would+ // make sign-in impossible while every signed-in test still passed.+ it('/auth is unguarded and pins its kind from the prop', () => {+ visit('/auth?token=jwt');++ expect(screen.getByTestId('callback-kind')).toHaveTextContent('auth');+ expect(screen.queryByTestId('guard-protected')).not.toBeInTheDocument();+ expect(screen.queryByTestId('guard-public')).not.toBeInTheDocument();+ });++ it('/callback/:kind takes its kind from the path', () => {+ visit('/callback/composio');++ expect(screen.getByTestId('callback-kind')).toHaveTextContent('composio');+ expect(screen.getByTestId('callback-status')).toBeEmptyDOMElement();+ expect(screen.queryByTestId('guard-protected')).not.toBeInTheDocument();+ });++ it('/callback/:kind/:status carries both segments', () => {+ // The two-segment form is a distinct <Route>. A provider redirecting to+ // `/callback/gmail/success` must not fall through to the catch-all.+ visit('/callback/gmail/success');++ expect(screen.getByTestId('callback-kind')).toHaveTextContent('gmail');+ expect(screen.getByTestId('callback-status')).toHaveTextContent('success');+ expect(screen.queryByTestId('default-redirect')).not.toBeInTheDocument();+ });++ it('routes a failure status to the same handler rather than the catch-all', () => {+ visit('/callback/gmail/error');++ expect(screen.getByTestId('callback-status')).toHaveTextContent('error');+ expect(screen.queryByTestId('default-redirect')).not.toBeInTheDocument();+ });+});++describe('AppRoutes — the whole route table stays classified', () => {+ // Source-level, so it covers routes whose pages are other specs' business.+ // A new route, or a changed guard on any existing one, fails here.+ const EXPECTED: Record<string, TableGuard> = {+ '/': 'public',+ '/auth': 'none',+ '/callback/:kind': 'none',+ '/callback/:kind/:status': 'none',+ '/onboarding/*': 'protected',+ '/home': 'redirect',+ '/human': 'protected',+ '/brain': 'protected',+ '/flows': 'protected',+ '/flows/draft': 'protected',+ '/flows/:id': 'protected',+ '/activity': 'redirect',+ '/intelligence': 'redirect',+ '/workflows/run': 'protected',+ '/connections': 'protected',+ '/skills': 'redirect',+ '/chat/:threadId?': 'protected',+ '/accounts': 'redirect',+ '/channels': 'redirect',+ '/invites': 'protected',+ '/feedback': 'redirect',+ '/notifications': 'protected',+ '/routines': 'redirect',+ '/rewards': 'protected',+ '/workflows': 'protected',+ '/webhooks': 'redirect',+ '/settings/*': 'protected',+ '/ptt-overlay': 'none',+ '/dev/agent-insights': 'none',+ '/dev/ui': 'none',+ '/dev/assistant-ui': 'none',+ '*': 'none',+ };++ function classifyRouteTable(): Record<string, TableGuard> {+ const fs = require('node:fs') as typeof import('node:fs');+ const path = require('node:path') as typeof import('node:path');+ const source = fs.readFileSync(path.resolve('src/AppRoutes.tsx'), 'utf8');++ const out: Record<string, TableGuard> = {};+ // Each `<Route path="X"` up to the start of the next one is that route's body.+ const starts = [...source.matchAll(/<Route\s+path="([^"]+)"/g)];+ starts.forEach((match, index) => {+ const from = match.index ?? 0;+ const to =+ index + 1 < starts.length ? (starts[index + 1].index ?? source.length) : source.length;+ const body = source.slice(from, to);+ if (/<Navigate\b/.test(body)) out[match[1]] = 'redirect';+ else if (/<ProtectedRoute\b[^>]*requireAuth=\{false\}/.test(body))+ out[match[1]] = 'protected-but-open';+ else if (/<ProtectedRoute\b/.test(body)) out[match[1]] = 'protected';+ else if (/<PublicRoute\b/.test(body)) out[match[1]] = 'public';+ else out[match[1]] = 'none';+ });+ return out;+ }++ it('every route carries the guard this table expects', () => {+ expect(classifyRouteTable()).toEqual(EXPECTED);+ });+});diff --git a/app/src/AppRoutesIOS.pairing.test.tsx b/app/src/AppRoutesIOS.pairing.test.tsxnew file mode 100644index 0000000000..f36f33ce3d--- /dev/null+++ b/app/src/AppRoutesIOS.pairing.test.tsx@@ -0,0 +1,119 @@+/**+ * `/pair` must stay reachable — including from an already-paired phone.+ *+ * openhuman#5479 ("Cannot Pair iPhone") is a wire-contract failure on the+ * desktop side: `[devices/tunnel] parse tunnel:register ack failed: missing+ * field 'channelId'`. Nothing in this file can fix that — it is Rust, in+ * `src/openhuman/security/devices/tunnel_client.rs`. What this file protects is+ * the thing that turns that bug from "retry it" into "the phone is bricked":+ * the route that lets a user pair again.+ *+ * `/pair` is the ONLY mobile route not wrapped in `RequirePairing`+ * (`AppRoutesIOS.tsx:57`). That is deliberate and load-bearing — a phone whose+ * saved profile points at a core it can no longer reach is "paired" as far as+ * `isPaired()` is concerned (`listProfiles().length > 0`), so wrapping `/pair`+ * or letting the catch-all swallow it would strand exactly the user who most+ * needs to re-pair. `AppRoutesIOS.test.tsx` covers `/pair` while UNPAIRED; this+ * covers the paired case, which is the one that regresses silently.+ *+ * The pairing screen's own behaviour (QR happy path, expiry, bad URL, missing+ * fields, transport unhealthy, camera errors, retry) is already covered by+ * `pages/ios/PairScreen.test.tsx`. Not repeated here.+ */+import { render, screen } from '@testing-library/react';+import { MemoryRouter } from 'react-router-dom';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('./features/human/HumanPage', () => ({+ default: () => <div data-testid="page-human">human</div>,+}));+vi.mock('./pages/Accounts', () => ({ default: () => <div data-testid="page-chat">chat</div> }));+vi.mock('./pages/Settings', () => ({+ default: () => <div data-testid="page-settings">settings</div>,+}));+vi.mock('./pages/ios/PairScreen', () => ({+ PairScreen: () => <div data-testid="page-pair">pair</div>,+}));+vi.mock('./components/ios/MobileTabBar', () => ({+ default: () => <nav data-testid="mobile-tab-bar">tabs</nav>,+}));++const listProfiles = vi.fn();+vi.mock('./services/transport/profileStore', () => ({ listProfiles: () => listProfiles() }));++const AppRoutesIOS = (await import('./AppRoutesIOS')).default;++const renderAt = (path: string) =>+ render(+ <MemoryRouter initialEntries={[path]}>+ <AppRoutesIOS />+ </MemoryRouter>+ );++/** A saved profile is all `isPaired()` looks at — not whether the core answers. */+const SAVED_PROFILE = [{ id: 'profile-1', label: 'Desk' }];++describe('AppRoutesIOS — re-pairing escape hatch', () => {+ beforeEach(() => listProfiles.mockReset());+ afterEach(() => vi.clearAllMocks());++ it('serves /pair to an already-paired phone rather than bouncing it to /human', () => {+ listProfiles.mockReturnValue(SAVED_PROFILE);++ renderAt('/pair');++ expect(screen.getByTestId('page-pair')).toBeInTheDocument();+ expect(screen.queryByTestId('page-human')).not.toBeInTheDocument();+ });++ it('still serves /pair when the saved profile is stale or broken', () => {+ // `isPaired()` is `listProfiles().length > 0` (AppRoutesIOS.tsx:29) — it+ // never asks whether the core is reachable. A phone holding a profile for a+ // desktop that is gone is indistinguishable from a healthy one here, and it+ // is precisely the phone that must be able to re-scan a QR code.+ listProfiles.mockReturnValue([{ id: 'dead-core', label: 'Old laptop' }]);++ renderAt('/pair');++ expect(screen.getByTestId('page-pair')).toBeInTheDocument();+ });++ it('shows no tab bar on /pair, paired or not', () => {+ // The tab bar navigates to paired-only surfaces. Rendering it over the+ // pairing screen offers exits that bounce straight back to /pair.+ for (const profiles of [[], SAVED_PROFILE]) {+ listProfiles.mockReturnValue(profiles);+ const { unmount } = renderAt('/pair');+ expect(screen.getByTestId('page-pair')).toBeInTheDocument();+ expect(screen.queryByTestId('mobile-tab-bar')).not.toBeInTheDocument();+ unmount();+ }+ });+});++describe('AppRoutesIOS — deep links a paired phone must honour', () => {+ beforeEach(() => listProfiles.mockReset());+ afterEach(() => vi.clearAllMocks());++ it('opens a specific thread at /chat/:threadId', () => {+ // The bare /chat form is covered by AppRoutesIOS.test.tsx; the optional+ // `:threadId` segment is what a notification deep link actually carries,+ // and a mismatch there lands the user on the catch-all instead.+ listProfiles.mockReturnValue(SAVED_PROFILE);++ renderAt('/chat/thread-abc');++ expect(screen.getByTestId('page-chat')).toBeInTheDocument();+ expect(screen.getByTestId('mobile-tab-bar')).toBeInTheDocument();+ expect(screen.queryByTestId('page-human')).not.toBeInTheDocument();+ });++ it('bounces a thread deep link to /pair when the phone is unpaired', () => {+ listProfiles.mockReturnValue([]);++ renderAt('/chat/thread-abc');++ expect(screen.getByTestId('page-pair')).toBeInTheDocument();+ expect(screen.queryByTestId('page-chat')).not.toBeInTheDocument();+ });+});