Files
PaperClipAI/cli/src/__tests__/routine-plugin-parity.test.ts
T
DottaandPaperclip 9c8adee48b feat(mcp) [split 5/8]: integrate adapters and deployment runtime (#9560)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Governed MCP access spans contracts, runtime enforcement, adapters,
UI surfaces, and operator verification
> - The parity reference PR #9534 is too large for effective automated
or human review
> - The feature therefore needs a linear stack whose individual diffs
stay below the 100-file review limit
> - This pull request is split 5/8 and focuses on remaining adapters,
CLI, plugin examples, and deployment packaging
> - The benefit is a standalone, testable review boundary while
preserving byte-for-byte parity at the top of the stack

## Linked Issues or Issue Description

- Related parity reference: #9534
- Problem: The backend runtime needs packaging, CLI propagation,
worktree provisioning, release manifests, and remaining adapter/plugin
consumers.
- Proposed solution: Adds the remaining runtime/deployment integration
after compile-required contracts and concrete MCP injection moved into
lower server levels.
- Alternatives considered: keeping #9534 as one 403-file review, or
rewriting the feature to manufacture seams; both were rejected in favor
of path extraction plus compile-driven boundary moves.
- Roadmap alignment: this advances the existing governed MCP/tool-access
work already represented by #9534; it does not introduce a separate
roadmap initiative.
- Stack position: base branch is
`pap10341-split/04-server-runtime-wiring`.
- Merge policy: merge bottom-up, in order, only after the complete
eight-PR stack has been reviewed and the top-of-stack parity gate
remains empty.
- Requested review: QA for CLI, packaging, and worktree behavior;
Greptile on every PR.

## What Changed

- Adds the remaining runtime/deployment integration after
compile-required contracts and concrete MCP injection moved into lower
server levels.
- Keeps this PR below 100 changed files and independently typecheckable.
- Preserves the final tree from #9534 when combined with the other seven
stack levels.

## Verification

- `pnpm typecheck`
- Focused CLI Vitest run — 4 files, 49 tests passed

## Risks

- Packaging omissions could make the feature work in source but fail in
Docker, worktrees, or release assembly.
- Stack risk: merging out of order can expose incomplete layers;
mitigate by following the documented bottom-up merge policy.
- Parity risk: later edits to an intermediate branch can drift from
#9534; mitigate by re-running the empty top-of-stack diff before merge.

> 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

- OpenAI Codex, exact model ID `gpt-5.4`; runtime-managed context
window; medium reasoning with repository, shell, Git, GitHub CLI, and
code-execution tools enabled.

## 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] Internal references are omitted except the execution-plan link
explicitly required for this coordinated split stack
- [x] My branch name describes the change 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


## Stack Coordination

- Internal execution plan:
[PAP-13874](/PAP/issues/PAP-13874#document-plan)
- Parity reference: #9534
- Stack: #9556 → #9557 → #9558 → #9559 → #9560 → #9561 → #9562 → #9563
- Merge bottom-up only after full-stack review and an empty parity diff
at #9563.

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-07-14 15:15:43 -05:00

144 lines
7.7 KiB
TypeScript

import { Command } from "commander";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { registerPluginCommands } from "../commands/client/plugin.js";
import { registerRoutineApiCommands } from "../commands/client/routine-api.js";
const COMPANY_ID = "22222222-2222-4222-8222-222222222222";
const ROUTINE_ID = "33333333-3333-4333-8333-333333333333";
const REVISION_ID = "44444444-4444-4444-8444-444444444444";
const TRIGGER_ID = "55555555-5555-4555-8555-555555555555";
function createProgram(): Command {
const program = new Command();
program.exitOverride();
program.configureOutput({ writeOut: () => {}, writeErr: () => {} });
registerRoutineApiCommands(program);
registerPluginCommands(program);
return program;
}
async function run(args: string[]): Promise<void> {
await createProgram().parseAsync([...args, "--api-base", "http://localhost:3100", "--api-key", "board-token"], { from: "user" });
}
describe("routine and plugin parity commands", () => {
beforeEach(() => {
vi.restoreAllMocks();
delete process.env.PAPERCLIP_API_KEY;
delete process.env.PAPERCLIP_API_URL;
vi.spyOn(console, "log").mockImplementation(() => {});
vi.spyOn(process.stdout, "write").mockImplementation(() => true);
});
afterEach(() => {
vi.restoreAllMocks();
});
it("wraps routine API endpoints", async () => {
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse()));
vi.stubGlobal("fetch", fetchMock);
await run(["routine", "list", "--company-id", COMPANY_ID, "--project-id", "p1"]);
await run(["routine", "create", "--company-id", COMPANY_ID, "--payload-json", "{}"]);
await run(["routine", "get", ROUTINE_ID]);
await run(["routine", "update", ROUTINE_ID, "--payload-json", "{}"]);
await run(["routine", "revisions", ROUTINE_ID]);
await run(["routine", "revision:restore", ROUTINE_ID, REVISION_ID]);
await run(["routine", "runs", ROUTINE_ID, "--limit", "5"]);
await run(["routine", "run", ROUTINE_ID]);
await run(["routine", "trigger:create", ROUTINE_ID, "--payload-json", "{}"]);
await run(["routine", "trigger:update", TRIGGER_ID, "--payload-json", "{}"]);
await run(["routine", "trigger:delete", TRIGGER_ID]);
await run(["routine", "trigger:rotate-secret", TRIGGER_ID]);
await run(["routine", "trigger:fire", "public-id"]);
expect(fetchMock.mock.calls.map((call) => [call[1]?.method ?? "GET", call[0]])).toEqual([
["GET", `http://localhost:3100/api/companies/${COMPANY_ID}/routines?projectId=p1`],
["POST", `http://localhost:3100/api/companies/${COMPANY_ID}/routines`],
["GET", `http://localhost:3100/api/routines/${ROUTINE_ID}`],
["PATCH", `http://localhost:3100/api/routines/${ROUTINE_ID}`],
["GET", `http://localhost:3100/api/routines/${ROUTINE_ID}/revisions`],
["POST", `http://localhost:3100/api/routines/${ROUTINE_ID}/revisions/${REVISION_ID}/restore`],
["GET", `http://localhost:3100/api/routines/${ROUTINE_ID}/runs?limit=5`],
["POST", `http://localhost:3100/api/routines/${ROUTINE_ID}/run`],
["POST", `http://localhost:3100/api/routines/${ROUTINE_ID}/triggers`],
["PATCH", `http://localhost:3100/api/routine-triggers/${TRIGGER_ID}`],
["DELETE", `http://localhost:3100/api/routine-triggers/${TRIGGER_ID}`],
["POST", `http://localhost:3100/api/routine-triggers/${TRIGGER_ID}/rotate-secret`],
["POST", "http://localhost:3100/api/routine-triggers/public/public-id/fire"],
]);
});
it("wraps deeper plugin endpoints", async () => {
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse()));
vi.stubGlobal("fetch", fetchMock);
await run(["plugin", "ui-contributions"]);
await run(["plugin", "tools"]);
await run(["plugin", "tool:execute", "--payload-json", "{}"]);
await run(["plugin", "health", "plug"]);
await run(["plugin", "logs", "plug"]);
await run(["plugin", "upgrade", "plug"]);
await run(["plugin", "config", "plug", "--company-id", COMPANY_ID]);
await run(["plugin", "config:set", "plug", "--company-id", COMPANY_ID, "--payload-json", "{}"]);
await run(["plugin", "config:test", "plug", "--company-id", COMPANY_ID, "--payload-json", "{}"]);
await run(["plugin", "jobs", "plug"]);
await run(["plugin", "job:runs", "plug", "job1"]);
await run(["plugin", "job:trigger", "plug", "job1"]);
await run(["plugin", "webhook", "plug", "endpoint", "--payload-json", "{}"]);
await run(["plugin", "dashboard", "plug"]);
await run(["plugin", "bridge:data", "plug", "--payload-json", "{}"]);
await run(["plugin", "bridge:action", "plug", "--payload-json", "{}"]);
await run(["plugin", "bridge:stream", "plug", "events", "--duration-ms", "1"]);
await run(["plugin", "data", "plug", "key", "--payload-json", "{}"]);
await run(["plugin", "action", "plug", "key", "--payload-json", "{}"]);
await run(["plugin", "local-folders", "plug", "--company-id", COMPANY_ID]);
await run(["plugin", "local-folder:status", "plug", "source", "--company-id", COMPANY_ID]);
await run(["plugin", "local-folder:validate", "plug", "source", "--company-id", COMPANY_ID, "--payload-json", "{}"]);
await run(["plugin", "local-folder:set", "plug", "source", "--company-id", COMPANY_ID, "--payload-json", "{}"]);
expect(fetchMock.mock.calls.map((call) => [call[1]?.method ?? "GET", call[0]])).toEqual([
["GET", "http://localhost:3100/api/plugins/ui-contributions"],
["GET", "http://localhost:3100/api/plugins/tools"],
["POST", "http://localhost:3100/api/plugins/tools/execute"],
["GET", "http://localhost:3100/api/plugins/plug/health"],
["GET", "http://localhost:3100/api/plugins/plug/logs"],
["POST", "http://localhost:3100/api/plugins/plug/upgrade"],
["GET", `http://localhost:3100/api/plugins/plug/config?companyId=${COMPANY_ID}`],
["POST", "http://localhost:3100/api/plugins/plug/config"],
["POST", "http://localhost:3100/api/plugins/plug/config/test"],
["GET", "http://localhost:3100/api/plugins/plug/jobs"],
["GET", "http://localhost:3100/api/plugins/plug/jobs/job1/runs"],
["POST", "http://localhost:3100/api/plugins/plug/jobs/job1/trigger"],
["POST", "http://localhost:3100/api/plugins/plug/webhooks/endpoint"],
["GET", "http://localhost:3100/api/plugins/plug/dashboard"],
["POST", "http://localhost:3100/api/plugins/plug/bridge/data"],
["POST", "http://localhost:3100/api/plugins/plug/bridge/action"],
["GET", "http://localhost:3100/api/plugins/plug/bridge/stream/events"],
["POST", "http://localhost:3100/api/plugins/plug/data/key"],
["POST", "http://localhost:3100/api/plugins/plug/actions/key"],
["GET", `http://localhost:3100/api/plugins/plug/companies/${COMPANY_ID}/local-folders`],
["GET", `http://localhost:3100/api/plugins/plug/companies/${COMPANY_ID}/local-folders/source/status`],
["POST", `http://localhost:3100/api/plugins/plug/companies/${COMPANY_ID}/local-folders/source/validate`],
["PUT", `http://localhost:3100/api/plugins/plug/companies/${COMPANY_ID}/local-folders/source`],
]);
});
it("resolves plugin config company context from the environment", async () => {
const fetchMock = vi.fn().mockImplementation(() => Promise.resolve(jsonResponse()));
vi.stubGlobal("fetch", fetchMock);
process.env.PAPERCLIP_COMPANY_ID = COMPANY_ID;
await run(["plugin", "config", "plug"]);
expect(fetchMock).toHaveBeenCalledWith(
`http://localhost:3100/api/plugins/plug/config?companyId=${COMPANY_ID}`,
expect.objectContaining({ method: "GET" }),
);
});
});
function jsonResponse(body: unknown = { ok: true }, init: ResponseInit = { status: 200 }): Response {
return new Response(JSON.stringify(body), init);
}