Files
PaperClipAI/server/src/__tests__/ephemeral-server-contract.test.ts
T
DottaandClaude Opus 5.5 12fc89b1f7 fix(cloud): let an online move proceed when Cloud supplies the database listener (#22263)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Hosted Paperclip servers can move from a server with a volume to a
volume-free server, which allows deploys without downtime
> - Before the move, Core checks that the volume-free configuration is
complete
> - That check requires `PAPERCLIP_DATABASE_LISTEN_URL` on the running
volume server, but only the volume-free replacement uses it, and Cloud
supplies it when it configures that replacement
> - Many older servers never had the setting, so they cannot move online
even when all their data is ready
> - This pull request stops an unset listener from blocking, and keeps a
listener that points at another database as a blocker
> - The benefit is that older servers can move online

## Linked Issues or Issue Description

**What existing behavior does this improve?**
The online move refuses a volume server that has no
`PAPERCLIP_DATABASE_LISTEN_URL`.

**Subsystem affected**
Server: ephemeral enrollment readiness
(`server/src/services/ephemeral-enrollment.ts`).

**Current behavior**
The eligibility read and preparation report
`volume_free_database_listener_required` for every server that has no
listener setting.

**Proposed behavior**
An unset listener does not block. A listener that does not match the
runtime database still blocks with the same name.

**Reason and benefit**
The replacement server receives the listener from Cloud. On staging,
this check alone blocks 18 servers whose data is otherwise ready.

**Breaking changes**
None. The startup contract for a running volume-free server is
unchanged.

## What Changed

- `services/ephemeral-enrollment.ts`: when the only configuration
failure is the listener, and the listener is unset, the readiness check
passes. The listener check is the last check in
`assertEphemeralServerConfig`, so all earlier settings were already
valid.
- `services/ephemeral-enrollment.test.ts`: tests for an unset listener
(eligible, and preparation succeeds) and a mismatched listener (still
blocked).

## Verification

- `npx vitest run src/services/ephemeral-enrollment.test.ts
src/routes/ephemeral-enrollment.test.ts`: 29/29 pass.

## Risks

- Low. Cloud's online arming passes `PAPERCLIP_DATABASE_LISTEN_URL` with
the replacement's variables. If the replacement did not get the setting,
the existing startup contract would still refuse to boot it, and the
move would not complete.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits, browser).

## 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>
2026-11-18 20:39:56 -06:00

70 lines
5.9 KiB
TypeScript

