Files
PaperClipAI/server/src/__tests__/instance-settings-managed-overlay.test.ts
T
Dotta 702368ffaf feat(github): graduate GitHub review bots out of experimental (#22996)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - GitHub Code Review Bot connects an agent to a dedicated GitHub App
so it reviews pull requests and responds to GitHub mentions
> - The feature was gated behind the default-off
`enableGitHubReviewBots` experimental instance setting, hiding the
catalog card, setup routes, identity links, and channel creation
> - People had to find and flip an instance-level experimental switch
before they could connect a GitHub review agent
> - This pull request graduates GitHub review bots to a normal always-on
feature, keeping `enableGitHubReviewBots` only as a deprecated
compatibility key that always resolves to `true`
> - The benefit is that every Paperclip instance exposes GitHub Code
Review Bot setup, discovery, and management by default without requiring
feature flags

## Linked Issues or Issue Description

**What existing behavior does this improve?**
GitHub Code Review Bot discovery, catalog visibility, setup/management
routes, identity-link endpoints, and Agent Channels visibility
(`enableGitHubReviewBots`).

**Subsystem affected**
Cross-cutting (`packages/shared`, `server/`, `ui/`, Storybook, E2E
specs, docs).

**Current behavior**
GitHub Code Review Bot is hidden from Connectors, `connections_search`,
chat-endpoint creation, identity-link confirmation, and UI
setup/settings routes until an instance admin turns on **Settings →
Experimental → GitHub review bots** (`enableGitHubReviewBots`).

**Proposed behavior**
GitHub Code Review Bot is always available as a standard feature on
every instance (self-hosted and Cloud), matching AgentMail and graduated
features such as Assistant connections (`enablePublicMcp`) and the AWS
connector (`enableAwsConnector`). `enableGitHubReviewBots` stays in
schemas and the feature catalog only as a deprecated compatibility key
that always normalizes to `true`, ignores stored or Cloud-managed
`false` values, and does not reject legacy `false` patches. Experimental
chat providers (Slack, Discord, Microsoft Teams, Telegram, iMessage
Photon, Speko) remain gated by `enableChatConnectors`.

**Reason and benefit**
Users can connect and manage GitHub review agents directly from
Connectors without an admin enabling an experimental flag first, and
Cloud stacks no longer require managed feature-flag overrides to expose
GitHub review bots.

**Breaking changes**
No schema migration or breaking API change. Existing rows, API patches,
and Cloud managed configs that still carry `enableGitHubReviewBots`
continue to parse cleanly, while the effective value is always `true`.
Instances that previously kept `enableGitHubReviewBots` off now display
GitHub Code Review Bot in Connectors and allow authorized managers
(`tools:manage_connections`) to create GitHub review bot endpoints.

## What Changed

- `packages/shared`: marked `enableGitHubReviewBots` as a deprecated
compatibility key in types, Zod defaults (`true`), and
`INSTANCE_FEATURE_CATALOG` (`cloudDefault: true`, `selfHostedDefault:
true`); updated `channelMethodEnabled` in `connector-availability.ts` so
`github` is always enabled alongside `agentmail`.
- `server` instance settings and Cloud staging:
`normalizeExperimentalSettings` always returns `enableGitHubReviewBots:
true`; `applyManagedExperimentalOverlay` and `updateExperimental` ignore
retired `enableGitHubReviewBots` entries so Cloud managed configs cannot
turn it off and legacy `false` patches are not rejected; removed
`enableGitHubReviewBots` from `CLOUD_STAGING_EXPERIMENTAL_KEYS`.
- `server` chat channels, discovery, and OpenAPI: allowed `github` in
`assertChatProviderEnabledForCreate`, `assertIdentityProviderEnabled`,
`assertIdentityLinkAccess`, and `connection-intents` discovery without
experimental flags while keeping `enableChatConnectors` enforcement for
experimental chat providers; updated the OpenAPI endpoint description.
- `ui` and Storybook: removed the **GitHub review bots** Experimental
settings toggle card; simplified `useChatConnectorsEnabled` and
`chatProviderVisible` so `github` and `github-code-review-bot` are
always visible; bypassed experimental loading wait for `provider=github`
in `ChatConnectorsExperimentalGate`; made the classic Agent Detail
Channels tab and `AgentChannelsPanel` empty-state copy always reflect
available agent identities; updated `canEnterAppsConnect`, `Browse`,
`ConnectionSetupFlow`, and `github-connections.stories.tsx`.
- Tests, E2E, runner-e2e, docs, and maps: updated unit, integration,
managed-overlay, runner-e2e, and Playwright E2E specs; refreshed
`tests/runner-e2e/source-sdk-public-inputs.json`; updated
`doc/connections/GITHUB.md`, `doc/connections/GITHUB-REVIEW-BOT.md`, and
`maps/feature-map/chat-channels.md`.

## Verification

- `pnpm --filter @paperclipai/shared build && pnpm --filter
@paperclipai/shared typecheck && pnpm --filter @paperclipai/server
typecheck && pnpm --filter @paperclipai/ui typecheck` — passed.
- `node scripts/check-maps.mjs && node scripts/storybook-catalog.mjs` —
passed.
- `pnpm vitest run packages/shared/src/validators/instance.test.ts
packages/shared/src/connector-availability.test.ts
packages/shared/src/feature-catalog.test.ts
server/src/__tests__/instance-settings-service.test.ts
server/src/__tests__/instance-settings-managed-overlay.test.ts
server/src/__tests__/instance-settings-cloud-defaults.test.ts
server/src/routes/chat-channels.identity.test.ts
server/src/__tests__/connection-intents-service.test.ts
server/src/__tests__/chat-channels/slack-ingress-and-threads.integration.test.ts
server/src/__tests__/chat-channels/github-setup-and-access.integration.test.ts`
— all passed.
- `pnpm vitest run ui/src/pages/apps/app-connect-policy.test.ts
ui/src/components/chat/ExternallyConnectedTaskBanner.test.tsx
ui/src/features/connections/ConnectionSetupFlow.slack-oauth.test.tsx` —
3 files, 62 tests passed.
- `pnpm --dir tests/runner-e2e vitest run github-review-journey.test.ts`
— 56 tests passed.
- `pnpm verify --explain` — confirmed
`tests/runner-e2e/source-sdk-public-inputs.json` is current; exited 2
for broad CI coverage (handled by required GitHub CI gates on this PR).

## Risks

- Behavioral shift: instances that had `enableGitHubReviewBots` off now
show GitHub Code Review Bot in Connectors and allow authorized users
with `tools:manage_connections` to configure GitHub review bots.
Existing permission boundaries (`tools:manage_connections`, company
scoping, GitHub App OAuth/installation consent) are unchanged.
- `useIssueChatBinding` now queries `/api/issues/:issueId/chat-binding`
for normal tasks even when `enableChatConnectors` is off so GitHub-bound
task banners remain visible; experimental chat bindings remain filtered
out by `chatProviderVisible` while `enableChatConnectors` is off.
- No database migration is required; stored `enableGitHubReviewBots`
JSON values become inert.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Google Gemini (high reasoning) in Antigravity, with tool use (shell,
file edits, test execution).

## 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
2026-11-25 16:01:38 -06:00

426 lines
20 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { Db } from "@paperclipai/db";
import { INSTANCE_FEATURE_CATALOG } from "@paperclipai/shared";
import {
applyManagedExperimentalOverlay,
instanceSettingsService,
normalizeExperimentalSettings,
} from "../services/instance-settings.js";
import { parseManagedConfigEnv } from "../services/managed-config.js";
import { evaluateExecutionAllowlist } from "../services/execution-allowlist.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 = {
transaction: (fn: (tx: Db) => Promise<unknown>) => fn(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(["team.staging.paperclip.app", "team.paperclip.app"])(
"enables private Notebook through managed config without changing stored opt-out on %s",
async (primaryHost) => {
const row = settingsRow({ enablePaperclipNotebook: false });
const { db, persistedSets } = stubDb(row);
const service = instanceSettingsService(db, { runtimeEnv: {
PAPERCLIP_PRIMARY_HOST: primaryHost,
...managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features: { enablePaperclipNotebook: true }, plugins: { autoInstall: [] },
})),
} });
expect(await service.getExperimental()).toMatchObject({
enablePaperclipNotebook: true,
managedKeys: { enablePaperclipNotebook: { managed: true, managedBy: "paperclip-cloud" } },
});
expect((await service.get()).experimental.enablePaperclipNotebook).toBe(true);
expect(persistedSets).toHaveLength(0);
expect(row.experimental).toEqual({ enablePaperclipNotebook: false });
expect((await instanceSettingsService(db, { runtimeEnv: {} }).getExperimental()).enablePaperclipNotebook).toBe(false);
},
);
it("persists an explicit self-hosted Notebook opt-in and disable across service recreation", async () => {
const row = settingsRow({});
const { db, persistedSets } = stubDb(row);
expect((await instanceSettingsService(db, { runtimeEnv: {} }).getExperimental()).enablePaperclipNotebook).toBe(false);
for (const enabled of [true, false]) {
const service = instanceSettingsService(db, { runtimeEnv: {} });
const updated = await service.updateExperimental({ enablePaperclipNotebook: enabled });
Object.assign(row, persistedSets.at(-1));
expect(updated.experimental.enablePaperclipNotebook).toBe(enabled);
expect((row.experimental as Record<string, unknown>).enablePaperclipNotebook).toBe(enabled);
expect((await instanceSettingsService(db, { runtimeEnv: {} }).getExperimental()).enablePaperclipNotebook).toBe(enabled);
}
});
it.each(["team.staging.paperclip.app", "team.paperclip.app", undefined])(
"enforces every Cloud-enabled flag over old tenant values on %s",
async (primaryHost) => {
const features = Object.fromEntries(Object.entries(INSTANCE_FEATURE_CATALOG)
.filter(([key, entry]) => entry.tier === "managed" && key !== "enableAgentChat")
.map(([key]) => [key, true]));
const stored = Object.fromEntries(Object.keys(features).map((key) => [key, false]));
const { db, persistedSets } = stubDb(settingsRow(stored));
const runtimeEnv = {
PAPERCLIP_PRIMARY_HOST: primaryHost,
...managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features, plugins: { autoInstall: [] },
})),
};
const service = instanceSettingsService(db, { runtimeEnv });
expect(await service.getExperimental()).toMatchObject(features);
expect((await service.get()).experimental).toMatchObject(features);
expect((await service.getExperimental()).managedKeys).toMatchObject(
Object.fromEntries(Object.keys(features)
.filter((key) =>
key !== "enableApps"
&& key !== "enableMcpAggregators"
&& key !== "enablePublicMcp"
&& key !== "enableAwsConnector"
&& key !== "enableGitHubReviewBots")
.map((key) => [key, { managed: true, managedBy: "paperclip-cloud" }])),
);
for (const key of Object.keys(features).filter((key) =>
key !== "enablePublicMcp" && key !== "enableAwsConnector" && key !== "enableGitHubReviewBots")) {
await expect(service.updateExperimental({ [key]: false })).rejects.toMatchObject({
status: 403,
details: { code: "settings_operator_managed" },
});
}
expect(persistedSets).toHaveLength(0);
expect(await instanceSettingsService(db, { runtimeEnv }).getExperimental()).toMatchObject(features);
},
);
it("accepts an old client's write of the retired assistant connections key while Cloud manages it", async () => {
const { db } = stubDb(settingsRow({}));
const runtimeEnv = managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features: { enablePublicMcp: true, enableStatusCards: true }, plugins: { autoInstall: [] },
}));
const service = instanceSettingsService(db, { runtimeEnv });
const updated = await service.updateExperimental({ enablePublicMcp: false, enablePaperclipNotebook: true });
expect(updated.experimental).toMatchObject({ enablePublicMcp: true, enablePaperclipNotebook: true });
});
it("keeps sandbox policy enforced on staging after a tenant tries to disable it", async () => {
const row = settingsRow({ enableManagedSandboxOnly: false });
const { db, persistedSets } = stubDb(row);
const runtimeEnv = {
PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
...managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features: { enableManagedSandboxOnly: true }, plugins: { autoInstall: [] },
})),
};
const service = instanceSettingsService(db, { runtimeEnv });
await expect(service.updateExperimental({ enableManagedSandboxOnly: false })).rejects.toMatchObject({ status: 403 });
expect(persistedSets).toHaveLength(0);
const restored = await instanceSettingsService(db, { runtimeEnv }).getExperimental();
for (const experimental of [await service.getExperimental(), restored]) {
expect(experimental).toMatchObject({
enableManagedSandboxOnly: true,
managedKeys: { enableManagedSandboxOnly: { managed: true, managedBy: "paperclip-cloud" } },
});
expect(evaluateExecutionAllowlist(
{ managedSandboxOnly: experimental.enableManagedSandboxOnly },
{ driver: "local", provider: null },
)).toMatchObject({ allowed: false, deniedDriver: "local" });
}
});
it("lets staging override disabled defaults while keeping Cloud-enabled features managed", async () => {
const row = settingsRow({});
const { db, persistedSets } = stubDb(row);
const runtimeEnv = {
...managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features: { enableStatusCards: true, enableChatConnectors: false, enableNativeRunner: true },
plugins: { autoInstall: [] },
})),
PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
};
const service = instanceSettingsService(db, { runtimeEnv });
const managedKeys = {
enableStatusCards: { managed: true, managedBy: "paperclip-cloud" },
enableNativeRunner: { managed: true, managedBy: "paperclip-cloud" },
};
expect(await service.getExperimental()).toMatchObject({
enableStatusCards: true, enableChatConnectors: false, enableNativeRunner: true, managedKeys,
});
expect(persistedSets).toHaveLength(0);
for (const enabled of [true, false]) {
const updated = await service.updateExperimental({ enableChatConnectors: enabled });
Object.assign(row, persistedSets.at(-1));
const expected = {
enableStatusCards: true, enableChatConnectors: enabled, enableNativeRunner: true, managedKeys,
};
expect(updated.experimental).toMatchObject(expected);
const restored = instanceSettingsService(db, { runtimeEnv });
expect(await restored.getExperimental()).toMatchObject(expected);
expect((await restored.get()).experimental).toMatchObject(expected);
expect(row.experimental).not.toHaveProperty("managedKeys");
expect(row.experimental).not.toHaveProperty("enableStatusCards");
}
expect((await service.updateExperimental({ enableNativeRunner: true })).experimental.enableNativeRunner).toBe(true);
const changedDefaults = instanceSettingsService(db, { runtimeEnv: {
...runtimeEnv,
PAPERCLIP_MANAGED_CONFIG: JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features: { enableStatusCards: false, enableChatConnectors: true, enableNativeRunner: true },
plugins: { autoInstall: [] },
}),
} });
expect(await changedDefaults.getExperimental()).toMatchObject({
enableStatusCards: false, enableChatConnectors: true, enableNativeRunner: true,
});
const production = instanceSettingsService(db, { runtimeEnv: { ...runtimeEnv, PAPERCLIP_PRIMARY_HOST: "team.paperclip.app" } });
expect(await production.getExperimental()).toMatchObject({
enableChatConnectors: false, enableNativeRunner: true,
managedKeys: { enableChatConnectors: { managed: true }, enableNativeRunner: { managed: true } },
});
});
it("preserves Cloud owner access policy on staging", async () => {
const { db } = stubDb(settingsRow({ enableOwnerInstanceAdmin: false }));
const service = instanceSettingsService(db, { runtimeEnv: {
PAPERCLIP_PRIMARY_HOST: "team.staging.paperclip.app",
...managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test",
features: { enableOwnerInstanceAdmin: true }, plugins: { autoInstall: [] },
})),
} });
expect(await service.getExperimental()).toMatchObject({
enableOwnerInstanceAdmin: true,
managedKeys: { enableOwnerInstanceAdmin: { managed: true, managedBy: "paperclip-cloud" } },
});
await expect(service.updateExperimental({ enableOwnerInstanceAdmin: false })).rejects.toMatchObject({ status: 403 });
});
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.each([{}, { enableAwsConnector: false }])("keeps the AWS connector on with legacy stored and managed values: %j", async (stored) => {
const { db } = stubDb(settingsRow(stored));
const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "legacy", features: { enableAwsConnector: false }, plugins: { autoInstall: [] },
})) });
const experimental = await service.getExperimental();
expect(experimental.enableAwsConnector).toBe(true);
expect(experimental.managedKeys).not.toHaveProperty("enableAwsConnector");
expect(await service.updateExperimental({ enableAwsConnector: false })).toMatchObject({ experimental: { enableAwsConnector: true } });
});
it("accepts an old client's write of the retired AWS connector key while Cloud lists it as on", async () => {
const { db } = stubDb(settingsRow({}));
const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({
v: 1, mode: "cloud", catalogVersion: "test", features: { enableAwsConnector: true }, plugins: { autoInstall: [] },
})) });
expect(await service.updateExperimental({ enableAwsConnector: false })).toMatchObject({ experimental: { enableAwsConnector: 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);
});
it("ignores Cloud-managed values for retired enableGitHubReviewBots and allows legacy off patches", async () => {
const managedOff = JSON.stringify({
v: 1,
mode: "cloud",
catalogVersion: "2026.720.0",
features: { enableGitHubReviewBots: false, enableStatusCards: true },
plugins: { autoInstall: [] },
});
const managedOn = JSON.stringify({
v: 1,
mode: "cloud",
catalogVersion: "2026.720.0",
features: { enableGitHubReviewBots: true },
plugins: { autoInstall: [] },
});
const { db } = stubDb(settingsRow({ enableGitHubReviewBots: false }));
const offSvc = instanceSettingsService(db, { runtimeEnv: managedEnv(managedOff) });
const experimental = await offSvc.getExperimental();
expect(experimental.enableGitHubReviewBots).toBe(true);
expect(experimental.managedKeys?.enableGitHubReviewBots).toBeUndefined();
const onSvc = instanceSettingsService(db, { runtimeEnv: managedEnv(managedOn) });
const updated = await onSvc.updateExperimental({ enableGitHubReviewBots: false });
expect(updated.experimental.enableGitHubReviewBots).toBe(true);
expect(updated.experimental.managedKeys?.enableGitHubReviewBots).toBeUndefined();
});
});