Skip to content

Commit bbaead8

Browse files
committed
test(server): preserve clones when project deletion is rejected
1 parent 6aca3fa commit bbaead8

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎apps/server/src/project/ProjectMutation.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as Deferred from "effect/Deferred";
44
import * as Effect from "effect/Effect";
55
import * as Fiber from "effect/Fiber";
66

7+
import { ProjectNotEmptyError } from "./ProjectService.ts";
78
import { mutateProjectWithClone } from "./ProjectMutation.ts";
89

910
const projectId = ProjectId.make("project-1");
@@ -24,6 +25,23 @@ const deletedProject: Project = {
2425
};
2526

2627
describe("mutateProjectWithClone", () => {
28+
it.effect("keeps the clone when deletion is rejected", () =>
29+
Effect.gen(function* () {
30+
const rejected = new ProjectNotEmptyError({ projectId });
31+
const result = yield* mutateProjectWithClone(
32+
{
33+
create: () => Effect.die("unused"),
34+
update: () => Effect.die("unused"),
35+
delete: () => Effect.fail(rejected),
36+
},
37+
{ discard: () => Effect.die("must not discard a project that still exists") },
38+
{ type: "project.delete", commandId: CommandId.make("rejected-delete"), projectId },
39+
).pipe(Effect.flip);
40+
41+
expect(result).toBe(rejected);
42+
}),
43+
);
44+
2745
it.effect("discards the clone record even when the caller disconnects mid-delete", () =>
2846
Effect.gen(function* () {
2947
const committed = yield* Deferred.make<void>();

‎apps/server/src/project/ProjectMutation.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ export const projectMutationOperation = Effect.fn("projectMutationOperation")(fu
5353
}
5454
});
5555

56-
/**
57-
* A deleted project's clone record goes with it. The record lives only in
58-
* memory and nothing else removes it, so a client that disconnects after the
59-
* delete commits must not skip the discard: the stale "Failed to clone" banner
60-
* would outlive the project, and Remove could no longer clear it.
61-
*/
56+
// A disconnect after deletion commits must not leave the in-memory clone record behind.
6257
export const mutateProjectWithClone = Effect.fn("mutateProjectWithClone")(function* (
6358
projects: ProjectMutations,
6459
clones: Pick<ProjectCloneTracker["Service"], "discard">,

0 commit comments

Comments
 (0)