Make harness choices deployment-configurable

Managed deployments need to control harness availability without changing Core policy. Add a generic environment contract and apply it across harness and model selectors, preserving saved supported profiles and validating import, team, and invite selections. Document deployment ownership in agent guidance.

Validation: focused local tests and typechecks passed; all applicable CI checks passed on the reviewed head. Greptile scored 5/5 with no unresolved comments.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip authored and GitHub committed 2026-11-20 15:45:36 -08:00
1 parent 104f323bee
commit ae2afd525b
35 files changed
+822 -88

No files matched your search

@@ -0,0 +1,30 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { logger } from "../middleware/logger.js";
import { getAvailableHarnesses } from "../services/harness-availability.js";
describe("deployment harness availability", () => {
afterEach(() => vi.restoreAllMocks());
it("has no built-in deployment allowlist", () => {
expect(getAvailableHarnesses({})).toBeUndefined();
});
it("accepts deployment-chosen IDs and refreshes when configuration changes", () => {
const env = { PAPERCLIP_AVAILABLE_HARNESSES: '["gemini_local","plugin:example","gemini_local"]' };
expect(getAvailableHarnesses(env)).toEqual(["gemini_local", "plugin:example"]);
env.PAPERCLIP_AVAILABLE_HARNESSES = '["pi_local"]';
expect(getAvailableHarnesses(env)).toEqual(["pi_local"]);
env.PAPERCLIP_AVAILABLE_HARNESSES = "[]";
expect(getAvailableHarnesses(env)).toEqual([]);
expect(getAvailableHarnesses({})).toBeUndefined();
});
it.each(["", "claude_local", "{}", "null", '["valid",1]', '["Invalid"]', '["has space"]', JSON.stringify(["a".repeat(129)]), JSON.stringify(Array(129).fill("codex_local")), " ".repeat(16_385)])(
"fails closed for malformed configuration %# without logging its value", raw => {
getAvailableHarnesses({});
const warn = vi.spyOn(logger, "warn").mockImplementation(() => undefined);
expect(getAvailableHarnesses({ PAPERCLIP_AVAILABLE_HARNESSES: raw })).toEqual([]);
expect(warn).toHaveBeenCalledExactlyOnceWith("PAPERCLIP_AVAILABLE_HARNESSES is invalid; harness selection is disabled");
},
);
});
+14
View File
@@ -116,6 +116,20 @@ describe("GET /health", () => {
});
});
it("publishes deployment harness policy and reflects configuration updates", async () => {
const env = {
PAPERCLIP_CLOUD_TENANT_SERVER_TOKEN: "tenant-token",
PAPERCLIP_PRIMARY_HOST: "example.paperclip.app",
PAPERCLIP_AVAILABLE_HARNESSES: '["gemini_local","plugin:example"]',
};
const app = createApp(undefined, testServerInfo, undefined, env);
expect((await request(app).get("/health")).body.cloud.availableHarnesses).toEqual(["gemini_local", "plugin:example"]);
env.PAPERCLIP_AVAILABLE_HARNESSES = "[]";
expect((await request(app).get("/health")).body.cloud.availableHarnesses).toEqual([]);
env.PAPERCLIP_AVAILABLE_HARNESSES = "invalid";
expect((await request(app).get("/health")).body.cloud.availableHarnesses).toEqual([]);
});
it("lists operator-hidden settings and drops unknown keys", async () => {
const app = createApp(undefined, testServerInfo, undefined, {
PAPERCLIP_HIDDEN_SETTINGS: "instance.plugins,instance.adapters,instance.bogus",
+3
View File
@@ -20,6 +20,7 @@ import {
} from "../services/cloud-instance.js";
import { getCloudRuntimeIdentity } from "../services/cloud-runtime-identity.js";
import { getHiddenSettings } from "../services/settings-visibility.js";
import { getAvailableHarnesses } from "../services/harness-availability.js";
import {
inspectDatabaseBackupHealth,
type DatabaseBackupHealthStatus,
@@ -102,12 +103,14 @@ function getCloudHealthStatus(env: CloudInstanceEnv) {
const context = getCloudStackContext(env);
if (!context) return undefined;
const runtimeIdentity = env === process.env ? getCloudRuntimeIdentity() : null;
const availableHarnesses = getAvailableHarnesses(env);
return {
managed: true as const,
managedBy: "paperclip-cloud" as const,
stackSlug: context.stackSlug,
cloudBaseUrl: context.cloudOrigin,
...(availableHarnesses !== undefined ? { availableHarnesses } : {}),
...(runtimeIdentity ? {
runtimeIdentity: {
canonicalOrigin: runtimeIdentity.canonicalOrigin,
@@ -0,0 +1,28 @@
import { logger } from "../middleware/logger.js";
export const AVAILABLE_HARNESSES_ENV_KEY = "PAPERCLIP_AVAILABLE_HARNESSES";
const harnessId = /^[a-z][a-z0-9_:-]{0,127}$/;
let cache: { raw: string | undefined; available: string[] | undefined } | undefined;
/** Unset leaves existing choices intact; an empty array or invalid value allows none. */
export function getAvailableHarnesses(env: Record<string, string | undefined> = process.env): string[] | undefined {
const raw = env[AVAILABLE_HARNESSES_ENV_KEY];
if (cache && cache.raw === raw) return cache.available;
let available: string[] | undefined;
if (raw !== undefined) {
let entries: unknown;
try {
entries = raw.length <= 16_384 ? JSON.parse(raw) : null;
} catch {
entries = null;
}
if (!Array.isArray(entries) || entries.length > 128 || entries.some((entry) => typeof entry !== "string" || !harnessId.test(entry))) {
logger.warn(`${AVAILABLE_HARNESSES_ENV_KEY} is invalid; harness selection is disabled`);
available = [];
} else {
available = [...new Set(entries)];
}
}
cache = { raw, available };
return available;
}