mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-29 21:07:40 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Its tests protect company boundaries, approvals, durable tasks, credentials and the board UI. > - Several owner suites repeat large database fixtures and render frames. > - Some tests repeat stronger proof or pass when the behavior they describe is broken. > - This pull request shares exact setup, removes proven duplicate cases and repairs weak observations. > - It preserves distinct security, lifecycle, concurrency and user-facing contracts. > - The benefit is 5,027 fewer test lines and stronger regression checks. ## Linked Issues or Issue Description Refs #15978. This continues the merged test-audit cleanup in [PR #15978](https://github.com/paperclipai/paperclip/pull/15978), which removed 11,976 test/support lines. The savings in this pull request are additional. Related open work: [PR #13460](https://github.com/paperclipai/paperclip/pull/13460) changes legacy OAuth parent/version lock ordering. This pull request retains those production paths and the existing lock-order test. Its secrets changes compact fixtures and repair the two AWS wrapper exclusion observations. Scoped title searches found no open duplicate audit or fixture-consolidation PR and no matching audit issue. The problem is described here using the enhancement template. **What existing behavior does this improve?** The maintenance and regression value of the existing server, UI, CLI, shared and wiki-plugin test suites. **Subsystem affected** Cross-cutting test code. Two UI modules also lose unused test inspection exports. **Current behavior** Owner tests repeat database rows, service inputs, HTTP setup and render frames. Some cases repeat stronger assertions. Two AWS lock tests record only cleanup events, so an AWS provider write can happen inside the held lock without failing those observations. Several other negative tests accept or do not observe the wrong result. Worktree fixtures also use a temporary path alias that conflicts with the existing canonical-path checks on macOS. **Proposed behavior** Use small local helpers that preserve exact inputs, fresh allocations, callbacks, query order and await positions. Remove only cases with named stronger keepers. Tighten negative assertions and observe actual AWS provider entry while a confirmed lock holder remains parked. Resolve temporary fixture roots to their canonical paths. **Reason and benefit** Remove 5,027 net test lines and 15 redundant registered executions. Remove 11 lines of unused UI inspection exports. Keep every distinct company, actor, approval, credential, persistence, stale-write and concurrency contract. No wall-time speedup is claimed for setup compaction. **Breaking changes** None for application behavior, APIs or stored data. The removed exports expose private UI test state and have no remaining callers. ## What Changed - Consolidate repeated runtime, workspace, portability, route, tool-access, policy, gateway and state-service fixtures. - Share repeated UI render frames and CLI/wiki-plugin setup while retaining the original actions and expected results. - Remove 15 repeated case executions only where the audit records an exact stronger keeper. - Repair weak HTTP/UI negative assertions and two AWS account-home lock observations. Keep the existing durable results and cleanup behavior. - Remove the unused `__inflightGetCount` and `__secondTickInternals` inspection exports. Keep observable request coalescing and ticker lifecycle checks. - Canonicalize temporary worktree fixture paths without weakening production path checks. - Record the owner decisions, savings, independent preservation reviews and validation in [the dated audit report](https://github.com/paperclipai/paperclip/blob/58c5c4aa241c85f4665a3159c192888bbb2a5cfa/doc/plans/2026-10-12-test-audit-rounds.md) and [the compact control evidence](https://github.com/paperclipai/paperclip/blob/58c5c4aa241c85f4665a3159c192888bbb2a5cfa/doc/plans/2026-10-12-test-audit-controls.json). ## Verification - Complete owner and retained-sibling baselines passed before each audit cutover. Independent reviewers checked the full original tests, actual helper bodies, exact inputs, receipt provenance, async order, fresh allocations and case registrations. - All 14 UI/route/wiki mutations failed at their intended assertions: ten UI/API/ticker controls, one route control and three wiki persistence/receipt controls. Each mutated production source was restored to its exact original bytes. - Both old AWS lock tests passed with their respective AWS-only lock bypass. Both repaired tests failed at the intended assertions with the same bypasses. These give 16 intended failures and two passing weak controls across 18 executions. Each source was restored exactly. - Final complete state-owner/sibling run: 329/329 passed at code revision `64370831ebe191e5ce092f85f79b6fb661df7e16`. - Final `pnpm -r typecheck`, `pnpm check:token-gates` and `pnpm build`: passed at the same code revision. - Delivery head `58c5c4aa241c85f4665a3159c192888bbb2a5cfa` includes the evidence commit and master `4b766b872993045a2e787404f0475503683e5ded`. All 27 audited test files and both application files match the locally verified code revision byte-for-byte. Current-head CI validates the integrated branch, including the incoming master changes. - All eight production-owner SHA guards for the 16 deliberate failing mutation controls still match the integrated delivery checkout. The mutation receipts therefore apply to those current owners. - Full default `pnpm test:run`: **failed** with exit 1 at frozen code revision `64370831ebe191e5ce092f85f79b6fb661df7e16`; HEAD and tracked source bytes remained unchanged. The first general-server group reported 878 passing files, four failing files and six skipped files; 17,846 passing cases, 24 failing cases and 105 skipped cases. Later groups did not run. Failures were `http-log-redaction` (socket hangup), `public-mcp` (initial 15-second timeout followed by hosted token “Refresh before subscribing” failures), `remove-test-home` (macOS `ENOTEMPTY` where permission errors were expected, plus cleanup failure), and `workspace-git-snapshot-streaming` (300-second timeout). All four failing test files and the relevant cleanup/MCP production owners are unchanged by this audit. Full local success is not claimed. - Focused complete-owner diagnosis at the same frozen revision: 149/152 passed, three failed, zero skipped. `public-mcp` passed 82/82 and `http-log-redaction` passed 66/66 unchanged. The two `remove-test-home` cases reproduced macOS `ENOTEMPTY` against an expected `EACCES`/`EPERM` contract; the 32 MiB workspace snapshot case reproduced its existing 300,000 ms timeout. HEAD and tracked files stayed clean. Exact blob comparison confirmed all four test files and the relevant cleanup/MCP owners match both inspected master `4b766b872993045a2e787404f0475503683e5ded` and the frozen local revision. The three remaining local failures are unresolved; no timeout, retry or assertion was weakened. - Current-head CI: [workflow 38299262149](https://github.com/paperclipai/paperclip/actions/runs/38299262149) has passed runner selection and created all downstream test/typecheck/build gates; those gates are queued, with no failures reported. Greptile completed successfully at `58c5c4aa241c85f4665a3159c192888bbb2a5cfa` with [5/5 and zero comments](https://github.com/paperclipai/paperclip/pull/16022#issuecomment-6131457592). All review threads are resolved or absent. This pull request will remain open after verification. Reviewers can reproduce the required workspace checks: ```sh pnpm -r typecheck pnpm check:token-gates pnpm test:run pnpm build ``` Browser suites were not run. Their sources and user journeys are unchanged by this audit. ## Risks - A fixture helper can hide a specialized input or change object freshness. Full-program expansion checks and independent reviews preserve the exact old inputs and execution order. - Removing duplicate proof can remove a distinct contract by mistake. The audit records the keeper for each deletion; all distinct security and lifecycle cases remain. - Concurrency checks can miss progress during a fixed delay. The AWS repairs record actual provider entry, confirm holder entry, use measured entry windows, require exact final event order and drain both operations in `finally`. - The full local default run failed. Focused diagnosis reproduced two macOS cleanup failures and one existing snapshot timeout in unchanged owners; these remain unresolved. Current-head CI is pending. No test deadline, retry policy, skip or CI shard was weakened to obtain a pass. > 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 with GPT-6, reasoning, repository inspection, code execution and delegated audit/review. The runtime does not expose the exact served model identifier or context-window size; those values are unavailable and are not inferred from the model catalog. ## 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 - [ ] 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 - [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>
813 lines
24 KiB
TypeScript
813 lines
24 KiB
TypeScript
import { Command } from "commander";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import type { CompanyPortabilityPreviewResult } from "@paperclipai/shared";
|
|
import {
|
|
buildCompanyDashboardUrl,
|
|
buildDefaultImportAdapterOverrides,
|
|
buildDefaultImportSelectionState,
|
|
buildImportSelectionCatalog,
|
|
buildSelectedFilesFromImportSelection,
|
|
renderCompanyImportPreview,
|
|
renderCompanyImportResult,
|
|
registerCompanyCommands,
|
|
resolveCompanyImportApplyConfirmationMode,
|
|
resolveCompanyImportApiPath,
|
|
} from "../commands/client/company.js";
|
|
|
|
const ORIGINAL_ENV = { ...process.env };
|
|
const COMPANY_ID = "22222222-2222-4222-8222-222222222222";
|
|
|
|
function makeProgram(): Command {
|
|
const program = new Command();
|
|
program.exitOverride();
|
|
program.configureOutput({
|
|
writeOut: () => undefined,
|
|
writeErr: () => undefined,
|
|
});
|
|
registerCompanyCommands(program);
|
|
return program;
|
|
}
|
|
|
|
async function runCommand(args: string[]): Promise<void> {
|
|
await makeProgram().parseAsync(args, { from: "user" });
|
|
}
|
|
|
|
function jsonResponse(body: unknown, status = 200): Response {
|
|
return new Response(JSON.stringify(body), {
|
|
status,
|
|
headers: { "content-type": "application/json" },
|
|
});
|
|
}
|
|
|
|
function company(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
id: COMPANY_ID,
|
|
name: "Paperclip",
|
|
description: null,
|
|
status: "active",
|
|
issuePrefix: "PAP",
|
|
issueCounter: 1,
|
|
budgetMonthlyCents: 0,
|
|
spentMonthlyCents: 0,
|
|
requireBoardApprovalForNewAgents: false,
|
|
feedbackDataSharingEnabled: false,
|
|
feedbackDataSharingConsentAt: null,
|
|
feedbackDataSharingConsentByUserId: null,
|
|
feedbackDataSharingTermsVersion: null,
|
|
logoAssetId: null,
|
|
createdAt: "2026-06-04T00:00:00.000Z",
|
|
updatedAt: "2026-06-04T00:00:00.000Z",
|
|
logoUrl: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function allImportEntities(): CompanyPortabilityPreviewResult["include"] {
|
|
return {
|
|
company: true,
|
|
agents: true,
|
|
projects: true,
|
|
issues: true,
|
|
skills: true,
|
|
};
|
|
}
|
|
|
|
function sourceCompanyManifest(): NonNullable<CompanyPortabilityPreviewResult["manifest"]["company"]> {
|
|
return {
|
|
path: "COMPANY.md",
|
|
name: "Source Co",
|
|
description: null,
|
|
logoPath: null,
|
|
requireBoardApprovalForNewAgents: false,
|
|
feedbackDataSharingEnabled: false,
|
|
feedbackDataSharingConsentAt: null,
|
|
feedbackDataSharingConsentByUserId: null,
|
|
feedbackDataSharingTermsVersion: null,
|
|
};
|
|
}
|
|
|
|
function ceoManifest(): CompanyPortabilityPreviewResult["manifest"]["agents"][number] {
|
|
return {
|
|
slug: "ceo",
|
|
name: "CEO",
|
|
path: "agents/ceo/AGENT.md",
|
|
skills: [],
|
|
role: "ceo",
|
|
title: null,
|
|
icon: null,
|
|
capabilities: null,
|
|
reportsToSlug: null,
|
|
reportsToExistingAgentId: null,
|
|
reportsToExistingAgentSlug: null,
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
permissionGrants: [],
|
|
budgetMonthlyCents: 0,
|
|
metadata: null,
|
|
};
|
|
}
|
|
|
|
function alphaProjectManifest(): CompanyPortabilityPreviewResult["manifest"]["projects"][number] {
|
|
return {
|
|
slug: "alpha",
|
|
name: "Alpha",
|
|
path: "projects/alpha/PROJECT.md",
|
|
description: null,
|
|
ownerAgentSlug: null,
|
|
leadAgentSlug: null,
|
|
targetDate: null,
|
|
color: null,
|
|
icon: null,
|
|
status: null,
|
|
executionWorkspacePolicy: null,
|
|
workspaces: [],
|
|
env: null,
|
|
metadata: null,
|
|
};
|
|
}
|
|
|
|
function kickoffIssueManifest(): CompanyPortabilityPreviewResult["manifest"]["issues"][number] {
|
|
return {
|
|
slug: "kickoff",
|
|
identifier: null,
|
|
title: "Kickoff",
|
|
path: "projects/alpha/issues/kickoff/TASK.md",
|
|
projectSlug: "alpha",
|
|
projectWorkspaceKey: null,
|
|
assigneeAgentSlug: "ceo",
|
|
description: null,
|
|
recurring: false,
|
|
routine: null,
|
|
legacyRecurrence: null,
|
|
status: null,
|
|
priority: null,
|
|
labelIds: [],
|
|
billingCode: null,
|
|
executionWorkspaceSettings: null,
|
|
assigneeAdapterOverrides: null,
|
|
comments: [],
|
|
metadata: null,
|
|
};
|
|
}
|
|
|
|
function openAiEnvInput(): CompanyPortabilityPreviewResult["envInputs"][number] {
|
|
return {
|
|
key: "OPENAI_API_KEY",
|
|
description: null,
|
|
agentSlug: "ceo",
|
|
projectSlug: null,
|
|
kind: "secret",
|
|
requirement: "required",
|
|
defaultValue: null,
|
|
portability: "portable",
|
|
};
|
|
}
|
|
|
|
describe("company CLI commands", () => {
|
|
let fetchMock: ReturnType<typeof vi.fn>;
|
|
let logSpy: ReturnType<typeof vi.spyOn>;
|
|
let errorSpy: ReturnType<typeof vi.spyOn>;
|
|
|
|
beforeEach(() => {
|
|
process.env = { ...ORIGINAL_ENV };
|
|
delete process.env.PAPERCLIP_API_URL;
|
|
delete process.env.PAPERCLIP_API_KEY;
|
|
delete process.env.PAPERCLIP_COMPANY_ID;
|
|
fetchMock = vi.fn();
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
|
|
errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = { ...ORIGINAL_ENV };
|
|
vi.unstubAllGlobals();
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("gets the current company from an explicit company context without board-wide listing", async () => {
|
|
fetchMock.mockResolvedValueOnce(jsonResponse(company()));
|
|
|
|
await runCommand([
|
|
"company",
|
|
"current",
|
|
"--company-id",
|
|
COMPANY_ID,
|
|
"--api-base",
|
|
"http://paperclip.test",
|
|
"--api-key",
|
|
"agent-token",
|
|
"--json",
|
|
]);
|
|
|
|
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
`http://paperclip.test/api/companies/${COMPANY_ID}`,
|
|
expect.objectContaining({ method: "GET" }),
|
|
);
|
|
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({ id: COMPANY_ID, name: "Paperclip" });
|
|
});
|
|
|
|
it("gets the current company from agent authentication when no company context is set", async () => {
|
|
fetchMock
|
|
.mockResolvedValueOnce(jsonResponse({ id: "agent-1", companyId: COMPANY_ID }))
|
|
.mockResolvedValueOnce(jsonResponse(company()));
|
|
|
|
await runCommand([
|
|
"company",
|
|
"current",
|
|
"--api-base",
|
|
"http://paperclip.test",
|
|
"--api-key",
|
|
"agent-token",
|
|
"--json",
|
|
]);
|
|
|
|
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
1,
|
|
"http://paperclip.test/api/agents/me",
|
|
expect.objectContaining({ method: "GET" }),
|
|
);
|
|
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
2,
|
|
`http://paperclip.test/api/companies/${COMPANY_ID}`,
|
|
expect.objectContaining({ method: "GET" }),
|
|
);
|
|
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject({ id: COMPANY_ID, name: "Paperclip" });
|
|
});
|
|
|
|
it("lists the scoped agent company when board-wide company listing is denied", async () => {
|
|
fetchMock
|
|
.mockResolvedValueOnce(jsonResponse({ error: "Board access required" }, 403))
|
|
.mockResolvedValueOnce(jsonResponse({ id: "agent-1", companyId: COMPANY_ID }))
|
|
.mockResolvedValueOnce(jsonResponse(company()));
|
|
|
|
await runCommand([
|
|
"company",
|
|
"list",
|
|
"--api-base",
|
|
"http://paperclip.test",
|
|
"--api-key",
|
|
"agent-token",
|
|
"--json",
|
|
]);
|
|
|
|
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
1,
|
|
"http://paperclip.test/api/companies",
|
|
expect.objectContaining({ method: "GET" }),
|
|
);
|
|
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
2,
|
|
"http://paperclip.test/api/agents/me",
|
|
expect.objectContaining({ method: "GET" }),
|
|
);
|
|
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
3,
|
|
`http://paperclip.test/api/companies/${COMPANY_ID}`,
|
|
expect.objectContaining({ method: "GET" }),
|
|
);
|
|
expect(JSON.parse(String(logSpy.mock.calls[0]?.[0]))).toMatchObject([{ id: COMPANY_ID, name: "Paperclip" }]);
|
|
});
|
|
|
|
it("explains that company creation requires board instance-admin authentication under agent auth", async () => {
|
|
fetchMock.mockResolvedValueOnce(jsonResponse({ error: "Board access required" }, 403));
|
|
vi.spyOn(process, "exit").mockImplementation(((code?: string | number | null) => {
|
|
throw new Error(`exit:${code ?? 0}`);
|
|
}) as typeof process.exit);
|
|
|
|
await expect(runCommand([
|
|
"company",
|
|
"create",
|
|
"--payload-json",
|
|
"{\"name\":\"Disposable\"}",
|
|
"--api-base",
|
|
"http://paperclip.test",
|
|
"--api-key",
|
|
"agent-token",
|
|
"--json",
|
|
])).rejects.toThrow("exit:1");
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
"http://paperclip.test/api/companies",
|
|
expect.objectContaining({ method: "POST" }),
|
|
);
|
|
const rendered = String(errorSpy.mock.calls[0]?.[0]);
|
|
expect(rendered).toContain("Creating companies requires board/instance-admin authentication");
|
|
expect(rendered).toContain("company list --json");
|
|
});
|
|
});
|
|
|
|
describe("resolveCompanyImportApiPath", () => {
|
|
it("uses company-scoped preview route for existing-company dry runs", () => {
|
|
expect(
|
|
resolveCompanyImportApiPath({
|
|
dryRun: true,
|
|
targetMode: "existing_company",
|
|
companyId: "company-123",
|
|
}),
|
|
).toBe("/api/companies/company-123/imports/preview");
|
|
});
|
|
|
|
it("uses company-scoped apply route for existing-company imports", () => {
|
|
expect(
|
|
resolveCompanyImportApiPath({
|
|
dryRun: false,
|
|
targetMode: "existing_company",
|
|
companyId: "company-123",
|
|
}),
|
|
).toBe("/api/companies/company-123/imports/apply");
|
|
});
|
|
|
|
it("keeps global routes for new-company imports", () => {
|
|
expect(
|
|
resolveCompanyImportApiPath({
|
|
dryRun: true,
|
|
targetMode: "new_company",
|
|
}),
|
|
).toBe("/api/companies/import/preview");
|
|
|
|
expect(
|
|
resolveCompanyImportApiPath({
|
|
dryRun: false,
|
|
targetMode: "new_company",
|
|
}),
|
|
).toBe("/api/companies/import");
|
|
});
|
|
|
|
it("throws when an existing-company import is missing a company id", () => {
|
|
expect(() =>
|
|
resolveCompanyImportApiPath({
|
|
dryRun: true,
|
|
targetMode: "existing_company",
|
|
companyId: " ",
|
|
})
|
|
).toThrow(/require a companyId/i);
|
|
});
|
|
});
|
|
|
|
describe("resolveCompanyImportApplyConfirmationMode", () => {
|
|
it("skips confirmation when --yes is set", () => {
|
|
expect(
|
|
resolveCompanyImportApplyConfirmationMode({
|
|
yes: true,
|
|
interactive: false,
|
|
json: false,
|
|
}),
|
|
).toBe("skip");
|
|
});
|
|
|
|
it("prompts in interactive text mode when --yes is not set", () => {
|
|
expect(
|
|
resolveCompanyImportApplyConfirmationMode({
|
|
yes: false,
|
|
interactive: true,
|
|
json: false,
|
|
}),
|
|
).toBe("prompt");
|
|
});
|
|
|
|
it("requires --yes for non-interactive apply", () => {
|
|
expect(() =>
|
|
resolveCompanyImportApplyConfirmationMode({
|
|
yes: false,
|
|
interactive: false,
|
|
json: false,
|
|
})
|
|
).toThrow(/non-interactive terminal requires --yes/i);
|
|
});
|
|
|
|
it("requires --yes for json apply", () => {
|
|
expect(() =>
|
|
resolveCompanyImportApplyConfirmationMode({
|
|
yes: false,
|
|
interactive: false,
|
|
json: true,
|
|
})
|
|
).toThrow(/with --json requires --yes/i);
|
|
});
|
|
});
|
|
|
|
describe("buildCompanyDashboardUrl", () => {
|
|
it("preserves the configured base path when building a dashboard URL", () => {
|
|
expect(buildCompanyDashboardUrl("https://paperclip.example/app/", "PAP")).toBe(
|
|
"https://paperclip.example/app/PAP/dashboard",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("renderCompanyImportPreview", () => {
|
|
it("summarizes the preview with counts, selection info, and truncated examples", () => {
|
|
const preview: CompanyPortabilityPreviewResult = {
|
|
include: allImportEntities(),
|
|
targetCompanyId: "company-123",
|
|
targetCompanyName: "Imported Co",
|
|
collisionStrategy: "rename",
|
|
selectedAgentSlugs: ["ceo", "cto", "eng-1", "eng-2", "eng-3", "eng-4", "eng-5"],
|
|
plan: {
|
|
companyAction: "update",
|
|
agentPlans: [
|
|
{ slug: "ceo", action: "create", plannedName: "CEO", existingAgentId: null, reason: null },
|
|
{ slug: "cto", action: "update", plannedName: "CTO", existingAgentId: "agent-2", reason: "replace strategy" },
|
|
{ slug: "eng-1", action: "skip", plannedName: "Engineer 1", existingAgentId: "agent-3", reason: "skip strategy" },
|
|
{ slug: "eng-2", action: "create", plannedName: "Engineer 2", existingAgentId: null, reason: null },
|
|
{ slug: "eng-3", action: "create", plannedName: "Engineer 3", existingAgentId: null, reason: null },
|
|
{ slug: "eng-4", action: "create", plannedName: "Engineer 4", existingAgentId: null, reason: null },
|
|
{ slug: "eng-5", action: "create", plannedName: "Engineer 5", existingAgentId: null, reason: null },
|
|
],
|
|
projectPlans: [
|
|
{ slug: "alpha", action: "create", plannedName: "Alpha", existingProjectId: null, reason: null },
|
|
],
|
|
issuePlans: [
|
|
{ slug: "kickoff", action: "create", plannedTitle: "Kickoff", reason: null },
|
|
],
|
|
},
|
|
manifest: {
|
|
schemaVersion: 1,
|
|
generatedAt: "2026-03-23T17:00:00.000Z",
|
|
source: {
|
|
companyId: "company-src",
|
|
companyName: "Source Co",
|
|
},
|
|
includes: allImportEntities(),
|
|
company: sourceCompanyManifest(),
|
|
sidebar: {
|
|
agents: ["ceo"],
|
|
projects: ["alpha"],
|
|
},
|
|
agents: [
|
|
ceoManifest(),
|
|
],
|
|
skills: [
|
|
{
|
|
key: "skill-a",
|
|
slug: "skill-a",
|
|
name: "Skill A",
|
|
path: "skills/skill-a/SKILL.md",
|
|
description: null,
|
|
sourceType: "inline",
|
|
sourceLocator: null,
|
|
sourceRef: null,
|
|
trustLevel: null,
|
|
compatibility: null,
|
|
metadata: null,
|
|
fileInventory: [],
|
|
},
|
|
],
|
|
projects: [
|
|
alphaProjectManifest(),
|
|
],
|
|
issues: [
|
|
kickoffIssueManifest(),
|
|
],
|
|
envInputs: [
|
|
openAiEnvInput(),
|
|
],
|
|
},
|
|
files: {
|
|
"COMPANY.md": "# Source Co",
|
|
},
|
|
envInputs: [
|
|
openAiEnvInput(),
|
|
],
|
|
warnings: ["One warning"],
|
|
errors: ["One error"],
|
|
};
|
|
|
|
const rendered = renderCompanyImportPreview(preview, {
|
|
sourceLabel: "GitHub: https://github.com/paperclipai/companies/demo",
|
|
targetLabel: "Imported Co (company-123)",
|
|
infoMessages: ["Using claude-local adapter"],
|
|
});
|
|
|
|
expect(rendered).toContain("Include");
|
|
expect(rendered).toContain("company, projects, tasks, agents, skills");
|
|
expect(rendered).toContain("7 agents total");
|
|
expect(rendered).toContain("1 project total");
|
|
expect(rendered).toContain("1 task total");
|
|
expect(rendered).toContain("skills: 1 skill packaged");
|
|
expect(rendered).toContain("+1 more");
|
|
expect(rendered).toContain("Using claude-local adapter");
|
|
expect(rendered).toContain("Warnings");
|
|
expect(rendered).toContain("Errors");
|
|
});
|
|
});
|
|
|
|
describe("renderCompanyImportResult", () => {
|
|
it("summarizes import results with created, updated, and skipped counts", () => {
|
|
const rendered = renderCompanyImportResult(
|
|
{
|
|
company: {
|
|
id: "company-123",
|
|
name: "Imported Co",
|
|
action: "updated",
|
|
},
|
|
agents: [
|
|
{ slug: "ceo", id: "agent-1", action: "created", name: "CEO", reason: null },
|
|
{ slug: "cto", id: "agent-2", action: "updated", name: "CTO", reason: "replace strategy" },
|
|
{ slug: "ops", id: null, action: "skipped", name: "Ops", reason: "skip strategy" },
|
|
],
|
|
skills: [
|
|
{
|
|
originalKey: "company/source/review",
|
|
originalSlug: "review",
|
|
key: "company/target/review-2",
|
|
slug: "review-2",
|
|
id: "skill-1",
|
|
action: "renamed",
|
|
reason: "rename strategy",
|
|
},
|
|
],
|
|
projects: [
|
|
{ slug: "app", id: "project-1", action: "created", name: "App", reason: null },
|
|
{ slug: "ops", id: "project-2", action: "updated", name: "Operations", reason: "replace strategy" },
|
|
{ slug: "archive", id: null, action: "skipped", name: "Archive", reason: "skip strategy" },
|
|
],
|
|
routines: [
|
|
{ slug: "weekly-report", id: "routine-1", action: "created", title: "Weekly report", status: "paused" },
|
|
],
|
|
envInputs: [],
|
|
warnings: ["Review API keys"],
|
|
},
|
|
{
|
|
targetLabel: "Imported Co (company-123)",
|
|
companyUrl: "https://paperclip.example/PAP/dashboard",
|
|
infoMessages: ["Using claude-local adapter"],
|
|
},
|
|
);
|
|
|
|
expect(rendered).toContain("Company");
|
|
expect(rendered).toContain("https://paperclip.example/PAP/dashboard");
|
|
expect(rendered).toContain("3 agents total (1 created, 1 updated, 1 skipped)");
|
|
expect(rendered).toContain("1 skill total (1 renamed)");
|
|
expect(rendered).toContain("3 projects total (1 created, 1 updated, 1 skipped)");
|
|
expect(rendered).toContain("Agent results");
|
|
expect(rendered).toContain("Skill results");
|
|
expect(rendered).toContain("Project results");
|
|
expect(rendered).toContain("Using claude-local adapter");
|
|
expect(rendered).toContain("Review API keys");
|
|
});
|
|
});
|
|
|
|
describe("import selection catalog", () => {
|
|
it("defaults to everything and keeps project selection separate from task selection", () => {
|
|
const preview: CompanyPortabilityPreviewResult = {
|
|
include: allImportEntities(),
|
|
targetCompanyId: "company-123",
|
|
targetCompanyName: "Imported Co",
|
|
collisionStrategy: "rename",
|
|
selectedAgentSlugs: ["ceo"],
|
|
plan: {
|
|
companyAction: "create",
|
|
agentPlans: [],
|
|
projectPlans: [],
|
|
issuePlans: [],
|
|
},
|
|
manifest: {
|
|
schemaVersion: 1,
|
|
generatedAt: "2026-03-23T18:00:00.000Z",
|
|
source: {
|
|
companyId: "company-src",
|
|
companyName: "Source Co",
|
|
},
|
|
includes: allImportEntities(),
|
|
company: {
|
|
path: "COMPANY.md",
|
|
name: "Source Co",
|
|
description: null,
|
|
logoPath: "images/company-logo.png",
|
|
requireBoardApprovalForNewAgents: false,
|
|
feedbackDataSharingEnabled: false,
|
|
feedbackDataSharingConsentAt: null,
|
|
feedbackDataSharingConsentByUserId: null,
|
|
feedbackDataSharingTermsVersion: null,
|
|
},
|
|
sidebar: {
|
|
agents: ["ceo"],
|
|
projects: ["alpha"],
|
|
},
|
|
agents: [
|
|
ceoManifest(),
|
|
],
|
|
skills: [
|
|
{
|
|
key: "skill-a",
|
|
slug: "skill-a",
|
|
name: "Skill A",
|
|
path: "skills/skill-a/SKILL.md",
|
|
description: null,
|
|
sourceType: "inline",
|
|
sourceLocator: null,
|
|
sourceRef: null,
|
|
trustLevel: null,
|
|
compatibility: null,
|
|
metadata: null,
|
|
fileInventory: [{ path: "skills/skill-a/helper.md", kind: "doc" }],
|
|
},
|
|
],
|
|
projects: [
|
|
alphaProjectManifest(),
|
|
],
|
|
issues: [
|
|
kickoffIssueManifest(),
|
|
],
|
|
envInputs: [],
|
|
},
|
|
files: {
|
|
"COMPANY.md": "# Source Co",
|
|
"README.md": "# Readme",
|
|
".paperclip.yaml": "schema: paperclip/v1\n",
|
|
"images/company-logo.png": {
|
|
encoding: "base64",
|
|
data: "",
|
|
contentType: "image/png",
|
|
},
|
|
"projects/alpha/PROJECT.md": "# Alpha",
|
|
"projects/alpha/notes.md": "project notes",
|
|
"projects/alpha/issues/kickoff/TASK.md": "# Kickoff",
|
|
"projects/alpha/issues/kickoff/details.md": "task details",
|
|
"agents/ceo/AGENT.md": "# CEO",
|
|
"agents/ceo/prompt.md": "prompt",
|
|
"skills/skill-a/SKILL.md": "# Skill A",
|
|
"skills/skill-a/helper.md": "helper",
|
|
},
|
|
envInputs: [],
|
|
warnings: [],
|
|
errors: [],
|
|
};
|
|
|
|
const catalog = buildImportSelectionCatalog(preview);
|
|
const state = buildDefaultImportSelectionState(catalog);
|
|
|
|
expect(state.company).toBe(true);
|
|
expect(state.projects.has("alpha")).toBe(true);
|
|
expect(state.issues.has("kickoff")).toBe(true);
|
|
expect(state.agents.has("ceo")).toBe(true);
|
|
expect(state.skills.has("skill-a")).toBe(true);
|
|
|
|
state.company = false;
|
|
state.issues.clear();
|
|
state.agents.clear();
|
|
state.skills.clear();
|
|
|
|
const selectedFiles = buildSelectedFilesFromImportSelection(catalog, state);
|
|
|
|
expect(selectedFiles).toContain(".paperclip.yaml");
|
|
expect(selectedFiles).toContain("projects/alpha/PROJECT.md");
|
|
expect(selectedFiles).toContain("projects/alpha/notes.md");
|
|
expect(selectedFiles).not.toContain("projects/alpha/issues/kickoff/TASK.md");
|
|
expect(selectedFiles).not.toContain("projects/alpha/issues/kickoff/details.md");
|
|
});
|
|
|
|
it("includes extension file even when all entities are deselected", () => {
|
|
const preview: CompanyPortabilityPreviewResult = {
|
|
include: allImportEntities(),
|
|
targetCompanyId: "company-123",
|
|
targetCompanyName: "Imported Co",
|
|
collisionStrategy: "rename",
|
|
selectedAgentSlugs: [],
|
|
plan: {
|
|
companyAction: "create",
|
|
agentPlans: [],
|
|
projectPlans: [],
|
|
issuePlans: [],
|
|
},
|
|
manifest: {
|
|
schemaVersion: 1,
|
|
generatedAt: "2026-03-23T18:00:00.000Z",
|
|
source: {
|
|
companyId: "company-src",
|
|
companyName: "Source Co",
|
|
},
|
|
includes: allImportEntities(),
|
|
company: sourceCompanyManifest(),
|
|
sidebar: {
|
|
agents: [],
|
|
projects: [],
|
|
},
|
|
agents: [],
|
|
skills: [],
|
|
projects: [],
|
|
issues: [],
|
|
envInputs: [],
|
|
},
|
|
files: {
|
|
".paperclip.yaml": "schema: paperclip/v1\n",
|
|
},
|
|
envInputs: [],
|
|
warnings: [],
|
|
errors: [],
|
|
};
|
|
|
|
const catalog = buildImportSelectionCatalog(preview);
|
|
const state = buildDefaultImportSelectionState(catalog);
|
|
|
|
state.company = false;
|
|
state.projects.clear();
|
|
state.issues.clear();
|
|
state.agents.clear();
|
|
state.skills.clear();
|
|
|
|
const selectedFiles = buildSelectedFilesFromImportSelection(catalog, state);
|
|
|
|
expect(selectedFiles).toContain(".paperclip.yaml");
|
|
expect(selectedFiles).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
describe("default adapter overrides", () => {
|
|
it("maps process-only imported agents to claude_local", () => {
|
|
const preview: CompanyPortabilityPreviewResult = {
|
|
include: {
|
|
company: false,
|
|
agents: true,
|
|
projects: false,
|
|
issues: false,
|
|
skills: false,
|
|
},
|
|
targetCompanyId: null,
|
|
targetCompanyName: null,
|
|
collisionStrategy: "rename",
|
|
selectedAgentSlugs: ["legacy-agent", "explicit-agent"],
|
|
plan: {
|
|
companyAction: "none",
|
|
agentPlans: [],
|
|
projectPlans: [],
|
|
issuePlans: [],
|
|
},
|
|
manifest: {
|
|
schemaVersion: 1,
|
|
generatedAt: "2026-03-23T18:20:00.000Z",
|
|
source: null,
|
|
includes: {
|
|
company: false,
|
|
agents: true,
|
|
projects: false,
|
|
issues: false,
|
|
skills: false,
|
|
},
|
|
company: null,
|
|
sidebar: null,
|
|
agents: [
|
|
{
|
|
slug: "legacy-agent",
|
|
name: "Legacy Agent",
|
|
path: "agents/legacy-agent/AGENT.md",
|
|
skills: [],
|
|
role: "agent",
|
|
title: null,
|
|
icon: null,
|
|
capabilities: null,
|
|
reportsToSlug: null,
|
|
reportsToExistingAgentId: null,
|
|
reportsToExistingAgentSlug: null,
|
|
adapterType: "process",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
permissionGrants: [],
|
|
budgetMonthlyCents: 0,
|
|
metadata: null,
|
|
},
|
|
{
|
|
slug: "explicit-agent",
|
|
name: "Explicit Agent",
|
|
path: "agents/explicit-agent/AGENT.md",
|
|
skills: [],
|
|
role: "agent",
|
|
title: null,
|
|
icon: null,
|
|
capabilities: null,
|
|
reportsToSlug: null,
|
|
reportsToExistingAgentId: null,
|
|
reportsToExistingAgentSlug: null,
|
|
adapterType: "codex_local",
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: {},
|
|
permissionGrants: [],
|
|
budgetMonthlyCents: 0,
|
|
metadata: null,
|
|
},
|
|
],
|
|
skills: [],
|
|
projects: [],
|
|
issues: [],
|
|
envInputs: [],
|
|
},
|
|
files: {},
|
|
envInputs: [],
|
|
warnings: [],
|
|
errors: [],
|
|
};
|
|
|
|
expect(buildDefaultImportAdapterOverrides(preview)).toEqual({
|
|
"legacy-agent": {
|
|
adapterType: "claude_local",
|
|
},
|
|
});
|
|
});
|
|
});
|