Skip to content

Commit 01a8db0

Browse files
authored
fix(server): refresh divergence after a merged branch ref changes (#31342)
1 parent 67eebac commit 01a8db0

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

‎apps/server/src/vcs/VcsStatusBroadcaster.test.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,14 @@ describe("VcsStatusBroadcaster", () => {
382382
);
383383

384384
it.effect("refreshes a loaded cwd without reusing a previous branch's PR", () => {
385-
const state = {
385+
const state: Parameters<typeof layerTestFor>[0] = {
386386
currentLocalStatus: baseLocalStatus,
387-
currentRemoteStatus: baseRemoteStatus,
387+
currentRemoteStatus: { ...baseRemoteStatus, aheadCount: 3, behindCount: 5 },
388388
localStatusCalls: 0,
389389
remoteStatusCalls: 0,
390390
localInvalidationCalls: 0,
391391
remoteInvalidationCalls: 0,
392+
remoteStatusRefreshUpstreamValues: [],
392393
};
393394

394395
return Effect.gen(function* () {
@@ -400,9 +401,14 @@ describe("VcsStatusBroadcaster", () => {
400401
yield* broadcaster.getStatus({ cwd: "/repo" });
401402
assert.equal(state.remoteStatusCalls, 1);
402403

403-
state.currentRemoteStatus = remoteStatusWithPr;
404+
state.backgroundWorkEnabled = false;
405+
state.currentRemoteStatus = { ...remoteStatusWithPr, aheadCount: 7 };
404406
const refreshed = yield* broadcaster.refreshPullRequestStatus("/repo");
405-
assert.deepStrictEqual(refreshed, remoteStatusWithPr);
407+
assert.deepStrictEqual(refreshed, state.currentRemoteStatus);
408+
const merged = yield* broadcaster.getStatus({ cwd: "/repo" });
409+
assert.equal(merged.aheadCount, 7);
410+
assert.equal(merged.behindCount, 0);
411+
assert.equal(state.remoteStatusRefreshUpstreamValues?.at(-1), false);
406412
assert.equal(state.remoteStatusCalls, 2);
407413
assert.equal(state.remoteInvalidationCalls, 2);
408414

@@ -944,7 +950,7 @@ describe("VcsStatusBroadcaster", () => {
944950
},
945951
);
946952

947-
it.effect("recovers a discarded branch lookup on the next permitted turn-end refresh", () => {
953+
it.effect("recovers a discarded branch lookup on the next turn-end refresh", () => {
948954
const state: Parameters<typeof layerTestFor>[0] = {
949955
currentLocalStatus: baseLocalStatus,
950956
currentRemoteStatus: { ...remoteStatusWithPr, aheadCount: 3, behindCount: 5 },
@@ -983,9 +989,6 @@ describe("VcsStatusBroadcaster", () => {
983989
pr: { ...remoteStatusWithPr.pr!, number: 2979, headRef: "feature/next-status" },
984990
};
985991
state.backgroundWorkEnabled = false;
986-
yield* broadcaster.refreshPullRequestStatus("/repo");
987-
assert.equal(state.remoteStatusCalls, 1);
988-
state.backgroundWorkEnabled = true;
989992
const recovered = yield* broadcaster.refreshPullRequestStatus("/repo");
990993
assert.deepStrictEqual(recovered, state.currentRemoteStatus);
991994
const cached = yield* broadcaster.getStatus({ cwd: "/repo" });

‎apps/server/src/vcs/VcsStatusBroadcaster.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,7 @@ export const make = Effect.gen(function* () {
540540
Effect.gen(function* () {
541541
const cached = yield* getCachedStatus(cwd);
542542
if (!cached?.local || cached.remote?.value === null) return null;
543-
const poller = (yield* SynchronizedRef.get(pollersRef)).get(cwd);
544-
const demandCwds = poller ? [...(yield* Ref.get(poller.demandCwds)).keys()] : [rawCwd];
545-
const shouldRefresh = (yield* Effect.forEach(
546-
demandCwds,
547-
(demandCwd) =>
548-
backgroundPolicy.shouldRunScopeWork({ type: "vcs-status", cwd: demandCwd }),
549-
{ concurrency: "unbounded" },
550-
)).some(Boolean);
551-
if (!shouldRefresh) return null;
543+
// Turn completion must update divergence even when background polling is paused.
552544
const remoteRead = yield* readRemoteStatus(cwd, {
553545
refreshUpstream: false,
554546
refreshMissingPullRequest: true,

0 commit comments

Comments
 (0)