mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 11:54:35 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Chat replies, comments and documents render Markdown through
`MarkdownBody`. Task links in that Markdown become company-aware links
> - `parseIssueReferenceFromHref` turned every task link into an
unprefixed `/issues/<id>` path. The router then added the viewer's
active company prefix
> - In chat-eval cohort 4 (`access.other-company`), a reply in company
COM linked `/BIR/issues/BIR-1`. The chat rendered it as
`/COM/issues/BIR-1`, which points into the wrong company
> - This pull request keeps the company that a task link names: an
explicit `/BIR/issues/...` prefix, or an identifier whose prefix belongs
to a known company
> - The benefit is that a link to another company's task opens that
company's task, not a same-numbered task or an error in the current
company
## Linked Issues or Issue Description
**What happened?**
A chat reply in company COM contained `[BIR-1](/BIR/issues/BIR-1)`. The
rendered link pointed to `/COM/issues/BIR-1`.
**Expected behavior**
A task link that names a company keeps that company: `/BIR/issues/BIR-1`
stays `/BIR/issues/BIR-1`. A bare `BIR-1` or `/issues/BIR-1` goes to BIR
when BIR is a company that the viewer knows.
**Steps to reproduce**
1. Have two companies, COM and BIR.
2. In a COM chat or comment, render the Markdown
`[BIR-1](/BIR/issues/BIR-1)`.
3. Inspect the link. Its `href` is `/COM/issues/BIR-1`.
**Paperclip version or commit**
master at f1aef0cb58.
## What Changed
- `ui/src/lib/issue-reference.ts`: a new `issueHref` builds the internal
link. It keeps the company prefix of an explicit `/PREFIX/issues/...`
path. When the path has no prefix, it uses the identifier's prefix if
that prefix is in the known company prefixes. Otherwise the link stays
`/issues/<id>` and resolves in the active company, as before.
- `ui/src/components/MarkdownBody.tsx`: passes the known company
prefixes to the explicit-link path too (the auto-link path already had
them).
- Tests: a red/green unit test with the recorded shape in
`issue-reference.test.ts`, and a rendered test in
`MarkdownBody.test.tsx` (COM and BIR known; explicit, bare and
unprefixed BIR links all render `/BIR/issues/BIR-1`). Existing
expectations that asserted the stripped `/issues/<id>` form now assert
the company-prefixed form.
## Verification
- `cd ui && npx vitest run src/components/MarkdownBody.test.tsx
src/lib/issue-reference.test.ts src/lib/company-routes.test.ts`: 105
tests pass.
- Red/green: with `issue-reference.ts` and `MarkdownBody.tsx` from
`origin/master`, the new tests fail (`/issues/BIR-1` instead of
`/BIR/issues/BIR-1`). With the change, they pass.
- `pnpm check:token-gates` is clean. `tsc -p ui/tsconfig.json` reports
only existing errors in
`ui/storybook/support/feature-map/FeatureOverview.tsx`, which this
change does not touch.
- A paid chat-eval run with this change is linked in a comment below.
## Risks
- Same-company links now carry the explicit prefix (`/COM/issues/COM-1`
instead of `/issues/COM-1` resolved to the same place). The route is the
same.
- An explicit link with a bare identifier as its target (`[x](JIRA-2)`)
is now gated by known company prefixes like auto-linked text. Such a
link to a non-Paperclip key stays an ordinary link.
- Low risk otherwise: no API, data or saved state changes.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code
execution in Claude Code.
## 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 <noreply@anthropic.com>
164 lines
8.0 KiB
TypeScript
164 lines
8.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyCompanyPrefix,
|
|
extractCompanyPrefixFromPath,
|
|
isBoardPathWithoutPrefix,
|
|
toCompanyRelativePath,
|
|
} from "./company-routes";
|
|
|
|
describe("company routes", () => {
|
|
it("keeps public Dot consent outside company-prefixed routes", () => {
|
|
const path = `/dot-connect/pcmcp_request_${"a".repeat(43)}`;
|
|
expect(extractCompanyPrefixFromPath(path)).toBeNull();
|
|
expect(applyCompanyPrefix(path, "DOT")).toBe(path);
|
|
});
|
|
it("keeps a company task path whose prefix matches a board route name", () => {
|
|
expect(extractCompanyPrefixFromPath("/ORG/issues/ORG-1")).toBe("ORG");
|
|
expect(applyCompanyPrefix("/ORG/issues/ORG-1", "ORG")).toBe("/ORG/issues/ORG-1");
|
|
expect(applyCompanyPrefix("/ORG/issues/ORG-1", "COM")).toBe("/ORG/issues/ORG-1");
|
|
expect(applyCompanyPrefix("/org", "ORG")).toBe("/ORG/org");
|
|
expect(applyCompanyPrefix("/issues/ORG-1", "ORG")).toBe("/ORG/issues/ORG-1");
|
|
});
|
|
it("treats the task-list alias as an unprefixed board route", () => {
|
|
expect(isBoardPathWithoutPrefix("/tasks")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/tasks")).toBeNull();
|
|
expect(applyCompanyPrefix("/tasks", "PAP")).toBe("/PAP/tasks");
|
|
});
|
|
|
|
it("treats execution workspace paths as board routes that need a company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/execution-workspaces/workspace-123")).toBe(true);
|
|
expect(isBoardPathWithoutPrefix("/execution-workspaces/workspace-123/routines")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/execution-workspaces/workspace-123")).toBeNull();
|
|
expect(applyCompanyPrefix("/execution-workspaces/workspace-123", "PAP")).toBe(
|
|
"/PAP/execution-workspaces/workspace-123",
|
|
);
|
|
expect(applyCompanyPrefix("/execution-workspaces/workspace-123/routines", "PAP")).toBe(
|
|
"/PAP/execution-workspaces/workspace-123/routines",
|
|
);
|
|
});
|
|
|
|
it("normalizes prefixed execution workspace paths back to company-relative paths", () => {
|
|
expect(toCompanyRelativePath("/PAP/execution-workspaces/workspace-123")).toBe(
|
|
"/execution-workspaces/workspace-123",
|
|
);
|
|
expect(toCompanyRelativePath("/PAP/execution-workspaces/workspace-123/routines")).toBe(
|
|
"/execution-workspaces/workspace-123/routines",
|
|
);
|
|
});
|
|
|
|
it("treats /search as a board route that needs a company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/search")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/search")).toBeNull();
|
|
expect(applyCompanyPrefix("/search", "PAP")).toBe("/PAP/search");
|
|
expect(applyCompanyPrefix("/search?q=hello%20world", "PAP")).toBe("/PAP/search?q=hello%20world");
|
|
expect(toCompanyRelativePath("/PAP/search?q=foo")).toBe("/search?q=foo");
|
|
});
|
|
|
|
it("rewrites company package paths with the active prefix", () => {
|
|
expect(applyCompanyPrefix("/company/export", "NEU")).toBe("/NEU/company/export");
|
|
expect(applyCompanyPrefix("/company/import", "NEU")).toBe("/NEU/company/import");
|
|
expect(applyCompanyPrefix("/org", "NEU")).toBe("/NEU/org");
|
|
});
|
|
|
|
it("does not double-apply the company prefix", () => {
|
|
expect(applyCompanyPrefix("/NEU/company/export", "NEU")).toBe("/NEU/company/export");
|
|
});
|
|
|
|
it("normalizes prefixed company export file URLs for parsing", () => {
|
|
expect(toCompanyRelativePath("/NEU/company/export/files/agents/ceo/AGENTS.md")).toBe(
|
|
"/company/export/files/agents/ceo/AGENTS.md",
|
|
);
|
|
});
|
|
|
|
// Regression for PAP-10257: Team Catalog navigation (auto-select + row/file
|
|
// clicks) produces company-relative `/teams-catalog/<key>` paths. Without
|
|
// `teams-catalog` in the board-route allowlist, `extractCompanyPrefixFromPath`
|
|
// misread the first segment as a company prefix and `useNavigate` skipped the
|
|
// rewrite, dropping the `/PAP/` prefix and crashing into "Company not found".
|
|
it("re-prefixes team catalog routes so navigate preserves the company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/teams")).toBe(false);
|
|
expect(isBoardPathWithoutPrefix("/teams-catalog")).toBe(true);
|
|
expect(isBoardPathWithoutPrefix("/teams-catalog/core-exec-team")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/teams-catalog/core-exec-team")).toBeNull();
|
|
|
|
// Auto-select effect: `/teams-catalog/<first-key>` must gain the `/PAP/` prefix.
|
|
expect(applyCompanyPrefix("/teams-catalog/core-exec-team", "PAP")).toBe(
|
|
"/PAP/teams-catalog/core-exec-team",
|
|
);
|
|
// File-tree click: nested `/files/<encoded>` path is preserved under the prefix.
|
|
expect(applyCompanyPrefix("/teams-catalog/core-exec-team/files/TEAM.md", "PAP")).toBe(
|
|
"/PAP/teams-catalog/core-exec-team/files/TEAM.md",
|
|
);
|
|
// Already-prefixed paths are left untouched (idempotent — no double prefix).
|
|
expect(applyCompanyPrefix("/PAP/teams-catalog/core-exec-team", "PAP")).toBe(
|
|
"/PAP/teams-catalog/core-exec-team",
|
|
);
|
|
// Round-trips back to a company-relative path.
|
|
expect(toCompanyRelativePath("/PAP/teams-catalog/core-exec-team")).toBe(
|
|
"/teams-catalog/core-exec-team",
|
|
);
|
|
});
|
|
|
|
it("treats /artifacts as a board route that needs a company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/artifacts")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/artifacts")).toBeNull();
|
|
expect(applyCompanyPrefix("/artifacts", "PAP")).toBe("/PAP/artifacts");
|
|
expect(toCompanyRelativePath("/PAP/artifacts")).toBe("/artifacts");
|
|
});
|
|
|
|
it("treats /audit as a board route that needs a company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/audit")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/audit")).toBeNull();
|
|
expect(applyCompanyPrefix("/audit", "PAP")).toBe("/PAP/audit");
|
|
expect(toCompanyRelativePath("/PAP/audit")).toBe("/audit");
|
|
});
|
|
|
|
it("treats /tools routes as board routes that need a company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/tools")).toBe(true);
|
|
expect(isBoardPathWithoutPrefix("/tools/runtime")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/tools")).toBeNull();
|
|
expect(applyCompanyPrefix("/tools", "PAP")).toBe("/PAP/tools");
|
|
expect(applyCompanyPrefix("/tools/runtime", "PAP")).toBe("/PAP/tools/runtime");
|
|
expect(applyCompanyPrefix("/PAP/tools/runtime", "PAP")).toBe("/PAP/tools/runtime");
|
|
expect(toCompanyRelativePath("/PAP/tools/runtime")).toBe("/tools/runtime");
|
|
});
|
|
|
|
it("recognizes Decisions without retaining the legacy attention route", () => {
|
|
expect(isBoardPathWithoutPrefix("/decisions")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/decisions")).toBeNull();
|
|
expect(applyCompanyPrefix("/decisions", "PAP")).toBe("/PAP/decisions");
|
|
|
|
expect(isBoardPathWithoutPrefix("/attention")).toBe(false);
|
|
expect(extractCompanyPrefixFromPath("/attention")).toBe("ATTENTION");
|
|
});
|
|
|
|
it("treats /timeline as a board route that needs a company prefix", () => {
|
|
expect(isBoardPathWithoutPrefix("/timeline")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/timeline")).toBeNull();
|
|
expect(applyCompanyPrefix("/timeline", "PAP")).toBe("/PAP/timeline");
|
|
expect(toCompanyRelativePath("/PAP/timeline")).toBe("/timeline");
|
|
});
|
|
|
|
it("treats Skill Studio create mode as an unprefixed board route", () => {
|
|
expect(isBoardPathWithoutPrefix("/skills/studio/new")).toBe(true);
|
|
expect(extractCompanyPrefixFromPath("/skills/studio/new")).toBeNull();
|
|
expect(applyCompanyPrefix("/skills/studio/new?forkFrom=skill-1", "PAP")).toBe(
|
|
"/PAP/skills/studio/new?forkFrom=skill-1",
|
|
);
|
|
expect(toCompanyRelativePath("/PAP/skills/studio/new?forkFrom=skill-1")).toBe(
|
|
"/skills/studio/new?forkFrom=skill-1",
|
|
);
|
|
});
|
|
|
|
it("preserves artifact deep-link anchors when applying the company prefix", () => {
|
|
expect(applyCompanyPrefix("/issues/PAP-10205#work-product-wp-1", "PAP")).toBe(
|
|
"/PAP/issues/PAP-10205#work-product-wp-1",
|
|
);
|
|
expect(applyCompanyPrefix("/issues/PAP-10306#attachment-att-1", "PAP")).toBe(
|
|
"/PAP/issues/PAP-10306#attachment-att-1",
|
|
);
|
|
// Already-prefixed paths are returned untouched.
|
|
expect(applyCompanyPrefix("/PAP/artifacts", "PAP")).toBe("/PAP/artifacts");
|
|
});
|
|
});
|