mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 01:24:30 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - App connections must work in both the operator UI and agent tool gateway. > - The first stack layer adds secure remote connections. > - Operators still need clear setup, test, and recovery states. > - This pull request adds the gateway behavior and the workspace connection experience. > - The benefit is a connection flow that is easier to understand and recover. ## Linked Issues or Issue Description Refs #11965 This is stack 2 of 11. It depends on stack 1 and replaces another reviewable part of #11965. ## What Changed - Improve remote tool gateway connection behavior. - Add clearer app setup, test, and recovery states. - Add focused server and UI tests for the new paths. - Keep the diff isolated from later identity and catalog work. - Stabilize DNS-pinned remote HTTP protocol fixtures and the managed-runtime public-origin fixture for this independently tested layer. ## Verification - `pnpm -r typecheck` - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/tool-access-service.test.ts` (150 passed) - `pnpm test:run` - `pnpm check:token-gates` - `pnpm build` ## Risks - Gateway errors now surface through new user-facing states. - A stale connection can require a new setup attempt. - The change does not add a database migration. - The injected HTTP transport and public URL are test-only fixtures; production DNS pinning and runtime behavior are unchanged. > I checked `ROADMAP.md`. This stack continues the existing app connection work from #11965 and does not duplicate another planned item. ## Model Used OpenAI Codex, GPT-5. The runtime model ID and context window were not exposed. The model used reasoning, tool use, and 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 - [x] My branch name describes the change 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>
148 lines
4.6 KiB
TypeScript
148 lines
4.6 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { flushSync } from "react-dom";
|
|
import { createRoot } from "react-dom/client";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import type { ToolMcpGatewayWithTokens } from "@paperclipai/shared";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { GatewayActivityPanel } from "./GatewayActivityPanel";
|
|
|
|
const listActivityMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("@/api/tools", () => ({
|
|
toolsApi: {
|
|
listActivity: (...args: unknown[]) => listActivityMock(...args),
|
|
},
|
|
}));
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
async function act(callback: () => void | Promise<void>) {
|
|
let result: void | Promise<void> = undefined;
|
|
flushSync(() => {
|
|
result = callback();
|
|
});
|
|
await result;
|
|
}
|
|
|
|
async function flushReact() {
|
|
for (let index = 0; index < 3; index += 1) {
|
|
await act(async () => {
|
|
await Promise.resolve();
|
|
await new Promise((resolve) => window.setTimeout(resolve, 0));
|
|
});
|
|
}
|
|
}
|
|
|
|
function event(id = "event-1", toolDisplayName = "Send Email") {
|
|
return {
|
|
id,
|
|
companyId: "company-1",
|
|
action: "tool_gateway.call_completed",
|
|
actorType: "gateway_client",
|
|
actorId: "client-1",
|
|
entityType: "tool_mcp_gateway",
|
|
entityId: "gateway-1",
|
|
details: { reasonCode: "tool_completed" },
|
|
createdAt: "2026-08-20T12:00:00.000Z",
|
|
agentId: null,
|
|
runId: null,
|
|
applicationId: "app-1",
|
|
connectionId: "connection-1",
|
|
agentDisplayName: null,
|
|
appDisplayName: "Gmail",
|
|
applicationDisplayName: "Gmail",
|
|
connectionDisplayName: "Gmail",
|
|
toolDisplayName,
|
|
normalizedOutcome: "allowed",
|
|
invocation: {
|
|
id: `invocation-${id}`,
|
|
toolName: "gmail:send_email",
|
|
status: "succeeded",
|
|
policyDecision: "allow",
|
|
approvalState: "not_required",
|
|
argumentsSummary: { summary: JSON.stringify({ to: "person@example.test", token: "***REDACTED***" }) },
|
|
resultSummary: { summary: JSON.stringify({ delivered: true }) },
|
|
resultSizeBytes: 18,
|
|
errorCode: null,
|
|
errorMessage: null,
|
|
startedAt: "2026-08-20T12:00:00.000Z",
|
|
completedAt: "2026-08-20T12:00:00.125Z",
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("GatewayActivityPanel", () => {
|
|
let container: HTMLDivElement;
|
|
let root: ReturnType<typeof createRoot>;
|
|
|
|
beforeEach(() => {
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
listActivityMock.mockResolvedValue({ events: [event()], nextCursor: null });
|
|
});
|
|
|
|
afterEach(() => {
|
|
flushSync(() => root?.unmount());
|
|
container.remove();
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
async function render() {
|
|
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
root = createRoot(container);
|
|
await act(async () => {
|
|
root.render(
|
|
<QueryClientProvider client={client}>
|
|
<GatewayActivityPanel
|
|
companyId="company-1"
|
|
gateway={{ id: "gateway-1" } as ToolMcpGatewayWithTokens}
|
|
/>
|
|
</QueryClientProvider>,
|
|
);
|
|
});
|
|
await flushReact();
|
|
}
|
|
|
|
function clickButton(text: string) {
|
|
const button = [...container.querySelectorAll("button")].find((item) => item.textContent?.includes(text));
|
|
expect(button, `button containing ${text}`).toBeTruthy();
|
|
return act(async () => {
|
|
button!.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
}
|
|
|
|
it("filters by gateway and expands redacted call details", async () => {
|
|
await render();
|
|
|
|
expect(listActivityMock).toHaveBeenCalledWith("company-1", {
|
|
gateway: "gateway-1",
|
|
window: "30d",
|
|
limit: 25,
|
|
cursor: undefined,
|
|
});
|
|
expect(container.textContent).toContain("Client used Send Email in Gmail");
|
|
|
|
await clickButton("used Send Email");
|
|
expect(container.textContent).toContain("gmail:send_email");
|
|
expect(container.textContent).toContain("Arguments (redacted)");
|
|
expect(container.textContent).toContain("***REDACTED***");
|
|
expect(container.textContent).toContain("Result (redacted)");
|
|
expect(container.textContent).toContain("125 ms");
|
|
});
|
|
|
|
it("loads the next cursor page", async () => {
|
|
listActivityMock.mockImplementation((_companyId: string, params: { cursor?: string }) =>
|
|
params.cursor === "cursor-2"
|
|
? Promise.resolve({ events: [event("event-2", "Read Email")], nextCursor: null })
|
|
: Promise.resolve({ events: [event()], nextCursor: "cursor-2" }),
|
|
);
|
|
await render();
|
|
|
|
await clickButton("Load more");
|
|
await flushReact();
|
|
expect(container.textContent).toContain("Read Email");
|
|
});
|
|
});
|