import { afterEach, expect, it, vi } from "vitest";
import { assertEphemeralServerConfig } from "../services/ephemeral-server-contract.js";
import { assertEphemeralWorkspaceExecution, assertEphemeralNativeRuntime, shouldUseRemoteWorkspaces } from "../services/remote-workspaces.js";
import { assertEphemeralAgentInstructions } from "../services/agent-instructions.js";
const config = { databaseUrl: "postgresql://runtime:fixture@ep-example-pooler.neon.test/tenant", storageProvider: "s3" as const };
const env = { PAPERCLIP_EPHEMERAL_SERVER: "true", PAPERCLIP_DURABLE_AGENT_FILES: "true", PAPERCLIP_SHARED_UI_ASSETS: "true",
PAPERCLIP_DECISION_SIGNING_SECRET: "synthetic-decision-key-for-deployment-tests",
PAPERCLIP_SECRETS_MASTER_KEY: Buffer.alloc(32, 7).toString("base64"), // 32-byte fixture, never an operator key
PAPERCLIP_DATABASE_LISTEN_URL: "postgresql://runtime:fixture@ep-example.neon.test/tenant" };
afterEach(() => vi.unstubAllEnvs());
it("requires shared storage and stable secrets without changing volume-backed startup", () => {
expect(assertEphemeralServerConfig(config, env)).toBe(env.PAPERCLIP_DATABASE_LISTEN_URL);
expect(assertEphemeralServerConfig({ storageProvider: "local_disk", databaseUrl: undefined }, {})).toBeNull();
for (const key of ["PAPERCLIP_DURABLE_AGENT_FILES", "PAPERCLIP_SHARED_UI_ASSETS", "PAPERCLIP_SECRETS_MASTER_KEY", "PAPERCLIP_DECISION_SIGNING_SECRET", "PAPERCLIP_DATABASE_LISTEN_URL"]) {
expect(() => assertEphemeralServerConfig(config, { ...env, [key]: "" })).toThrow("Volume-free server configuration");
}
expect(() => assertEphemeralServerConfig({ ...config, storageProvider: "local_disk" }, env)).toThrow("shared S3");
});
it("waives an absent listener only for a caller that opts in, and still requires a postgres runtime database", () => {
const unset = { ...env, PAPERCLIP_DATABASE_LISTEN_URL: "" };
expect(() => assertEphemeralServerConfig(config, unset)).toThrow(/PAPERCLIP_DATABASE_LISTEN_URL/);
expect(assertEphemeralServerConfig(config, unset, { allowMissingListener: true })).toBeNull();
expect(() => assertEphemeralServerConfig({ ...config, databaseUrl: "not a url" }, unset, { allowMissingListener: true }))
.toThrow(/an external postgres DATABASE_URL is required/);
expect(() => assertEphemeralServerConfig({ ...config, databaseUrl: "mysql://runtime@db.test/tenant" }, unset, { allowMissingListener: true }))
.toThrow(/an external postgres DATABASE_URL is required/);
expect(() => assertEphemeralServerConfig(config, { ...env, PAPERCLIP_DATABASE_LISTEN_URL: "postgres://runtime:fixture@other.test/tenant" },
{ allowMissingListener: true })).toThrow(/direct connection to the same database/);
});
it("never connects the listener with migration privileges, another tenant, or through a transaction pooler", () => {
for (const url of [env.PAPERCLIP_DATABASE_LISTEN_URL.replace("runtime:", "migration:"),
env.PAPERCLIP_DATABASE_LISTEN_URL.replace("/tenant", "/neighbor"), config.databaseUrl,
env.PAPERCLIP_DATABASE_LISTEN_URL.replace("ep-example.", "ep-neighbor.")]) {
expect(() => assertEphemeralServerConfig(config, { ...env, PAPERCLIP_DATABASE_LISTEN_URL: url })).toThrow("runtime role");
}
});
it("requires remote workspace authority and native execution independently of provider lifecycle", () => {
vi.stubEnv("PAPERCLIP_EPHEMERAL_SERVER", "true");
const remote = { externalConversation: false, adapterType: "paperclip_runner", pluginTaskWorkspace: false, remoteAuthority: true };
expect(() => assertEphemeralWorkspaceExecution(remote)).not.toThrow();
expect(() => assertEphemeralWorkspaceExecution({ ...remote, remoteAuthority: false, pluginTaskWorkspace: true })).not.toThrow();
for (const patch of [{ remoteAuthority: false }, { adapterType: "process" }]) {
expect(() => assertEphemeralWorkspaceExecution({ ...remote, ...patch })).toThrow("native Paperclip Runner");
}
expect(() => assertEphemeralNativeRuntime(true)).not.toThrow();
expect(() => assertEphemeralNativeRuntime(false)).toThrow("native Paperclip Runner");
const agent = { id: "agent", companyId: "company", name: "Agent", adapterConfig: {} };
expect(() => assertEphemeralAgentInstructions(agent)).not.toThrow();
expect(() => assertEphemeralAgentInstructions({ ...agent, adapterConfig: { instructionsBundleMode: "external", instructionsRootPath: "/old-volume" } })).toThrow("managed agent instructions");
vi.stubEnv("PAPERCLIP_EPHEMERAL_SERVER", "false");
expect(() => assertEphemeralWorkspaceExecution({ ...remote, remoteAuthority: false })).not.toThrow();
expect(() => assertEphemeralNativeRuntime(false)).not.toThrow();
});
it.each(["claude_local", "codex_local", "cursor", "gemini_local", "grok_local", "kimi_local", "opencode_local", "pi_local"])("admits %s over SSH only with durable remote workspace authority", adapterType => {
vi.stubEnv("PAPERCLIP_EPHEMERAL_SERVER", "true");
vi.stubEnv("DATABASE_URL", config.databaseUrl);
vi.stubEnv("PAPERCLIP_STORAGE_PROVIDER", "s3");
vi.stubEnv("PAPERCLIP_SECRETS_MASTER_KEY", env.PAPERCLIP_SECRETS_MASTER_KEY);
const remote = { externalConversation: false, adapterType, environmentDriver: "ssh", pluginTaskWorkspace: false, remoteAuthority: true };
expect(shouldUseRemoteWorkspaces({ adapterType, environmentDriver: "ssh", experimentalEnabled: true })).toBe(true);
expect(() => assertEphemeralWorkspaceExecution(remote)).not.toThrow();
expect(() => assertEphemeralWorkspaceExecution({ ...remote, remoteAuthority: false })).toThrow();
expect(() => assertEphemeralWorkspaceExecution({ ...remote, environmentDriver: "local" })).toThrow();
expect(() => assertEphemeralWorkspaceExecution({ ...remote, adapterType: "process" })).toThrow();
expect(() => assertEphemeralNativeRuntime(false, { ...remote, remoteCwd: "/workspace", authorityCwd: "/workspace" })).not.toThrow();
expect(() => assertEphemeralNativeRuntime(false, { ...remote, remoteCwd: "/other", authorityCwd: "/workspace" })).toThrow();
});