Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🚧 fix(project): temporarily disable task moves (#20667)

Bryan1e86647c12a3
diff --git a/apps/cli/src/commands/project.test.ts b/apps/cli/src/commands/project.test.ts
index 1574459f9f9..dc3217667d4 100644
--- a/apps/cli/src/commands/project.test.ts
+++ b/apps/cli/src/commands/project.test.ts
@@ -1,5 +1,5 @@
import { Command } from 'commander';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { registerProjectCommand } from './project';
@@ -13,7 +13,6 @@ const { mockClient, mockResolveWorkspaceId } = vi.hoisted(() => ({
delete: { mutate: vi.fn() },
detail: { query: vi.fn() },
list: { query: vi.fn() },
- moveTask: { mutate: vi.fn() },
rejectCompletion: { mutate: vi.fn() },
removeAgent: { mutate: vi.fn() },
removeKnowledgeBase: { mutate: vi.fn() },
@@ -48,6 +47,10 @@ describe('project command', () => {
vi.spyOn(console, 'log').mockImplementation(() => {});
});
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
it('creates a project', async () => {
mockClient.project.create.mutate.mockResolvedValue({ data: { id: 'prj_1' } });
await createProgram().parseAsync([
diff --git a/apps/cli/src/commands/project.ts b/apps/cli/src/commands/project.ts
index 3cc2513a333..f11cf8f7806 100644
--- a/apps/cli/src/commands/project.ts
+++ b/apps/cli/src/commands/project.ts
@@ -206,10 +206,6 @@ export function registerProjectCommand(program: Command) {
console.log(`${pc.bold('task')}: ${url}`);
},
);
- task.command('move <projectId> <taskId>').action(async (projectId: string, taskId: string) => {
- const result = await (await getTrpcClient()).project.moveTask.mutate({ id: projectId, taskId });
- console.log(`${pc.green('✓')} Moved ${result.data.length} task(s)`);
- });
project.command('request-review <id>').action(async (id: string) => {
await (await getTrpcClient()).project.requestCompletion.mutate({ id });
diff --git a/apps/server/src/routers/lambda/project.ts b/apps/server/src/routers/lambda/project.ts
index 4f188d41f2c..1c7c30fd47c 100644
--- a/apps/server/src/routers/lambda/project.ts
+++ b/apps/server/src/routers/lambda/project.ts
@@ -204,15 +204,15 @@ export const projectRouter = router({
}
}),
+ // Keep the released API contract so old clients receive a clear business error.
+ // Project moves are paused while project-scoped task numbering is redesigned.
moveTask: projectWriteProcedure
.input(idInput.extend({ taskId: z.string() }))
- .mutation(async ({ ctx, input }) => {
- try {
- const rows = requireResult(await ctx.projectModel.moveTaskTree(input.id, input.taskId));
- return { data: rows, message: `${rows.length} task(s) moved`, success: true };
- } catch (error) {
- mapProjectError(error, 'moveTask');
- }
+ .mutation(async () => {
+ throw new TRPCError({
+ code: 'PRECONDITION_FAILED',
+ message: 'Moving tasks between projects is temporarily disabled',
+ });
}),
rejectCompletion: projectWriteProcedure
diff --git a/packages/database/src/models/__tests__/project.test.ts b/packages/database/src/models/__tests__/project.test.ts
index 9efe5cb2cb0..29a8259c1c1 100644
--- a/packages/database/src/models/__tests__/project.test.ts
+++ b/packages/database/src/models/__tests__/project.test.ts
@@ -312,63 +312,6 @@ describe('ProjectModel', () => {
expect(await serverDB.select().from(works).where(eq(works.id, work.id))).toHaveLength(1);
});
- it('moves a task subtree into a project', async () => {
- const project = await createProject(model, { name: 'Tasks' });
- const taskModel = new TaskModel(serverDB, userId);
- const parent = await taskModel.create({ instruction: 'Parent' });
- const child = await taskModel.create({ instruction: 'Child', parentTaskId: parent.id });
-
- const moved = await model.moveTaskTree(project.id, parent.id);
- expect(moved?.map(({ id }) => id).sort()).toEqual([child.id, parent.id].sort());
- const projectTasks = await model.listTasks(project.id);
- expect(projectTasks?.map(({ id }) => id).sort()).toEqual([child.id, parent.id].sort());
- });
-
- it('preserves project tree boundaries when moving tasks', async () => {
- const source = await createProject(model, { name: 'Source' });
- const target = await createProject(model, { name: 'Target' });
- const taskModel = new TaskModel(serverDB, userId);
- const parent = await taskModel.create({ instruction: 'Parent', projectId: source.id });
- const child = await taskModel.create({
- instruction: 'Child',
- parentTaskId: parent.id,
- projectId: source.id,
- });
-
- await expect(model.moveTaskTree(target.id, child.id)).rejects.toThrow(
- 'Cannot move a task away from its parent project',
- );
- await serverDB.update(tasks).set({ projectId: target.id }).where(eq(tasks.id, parent.id));
- expect(await model.moveTaskTree(target.id, child.id)).toEqual([
- expect.objectContaining({ id: child.id }),
- ]);
- await expect(model.moveTaskTree(target.id, 'missing')).rejects.toThrow('Task not found');
- expect(await model.moveTaskTree('missing', child.id)).toBeNull();
- });
-
- it('rejects moving a workspace task tree with descendants created by another member', async () => {
- await serverDB.insert(workspaces).values({
- id: 'mixed-tree-workspace',
- name: 'Mixed Tree',
- primaryOwnerId: userId,
- slug: 'mixed-tree-workspace',
- });
- const workspaceModel = new ProjectModel(serverDB, userId, 'mixed-tree-workspace');
- const ownerTasks = new TaskModel(serverDB, userId, 'mixed-tree-workspace');
- const memberTasks = new TaskModel(serverDB, otherUserId, 'mixed-tree-workspace');
- const project = await createProject(workspaceModel, { name: 'Target' });
- const parent = await ownerTasks.create({ instruction: 'Parent' });
- await memberTasks.create({
- instruction: 'Member child',
- parentTaskId: parent.id,
- visibility: 'private',
- });
-
- await expect(workspaceModel.moveTaskTree(project.id, parent.id)).rejects.toThrow(
- 'Cannot move a task tree containing tasks created by another user',
- );
- });
-
it('enforces project boundaries in the shared dependency model path', async () => {
const firstProject = await createProject(model, { name: 'First' });
const secondProject = await createProject(model, { name: 'Second' });
diff --git a/packages/database/src/models/project.ts b/packages/database/src/models/project.ts
index 86828434211..737bbcca098 100644
--- a/packages/database/src/models/project.ts
+++ b/packages/database/src/models/project.ts
@@ -464,79 +464,6 @@ export class ProjectModel {
return rows.map(({ id }) => id);
}
- async moveTaskTree(projectId: string, taskId: string) {
- if (!(await this.findManageableById(projectId))) return null;
- const taskScope = buildWorkspaceWhere(
- { userId: this.userId, workspaceId: this.workspaceId },
- {
- isDeleted: tasks.isDeleted,
- userId: tasks.createdByUserId,
- visibility: tasks.visibility,
- workspaceId: tasks.workspaceId,
- },
- );
- const [root] = await this.db
- .select()
- .from(tasks)
- .where(and(eq(tasks.id, taskId), taskScope, eq(tasks.createdByUserId, this.userId)))
- .limit(1);
- if (!root) throw new Error('Task not found');
- if (root.parentTaskId) {
- const [parent] = await this.db
- .select({ projectId: tasks.projectId })
- .from(tasks)
- .where(and(eq(tasks.id, root.parentTaskId), taskScope))
- .limit(1);
- if (parent?.projectId !== projectId) {
- throw new Error('Cannot move a task away from its parent project');
- }
- }
-
- // Visibility must not hide private descendants here: moving the visible
- // parent while leaving an unseen child behind would split one tree across
- // projects. The creator check below still rejects any row not owned by the
- // caller before the update runs.
- const treeScope = this.workspaceId
- ? eq(tasks.workspaceId, this.workspaceId)
- : and(eq(tasks.createdByUserId, this.userId), isNull(tasks.workspaceId));
- const descendants = await this.db.execute<{ created_by_user_id: string }>(sql`
- WITH RECURSIVE task_tree AS (
- SELECT ${tasks.id}, ${tasks.createdByUserId}
- FROM ${tasks}
- WHERE ${tasks.id} = ${root.id} AND ${treeScope}
- UNION ALL
- SELECT ${tasks.id}, ${tasks.createdByUserId}
- FROM ${tasks}
- JOIN task_tree parent ON ${tasks.parentTaskId} = parent.id
- WHERE ${treeScope}
- )
- SELECT created_by_user_id FROM task_tree
- `);
- if (descendants.rows.some(({ created_by_user_id }) => created_by_user_id !== this.userId)) {
- throw new Error('Cannot move a task tree containing tasks created by another user');
- }
-
- const { rows } = await this.db.execute<{ id: string }>(sql`
- WITH RECURSIVE task_tree AS (
- SELECT ${tasks.id}
- FROM ${tasks}
- WHERE ${tasks.id} = ${root.id} AND ${taskScope}
- AND ${tasks.createdByUserId} = ${this.userId}
- UNION ALL
- SELECT ${tasks.id}
- FROM ${tasks}
- JOIN task_tree parent ON ${tasks.parentTaskId} = parent.id
- WHERE ${taskScope} AND ${tasks.createdByUserId} = ${this.userId}
- )
- UPDATE ${tasks}
- SET ${sql.identifier(tasks.projectId.name)} = ${projectId},
- ${sql.identifier(tasks.updatedAt.name)} = NOW()
- WHERE ${tasks.id} IN (SELECT id FROM task_tree)
- RETURNING ${tasks.id}
- `);
- return rows;
- }
-
async requestCompletion(id: string) {
const project = await this.findManageableById(id);
if (!project) return null;