From b5447432bd0de18398aab67b5294702f87b3b9e8 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:15:17 -0600 Subject: [PATCH] fix(ui): keep the active company on Cases and Status navigation links (#21794) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The board UI builds company-prefixed links, such as `/PAP/cases`, from short paths in the sidebar > - The Cases and Status links use `/cases` and `/status`, but these roots were not in the board route list > - The router read `cases` as a company prefix and left the link unprefixed, so the link only worked through the unprefixed redirect > - When a person clicked Cases before the company list loaded, the redirect picked an arbitrary company and showed its empty case list > - The same race made `tests/e2e/cases-read-only.spec.ts` fail in "ci / e2e shard (2/8)" on unrelated PRs (#21683, #21715, #21765) > - This pull request adds both roots to the board route list and makes the e2e test force the race > - The benefit is that Cases and Status always open in the company the person is in, and the flaky e2e test becomes deterministic ## Linked Issues or Issue Description Refs #21683 Refs #21715 Refs #21765 **What happened?** The read-only Cases e2e test failed about once per day with `Expected: 3, Received: 0` links in the case list (job 132875164249 on #21765, job 132680942843 on #21715). The failure screenshot shows the sidebar of a different company ("Passive artifacts …", created by the previous spec) and "No cases yet". The server log shows that the page asked for the cases of the other company and never for the test company. **Expected behavior** A click on the Cases or Status link opens that page for the company in the URL, also when the click happens before the company list has loaded. **Steps to reproduce** 1. Have two or more companies. 2. Open `//issues` on a slow connection (the e2e test holds `GET /api/companies`). 3. Before the company list loads, open More and click Cases. 4. The URL becomes `/cases`. When the list loads, the app redirects to `//cases` and shows another company's empty case list. **Paperclip version or commit** `master` at 46e5e4450f. ## What Changed - `ui/src/lib/company-routes.ts`: add `cases` and `status` to `BOARD_ROUTE_ROOTS`, so `applyCompanyPrefix("/cases", "PAP")` returns `/PAP/cases`. Remove the part of the `caseHref` doc comment that described the old behavior. - `ui/src/lib/company-routes.test.ts`: unit test for both roots (red before the fix, green after). - `tests/e2e/cases-read-only.spec.ts`: hold `GET /api/companies` until the Cases link is clicked, then require the URL `//cases`. Without the fix the URL is `/cases`, so the test fails every time instead of sometimes. ## Verification - `cd ui && npx vitest run src/lib/company-routes.test.ts src/App.cases-routing.test.tsx src/lib/router.company-task-link.test.tsx`: 23 passed. The new test failed on `master` (2 failed). - E2E, before the fix (spec change only): `npx playwright test --config tests/e2e/playwright.config.ts tests/e2e/cases-read-only.spec.ts --repeat-each=5`: 5 of 5 failed with `Received string: "http://127.0.0.1:3199/cases"`. - E2E, after the fix: same command with `--repeat-each=50` on a loaded machine (load average 6 to 12): 50 of 50 passed. - The e2e config starts its own server on port 3199 (`reuseExistingServer: false`) with a fresh `mkdtemp` home and its own embedded PostgreSQL data directory, so these runs did not touch any other instance. ## Risks - Low risk. A company whose issue prefix is exactly `CASES` or `STATUS` now gets the same treatment as a company named after any other board route (for example `TASKS`): a bare `/CASES` path is read as the Cases page. The existing `//issues` exception still applies. - No API, schema, or migration change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, local Playwright runs). ## 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 not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [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 - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 --- tests/e2e/cases-read-only.spec.ts | 8 ++++++++ ui/src/lib/company-routes.test.ts | 8 ++++++++ ui/src/lib/company-routes.ts | 7 ++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/e2e/cases-read-only.spec.ts b/tests/e2e/cases-read-only.spec.ts index 22183302f14..b40226ea49e 100644 --- a/tests/e2e/cases-read-only.spec.ts +++ b/tests/e2e/cases-read-only.spec.ts @@ -76,9 +76,17 @@ test("browses passive cases and rolled-up task documents without starting work o await page.setViewportSize({ width: 1440, height: 1000 }); // The agentless dashboard offers onboarding. Start on the ordinary task // list so this zero-agent fixture can use Cases navigation without setup. + let releaseCompanies!: () => void; + const companiesHeld = new Promise(resolve => { releaseCompanies = resolve; }); + await page.route(url => url.pathname === "/api/companies", async route => { + await companiesHeld; + await route.continue(); + }); await page.goto(`/${company.issuePrefix}/issues`); await page.getByRole("button", { name: "More workspace pages", exact: true }).click(); await page.getByRole("link", { name: /^Cases\b/ }).first().click(); + await expect(page).toHaveURL(new RegExp(`/${company.issuePrefix}/cases$`)); + releaseCompanies(); const casePage = page.getByTestId("case-pages"); const list = page.getByRole("region", { name: "Case list", exact: true }); const choose = async (filter: string, option: string) => { diff --git a/ui/src/lib/company-routes.test.ts b/ui/src/lib/company-routes.test.ts index 0b2631debe6..713b55ff4d7 100644 --- a/ui/src/lib/company-routes.test.ts +++ b/ui/src/lib/company-routes.test.ts @@ -139,6 +139,14 @@ describe("company routes", () => { expect(toCompanyRelativePath("/PAP/timeline")).toBe("/timeline"); }); + it.each(["cases", "status"])("keeps the active company on /%s navigation links", (root) => { + expect(isBoardPathWithoutPrefix(`/${root}`)).toBe(true); + expect(extractCompanyPrefixFromPath(`/${root}`)).toBeNull(); + expect(applyCompanyPrefix(`/${root}`, "PAP")).toBe(`/PAP/${root}`); + expect(applyCompanyPrefix(`/PAP/${root}`, "REA")).toBe(`/PAP/${root}`); + expect(toCompanyRelativePath(`/PAP/${root}`)).toBe(`/${root}`); + }); + it("treats Skill Studio create mode as an unprefixed board route", () => { expect(isBoardPathWithoutPrefix("/skills/studio/new")).toBe(true); expect(extractCompanyPrefixFromPath("/skills/studio/new")).toBeNull(); diff --git a/ui/src/lib/company-routes.ts b/ui/src/lib/company-routes.ts index 34012edc128..5b0b2c6c818 100644 --- a/ui/src/lib/company-routes.ts +++ b/ui/src/lib/company-routes.ts @@ -31,6 +31,8 @@ const BOARD_ROUTE_ROOTS = new Set([ "search", "settings", "timeline", + "cases", + "status", ]); const GLOBAL_ROUTE_ROOTS = new Set(["auth", "invite", "board-claim", "cli-auth", "mcp-connect", "dot-connect", "assistant-connections", "docs", "instance"]); @@ -93,11 +95,6 @@ export function applyCompanyPrefix(path: string, companyPrefix: string | null | * Build a company-prefixed href for an experimental Cases route, e.g. * `caseHref("PAP", "PAP-C5")` → `/PAP/cases/PAP-C5`. * - * Case paths carry identifiers like `PAP-C5` in the first segment, which the - * generic {@link applyCompanyPrefix} mistakes for a company prefix ("CASES") and - * therefore leaves `/cases/...` unprefixed — every case link then only resolves - * via the PAP-13002 unprefixed→prefixed redirect. This builder emits the - * prefixed href directly so case-to-case navigation matches the rest of the app. * Falls back to the unprefixed path (still valid via the redirect) when no * company is active. */