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
34 changes: 34 additions & 0 deletions frontend/e2e/chat-groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,40 @@ test("loads chat groups successfully and files their chats", async ({ page }) =>
await expect(page.getByText("Research")).toBeVisible();
});

test("keeps every move destination reachable above the footer in a short drawer", async ({ page }) => {
await page.setViewportSize({ width: 667, height: 375 });
const groups = Array.from({ length: 12 }, (_, index) => ({
id: `folder-${index}`, name: `Folder ${index}`, collapsed: true, position: index,
timestamp: "2026-01-01T00:00:00Z",
}));
await stubWorkspace(page, groups);
await page.route("**/api/v1/chats", (route) => route.fulfill({
json: [{ id: "loose", title: "Loose chat", timestamp: "2026-01-01T00:00:00Z", group_id: null }],
}));
await page.goto("/#bootstrap=launcher-token");
await page.getByRole("button", { name: "Show chat history" }).click();
const trigger = page.getByRole("button", { name: "Move Loose chat to a group" });
await trigger.focus();
await trigger.press("Enter");
const menu = page.getByRole("menu");
const list = page.locator(".chat-list");
const fits = async () => {
const popup = await menu.boundingBox();
const area = await list.boundingBox();
return !!popup && !!area && popup.y >= area.y && popup.y + popup.height <= area.y + area.height;
};
await expect.poll(fits).toBe(true);
await page.setViewportSize({ width: 667, height: 350 });
await expect.poll(fits).toBe(true);
await page.keyboard.press("End");
const destination = page.getByRole("menuitem", { name: "Folder 11" });
await expect(destination).toBeFocused();
expect(await destination.evaluate((item) => {
const { x, y, width, height } = item.getBoundingClientRect();
return item.contains(document.elementFromPoint(x + width / 2, y + height / 2));
})).toBe(true);
});

