diff --git a/src/frontend/terminal/TerminalApp.tsx b/src/frontend/terminal/TerminalApp.tsx index 79840f8..af150e6 100644 --- a/src/frontend/terminal/TerminalApp.tsx +++ b/src/frontend/terminal/TerminalApp.tsx @@ -55,6 +55,9 @@ const TerminalApp: React.FC = ({ hostId, tmuxSession }) => { executeCommand={ tmuxSession ? tmuxAttachCommand(tmuxSession) : undefined } + // Direct attach, so Auto tmux does not show the session picker + // instead; executeCommand is the fallback (see TerminalTabContent). + tmuxAttachSession={tmuxSession || undefined} tmuxSession={tmuxSession || undefined} /> diff --git a/src/frontend/terminal/TerminalTabContent.tsx b/src/frontend/terminal/TerminalTabContent.tsx index 346a378..fc3d164 100644 --- a/src/frontend/terminal/TerminalTabContent.tsx +++ b/src/frontend/terminal/TerminalTabContent.tsx @@ -127,6 +127,15 @@ export function TerminalTabContent({ ? tmuxAttachCommand(tab.data.tmuxSession) : undefined } + // Ask the backend for a direct attach as well. With Auto tmux on + // and several sessions on the host it would otherwise show the + // session picker and never run executeCommand, which stays as + // the fallback for a backend without the tmux service. + tmuxAttachSession={ + typeof tab.data?.tmuxSession === "string" + ? tab.data.tmuxSession || undefined + : undefined + } tmuxSession={ typeof tab.data?.tmuxSession === "string" ? tab.data.tmuxSession || undefined diff --git a/tests/frontend/terminal/TerminalApp.test.tsx b/tests/frontend/terminal/TerminalApp.test.tsx index 29b801e..6218528 100644 --- a/tests/frontend/terminal/TerminalApp.test.tsx +++ b/tests/frontend/terminal/TerminalApp.test.tsx @@ -3,8 +3,11 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import type { ReactNode } from "react"; import { useCommandHistory } from "../../../src/frontend/terminal/command-history/CommandHistoryContext"; +const captured = vi.hoisted(() => ({ props: [] as Record[] })); + vi.mock("../../../src/frontend/terminal/Terminal", () => ({ - Terminal: () => { + Terminal: (props: Record) => { + captured.props.push(props); useCommandHistory(); return
terminal
; }, @@ -25,11 +28,27 @@ vi.mock("@termix-ssh/plugin-sdk/frontend", () => ({ import TerminalApp from "../../../src/frontend/terminal/TerminalApp"; -afterEach(cleanup); +afterEach(() => { + cleanup(); + captured.props = []; +}); describe("TerminalApp", () => { it("renders the terminal inside a command history provider", () => { render(); expect(screen.getByText("terminal")).toBeTruthy(); }); + + it("asks for a direct attach to the tmux session it was opened for", () => { + render(); + expect(captured.props.at(-1)?.tmuxAttachSession).toBe("build"); + expect(captured.props.at(-1)?.executeCommand).toBe( + "tmux attach-session -t '=build'", + ); + }); + + it("asks for no tmux session when opened without one", () => { + render(); + expect(captured.props.at(-1)?.tmuxAttachSession).toBeUndefined(); + }); }); diff --git a/tests/frontend/terminal/TerminalTabContent.test.tsx b/tests/frontend/terminal/TerminalTabContent.test.tsx index 2407bf3..20ffec1 100644 --- a/tests/frontend/terminal/TerminalTabContent.test.tsx +++ b/tests/frontend/terminal/TerminalTabContent.test.tsx @@ -86,6 +86,17 @@ describe("TerminalTabContent in a split", () => { renderTab(undefined, { tmuxSession: 42 }); await waitFor(() => expect(captured.props.length).toBeGreaterThan(0)); expect(captured.props.at(-1)?.executeCommand).toBeUndefined(); + expect(captured.props.at(-1)?.tmuxAttachSession).toBeUndefined(); + }); + it("asks for a direct attach, so Auto tmux does not show the session picker instead", async () => { + renderTab(undefined, { tmuxSession: "agent's session" }); + await waitFor(() => expect(captured.props.length).toBeGreaterThan(0)); + expect(captured.props.at(-1)?.tmuxAttachSession).toBe("agent's session"); + }); + it("asks for no tmux session in an ordinary tab", async () => { + renderTab(undefined); + await waitFor(() => expect(captured.props.length).toBeGreaterThan(0)); + expect(captured.props.at(-1)?.tmuxAttachSession).toBeUndefined(); }); });