Files
paperclip/tests/e2e/sidebar-takeover.spec.ts
Dotta 50bff3b274 feat(ui): add collapsible sidebar rail and takeover panes (#7824)
## Thinking Path

> - Paperclip is the open source control plane people use to manage AI
agents, work, and company context.
> - The board UI sidebar is the main way operators keep orientation
across companies, projects, agents, issues, and settings.
> - The existing fixed expanded sidebar competes with route-specific
navigation, especially company settings and plugin routes that bring
their own contextual sidebar.
> - A collapsible primary rail preserves global navigation while giving
contextual pages more horizontal room.
> - This pull request adds a persisted collapsed rail, hover/focus peek,
keyboard toggle, and a secondary sidebar takeover model for settings and
plugin `routeSidebar` surfaces.
> - The benefit is a denser board shell that keeps the app rail
available without replacing it when a route needs its own navigation.

## Linked Issues or Issue Description

Paperclip issue: PAP-10638 Create collapsible sidebar branch.

Related GitHub PR found during duplicate search: #3838
(`feat/collapsible-sidebar`) covers a similar sidebar area but is a
different head branch and implementation. This PR intentionally packages
the work from `PAP-10638-collapsable-sidebar` into one reviewable
branch.

Problem description:

The board shell needs a first-class collapsed sidebar mode. Contextual
surfaces such as company settings and plugin route sidebars should not
replace the global app sidebar; they should collapse the app sidebar to
a rail and render their contextual navigation beside it.

## What Changed

- Added desktop collapsed/sidebar-peek state to `SidebarContext`,
including persisted user pins, route collapse requests, and forced
collapse for secondary-sidebar routes.
- Replaced the old resizable sidebar pane with `SidebarShell`, which
supports a fixed 64px rail, persisted expanded width, keyboard/pointer
resizing, and hover/focus peek overlay behavior.
- Updated `Sidebar`, sidebar nav items, project/agent sections, badges,
and account/company menu presentation for expanded, collapsed, and
peeking states.
- Added `RequestCollapsedSidebar` and `SecondarySidebar` so routes and
plugin `routeSidebar` slots can request contextual sidebar layouts
without replacing the primary app sidebar.
- Wired company settings and plugin route sidebars into the
secondary-pane takeover model.
- Added focused Vitest coverage for sidebar state precedence, shell
sizing, nav item rail rendering, keyboard shortcuts, layout takeover
behavior, and route collapse requests.
- Updated plugin authoring docs/spec references for route sidebar
behavior.

## Verification

Targeted local verification passed:

```sh
NODE_ENV=test pnpm run preflight:workspace-links && NODE_ENV=test pnpm exec vitest run ui/src/context/SidebarContext.test.tsx ui/src/components/SidebarShell.test.tsx ui/src/components/Sidebar.test.tsx ui/src/components/Layout.test.tsx ui/src/components/RequestCollapsedSidebar.test.tsx ui/src/components/SidebarNavItem.test.tsx ui/src/components/SidebarAgents.test.tsx ui/src/components/SidebarProjects.test.tsx ui/src/components/KeyboardShortcutsCheatsheet.test.tsx ui/src/hooks/useKeyboardShortcuts.test.tsx
```

Result: 10 test files passed, 88 tests passed.

Additional follow-up verification passed after review fixes:

```sh
NODE_ENV=test pnpm run preflight:workspace-links && NODE_ENV=test pnpm exec vitest run ui/src/components/Layout.test.tsx ui/src/context/SidebarContext.test.tsx && pnpm --filter /ui typecheck
```

Result: 2 test files passed, 28 tests passed, and UI typecheck passed.

Latest PR-head remote checks: Paperclip PR workflow, Snyk, Socket, and
Greptile are green; commitperclip `review` is cancelled in its
security-gate step after filing a non-blocking neutral `security-review`
check.

Notes:

- A direct run without `NODE_ENV=test` loads React's production build in
this workspace, where `act` is unavailable; the command above matches
the repo stable runner's test environment.
- I did not run Playwright/browser e2e or full workspace build/typecheck
in this PR-creation heartbeat.
- QA screenshots are attached in
https://github.com/paperclipai/paperclip/pull/7824#issuecomment-4661968387
for expanded, collapsed rail, hover peek, and settings secondary-sidebar
states.

## Risks

- Medium UI layout risk: this changes the board shell and primary
sidebar composition across many routes.
- Local storage migration risk is low: new collapsed state uses a new
key and existing width storage remains scoped to the sidebar width.
- Plugin route risk: plugin `routeSidebar` slots now render as secondary
panes on desktop, so plugin authors should confirm their route sidebar
content fits a 240px contextual pane.
- Mobile risk appears low because mobile keeps the drawer model and
gates collapsed/peek behavior to desktop.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex coding agent based on GPT-5, with local shell/git/GitHub
CLI tool use. Exact service-side model identifier and context window
were not exposed in this runtime.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] If this change affects the UI, I have included before/after
screenshots
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-06-09 13:25:17 -05:00

