mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents use outside services through connections, and the control plane holds each connection's credentials > - Companies want agents to "do things on AWS" with exactly the permissions they choose, without Paperclip storing long-lived AWS keys or rebuilding the AWS API > - AWS hosts an MCP server that runs any AWS API call in its own sandbox, and it accepts a one-hour bearer token that can be minted from IAM credentials > - This pull request adds an AWS connection that mints that token for each connection at call time. The role method proves the connection with the company's workload identity issuer (#22083), so no AWS key is stored > - The benefit is that each AWS connection carries its own role and permissions, AWS enforces them, and agents never see any AWS credential ## Linked Issues or Issue Description Refs #22083 (workload identity issuer) and #22191 (spike findings). **Subsystem affected** Connections (tool access), tool gateway, shared app definitions, instance settings. **Problem or motivation** Paperclip has no way to connect AWS. AWS's hosted MCP server needs a bearer token from AWS Sign-in, minted from IAM credentials. No existing credential path mints a header at call time from a role or key. **Proposed solution** Methods can declare `credentialMinter: "aws_mcp"`. The gateway and connection health checks mint the `Authorization` header at call time, and they share one in-memory cache per connection and grant (about 55 minutes). There are two methods: - Role (`AssumeRoleWithWebIdentity` with a Paperclip-signed connection token). - Access key (the key directly, `GetFederationToken`, or `AssumeRole`). Read-only connections add `ReadOnlyAccess` and `AWSMCPSignInOAuthAccessPolicy` as session policies, so AWS refuses changes. The feature is behind the `enableAwsConnector` experimental setting. **Alternatives considered** - Run AWS's `mcp-proxy-for-aws` process on the control plane. Rejected: it adds a Python runtime and processes, and gives nothing the token exchange does not. - Put credentials in the agent sandbox and use the AWS CLI. Deferred: there is no per-call governance, and every sandbox would need the CLI. - Add a new `credentialSource`. Rejected: it needs a migration, and the `vercel_connect` database rules do not fit stored access keys. ## What Changed - `packages/shared`: - `credentialMinter` on connection methods. The validator requires `mcp_remote` and `api_key`, and does not allow `keyPlacement` or another credential source. - The `aws` app definition (two methods, reviewed tools, `mcpSessionRequired`, experimental key). - The `enableAwsConnector` setting in the catalog, types and validators. - `aws` added to the connectable apps. - `server/src/services/connectors/aws/mcp-credentials.ts`: - Settings parsing and checks. The URL must be AWS's endpoint for the saved region, and the role ARN must be valid. - The minter: role or key session, read-only session policies, Sign-in exchange, cache keyed on settings, key references and status, in-flight de-duplication, eviction. - A plain-language error mapping that never shows AWS's own text, because that text can contain account IDs and ARNs. - Gateway (`resolveCredentialHeadersUnrecorded`), credential access (`resolveCredentialHeaders`), catalog discovery and health-failure mapping: - The AWS branch. - After a 401, the gateway evicts the token and mints again, then requires an explicit retry (no replay). Discovery lists again. - Setup: - Minted methods may save a draft without contacting the provider. The role must trust a connection that already exists. - Saving an AWS role draft publishes the company's issuer, so AWS can validate it when the customer registers it. - `workload-identity.ts`: a draft connection can get a token, so setup can test it. Disabled, archived or switched-off connections still get none. - `server/package.json`: `@aws-sdk/client-sts` and `@aws-sdk/client-signin`. The lockfile is left to the refresh workflow. - Artwork: AWS light and dark marks from LobeHub's MIT icon set (already licensed in the repo). The manifest entry passes the brand checks. - `scripts/ingest-app-definitions.mjs`: minted methods are exempt from the `keyPlacement` requirement. The override source is `scripts/app-definition-overrides/aws.json`. Permission reviews are added. - UI: the experimental settings toggle, in alphabetical position. - Docs: `doc/connections/AWS.md`, the connections index, the issuer API doc (draft rule), and the plan's phase table. ## Verification - `server/src/services/connectors/aws/mcp-credentials.test.ts` (7 tests) covers these items: - Both methods and the read-only policies. - Caching, revision, forced refresh, expiry and eviction. - Concurrent de-duplication. - The error mapping, with no AWS text leaking. - Settings validation, including the URL and region check and the rule that an unknown access level means read only. - `server/src/__tests__/aws-mcp-connector.test.ts` (3 tests, real setup, catalog and gateway code with a fake AWS and a session-requiring fake MCP server) covers these items: - The setting gates setup. - The access key is never sent as a header or stored in config. - A cached token is reused. - After a 401, a fresh token is minted and the call is not replayed. - Role draft-then-resume publishes the issuer. - The signed token has the right `iss`, `sub` and `aud`. - An AWS refusal shows a plain health message without the account ID. - Red/green: - Removing the gateway hook fails the access-key test. - Turning off `mcpSessionRequired` fails both integration tests. - Removing draft support for minted methods fails both integration tests. - Restoring each change passes again. - Nearby suites: `tool-gateway-service`, `tool-access-service`, `remote-mcp-connectors`, `instance-settings-service`, `workload-identity`, plus the new files. 775 of 775 pass. - Shared `app-definitions.test.ts` passes (42), including new `credentialMinter` schema tests. UI `InstanceExperimentalSettings` (63) and the brand asset tests pass. `check-app-brand-assets` validates 112 identities. - Typecheck is clean for `packages/shared`, `server` and `ui`. The only UI errors are in Storybook's generated catalog files, which this worktree has not built. - **Real AWS** (Paperclip dev account, integrated code path, issuer behind a temporary public tunnel): - Access key, read only: 8 tools listed. `run_script` `ListBuckets` succeeded in 8.9 s on a cold sandbox. AWS refused `CreateBucket` ("no session policy allows"). - Role: the draft was saved without contacting AWS, and the issuer was published. After an IAM provider and a role trusting only that connection were created, resuming setup listed 8 tools. `ListBuckets` succeeded in 12.8 s. The role's own permissions refused `CreateBucket`. - This run found two bugs the fakes did not: AWS needs MCP sessions for calls, and the role method needs draft-first setup with the issuer published. Both are fixed and both now have tests. - All IAM users, keys, roles, providers and buckets were deleted, and a listing confirmed it. - Not run: Paperclip Cloud staging (the setting is off by default), and `AssumeRole` from an access key with a role ARN against real AWS (unit tests only). ## Risks - The feature is off by default, behind `enableAwsConnector`. No migration. - New dependencies `@aws-sdk/client-sts` and `@aws-sdk/client-signin` are in the existing `@aws-sdk` family (the server already uses `client-s3`). - Minted tokens are held only in process memory. A restart mints again. A cached token can outlive a deactivated key by up to an hour, unless AWS returns 401, which evicts it. - `aws___run_script` is classified as a write, so the normal approval and ask-first policy applies. Read-only connections rely on AWS session policies. - The guided setup screen and the CloudFormation template are not in this PR. Setup uses the generic form and the documented draft and resume steps. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, AWS SDK for JavaScript against the Paperclip dev AWS account, a Cloudflare quick tunnel, an exploration subagent). ## 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 - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
527 lines
24 KiB
TypeScript
527 lines
24 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { INSTANCE_FEATURE_CATALOG, instanceExperimentalSettingsSchema, type InstanceExperimentalSettings } from "@paperclipai/shared";
|
|
import {
|
|
applyExperimentalSettingsPatch,
|
|
applyCloudCatalogDefaults,
|
|
applyManagedExperimentalOverlay,
|
|
normalizeExperimentalSettings,
|
|
resolveWorktreeRunExecutionActivationState,
|
|
} from "../services/instance-settings.js";
|
|
import type { ManagedInstanceConfig } from "../services/managed-config.js";
|
|
|
|
describe("instance settings service", () => {
|
|
it("retains the legacy composer preference through saved and unrelated settings updates", () => {
|
|
expect(normalizeExperimentalSettings({}).enableLegacyComposerSubmit).toBe(false);
|
|
const enabled = applyExperimentalSettingsPatch({}, { enableLegacyComposerSubmit: true });
|
|
const saved = JSON.parse(JSON.stringify(enabled));
|
|
expect(normalizeExperimentalSettings(saved).enableLegacyComposerSubmit).toBe(true);
|
|
expect(applyExperimentalSettingsPatch(saved, { enableCases: true }).enableLegacyComposerSubmit).toBe(true);
|
|
expect(applyExperimentalSettingsPatch(saved, { enableLegacyComposerSubmit: false }).enableLegacyComposerSubmit).toBe(false);
|
|
});
|
|
it("keeps Agent Chat on for new and existing people, ignoring stored and managed off values", () => {
|
|
expect(instanceExperimentalSettingsSchema.parse({}).enableAgentChat).toBe(true);
|
|
expect(INSTANCE_FEATURE_CATALOG.enableAgentChat).toMatchObject({ cloudDefault: true, selfHostedDefault: true });
|
|
for (const stored of [undefined, null, {}, { enableAgentChat: false }, { enableAgentChat: false, enableCases: "invalid" }]) {
|
|
expect(normalizeExperimentalSettings(stored).enableAgentChat).toBe(true);
|
|
}
|
|
expect(applyExperimentalSettingsPatch({}, { enableAgentChat: false }).enableAgentChat).toBe(true);
|
|
const config: ManagedInstanceConfig = {
|
|
v: 1, mode: "cloud", catalogVersion: "test", plugins: { autoInstall: [] }, environments: [], pluginEnvironments: [],
|
|
features: { enableAgentChat: false },
|
|
};
|
|
const result = applyManagedExperimentalOverlay(normalizeExperimentalSettings({ enableAgentChat: false }), config);
|
|
expect(result.experimental.enableAgentChat).toBe(true);
|
|
expect(result.managedKeys.enableAgentChat).toBeUndefined();
|
|
});
|
|
|
|
it("defaults remote workspace enrollment on while preserving explicit operator choices", () => {
|
|
expect(instanceExperimentalSettingsSchema.parse({}).remoteWorkspaceStorageEnabled).toBe(true);
|
|
expect(INSTANCE_FEATURE_CATALOG.remoteWorkspaceStorageEnabled).toMatchObject({ cloudDefault: true, selfHostedDefault: true });
|
|
for (const stored of [undefined, null, {}, { enableApps: true }, { remoteWorkspaceStorageEnabled: "invalid" }]) {
|
|
expect(normalizeExperimentalSettings(stored).remoteWorkspaceStorageEnabled).toBe(true);
|
|
}
|
|
const disabled = applyExperimentalSettingsPatch({}, { remoteWorkspaceStorageEnabled: false });
|
|
expect(normalizeExperimentalSettings(JSON.parse(JSON.stringify(disabled))).remoteWorkspaceStorageEnabled).toBe(false);
|
|
expect(normalizeExperimentalSettings({ remoteWorkspaceStorageEnabled: false, enableCases: "invalid" }).remoteWorkspaceStorageEnabled).toBe(false);
|
|
expect(applyExperimentalSettingsPatch(disabled, { enableStatusCards: true }).remoteWorkspaceStorageEnabled).toBe(false);
|
|
expect(applyExperimentalSettingsPatch(disabled, { remoteWorkspaceStorageEnabled: true }).remoteWorkspaceStorageEnabled).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
{ stored: {}, managed: undefined, expected: true },
|
|
{ stored: { remoteWorkspaceStorageEnabled: false }, managed: undefined, expected: false },
|
|
{ stored: { remoteWorkspaceStorageEnabled: false }, managed: true, expected: true },
|
|
{ stored: { remoteWorkspaceStorageEnabled: true }, managed: false, expected: false },
|
|
])("respects Cloud enrollment defaults and managed choices: $expected", ({ stored, managed, expected }) => {
|
|
const config: ManagedInstanceConfig = {
|
|
v: 1, mode: "cloud", catalogVersion: "test", plugins: { autoInstall: [] }, environments: [], pluginEnvironments: [],
|
|
features: managed === undefined ? {} : { remoteWorkspaceStorageEnabled: managed },
|
|
};
|
|
const normalized = normalizeExperimentalSettings(stored);
|
|
const result = applyManagedExperimentalOverlay(applyCloudCatalogDefaults(normalized, stored, config), config);
|
|
expect(result.experimental.remoteWorkspaceStorageEnabled).toBe(expected);
|
|
expect(normalized.remoteWorkspaceStorageEnabled).toBe("remoteWorkspaceStorageEnabled" in stored ? stored.remoteWorkspaceStorageEnabled : true);
|
|
expect(result.managedKeys.remoteWorkspaceStorageEnabled).toEqual(managed === undefined
|
|
? undefined : { managed: true, managedBy: "paperclip-cloud" });
|
|
});
|
|
it("keeps Notebook off for legacy or invalid settings and round-trips explicit operator choices", () => {
|
|
for (const stored of [undefined, null, {}, { enableApps: true },
|
|
{ enablePaperclipNotebook: "true" }, { enablePaperclipNotebook: 1 },
|
|
{ enablePaperclipNotebook: true, enableCases: "invalid" }]) {
|
|
expect(normalizeExperimentalSettings(stored).enablePaperclipNotebook).toBe(false);
|
|
}
|
|
const enabled = applyExperimentalSettingsPatch({}, { enablePaperclipNotebook: true });
|
|
const restored = normalizeExperimentalSettings(JSON.parse(JSON.stringify(enabled)));
|
|
expect(restored).toMatchObject({ enablePaperclipNotebook: true, enableMemoryConnectors: false });
|
|
const disabled = applyExperimentalSettingsPatch(restored, { enablePaperclipNotebook: false });
|
|
expect(normalizeExperimentalSettings(JSON.parse(JSON.stringify(disabled))).enablePaperclipNotebook).toBe(false);
|
|
});
|
|
it("keeps OpenAI Dot opt-in and persists its setting independently of its prerequisites", () => {
|
|
expect(normalizeExperimentalSettings({}).enableOpenAiDot).toBe(false);
|
|
const enabled = applyExperimentalSettingsPatch({}, { enableOpenAiDot: true });
|
|
expect(normalizeExperimentalSettings(JSON.parse(JSON.stringify(enabled)))).toMatchObject({
|
|
enableOpenAiDot: true, enablePublicMcp: true,
|
|
});
|
|
expect(applyExperimentalSettingsPatch(enabled, { enableOpenAiDot: false }).enableOpenAiDot).toBe(false);
|
|
});
|
|
it("keeps chat connectors opt-in across legacy storage and patches without disabling Apps", () => {
|
|
for (const stored of [undefined, {}, { enableApps: true }, { enableConferenceRoomChat: true }]) {
|
|
expect(normalizeExperimentalSettings(stored).enableChatConnectors).toBe(false);
|
|
}
|
|
const enabled = applyExperimentalSettingsPatch({}, { enableChatConnectors: true });
|
|
expect(normalizeExperimentalSettings(JSON.parse(JSON.stringify(enabled))).enableChatConnectors).toBe(true);
|
|
const disabled = applyExperimentalSettingsPatch(enabled, { enableChatConnectors: false });
|
|
expect(disabled).toMatchObject({ enableApps: true, enableChatConnectors: false });
|
|
});
|
|
it("keeps GitHub review bots independent across legacy normalization and persistence", () => {
|
|
expect(normalizeExperimentalSettings({ enableChatConnectors: true })).toMatchObject({ enableChatConnectors: true, enableGitHubReviewBots: false });
|
|
const saved = applyExperimentalSettingsPatch({}, { enableGitHubReviewBots: true });
|
|
expect(normalizeExperimentalSettings(JSON.parse(JSON.stringify(saved)))).toMatchObject({ enableChatConnectors: false, enableGitHubReviewBots: true });
|
|
});
|
|
it("ignores retired experimental flags without resetting current settings", () => {
|
|
expect(normalizeExperimentalSettings({
|
|
enableEnvironments: true,
|
|
enableNativeRunner: false,
|
|
enableAiConnectionRouters: false,
|
|
enableManagedSandboxOnly: false,
|
|
enableIsolatedWorkspaces: true,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableBuiltInAgents: true,
|
|
enableGoalsSidebarLink: true,
|
|
enableServerInfoDebugView: true,
|
|
enablePaperclipDeveloperMode: true,
|
|
autoRestartDevServerWhenIdle: true,
|
|
enableWorkspaceBranchReconcileForward: true,
|
|
enableWorkspaceDirtyQuarantineRepair: false,
|
|
enableNewestFirstIssueThread: true,
|
|
enablePipelines: true,
|
|
})).toEqual({
|
|
enableEnvironments: true,
|
|
enableNativeRunner: false,
|
|
remoteWorkspaceStorageEnabled: true,
|
|
enableAiConnectionRouters: false,
|
|
enableManagedSandboxOnly: false,
|
|
enableIsolatedWorkspaces: true,
|
|
enableIsolatedWorkspacesByDefault: false,
|
|
enableStreamlinedLeftNavigation: true,
|
|
enableStreamlinedUi: true,
|
|
enableApps: true,
|
|
enableMcpAggregators: true,
|
|
enableAgentChat: true,
|
|
enablePublicMcp: true,
|
|
enableOpenAiDot: false,
|
|
enableMuse: false,
|
|
enableGrokBot: false,
|
|
enableCombinedInboxTasks: false,
|
|
enableArtifactsV1: true,
|
|
enableChatConnectors: false,
|
|
enableGitHubReviewBots: false,
|
|
enableMemoryConnectors: false,
|
|
enablePaperclipNotebook: false,
|
|
enableGoogleWorkspaceConnector: false,
|
|
enableAwsConnector: false,
|
|
enableConferenceRoomChat: false,
|
|
enableClassicTaskInterface: false,
|
|
enableLegacyComposerSubmit: false,
|
|
enableExternalObjects: false,
|
|
enableSmokeLab: false,
|
|
enableCases: false,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableBuiltInAgents: true,
|
|
enableBetaSkills: false,
|
|
enableSummaries: false,
|
|
enableStatusCards: false,
|
|
enableResponsibilities: false,
|
|
enableDecisions: false,
|
|
enableFastResponses: false,
|
|
enableGoalsSidebarLink: true,
|
|
enableServerInfoDebugView: true,
|
|
enablePaperclipDeveloperMode: true,
|
|
enableSimplifiedEnglishInteractions: false,
|
|
enableFirstTaskPlanProposal: false,
|
|
autoRestartDevServerWhenIdle: true,
|
|
enableWorkspaceBranchReconcileForward: true,
|
|
enableWorkspaceDirtyQuarantineRepair: false,
|
|
enableOwnerInstanceAdmin: false,
|
|
enableSandboxDuplexBridge: false,
|
|
enableMcpTasks: false,
|
|
enableRunnerPreviewIngress: false,
|
|
enableWorktreeRunExecution: false,
|
|
worktreeRunExecutionActivatedAt: null,
|
|
worktreeRunExecutionActivationInstanceId: null,
|
|
});
|
|
});
|
|
|
|
it("defaults streamlined UI on without inheriting the retired navigation preference", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableStreamlinedUi).toBe(true);
|
|
expect(normalizeExperimentalSettings({}).enableStreamlinedUi).toBe(true);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: false }).enableStreamlinedUi,
|
|
).toBe(true);
|
|
expect(normalizeExperimentalSettings({ enableStreamlinedUi: false }).enableStreamlinedUi).toBe(false);
|
|
});
|
|
|
|
it("keeps Apps on for empty, legacy, and explicitly disabled stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableApps).toBe(true);
|
|
expect(normalizeExperimentalSettings({}).enableApps).toBe(true);
|
|
expect(normalizeExperimentalSettings({ enableCases: true }).enableApps).toBe(true);
|
|
expect(normalizeExperimentalSettings({ enableApps: false }).enableApps).toBe(true);
|
|
});
|
|
|
|
it("retains the deprecated ingress key for stored-settings compatibility", () => {
|
|
expect(
|
|
normalizeExperimentalSettings({ enableRunnerPreviewIngress: true })
|
|
.enableRunnerPreviewIngress,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("defaults enableConferenceRoomChat to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableConferenceRoomChat).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableConferenceRoomChat).toBe(false);
|
|
// Rows persisted before the flag existed (PAP-137) must normalize to off.
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true }).enableConferenceRoomChat,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableClassicTaskInterface to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableClassicTaskInterface).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableClassicTaskInterface).toBe(false);
|
|
// The retired enableTaskChatRedesign key must not bleed into the new flag:
|
|
// an install that had the chat redesign ON opted into chat-style, which is
|
|
// now the default — not into the classic view.
|
|
expect(
|
|
normalizeExperimentalSettings({ enableTaskChatRedesign: true }).enableClassicTaskInterface,
|
|
).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableClassicTaskInterface: true }).enableClassicTaskInterface,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("defaults enableSimplifiedEnglishInteractions to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableSimplifiedEnglishInteractions).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableSimplifiedEnglishInteractions).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true })
|
|
.enableSimplifiedEnglishInteractions,
|
|
).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableSimplifiedEnglishInteractions: true })
|
|
.enableSimplifiedEnglishInteractions,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("defaults enableSmokeLab to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableSmokeLab).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableSmokeLab).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableExternalObjects: true }).enableSmokeLab,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableServerInfoDebugView to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableServerInfoDebugView).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableServerInfoDebugView).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ autoRestartDevServerWhenIdle: true }).enableServerInfoDebugView,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enablePaperclipDeveloperMode to false for empty and legacy settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enablePaperclipDeveloperMode).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enablePaperclipDeveloperMode).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableServerInfoDebugView: true })
|
|
.enablePaperclipDeveloperMode,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableGoalsSidebarLink to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableGoalsSidebarLink).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableGoalsSidebarLink).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true }).enableGoalsSidebarLink,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableDecisions to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableDecisions).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableDecisions).toBe(false);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableStreamlinedLeftNavigation: true }).enableDecisions,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults workspace branch repair settings to true for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableWorkspaceBranchReconcileForward).toBe(true);
|
|
expect(normalizeExperimentalSettings({}).enableWorkspaceBranchReconcileForward).toBe(true);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableExperimentalFileViewer: true })
|
|
.enableWorkspaceBranchReconcileForward,
|
|
).toBe(true);
|
|
expect(normalizeExperimentalSettings(undefined).enableWorkspaceDirtyQuarantineRepair).toBe(true);
|
|
expect(normalizeExperimentalSettings({}).enableWorkspaceDirtyQuarantineRepair).toBe(true);
|
|
expect(
|
|
normalizeExperimentalSettings({ enableWorkspaceBranchReconcileForward: false })
|
|
.enableWorkspaceDirtyQuarantineRepair,
|
|
).toBe(true);
|
|
});
|
|
|
|
it("round-trips an enableConferenceRoomChat patch through the update merge", () => {
|
|
// updateExperimental merges `{ ...normalize(current), ...patch }` and
|
|
// re-normalizes; emulate that to prove the flag survives the roundtrip
|
|
// without disturbing other settings.
|
|
const current = normalizeExperimentalSettings({});
|
|
const enabled = normalizeExperimentalSettings({ ...current, enableConferenceRoomChat: true });
|
|
expect(enabled.enableConferenceRoomChat).toBe(true);
|
|
expect(enabled.enableStreamlinedLeftNavigation).toBe(true);
|
|
|
|
const disabled = normalizeExperimentalSettings({ ...enabled, enableConferenceRoomChat: false });
|
|
expect(disabled).toEqual(current);
|
|
});
|
|
|
|
it("rejects non-boolean enableConferenceRoomChat values back to the default", () => {
|
|
expect(
|
|
normalizeExperimentalSettings({ enableConferenceRoomChat: "yes" }).enableConferenceRoomChat,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("defaults enableBuiltInAgents to false for empty and legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableBuiltInAgents).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableBuiltInAgents).toBe(false);
|
|
expect(normalizeExperimentalSettings({ enableExternalObjects: true }).enableBuiltInAgents).toBe(false);
|
|
});
|
|
|
|
it("preserves enableBetaSkills and defaults it off for legacy stored settings", () => {
|
|
expect(normalizeExperimentalSettings(undefined).enableBetaSkills).toBe(false);
|
|
expect(normalizeExperimentalSettings({}).enableBetaSkills).toBe(false);
|
|
expect(normalizeExperimentalSettings({ enableBetaSkills: true }).enableBetaSkills).toBe(true);
|
|
});
|
|
|
|
it("sets worktree run execution activation fields on a false to true transition", () => {
|
|
const activatedAt = new Date("2026-07-10T12:00:00.000Z");
|
|
|
|
const next = applyExperimentalSettingsPatch(
|
|
{ enableWorktreeRunExecution: false },
|
|
{ enableWorktreeRunExecution: true },
|
|
{
|
|
now: () => activatedAt,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(next.enableWorktreeRunExecution).toBe(true);
|
|
expect(next.worktreeRunExecutionActivatedAt).toBe("2026-07-10T12:00:00.000Z");
|
|
expect(next.worktreeRunExecutionActivationInstanceId).toBe("worktree-instance");
|
|
});
|
|
|
|
it("clears worktree run execution activation fields on a true to false transition", () => {
|
|
const next = applyExperimentalSettingsPatch(
|
|
{
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "worktree-instance",
|
|
},
|
|
{ enableWorktreeRunExecution: false },
|
|
{
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(next.enableWorktreeRunExecution).toBe(false);
|
|
expect(next.worktreeRunExecutionActivatedAt).toBeNull();
|
|
expect(next.worktreeRunExecutionActivationInstanceId).toBeNull();
|
|
});
|
|
|
|
it("refreshes the activation cutoff when worktree run execution is re-toggled", () => {
|
|
const firstActivation = applyExperimentalSettingsPatch(
|
|
{ enableWorktreeRunExecution: false },
|
|
{ enableWorktreeRunExecution: true },
|
|
{
|
|
now: () => new Date("2026-07-10T12:00:00.000Z"),
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
const disabled = applyExperimentalSettingsPatch(
|
|
firstActivation,
|
|
{ enableWorktreeRunExecution: false },
|
|
{
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
const secondActivation = applyExperimentalSettingsPatch(
|
|
disabled,
|
|
{ enableWorktreeRunExecution: true },
|
|
{
|
|
now: () => new Date("2026-07-10T12:05:00.000Z"),
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(secondActivation.worktreeRunExecutionActivatedAt).toBe("2026-07-10T12:05:00.000Z");
|
|
expect(secondActivation.worktreeRunExecutionActivatedAt).not.toBe(
|
|
firstActivation.worktreeRunExecutionActivatedAt,
|
|
);
|
|
});
|
|
|
|
it("strips client-supplied activation fields before applying experimental patches", () => {
|
|
const next = applyExperimentalSettingsPatch(
|
|
{ enableWorktreeRunExecution: false },
|
|
{
|
|
enableWorktreeRunExecution: false,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "copied-instance",
|
|
},
|
|
{
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
},
|
|
);
|
|
|
|
expect(next.worktreeRunExecutionActivatedAt).toBeNull();
|
|
expect(next.worktreeRunExecutionActivationInstanceId).toBeNull();
|
|
});
|
|
|
|
it("resolves worktree run execution as armed only when the cutoff matches the current instance", async () => {
|
|
const experimental = normalizeExperimentalSettings({
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "worktree-instance",
|
|
});
|
|
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => experimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toEqual({
|
|
armed: true,
|
|
cutoff: "2026-07-10T12:00:00.000Z",
|
|
activationInstanceId: "worktree-instance",
|
|
reason: null,
|
|
});
|
|
});
|
|
|
|
it("fails closed when worktree run execution is missing a cutoff", async () => {
|
|
const experimental = normalizeExperimentalSettings({
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivationInstanceId: "worktree-instance",
|
|
});
|
|
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => experimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
reason: "missing_cutoff",
|
|
});
|
|
});
|
|
|
|
it("fails closed when worktree run execution was activated by another instance", async () => {
|
|
const experimental = normalizeExperimentalSettings({
|
|
enableWorktreeRunExecution: true,
|
|
worktreeRunExecutionActivatedAt: "2026-07-10T12:00:00.000Z",
|
|
worktreeRunExecutionActivationInstanceId: "source-instance",
|
|
});
|
|
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => experimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "target-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
activationInstanceId: "source-instance",
|
|
reason: "instance_id_mismatch",
|
|
});
|
|
});
|
|
|
|
it("fails closed on settings read errors and avoids reads outside worktree runtimes", async () => {
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental: async () => {
|
|
throw new Error("settings unavailable");
|
|
},
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
reason: "settings_read_error",
|
|
});
|
|
|
|
const getExperimental = vi.fn<() => Promise<InstanceExperimentalSettings>>();
|
|
await expect(
|
|
resolveWorktreeRunExecutionActivationState({
|
|
getExperimental,
|
|
runtimeEnv: {
|
|
PAPERCLIP_IN_WORKTREE: "false",
|
|
PAPERCLIP_INSTANCE_ID: "worktree-instance",
|
|
},
|
|
}),
|
|
).resolves.toMatchObject({
|
|
armed: false,
|
|
cutoff: null,
|
|
reason: "not_worktree_runtime",
|
|
});
|
|
expect(getExperimental).not.toHaveBeenCalled();
|
|
});
|
|
|
|
});
|