diff --git a/server/src/__tests__/heartbeat-workspace-session.test.ts b/server/src/__tests__/heartbeat-workspace-session.test.ts index bb6242fd2df..1a650cfa337 100644 --- a/server/src/__tests__/heartbeat-workspace-session.test.ts +++ b/server/src/__tests__/heartbeat-workspace-session.test.ts @@ -444,10 +444,40 @@ describe("assertGitSensitiveAdapterWorkspaceValid", () => { }, }), "missing_git_metadata", - "has no .git metadata", + "is not inside a git worktree", ); }); + it("accepts a workspace-linked issue when adapter cwd is a subdirectory inside a git worktree", async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "paperclip-git-parent-")); + try { + const cwd = path.join(root, "nested", "project"); + await fs.mkdir(cwd, { recursive: true }); + await execFile("git", ["init"], { cwd: root }); + + const input = buildWorkspaceValidationInput(); + + await expect( + assertGitSensitiveAdapterWorkspaceValid( + buildWorkspaceValidationInput({ + resolvedWorkspace: buildResolvedWorkspace({ cwd }), + executionWorkspace: { + ...input.executionWorkspace, + baseCwd: cwd, + cwd, + }, + persistedExecutionWorkspace: { + ...input.persistedExecutionWorkspace!, + cwd, + }, + }), + ), + ).resolves.toBeUndefined(); + } finally { + await fs.rm(root, { recursive: true, force: true }); + } + }); + it("does not apply the git-sensitive workspace guard to non-local execution targets", async () => { const input = buildWorkspaceValidationInput(); diff --git a/server/src/services/heartbeat/workspaces.ts b/server/src/services/heartbeat/workspaces.ts index 40a2b6e8733..e11de057b32 100644 --- a/server/src/services/heartbeat/workspaces.ts +++ b/server/src/services/heartbeat/workspaces.ts @@ -830,9 +830,8 @@ export function fingerprintFinalizeWorkspaceBranchValidation(input: { async function hasGitMetadata(cwd: string | null | undefined) { const normalized = readNonEmptyString(cwd); if (!normalized) return false; - return fs - .lstat(path.resolve(normalized, ".git")) - .then((entry) => entry.isDirectory() || entry.isFile()) + return execFile("git", ["-C", path.resolve(normalized), "rev-parse", "--is-inside-work-tree"]) + .then((result) => result.stdout.trim() === "true") .catch(() => false); } @@ -1278,7 +1277,7 @@ export async function assertGitSensitiveAdapterWorkspaceValid(input: { ) { fail( "missing_git_metadata", - `Issue ${issue.identifier ?? issue.id} expected a git workspace for ${input.adapterType}, but "${effectiveCwd}" has no .git metadata.`, + `Issue ${issue.identifier ?? issue.id} expected a git workspace for ${input.adapterType}, but "${effectiveCwd}" is not inside a git worktree.`, ); }