Compare commits
1 Commits
test/ms23-
...
b12a443abe
| Author | SHA1 | Date | |
|---|---|---|---|
| b12a443abe |
@@ -132,7 +132,7 @@ describe("KanbanPage add task flow", (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Click the "+ Add task" button in the To Do column
|
// Click the "+ Add task" button in the To Do column
|
||||||
const addTaskButtons = await screen.findAllByRole("button", { name: /\+ Add task/i });
|
const addTaskButtons = screen.getAllByRole("button", { name: /\+ Add task/i });
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
await user.click(addTaskButtons[0]!); // First column is "To Do"
|
await user.click(addTaskButtons[0]!); // First column is "To Do"
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ describe("KanbanPage add task flow", (): void => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Click the "+ Add task" button
|
// Click the "+ Add task" button
|
||||||
const addTaskButtons = await screen.findAllByRole("button", { name: /\+ Add task/i });
|
const addTaskButtons = screen.getAllByRole("button", { name: /\+ Add task/i });
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
await user.click(addTaskButtons[0]!);
|
await user.click(addTaskButtons[0]!);
|
||||||
|
|
||||||
|
|||||||
@@ -1,205 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { render, screen, waitFor } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
||||||
import type { ButtonHTMLAttributes, HTMLAttributes, ReactNode } from "react";
|
|
||||||
|
|
||||||
interface MockButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
||||||
children: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MockBadgeProps extends HTMLAttributes<HTMLElement> {
|
|
||||||
children: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AuditLogEntry {
|
|
||||||
id: string;
|
|
||||||
userId: string;
|
|
||||||
sessionId: string;
|
|
||||||
provider: string;
|
|
||||||
action: string;
|
|
||||||
content: string | null;
|
|
||||||
metadata: unknown;
|
|
||||||
createdAt: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AuditLogResponse {
|
|
||||||
items: AuditLogEntry[];
|
|
||||||
total: number;
|
|
||||||
page: number;
|
|
||||||
pages: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockApiGet = vi.fn<(endpoint: string) => Promise<AuditLogResponse>>();
|
|
||||||
|
|
||||||
vi.mock("@/lib/api/client", () => ({
|
|
||||||
apiGet: (endpoint: string): Promise<AuditLogResponse> => mockApiGet(endpoint),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/ui/button", () => ({
|
|
||||||
Button: ({ children, ...props }: MockButtonProps): React.JSX.Element => (
|
|
||||||
<button {...props}>{children}</button>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/ui/badge", () => ({
|
|
||||||
Badge: ({ children, ...props }: MockBadgeProps): React.JSX.Element => (
|
|
||||||
<span {...props}>{children}</span>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { AuditLogDrawer } from "./AuditLogDrawer";
|
|
||||||
|
|
||||||
function renderWithQueryClient(ui: React.JSX.Element): ReturnType<typeof render> {
|
|
||||||
const queryClient = new QueryClient({
|
|
||||||
defaultOptions: {
|
|
||||||
queries: { retry: false },
|
|
||||||
mutations: { retry: false },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return render(<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>);
|
|
||||||
}
|
|
||||||
|
|
||||||
function responseWith(items: AuditLogEntry[], page: number, pages: number): AuditLogResponse {
|
|
||||||
return {
|
|
||||||
items,
|
|
||||||
total: items.length,
|
|
||||||
page,
|
|
||||||
pages,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("AuditLogDrawer", (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
mockApiGet.mockResolvedValue(responseWith([], 1, 0));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("opens from trigger text and renders empty state", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
renderWithQueryClient(<AuditLogDrawer trigger="Audit" />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Audit" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(screen.getByText("Audit Log")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("No audit entries found.")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders audit entries with action, session id, and payload", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
mockApiGet.mockResolvedValue(
|
|
||||||
responseWith(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
id: "entry-1",
|
|
||||||
userId: "operator-1",
|
|
||||||
sessionId: "1234567890abcdef",
|
|
||||||
provider: "internal",
|
|
||||||
action: "inject",
|
|
||||||
content: "Run diagnostics",
|
|
||||||
metadata: { payload: { ignored: true } },
|
|
||||||
createdAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
1,
|
|
||||||
1
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
renderWithQueryClient(<AuditLogDrawer trigger="Audit" />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Audit" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(screen.getByText("inject")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("12345678")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("Run diagnostics")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("supports pagination and metadata payload summary", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
mockApiGet.mockImplementation((endpoint: string): Promise<AuditLogResponse> => {
|
|
||||||
const query = endpoint.split("?")[1] ?? "";
|
|
||||||
const params = new URLSearchParams(query);
|
|
||||||
const page = Number(params.get("page") ?? "1");
|
|
||||||
|
|
||||||
if (page === 1) {
|
|
||||||
return Promise.resolve({
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
id: "entry-page-1",
|
|
||||||
userId: "operator-2",
|
|
||||||
sessionId: "abcdefgh12345678",
|
|
||||||
provider: "internal",
|
|
||||||
action: "pause",
|
|
||||||
content: "",
|
|
||||||
metadata: { payload: { reason: "hold" } },
|
|
||||||
createdAt: "2026-03-07T19:01:00.000Z",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
total: 2,
|
|
||||||
page: 1,
|
|
||||||
pages: 2,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve({
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
id: "entry-page-2",
|
|
||||||
userId: "operator-3",
|
|
||||||
sessionId: "zzzz111122223333",
|
|
||||||
provider: "internal",
|
|
||||||
action: "kill",
|
|
||||||
content: null,
|
|
||||||
metadata: { payload: { force: true } },
|
|
||||||
createdAt: "2026-03-07T19:02:00.000Z",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
total: 2,
|
|
||||||
page: 2,
|
|
||||||
pages: 2,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
renderWithQueryClient(<AuditLogDrawer trigger="Audit" />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Audit" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(screen.getByText("Page 1 of 2")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("reason=hold")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Next" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(screen.getByText("Page 2 of 2")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("force=true")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("includes sessionId filter in query string", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
renderWithQueryClient(<AuditLogDrawer trigger="Audit" sessionId="session 7" />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Audit" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(mockApiGet).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
const firstCall = mockApiGet.mock.calls[0];
|
|
||||||
const endpoint = firstCall?.[0] ?? "";
|
|
||||||
|
|
||||||
expect(endpoint).toContain("sessionId=session+7");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { render, screen, waitFor } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import type {
|
|
||||||
ButtonHTMLAttributes,
|
|
||||||
InputHTMLAttributes,
|
|
||||||
LabelHTMLAttributes,
|
|
||||||
ReactNode,
|
|
||||||
} from "react";
|
|
||||||
|
|
||||||
interface MockButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
||||||
children: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MockInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
||||||
children?: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MockLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
||||||
children: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MockSession {
|
|
||||||
id: string;
|
|
||||||
providerId: string;
|
|
||||||
providerType: string;
|
|
||||||
status: "active" | "paused";
|
|
||||||
createdAt: Date;
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockApiPost = vi.fn<(endpoint: string, body?: unknown) => Promise<{ message: string }>>();
|
|
||||||
|
|
||||||
vi.mock("@/lib/api/client", () => ({
|
|
||||||
apiPost: (endpoint: string, body?: unknown): Promise<{ message: string }> =>
|
|
||||||
mockApiPost(endpoint, body),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/ui/button", () => ({
|
|
||||||
Button: ({ children, ...props }: MockButtonProps): React.JSX.Element => (
|
|
||||||
<button {...props}>{children}</button>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/ui/input", () => ({
|
|
||||||
Input: ({ ...props }: MockInputProps): React.JSX.Element => <input {...props} />,
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/ui/label", () => ({
|
|
||||||
Label: ({ children, ...props }: MockLabelProps): React.JSX.Element => (
|
|
||||||
<label {...props}>{children}</label>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { KillAllDialog } from "./KillAllDialog";
|
|
||||||
|
|
||||||
function makeSession(overrides: Partial<MockSession>): MockSession {
|
|
||||||
return {
|
|
||||||
id: "session-1",
|
|
||||||
providerId: "internal",
|
|
||||||
providerType: "internal",
|
|
||||||
status: "active",
|
|
||||||
createdAt: new Date("2026-03-07T10:00:00.000Z"),
|
|
||||||
updatedAt: new Date("2026-03-07T10:01:00.000Z"),
|
|
||||||
...overrides,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("KillAllDialog", (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
mockApiPost.mockResolvedValue({ message: "killed" });
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders trigger button and requires exact confirmation text", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(<KillAllDialog sessions={[makeSession({})]} />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All" }));
|
|
||||||
|
|
||||||
const confirmInput = screen.getByLabelText("Type KILL ALL to confirm");
|
|
||||||
const confirmButton = screen.getByRole("button", { name: "Kill All Agents" });
|
|
||||||
|
|
||||||
expect(confirmButton).toBeDisabled();
|
|
||||||
|
|
||||||
await user.type(confirmInput, "kill all");
|
|
||||||
expect(confirmButton).toBeDisabled();
|
|
||||||
|
|
||||||
await user.clear(confirmInput);
|
|
||||||
await user.type(confirmInput, "KILL ALL");
|
|
||||||
|
|
||||||
expect(confirmButton).toBeEnabled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("kills only internal sessions by default and invokes completion callback", async (): Promise<void> => {
|
|
||||||
const onComplete = vi.fn<() => void>();
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<KillAllDialog
|
|
||||||
sessions={[
|
|
||||||
makeSession({ id: "internal-1", providerType: "internal" }),
|
|
||||||
makeSession({ id: "external-1", providerType: "external" }),
|
|
||||||
]}
|
|
||||||
onComplete={onComplete}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All" }));
|
|
||||||
await user.type(screen.getByLabelText("Type KILL ALL to confirm"), "KILL ALL");
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All Agents" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith("/api/mission-control/sessions/internal-1/kill", {
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockApiPost).not.toHaveBeenCalledWith("/api/mission-control/sessions/external-1/kill", {
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
expect(onComplete).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("kills all providers when all scope is selected", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<KillAllDialog
|
|
||||||
sessions={[
|
|
||||||
makeSession({ id: "internal-2", providerType: "internal" }),
|
|
||||||
makeSession({ id: "external-2", providerType: "external" }),
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All" }));
|
|
||||||
await user.click(screen.getByRole("radio", { name: /All providers \(2\)/ }));
|
|
||||||
await user.type(screen.getByLabelText("Type KILL ALL to confirm"), "KILL ALL");
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All Agents" }));
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith("/api/mission-control/sessions/internal-2/kill", {
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith("/api/mission-control/sessions/external-2/kill", {
|
|
||||||
force: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("shows empty-scope warning when internal sessions are unavailable", async (): Promise<void> => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<KillAllDialog
|
|
||||||
sessions={[
|
|
||||||
makeSession({ id: "external-only", providerId: "ext", providerType: "external" }),
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All" }));
|
|
||||||
await user.type(screen.getByLabelText("Type KILL ALL to confirm"), "KILL ALL");
|
|
||||||
|
|
||||||
expect(screen.getByText("No sessions in the selected scope.")).toBeInTheDocument();
|
|
||||||
expect(screen.getByRole("button", { name: "Kill All Agents" })).toBeDisabled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
||||||
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
|
||||||
import { MAX_PANEL_COUNT, MissionControlPanel, type PanelConfig } from "./MissionControlPanel";
|
|
||||||
|
|
||||||
interface MockButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
||||||
children: ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MockOrchestratorPanelProps {
|
|
||||||
sessionId?: string;
|
|
||||||
onClose?: () => void;
|
|
||||||
closeDisabled?: boolean;
|
|
||||||
onExpand?: () => void;
|
|
||||||
expanded?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockOrchestratorPanel = vi.fn<(props: MockOrchestratorPanelProps) => React.JSX.Element>();
|
|
||||||
|
|
||||||
vi.mock("@/components/mission-control/OrchestratorPanel", () => ({
|
|
||||||
OrchestratorPanel: (props: MockOrchestratorPanelProps): React.JSX.Element =>
|
|
||||||
mockOrchestratorPanel(props),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/ui/button", () => ({
|
|
||||||
Button: ({ children, ...props }: MockButtonProps): React.JSX.Element => (
|
|
||||||
<button {...props}>{children}</button>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
function buildPanels(count: number): PanelConfig[] {
|
|
||||||
return Array.from({ length: count }, (_, index) => ({
|
|
||||||
sessionId: `session-${String(index + 1)}`,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("MissionControlPanel", (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
|
|
||||||
mockOrchestratorPanel.mockImplementation(
|
|
||||||
({ sessionId, closeDisabled, expanded }: MockOrchestratorPanelProps): React.JSX.Element => (
|
|
||||||
<div
|
|
||||||
data-testid="orchestrator-panel"
|
|
||||||
data-session-id={sessionId ?? ""}
|
|
||||||
data-close-disabled={String(closeDisabled ?? false)}
|
|
||||||
data-expanded={String(expanded ?? false)}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders the panel grid and default heading", (): void => {
|
|
||||||
render(
|
|
||||||
<MissionControlPanel
|
|
||||||
panels={[{}]}
|
|
||||||
onAddPanel={vi.fn<() => void>()}
|
|
||||||
onRemovePanel={vi.fn<(index: number) => void>()}
|
|
||||||
onExpandPanel={vi.fn<(index: number) => void>()}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.getByRole("heading", { name: "Panels" })).toBeInTheDocument();
|
|
||||||
expect(screen.getAllByTestId("orchestrator-panel")).toHaveLength(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("calls onAddPanel when the add button is clicked", (): void => {
|
|
||||||
const onAddPanel = vi.fn<() => void>();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<MissionControlPanel
|
|
||||||
panels={[{}]}
|
|
||||||
onAddPanel={onAddPanel}
|
|
||||||
onRemovePanel={vi.fn<(index: number) => void>()}
|
|
||||||
onExpandPanel={vi.fn<(index: number) => void>()}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
fireEvent.click(screen.getByRole("button", { name: "Add panel" }));
|
|
||||||
|
|
||||||
expect(onAddPanel).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("disables add panel at the configured maximum", (): void => {
|
|
||||||
render(
|
|
||||||
<MissionControlPanel
|
|
||||||
panels={buildPanels(MAX_PANEL_COUNT)}
|
|
||||||
onAddPanel={vi.fn<() => void>()}
|
|
||||||
onRemovePanel={vi.fn<(index: number) => void>()}
|
|
||||||
onExpandPanel={vi.fn<(index: number) => void>()}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const addButton = screen.getByRole("button", { name: "Add panel" });
|
|
||||||
|
|
||||||
expect(addButton).toBeDisabled();
|
|
||||||
expect(addButton).toHaveAttribute("title", "Maximum of 6 panels");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("passes closeDisabled=false when more than one panel exists", (): void => {
|
|
||||||
render(
|
|
||||||
<MissionControlPanel
|
|
||||||
panels={buildPanels(2)}
|
|
||||||
onAddPanel={vi.fn<() => void>()}
|
|
||||||
onRemovePanel={vi.fn<(index: number) => void>()}
|
|
||||||
onExpandPanel={vi.fn<(index: number) => void>()}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderedPanels = screen.getAllByTestId("orchestrator-panel");
|
|
||||||
expect(renderedPanels).toHaveLength(2);
|
|
||||||
|
|
||||||
for (const panel of renderedPanels) {
|
|
||||||
expect(panel).toHaveAttribute("data-close-disabled", "false");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders only the expanded panel in focused mode", (): void => {
|
|
||||||
render(
|
|
||||||
<MissionControlPanel
|
|
||||||
panels={[{ sessionId: "session-1" }, { sessionId: "session-2", expanded: true }]}
|
|
||||||
onAddPanel={vi.fn<() => void>()}
|
|
||||||
onRemovePanel={vi.fn<(index: number) => void>()}
|
|
||||||
onExpandPanel={vi.fn<(index: number) => void>()}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderedPanels = screen.getAllByTestId("orchestrator-panel");
|
|
||||||
|
|
||||||
expect(renderedPanels).toHaveLength(1);
|
|
||||||
expect(renderedPanels[0]).toHaveAttribute("data-session-id", "session-2");
|
|
||||||
expect(renderedPanels[0]).toHaveAttribute("data-expanded", "true");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("handles Escape key by toggling expanded panel", async (): Promise<void> => {
|
|
||||||
const onExpandPanel = vi.fn<(index: number) => void>();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<MissionControlPanel
|
|
||||||
panels={[{ sessionId: "session-1", expanded: true }, { sessionId: "session-2" }]}
|
|
||||||
onAddPanel={vi.fn<() => void>()}
|
|
||||||
onRemovePanel={vi.fn<(index: number) => void>()}
|
|
||||||
onExpandPanel={onExpandPanel}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
fireEvent.keyDown(window, { key: "Escape" });
|
|
||||||
|
|
||||||
await waitFor((): void => {
|
|
||||||
expect(onExpandPanel).toHaveBeenCalledWith(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
import type { ReactElement } from "react";
|
|
||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
||||||
import { render, screen, waitFor } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { GlobalAgentRoster } from "../GlobalAgentRoster";
|
|
||||||
|
|
||||||
const { mockApiGet, mockApiPost } = vi.hoisted(() => ({
|
|
||||||
mockApiGet: vi.fn(),
|
|
||||||
mockApiPost: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/lib/api/client", () => ({
|
|
||||||
apiGet: mockApiGet,
|
|
||||||
apiPost: mockApiPost,
|
|
||||||
}));
|
|
||||||
|
|
||||||
function renderWithQueryClient(ui: ReactElement): void {
|
|
||||||
const queryClient = new QueryClient({
|
|
||||||
defaultOptions: {
|
|
||||||
queries: { retry: false, gcTime: 0 },
|
|
||||||
mutations: { retry: false },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
render(<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("GlobalAgentRoster (__tests__)", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
vi.stubGlobal("fetch", vi.fn());
|
|
||||||
mockApiGet.mockReset();
|
|
||||||
mockApiPost.mockReset();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
vi.unstubAllGlobals();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders empty state when no sessions", async () => {
|
|
||||||
mockApiGet.mockResolvedValueOnce([]);
|
|
||||||
|
|
||||||
renderWithQueryClient(<GlobalAgentRoster />);
|
|
||||||
|
|
||||||
expect(await screen.findByText("No active agents")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders session rows grouped by provider", async () => {
|
|
||||||
mockApiGet.mockResolvedValueOnce([
|
|
||||||
{
|
|
||||||
id: "sess-int-123456",
|
|
||||||
providerId: "internal",
|
|
||||||
providerType: "internal",
|
|
||||||
status: "active",
|
|
||||||
createdAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
updatedAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "sess-rem-654321",
|
|
||||||
providerId: "remote-a",
|
|
||||||
providerType: "remote",
|
|
||||||
status: "paused",
|
|
||||||
createdAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
updatedAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
renderWithQueryClient(<GlobalAgentRoster />);
|
|
||||||
|
|
||||||
expect(await screen.findByText("internal")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("remote-a (remote)")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("sess-int")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("sess-rem")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("kill button per row calls the API", async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
mockApiGet.mockResolvedValueOnce([
|
|
||||||
{
|
|
||||||
id: "killme123456",
|
|
||||||
providerId: "internal",
|
|
||||||
providerType: "internal",
|
|
||||||
status: "active",
|
|
||||||
createdAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
updatedAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
mockApiPost.mockResolvedValue({ message: "ok" });
|
|
||||||
|
|
||||||
renderWithQueryClient(<GlobalAgentRoster />);
|
|
||||||
|
|
||||||
const killButton = await screen.findByRole("button", { name: "Kill session killme12" });
|
|
||||||
await user.click(killButton);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith("/api/mission-control/sessions/killme123456/kill", {
|
|
||||||
force: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("onSelectSession callback fires on row click", async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
const onSelectSession = vi.fn();
|
|
||||||
|
|
||||||
mockApiGet.mockResolvedValueOnce([
|
|
||||||
{
|
|
||||||
id: "selectme123456",
|
|
||||||
providerId: "internal",
|
|
||||||
providerType: "internal",
|
|
||||||
status: "active",
|
|
||||||
createdAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
updatedAt: "2026-03-07T19:00:00.000Z",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
renderWithQueryClient(<GlobalAgentRoster onSelectSession={onSelectSession} />);
|
|
||||||
|
|
||||||
const sessionLabel = await screen.findByText("selectme");
|
|
||||||
const row = sessionLabel.closest('[role="button"]');
|
|
||||||
|
|
||||||
if (!row) {
|
|
||||||
throw new Error("Expected session row for selectme123456");
|
|
||||||
}
|
|
||||||
|
|
||||||
await user.click(row);
|
|
||||||
|
|
||||||
expect(onSelectSession).toHaveBeenCalledWith("selectme123456");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
import { render, screen, waitFor } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import type { AgentSession } from "@mosaic/shared";
|
|
||||||
import { KillAllDialog } from "../KillAllDialog";
|
|
||||||
import * as apiClient from "@/lib/api/client";
|
|
||||||
|
|
||||||
vi.mock("@/lib/api/client", () => ({
|
|
||||||
apiPost: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const mockApiPost = vi.mocked(apiClient.apiPost);
|
|
||||||
const baseDate = new Date("2026-03-07T14:00:00.000Z");
|
|
||||||
|
|
||||||
const sessions: AgentSession[] = [
|
|
||||||
{
|
|
||||||
id: "session-internal-1",
|
|
||||||
providerId: "provider-internal-1",
|
|
||||||
providerType: "internal",
|
|
||||||
status: "active",
|
|
||||||
createdAt: baseDate,
|
|
||||||
updatedAt: baseDate,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "session-internal-2",
|
|
||||||
providerId: "provider-internal-2",
|
|
||||||
providerType: "internal",
|
|
||||||
status: "paused",
|
|
||||||
createdAt: baseDate,
|
|
||||||
updatedAt: baseDate,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "session-external-1",
|
|
||||||
providerId: "provider-openclaw-1",
|
|
||||||
providerType: "openclaw",
|
|
||||||
status: "active",
|
|
||||||
createdAt: baseDate,
|
|
||||||
updatedAt: baseDate,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
describe("KillAllDialog (__tests__)", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
vi.stubGlobal("fetch", vi.fn());
|
|
||||||
mockApiPost.mockResolvedValue({ message: "killed" } as never);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Confirm button disabled until "KILL ALL" typed exactly', async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(<KillAllDialog sessions={sessions} />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All" }));
|
|
||||||
|
|
||||||
const input = screen.getByLabelText("Type KILL ALL to confirm");
|
|
||||||
const confirmButton = screen.getByRole("button", { name: "Kill All Agents" });
|
|
||||||
|
|
||||||
expect(confirmButton).toBeDisabled();
|
|
||||||
|
|
||||||
await user.type(input, "kill all");
|
|
||||||
expect(confirmButton).toBeDisabled();
|
|
||||||
|
|
||||||
await user.clear(input);
|
|
||||||
await user.type(input, "KILL ALL");
|
|
||||||
expect(confirmButton).toBeEnabled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("fires kill API for each session on confirm", async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(<KillAllDialog sessions={sessions} />);
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All" }));
|
|
||||||
await user.click(screen.getByLabelText("All providers (3)"));
|
|
||||||
await user.type(screen.getByLabelText("Type KILL ALL to confirm"), "KILL ALL");
|
|
||||||
await user.click(screen.getByRole("button", { name: "Kill All Agents" }));
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(mockApiPost).toHaveBeenCalledTimes(3);
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith(
|
|
||||||
"/api/mission-control/sessions/session-internal-1/kill",
|
|
||||||
{ force: true }
|
|
||||||
);
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith(
|
|
||||||
"/api/mission-control/sessions/session-internal-2/kill",
|
|
||||||
{ force: true }
|
|
||||||
);
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith(
|
|
||||||
"/api/mission-control/sessions/session-external-1/kill",
|
|
||||||
{ force: true }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import { render, screen } from "@testing-library/react";
|
|
||||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { OrchestratorPanel } from "../OrchestratorPanel";
|
|
||||||
import * as missionControlHooks from "@/hooks/useMissionControl";
|
|
||||||
|
|
||||||
vi.mock("@/hooks/useMissionControl", () => ({
|
|
||||||
useSessionStream: vi.fn(),
|
|
||||||
useSessions: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/mission-control/PanelControls", () => ({
|
|
||||||
PanelControls: (): React.JSX.Element => <div data-testid="panel-controls" />,
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/mission-control/BargeInInput", () => ({
|
|
||||||
BargeInInput: ({ sessionId }: { sessionId: string }): React.JSX.Element => (
|
|
||||||
<div data-testid="barge-in-input">barge-in:{sessionId}</div>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("date-fns", () => ({
|
|
||||||
formatDistanceToNow: (): string => "moments ago",
|
|
||||||
}));
|
|
||||||
|
|
||||||
const mockUseSessionStream = vi.mocked(missionControlHooks.useSessionStream);
|
|
||||||
const mockUseSessions = vi.mocked(missionControlHooks.useSessions);
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
Object.defineProperty(window.HTMLElement.prototype, "scrollIntoView", {
|
|
||||||
configurable: true,
|
|
||||||
value: vi.fn(),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("OrchestratorPanel (__tests__)", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
|
|
||||||
mockUseSessionStream.mockReturnValue({
|
|
||||||
messages: [],
|
|
||||||
status: "connected",
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
mockUseSessions.mockReturnValue({
|
|
||||||
sessions: [],
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders empty state when no sessionId", () => {
|
|
||||||
render(<OrchestratorPanel />);
|
|
||||||
|
|
||||||
expect(screen.getByText("Select an agent to view its stream")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders connection indicator", () => {
|
|
||||||
const { container } = render(<OrchestratorPanel sessionId="session-1" />);
|
|
||||||
|
|
||||||
expect(screen.getByText("Connected")).toBeInTheDocument();
|
|
||||||
expect(container.querySelector(".bg-emerald-500")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("renders message list when messages are present", () => {
|
|
||||||
mockUseSessionStream.mockReturnValue({
|
|
||||||
messages: [
|
|
||||||
{
|
|
||||||
id: "msg-1",
|
|
||||||
sessionId: "session-1",
|
|
||||||
role: "assistant",
|
|
||||||
content: "Mission update one",
|
|
||||||
timestamp: "2026-03-07T21:00:00.000Z",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "msg-2",
|
|
||||||
sessionId: "session-1",
|
|
||||||
role: "tool",
|
|
||||||
content: "Mission update two",
|
|
||||||
timestamp: "2026-03-07T21:00:01.000Z",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
status: "connected",
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
render(<OrchestratorPanel sessionId="session-1" />);
|
|
||||||
|
|
||||||
expect(screen.getByText("Mission update one")).toBeInTheDocument();
|
|
||||||
expect(screen.getByText("Mission update two")).toBeInTheDocument();
|
|
||||||
expect(screen.queryByText("Waiting for messages...")).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
||||||
import { render, screen, waitFor } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
||||||
import { PanelControls } from "../PanelControls";
|
|
||||||
import * as apiClient from "@/lib/api/client";
|
|
||||||
|
|
||||||
vi.mock("@/lib/api/client", () => ({
|
|
||||||
apiPost: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const mockApiPost = vi.mocked(apiClient.apiPost);
|
|
||||||
|
|
||||||
function renderPanelControls(status: string): void {
|
|
||||||
const queryClient = new QueryClient({
|
|
||||||
defaultOptions: {
|
|
||||||
queries: { retry: false },
|
|
||||||
mutations: { retry: false },
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<QueryClientProvider client={queryClient}>
|
|
||||||
<PanelControls sessionId="session-1" status={status} />
|
|
||||||
</QueryClientProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("PanelControls (__tests__)", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
vi.stubGlobal("fetch", vi.fn());
|
|
||||||
mockApiPost.mockResolvedValue({ message: "ok" } as never);
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
vi.unstubAllGlobals();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Pause button disabled when status=paused", () => {
|
|
||||||
renderPanelControls("paused");
|
|
||||||
|
|
||||||
expect(screen.getByRole("button", { name: "Pause session" })).toBeDisabled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Resume button disabled when status=active", () => {
|
|
||||||
renderPanelControls("active");
|
|
||||||
|
|
||||||
expect(screen.getByRole("button", { name: "Resume session" })).toBeDisabled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("Kill buttons disabled when status=killed", () => {
|
|
||||||
renderPanelControls("killed");
|
|
||||||
|
|
||||||
expect(screen.getByRole("button", { name: "Gracefully kill session" })).toBeDisabled();
|
|
||||||
expect(screen.getByRole("button", { name: "Force kill session" })).toBeDisabled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("clicking pause calls the API", async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
renderPanelControls("active");
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: "Pause session" }));
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(mockApiPost).toHaveBeenCalledWith("/api/mission-control/sessions/session-1/pause");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import type { ReactNode } from "react";
|
|
||||||
import { render, screen } from "@testing-library/react";
|
|
||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { MissionControlLayout } from "../MissionControlLayout";
|
|
||||||
|
|
||||||
vi.mock("@/components/mission-control/AuditLogDrawer", () => ({
|
|
||||||
AuditLogDrawer: ({ trigger }: { trigger: ReactNode }): React.JSX.Element => (
|
|
||||||
<div data-testid="audit-log-drawer">{trigger}</div>
|
|
||||||
),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/mission-control/GlobalAgentRoster", () => ({
|
|
||||||
GlobalAgentRoster: (): React.JSX.Element => <div data-testid="global-agent-roster" />,
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("@/components/mission-control/MissionControlPanel", () => ({
|
|
||||||
MissionControlPanel: (): React.JSX.Element => <div data-testid="mission-control-panel" />,
|
|
||||||
MIN_PANEL_COUNT: 1,
|
|
||||||
MAX_PANEL_COUNT: 6,
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("Mission Control Phase 2 Gate", () => {
|
|
||||||
it("Phase 2 gate: MissionControlLayout renders with all components present", () => {
|
|
||||||
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation((..._args) => undefined);
|
|
||||||
|
|
||||||
render(<MissionControlLayout />);
|
|
||||||
|
|
||||||
expect(screen.getByTestId("global-agent-roster")).toBeInTheDocument();
|
|
||||||
expect(screen.getByTestId("mission-control-panel")).toBeInTheDocument();
|
|
||||||
expect(consoleErrorSpy).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
consoleErrorSpy.mockRestore();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -102,5 +102,5 @@ describe("OnboardingWizard", () => {
|
|||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(mockPush).toHaveBeenCalledWith("/");
|
expect(mockPush).toHaveBeenCalledWith("/");
|
||||||
});
|
});
|
||||||
}, 10_000);
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user