mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 02:30:43 +01:00
fix: preserve Codex runner intent and private eval evidence
Retain native setup links and built-in settings, record explicit runner choices, and qualify native/legacy skill fixtures. Keep full grading artifacts private while projecting safe first-task summaries. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
38199ea8e6
commit
1be8502f27
15 files changed
+454
-32
No files matched your search
@@ -28,8 +28,8 @@ export function CodexRunnerSelect({
|
||||
<SelectPopover
|
||||
aria-label="Runner"
|
||||
disabled={disabled}
|
||||
value={value === "auto" ? defaultRunner ?? "auto" : value}
|
||||
displayValue={value === "auto" && !defaultRunner ? (pending ? "Checking runner availability…" : "Automatic selection unavailable") : undefined}
|
||||
value={value}
|
||||
displayValue={value === "auto" ? (defaultRunner ? `${defaultRunner === "paperclip" ? "Paperclip Runner" : "Legacy runner"} (default)` : pending ? "Checking runner availability…" : "Automatic selection unavailable") : undefined}
|
||||
onValueChange={next => onChange(next as AgentRunnerChoice)}
|
||||
options={[
|
||||
{ value: "paperclip", label: `Paperclip Runner${defaultRunner === "paperclip" ? " (default)" : ""}`, disabled: !supportedRunners.includes("paperclip") && value !== "paperclip" },
|
||||
|
||||
@@ -11,6 +11,9 @@ import type { BuiltInAgentState } from "@/api/builtInAgents";
|
||||
const provisionMock = vi.hoisted(() => vi.fn());
|
||||
const updateMock = vi.hoisted(() => vi.fn());
|
||||
const adapterModelsMock = vi.hoisted(() => vi.fn());
|
||||
const adapterDiscoveryMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("@/api/adapters", () => ({ adaptersApi: { list: adapterDiscoveryMock } }));
|
||||
|
||||
vi.mock("@/api/builtInAgents", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("@/api/builtInAgents")>();
|
||||
@@ -72,6 +75,15 @@ function makeState(overrides: Partial<BuiltInAgentState> = {}): BuiltInAgentStat
|
||||
};
|
||||
}
|
||||
|
||||
function makeSavedAgent(adapterType: "codex_local" | "paperclip_runner", adapterConfig: Record<string, unknown>): NonNullable<BuiltInAgentState["agent"]> {
|
||||
return {
|
||||
id: "a1", companyId: "c1", name: "Briefs Agent", urlKey: "briefs-agent", role: "general", title: null, icon: null,
|
||||
status: "idle", reportsTo: null, capabilities: null, adapterType, adapterConfig, runtimeConfig: {}, defaultEnvironmentId: null,
|
||||
budgetMonthlyCents: 0, spentMonthlyCents: 0, pauseReason: null, pausedAt: null, permissions: { canCreateAgents: false },
|
||||
lastHeartbeatAt: null, metadata: null, createdAt: new Date(0), updatedAt: new Date(0),
|
||||
};
|
||||
}
|
||||
|
||||
async function flushReact() {
|
||||
for (let index = 0; index < 6; index += 1) {
|
||||
await Promise.resolve();
|
||||
@@ -117,6 +129,7 @@ describe("ConfigureBuiltInAgentModal (PAP-12978)", () => {
|
||||
provisionMock.mockReset();
|
||||
updateMock.mockReset();
|
||||
adapterModelsMock.mockReset().mockResolvedValue([]);
|
||||
adapterDiscoveryMock.mockReset().mockResolvedValue([{ type: "codex_local", supportedRunners: ["paperclip", "legacy"], defaultRunner: "legacy" }]);
|
||||
onOpenChange.mockReset();
|
||||
onConfigured.mockReset();
|
||||
});
|
||||
@@ -189,6 +202,40 @@ describe("ConfigureBuiltInAgentModal (PAP-12978)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["codex_local", "paperclip_runner"] as const)("lets the server translate saved %s settings for a runner-only change", async adapterType => {
|
||||
const savedConfig = { model: "gpt-5", timeoutSec: 45, modelReasoningEffort: "high", env: { CODEX_HOME: { type: "secret_ref", secretId: "account-1" } }, ...(adapterType === "paperclip_runner" ? { provider: "codex", codexPermissionMode: "never", lifecycleMode: "per_turn" } : {}) };
|
||||
const state = makeState({ status: "ready", agentId: "a1", agent: makeSavedAgent(adapterType, savedConfig) });
|
||||
provisionMock.mockResolvedValue(state);
|
||||
await renderModal(state);
|
||||
const summary = document.querySelector("summary")!;
|
||||
flushSync(() => summary.dispatchEvent(new MouseEvent("click", { bubbles: true })));
|
||||
flushSync(() => document.querySelector('[aria-label="Runner"]')!.dispatchEvent(new MouseEvent("click", { bubbles: true })));
|
||||
await flushReact();
|
||||
const runner = adapterType === "paperclip_runner" ? "legacy" : "paperclip";
|
||||
flushSync(() => document.querySelector(`[role="option"][data-value="${runner}"]`)!.dispatchEvent(new MouseEvent("click", { bubbles: true })));
|
||||
await flushReact();
|
||||
flushSync(() => findButton("Configure")!.dispatchEvent(new MouseEvent("click", { bubbles: true })));
|
||||
await flushReact();
|
||||
expect(provisionMock).toHaveBeenCalledWith("c1", "briefs", { runner });
|
||||
expect(state.agent?.adapterConfig).toEqual(savedConfig);
|
||||
});
|
||||
|
||||
it("merges a built-in model edit into the saved native configuration", async () => {
|
||||
const savedConfig = { provider: "codex", model: "gpt-5", timeoutSec: 45, modelReasoningEffort: "high", env: { CODEX_HOME: { type: "secret_ref", secretId: "account-1" } } };
|
||||
const state = makeState({ status: "ready", agentId: "a1", agent: makeSavedAgent("paperclip_runner", savedConfig) });
|
||||
provisionMock.mockResolvedValue(state);
|
||||
await renderModal(state);
|
||||
const modelInput = document.querySelector('[data-testid="model-input"]') as HTMLInputElement;
|
||||
flushSync(() => {
|
||||
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(modelInput, "gpt-6-sol");
|
||||
modelInput.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
});
|
||||
await flushReact();
|
||||
flushSync(() => findButton("Configure")!.dispatchEvent(new MouseEvent("click", { bubbles: true })));
|
||||
await flushReact();
|
||||
expect(provisionMock).toHaveBeenCalledWith("c1", "briefs", { adapterType: "paperclip_runner", adapterConfig: { ...savedConfig, model: "gpt-6-sol" } });
|
||||
});
|
||||
|
||||
it("shows a visible error and blocks provisioning for an unknown model", async () => {
|
||||
adapterModelsMock.mockResolvedValue([
|
||||
{ id: "claude-haiku-4-5", label: "Claude Haiku 4.5" },
|
||||
|
||||
@@ -134,10 +134,16 @@ export function ConfigureBuiltInAgentModal({
|
||||
mutationFn: async () => {
|
||||
const adapterConfig: Record<string, unknown> = {};
|
||||
if (model.trim()) adapterConfig.model = model.trim();
|
||||
const existing = state.agent;
|
||||
const sameHarness = existing && agentHarnessType(existing.adapterType, existing.adapterConfig) === adapterType;
|
||||
const savedModel = typeof existing?.adapterConfig.model === "string" ? existing.adapterConfig.model.trim() : "";
|
||||
// A runner-only change must let the server translate the full saved config.
|
||||
const adapterInput = sameHarness && normalizedModel === savedModel ? {}
|
||||
: sameHarness ? { adapterType: existing.adapterType, adapterConfig: { ...existing.adapterConfig, ...adapterConfig } }
|
||||
: { adapterType, adapterConfig };
|
||||
const result = await builtInAgentsApi.provision(companyId, definition.key, {
|
||||
adapterType: state.agent && agentHarnessType(state.agent.adapterType, state.agent.adapterConfig) === adapterType ? state.agent.adapterType : adapterType,
|
||||
...adapterInput,
|
||||
...(adapterType === "codex_local" && runner !== undefined ? { runner } : {}),
|
||||
adapterConfig,
|
||||
...(budgetMonthlyCents !== undefined ? { budgetMonthlyCents } : {}),
|
||||
});
|
||||
return result;
|
||||
|
||||
@@ -92,6 +92,7 @@ export function NewAgentSetup() {
|
||||
name={params.get("name") ?? ""}
|
||||
adapterType={params.get("adapterType") === "paperclip_runner" && (params.get("runnerProvider") ?? "codex") === "codex" ? "codex_local" : params.get("adapterType") ?? ""}
|
||||
initialRunner={params.get("runner") ?? (params.get("adapterType") === "paperclip_runner" && (params.get("runnerProvider") ?? "codex") === "codex" ? "paperclip" : "auto")}
|
||||
preserveNativeCodex={params.get("adapterType") === "paperclip_runner" && (params.get("runnerProvider") ?? "codex") === "codex"}
|
||||
runnerProvider={params.get("runnerProvider") ?? "codex"}
|
||||
createdAgentId={params.get("createdAgentId")}
|
||||
/>
|
||||
@@ -104,6 +105,7 @@ function Setup({
|
||||
adapterType,
|
||||
runnerProvider,
|
||||
initialRunner,
|
||||
preserveNativeCodex,
|
||||
createdAgentId,
|
||||
}: {
|
||||
companyId: string;
|
||||
@@ -111,6 +113,7 @@ function Setup({
|
||||
adapterType: string;
|
||||
runnerProvider: string;
|
||||
initialRunner: string;
|
||||
preserveNativeCodex: boolean;
|
||||
createdAgentId: string | null;
|
||||
}) {
|
||||
const navigate = useNavigate();
|
||||
@@ -118,6 +121,7 @@ function Setup({
|
||||
const { openNewIssue } = useDialogActions();
|
||||
const appearanceDraft = useAgentAppearanceDraft(`${companyId}:new-agent`);
|
||||
const [runner, setRunner] = useState<AgentRunnerChoice>(initialRunner === "legacy" || initialRunner === "paperclip" ? initialRunner : "auto");
|
||||
const requestAdapterType = preserveNativeCodex && runner === "paperclip" ? "paperclip_runner" : adapterType;
|
||||
const isRunner = adapterType === "paperclip_runner";
|
||||
const isDot = isRunner && runnerProvider === "openai_dot";
|
||||
const brandType = isDot ? "openai_dot" : isRunner
|
||||
@@ -335,7 +339,7 @@ function Setup({
|
||||
adapter.loaded &&
|
||||
!adapter.disabled &&
|
||||
!getAdapterDisplay(adapterType).comingSoon,
|
||||
);
|
||||
) && (requestAdapterType !== "paperclip_runner" || adapterType === "paperclip_runner" || adapterInventory.data?.some(adapter => adapter.type === "paperclip_runner" && adapter.loaded && !adapter.disabled));
|
||||
const ready = Boolean(
|
||||
available &&
|
||||
(adapterType !== "codex_local" || runner !== "auto" || Boolean(adapters.data)) &&
|
||||
@@ -380,6 +384,9 @@ function Setup({
|
||||
: {}),
|
||||
};
|
||||
const config = getUIAdapter(adapterType).buildAdapterConfig(values);
|
||||
if (preserveNativeCodex && runner === "paperclip") {
|
||||
Object.assign(config, { provider: "codex", codexPermissionMode: "never", lifecycleMode: "per_turn" });
|
||||
}
|
||||
if (isRunner)
|
||||
Object.assign(config, {
|
||||
provider: (runnerProvider === "claude" || runnerProvider === "grok") ? "acpx" : runnerProvider,
|
||||
@@ -464,7 +471,7 @@ function Setup({
|
||||
const config = await preparedConfig(nextConnection);
|
||||
const tested = await testAgentSetup({
|
||||
companyId,
|
||||
adapterType,
|
||||
adapterType: requestAdapterType,
|
||||
providerAdapter: brandType,
|
||||
...(adapterType === "codex_local" && runner !== "auto" ? { runner } : {}),
|
||||
adapterConfig: config,
|
||||
@@ -538,7 +545,7 @@ function Setup({
|
||||
appearance: appearanceDraft.appearance,
|
||||
role: existing.length ? "general" : "ceo",
|
||||
...(leader ? { reportsTo: leader.id } : {}),
|
||||
adapterType,
|
||||
adapterType: requestAdapterType,
|
||||
...(adapterType === "codex_local" && runner !== "auto" ? { runner } : {}),
|
||||
adapterConfig: config,
|
||||
defaultEnvironmentId:
|
||||
|
||||
@@ -200,6 +200,45 @@ afterEach(async () => {
|
||||
container.remove();
|
||||
});
|
||||
describe("New agent setup", () => {
|
||||
it("records an explicit legacy choice when it matches the Mac default, then preserves it on Linux", async () => {
|
||||
settings.get.mockResolvedValue({ defaultEnvironmentId: "local-1" });
|
||||
envApi.list.mockResolvedValue([
|
||||
{ id: "local-1", name: "Mac", driver: "local", status: "active", config: {} },
|
||||
{ id: "linux-ssh", name: "Linux", driver: "ssh", status: "active", config: {} },
|
||||
]);
|
||||
adapterApi.list.mockImplementation(async (context?: { environmentId?: string | null }) => state.adapters.map((adapter: any) =>
|
||||
adapter.type === "codex_local" ? { ...adapter, supportedRunners: context?.environmentId === "linux-ssh" ? ["paperclip", "legacy"] : ["legacy"], defaultRunner: context?.environmentId === "linux-ssh" ? "paperclip" : "legacy" } : adapter));
|
||||
await render("codex_local");
|
||||
await act(async () => (container.querySelector("summary") as HTMLElement).click());
|
||||
const runner = container.querySelector<HTMLButtonElement>('[aria-label="Runner"]')!;
|
||||
expect(runner.textContent).toBe("Legacy runner (default)");
|
||||
await act(async () => runner.click());
|
||||
await act(async () => document.querySelector<HTMLButtonElement>('[role="option"][data-value="legacy"]')!.click());
|
||||
await connect("OpenAI");
|
||||
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", "codex_local", expect.objectContaining({ runner: "legacy" }));
|
||||
const environment = container.querySelector<HTMLSelectElement>('select[aria-label="Environment"]')!;
|
||||
await act(async () => { environment.value = "linux-ssh"; environment.dispatchEvent(new Event("change", { bubbles: true })); });
|
||||
await settle();
|
||||
await connect("OpenAI");
|
||||
await click("Finish setup");
|
||||
expect(api.testEnvironment).toHaveBeenLastCalledWith("company-1", "codex_local", expect.objectContaining({ environmentId: "linux-ssh", runner: "legacy" }));
|
||||
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "codex_local", runner: "legacy" });
|
||||
});
|
||||
|
||||
it("preserves an old native Codex setup link on an unqualified target with the experiment off", async () => {
|
||||
settings.getExperimental.mockResolvedValue({ enableNativeRunner: false });
|
||||
adapterApi.list.mockImplementation(async () => state.adapters.map((adapter: any) => adapter.type === "codex_local" ? { ...adapter, supportedRunners: ["legacy"], defaultRunner: "legacy" } : adapter));
|
||||
api.testEnvironment.mockImplementation(async (_company, adapterType, payload) => {
|
||||
if (adapterType === "codex_local" && payload.runner === "paperclip") throw new Error("This target is not qualified for a new native default.");
|
||||
return { ...pass, adapterType, checks: [{ code: "paperclip_runner_codex_hello_probe_passed", level: "info", message: "Native runtime replied" }] };
|
||||
});
|
||||
await render("paperclip_runner", "codex");
|
||||
await connect("OpenAI");
|
||||
await click("Finish setup");
|
||||
expect(api.testEnvironment).toHaveBeenCalledWith("company-1", "paperclip_runner", expect.objectContaining({ runner: "paperclip", adapterConfig: expect.objectContaining({ provider: "codex" }) }));
|
||||
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "paperclip_runner", runner: "paperclip", adapterConfig: { provider: "codex" } });
|
||||
});
|
||||
|
||||
it("discovers the runner for the selected target and rechecks after changing environments", async () => {
|
||||
settings.get.mockResolvedValue({ defaultEnvironmentId: "linux-ssh" });
|
||||
envApi.list.mockResolvedValue([
|
||||
@@ -801,8 +840,8 @@ describe("New agent setup", () => {
|
||||
await click("Finish setup");
|
||||
const config = api.hire.mock.calls[0][1].adapterConfig;
|
||||
if (runner === "codex") {
|
||||
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "codex_local", runner: "paperclip" });
|
||||
expect(api.testEnvironment).toHaveBeenCalledWith("company-1", "codex_local", expect.objectContaining({ runner: "paperclip" }));
|
||||
expect(api.hire.mock.calls[0][1]).toMatchObject({ adapterType: "paperclip_runner", runner: "paperclip" });
|
||||
expect(api.testEnvironment).toHaveBeenCalledWith("company-1", "paperclip_runner", expect.objectContaining({ runner: "paperclip" }));
|
||||
} else expect(config.provider).toBe(runner === "claude" ? "acpx" : runner);
|
||||
if (runner === "claude") {
|
||||
expect(config.acpxAgent).toBe("claude");
|
||||
@@ -871,6 +910,7 @@ describe("New agent setup", () => {
|
||||
});
|
||||
it("blocks a disabled runner even when opened through a URL", async () => {
|
||||
state.adapters = [
|
||||
{ type: "codex_local", loaded: true, disabled: false },
|
||||
{ type: "paperclip_runner", loaded: true, disabled: true },
|
||||
];
|
||||
await render("paperclip_runner");
|
||||
|
||||
Reference in new issue
Block a user