mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-30 09:05:15 +01:00
Show CLI as the visible initial engine for fresh legacy agents on active Boat environments and preserve explicit choices through probe and hire. Permit the runtime engine selector on attached Boat environments while retaining managed host-path restrictions and other environment policy. Co-Authored-By: Paperclip <noreply@paperclip.ing>
184 lines
7.0 KiB
TypeScript
184 lines
7.0 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { createRoot } from "react-dom/client";
|
|
import { act } from "react";
|
|
import type { ReactNode } from "react";
|
|
|
|
import type { ComponentType } from "react";
|
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
import { TooltipProvider } from "../components/ui/tooltip";
|
|
import type { AdapterConfigFieldsProps, AdapterConfigSection } from "./types";
|
|
import { CodexLocalConfigFields } from "./codex-local/config-fields";
|
|
import { ClaudeLocalAdvancedFields } from "./claude-local/config-fields";
|
|
import { GeminiLocalConfigFields } from "./gemini-local/config-fields";
|
|
import { ProcessConfigFields } from "./process/config-fields";
|
|
import { OpenClawGatewayConfigFields } from "./openclaw-gateway/config-fields";
|
|
import { HermesGatewayConfigFields } from "./hermes-gateway/config-fields";
|
|
|
|
beforeAll(() => { Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true }); });
|
|
|
|
async function renderMarkup(node: ReactNode, expand?: string): Promise<string> {
|
|
const container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
const root = createRoot(container);
|
|
await act(async () => root.render(node));
|
|
if (expand) await act(async () => {
|
|
container.querySelector(`[aria-label="${expand}"]`)?.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
|
});
|
|
const html = container.innerHTML + Array.from(document.body.children).filter(child => child !== container).map(child => child.outerHTML).join("");
|
|
await act(async () => root.unmount());
|
|
container.remove();
|
|
return html;
|
|
}
|
|
|
|
async function renderSection(
|
|
Component: ComponentType<AdapterConfigFieldsProps>,
|
|
adapterType: string,
|
|
section: AdapterConfigSection,
|
|
config: Record<string, unknown> = {},
|
|
expand?: string,
|
|
) {
|
|
return renderMarkup(
|
|
<TooltipProvider>
|
|
<Component
|
|
mode="edit"
|
|
isCreate={false}
|
|
adapterType={adapterType}
|
|
section={section}
|
|
values={null}
|
|
set={null}
|
|
config={config}
|
|
eff={(_group, _key, original) => original}
|
|
mark={() => {}}
|
|
models={[]}
|
|
hideInstructionsFile
|
|
/>
|
|
</TooltipProvider>,
|
|
expand,
|
|
);
|
|
}
|
|
|
|
describe("adapter configuration sections", () => {
|
|
it.each([
|
|
[CodexLocalConfigFields, "codex_local"], [ClaudeLocalAdvancedFields, "claude_local"],
|
|
] as const)("exposes an attached computer engine without host-path fields: %s %s", async (Component, adapterType) => {
|
|
const html = await renderMarkup(<TooltipProvider><Component
|
|
mode="edit" isCreate={false} adapterType={adapterType} values={null} set={null}
|
|
config={{ engine: "acp", stateDir: "/private/host-state", agentCommand: "/private/host-command" }}
|
|
eff={(_group, _key, original) => original} mark={() => {}} models={[]}
|
|
managedSandboxOnly allowExecutionEngineSelection hideInstructionsFile
|
|
/></TooltipProvider>);
|
|
expect(html).toContain("Execution engine");
|
|
expect(html).toContain('value="cli"');
|
|
expect(html).not.toContain("/private/host-state");
|
|
expect(html).not.toContain("/private/host-command");
|
|
expect(html).not.toContain("ACP server command");
|
|
expect(html).not.toContain("ACP state directory");
|
|
});
|
|
|
|
it("separates provider selection from lifecycle and hides fixed Codex permissions", async () => {
|
|
const config = {
|
|
provider: "codex",
|
|
lifecycleMode: "warm",
|
|
idleTimeoutMs: 45000,
|
|
};
|
|
const adapter = await renderSection(
|
|
CodexLocalConfigFields,
|
|
"paperclip_runner",
|
|
"adapter",
|
|
config,
|
|
);
|
|
const configuration = await renderSection(
|
|
CodexLocalConfigFields,
|
|
"paperclip_runner",
|
|
"configuration",
|
|
config,
|
|
);
|
|
const policy = await renderSection(
|
|
CodexLocalConfigFields,
|
|
"paperclip_runner",
|
|
"runPolicy",
|
|
config,
|
|
);
|
|
expect(adapter).toContain('aria-label="Harness"');
|
|
expect(adapter).not.toContain("Runner lifecycle");
|
|
expect(configuration).not.toContain("Permission mode");
|
|
expect(configuration).not.toContain("Runner lifecycle");
|
|
expect(policy).toContain("Runner lifecycle");
|
|
expect(policy).toContain('value="45000"');
|
|
expect(policy).not.toContain("ACP agents");
|
|
});
|
|
|
|
it("keeps ACP agent admission choices in the adapter section", async () => {
|
|
const config = { provider: "acpx", acpxAgent: "claude" };
|
|
const adapter = await renderSection(CodexLocalConfigFields, "paperclip_runner", "adapter", config, "ACP agent");
|
|
const policy = await renderSection(CodexLocalConfigFields, "paperclip_runner", "runPolicy", config);
|
|
|
|
const options = new DOMParser().parseFromString(adapter, "text/html").querySelectorAll('[role="option"]');
|
|
expect(Array.from(options, option => ({ label: option.textContent?.trim(), disabled: option.hasAttribute("data-disabled") })))
|
|
.toEqual(expect.arrayContaining([
|
|
{ label: "Claude", disabled: false }, { label: "Pi", disabled: false },
|
|
{ label: "Cursor", disabled: false }, { label: "GitHub Copilot — qualification pending", disabled: true },
|
|
]));
|
|
expect(adapter).not.toContain("Runner lifecycle");
|
|
expect(policy).toContain("Runner lifecycle");
|
|
expect(policy).not.toContain("ACP agent");
|
|
expect(policy).not.toContain("qualification pending");
|
|
});
|
|
|
|
it.each([
|
|
["claude_local", ClaudeLocalAdvancedFields],
|
|
["codex_local", CodexLocalConfigFields],
|
|
["gemini_local", GeminiLocalConfigFields],
|
|
] as const)(
|
|
"separates ACP commands and lifecycle for %s",
|
|
async (type, Component) => {
|
|
const config = {
|
|
engine: "acp",
|
|
agentCommand: "saved-command",
|
|
warmHandleIdleMs: 1234,
|
|
};
|
|
expect(await renderSection(Component, type, "advanced", config)).toContain(
|
|
'value="saved-command"',
|
|
);
|
|
expect(
|
|
await renderSection(Component, type, "configuration", config),
|
|
).not.toContain("ACP server command");
|
|
const policy = await renderSection(Component, type, "runPolicy", config);
|
|
expect(policy).toContain("ACP session mode");
|
|
expect(policy).toContain('value="1234"');
|
|
expect(policy).not.toContain("ACP server command");
|
|
},
|
|
);
|
|
|
|
it("keeps process command and arguments under Advanced with saved values", async () => {
|
|
const config = { command: "node", args: ["worker.js", "--quiet"] };
|
|
expect(
|
|
await renderSection(ProcessConfigFields, "process", "configuration", config),
|
|
).toBe("");
|
|
const advanced = await renderSection(
|
|
ProcessConfigFields,
|
|
"process",
|
|
"advanced",
|
|
config,
|
|
);
|
|
expect(advanced).toContain('value="node"');
|
|
expect(advanced).toContain('value="worker.js, --quiet"');
|
|
});
|
|
|
|
it.each([
|
|
["openclaw_gateway", OpenClawGatewayConfigFields],
|
|
["hermes_gateway", HermesGatewayConfigFields],
|
|
] as const)(
|
|
"moves %s timeouts without changing their values",
|
|
async (type, Component) => {
|
|
const config = { timeoutSec: 37 };
|
|
expect(
|
|
await renderSection(Component, type, "configuration", config),
|
|
).not.toContain('value="37"');
|
|
expect(await renderSection(Component, type, "runPolicy", config)).toContain(
|
|
'value="37"',
|
|
);
|
|
},
|
|
);
|
|
});
|