Skip to content
TypeScript

fix(server): refresh divergence after a merged branch ref changes (#31342)

Yash Singh01a8db0aad27
diff --git a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts
index be3a286ffc3..45b130f9a2b 100644
--- a/apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+++ b/apps/server/src/vcs/VcsStatusBroadcaster.test.ts
@@ -382,13 +382,14 @@ describe("VcsStatusBroadcaster", () => {
);
it.effect("refreshes a loaded cwd without reusing a previous branch's PR", () => {
- const state = {
+ const state: Parameters<typeof layerTestFor>[0] = {
currentLocalStatus: baseLocalStatus,
- currentRemoteStatus: baseRemoteStatus,
+ currentRemoteStatus: { ...baseRemoteStatus, aheadCount: 3, behindCount: 5 },
localStatusCalls: 0,
remoteStatusCalls: 0,
localInvalidationCalls: 0,
remoteInvalidationCalls: 0,
+ remoteStatusRefreshUpstreamValues: [],
};
return Effect.gen(function* () {
@@ -400,9 +401,14 @@ describe("VcsStatusBroadcaster", () => {
yield* broadcaster.getStatus({ cwd: "/repo" });
assert.equal(state.remoteStatusCalls, 1);
- state.currentRemoteStatus = remoteStatusWithPr;
+ state.backgroundWorkEnabled = false;
+ state.currentRemoteStatus = { ...remoteStatusWithPr, aheadCount: 7 };
const refreshed = yield* broadcaster.refreshPullRequestStatus("/repo");
- assert.deepStrictEqual(refreshed, remoteStatusWithPr);
+ assert.deepStrictEqual(refreshed, state.currentRemoteStatus);
+ const merged = yield* broadcaster.getStatus({ cwd: "/repo" });
+ assert.equal(merged.aheadCount, 7);
+ assert.equal(merged.behindCount, 0);
+ assert.equal(state.remoteStatusRefreshUpstreamValues?.at(-1), false);
assert.equal(state.remoteStatusCalls, 2);
assert.equal(state.remoteInvalidationCalls, 2);
@@ -944,7 +950,7 @@ describe("VcsStatusBroadcaster", () => {
},
);
- it.effect("recovers a discarded branch lookup on the next permitted turn-end refresh", () => {
+ it.effect("recovers a discarded branch lookup on the next turn-end refresh", () => {
const state: Parameters<typeof layerTestFor>[0] = {
currentLocalStatus: baseLocalStatus,
currentRemoteStatus: { ...remoteStatusWithPr, aheadCount: 3, behindCount: 5 },
@@ -983,9 +989,6 @@ describe("VcsStatusBroadcaster", () => {
pr: { ...remoteStatusWithPr.pr!, number: 2979, headRef: "feature/next-status" },
};
state.backgroundWorkEnabled = false;
- yield* broadcaster.refreshPullRequestStatus("/repo");
- assert.equal(state.remoteStatusCalls, 1);
- state.backgroundWorkEnabled = true;
const recovered = yield* broadcaster.refreshPullRequestStatus("/repo");
assert.deepStrictEqual(recovered, state.currentRemoteStatus);
const cached = yield* broadcaster.getStatus({ cwd: "/repo" });
diff --git a/apps/server/src/vcs/VcsStatusBroadcaster.ts b/apps/server/src/vcs/VcsStatusBroadcaster.ts
index 327e0bcb1bb..7fee5379e4a 100644
--- a/apps/server/src/vcs/VcsStatusBroadcaster.ts
+++ b/apps/server/src/vcs/VcsStatusBroadcaster.ts
@@ -540,15 +540,7 @@ export const make = Effect.gen(function* () {
Effect.gen(function* () {
const cached = yield* getCachedStatus(cwd);
if (!cached?.local || cached.remote?.value === null) return null;
- const poller = (yield* SynchronizedRef.get(pollersRef)).get(cwd);
- const demandCwds = poller ? [...(yield* Ref.get(poller.demandCwds)).keys()] : [rawCwd];
- const shouldRefresh = (yield* Effect.forEach(
- demandCwds,
- (demandCwd) =>
- backgroundPolicy.shouldRunScopeWork({ type: "vcs-status", cwd: demandCwd }),
- { concurrency: "unbounded" },
- )).some(Boolean);
- if (!shouldRefresh) return null;
+ // Turn completion must update divergence even when background polling is paused.
const remoteRead = yield* readRemoteStatus(cwd, {
refreshUpstream: false,
refreshMissingPullRequest: true,