mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
fix: preserve workspace ownership through project changes and recovery
Keep project edits organizational, validate immutable native task roots before materialization, align authorization fixtures, and correct live E2E evidence collection. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
0f4818c623
commit
58bcb04bfd
24 files changed
+176
-40
No files matched your search
@@ -13,6 +13,7 @@ import {
|
||||
import {
|
||||
agents,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
createDb,
|
||||
heartbeatRuns,
|
||||
@@ -113,6 +114,7 @@ describe("durable inbound chat scheduler receipts", () => {
|
||||
defaultResponsibleUserId: "board-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(authUsers).values({ id: "board-user", name: "Fixture user", email: "board-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "board-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
|
||||
@@ -13,7 +13,9 @@ import {
|
||||
agentTaskSessions,
|
||||
agentWakeupRequests,
|
||||
agents,
|
||||
authUsers,
|
||||
companies,
|
||||
companyMemberships,
|
||||
companySkills,
|
||||
createDb,
|
||||
documentRevisions,
|
||||
@@ -107,6 +109,17 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
let tempDb: Awaited<ReturnType<typeof startEmbeddedPostgresTestDatabase>> | null = null;
|
||||
const tempRoots: string[] = [];
|
||||
|
||||
async function grantResponsibleUser(companyId: string) {
|
||||
await db.insert(authUsers).values({
|
||||
id: "responsible-user", name: "Responsible user", email: "accepted-plan@example.test",
|
||||
createdAt: new Date(), updatedAt: new Date(),
|
||||
}).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId, principalType: "user", principalId: "responsible-user",
|
||||
status: "active", membershipRole: "member",
|
||||
});
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
tempDb = await startEmbeddedPostgresTestDatabase("paperclip-accepted-plan-workspace-");
|
||||
db = createDb(tempDb.connectionString);
|
||||
@@ -154,6 +167,7 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
await db.delete(agents);
|
||||
await db.delete(workspaceOperations);
|
||||
await db.delete(companySkills);
|
||||
await db.delete(companyMemberships);
|
||||
await db.delete(companies);
|
||||
});
|
||||
|
||||
@@ -302,6 +316,7 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId);
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
@@ -476,6 +491,7 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId);
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
@@ -712,6 +728,7 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId);
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
@@ -871,6 +888,7 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId);
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
@@ -1031,6 +1049,7 @@ describeEmbeddedPostgres("accepted plan workspace refresh", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId);
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
agentWakeupRequests,
|
||||
companySkills,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
createDb,
|
||||
documentRevisions,
|
||||
documents,
|
||||
@@ -97,6 +99,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
beforeAll(async () => {
|
||||
tempDb = await startEmbeddedPostgresTestDatabase("paperclip-heartbeat-dependency-scheduling-");
|
||||
db = createDb(tempDb.connectionString);
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture owner", email: "owner@example.test", createdAt: new Date(), updatedAt: new Date() });
|
||||
heartbeat = heartbeatService(db);
|
||||
await ensureIssueRelationsTable(db);
|
||||
}, 20_000);
|
||||
@@ -158,6 +161,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
try {
|
||||
await db.transaction(async (tx) => {
|
||||
await tx.delete(companySkills);
|
||||
await tx.delete(companyMemberships);
|
||||
await tx.delete(companies);
|
||||
});
|
||||
break;
|
||||
@@ -199,6 +203,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
await db.insert(companies).values({ id: companyId, name: "Native handoff",
|
||||
issuePrefix: `N${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
||||
requireBoardApprovalForNewAgents: false, defaultResponsibleUserId: "responsible-user" });
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({ id: agentId, companyId, name: "Parent", role: "engineer",
|
||||
status: "active", adapterType: "codex_local", adapterConfig: {}, permissions: {},
|
||||
runtimeConfig: { heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 } } });
|
||||
@@ -265,6 +270,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
issuePrefix: `N${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -354,6 +360,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
it.each(["onboarding", "ordinary", "cancelled"])("dispatches only a verified completed onboarding report: %s", async kind => {
|
||||
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), childId = randomUUID();
|
||||
await db.insert(companies).values({ id: companyId, name: "Completion", issuePrefix: `R${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}` });
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({ id: agentId, companyId, name: "Lead", role: "engineer", status: "active", adapterType: "codex_local",
|
||||
adapterConfig: {}, runtimeConfig: { heartbeat: { wakeOnDemand: true, maxConcurrentRuns: 1 } }, permissions: {} });
|
||||
await db.insert(issues).values({ id: issueId, companyId, title: "Parent", status: kind === "cancelled" ? "cancelled" : "done",
|
||||
@@ -390,6 +397,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
issuePrefix: `R${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -486,6 +494,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -741,6 +750,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
issuePrefix: `D${companyId.replace(/-/g, "").slice(0, 6).toUpperCase()}`,
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -874,6 +884,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -1011,6 +1022,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -1211,6 +1223,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
@@ -1343,6 +1356,7 @@ describeEmbeddedPostgres("heartbeat dependency-aware queued run selection", () =
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
companyId,
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
agentRuntimeState,
|
||||
budgetPolicies,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
companySkills,
|
||||
costEvents,
|
||||
@@ -129,6 +130,7 @@ describeEmbeddedPostgres("heartbeat resolved dependency wake reconciliation", ()
|
||||
await db.delete(companyMemberships);
|
||||
await db.delete(companySkills);
|
||||
await db.delete(companies);
|
||||
await db.delete(authUsers).where(eq(authUsers.id, "responsible-user"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -356,6 +358,7 @@ describeEmbeddedPostgres("heartbeat resolved dependency wake reconciliation", ()
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
});
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture user", email: "responsible-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { EMBEDDED_POSTGRES_TEST_TIMEOUT_MS } from "@paperclipai/db";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { agents, companies, companyMemberships, createDb, heartbeatRuns, issues } from "@paperclipai/db";
|
||||
import { agents, authUsers, companies, companyMemberships, createDb, heartbeatRuns, issues } from "@paperclipai/db";
|
||||
import { getEmbeddedPostgresTestSupport, startEmbeddedPostgresTestDatabase } from "./helpers/embedded-postgres.js";
|
||||
import { heartbeatService } from "../services/heartbeat.js";
|
||||
|
||||
@@ -29,6 +29,7 @@ suite("native terminal-run cleanup admission", () => {
|
||||
it("holds the same task until its native executor settles while allowing unrelated tasks", async () => {
|
||||
const companyId = randomUUID(), agentId = randomUUID(), issueId = randomUUID(), otherIssueId = randomUUID();
|
||||
await db.insert(companies).values({ id: companyId, name: "Cleanup admission", issuePrefix: "CLN", defaultResponsibleUserId: "owner" });
|
||||
await db.insert(authUsers).values({ id: "owner", name: "Fixture user", email: "owner@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "owner", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({ id: agentId, companyId, name: "Worker", role: "engineer", status: "idle", adapterType: "process",
|
||||
adapterConfig: {}, permissions: {}, runtimeConfig: { heartbeat: { enabled: false, wakeOnDemand: true, maxConcurrentRuns: 20 } } });
|
||||
|
||||
@@ -5,7 +5,9 @@ import path from "node:path";
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
agents,
|
||||
authUsers,
|
||||
companies,
|
||||
companyMemberships,
|
||||
createDb,
|
||||
environments,
|
||||
executionWorkspaces,
|
||||
@@ -60,6 +62,16 @@ describeEmbeddedPostgres("heartbeat plugin environments", () => {
|
||||
let db!: ReturnType<typeof createDb>;
|
||||
const tempRoots: string[] = [];
|
||||
|
||||
async function grantResponsibleUser(companyId: string, userId: string) {
|
||||
await db.insert(authUsers).values({
|
||||
id: userId, name: "Responsible user", email: `${userId}@example.test`,
|
||||
createdAt: new Date(), updatedAt: new Date(),
|
||||
}).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId, principalType: "user", principalId: userId, status: "active", membershipRole: "member",
|
||||
});
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const started = await startEmbeddedPostgresTestDatabase("heartbeat-plugin-environment");
|
||||
stopDb = started.stop;
|
||||
@@ -116,6 +128,7 @@ describeEmbeddedPostgres("heartbeat plugin environments", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId, "responsible-user");
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
@@ -360,6 +373,8 @@ describeEmbeddedPostgres("heartbeat plugin environments", () => {
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
]);
|
||||
await grantResponsibleUser(companyAId, "responsible-user-a");
|
||||
await grantResponsibleUser(companyBId, "responsible-user-b");
|
||||
await db.insert(projects).values([
|
||||
{
|
||||
id: projectAId,
|
||||
@@ -523,6 +538,7 @@ describeEmbeddedPostgres("heartbeat plugin environments", () => {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await grantResponsibleUser(companyId, "responsible-user");
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
companyId,
|
||||
|
||||
@@ -6050,8 +6050,10 @@ describeEmbeddedPostgres("heartbeat orphaned process recovery", () => {
|
||||
executionRecovery: { kind: "bootstrap", providerWorkStarted: false },
|
||||
},
|
||||
});
|
||||
expect(run.error).toContain("checkout could not be prepared");
|
||||
expect(run.error).toContain("Configured project workspace is unavailable");
|
||||
expect(run.error).toContain("Repair the configured path or repository access");
|
||||
const validation = run.resultJson!.workspaceValidation as Record<string, unknown>;
|
||||
expect(validation.baseCwdFallback).toBe(false);
|
||||
const materializations = validation.materializationFailures as Array<Record<string, unknown>>;
|
||||
expect(materializations).toHaveLength(failures.length);
|
||||
expect(materializations.map((failure) => failure.connectionFailure)).toEqual(failures.map((failure) =>
|
||||
|
||||
@@ -7,7 +7,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { agents, companies, companyMemberships, createDb, environments, executionWorkspaces, heartbeatRuns, issues, projects, projectWorkspaces } from "@paperclipai/db";
|
||||
import { agents, authUsers, companies, companyMemberships, createDb, environments, executionWorkspaces, heartbeatRuns, issues, projects, projectWorkspaces } from "@paperclipai/db";
|
||||
import { setExpensiveWorkspaceGitExecutor } from "@paperclipai/adapter-utils/git-workspace-sync";
|
||||
import { buildProjectMentionHref } from "@paperclipai/shared";
|
||||
import { createWorkspaceGitOperationScheduler, WorkspaceGitScanError } from "../services/workspace-git-operation-scheduler.js";
|
||||
@@ -38,6 +38,7 @@ suite("task project repository provisioning", () => {
|
||||
vi.stubEnv("PAPERCLIP_MULTI_PROJECT_WORKSPACE_SYNC", "false");
|
||||
database = await startEmbeddedPostgresTestDatabase("project-repositories");
|
||||
db = createDb(database.connectionString);
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture owner", email: "owner@example.test", createdAt: new Date(), updatedAt: new Date() });
|
||||
heartbeat = heartbeatService(db);
|
||||
execute.mockImplementation(async (input) => {
|
||||
await db.update(issues).set({ status: "done" }).where(eq(issues.id, input.context.issueId));
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
agentRuntimeState,
|
||||
agentWakeupRequests,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
companySkills,
|
||||
createDb,
|
||||
@@ -121,6 +122,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => {
|
||||
await db.delete(companySkills);
|
||||
await db.delete(companyMemberships);
|
||||
await db.delete(companies);
|
||||
await db.delete(authUsers);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -300,6 +302,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => {
|
||||
const { companyId, agentId } = await seedCompany();
|
||||
const issueResponsibleUserId = `issue-owner-${randomUUID()}`;
|
||||
const commenterUserId = `commenter-${randomUUID()}`;
|
||||
await db.insert(authUsers).values([issueResponsibleUserId, commenterUserId].map(id => ({ id, name: "Fixture user", email: `${id}@example.test`, createdAt: new Date(), updatedAt: new Date() })));
|
||||
await db.insert(companyMemberships).values([issueResponsibleUserId, commenterUserId].map(principalId => ({ companyId, principalType: "user" as const, principalId, status: "active", membershipRole: "member" })));
|
||||
const issueId = randomUUID();
|
||||
await db.insert(issues).values({
|
||||
@@ -357,6 +360,7 @@ describeEmbeddedPostgres("heartbeat responsible-user invariant", () => {
|
||||
const { companyId, agentId } = await seedCompany();
|
||||
const issueResponsibleUserId = `issue-owner-${randomUUID()}`;
|
||||
const commenterUserId = `commenter-${randomUUID()}`;
|
||||
await db.insert(authUsers).values([issueResponsibleUserId, commenterUserId].map(id => ({ id, name: "Fixture user", email: `${id}@example.test`, createdAt: new Date(), updatedAt: new Date() })));
|
||||
await db.insert(companyMemberships).values([issueResponsibleUserId, commenterUserId].map(principalId => ({ companyId, principalType: "user" as const, principalId, status: "active", membershipRole: "member" })));
|
||||
const issueId = randomUUID();
|
||||
const commentId = randomUUID();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
agents, chatConversations, chatDeliveries, chatEndpointResources,
|
||||
agents, authUsers, chatConversations, chatDeliveries, chatEndpointResources,
|
||||
chatEndpoints, chatExternalPrincipals, chatIdentityLinks, chatMessageLinks,
|
||||
companies, companyMemberships, createDb, issueComments, issues,
|
||||
toolApplications, toolConnections,
|
||||
@@ -55,6 +55,7 @@ describePostgres("saved Slack invitation command in heartbeat prompts", () => {
|
||||
const endpointId = randomUUID(), resourceId = randomUUID(), conversationId = randomUUID();
|
||||
const applicationId = randomUUID(), connectionId = randomUUID(), principalId = randomUUID();
|
||||
const userId = `invitation-user-${randomUUID()}`;
|
||||
await db.insert(authUsers).values({ id: userId, name: "Invitation user", email: `${userId}@example.test`, createdAt: new Date(), updatedAt: new Date() });
|
||||
await db.insert(companies).values({ id: companyId, name: "Invitation fixture", issuePrefix: `I${companyId.slice(0, 6)}` });
|
||||
await db.insert(agents).values({
|
||||
id: agentId, companyId, name: "Original researcher", adapterType, status: "idle",
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
agentWakeupRequests,
|
||||
agents,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
companySkills,
|
||||
createDb,
|
||||
@@ -344,6 +345,7 @@ async function seedBranchContainmentRun(
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
});
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture user", email: "responsible-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
@@ -932,6 +934,7 @@ describeEmbeddedPostgres("heartbeat workspace branch containment", () => {
|
||||
await db.delete(companySkills);
|
||||
await db.delete(companyMemberships);
|
||||
await db.delete(companies);
|
||||
await db.delete(authUsers).where(eq(authUsers.id, "responsible-user"));
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
@@ -976,6 +979,7 @@ describeEmbeddedPostgres("heartbeat workspace branch containment", () => {
|
||||
};
|
||||
await instanceSettingsService(db).updateExperimental({ enableIsolatedWorkspaces: true });
|
||||
await db.insert(companies).values({ id: companyId, name: "Retained source", issuePrefix, status: "active", defaultResponsibleUserId: "responsible-user" });
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture user", email: "responsible-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(projects).values({ id: projectId, companyId, name: "Repository replacement", status: "active",
|
||||
executionWorkspacePolicy: { enabled: true, defaultMode: "isolated_workspace", workspaceStrategy: { type: "git_worktree", baseRef: "HEAD" } } });
|
||||
@@ -1082,6 +1086,7 @@ describeEmbeddedPostgres("heartbeat workspace branch containment", () => {
|
||||
status: "active",
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture user", email: "responsible-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(agents).values({
|
||||
id: agentId,
|
||||
|
||||
@@ -7,11 +7,13 @@ import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest
|
||||
import {
|
||||
costEvents,
|
||||
agents,
|
||||
authUsers,
|
||||
agentRuntimeState,
|
||||
agentWakeupRequests,
|
||||
activityLog,
|
||||
budgetPolicies,
|
||||
companies,
|
||||
companyMemberships,
|
||||
companySkills,
|
||||
createDb,
|
||||
closeRegisteredClients,
|
||||
@@ -200,6 +202,7 @@ describeEmbeddedPostgres("shared-workspace run serialization", () => {
|
||||
await db.delete(agents);
|
||||
await db.delete(environments);
|
||||
await db.delete(companySkills);
|
||||
await db.delete(companyMemberships);
|
||||
await db.delete(companies);
|
||||
}
|
||||
|
||||
@@ -280,6 +283,14 @@ describeEmbeddedPostgres("shared-workspace run serialization", () => {
|
||||
requireBoardApprovalForNewAgents: false,
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(authUsers).values({
|
||||
id: "responsible-user", name: "Responsible user", email: "workspace-busy@example.test",
|
||||
createdAt: now, updatedAt: now,
|
||||
}).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId, principalType: "user", principalId: "responsible-user",
|
||||
status: "active", membershipRole: "member",
|
||||
});
|
||||
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
agentWakeupRequests,
|
||||
agents,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
companySkills,
|
||||
createDb,
|
||||
@@ -168,6 +169,7 @@ async function seedRunTarget(db: Db, repoRoot: string) {
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
});
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture user", email: "responsible-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db.insert(projects).values({
|
||||
id: projectId,
|
||||
@@ -312,6 +314,7 @@ describeEmbeddedPostgres("heartbeat workspace finalization branch guard", () =>
|
||||
await db.delete(companySkills);
|
||||
await db.delete(companyMemberships);
|
||||
await db.delete(companies);
|
||||
await db.delete(authUsers).where(eq(authUsers.id, "responsible-user"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
||||
@@ -4,7 +4,9 @@ import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { eq } from "drizzle-orm";
|
||||
import {
|
||||
agents,
|
||||
authUsers,
|
||||
companies,
|
||||
companyMemberships,
|
||||
completionContracts,
|
||||
createDb,
|
||||
heartbeatRuns,
|
||||
@@ -67,6 +69,13 @@ describe("P6-32 legacy finalization regression", () => {
|
||||
status: "active",
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(authUsers).values({
|
||||
id: "responsible-user", name: "Responsible user", email: "legacy-finalization@example.test",
|
||||
createdAt: new Date(), updatedAt: new Date(),
|
||||
});
|
||||
await db.insert(companyMemberships).values({
|
||||
companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member",
|
||||
});
|
||||
await db.insert(projects).values({ id: projectId, companyId, name: "Legacy project", status: "active" });
|
||||
await db.insert(projectWorkspaces).values({
|
||||
id: projectWorkspaceId,
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
agentWakeupRequests,
|
||||
agents,
|
||||
companies,
|
||||
authUsers,
|
||||
companyMemberships,
|
||||
completionContracts,
|
||||
createDb,
|
||||
@@ -797,6 +798,7 @@ describe.each(["unchanged", "newer_active", "stale_idle"] as const)(
|
||||
status: "active",
|
||||
defaultResponsibleUserId: "responsible-user",
|
||||
});
|
||||
await db.insert(authUsers).values({ id: "responsible-user", name: "Fixture user", email: "responsible-user@example.test", createdAt: new Date(), updatedAt: new Date() }).onConflictDoNothing();
|
||||
await db.insert(companyMemberships).values({ companyId, principalType: "user", principalId: "responsible-user", status: "active", membershipRole: "member" });
|
||||
await db
|
||||
.insert(projects)
|
||||
|
||||
@@ -266,6 +266,8 @@ describe("native external chat workspace boundary", () => {
|
||||
path.join(instanceRoot, "workspaces", agentId),
|
||||
]) {
|
||||
const oldInput = { ...execution, workspace: { cwd } };
|
||||
const admittedScope = { ...scopeA, taskRoot: cwd };
|
||||
expect(nativeChatWorkspaceCwd(admittedScope, null, false)).toBeNull();
|
||||
expect(
|
||||
nativeChatWorkspaceMatches({
|
||||
scope: scopeA,
|
||||
@@ -275,6 +277,8 @@ describe("native external chat workspace boundary", () => {
|
||||
).toBe(false);
|
||||
expect(oldInput.workspace.cwd).toBe(cwd);
|
||||
}
|
||||
const legacyTaskRoot = path.join(instanceRoot, "chat-workspaces", companyId, agentId, issueA);
|
||||
expect(nativeChatWorkspaceCwd({ ...scopeA, taskRoot: legacyTaskRoot }, null, false)).toBe(legacyTaskRoot);
|
||||
});
|
||||
|
||||
it("fails closed if an existing task directory is a symlink to another task", async () => {
|
||||
|
||||
@@ -101,16 +101,26 @@ export type NativeChatProjectWorkspace = {
|
||||
providerRef: string | null;
|
||||
};
|
||||
|
||||
function isNativeChatTaskRoot(scope: NativeChatWorkspaceScope): boolean {
|
||||
const relative = path.relative(scope.instanceRoot, scope.taskRoot);
|
||||
const allowedTask = path.join("isolated-workspaces", segment(scope.companyId), segment(scope.issueId));
|
||||
const legacyParts = relative.split(path.sep);
|
||||
return relative === allowedTask || (
|
||||
legacyParts.length === 4 && legacyParts[0] === "chat-workspaces" &&
|
||||
legacyParts[1] === scope.companyId && /^[a-zA-Z0-9_-]+$/.test(legacyParts[2]!) && legacyParts[3] === scope.issueId
|
||||
);
|
||||
}
|
||||
|
||||
/** No implicit move from an intentionally configured repository to an empty cwd. */
|
||||
export function nativeChatWorkspaceCwd(
|
||||
scope: NativeChatWorkspaceScope,
|
||||
workspace: NativeChatProjectWorkspace | null,
|
||||
reuseExisting: boolean,
|
||||
): string | null {
|
||||
if (!scope.projectId) return workspace === null || (
|
||||
if (!scope.projectId) return isNativeChatTaskRoot(scope) && (workspace === null || (
|
||||
workspace.companyId === scope.companyId && workspace.sourceIssueId === scope.issueId &&
|
||||
workspace.projectId === null && workspace.cwd === scope.taskRoot && ["active", "idle"].includes(workspace.status)
|
||||
) ? scope.taskRoot : null;
|
||||
)) ? scope.taskRoot : null;
|
||||
if (
|
||||
!reuseExisting ||
|
||||
!workspace ||
|
||||
@@ -136,11 +146,7 @@ export async function materializeNativeChatTaskRoot(
|
||||
throw new Error("native_chat_workspace_project_requires_isolation");
|
||||
let cursor = scope.instanceRoot;
|
||||
const relative = path.relative(scope.instanceRoot, scope.taskRoot);
|
||||
const allowedTask = path.join("isolated-workspaces", segment(scope.companyId), segment(scope.issueId));
|
||||
const legacyParts = relative.split(path.sep);
|
||||
const allowedLegacy = legacyParts.length === 4 && legacyParts[0] === "chat-workspaces" &&
|
||||
legacyParts[1] === scope.companyId && /^[a-zA-Z0-9_-]+$/.test(legacyParts[2]!) && legacyParts[3] === scope.issueId;
|
||||
if (relative !== allowedTask && !allowedLegacy) throw new Error("native_chat_workspace_path_not_isolated");
|
||||
if (!isNativeChatTaskRoot(scope)) throw new Error("native_chat_workspace_path_not_isolated");
|
||||
for (const part of relative.split(path.sep)) {
|
||||
cursor = path.join(cursor, part);
|
||||
await mkdir(cursor, { mode: 0o700 }).catch(
|
||||
|
||||
@@ -47,7 +47,7 @@ export function taskWorkspacePrompt(nonce: string, turn: 1 | 2 | 3, native: bool
|
||||
`Update ${files.note} to exactly ${JSON.stringify(files.noteBytes(3))}.`,
|
||||
`Register ${files.proof} as a downloadable artifact work product with exact title ${files.proof}.`,
|
||||
];
|
||||
return [...content, api,
|
||||
return [...content, "The quoted \\n escapes denote actual LF bytes. Include the final LF when writing each exact string; verify byte counts before finishing.", api,
|
||||
turn < 3 ? "Save a short Paperclip task document describing this completed step as its durable work product. Then complete this step and mark the task Done; do not wait for the next user message."
|
||||
: "Validate the written and downloaded-proof source bytes before completing the task.",
|
||||
native ? "Use paperclip_finish with reportedWorkDisposition done, the current completion contract revision, satisfied objective criterion, real evidence references, and no remaining work for THIS requested step."
|
||||
|
||||
@@ -8,7 +8,7 @@ import { createTaskThroughUi, submitTaskReply } from "./user-actions.js";
|
||||
import { collectRunEvents } from "./run-observations.js";
|
||||
import { readRegisteredArtifacts } from "./registered-artifact.js";
|
||||
import { TASK_WORKSPACES_BUDGET_CENTS, taskWorkspaceFiles, taskWorkspacePrompt } from "./task-workspaces-cases.js";
|
||||
import { gradeTaskWorkspaces, type TaskWorkspaceCheckpoint, type TaskWorkspaceObservation } from "./task-workspaces-scoring.js";
|
||||
import { gradeTaskWorkspaces, isRepositoryPreparationReceipt, type TaskWorkspaceCheckpoint, type TaskWorkspaceObservation } from "./task-workspaces-scoring.js";
|
||||
import type { LiveFixtureValues } from "./live-fixtures.js";
|
||||
import type { MatrixExecution } from "./types.js";
|
||||
|
||||
@@ -111,9 +111,7 @@ export async function runTaskWorkspacesFlow(input: {
|
||||
&& event.payload.prpEvent.runId === run.id && event.payload.prpEvent.payload?.result?.reportedWorkDisposition === "done")
|
||||
&& events.some(event => event.eventType === "run.terminal" && event.payload?.prpEvent?.sourceKind === "control_plane"
|
||||
&& event.payload.prpEvent.runId === run.id && event.payload.prpEvent.payload?.runTerminalState === "succeeded") },
|
||||
prepareCalls: events.filter(event => event.eventType === "tool.execution.completed"
|
||||
&& event.payload?.prpEvent?.sourceKind === "runner" && event.payload.prpEvent.runId === run.id
|
||||
&& /(?:^|\.)prepare_repository$/.test(String(event.payload.prpEvent.payload?.name)) && event.payload.prpEvent.payload?.status === "completed").length,
|
||||
prepareCalls: events.filter(event => isRepositoryPreparationReceipt(event, run.id)).length,
|
||||
};
|
||||
if (turn > 1) {
|
||||
const repository = view.repositories[0];
|
||||
@@ -132,7 +130,7 @@ export async function runTaskWorkspacesFlow(input: {
|
||||
.filter(lease => lease.issueId === issue!.id && typeof lease.providerLeaseId === "string").map(lease => lease.heartbeatRunId);
|
||||
await save(`turn-${turn}`);
|
||||
await page.reload();
|
||||
await expect(page.getByTestId("issue-detail-header")).toBeVisible();
|
||||
await expect(page.getByTestId("task-chat-thread-header").getByTestId("issue-detail-header")).toBeVisible();
|
||||
await expect(page.getByTestId("task-chat-agent-bubble").filter({ hasText: `TASK-WORKSPACE-${turn}-${nonce}` }).last()).toBeVisible({ timeout: 30_000 });
|
||||
await input.capture(`task-files-turn-${turn}`, `Projectless task after turn ${turn}`, `task-files-turn-${turn}.png`);
|
||||
}
|
||||
|
||||
@@ -74,3 +74,14 @@ export function gradeTaskWorkspaces(value: TaskWorkspaceObservation) {
|
||||
"Every remote turn has a public Daytona environment lease attributed to that run.");
|
||||
return checks;
|
||||
}
|
||||
|
||||
/** Count durable runner receipts, including the provider's normalized tool name. */
|
||||
export function isRepositoryPreparationReceipt(event: {
|
||||
eventType?: string;
|
||||
payload?: { prpEvent?: { sourceKind?: string; runId?: string; payload?: { name?: string; status?: string } } };
|
||||
}, runId: string) {
|
||||
const receipt = event.payload?.prpEvent;
|
||||
return event.eventType === "tool.execution.completed" && receipt?.sourceKind === "runner"
|
||||
&& receipt.runId === runId && receipt.payload?.status === "completed"
|
||||
&& ["prepare_repository", "paperclip.prepare_repository", "paperclip_prepare_repository"].includes(receipt.payload.name ?? "");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runnerMatrix } from "./catalog.js";
|
||||
import { gradeTaskWorkspaces, type TaskWorkspaceObservation } from "./task-workspaces-scoring.js";
|
||||
import { gradeTaskWorkspaces, isRepositoryPreparationReceipt, type TaskWorkspaceObservation } from "./task-workspaces-scoring.js";
|
||||
import { TASK_WORKSPACES_SUITE, taskWorkspaceFiles, taskWorkspacePrompt } from "./task-workspaces-cases.js";
|
||||
|
||||
function valid(): TaskWorkspaceObservation {
|
||||
@@ -43,6 +43,18 @@ describe("task workspace product E2E", () => {
|
||||
expect(taskWorkspacePrompt("fixture", 1, false)).toContain("POST /api/issues/$PAPERCLIP_TASK_ID/workspace/repositories twice");
|
||||
expect(taskWorkspacePrompt("fixture", 3, true)).not.toContain(taskWorkspaceFiles("fixture").repositoryBytes.trim());
|
||||
});
|
||||
it("recognizes the normalized provider receipt and rejects claims from another source/run", () => {
|
||||
const receipt = { eventType: "tool.execution.completed", payload: { prpEvent: {
|
||||
sourceKind: "runner", runId: "run-1", payload: { name: "paperclip_prepare_repository", status: "completed" },
|
||||
} } };
|
||||
expect(isRepositoryPreparationReceipt(receipt, "run-1")).toBe(true);
|
||||
expect(isRepositoryPreparationReceipt(receipt, "another-run")).toBe(false);
|
||||
receipt.payload.prpEvent.sourceKind = "control_plane";
|
||||
expect(isRepositoryPreparationReceipt(receipt, "run-1")).toBe(false);
|
||||
receipt.payload.prpEvent.sourceKind = "runner";
|
||||
receipt.payload.prpEvent.payload.status = "failed";
|
||||
expect(isRepositoryPreparationReceipt(receipt, "run-1")).toBe(false);
|
||||
});
|
||||
it("accepts independently consistent persisted observations", () => {
|
||||
expect(gradeTaskWorkspaces(valid()).filter(check => !check.passed)).toEqual([]);
|
||||
const legacy = valid(); legacy.native = false; legacy.daytona = false;
|
||||
|
||||
@@ -16,6 +16,7 @@ import type { Issue, IssueDocument } from "@paperclipai/shared";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { getLastProjectId } from "../lib/recent-projects";
|
||||
import { IssueProperties } from "./IssueProperties";
|
||||
import { applyOptimisticIssueFieldUpdate } from "../lib/optimistic-issue-comments";
|
||||
import { queryKeys } from "../lib/queryKeys";
|
||||
|
||||
const mockAgentsApi = vi.hoisted(() => ({
|
||||
@@ -1940,6 +1941,36 @@ describe("IssueProperties", () => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
it("changes only project organization while preserving the bound workspace", async () => {
|
||||
mockProjectsApi.list.mockResolvedValue([createProject({ name: "Target Project" })]);
|
||||
const workspace = createExecutionWorkspace({ projectId: null, projectWorkspaceId: null });
|
||||
const issue = createIssue({
|
||||
executionWorkspaceId: workspace.id,
|
||||
currentExecutionWorkspace: workspace,
|
||||
});
|
||||
const onUpdate = vi.fn();
|
||||
const root = renderProperties(container, { issue, childIssues: [], onUpdate, inline: true });
|
||||
await flush();
|
||||
await act(() => findRowTrigger(container, "Project")!.click());
|
||||
const project = [...document.querySelectorAll<HTMLButtonElement>("button")]
|
||||
.find((button) => button.textContent?.trim() === "Target Project")!;
|
||||
act(() => project.click());
|
||||
expect(onUpdate).toHaveBeenLastCalledWith({ projectId: "project-1" });
|
||||
const assigned = applyOptimisticIssueFieldUpdate(issue, onUpdate.mock.lastCall![0])!;
|
||||
expect(assigned.executionWorkspaceId).toBe(workspace.id);
|
||||
expect(assigned.currentExecutionWorkspace).toBe(workspace);
|
||||
await act(() => findRowTrigger(container, "Project")!.click());
|
||||
const none = [...document.querySelectorAll<HTMLButtonElement>("button")]
|
||||
.find((button) => button.textContent?.trim() === "No project")!;
|
||||
act(() => none.click());
|
||||
expect(onUpdate).toHaveBeenLastCalledWith({ projectId: null });
|
||||
const cleared = applyOptimisticIssueFieldUpdate(assigned, onUpdate.mock.lastCall![0])!;
|
||||
expect(cleared.executionWorkspaceId).toBe(workspace.id);
|
||||
expect(cleared.currentExecutionWorkspace).toBe(workspace);
|
||||
expect(cleared.currentExecutionWorkspace?.cwd).toBe(workspace.cwd);
|
||||
act(() => root.unmount());
|
||||
});
|
||||
|
||||
it("shows a green service link above the workspace row for a live non-main workspace", async () => {
|
||||
mockProjectsApi.list.mockResolvedValue([createProject()]);
|
||||
const serviceUrl = "http://127.0.0.1:62475";
|
||||
|
||||
@@ -102,8 +102,6 @@ import { ExternalObjectRows } from "./external-object-rows";
|
||||
import {
|
||||
asRecord,
|
||||
compactRecord,
|
||||
defaultExecutionWorkspaceModeForProject,
|
||||
defaultProjectWorkspaceIdForProject,
|
||||
isMainIssueWorkspace,
|
||||
overrideLane,
|
||||
sortAdapterModels,
|
||||
@@ -2008,26 +2006,7 @@ export function IssueProperties({
|
||||
option.id === (issue.projectId ?? "") && "bg-accent",
|
||||
)}
|
||||
onClick={() => {
|
||||
if (option.kind === "project") {
|
||||
const defaultMode = defaultExecutionWorkspaceModeForProject(option.project);
|
||||
onUpdate({
|
||||
projectId: option.project.id,
|
||||
projectWorkspaceId: defaultProjectWorkspaceIdForProject(option.project),
|
||||
executionWorkspaceId: null,
|
||||
executionWorkspacePreference: workspaceIsolationControlsVisible ? defaultMode : null,
|
||||
executionWorkspaceSettings: workspaceIsolationControlsVisible && option.project.executionWorkspacePolicy?.enabled
|
||||
? { mode: defaultMode }
|
||||
: null,
|
||||
});
|
||||
} else {
|
||||
onUpdate({
|
||||
projectId: null,
|
||||
projectWorkspaceId: null,
|
||||
executionWorkspaceId: null,
|
||||
executionWorkspacePreference: null,
|
||||
executionWorkspaceSettings: null,
|
||||
});
|
||||
}
|
||||
onUpdate({ projectId: option.kind === "project" ? option.project.id : null });
|
||||
setProjectOpen(false);
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -52,6 +52,8 @@ vi.mock("@/api/chatEndpoints", () => ({
|
||||
listPrincipals: mocks.links,
|
||||
},
|
||||
}));
|
||||
vi.mock("@/api/projects", () => ({ projectsApi: { list: vi.fn().mockResolvedValue([]) } }));
|
||||
vi.mock("@/api/execution-workspaces", () => ({ executionWorkspacesApi: { listSummaries: vi.fn().mockResolvedValue([]) } }));
|
||||
vi.mock("@/api/access", () => ({ accessApi: { listMembers: mocks.members } }));
|
||||
vi.mock("@/api/agents", () => ({ agentsApi: { get: vi.fn() } }));
|
||||
vi.mock("@/context/BreadcrumbContext", () => ({
|
||||
|
||||
Reference in new issue
Block a user