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: keep Shell session controls reachable on phones (#9710)

Adam Eivyea024692ad1d
diff --git a/client/src/pages/Shell.browser.test.js b/client/src/pages/Shell.browser.test.js
new file mode 100644
index 0000000000..774eb23ed0
--- /dev/null
+++ b/client/src/pages/Shell.browser.test.js
@@ -0,0 +1,189 @@
+// @vitest-environment node
+import { afterAll, beforeAll, describe, expect, it } from 'vitest';
+import { existsSync } from 'node:fs';
+import { mkdtemp, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { createServer } from 'vite';
+import react from '@vitejs/plugin-react';
+import { chromium } from 'playwright-core';
+
+const chrome = [process.env.CHROME_PATH, chromium.executablePath(),
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
+ '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',
+].find(path => path && existsSync(path));
+
+// Render the actual page, toolbars and Tailwind stylesheet inside Layout's
+// clipped full-width main. Only transport/session hooks and APIs are replaced:
+// this fixture cannot connect to a real shell or invoke a host-control action.
+describe.skipIf(!chrome)('Shell header reachability (#9710)', () => {
+ let server;
+ let browser;
+ let browserTemp;
+ let origin;
+ beforeAll(async () => {
+ browserTemp = await mkdtemp(join(tmpdir(), 'shell-header-chrome-'));
+ server = await createServer({
+ configFile: false,
+ cacheDir: join(browserTemp, 'vite-cache'),
+ root: fileURLToPath(new URL('../..', import.meta.url)),
+ plugins: [react(), {
+ name: 'shell-browser-fixture',
+ enforce: 'pre',
+ resolveId(id) {
+ if (id === '/shell-fixture.jsx') return '\0shell-fixture.jsx';
+ if (/\/hooks\/useShellSession(?:\.js)?$/.test(id)) return '\0shell-session';
+ if (/\/hooks\/useItermSession(?:\.js)?$/.test(id)) return '\0iterm-session';
+ if (/\/hooks\/useInstanceFeatures(?:\.js)?$/.test(id)) return '\0shell-features';
+ if (/\/services\/api(?:\.js)?$/.test(id)) return '\0shell-api';
+ },
+ load(id) {
+ if (id === '\0shell-api') return 'export const getApps = async () => [];';
+ if (id === '\0iterm-session') return 'export const useItermSession = () => { throw new Error("Unexpected iTerm connection"); };';
+ if (id === '\0shell-features') return `
+ export const useInstanceFeatures = () => ({
+ isFeatureEnabled: id => id === 'iterm' && new URLSearchParams(location.search).get('iterm') === 'true'
+ });
+ `;
+ if (id === '\0shell-session') return `
+ const params = new URLSearchParams(location.search);
+ const live = params.get('live') === 'true';
+ const badge = params.get('badge') === 'true';
+ const forbidden = () => { throw new Error('Host controls must not be invoked by geometry validation'); };
+ export const MAX_SESSIONS = 20;
+ export const useShellSession = () => ({
+ terminalRef: { current: null }, connected: true, isLiveRun: live,
+ interactiveCount: live ? 0 : 1, liveRunCount: badge ? 1 : 0,
+ activeSessionId: 'example-session',
+ sessions: [{ sessionId: 'example-session', label: 'Example session', external: live, createdAt: 0 }],
+ restartSession: forbidden, stopSession: forbidden, startNewSession: forbidden,
+ switchToSession: forbidden, killOtherSession: forbidden,
+ });
+ `;
+ if (id !== '\0shell-fixture.jsx') return;
+ return `
+ import React from 'react';
+ import { createRoot } from 'react-dom/client';
+ import { MemoryRouter } from 'react-router';
+ import Shell from '/src/pages/Shell.jsx';
+ import '/src/index.css';
+ createRoot(document.getElementById('root')).render(
+ React.createElement(MemoryRouter, { initialEntries: ['/shell/example-session'] },
+ React.createElement('div', { className: 'h-dvh flex flex-col overflow-x-hidden' },
+ React.createElement('div', { className: 'h-14 shrink-0' }, 'Example app header'),
+ React.createElement('main', { id: 'main-content', className: 'relative overflow-hidden flex-1 min-h-0' },
+ React.createElement(Shell))))
+ );
+ `;
+ },
+ configureServer(vite) {
+ vite.middlewares.use('/shell-test', async (_req, res) => {
+ res.setHeader('Content-Type', 'text/html');
+ res.end(await vite.transformIndexHtml('/shell-test',
+ '<div id="root"></div><script type="module" src="/shell-fixture.jsx"></script>'));
+ });
+ },
+ }],
+ server: { host: '127.0.0.1', port: 0 },
+ });
+ await server.listen();
+ origin = server.resolvedUrls.local[0];
+ browser = await chromium.launch({ executablePath: chrome, headless: true, args: ['--mute-audio'],
+ env: { ...process.env, TMPDIR: browserTemp, TMP: browserTemp, TEMP: browserTemp },
+ });
+ }, 60000);
+ afterAll(async () => {
+ try {
+ await browser?.close();
+ } finally {
+ await server?.close();
+ if (browserTemp) await rm(browserTemp, { recursive: true, force: true });
+ }
+ });
+
+ // The selected ordinary shell and the presence of OTHER live runs are
+ // independent. A selected live run necessarily contributes its own badge.
+ const states = [true, false].flatMap(iterm => [
+ { iterm, live: false, badge: true },
+ { iterm, live: false, badge: false },
+ { iterm, live: true, badge: true },
+ ]);
+ it.each([
+ { width: 360, height: 800 }, { width: 390, height: 844 },
+ { width: 768, height: 1024 }, { width: 1440, height: 900 },
+ ])('keeps applicable controls hit-testable at $width x $height', async viewport => {
+ const page = await browser.newPage({ viewport, hasTouch: viewport.width < 640 });
+ try {
+ const errors = [];
+ const unexpectedRequests = [];
+ page.on('pageerror', error => errors.push(error.message));
+ await page.route('**/*', route => {
+ const url = new URL(route.request().url());
+ if (url.origin !== new URL(origin).origin || /^\/(api|socket\.io)(\/|$)/.test(url.pathname)) {
+ unexpectedRequests.push(url.pathname);
+ return route.abort();
+ }
+ return route.continue();
+ });
+ for (const state of states) {
+ await page.goto(`${origin}shell-test?${new URLSearchParams(state)}`);
+ const controls = page.getByRole('group', { name: 'Session controls' });
+ try {
+ await controls.waitFor({ timeout: 10000 });
+ } catch (error) {
+ throw new Error(`Fixture did not render: ${errors.join('; ') || error.message}`, { cause: error });
+ }
+ expect(await controls.getByRole('button').allTextContents()).toEqual(
+ state.live ? ['Fullscreen', 'Stop', 'New'] : ['Fullscreen', 'Restart', 'Stop', 'New']);
+ const geometry = await controls.getByRole('button').evaluateAll(buttons => buttons.map(button => {
+ const r = button.getBoundingClientRect();
+ return { name: button.getAttribute('title'), left: r.left, right: r.right,
+ top: r.top, bottom: r.bottom, width: r.width, height: r.height,
+ hit: button.contains(document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2)) };
+ }));
+ for (const rect of geometry) {
+ expect(rect, JSON.stringify(state)).toMatchObject({ hit: true });
+ expect(rect.left).toBeGreaterThanOrEqual(0);
+ expect(rect.right).toBeLessThanOrEqual(viewport.width);
+ expect(rect.top).toBeGreaterThanOrEqual(0);
+ expect(rect.bottom).toBeLessThanOrEqual(viewport.height);
+ expect(rect.width).toBeGreaterThanOrEqual(44);
+ expect(rect.height).toBeGreaterThanOrEqual(44);
+ }
+ expect(await page.getByRole('tablist', { name: 'Terminal source' }).count()).toBe(state.iterm ? 1 : 0);
+ expect(await page.getByRole('button', { name: 'About live TUI runs' }).count()).toBe(state.badge ? 1 : 0);
+ if (state.badge) {
+ const help = page.getByRole('button', { name: 'About live TUI runs' });
+ const helpGeometry = await help.evaluate(el => {
+ const r = el.getBoundingClientRect();
+ return { width: r.width, height: r.height,
+ hit: el.contains(document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2)) };
+ });
+ expect(helpGeometry).toMatchObject({ hit: true, width: 44, height: 44 });
+ }
+ const layout = await page.locator('#main-content').evaluate(main => {
+ const shell = main.firstElementChild;
+ const header = shell.firstElementChild;
+ const terminal = shell.querySelector('.flex-1.bg-port-bg');
+ return { mainOverflow: main.scrollWidth - main.clientWidth,
+ pageOverflow: document.documentElement.scrollWidth - innerWidth,
+ headerOverflow: header.scrollWidth - header.clientWidth,
+ terminalHeight: terminal.getBoundingClientRect().height,
+ headerHeight: header.getBoundingClientRect().height };
+ });
+ expect(layout.mainOverflow).toBeLessThanOrEqual(0);
+ expect(layout.pageOverflow).toBeLessThanOrEqual(0);
+ expect(layout.headerOverflow).toBeLessThanOrEqual(0);
+ expect(layout.terminalHeight).toBeGreaterThan(300);
+ // Tablet metadata can wrap when the complete conditional header is wider
+ // than its container. Desktop keeps one row, allowing font rounding.
+ if (viewport.width >= 1440) expect(layout.headerHeight).toBeLessThanOrEqual(48);
+ }
+ expect(errors).toEqual([]);
+ expect(unexpectedRequests).toEqual([]);
+ } finally {
+ await page.close();
+ }
+ }, 60000);
+});
diff --git a/client/src/pages/Shell.jsx b/client/src/pages/Shell.jsx
index d8a40342b5..0f3e5f9e10 100644
--- a/client/src/pages/Shell.jsx
+++ b/client/src/pages/Shell.jsx
@@ -144,19 +144,14 @@ function PortosShellView() {
className={isFullscreen
? 'fixed inset-0 z-[70] flex flex-col bg-port-bg p-2'
// Deliberately tighter than the app-wide `p-4 md:p-6` mobile gutter: every
- // pixel here is a terminal row/column, and the chrome above it is already
- // compressed to three fixed rows. `gap` (not per-child `mb-*`) owns the
+ // pixel here is a terminal row/column. `gap` (not per-child `mb-*`) owns the
// vertical rhythm so the tab strip doesn't bake page spacing into itself.
: 'h-full flex flex-col gap-2 md:gap-3 p-2 md:p-6'}>
{/* Header (hidden in fullscreen — the compact bottom bar takes over) */}
{!isFullscreen && (
- // Single non-wrapping row on mobile: the status pill collapses to a bare dot
- // and the session count drops out, so the action buttons stay on the title
- // line instead of wrapping to a second row above the fold.
- <div className="flex items-center gap-2">
- {/* Everything else in this row is `shrink-0`, so the title is what absorbs
- an overflow — without it a narrow phone would push the row wider than
- the page and give the whole document a horizontal scrollbar. */}
+ // Phones give actions their own row. Metadata and actions can wrap
+ // independently; wider containers share a row whenever both groups fit.
+ <div className="flex flex-wrap items-center gap-2 min-w-0 shrink-0">
<h1 className="text-xl font-semibold text-white min-w-0 truncate">Shell</h1>
<ShellSourceSwitch source="portos" />
<div
@@ -189,11 +184,11 @@ function PortosShellView() {
</InfoTooltip>
</span>
)}
- <div className="flex items-center gap-2 ml-auto shrink-0">
+ <div role="group" aria-label="Session controls" className="flex flex-wrap items-center gap-2 w-full max-w-full sm:w-auto sm:ml-auto">
<button
onClick={() => setIsFullscreen(true)}
ref={toggleRef}
- className="flex items-center gap-1.5 px-2.5 py-2 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded-lg text-sm transition-colors border border-port-border min-h-[40px]"
+ className="flex items-center gap-1.5 px-2.5 py-2 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded-lg text-sm transition-colors border border-port-border min-h-[44px] min-w-[44px] shrink-0"
title="Fullscreen terminal"
aria-label="Fullscreen terminal"
>
@@ -204,7 +199,7 @@ function PortosShellView() {
{connected && !isLiveRun && (
<button
onClick={restartSession}
- className="flex items-center gap-1.5 px-2.5 py-2 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded-lg text-sm transition-colors border border-port-border min-h-[40px]"
+ className="flex items-center gap-1.5 px-2.5 py-2 bg-port-card hover:bg-port-border text-gray-300 hover:text-white rounded-lg text-sm transition-colors border border-port-border min-h-[44px] min-w-[44px] shrink-0"
title="Restart session (kill + new)"
>
<RefreshCw size={16} />
@@ -214,7 +209,7 @@ function PortosShellView() {
{connected && (
<button
onClick={stopSession}
- className="flex items-center gap-1.5 px-2.5 py-2 bg-port-error/20 hover:bg-port-error/30 text-port-error rounded-lg text-sm transition-colors min-h-[40px]"
+ className="flex items-center gap-1.5 px-2.5 py-2 bg-port-error/20 hover:bg-port-error/30 text-port-error rounded-lg text-sm transition-colors min-h-[44px] min-w-[44px] shrink-0"
title={isLiveRun ? 'Stop this TUI run' : 'Kill current session'}
>
<PowerOff size={16} />
@@ -223,7 +218,7 @@ function PortosShellView() {
)}
<button
onClick={startNewSession}
- className="flex items-center gap-1.5 px-2.5 py-2 bg-port-accent hover:bg-port-accent/80 text-white rounded-lg text-sm transition-colors min-h-[40px]"
+ className="flex items-center gap-1.5 px-2.5 py-2 bg-port-accent hover:bg-port-accent/80 text-white rounded-lg text-sm transition-colors min-h-[44px] min-w-[44px] shrink-0"
title="Start new session"
>
<Power size={16} />
diff --git a/client/src/pages/Shell.test.jsx b/client/src/pages/Shell.test.jsx
index a544a24623..17c6f00f54 100644
--- a/client/src/pages/Shell.test.jsx
+++ b/client/src/pages/Shell.test.jsx
@@ -1,13 +1,13 @@
-import { describe, it, expect, vi, afterEach } from 'vitest';
-import { render, cleanup, act } from '@testing-library/react';
+import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest';
+import { render, cleanup, act, screen, fireEvent } from '@testing-library/react';
import { MemoryRouter, Route, Routes } from 'react-router';
-const mocks = vi.hoisted(() => ({ shell: vi.fn(), iterm: vi.fn() }));
+const mocks = vi.hoisted(() => ({ shell: vi.fn(), iterm: vi.fn(), state: {}, itermEnabled: true, restart: vi.fn(), stop: vi.fn(), start: vi.fn() }));
vi.mock('../hooks/useShellSession', () => ({
MAX_SESSIONS: 20,
useShellSession: (...args) => {
mocks.shell(...args);
- return { terminalRef: { current: null }, connected: false, sessions: [], interactiveCount: 0, liveRunCount: 0 };
+ return mocks.state;
},
}));
vi.mock('../hooks/useItermSession', () => ({
@@ -17,7 +17,7 @@ vi.mock('../hooks/useItermSession', () => ({
},
}));
vi.mock('../hooks/useInstanceFeatures.js', () => ({
- useInstanceFeatures: () => ({ features: [], isFeatureEnabled: () => true }),
+ useInstanceFeatures: () => ({ features: [], isFeatureEnabled: (id) => id !== 'iterm' || mocks.itermEnabled }),
}));
vi.mock('../services/api', () => ({
getApps: vi.fn(async () => []),
@@ -26,6 +26,16 @@ vi.mock('../services/api', () => ({
import Shell from './Shell';
+beforeEach(() => {
+ mocks.itermEnabled = true;
+ mocks.state = {
+ terminalRef: { current: null }, connected: false, sessions: [],
+ interactiveCount: 0, liveRunCount: 0, isLiveRun: false,
+ restartSession: mocks.restart, stopSession: mocks.stop, startNewSession: mocks.start,
+ };
+});
+afterEach(cleanup);
+
const renderAt = (path) => render(
<MemoryRouter initialEntries={[path]}>
<Routes>
@@ -41,8 +51,6 @@ const renderAt = (path) => render(
// never subscribes to iTerm2 sessions, and the iTerm2 view never lists,
// auto-starts or navigates PortOS shells.
describe('Shell page source routing (#8114)', () => {
- afterEach(() => { cleanup(); mocks.shell.mockClear(); mocks.iterm.mockClear(); });
-
it('renders only the PortOS view at /shell and /shell/:sessionId', async () => {
renderAt('/shell');
renderAt('/shell/abc123');
@@ -57,3 +65,44 @@ describe('Shell page source routing (#8114)', () => {
expect(mocks.shell).not.toHaveBeenCalled();
});
});
+
+// These rendered interactions pin the lifecycle guards while the header wraps;
+// the browser companion test pins actual geometry, which happy-dom cannot do.
+describe('Shell conditional session controls (#9710)', () => {
+ it.each([
+ { iterm: false, connected: true, live: false, badge: false },
+ { iterm: true, connected: true, live: false, badge: true },
+ { iterm: false, connected: true, live: true, badge: true },
+ { iterm: true, connected: true, live: true, badge: true },
+ { iterm: true, connected: false, live: false, badge: false },
+ ])('preserves controls for %j', async ({ iterm, connected, live, badge }) => {
+ mocks.itermEnabled = iterm;
+ mocks.state = {
+ ...mocks.state, connected, isLiveRun: live, liveRunCount: badge ? 1 : 0,
+ interactiveCount: live ? 0 : 1, activeSessionId: 'example-session',
+ sessions: [{ sessionId: 'example-session', label: 'Example session', external: live, createdAt: 0 }],
+ };
+ renderAt('/shell/example-session');
+ await act(async () => {});
+ expect(screen.queryByRole('tablist', { name: 'Terminal source' }) !== null).toBe(iterm);
+ expect(screen.getByText(connected ? 'Connected' : 'Disconnected', { selector: '.sr-only' })).toBeInTheDocument();
+ expect(screen.queryByRole('button', { name: 'About live TUI runs' }) !== null).toBe(badge);
+ if (badge) {
+ fireEvent.click(screen.getByRole('button', { name: 'About live TUI runs' }));
+ expect(screen.getByRole('tooltip')).toHaveTextContent('Stop to end it');
+ }
+ const controls = screen.getByRole('group', { name: 'Session controls' });
+ expect(controls.querySelector('[title="Restart session (kill + new)"]') !== null).toBe(connected && !live);
+ expect(controls.querySelector('[title="Stop this TUI run"], [title="Kill current session"]') !== null).toBe(connected);
+ if (connected && !live) fireEvent.click(screen.getByRole('button', { name: 'Restart', exact: true }));
+ if (connected) fireEvent.click(screen.getByRole('button', { name: 'Stop', exact: true }));
+ fireEvent.click(screen.getByRole('button', { name: 'New', exact: true }));
+ expect(mocks.restart).toHaveBeenCalledTimes(connected && !live ? 1 : 0);
+ expect(mocks.stop).toHaveBeenCalledTimes(connected ? 1 : 0);
+ expect(mocks.start).toHaveBeenCalledTimes(1);
+ fireEvent.click(screen.getByRole('button', { name: 'Fullscreen terminal' }));
+ expect(screen.getByRole('dialog', { name: 'Terminal fullscreen view' })).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Exit fullscreen' }));
+ expect(screen.getByRole('group', { name: 'Session controls' })).toBeInTheDocument();
+ });
+});