mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 18:31:34 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The agent detail page uses route references that can be based on an agent's URL key. > - Renaming an agent can change that URL key while the browser is still on the old route. > - After save or rollback, refetching the stale route reference can render an "Agent not found" state even though the agent still exists. > - This pull request redirects the detail page to the updated canonical route when the saved agent's route reference changes. > - The benefit is that agent renames keep users on the same configuration workflow without landing on a stale URL. ## Linked Issues or Issue Description - Refs #1848 - Related public search performed for agent rename/not-found issues and PRs; no closer in-flight PR was found. - Bug context: after saving a renamed agent or rolling back to a revision with a different name-derived URL key, the agent detail page could continue using the old URL and show "Agent not found". ## What Changed - Added a small route-sync helper that compares the previous and updated agent route refs after mutations. - Redirects the agent detail page with `replace: true` when a save or rollback changes the canonical route ref. - Removes the stale detail-query cache entry so the old route reference is not refetched after a rename. ## Verification - Local outgoing patch scan for common secrets, private paths/emails, and internal issue/link references: no matches. - `corepack pnpm install --frozen-lockfile` - `corepack pnpm --dir ui run typecheck` - `corepack pnpm --dir ui exec vitest run src/pages/AgentDetail.progress.test.ts src/App.test.tsx` - `corepack pnpm check:token-gates` ## Risks - Low risk: the redirect only runs when the updated agent resolves to a different route ref than the current agent. - If a future mutation response omits both URL key and name, the existing route-ref fallback behavior still applies. ## Model Used OpenAI Codex, GPT-5 coding agent via the local Codex adapter, with tool-assisted repository inspection, shell execution, and GitHub API use. ## 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 --------- Co-authored-by: Claude <noreply@paperclip.ing>
105 lines
3.4 KiB
TypeScript
105 lines
3.4 KiB
TypeScript
import { QueryClient } from "@tanstack/react-query";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { queryKeys } from "../lib/queryKeys";
|
|
import {
|
|
buildHeartbeatProgressLogLine,
|
|
heartbeatProgressLogLineKey,
|
|
syncAgentRouteAfterRename,
|
|
} from "./AgentDetail";
|
|
|
|
describe("buildHeartbeatProgressLogLine", () => {
|
|
it("renders progress messages with phase prefixes as system log lines", () => {
|
|
expect(
|
|
buildHeartbeatProgressLogLine(
|
|
{
|
|
message: "Syncing issue history",
|
|
phase: "workspace",
|
|
updatedAt: "2026-07-04T05:00:00.000Z",
|
|
},
|
|
"2026-07-04T04:59:00.000Z",
|
|
),
|
|
).toEqual({
|
|
ts: "2026-07-04T05:00:00.000Z",
|
|
stream: "system",
|
|
chunk: "[workspace] Syncing issue history",
|
|
});
|
|
});
|
|
|
|
it("renders progress messages without phases using the live event timestamp", () => {
|
|
expect(
|
|
buildHeartbeatProgressLogLine(
|
|
{ message: "Preparing workspace" },
|
|
"2026-07-04T05:01:00.000Z",
|
|
),
|
|
).toEqual({
|
|
ts: "2026-07-04T05:01:00.000Z",
|
|
stream: "system",
|
|
chunk: "Preparing workspace",
|
|
});
|
|
});
|
|
|
|
it("ignores empty progress messages", () => {
|
|
expect(
|
|
buildHeartbeatProgressLogLine(
|
|
{ message: " ", phase: "workspace" },
|
|
"2026-07-04T05:02:00.000Z",
|
|
),
|
|
).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("heartbeatProgressLogLineKey", () => {
|
|
it("uses the rendered log line fields as the replay key", () => {
|
|
const line = {
|
|
ts: "2026-07-04T05:03:00.000Z",
|
|
stream: "system" as const,
|
|
chunk: "[workspace] Syncing issue history",
|
|
};
|
|
|
|
expect(heartbeatProgressLogLineKey(line)).toBe(
|
|
"2026-07-04T05:03:00.000Z\u0000system\u0000[workspace] Syncing issue history",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("syncAgentRouteAfterRename", () => {
|
|
it("replaces stale agent routes after a rename changes the URL key", () => {
|
|
const queryClient = new QueryClient();
|
|
const navigate = vi.fn();
|
|
queryClient.setQueryData(queryKeys.agents.detail("old-agent"), { id: "agent-1" });
|
|
queryClient.setQueryData(queryKeys.agents.detail("renamed-agent"), { id: "agent-1" });
|
|
|
|
const redirected = syncAgentRouteAfterRename(
|
|
queryClient,
|
|
navigate,
|
|
{ id: "agent-1", name: "Old Agent", urlKey: "old-agent" },
|
|
{ id: "agent-1", name: "Renamed Agent", urlKey: "renamed-agent" },
|
|
"configuration",
|
|
);
|
|
|
|
expect(redirected).toBe(true);
|
|
expect(navigate).toHaveBeenCalledWith("/agents/renamed-agent/configuration", { replace: true });
|
|
expect(queryClient.getQueryData(queryKeys.agents.detail("old-agent"))).toBeUndefined();
|
|
expect(queryClient.getQueryData(queryKeys.agents.detail("renamed-agent"))).toEqual({ id: "agent-1" });
|
|
});
|
|
|
|
it("does not redirect when the canonical route ref stays the same", () => {
|
|
const queryClient = new QueryClient();
|
|
const navigate = vi.fn();
|
|
queryClient.setQueryData(queryKeys.agents.detail("same-agent"), { id: "agent-1" });
|
|
|
|
const redirected = syncAgentRouteAfterRename(
|
|
queryClient,
|
|
navigate,
|
|
{ id: "agent-1", name: "Same Agent", urlKey: "same-agent" },
|
|
{ id: "agent-1", name: "Same Agent", urlKey: "same-agent" },
|
|
"configuration",
|
|
);
|
|
|
|
expect(redirected).toBe(false);
|
|
expect(navigate).not.toHaveBeenCalled();
|
|
expect(queryClient.getQueryData(queryKeys.agents.detail("same-agent"))).toEqual({ id: "agent-1" });
|
|
});
|
|
});
|