fix(ui): link routine projects by ID (#23332)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Routines assign repeated work to an agent and an optional project.
> - A routine stores its project ID, but its detail page links to the
project's name-derived URL key.
> - A cached name can stop identifying that project after a rename.
> - This pull request uses the project ID in that link.
> - The link stays attached to the selected project when its name
changes.

## Linked Issues or Issue Description

**What happened?**

The routine detail page prefers a project's name-derived URL key over
its ID. A cached routine page can link to an old project name after a
rename. If another project takes that name, the old link can resolve to
the other project. Saved routine associations, filters, and scheduler
joins already use project IDs.

**Expected behavior**

The project link should identify the routine's selected project by ID.

**Steps to reproduce**

1. Open a routine attached to a project named Operations.
2. Rename the project while the routine page retains its cached project
data.
3. Inspect the routine's project link. Before this change, it uses
`/projects/operations`. After this change, it uses
`/projects/<project-id>`.

## What Changed

- Use the project ID for the project link on the routine detail page.
- Add rendered-link regression tests for a rename, same-name projects,
and an unassigned routine.

## Verification

- Confirmed that the rename and same-name link tests fail before the
fix.
- All 24 focused tests pass across routine page, routine form, routine
list filtering, routine row selection, and company link routing.
- `pnpm --filter @paperclipai/ui typecheck`: passed after building the
fresh worktree's shared and plugin SDK dependencies.
- `node scripts/check-test-budget.mjs --files
ui/src/components/routine-page/RoutinePage.test.tsx`: passed.
- `pnpm verify`: passed on final head
`989dad85d8fc6dfe45cc4490e798dd8da1fb1ff1`. All 309 selected files
passed: 4,012 UI tests and 537 CLI tests passed, with one UI test
skipped. Environment: macOS arm64, Node 25.6.1, pnpm 9.15.4.
- Earlier attempts exposed missing Postgres package library symlinks in
the fresh worktree, then a run invalidated by changed setup inputs. Ran
the dependency's own symlink hydration script and repeated verification
on the stable final checkout. Those earlier attempts are not counted as
passes.
- CI
[typecheck](https://github.com/paperclipai/paperclip/actions/runs/46527285069/job/142231921191),
[build](https://github.com/paperclipai/paperclip/actions/runs/46527285069/job/142231921278),
and
[policy](https://github.com/paperclipai/paperclip/actions/runs/46527285069/job/142231921302)
passed on the final head. All selected test and browser shards passed.
The final [verify
gate](https://github.com/paperclipai/paperclip/actions/runs/46527285069/job/142233704075)
and [e2e
gate](https://github.com/paperclipai/paperclip/actions/runs/46527285069/job/142233695844)
passed on the same head.
- [Greptile
review](https://github.com/paperclipai/paperclip/pull/23332#issuecomment-7293910180):
5/5 on the final head, with no findings.
- No live tenant, deployment, or browser acceptance test was run. This
change only changes a link target.
- Reviewed the complete diff locally for secrets, personal data, and run
artifacts.

## Risks

Low risk. The project page already accepts project IDs and applies its
existing authorization and canonical URL handling. The link's visible
label stays the project name. There is no schema or API change. Revert
the link change to restore the former behavior.

## Model Used

OpenAI Codex, `gpt-6.1-sol`, with xhigh reasoning effort and local code
execution.

## 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
- [x] 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: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip authored and GitHub committed 2026-11-30 14:35:46 -08:00
1 parent 3884cc6df4
commit d71d039ad7
2 files changed
+69 -1

No files matched your search

@@ -0,0 +1,68 @@
import type { RoutineDetail } from "@paperclipai/shared";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { renderToStaticMarkup } from "react-dom/server";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it, vi } from "vitest";
import { RoutinePage, type RoutinePageProject } from "./RoutinePage";
vi.mock("@/context/CompanyContext", () => ({
useCompany: () => ({ selectedCompany: { issuePrefix: "ACME" } }),
}));
const routine: RoutineDetail = {
id: "routine-1", companyId: "company-1", projectId: "project-1",
title: "Weekly review", description: null, status: "active", priority: "medium",
goalId: null, parentIssueId: null, assigneeAgentId: null, responsibleUserId: null,
concurrencyPolicy: "coalesce_if_active", catchUpPolicy: "skip_missed",
activityGatePolicy: "always", activityGateScope: "company", variables: [],
latestRevisionId: null, latestRevisionNumber: 1,
createdByAgentId: null, createdByUserId: null, updatedByAgentId: null, updatedByUserId: null,
lastTriggeredAt: null, lastEnqueuedAt: null,
createdAt: new Date(0), updatedAt: new Date(0),
project: null, assignee: null, parentIssue: null, activeIssue: null,
triggers: [], recentRuns: [],
};
function renderPage(project: RoutinePageProject | null) {
return renderToStaticMarkup(
<MemoryRouter initialEntries={["/ACME/routines/routine-1"]}>
<QueryClientProvider client={new QueryClient()}>
<RoutinePage
routine={{ ...routine, projectId: project?.id ?? null }}
project={project}
agent={null}
responsibleUser={null}
history={[]}
onToggleActive={vi.fn()}
onEdit={vi.fn()}
onSaveSchedule={vi.fn()}
onRemoveSchedule={vi.fn()}
onOpenWebhook={vi.fn()}
/>
</QueryClientProvider>
</MemoryRouter>,
);
}
describe("routine project navigation", () => {
it("keeps the linked project ID when its name and URL key change", () => {
for (const name of ["Operations", "Renamed operations"]) {
const html = renderPage({ id: routine.projectId!, name, urlKey: name.toLowerCase().replaceAll(" ", "-") });
expect(html).toContain(`href="/ACME/projects/${routine.projectId}"`);
expect(html).toContain(name);
}
});
it("keeps same-name projects distinct", () => {
for (const id of ["project-1", "project-2"]) {
const html = renderPage({ id, name: "Operations", urlKey: "operations" });
expect(html).toContain(`href="/ACME/projects/${id}"`);
}
});
it("shows an unassigned routine without a project link", () => {
const html = renderPage(null);
expect(html).toContain("No project");
expect(html).not.toContain("/projects/");
});
});
@@ -579,7 +579,7 @@ export function RoutinePage({
<Field label="Project">
{project ? (
<Link
to={`/projects/${project.urlKey ?? project.id}`}
to={`/projects/${project.id}`}
className="flex w-fit max-w-full items-center gap-2 py-1.5 text-sm font-medium hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
>
<span className="h-3.5 w-3.5 shrink-0 rounded-sm" style={{ backgroundColor: project.color ?? "var(--project-none)" }} aria-hidden="true" />