mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 08:22:20 +02:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Its tool gateway applies company access rules and approval controls to connected apps. > - MCP aggregators expose many apps through one provider endpoint. > - Each aggregator needs its own credential, catalog, grants, and lifecycle in Paperclip. > - This pull request adds independent Zapier, Arcade, Composio Connect, and Executor setup with a common Access → Connect layout. > - A default-off MCP aggregators flag lets operators opt in while we complete provider acceptance tests. > - Agents use the normal Paperclip permissions, Test screen, and gateway after setup. ## Linked Issues or Issue Description **Subsystem affected** Apps, connection setup, shared contracts, and the remote MCP gateway. **Problem or motivation** Aggregator endpoints need clear provider setup and correct MCP sessions. Generic setup does not explain each provider's authentication or broad execution tools. Provider approval must preserve the original execution instead of replaying a write. **Proposed solution** Add four separate connectors behind Settings → Experimental → MCP aggregators. Start with human and agent access, then connect the endpoint and read its tools. Enable tools by default. Use the existing Permissions and Test screens after setup. Keep legacy Composio API-key and child connections intact. **Alternatives considered** A shared connection for all providers would mix credentials and access rules. Separate provider-specific permission and test screens would duplicate existing controls. Vercel Connect is outside this change. **Roadmap alignment** Extends the existing MCP Tool Gateway & Apps capability and the Connected Apps roadmap area. This work was requested and reviewed by the maintainer. Related work: #11894, #12630, #12632, #12634, and #12906 concern the legacy Composio broker. #13102 also covers remote MCP pagination. This change preserves the broker path and adds initialized sessions, response matching, and provider resume handling alongside pagination. ## What Changed - Add branded setup and interactive Storybooks for Zapier, Arcade, Composio Connect, and Executor. Use the existing access controls and normal action tests. Do not request a connection name or action choices during setup. - Add the default-off `enableMcpAggregators` flag to settings, managed feature metadata, the catalog, and setup guards. Hidden connections keep running. Legacy Composio connections remain unchanged. - Reuse the vault, grants, policy, and catalog models. Support OAuth discovery, bearer tokens, custom headers, and credential-bearing URLs. Add no database tables or migrations. - Initialize and retain Streamable HTTP sessions by connection and effective credentials. Read paginated catalogs and match streaming responses to request IDs. - Classify unfamiliar aggregator tools as writes despite upstream read-only hints; only exact reviewed read capabilities enter the read-only allowlist. Legacy Composio child behavior is preserved. - Preserve provider authorization links and execution IDs. Support Executor approve/resume, decline, and cancel without automatic replay of uncertain writes. - Preserve Off and Ask first choices during refresh and reconnect. Allow new tools and retire removed tools. Keep agent access updates atomic and preserve an empty agent selection. - Document connector UX rules, provider branding sources, and live acceptance results. - Stabilize the existing Sentry release fixture after its repeated CI failure by reusing one module mock; production Sentry behavior is unchanged. ## Verification - Final head `d11781970`: [CI run](https://github.com/paperclipai/paperclip/actions/runs/35633534900) passed, including broad typecheck, test shards, build, and E2E. All 54 checks pass; 2 optional checks are skipped. Greptile is 5/5, Security Scan passes, and all review threads are resolved. - Passed 27 focused connector Vitest checks and 18 connector-only Storybook browser checks before the flag change. All 85 stories rendered at desktop and narrow widths. - Passed 5 connector lifecycle/server checks and 7 selected flag checks after adding the flag. The latter cover settings, managed defaults, cached catalog visibility, and all four setup routes. - Review fixes passed 13 risk/handoff/lifecycle checks, dedicated session-expiration and transport regressions, 13 selected connector/gateway CI cases, and 10 selected setup/reconnect UI cases. A real Composio connection-list call also succeeded through the refreshed UI on `9ab115f71`. - UI and server TypeScript checks passed. UI build, Storybook build, token gates, and diff whitespace checks passed during implementation. - Real browser and real Paperclip agent tests passed for Arcade, Composio, and Executor. Tested action permissions, denied agent access, reconnect, disconnect, and isolation. Tested Arcade catalog additions/removal and Executor provider approve/resume, decline, and cancel. - Zapier live acceptance is incomplete. Its dedicated provider server is configured, but its credential-copy dialog returned an empty clipboard through browser automation. No live Zapier action is claimed. - The three isolated Sentry release cases pass after the CI fixture fix. - Local verification is deliberately narrow at the maintainer's request. The full local suite, recursive typecheck, and repository-wide build were not run. CI provides the broader checks. ## Risks - Shared MCP transport changes affect other remote MCP servers. Protocol fixtures cover initialized sessions, streaming response matching, pagination, and isolation. - Broad execution tools remain broad permissions. The provider governs actions inside those tools. - Provider handoff links are retained briefly in memory. After a server restart, a one-time link may require reopening the provider dashboard. Paperclip does not replay the original call. - Zapier remains unproven live. Custom-header imports and self-hosted endpoints have fixture coverage rather than a separate live account for every variant. - Turning the experimental flag off hides setup; it does not revoke existing credentials or stop existing connections. ## Model Used OpenAI GPT-6 through Codex, with reasoning, repository tools, shell execution, and browser automation. The exact runtime model ID and context-window size are not exposed in this session. A separate Anthropic-backed Paperclip agent performed live gateway acceptance tasks. ## 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>
427 lines
17 KiB
TypeScript
427 lines
17 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import type { InstanceExperimentalSettings } from "@paperclipai/shared";
|
|
import {
|
|
applyExperimentalSettingsPatch,
|
|
normalizeExperimentalSettings,
|
|
resolveWorktreeRunExecutionActivationState,
|
|
} from "../services/instance-settings.js";
|
|
|
|
describe("instance settings service", () => {
|
|
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("ignores retired experimental flags without resetting current settings", () => {
|
|
expect(normalizeExperimentalSettings({
|
|
enableEnvironments: true,
|
|
enableNativeRunner: 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,
|
|
})).toEqual({
|
|
enableEnvironments: true,
|
|
enableNativeRunner: false,
|
|
enableManagedSandboxOnly: false,
|
|
enableIsolatedWorkspaces: true,
|
|
enableIsolatedWorkspacesByDefault: false,
|
|
enableStreamlinedLeftNavigation: true,
|
|
enableStreamlinedUi: true,
|
|
enableApps: true,
|
|
enableAgentChat: false,
|
|
enableChatConnectors: false,
|
|
enableMcpAggregators: false,
|
|
enableConferenceRoomChat: false,
|
|
enableClassicTaskInterface: false,
|
|
enableExternalObjects: false,
|
|
enableSmokeLab: false,
|
|
enablePipelines: false,
|
|
enableCases: false,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableBuiltInAgents: true,
|
|
enableBetaSkills: false,
|
|
enableSummaries: false,
|
|
enableStatusCards: false,
|
|
enableDecisions: false,
|
|
enableGoalsSidebarLink: true,
|
|
enableServerInfoDebugView: true,
|
|
enablePaperclipDeveloperMode: true,
|
|
enableSimplifiedEnglishInteractions: false,
|
|
enableFirstTaskPlanProposal: false,
|
|
autoRestartDevServerWhenIdle: true,
|
|
enableWorkspaceBranchReconcileForward: true,
|
|
enableWorkspaceDirtyQuarantineRepair: false,
|
|
enableOwnerInstanceAdmin: false,
|
|
enableSandboxDuplexBridge: 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({ enablePipelines: 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();
|
|
});
|
|
|
|
});
|