diff --git a/apps/server/src/checkpointing/CheckpointStore.test.ts b/apps/server/src/checkpointing/CheckpointStore.test.ts index d089fcbec6..978327d7ee 100644 --- a/apps/server/src/checkpointing/CheckpointStore.test.ts +++ b/apps/server/src/checkpointing/CheckpointStore.test.ts @@ -114,6 +114,21 @@ it.layer(TestLayer)("CheckpointStore.layer", (it) => { }), ); + it.effect("recognizes an owned Git repository through a symbolic path alias", () => + Effect.gen(function* () { + const tmp = yield* makeTmpDir(); + const fileSystem = yield* FileSystem.FileSystem; + const repositoryPath = NodePath.join(tmp, "repository"); + const aliasPath = NodePath.join(tmp, "repository-alias"); + yield* fileSystem.makeDirectory(repositoryPath); + yield* initRepoWithCommit(repositoryPath); + yield* fileSystem.symlink(repositoryPath, aliasPath); + const checkpointStore = yield* CheckpointStore.CheckpointStore; + + expect(yield* checkpointStore.isGitRepository(aliasPath)).toBe(true); + }), + ); + it.effect("treats a standalone project nested under another repository as non-Git", () => Effect.gen(function* () { const tmp = yield* makeTmpDir(); diff --git a/apps/server/src/checkpointing/CheckpointStore.ts b/apps/server/src/checkpointing/CheckpointStore.ts index 668a46324e..e84ecfd34c 100644 --- a/apps/server/src/checkpointing/CheckpointStore.ts +++ b/apps/server/src/checkpointing/CheckpointStore.ts @@ -115,6 +115,8 @@ export const make = Effect.gen(function* () { "checkpoints", NodeCrypto.createHash("sha256").update(NodePath.resolve(cwd)).digest("hex"), ); + const canonicalizeWorkspacePath = (value: string) => + fileSystem.realPath(value).pipe(Effect.orElseSucceed(() => NodePath.resolve(value))); const runShadowGit = Effect.fn("CheckpointStore.runShadowGit")(function* (input: { readonly operation: string; @@ -337,22 +339,24 @@ export const make = Effect.gen(function* () { ) { const handle = yield* vcsRegistry.detect({ cwd }); const workspaceOwnsRepository = - handle !== null && NodePath.resolve(handle.repository.rootPath) === NodePath.resolve(cwd); + handle !== null && + (yield* canonicalizeWorkspacePath(handle.repository.rootPath)) === + (yield* canonicalizeWorkspacePath(cwd)); return workspaceOwnsRepository ? (handle.driver.checkpoints ?? shadowCheckpoints) : shadowCheckpoints; }); - const isGitRepository: CheckpointStore["Service"]["isGitRepository"] = (cwd) => - vcsRegistry - .detect({ cwd, requestedKind: "git" }) - .pipe( - Effect.map( - (repository) => - repository !== null && - NodePath.resolve(repository.repository.rootPath) === NodePath.resolve(cwd), - ), - ); + const isGitRepository: CheckpointStore["Service"]["isGitRepository"] = Effect.fn( + "CheckpointStore.isGitRepository", + )(function* (cwd) { + const repository = yield* vcsRegistry.detect({ cwd, requestedKind: "git" }); + return ( + repository !== null && + (yield* canonicalizeWorkspacePath(repository.repository.rootPath)) === + (yield* canonicalizeWorkspacePath(cwd)) + ); + }); const captureCheckpoint: CheckpointStore["Service"]["captureCheckpoint"] = Effect.fn( "captureCheckpoint",