Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/frontend/terminal/TerminalApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const TerminalApp: React.FC<TerminalAppProps> = ({ 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}
/>
</CommandHistoryProvider>
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/terminal/TerminalTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions tests/frontend/terminal/TerminalApp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>[] }));

vi.mock("../../../src/frontend/terminal/Terminal", () => ({
Terminal: () => {
Terminal: (props: Record<string, unknown>) => {
captured.props.push(props);
useCommandHistory();
return <div>terminal</div>;
},
Expand All @@ -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(<TerminalApp hostId="15" />);
expect(screen.getByText("terminal")).toBeTruthy();
});

it("asks for a direct attach to the tmux session it was opened for", () => {
render(<TerminalApp hostId="15" tmuxSession="build" />);
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(<TerminalApp hostId="15" />);
expect(captured.props.at(-1)?.tmuxAttachSession).toBeUndefined();
});
});
11 changes: 11 additions & 0 deletions tests/frontend/terminal/TerminalTabContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down