Skip to content
TypeScript

fix(cli): t3 project remove finds a deleted project by a relative or trailing-slash path (#30562)

MarcoDotIO31096388aa48
diff --git a/apps/server/src/cli/project.test.ts b/apps/server/src/cli/project.test.ts
index 9d721531f4a..035b7d7e6f7 100644
--- a/apps/server/src/cli/project.test.ts
+++ b/apps/server/src/cli/project.test.ts
@@ -389,23 +389,26 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))(
it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))(
"project lookup with unavailable workspaces",
(it) => {
- it.effect.each(["id", "stored path"] as const)(
- "removes an empty project by %s after its directory is gone",
- (identifier) =>
- Effect.gen(function* () {
- const fs = yield* FileSystem.FileSystem;
- const { baseDir, workspaceRoot, project } = yield* makeProjectLookupFixture();
- yield* fs.rename(workspaceRoot, `${workspaceRoot}-removed`);
- yield* runCli([
- "project",
- "remove",
- identifier === "id" ? project.id : workspaceRoot,
- "--base-dir",
- baseDir,
- ]);
- assert.deepEqual((yield* readProjects(baseDir)).projects, []);
- assert.isFalse(yield* fs.exists(workspaceRoot));
- }),
+ it.effect.each([
+ "id",
+ "stored path",
+ "relative path",
+ "path with a trailing separator",
+ ] as const)("removes an empty project by %s after its directory is gone", (identifier) =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const { baseDir, workspaceRoot, project } = yield* makeProjectLookupFixture();
+ yield* fs.rename(workspaceRoot, `${workspaceRoot}-removed`);
+ const target = {
+ id: project.id,
+ "stored path": workspaceRoot,
+ "relative path": NodePath.relative(process.cwd(), workspaceRoot),
+ "path with a trailing separator": `${workspaceRoot}${NodePath.sep}`,
+ }[identifier];
+ yield* runCli(["project", "remove", target, "--base-dir", baseDir]);
+ assert.deepEqual((yield* readProjects(baseDir)).projects, []);
+ assert.isFalse(yield* fs.exists(workspaceRoot));
+ }),
);
it.effect("does not resolve another environment's project ID in an empty database", () =>
diff --git a/apps/server/src/cli/project.ts b/apps/server/src/cli/project.ts
index cf34c45d5ec..f604f8eb436 100644
--- a/apps/server/src/cli/project.ts
+++ b/apps/server/src/cli/project.ts
@@ -292,12 +292,15 @@ const findActiveProjectTarget = Effect.fn("findActiveProjectTarget")(function* (
const normalizedWorkspaceRootResult = yield* Effect.result(
normalizeWorkspaceRootForProjectCommand(trimmedIdentifier),
);
+ // A stored workspace path still identifies its project after the directory is gone, so a
+ // relative or trailing-slash path resolves the same way it would while the directory exists.
const normalizedWorkspaceRoot =
- normalizedWorkspaceRootResult._tag === "Success" ? normalizedWorkspaceRootResult.success : null;
+ normalizedWorkspaceRootResult._tag === "Success"
+ ? normalizedWorkspaceRootResult.success
+ : normalizedWorkspaceRootResult.failure.normalizedWorkspaceRoot;
- // A stored workspace path still identifies its project after the directory is gone.
const exactWorkspaceMatch = activeProjects.find(
- (project) => project.workspaceRoot === (normalizedWorkspaceRoot ?? trimmedIdentifier),
+ (project) => project.workspaceRoot === normalizedWorkspaceRoot,
);
const resolved = exactWorkspaceMatch;
@@ -306,7 +309,7 @@ const findActiveProjectTarget = Effect.fn("findActiveProjectTarget")(function* (
operation: "resolveProjectTarget",
identifier: trimmedIdentifier,
activeProjectCount: activeProjects.length,
- ...(normalizedWorkspaceRoot === null ? {} : { normalizedWorkspaceRoot }),
+ normalizedWorkspaceRoot,
...(normalizedWorkspaceRootResult._tag === "Failure"
? { cause: normalizedWorkspaceRootResult.failure }
: {}),