test("does not let a late initial group response erase a group created while loading", async ({ page }) => {
let releaseInitialGroups!: () => void;
const initialGroups = new Promise<void>((resolve) => { releaseInitialGroups = resolve; });
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/features/shell/AppShell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ describe("AppShell", () => {
expect(window.location.pathname).toBe("/chat/new");
});

it("clears a history search and returns focus to the search field", async () => {
const user = userEvent.setup();
const view = renderShell({ chats: [
{ id: "chat-1", title: "Quarterly planning", timestamp: "2026-01-01T00:00:00Z" },
{ id: "chat-2", title: "Release notes", timestamp: "2026-01-02T00:00:00Z" },
] });

const field = screen.getByRole("searchbox", { name: "Search chats by title" });
await user.type(field, "release");
expect(screen.queryByRole("button", { name: "Quarterly planning" })).not.toBeInTheDocument();
await user.click(screen.getByRole("button", { name: "Clear chat search" }));
expect(field).toHaveFocus();
expect(field).toHaveValue("");
expect(screen.getByRole("button", { name: "Quarterly planning" })).toBeVisible();

await user.type(field, "release");
view.rerender(<AppShell {...view.props} chats={[]} />);
await user.click(screen.getByRole("button", { name: "Clear chat search" }));
expect(screen.getByText("No threads yet.")).toBeVisible();
});

it("removes the collapsed sidebar from the accessibility and tab trees", async () => {
const user = userEvent.setup();
renderShell();
Expand Down
67 changes: 43 additions & 24 deletions frontend/src/features/shell/AppShell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState, type FormEvent, type ReactNode } from "react";
import { FolderCode, Menu, Plus, Search, Settings, Trash2 } from "lucide-react";
import { ArrowRight, FolderCode, PanelLeft, Plus, Search, Settings, Trash2, X } from "lucide-react";
import type { ChatGroup, ChatSummary, CodeExecutionSourceResponse, ExecutionApprovalDecisionRequest, ExecutionTaskSummary, ModelResponse } from "../../../../contracts/cortex-api";
import { displayChatTitle } from "../../lib/chatTitle";
import { chatPath, parseAppRoute, useNavigate, usePathname } from "../../lib/navigation";
Expand Down Expand Up @@ -58,6 +58,7 @@ export function AppShell({
const [renameTarget, setRenameTarget] = useState<ChatSummary | null>(null);
const [deleteTarget, setDeleteTarget] = useState<ChatSummary | null>(null);
const [chatQuery, setChatQuery] = useState("");
const searchRef = useRef<HTMLInputElement>(null);
const previousPathnameRef = useRef(pathname);

const isSettings = parseAppRoute(pathname).kind === "settings";
Expand Down Expand Up @@ -122,9 +123,11 @@ export function AppShell({
className="window-control sidebar-toggle"
type="button"
aria-label={sidebarVisible ? "Hide chat history" : "Show chat history"}
aria-expanded={sidebarVisible}
aria-controls="thread-archive"
onClick={() => setSidebarVisible((visible) => !visible)}
>
<Menu aria-hidden="true" size={17} />
<PanelLeft aria-hidden="true" size={17} />
</button>
<div className="window-title-group">
<span className="window-kicker">Cortex</span>
Expand Down Expand Up @@ -155,34 +158,43 @@ export function AppShell({
<div className="workspace-body">
{sidebarVisible && <button className="sidebar-scrim" aria-label="Close chat history" onClick={() => setSidebarVisible(false)} />}
<aside
id="thread-archive"
className="sidebar"
aria-label="Chat history"
aria-hidden={!sidebarVisible}
inert={!sidebarVisible ? true : undefined}
>
<div className="sidebar-brand">
<span className="sidebar-brand-mark" aria-hidden="true"><img src="/cortex.svg" alt="" /></span>
<span className="sidebar-brand-copy"><strong>Cortex</strong></span>
<header className="archive-cover">
<div className="archive-imprint"><img src="/cortex.svg" alt="" />Cortex</div>
<h2>Thread <em>archive</em></h2>
</header>
<div className="archive-tools">
<button className="new-chat-button" type="button" onClick={createChat}>
New thread
<Plus aria-hidden="true" size={18} />
</button>
{(chats.length > 0 || chatQuery.length > 0) && (
<div className="sidebar-search">
<Search aria-hidden="true" size={15} />
<input
ref={searchRef}
type="search"
placeholder="Search chats"
aria-label="Search chats by title"
value={chatQuery}
onChange={(event) => setChatQuery(event.target.value)}
/>
{chatQuery && (
<button type="button" className="archive-clear-search" aria-label="Clear chat search" onClick={() => {
setChatQuery("");
searchRef.current?.focus();
}}>
<X aria-hidden="true" size={14} />
</button>
)}
</div>
)}
</div>
<button className="new-chat-button" type="button" onClick={createChat}>
<Plus aria-hidden="true" size={16} />
New thread
</button>
<NavigationLink to="/workspace" className="new-chat-button" aria-current={isWorkspace ? "page" : undefined}>
<FolderCode aria-hidden="true" size={16} /> Project workspace
</NavigationLink>
{chats.length > 0 && (
<div className="sidebar-search">
<Search aria-hidden="true" size={14} />
<input
type="search"
placeholder="Search chats"
aria-label="Search chats by title"
value={chatQuery}
onChange={(event) => setChatQuery(event.target.value)}
/>
</div>
)}
<InlineBoundary scope="chat-library" label="The chat list">
<ChatLibrary
chats={chats}
Expand All @@ -200,6 +212,13 @@ export function AppShell({
onMoveChat={onMoveChat}
/>
</InlineBoundary>
<footer className="archive-footer">
<NavigationLink to="/workspace" className="archive-workspace" aria-current={isWorkspace ? "page" : undefined}>
<span className="archive-workspace-icon"><FolderCode aria-hidden="true" size={17} /></span>
Project workspace
<ArrowRight aria-hidden="true" size={15} />
</NavigationLink>
</footer>
</aside>

<main className={`main-content ${isSettings ? "settings-content" : isWorkspace ? "workspace-content" : "chat-content"}`}>{children}</main>
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/features/shell/ChatLibrary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,58 @@ function renderLibrary(overrides: Partial<React.ComponentProps<typeof ChatLibrar
}

describe("ChatLibrary", () => {
it("orders local calendar months newest first, preserving row order and undated threads", () => {
const june = new Date(2026, 5, 1, 0, 1);
const earlierYear = new Date(2025, 5, 10, 12);
const laterInJune = new Date(2026, 5, 25, 12);
const month = new Intl.DateTimeFormat(undefined, { month: "long", year: "numeric" });
renderLibrary({
groups: [group("g1", "Research")],
chats: [
{ ...chat("old", "Earlier year", "missing-group"), timestamp: earlierYear.toISOString() },
{ ...chat("bad", "Imported chat"), timestamp: "not recorded" },
{ ...chat("first", "First in June"), timestamp: june.toISOString() },
{ ...chat("second", "Second in June"), timestamp: laterInJune.toISOString() },
{ ...chat("filed", "Filed chat", "g1"), timestamp: june.toISOString() },
{ ...chat("missing", "Missing date"), timestamp: "" },
],
});

const headings = screen.getAllByRole("heading", { level: 4 });
expect(headings.map((heading) => heading.textContent)).toEqual([
month.format(june), month.format(earlierYear), "Date unavailable",
]);
const visibleTitles = (heading: HTMLElement) => within(heading.closest("section")!)
.getAllByRole("button").filter((button) => button.classList.contains("chat-row-select")).map((button) => button.textContent);
expect(visibleTitles(headings[0])).toEqual(["First in June", "Second in June"]);
expect(visibleTitles(headings[1])).toEqual(["Earlier year"]);
expect(visibleTitles(headings[2])).toEqual(["Imported chat", "Missing date"]);
expect(within(headings[2].closest("section")!).queryByRole("time")).not.toBeInTheDocument();
const filed = screen.getByRole("button", { name: "Filed chat" });
expect(filed.compareDocumentPosition(headings[0]) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
const date = within(filed.closest("section")!).getByRole("time");
expect(date).toHaveAttribute("datetime", june.toISOString());
expect(date).toHaveTextContent(new Intl.DateTimeFormat(undefined, { month: "short", day: "numeric" }).format(june));
});

it("counts matching chats across groups and omits month sections during search", () => {
const view = renderLibrary({
groups: [group("g1", "Research", true)],
chats: [chat("one", "Plan for May", "g1"), chat("two", "Plan for June"), chat("three", "Notes")],
});
expect(screen.getByRole("status")).toHaveTextContent("3 threads");
view.rerender(<ChatLibrary {...view.props} query="plan" />);
expect(screen.getByRole("heading", { name: "Search results" })).toBeVisible();
expect(screen.getByRole("status")).toHaveTextContent("2 results");
expect(screen.queryByRole("heading", { level: 4 })).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "Plan for May" })).toBeVisible();
expect(screen.getByRole("button", { name: "Plan for June" })).toBeVisible();
view.rerender(<ChatLibrary {...view.props} query="may" />);
expect(screen.getByRole("status")).toHaveTextContent(/^1 result$/);
view.rerender(<ChatLibrary {...view.props} query="nothing" />);
expect(screen.getByRole("status")).toHaveTextContent("0 results");
});

it("files chats under their group and leaves the rest ungrouped", () => {
renderLibrary({
groups: [group("g1", "Research")],
Expand Down
Loading
Loading