Files
PaperClipAI/server/src/__tests__/instance-settings-managed-overlay.test.ts
T
DottaandPaperclip 9077748894 Remove the Pipelines experiment and preserve its data (#16834)
## Thinking Path

> - Paperclip manages AI agents and their work.
> - Pipelines was an unused experiment with its own UI, API, CLI, and
automation.
> - Keeping it leaves unsupported product surfaces and extra task-detail
queries.
> - Removing the experiment must preserve data that users already saved.
> - This pull request removes the feature and keeps its database schema
and migration history.
> - Cases and Routines remain available as separate features.

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Remove the unused Pipelines experiment across the application.

**Current behavior**

The experiment includes pipeline boards, stage settings, case
automation, review queues, learnings, permissions, and CLI commands.
Task detail also queries pipeline links.

**Proposed behavior**

Remove all these product surfaces and their implementation. Preserve
existing tables, records, and documents. Ignore the retired boolean in
older managed configurations so upgrades still start.

**Breaking changes**

Pipeline URLs, API endpoints, CLI commands, and `pipelines:write` are
removed. Task detail no longer includes the old `linkedCases` field. The
independent Cases API remains available. No database migration or
cleanup is included.

Related feature work: #7907, #9110, #10905, #11375, #13004, #14671,
#16133. Related issues: #9663, #10310, #10312. This removal supersedes
the feature; it does not implement those pending enhancements or delete
their saved data.

## What Changed

- Remove Pipeline UI pages, navigation, gates, clients, query keys,
helpers, and unused design tokens.
- Remove Pipeline REST routes, services, automation dispatch,
task-detail queries, and OpenAPI discovery.
- Remove the CLI commands, shared contracts, experimental flag, catalog
entry, and permission defaults.
- Remove feature-specific tests, tutorials, smoke scripts, maps, and
Storybook examples.
- Preserve database schema, migration history, and the reserved document
key used by old records.
- Keep Cases routes independent and cover obsolete stored and managed
settings.

## Verification

- Passed: `pnpm build` and `pnpm -r typecheck`.
- Passed: targeted settings, managed configuration, sidebar, settings
UI, routing, and feature-catalog tests. A first sidebar run caught a
shared Workspaces icon import; the import was restored and the sidebar
rerun passed.
- Passed: 40 tests covering Cases routes, OpenAPI discovery, retained
Pipeline table constraints, and schema snapshot drift.
- Passed: token gates, map validation, generated API metadata check,
Storybook catalog validation, and 28 map/catalog tests.
- Passed: isolated local browser verification of navigation and
Experimental settings with Pipelines absent; Cases and Routines still
open normally. Live GET/POST requests to retired Pipeline endpoints
return 404, and the retired setting is absent. CLI help has no Pipeline
commands.
- Passed: 22 access-service and agent-default-grant tests after
restoring unrelated permission assertions flagged in review.
- Local full run: `pnpm test:run` reported one failure in the unchanged
workspace-runtime port-allocation test. That test passed in an isolated
rerun. The long local run was stopped after full CI passed; it is not
reported as a complete local pass.
- Passed: all 56 checks on `def9181f3a4491d95fca1d38e9739f5b821aae3e` (2
conditional checks skipped), including build, typecheck, test shards,
and browser suites. Eleven interrupted CI jobs reported “The operation
was canceled”; their one-time retry passed. [CI
run](https://github.com/paperclipai/paperclip/actions/runs/39255211006).
- Greptile: 5/5 on the final commit, with the only review finding fixed
and resolved.
- Sandbox socket restrictions affected the first build/API test
attempts. The same commands ran with local sockets available.

## Risks

- Existing Pipeline clients must stop using the removed endpoints and
commands.
- Existing data remains in the database and backups, but the removed UI
no longer displays it.
- Historical boolean `enablePipelines` values are ignored. They cannot
restore the feature.
- Cases and Routines must retain their separate behavior. Targeted route
tests cover this boundary.

## Model Used

OpenAI Codex, GPT-6, with repository inspection, editing, shell
execution, and browser verification. The exact deployed model ID and
context-window size are not exposed in this session.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-19 08:09:46 -05:00

192 lines
8.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { Db } from "@paperclipai/db";
import {
applyManagedExperimentalOverlay,
instanceSettingsService,
normalizeExperimentalSettings,
} from "../services/instance-settings.js";
import { parseManagedConfigEnv } from "../services/managed-config.js";
const MANAGED_RAW = JSON.stringify({
v: 1,
mode: "cloud",
catalogVersion: "2026.720.0",
// enableApps is retained only for compatibility and must be ignored;
// enableStatusCards remains a live managed feature.
features: { enableApps: false, enableStatusCards: true },
plugins: { autoInstall: [] },
});
function managedEnv(raw: string | undefined = MANAGED_RAW) {
return { PAPERCLIP_MANAGED_CONFIG: raw };
}
/**
* Minimal stand-in for the drizzle query chains instanceSettingsService uses.
* Captures every `update().set()` payload so tests can assert what would be
* persisted.
*/
function stubDb(row: Record<string, unknown>) {
const persistedSets: Array<Record<string, unknown>> = [];
const db = {
select: () => ({ from: () => ({ where: () => Promise.resolve([row]) }) }),
insert: () => {
throw new Error("unexpected insert in test");
},
update: () => ({
set: (values: Record<string, unknown>) => {
persistedSets.push(values);
return { where: () => ({ returning: () => Promise.resolve([{ ...row, ...values }]) }) };
},
}),
} as unknown as Db;
return { db, persistedSets };
}
function settingsRow(experimental: Record<string, unknown>) {
return {
id: "row-1",
singletonKey: "default",
defaultEnvironmentId: null,
general: {},
experimental,
createdAt: new Date("2026-06-20T00:00:00.000Z"),
updatedAt: new Date("2026-06-20T00:00:00.000Z"),
};
}
describe("applyManagedExperimentalOverlay", () => {
it("is the identity with no managed config (self-hosted)", () => {
const experimental = normalizeExperimentalSettings({ enableApps: true });
const result = applyManagedExperimentalOverlay(experimental, null);
expect(result.experimental).toEqual(experimental);
expect(result.managedKeys).toEqual({});
});
it("ignores the retired Apps flag while overlaying live managed values", () => {
const config = parseManagedConfigEnv(managedEnv())!;
const stored = normalizeExperimentalSettings({ enableApps: true });
const { experimental, managedKeys } = applyManagedExperimentalOverlay(stored, config);
expect(experimental.enableApps).toBe(true);
// managed overlay > schema default
expect(experimental.enableStatusCards).toBe(true);
// unmanaged keys keep their stored/default values
expect(experimental.enableCases).toBe(false);
expect(managedKeys).toEqual({
enableStatusCards: { managed: true, managedBy: "paperclip-cloud" },
});
// input is not mutated
expect(stored.enableApps).toBe(true);
});
});
describe("instanceSettingsService managed overlay", () => {
it.each([{}, { enableMcpAggregators: false }])("keeps aggregators on with legacy stored and managed values: %j", async (stored) => {
const { db } = stubDb(settingsRow({ ...stored, enableChatConnectors: true }));
const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "legacy", features: { enableMcpAggregators: false }, plugins: { autoInstall: [] },
})) });
expect(await service.getExperimental()).toMatchObject({ enableMcpAggregators: true, enableChatConnectors: true, managedKeys: {} });
expect(await service.updateExperimental({ enableMcpAggregators: false })).toMatchObject({ experimental: { enableMcpAggregators: true, enableChatConnectors: true } });
});
it("persists chat connector opt-in and reads it back after service reconstruction", async () => {
const row = settingsRow({});
const { db, persistedSets } = stubDb(row);
const service = instanceSettingsService(db, { runtimeEnv: {} });
expect((await service.getExperimental()).enableChatConnectors).toBe(false);
for (const enabled of [true, false]) {
const updated = await service.updateExperimental({ enableChatConnectors: enabled });
Object.assign(row, persistedSets.at(-1));
expect(updated.experimental.enableChatConnectors).toBe(enabled);
const restored = await instanceSettingsService(db, { runtimeEnv: {} }).getExperimental();
expect(restored).toMatchObject({ enableApps: true, enableChatConnectors: enabled });
}
});
it("overlays the managed chat connector gate without changing stored data", async () => {
const { db, persistedSets } = stubDb(settingsRow({ enableChatConnectors: true }));
const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test", features: { enableChatConnectors: false }, plugins: { autoInstall: [] },
})) });
expect(await service.getExperimental()).toMatchObject({
enableChatConnectors: false,
managedKeys: { enableChatConnectors: { managed: true, managedBy: "paperclip-cloud" } },
});
expect(persistedSets).toHaveLength(0);
});
it("fails closed at construction on a malformed managed config", () => {
const { db } = stubDb(settingsRow({}));
expect(() => instanceSettingsService(db, { runtimeEnv: managedEnv("{bad") })).toThrow(
/PAPERCLIP_MANAGED_CONFIG is not valid JSON/,
);
});
it("overlays managed values on getExperimental and exposes managedKeys", async () => {
const { db } = stubDb(settingsRow({ enableApps: true }));
const svc = instanceSettingsService(db, { runtimeEnv: managedEnv() });
const experimental = await svc.getExperimental();
expect(experimental.enableApps).toBe(true);
expect(experimental.enableStatusCards).toBe(true);
expect(experimental.managedKeys).toEqual({
enableStatusCards: { managed: true, managedBy: "paperclip-cloud" },
});
});
it("overlays managed values on get()", async () => {
const { db } = stubDb(settingsRow({ enableApps: true }));
const svc = instanceSettingsService(db, { runtimeEnv: managedEnv() });
const settings = await svc.get();
expect(settings.experimental.enableApps).toBe(true);
expect(settings.experimental.managedKeys?.enableApps).toBeUndefined();
});
it("leaves the self-hosted read path unchanged (no managedKeys field)", async () => {
const { db } = stubDb(settingsRow({ enableApps: true }));
const svc = instanceSettingsService(db, { runtimeEnv: {} });
const experimental = await svc.getExperimental();
expect(experimental.enableApps).toBe(true);
expect(Object.prototype.hasOwnProperty.call(experimental, "managedKeys")).toBe(false);
expect(experimental).toEqual(normalizeExperimentalSettings({ enableApps: true }));
const settings = await svc.get();
expect(Object.prototype.hasOwnProperty.call(settings.experimental, "managedKeys")).toBe(false);
});
it("never persists the overlay: updates write stored values, responses show managed ones", async () => {
const { db, persistedSets } = stubDb(settingsRow({ enableApps: true }));
const svc = instanceSettingsService(db, { runtimeEnv: managedEnv() });
const updated = await svc.updateExperimental({ enableCases: true });
expect(persistedSets).toHaveLength(1);
const persisted = persistedSets[0]!.experimental as Record<string, unknown>;
// The retired compatibility key normalizes on, independent of the
// managed document's historical value.
expect(persisted.enableApps).toBe(true);
// The overlay-added value is not written.
expect(persisted.enableStatusCards).toBe(false);
expect(persisted.enableCases).toBe(true);
expect(persisted).not.toHaveProperty("managedKeys");
// The response still reflects the overlay.
expect(updated.experimental.enableApps).toBe(true);
expect(updated.experimental.enableStatusCards).toBe(true);
expect(updated.experimental.managedKeys?.enableApps).toBeUndefined();
});
it("does not let managed metadata leak into self-hosted writes", async () => {
const { db, persistedSets } = stubDb(settingsRow({}));
const svc = instanceSettingsService(db, { runtimeEnv: {} });
const updated = await svc.updateExperimental({ enableCases: true });
expect(persistedSets).toHaveLength(1);
expect(persistedSets[0]!.experimental).not.toHaveProperty("managedKeys");
expect(Object.prototype.hasOwnProperty.call(updated.experimental, "managedKeys")).toBe(false);
});
});