Skip to content
Open
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
69 changes: 68 additions & 1 deletion frontend/src/renderer/components/ShellTopbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import type { WorkspaceSession } from "../types/workspace";
import { TopbarKillButton } from "./ShellTopbar";

const { postMock } = vi.hoisted(() => ({
const { navigateMock, postMock, useWorkspaceQueryMock } = vi.hoisted(() => ({
navigateMock: vi.fn(),
postMock: vi.fn(),
useWorkspaceQueryMock: vi.fn(),
}));

vi.mock("@tanstack/react-router", () => ({
useNavigate: () => navigateMock,
useParams: () => ({}),
}));

vi.mock("../hooks/useWorkspaceQuery", async (importOriginal) => {
const actual = await importOriginal<typeof import("../hooks/useWorkspaceQuery")>();
return {
...actual,
useWorkspaceQuery: () => useWorkspaceQueryMock(),
};
});

vi.mock("../lib/api-client", () => ({
apiClient: {
POST: postMock,
Expand All @@ -35,6 +50,19 @@ const worker: WorkspaceSession = {
prs: [],
};

const orchestrator: WorkspaceSession = {
id: "orch-1",
workspaceId: "proj-1",
workspaceName: "my-app",
title: "orchestrator",
provider: "claude-code",
kind: "orchestrator",
branch: "main",
status: "working",
updatedAt: "2026-06-10T00:00:00Z",
prs: [],
};

function renderKill(session: WorkspaceSession = worker) {
const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -51,8 +79,14 @@ function renderKill(session: WorkspaceSession = worker) {
}

beforeEach(() => {
navigateMock.mockReset();
postMock.mockReset();
postMock.mockResolvedValue({ data: { ok: true, sessionId: "sess-1" }, error: undefined });
useWorkspaceQueryMock.mockReturnValue({
data: [{ id: "proj-1", name: "my-app", path: "/p/my-app", type: "main", sessions: [] }],
isLoading: false,
isError: false,
});
});

describe("TopbarKillButton", () => {
Expand Down Expand Up @@ -89,4 +123,37 @@ describe("TopbarKillButton", () => {

expect(await screen.findByText("session not found")).toBeInTheDocument();
});

it("navigates back to the project orchestrator after a successful kill", async () => {
useWorkspaceQueryMock.mockReturnValue({
data: [{ id: "proj-1", name: "my-app", path: "/p/my-app", type: "main", sessions: [worker, orchestrator] }],
isLoading: false,
isError: false,
});
renderKill();

await userEvent.click(screen.getByRole("button", { name: "Kill session" }));
await userEvent.click(screen.getByRole("button", { name: "Confirm kill" }));

await waitFor(() => {
expect(navigateMock).toHaveBeenCalledWith({
to: "/projects/$projectId/sessions/$sessionId",
params: { projectId: "proj-1", sessionId: "orch-1" },
});
});
});

it("falls back to the project board when no orchestrator is available", async () => {
renderKill();

await userEvent.click(screen.getByRole("button", { name: "Kill session" }));
await userEvent.click(screen.getByRole("button", { name: "Confirm kill" }));

await waitFor(() => {
expect(navigateMock).toHaveBeenCalledWith({
to: "/projects/$projectId",
params: { projectId: "proj-1" },
});
});
});
});
12 changes: 12 additions & 0 deletions frontend/src/renderer/components/ShellTopbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ export function ShellTopbar() {
// terminated group.
export function TopbarKillButton({ session }: { session: WorkspaceSession }) {
const queryClient = useQueryClient();
const navigate = useNavigate();
const all = useWorkspaceQuery().data ?? [];
const [confirming, setConfirming] = useState(false);
const [error, setError] = useState<string | null>(null);

Expand All @@ -262,6 +264,16 @@ export function TopbarKillButton({ session }: { session: WorkspaceSession }) {
void captureRendererEvent("ao.renderer.session_kill_succeeded", { project_id: session.workspaceId });
setConfirming(false);
void queryClient.invalidateQueries({ queryKey: workspaceQueryKey });
const projectId = session.workspaceId;
const orchestrator = projectId ? findProjectOrchestrator(all, projectId) : undefined;
if (orchestrator && projectId) {
void navigate({
to: "/projects/$projectId/sessions/$sessionId",
params: { projectId, sessionId: orchestrator.id },
});
} else if (projectId) {
void navigate({ to: "/projects/$projectId", params: { projectId } });
}
},
onError: (e) => {
void captureRendererEvent("ao.renderer.session_kill_failed", { project_id: session.workspaceId });
Expand Down
Loading