Files
PaperClipAI/ui/src/components/TrustPresetSection.test.tsx
T
DottaandPaperclip 507dc70be2 fix(evals): bind hosted controller admission to the first attempt (#17523)
Bind hosted controller admission to the repository, GitHub run, first attempt, workflow revision and selected execution before credential reads or provider launch. Keep offline evidence replay independent of the current worker environment. Preserve the single-project boundary editor and refresh project-access data with agent-detail updates.

Verified head: 1e588f75fe.
Validation: 74 synthetic source/portable controller tests, 98 focused UI tests and token gates passed before the ancestry-only final sync; four hosted/portable regressions pass again with unchanged eval and UI repair trees. Final exact-head full CI passed (40387856225), and Greptile reviewed this head at 5/5 with zero unresolved findings. The optional secondary Paperclip Review is paused and not counted as completed. No paid work or schedule changes.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-26 14:43:58 -05:00

111 lines
3.9 KiB
TypeScript

// @vitest-environment jsdom
import { createRoot, type Root } from "react-dom/client";
import { flushSync } from "react-dom";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { AgentPermissions } from "@paperclipai/shared";
import { TrustPresetSection } from "./TrustPresetSection";
import { TooltipProvider } from "@/components/ui/tooltip";
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
let root: Root | null = null;
let container: HTMLDivElement | null = null;
function renderSection(permissions: Partial<AgentPermissions>, withProjectEditor = false) {
container = document.createElement("div");
document.body.appendChild(container);
const onChange = vi.fn();
const createdRoot = createRoot(container);
root = createdRoot;
flushSync(() => {
createdRoot.render(
<TooltipProvider>
<TrustPresetSection
projectAccessEditor={withProjectEditor ? <div>Allowed projects</div> : undefined}
permissions={permissions}
onChange={onChange}
companyId="company-1"
projectCandidates={[{ id: "project-1", label: "Paperclip App" }]}
issueCandidates={[{ id: "issue-1", label: "PAP-1 · Review PR" }]}
/>
</TooltipProvider>,
);
});
return { onChange, text: () => container?.textContent ?? "" };
}
afterEach(() => {
if (root) {
flushSync(() => root?.unmount());
}
container?.remove();
root = null;
container = null;
});
describe("TrustPresetSection", () => {
it("hides the CE boundary editor under Standard", () => {
const view = renderSection({ canCreateAgents: false, trustPreset: "standard" });
expect(view.text()).toContain("Trust preset");
expect(view.text()).not.toContain("Boundary type");
expect(view.text()).not.toContain("Get Paperclip EE.");
});
it("shows a selectable CE boundary editor for low-trust review", () => {
const view = renderSection({
canCreateAgents: false,
trustPreset: "low_trust_review",
authorizationPolicy: {
trustPreset: "low_trust_review",
trustBoundary: {
mode: "low_trust_review",
companyId: "company-1",
projectIds: ["project-1"],
},
},
});
expect(view.text()).toContain("Containment active");
expect(view.text()).toContain("Boundary type");
expect(view.text()).toContain("Paperclip App");
expect(view.text()).toContain("Get Paperclip EE.");
expect(view.text()).not.toContain("Managed by EE/API");
});
it("keeps the single-boundary controls when the allowed-project editor is present", () => {
const view = renderSection({ trustPreset: "low_trust_review", authorizationPolicy: {
trustPreset: "low_trust_review", trustBoundary: {
mode: "low_trust_review", companyId: "company-1", projectIds: ["project-1"],
},
} }, true);
expect(view.text()).toContain("Allowed projects");
expect(view.text()).toContain("Boundary type");
const clear = [...container!.querySelectorAll("button")].find(button => button.textContent === "Clear boundary");
expect(clear).toBeDefined();
flushSync(() => clear!.click());
const changed = view.onChange.mock.calls[0][0];
expect(changed.trustPreset).toBe("low_trust_review");
expect(changed.authorizationPolicy.trustBoundary.projectIds).toBeUndefined();
});
it("renders multi-boundary policies as read-only", () => {
const view = renderSection({
canCreateAgents: false,
trustPreset: "low_trust_review",
authorizationPolicy: {
trustPreset: "low_trust_review",
trustBoundary: {
mode: "low_trust_review",
companyId: "company-1",
projectIds: ["project-1", "project-2"],
},
},
});
expect(view.text()).toContain("Managed by EE/API");
expect(view.text()).toContain("2 boundaries");
expect(view.text()).not.toContain("Clear boundary");
});
});