mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-19 12:10:37 +09:00
## Thinking Path > - Paperclip is the control plane for autonomous AI companies. > - V1 needs to stay local-first while also supporting shared, authenticated deployments. > - Human operators need real identities, company membership, invite flows, profile surfaces, and company-scoped access controls. > - Agents and operators also need the existing issue, inbox, workspace, approval, and plugin flows to keep working under those authenticated boundaries. > - This branch accumulated the multi-user implementation, follow-up QA fixes, workspace/runtime refinements, invite UX improvements, release-branch conflict resolution, and review hardening. > - This pull request consolidates that branch onto the current `master` branch as a single reviewable PR. > - The benefit is a complete multi-user implementation path with tests and docs carried forward without dropping existing branch work. ## What Changed - Added authenticated human-user access surfaces: auth/session routes, company user directory, profile settings, company access/member management, join requests, and invite management. - Added invite creation, invite landing, onboarding, logo/branding, invite grants, deduped join requests, and authenticated multi-user E2E coverage. - Tightened company-scoped and instance-admin authorization across board, plugin, adapter, access, issue, and workspace routes. - Added profile-image URL validation hardening, avatar preservation on name-only profile updates, and join-request uniqueness migration cleanup for pending human requests. - Added an atomic member role/status/grants update path so Company Access saves no longer leave partially updated permissions. - Improved issue chat, inbox, assignee identity rendering, sidebar/account/company navigation, workspace routing, and execution workspace reuse behavior for multi-user operation. - Added and updated server/UI tests covering auth, invites, membership, issue workspace inheritance, plugin authz, inbox/chat behavior, and multi-user flows. - Merged current `public-gh/master` into this branch, resolved all conflicts, and verified no `pnpm-lock.yaml` change is included in this PR diff. ## Verification - `pnpm exec vitest run server/src/__tests__/issues-service.test.ts ui/src/components/IssueChatThread.test.tsx ui/src/pages/Inbox.test.tsx` - `pnpm run preflight:workspace-links && pnpm exec vitest run server/src/__tests__/plugin-routes-authz.test.ts` - `pnpm exec vitest run server/src/__tests__/plugin-routes-authz.test.ts server/src/__tests__/workspace-runtime-service-authz.test.ts server/src/__tests__/access-validators.test.ts` - `pnpm exec vitest run server/src/__tests__/authz-company-access.test.ts server/src/__tests__/routines-routes.test.ts server/src/__tests__/sidebar-preferences-routes.test.ts server/src/__tests__/approval-routes-idempotency.test.ts server/src/__tests__/openclaw-invite-prompt-route.test.ts server/src/__tests__/agent-cross-tenant-authz-routes.test.ts server/src/__tests__/routines-e2e.test.ts` - `pnpm exec vitest run server/src/__tests__/auth-routes.test.ts ui/src/pages/CompanyAccess.test.tsx` - `pnpm --filter @paperclipai/shared typecheck && pnpm --filter @paperclipai/db typecheck && pnpm --filter @paperclipai/server typecheck` - `pnpm --filter @paperclipai/shared typecheck && pnpm --filter @paperclipai/server typecheck` - `pnpm --filter @paperclipai/ui typecheck` - `pnpm db:generate` - `npx playwright test --config tests/e2e/playwright.config.ts --list` - Confirmed branch has no uncommitted changes and is `0` commits behind `public-gh/master` before PR creation. - Confirmed no `pnpm-lock.yaml` change is staged or present in the PR diff. ## Risks - High review surface area: this PR contains the accumulated multi-user branch plus follow-up fixes, so reviewers should focus especially on company-boundary enforcement and authenticated-vs-local deployment behavior. - UI behavior changed across invites, inbox, issue chat, access settings, and sidebar navigation; no browser screenshots are included in this branch-consolidation PR. - Plugin install, upgrade, and lifecycle/config mutations now require instance-admin access, which is intentional but may change expectations for non-admin board users. - A join-request dedupe migration rejects duplicate pending human requests before creating unique indexes; deployments with unusual historical duplicates should review the migration behavior. - Company member role/status/grant saves now use a new combined endpoint; older separate endpoints remain for compatibility. - Full production build was not run locally in this heartbeat; CI should cover the full matrix. ## Model Used - OpenAI Codex coding agent, GPT-5-based model, CLI/tool-use environment. Exact deployed model identifier and context window were not exposed by the runtime. ## 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 run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge Note on screenshots: this is a branch-consolidation PR for an already-developed multi-user branch, and no browser screenshots were captured during this heartbeat. --------- Co-authored-by: dotta <dotta@example.com> Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
525 lines
18 KiB
TypeScript
525 lines
18 KiB
TypeScript
import express from "express";
|
|
import request from "supertest";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mockAgentService = vi.hoisted(() => ({
|
|
getById: vi.fn(),
|
|
update: vi.fn(),
|
|
create: vi.fn(),
|
|
resolveByReference: vi.fn(),
|
|
}));
|
|
|
|
const mockAccessService = vi.hoisted(() => ({
|
|
canUser: vi.fn(),
|
|
hasPermission: vi.fn(),
|
|
getMembership: vi.fn(),
|
|
listPrincipalGrants: vi.fn(),
|
|
ensureMembership: vi.fn(),
|
|
setPrincipalPermission: vi.fn(),
|
|
}));
|
|
|
|
const mockApprovalService = vi.hoisted(() => ({
|
|
create: vi.fn(),
|
|
}));
|
|
const mockBudgetService = vi.hoisted(() => ({}));
|
|
const mockHeartbeatService = vi.hoisted(() => ({}));
|
|
const mockIssueApprovalService = vi.hoisted(() => ({
|
|
linkManyForApproval: vi.fn(),
|
|
}));
|
|
const mockWorkspaceOperationService = vi.hoisted(() => ({}));
|
|
const mockAgentInstructionsService = vi.hoisted(() => ({
|
|
getBundle: vi.fn(),
|
|
readFile: vi.fn(),
|
|
updateBundle: vi.fn(),
|
|
writeFile: vi.fn(),
|
|
deleteFile: vi.fn(),
|
|
exportFiles: vi.fn(),
|
|
ensureManagedBundle: vi.fn(),
|
|
materializeManagedBundle: vi.fn(),
|
|
}));
|
|
|
|
const mockCompanySkillService = vi.hoisted(() => ({
|
|
listRuntimeSkillEntries: vi.fn(),
|
|
resolveRequestedSkillKeys: vi.fn(),
|
|
}));
|
|
|
|
const mockSecretService = vi.hoisted(() => ({
|
|
resolveAdapterConfigForRuntime: vi.fn(),
|
|
normalizeAdapterConfigForPersistence: vi.fn(async (_companyId: string, config: Record<string, unknown>) => config),
|
|
}));
|
|
|
|
const mockLogActivity = vi.hoisted(() => vi.fn());
|
|
const mockTrackAgentCreated = vi.hoisted(() => vi.fn());
|
|
const mockGetTelemetryClient = vi.hoisted(() => vi.fn());
|
|
const mockSyncInstructionsBundleConfigFromFilePath = vi.hoisted(() => vi.fn());
|
|
|
|
const mockAdapter = vi.hoisted(() => ({
|
|
listSkills: vi.fn(),
|
|
syncSkills: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@paperclipai/shared/telemetry", () => ({
|
|
trackAgentCreated: mockTrackAgentCreated,
|
|
trackErrorHandlerCrash: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("../telemetry.js", () => ({
|
|
getTelemetryClient: mockGetTelemetryClient,
|
|
}));
|
|
|
|
vi.mock("../services/index.js", () => ({
|
|
agentService: () => mockAgentService,
|
|
agentInstructionsService: () => mockAgentInstructionsService,
|
|
accessService: () => mockAccessService,
|
|
approvalService: () => mockApprovalService,
|
|
companySkillService: () => mockCompanySkillService,
|
|
budgetService: () => mockBudgetService,
|
|
heartbeatService: () => mockHeartbeatService,
|
|
issueApprovalService: () => mockIssueApprovalService,
|
|
issueService: () => ({}),
|
|
logActivity: mockLogActivity,
|
|
secretService: () => mockSecretService,
|
|
syncInstructionsBundleConfigFromFilePath: mockSyncInstructionsBundleConfigFromFilePath,
|
|
workspaceOperationService: () => mockWorkspaceOperationService,
|
|
}));
|
|
|
|
vi.mock("../adapters/index.js", () => ({
|
|
findServerAdapter: vi.fn(() => mockAdapter),
|
|
findActiveServerAdapter: vi.fn(() => mockAdapter),
|
|
listAdapterModels: vi.fn(),
|
|
detectAdapterModel: vi.fn(),
|
|
}));
|
|
|
|
function registerModuleMocks() {
|
|
vi.doMock("@paperclipai/shared/telemetry", () => ({
|
|
trackAgentCreated: mockTrackAgentCreated,
|
|
trackErrorHandlerCrash: vi.fn(),
|
|
}));
|
|
|
|
vi.doMock("../telemetry.js", () => ({
|
|
getTelemetryClient: mockGetTelemetryClient,
|
|
}));
|
|
|
|
vi.doMock("../services/index.js", () => ({
|
|
agentService: () => mockAgentService,
|
|
agentInstructionsService: () => mockAgentInstructionsService,
|
|
accessService: () => mockAccessService,
|
|
approvalService: () => mockApprovalService,
|
|
companySkillService: () => mockCompanySkillService,
|
|
budgetService: () => mockBudgetService,
|
|
heartbeatService: () => mockHeartbeatService,
|
|
issueApprovalService: () => mockIssueApprovalService,
|
|
issueService: () => ({}),
|
|
logActivity: mockLogActivity,
|
|
secretService: () => mockSecretService,
|
|
syncInstructionsBundleConfigFromFilePath: mockSyncInstructionsBundleConfigFromFilePath,
|
|
workspaceOperationService: () => mockWorkspaceOperationService,
|
|
}));
|
|
|
|
vi.doMock("../adapters/index.js", () => ({
|
|
findServerAdapter: vi.fn(() => mockAdapter),
|
|
findActiveServerAdapter: vi.fn(() => mockAdapter),
|
|
listAdapterModels: vi.fn(),
|
|
detectAdapterModel: vi.fn(),
|
|
}));
|
|
}
|
|
|
|
function createDb(requireBoardApprovalForNewAgents = false) {
|
|
return {
|
|
select: vi.fn(() => ({
|
|
from: vi.fn(() => ({
|
|
where: vi.fn(async () => [
|
|
{
|
|
id: "company-1",
|
|
requireBoardApprovalForNewAgents,
|
|
},
|
|
]),
|
|
})),
|
|
})),
|
|
};
|
|
}
|
|
|
|
async function createApp(db: Record<string, unknown> = createDb()) {
|
|
const [{ agentRoutes }, { errorHandler }] = await Promise.all([
|
|
vi.importActual<typeof import("../routes/agents.js")>("../routes/agents.js"),
|
|
vi.importActual<typeof import("../middleware/index.js")>("../middleware/index.js"),
|
|
]);
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.use((req, _res, next) => {
|
|
(req as any).actor = {
|
|
type: "board",
|
|
userId: "local-board",
|
|
companyIds: ["company-1"],
|
|
source: "local_implicit",
|
|
isInstanceAdmin: false,
|
|
};
|
|
next();
|
|
});
|
|
app.use("/api", agentRoutes(db as any));
|
|
app.use(errorHandler);
|
|
return app;
|
|
}
|
|
|
|
function makeAgent(adapterType: string) {
|
|
return {
|
|
id: "11111111-1111-4111-8111-111111111111",
|
|
companyId: "company-1",
|
|
name: "Agent",
|
|
role: "engineer",
|
|
title: "Engineer",
|
|
status: "active",
|
|
reportsTo: null,
|
|
capabilities: null,
|
|
adapterType,
|
|
adapterConfig: {},
|
|
runtimeConfig: {},
|
|
permissions: null,
|
|
updatedAt: new Date(),
|
|
};
|
|
}
|
|
|
|
describe("agent skill routes", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
vi.doUnmock("../routes/agents.js");
|
|
vi.doUnmock("../routes/authz.js");
|
|
vi.doUnmock("../middleware/index.js");
|
|
registerModuleMocks();
|
|
vi.resetAllMocks();
|
|
mockSyncInstructionsBundleConfigFromFilePath.mockImplementation((_agent, config) => config);
|
|
mockGetTelemetryClient.mockReturnValue({ track: vi.fn() });
|
|
mockAgentService.resolveByReference.mockResolvedValue({
|
|
ambiguous: false,
|
|
agent: makeAgent("claude_local"),
|
|
});
|
|
mockSecretService.resolveAdapterConfigForRuntime.mockResolvedValue({ config: { env: {} } });
|
|
mockCompanySkillService.listRuntimeSkillEntries.mockResolvedValue([
|
|
{
|
|
key: "paperclipai/paperclip/paperclip",
|
|
runtimeName: "paperclip",
|
|
source: "/tmp/paperclip",
|
|
required: true,
|
|
requiredReason: "required",
|
|
},
|
|
]);
|
|
mockCompanySkillService.resolveRequestedSkillKeys.mockImplementation(
|
|
async (_companyId: string, requested: string[]) =>
|
|
requested.map((value) =>
|
|
value === "paperclip"
|
|
? "paperclipai/paperclip/paperclip"
|
|
: value,
|
|
),
|
|
);
|
|
mockAdapter.listSkills.mockResolvedValue({
|
|
adapterType: "claude_local",
|
|
supported: true,
|
|
mode: "ephemeral",
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
entries: [],
|
|
warnings: [],
|
|
});
|
|
mockAdapter.syncSkills.mockResolvedValue({
|
|
adapterType: "claude_local",
|
|
supported: true,
|
|
mode: "ephemeral",
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
entries: [],
|
|
warnings: [],
|
|
});
|
|
mockAgentService.update.mockImplementation(async (_id: string, patch: Record<string, unknown>) => ({
|
|
...makeAgent("claude_local"),
|
|
adapterConfig: patch.adapterConfig ?? {},
|
|
}));
|
|
mockAgentService.create.mockImplementation(async (_companyId: string, input: Record<string, unknown>) => ({
|
|
...makeAgent(String(input.adapterType ?? "claude_local")),
|
|
...input,
|
|
adapterConfig: input.adapterConfig ?? {},
|
|
runtimeConfig: input.runtimeConfig ?? {},
|
|
budgetMonthlyCents: Number(input.budgetMonthlyCents ?? 0),
|
|
permissions: null,
|
|
}));
|
|
mockApprovalService.create.mockImplementation(async (_companyId: string, input: Record<string, unknown>) => ({
|
|
id: "approval-1",
|
|
companyId: "company-1",
|
|
type: "hire_agent",
|
|
status: "pending",
|
|
payload: input.payload ?? {},
|
|
}));
|
|
mockAgentInstructionsService.materializeManagedBundle.mockImplementation(
|
|
async (agent: Record<string, unknown>, files: Record<string, string>) => ({
|
|
bundle: null,
|
|
adapterConfig: {
|
|
...((agent.adapterConfig as Record<string, unknown> | undefined) ?? {}),
|
|
instructionsBundleMode: "managed",
|
|
instructionsRootPath: `/tmp/${String(agent.id)}/instructions`,
|
|
instructionsEntryFile: "AGENTS.md",
|
|
instructionsFilePath: `/tmp/${String(agent.id)}/instructions/AGENTS.md`,
|
|
promptTemplate: files["AGENTS.md"] ?? "",
|
|
},
|
|
}),
|
|
);
|
|
mockLogActivity.mockResolvedValue(undefined);
|
|
mockAccessService.canUser.mockResolvedValue(true);
|
|
mockAccessService.hasPermission.mockResolvedValue(true);
|
|
mockAccessService.getMembership.mockResolvedValue(null);
|
|
mockAccessService.listPrincipalGrants.mockResolvedValue([]);
|
|
mockAccessService.ensureMembership.mockResolvedValue(undefined);
|
|
mockAccessService.setPrincipalPermission.mockResolvedValue(undefined);
|
|
});
|
|
|
|
it("skips runtime materialization when listing Claude skills", async () => {
|
|
mockAgentService.getById.mockResolvedValue(makeAgent("claude_local"));
|
|
|
|
const res = await request(await createApp())
|
|
.get("/api/agents/11111111-1111-4111-8111-111111111111/skills?companyId=company-1");
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
|
expect(mockAdapter.listSkills).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
adapterType: "claude_local",
|
|
config: expect.objectContaining({
|
|
paperclipRuntimeSkills: expect.any(Array),
|
|
}),
|
|
}),
|
|
);
|
|
}, 10_000);
|
|
|
|
it("skips runtime materialization when listing Codex skills", async () => {
|
|
mockAgentService.getById.mockResolvedValue(makeAgent("codex_local"));
|
|
mockAdapter.listSkills.mockResolvedValue({
|
|
adapterType: "codex_local",
|
|
supported: true,
|
|
mode: "ephemeral",
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
entries: [],
|
|
warnings: [],
|
|
});
|
|
|
|
const res = await request(await createApp())
|
|
.get("/api/agents/11111111-1111-4111-8111-111111111111/skills?companyId=company-1");
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
|
});
|
|
|
|
it("keeps runtime materialization for persistent skill adapters", async () => {
|
|
mockAgentService.getById.mockResolvedValue(makeAgent("cursor"));
|
|
mockAdapter.listSkills.mockResolvedValue({
|
|
adapterType: "cursor",
|
|
supported: true,
|
|
mode: "persistent",
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
entries: [],
|
|
warnings: [],
|
|
});
|
|
|
|
const res = await request(await createApp())
|
|
.get("/api/agents/11111111-1111-4111-8111-111111111111/skills?companyId=company-1");
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
|
});
|
|
|
|
it("skips runtime materialization when syncing Claude skills", async () => {
|
|
mockAgentService.getById.mockResolvedValue(makeAgent("claude_local"));
|
|
|
|
const res = await request(await createApp())
|
|
.post("/api/agents/11111111-1111-4111-8111-111111111111/skills/sync?companyId=company-1")
|
|
.send({ desiredSkills: ["paperclipai/paperclip/paperclip"] });
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
|
expect(mockAdapter.syncSkills).toHaveBeenCalled();
|
|
});
|
|
|
|
it("canonicalizes desired skill references before syncing", async () => {
|
|
mockAgentService.getById.mockResolvedValue(makeAgent("claude_local"));
|
|
|
|
const res = await request(await createApp())
|
|
.post("/api/agents/11111111-1111-4111-8111-111111111111/skills/sync?companyId=company-1")
|
|
.send({ desiredSkills: ["paperclip"] });
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
|
expect(mockAgentService.update).toHaveBeenCalledWith(
|
|
expect.any(String),
|
|
expect.objectContaining({
|
|
adapterConfig: expect.objectContaining({
|
|
paperclipSkillSync: expect.objectContaining({
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
}),
|
|
}),
|
|
}),
|
|
expect.any(Object),
|
|
);
|
|
});
|
|
|
|
it("persists canonical desired skills when creating an agent directly", async () => {
|
|
const res = await request(await createApp())
|
|
.post("/api/companies/company-1/agents")
|
|
.send({
|
|
name: "QA Agent",
|
|
role: "engineer",
|
|
adapterType: "claude_local",
|
|
desiredSkills: ["paperclip"],
|
|
adapterConfig: {},
|
|
});
|
|
|
|
expect([200, 201], JSON.stringify(res.body)).toContain(res.status);
|
|
expect(mockAgentService.create).toHaveBeenCalledWith(
|
|
"company-1",
|
|
expect.objectContaining({
|
|
adapterConfig: expect.objectContaining({
|
|
paperclipSkillSync: expect.objectContaining({
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
}),
|
|
}),
|
|
}),
|
|
);
|
|
expect(mockTrackAgentCreated).toHaveBeenCalledWith(
|
|
expect.anything(),
|
|
expect.objectContaining({
|
|
agentId: "11111111-1111-4111-8111-111111111111",
|
|
agentRole: "engineer",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("materializes a managed AGENTS.md for directly created local agents", async () => {
|
|
const res = await request(await createApp())
|
|
.post("/api/companies/company-1/agents")
|
|
.send({
|
|
name: "QA Agent",
|
|
role: "engineer",
|
|
adapterType: "claude_local",
|
|
adapterConfig: {
|
|
promptTemplate: "You are QA.",
|
|
},
|
|
});
|
|
|
|
expect([200, 201], JSON.stringify(res.body)).toContain(res.status);
|
|
expect(mockAgentService.update).toHaveBeenCalledWith(
|
|
"11111111-1111-4111-8111-111111111111",
|
|
expect.objectContaining({
|
|
adapterConfig: expect.objectContaining({
|
|
instructionsBundleMode: "managed",
|
|
instructionsEntryFile: "AGENTS.md",
|
|
instructionsFilePath: "/tmp/11111111-1111-4111-8111-111111111111/instructions/AGENTS.md",
|
|
}),
|
|
}),
|
|
);
|
|
expect(mockAgentService.update.mock.calls.at(-1)?.[1]).not.toMatchObject({
|
|
adapterConfig: expect.objectContaining({
|
|
promptTemplate: expect.anything(),
|
|
}),
|
|
});
|
|
});
|
|
|
|
it("materializes the bundled CEO instruction set for default CEO agents", async () => {
|
|
const res = await request(await createApp())
|
|
.post("/api/companies/company-1/agents")
|
|
.send({
|
|
name: "CEO",
|
|
role: "ceo",
|
|
adapterType: "claude_local",
|
|
adapterConfig: {},
|
|
});
|
|
|
|
expect([200, 201], JSON.stringify(res.body)).toContain(res.status);
|
|
expect(mockAgentInstructionsService.materializeManagedBundle).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
id: "11111111-1111-4111-8111-111111111111",
|
|
role: "ceo",
|
|
adapterType: "claude_local",
|
|
}),
|
|
expect.objectContaining({
|
|
"AGENTS.md": expect.stringContaining("You are the CEO."),
|
|
"HEARTBEAT.md": expect.stringContaining("CEO Heartbeat Checklist"),
|
|
"SOUL.md": expect.stringContaining("CEO Persona"),
|
|
"TOOLS.md": expect.stringContaining("# Tools"),
|
|
}),
|
|
{ entryFile: "AGENTS.md", replaceExisting: false },
|
|
);
|
|
});
|
|
|
|
it("materializes the bundled default instruction set for non-CEO agents with no prompt template", async () => {
|
|
const res = await request(await createApp())
|
|
.post("/api/companies/company-1/agents")
|
|
.send({
|
|
name: "Engineer",
|
|
role: "engineer",
|
|
adapterType: "claude_local",
|
|
adapterConfig: {},
|
|
});
|
|
|
|
expect([200, 201], JSON.stringify(res.body)).toContain(res.status);
|
|
await vi.waitFor(() => {
|
|
expect(mockAgentInstructionsService.materializeManagedBundle).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
id: "11111111-1111-4111-8111-111111111111",
|
|
role: "engineer",
|
|
adapterType: "claude_local",
|
|
}),
|
|
expect.objectContaining({
|
|
"AGENTS.md": expect.stringContaining("Keep the work moving until it's done."),
|
|
}),
|
|
{ entryFile: "AGENTS.md", replaceExisting: false },
|
|
);
|
|
});
|
|
});
|
|
|
|
it("includes canonical desired skills in hire approvals", async () => {
|
|
const db = createDb(true);
|
|
|
|
const res = await request(await createApp(db))
|
|
.post("/api/companies/company-1/agent-hires")
|
|
.send({
|
|
name: "QA Agent",
|
|
role: "engineer",
|
|
adapterType: "claude_local",
|
|
desiredSkills: ["paperclip"],
|
|
adapterConfig: {},
|
|
});
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(201);
|
|
expect(mockApprovalService.create).toHaveBeenCalledWith(
|
|
"company-1",
|
|
expect.objectContaining({
|
|
payload: expect.objectContaining({
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
requestedConfigurationSnapshot: expect.objectContaining({
|
|
desiredSkills: ["paperclipai/paperclip/paperclip"],
|
|
}),
|
|
}),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("uses managed AGENTS config in hire approval payloads", async () => {
|
|
const res = await request(await createApp(createDb(true)))
|
|
.post("/api/companies/company-1/agent-hires")
|
|
.send({
|
|
name: "QA Agent",
|
|
role: "engineer",
|
|
adapterType: "claude_local",
|
|
adapterConfig: {
|
|
promptTemplate: "You are QA.",
|
|
},
|
|
});
|
|
|
|
expect(res.status, JSON.stringify(res.body)).toBe(201);
|
|
expect(mockApprovalService.create).toHaveBeenCalledWith(
|
|
"company-1",
|
|
expect.objectContaining({
|
|
payload: expect.objectContaining({
|
|
adapterConfig: expect.objectContaining({
|
|
instructionsBundleMode: "managed",
|
|
instructionsEntryFile: "AGENTS.md",
|
|
instructionsFilePath: "/tmp/11111111-1111-4111-8111-111111111111/instructions/AGENTS.md",
|
|
}),
|
|
}),
|
|
}),
|
|
);
|
|
const approvalInput = mockApprovalService.create.mock.calls.at(-1)?.[1] as
|
|
| { payload?: { adapterConfig?: Record<string, unknown> } }
|
|
| undefined;
|
|
expect(approvalInput?.payload?.adapterConfig?.promptTemplate).toBeUndefined();
|
|
});
|
|
});
|