Files
PaperClipAI/server/scripts/verify-runner-vendor-dependencies.test.mjs
DottaandPaperclip db2f00947b fix(runner): include Claude ACP in the server package (#15912)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The server ships a copy of Paperclip Runner for native agent
execution.
> - The Claude ACP bridge is a runner dependency, but it was absent from
the server package.
> - The runner resolves this bridge dynamically, so the import-based
packaging check missed it.
> - A Claude session then failed before startup and showed a generic
connection error.
> - This pull request ships the qualified bridge and reports a missing
runtime with repair steps.

## Linked Issues or Issue Description

**What happened?**

A server install with the vendored runner could not load
`@agentclientprotocol/claude-agent-acp/package.json`. The runtime test
suggested checking the model or provider connection. The task reported
an interrupted runner session.

**Expected behavior**

The server package includes its qualified Claude ACP runtime. A missing
bundled runtime reports an installation error and explains how to repair
it.

**Steps to reproduce**

1. Use a server install with the vendored runner and no Claude ACP
bridge.
2. Select the Paperclip Runner ACP harness and the Claude provider.
3. Run the runtime test or open a session.
4. Observe a missing-module failure before Claude starts.

**Paperclip version or commit**

Reproduced on `e733bddc45`. This branch is based on current master.

**Deployment mode**

Self-hosted server built from source.

Related: #15224 upgrades the Claude bridge. This PR fixes its omission
from the server package and keeps the current qualified version. A
future bridge upgrade must update the server pin too.

## What Changed

- Add Claude ACP `0.73.0` to the server dependencies and bundled
dependencies.
- Pin the qualified Claude SDK and bridge dependencies in the npm bundle
producer graph. Publish its native packages as consumer optional
dependencies instead of shipping the producer executable.
- Bind source-built vendored runners to the shared pnpm dependency store
while retaining the server manifest as the provider authority. Keep
published npm and self-rooted deployment roots unchanged.
- Include dynamically resolved Claude and Codex bridges in the vendor
dependency check.
- Preserve the missing-package category through the sidecar, Rust
transport, and native session executor. Stop automatic retries for this
installation failure.
- Show **Runtime missing** in the runtime test and task thread. Explain
the reinstall or rebuild, server restart, and runtime test steps.
- Add regression tests and document the repair procedure.

## Verification

- Red/green comparison with the production sidecar: the same
missing-package setup returns a raw require-stack error on the original
code and an actionable, non-retryable missing-runtime error on this
branch.
- The rebuilt server's vendored Claude installation probe passes using
the source-server authority selected by the launcher, without starting a
provider or making a model request.
- Focused server verification: 830 tests passed. Runner installation and
sidecar error tests: 83 passed, with 6 platform-specific skips.
Packaging tests: 28 passed. Rust transport tests: 7 passed.
- Source/deployment authority tests: 3 passed. Red/green packaging tests
include a Linux-produced Claude SDK bundle, actual npm pack, and closed
executable admission on Linux x64 and macOS ARM64/x64.
- Full UI suite: 8,113 tests passed.
- `pnpm -r typecheck` and `pnpm build` passed on the rebased branch.
- Full current-head CI passed, including all general and serialized test
lanes, Runner Rust/Vitest verification, typecheck, build, and all eight
e2e shards. Greptile reviewed `d6a2741834ff922956560f2f689382827bbaf9e0`
at 5/5 with no unresolved threads.
- Local full-suite limitation: an earlier parallel attempt hit Postgres
startup failures and timeouts; the affected server tests and a database
fixture passed in isolation. The subsequent serial `pnpm test:run` was
stopped while still running after complete CI passed. Focused local
tests, full UI tests, typecheck, and build completed as listed above.
- Token gates and `git diff --check` passed.

## Risks

- Bundling the Claude bridge increases the server package size. The
producer graph retains the qualified SDK version and existing isolation
patch. Native platform declarations move to the published server
manifest, while the runtime keeps its exact version, declared-slot,
no-follow, and executable digest checks.
- The new failure category is permanent. Operators must repair the
server installation before they retry the task.
- Existing failed runs retain their recorded error. The clearer message
applies to new runtime tests and runs.
- No database schema or migration changes.

## Model Used

OpenAI GPT-6 through Codex. The system reports the model family; the
exact deployment ID and context-window size are not exposed in this
session. Used reasoning, browser inspection, tool use, and code
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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-12 06:51:22 -05:00

118 lines
5.0 KiB
JavaScript

import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
findMissingVendorDependencies,
findRunnerExternalPackages,
findRunnerRuntimePackages,
} from "./verify-runner-vendor-dependencies.mjs";
describe("findMissingVendorDependencies", () => {
it("returns nothing when every runner dependency is already declared on server", () => {
const missing = findMissingVendorDependencies(
new Set(["acpx", "ajv", "smol-toml"]),
new Set(["acpx", "ajv", "smol-toml", "express"]),
);
expect(missing).toEqual([]);
});
it("flags a runner dependency that isn't mirrored into server/package.json", () => {
// This is the exact shape of the incident this check exists to catch:
// packages/paperclip-runner/package.json grew a new runtime dependency
// (smol-toml) that never got mirrored into server/package.json, so the
// vendored `cp -R` copy failed to resolve it at runtime (#13110, #13116).
const missing = findMissingVendorDependencies(
new Set(["acpx", "ajv", "smol-toml"]),
new Set(["acpx", "ajv"]),
);
expect(missing).toEqual(["smol-toml"]);
});
it("sorts multiple missing dependencies for a stable error message", () => {
const missing = findMissingVendorDependencies(
new Set(["smol-toml", "ajv-formats", "acpx"]),
new Set(),
);
expect(missing).toEqual(["acpx", "ajv-formats", "smol-toml"]);
});
});
describe("findRunnerExternalPackages", () => {
// Fixture-level coverage for the actual esbuild scan, not just the diff
// function: a real dist/index.js + dist/testing.js on disk, structurally
// matching packages/paperclip-runner's shape (testing.js re-exports
// index.js, which imports another local module that imports a bare npm
// specifier), plus package.json dependency noise that should be ignored
// because nothing reachable from these entry points imports it.
let fixtureDir;
afterEach(() => {
if (fixtureDir) rmSync(fixtureDir, { recursive: true, force: true });
fixtureDir = undefined;
});
function writeFixture() {
fixtureDir = mkdtempSync(join(tmpdir(), "paperclip-runner-vendor-fixture-"));
writeFileSync(
join(fixtureDir, "internal.js"),
'import { parse } from "smol-toml";\n' +
"export function parseSomething(text) { return parse(text); }\n",
);
writeFileSync(
join(fixtureDir, "index.js"),
'export * from "./internal.js";\nexport const marker = "index";\n',
);
writeFileSync(
join(fixtureDir, "testing.js"),
'export * from "./index.js";\nexport const testingMarker = "testing";\n',
);
return [join(fixtureDir, "index.js"), join(fixtureDir, "testing.js")];
}
it("reports only the npm packages actually reachable from the entry points", async () => {
const entryPoints = writeFixture();
const externalPackageNames = await findRunnerExternalPackages(entryPoints);
// smol-toml is reachable through internal.js -> index.js -> testing.js
// and must be reported. Nothing else was imported anywhere in the
// fixture, so this also proves the scan doesn't fall back to "every
// dependency the package declares" (which is what made the check
// over-broad before -- see the module header).
expect(externalPackageNames).toEqual(new Set(["smol-toml"]));
});
it("checks dynamically resolved bundled providers even without a JavaScript import", async () => {
const entryPoints = writeFixture();
const profiles = JSON.parse(readFileSync(new URL("../../packages/paperclip-runner/acpx-profiles.json", import.meta.url), "utf8"));
const packages = await findRunnerRuntimePackages(entryPoints, profiles);
expect(findMissingVendorDependencies(packages, new Set(["smol-toml", "@agentclientprotocol/codex-acp"])))
.toEqual(["@agentclientprotocol/claude-agent-acp"]);
expect(packages.has("pi-acp")).toBe(false);
});
it("throws a clear, actionable error when an entry point is missing", async () => {
fixtureDir = mkdtempSync(join(tmpdir(), "paperclip-runner-vendor-fixture-"));
const missingEntryPoint = join(fixtureDir, "index.js");
await expect(findRunnerExternalPackages([missingEntryPoint])).rejects.toThrow(
/expected build output at .*index\.js.*Run "pnpm --filter @paperclipai\/paperclip-runner build" first/s,
);
});
});
// Claude is resolved through createRequire at runtime, outside esbuild's graph.
it("ships the qualified Claude ACP server with the vendored runner", () => {
const server = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
const profiles = JSON.parse(readFileSync(new URL("../../packages/paperclip-runner/acpx-profiles.json", import.meta.url), "utf8"));
const claude = profiles.profiles.claude;
expect(server.dependencies[claude.agentServerPackage]).toBe(claude.agentServerVersion);
expect(server.bundleDependencies).toContain(claude.agentServerPackage);
});