162 lines
7.0 KiB
TypeScript

import { test, expect, request as pwRequest, type APIRequestContext } from "@playwright/test";
/**
* E2E: Sidebar takeover model (PAP-10695).
*
* Takeover routes (company settings, plugin `routeSidebar`) no longer *replace*
* the main app sidebar. Instead the host collapses the app `<Sidebar/>` to its
* 64px rail (still peek-able) and renders the contextual sidebar in a second
* pane → `[ app rail ][ secondary ~240px ][ content ]`.
*
* These specs assert the rail + secondary pane coexist on a company settings
* route, and that an explicit user pin (expanded) wins over the route-driven
* collapse (pin precedence).
*
* The plugin `routeSidebar` half of this behavior shares the exact same Layout
* code path (one `secondarySidebar`/`hasSecondarySidebar` resolver drives both
* company-settings and plugin routes) and is covered by the unit tests in
* `ui/src/components/Layout.test.tsx`. A live plugin-route e2e requires the
* `plugin-llm-wiki` plugin to be installed in the throwaway e2e instance, which
* is out of scope for this default local_trusted run; visual QA of both panes
* is delegated to the QA child issue.
*/
const PORT = Number(process.env.PAPERCLIP_E2E_PORT ?? 3199);
const BASE_URL = `http://127.0.0.1:${PORT}`;
const COMPANY_NAME_PREFIX = "E2E-SidebarTakeover";
const COLLAPSED_STORAGE_KEY = "paperclip.sidebar.collapsed";
// The sidebar header's "Open search" control only renders when the app sidebar
// is expanded (pinned or peeking); in the collapsed rail it is hidden to fit
// the 64px width. Its presence/absence is therefore a stable proxy for the
// app sidebar's collapsed state (see Sidebar.tsx).
const APP_SIDEBAR_EXPANDED_MARKER = "Open search";
async function createCompany(board: APIRequestContext): Promise<{ id: string; prefix: string }> {
const healthRes = await board.get(`${BASE_URL}/api/health`);
expect(healthRes.ok()).toBe(true);
const health = await healthRes.json();
expect(health.deploymentMode).toBe("local_trusted");
const companyRes = await board.post(`${BASE_URL}/api/companies`, {
data: { name: `${COMPANY_NAME_PREFIX}-${Date.now()}` },
});
if (!companyRes.ok()) {
throw new Error(`POST /api/companies → ${companyRes.status()}: ${await companyRes.text()}`);
}
const company = await companyRes.json();
return {
id: company.id,
prefix: company.issuePrefix ?? company.prefix ?? company.urlKey ?? "E2E",
};
}
test.describe("Sidebar takeover (collapse + secondary pane)", () => {
let board: APIRequestContext;
let companyId: string;
let prefix: string;
test.beforeAll(async () => {
board = await pwRequest.newContext({ baseURL: BASE_URL });
const company = await createCompany(board);
companyId = company.id;
prefix = company.prefix;
});
test.afterAll(async () => {
await board.delete(`${BASE_URL}/api/companies/${companyId}`).catch(() => {});
await board.dispose();
});
test.beforeEach(async ({ page }) => {
// Start each test from a clean (unpinned) sidebar state so the route-driven
// collapse is the only thing acting on it.
await page.addInitScript((key) => {
window.localStorage.removeItem(key);
}, COLLAPSED_STORAGE_KEY);
});
test("collapses the app sidebar to its rail and shows the settings sidebar beside it", async ({ page }) => {
await page.goto(`/${prefix}/company/settings`);
// The contextual (secondary) pane is present...
const secondary = page.locator("[data-secondary-sidebar]");
await expect(secondary).toBeVisible();
await expect(secondary).toHaveCount(1);
// ...and it is ~240px wide (w-60), distinct from the 64px app rail.
const secondaryBox = await secondary.boundingBox();
expect(secondaryBox).not.toBeNull();
expect(secondaryBox!.width).toBeGreaterThan(180);
// The app sidebar is NOT replaced — its company nav still renders...
await expect(page.getByRole("link", { name: "Dashboard" })).toBeVisible();
// ...but it is collapsed to its rail: the expanded-only "Open search"
// header control is hidden.
await expect(page.getByLabel(APP_SIDEBAR_EXPANDED_MARKER)).toHaveCount(0);
});
test("renders the secondary pane nav labels at full width despite the app rail collapse", async ({ page }) => {
// Regression (PAP-10700): the secondary pane is 240px wide, but its
// SidebarNavItem children read the *global* collapsed state and used to
// render icon-only (label `w-0 text-transparent`), making the settings nav
// unreadable in the default takeover state. The pane must force full labels.
await page.goto(`/${prefix}/company/settings`);
const secondary = page.locator("[data-secondary-sidebar]");
await expect(secondary).toBeVisible();
// App sidebar is collapsed to its rail (default unpinned takeover state)...
await expect(page.getByLabel(APP_SIDEBAR_EXPANDED_MARKER)).toHaveCount(0);
// ...yet a settings nav label renders at its full text width, not clipped to
// zero. "Environments" is unique to the company-settings nav.
const envLabel = secondary.getByText("Environments", { exact: true });
await expect(envLabel).toBeVisible();
const labelBox = await envLabel.boundingBox();
expect(labelBox).not.toBeNull();
expect(labelBox!.width).toBeGreaterThan(20);
});
test("settings force-collapse overrides an expanded pin without mutating it", async ({ page }) => {
// User has pinned the sidebar expanded ("0"). Company settings is a hard
// secondary-sidebar takeover route, so forceCollapsed wins while the route is
// active (force > pin > route request > default) but must not mutate the pin.
await page.addInitScript(
({ key }) => {
window.localStorage.setItem(key, "0");
},
{ key: COLLAPSED_STORAGE_KEY },
);
await page.goto(`/${prefix}/company/settings`);
// Secondary pane still shows on the takeover route.
await expect(page.locator("[data-secondary-sidebar]")).toBeVisible();
// The app sidebar is hard-collapsed despite the stored expanded pin.
await expect(page.getByLabel(APP_SIDEBAR_EXPANDED_MARKER)).toHaveCount(0);
await page.goto(`/${prefix}/dashboard`);
// Leaving the takeover route clears the force and restores the user's
// persisted expanded pin.
await expect(page.locator("[data-secondary-sidebar]")).toHaveCount(0);
await expect(page.getByLabel(APP_SIDEBAR_EXPANDED_MARKER)).toBeVisible();
});
test("leaving the takeover route removes the secondary pane and restores the sidebar", async ({ page }) => {
await page.goto(`/${prefix}/company/settings`);
await expect(page.locator("[data-secondary-sidebar]")).toBeVisible();
await expect(page.getByLabel(APP_SIDEBAR_EXPANDED_MARKER)).toHaveCount(0);
// Navigate to a plain (non-takeover) route.
await page.goto(`/${prefix}/dashboard`);
// No secondary pane, and the app sidebar is no longer force-collapsed.
await expect(page.locator("[data-secondary-sidebar]")).toHaveCount(0);
await expect(page.getByLabel(APP_SIDEBAR_EXPANDED_MARKER)).toBeVisible();
});
});