mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
Use agent AI accounts in SSH environments
Stage the selected agent account in a private remote home and restore refreshed credentials before cleanup. Preserve remote authentication for existing SSH environments and expose it as an advanced option. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
2dcfdabc79
commit
8490bf9df2
41 files changed
+4471
-3774
No files matched your search
@@ -575,6 +575,24 @@ describe("agent test-environment route", () => {
|
||||
expect(mockCopilotModels).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([undefined, true, false])("uses the selected SSH authentication source for probes (%s)", async useHostAuth => {
|
||||
const environmentId = "11111111-1111-4111-8111-111111111111";
|
||||
mockEnvironmentService.getById.mockResolvedValue({ id: environmentId, name: "SSH", driver: "ssh",
|
||||
config: { ...(useHostAuth !== undefined ? { useHostAuth } : {}), host: "fixture.invalid", username: "fixture", remoteWorkspacePath: "/workspace" } });
|
||||
const target = { kind: "remote", transport: "ssh", remoteCwd: "/workspace", spec: { host: "fixture.invalid", port: 22, username: "fixture", remoteCwd: "/workspace", remoteWorkspacePath: "/workspace", useHostAuth } };
|
||||
mockResolveEnvironmentExecutionTarget.mockResolvedValue(target);
|
||||
const response = await request(await createApp()).post("/api/companies/company-1/adapters/external_test/test-environment")
|
||||
.send({ adapterConfig: {}, environmentId });
|
||||
if (useHostAuth === false) {
|
||||
expect(response.status, JSON.stringify(response.body)).toBe(422);
|
||||
expect(response.body.code).toBe("ssh_ai_connection_required");
|
||||
expect(testEnvironmentSpy).not.toHaveBeenCalled();
|
||||
} else {
|
||||
expect(response.status, JSON.stringify(response.body)).toBe(200);
|
||||
expect(testEnvironmentSpy).toHaveBeenCalledWith(expect.objectContaining({ executionTarget: target }));
|
||||
}
|
||||
});
|
||||
|
||||
it("tests the instance default sandbox when the agent inherits its environment", async () => {
|
||||
const environmentId = "11111111-1111-4111-8111-111111111111";
|
||||
mockInstanceSettingsService.get.mockResolvedValue({ defaultEnvironmentId: environmentId });
|
||||
|
||||
@@ -3,6 +3,17 @@ import { HttpError } from "../errors.js";
|
||||
import { normalizeEnvironmentConfig, parseEnvironmentDriverConfig } from "../services/environment-config.ts";
|
||||
|
||||
describe("environment config helpers", () => {
|
||||
it.each([undefined, true, false])("preserves SSH authentication compatibility when useHostAuth is %s", useHostAuth => {
|
||||
const config = normalizeEnvironmentConfig({ driver: "ssh", config: {
|
||||
host: "ssh.example.test", username: "fixture", remoteWorkspacePath: "/workspace",
|
||||
...(useHostAuth !== undefined ? { useHostAuth } : {}),
|
||||
} });
|
||||
expect(config.useHostAuth).toBe(useHostAuth);
|
||||
expect(Object.hasOwn(config, "useHostAuth")).toBe(useHostAuth !== undefined);
|
||||
expect(() => normalizeEnvironmentConfig({ driver: "ssh", config: { ...config, useHostAuth: "false" } })).toThrow(HttpError);
|
||||
});
|
||||
|
||||
|
||||
it("normalizes SSH config into its canonical stored shape", () => {
|
||||
const config = normalizeEnvironmentConfig({
|
||||
driver: "ssh",
|
||||
|
||||
@@ -333,7 +333,7 @@ describePostgres("heartbeat execution configuration through adapter dispatch", (
|
||||
}
|
||||
});
|
||||
|
||||
async function configuration(f: Awaited<ReturnType<typeof seed>>, config: Record<string, unknown>, snapshot: Record<string, unknown> = {}, type = "paperclip_runner", explicitTaskDirectory = false, requestedExecutionWorkspaceMode: HeartbeatExecutionConfigurationInput["policy"]["requestedExecutionWorkspaceMode"] = "shared_workspace", selectedEnvironmentForConfig: HeartbeatExecutionConfigurationInput["environment"]["selectedEnvironmentForConfig"] = null, pinnedSkillTest?: HeartbeatExecutionConfigurationInput["task"]["pinnedSkillTest"], adoptingLiveRunner = false) {
|
||||
async function configuration(f: Awaited<ReturnType<typeof seed>>, config: Record<string, unknown>, snapshot: Record<string, unknown> = {}, type = "paperclip_runner", explicitTaskDirectory = false, requestedExecutionWorkspaceMode: HeartbeatExecutionConfigurationInput["policy"]["requestedExecutionWorkspaceMode"] = "shared_workspace", selectedEnvironmentForConfig: HeartbeatExecutionConfigurationInput["environment"]["selectedEnvironmentForConfig"] = null, pinnedSkillTest?: HeartbeatExecutionConfigurationInput["task"]["pinnedSkillTest"], adoptingLiveRunner = false, aiBinding?: HeartbeatExecutionConfigurationInput["config"]["aiBinding"]) {
|
||||
const [agent] = await db.update(agents).set({ adapterType: type, adapterConfig: config }).where(eq(agents.id, f.agentId)).returning();
|
||||
const [run] = await db.insert(heartbeatRuns).values({ companyId: f.companyId, agentId: f.agentId, issueId: f.issueId, scopeKind: "issue", status: "running", contextSnapshot: snapshot }).returning();
|
||||
const resolvedInstanceSettings = await instanceSettingsService(db).get();
|
||||
@@ -344,7 +344,7 @@ describePostgres("heartbeat execution configuration through adapter dispatch", (
|
||||
task: { issueId: f.issueId, context: { ...snapshot, issueId: f.issueId }, responsibleUserId: null, pinnedSkillTest, adoptingLiveRunner,
|
||||
acceptedPlanContinuationWake: false, acceptedPlanWakeRoutingDecision: null,
|
||||
taskProjectContext: null, routineEnvContext: { routineId: null, env: null, responsibleUserId: null } },
|
||||
config: { sourceWorkspaceConfig: config, aiBinding: undefined },
|
||||
config: { sourceWorkspaceConfig: config, aiBinding },
|
||||
policy: { trustPreset: { kind: "standard", preset: "standard", boundary: null, sourcePresets: {} }, useIsolatedTaskDirectory: false, explicitTaskDirectory, requestedExecutionWorkspaceMode },
|
||||
environment: { selectedEnvironmentId: environment.id, selectedEnvironmentForConfig: environment,
|
||||
resolvedInstanceSettings, persistedNativeExecutionInput: adoptingLiveRunner
|
||||
@@ -356,6 +356,31 @@ describePostgres("heartbeat execution configuration through adapter dispatch", (
|
||||
}) };
|
||||
}
|
||||
|
||||
it.each([undefined, true, false])("defaults existing SSH environments to remote authentication and honors the saved choice (saved=%s)", async useHostAuth => {
|
||||
const f = await seed(true);
|
||||
const environment = { ...await environmentService(db).ensureLocalEnvironment(), driver: "ssh", config: { ...(useHostAuth !== undefined ? { useHostAuth } : {}), host: "fixture.invalid", username: "fixture", remoteWorkspacePath: "/workspace" } } as Environment;
|
||||
const binding = aiConnectionBindingSchema.parse((await db.select().from(agents).where(eq(agents.id, f.agentId)))[0]!.runtimeConfig!.aiConnection);
|
||||
const prepare = vi.spyOn(aiRuntime, "prepareManagedAiRuntime").mockRejectedValue(new Error("fixture managed account reached"));
|
||||
const opening = await configuration(f, { provider: "codex" }, {}, "paperclip_runner", false, "shared_workspace", environment, undefined, false, binding);
|
||||
if (useHostAuth !== false) {
|
||||
const result = await opening.prepare();
|
||||
expect(result.prepared).toBe(true);
|
||||
if (!result.prepared) throw new Error("SSH configuration failed");
|
||||
expect(result.runtimeConfig.homeMode).toBe("preconfigured");
|
||||
expect(prepare).not.toHaveBeenCalled();
|
||||
} else {
|
||||
await expect(opening.prepare()).rejects.toThrow("fixture managed account reached");
|
||||
expect(prepare).toHaveBeenCalledOnce();
|
||||
}
|
||||
});
|
||||
|
||||
it("requires an agent AI account for a new SSH environment when remote authentication is off", async () => {
|
||||
const f = await seed();
|
||||
const environment = { ...await environmentService(db).ensureLocalEnvironment(), driver: "ssh", config: { useHostAuth: false } } as Environment;
|
||||
const opening = await configuration(f, { provider: "codex" }, {}, "paperclip_runner", false, "shared_workspace", environment);
|
||||
await expect(opening.prepare()).rejects.toMatchObject({ resultJson: { configurationIncomplete: { reason: "ssh_ai_connection_required" } } });
|
||||
});
|
||||
|
||||
it("delivers the Studio pin instead of ordinary assignments and recovers that exact native selection", async () => {
|
||||
const f = await seed(), skills = companySkillService(db);
|
||||
const selected = await skills.createLocalSkill(f.companyId, { name: "Unassigned Studio skill", markdown: "# Studio\nOriginal selected bytes.\n" });
|
||||
|
||||
Reference in new issue
Block a user