diff --git a/packages/server/src/server/workspace-git-service.primitive.test.ts b/packages/server/src/server/workspace-git-service.primitive.test.ts index 781437426..6060e74a9 100644 --- a/packages/server/src/server/workspace-git-service.primitive.test.ts +++ b/packages/server/src/server/workspace-git-service.primitive.test.ts @@ -631,6 +631,30 @@ describe("WorkspaceGitServiceImpl primitive refresh entrypoint", () => { github.dispose?.(); }); + test("subscription skips GitHub self-heal polling when the checkout has no GitHub remote", async () => { + const retainCurrentPullRequestStatusPoll = vi.fn(() => ({ unsubscribe: vi.fn() })); + const github = { + ...createGitHubServiceStub(), + retainCurrentPullRequestStatusPoll, + }; + const getCheckoutStatus = vi.fn(async (cwd: string) => + createCheckoutStatus(cwd, { + hasRemote: false, + remoteUrl: null, + }), + ); + const service = createService({ + getCheckoutStatus, + github, + }); + const subscription = await service.subscribe({ cwd: "/tmp/repo" }, vi.fn()); + + expect(retainCurrentPullRequestStatusPoll).not.toHaveBeenCalled(); + + subscription.unsubscribe(); + service.dispose(); + }); + test("multiple subscribers on the same target share one self-heal timer", async () => { let nowMs = 0; const getCheckoutStatus = vi.fn(async (cwd: string) => createCheckoutStatus(cwd)); diff --git a/packages/server/src/server/workspace-git-service.ts b/packages/server/src/server/workspace-git-service.ts index da03d383d..c42c41c5e 100644 --- a/packages/server/src/server/workspace-git-service.ts +++ b/packages/server/src/server/workspace-git-service.ts @@ -945,8 +945,14 @@ export class WorkspaceGitServiceImpl implements WorkspaceGitService { return; } - const headRef = target.latestSnapshot?.git.currentBranch ?? null; - if (!headRef || !this.deps.github.retainCurrentPullRequestStatusPoll) { + const snapshot = target.latestSnapshot; + if (!snapshot || !this.deps.github.retainCurrentPullRequestStatusPoll) { + this.stopGitHubPollForTarget(target); + return; + } + + const headRef = snapshot.git.currentBranch; + if (!headRef || !hasGitHubRemoteUrl(snapshot.git.remoteUrl)) { this.stopGitHubPollForTarget(target); return; }