Skip to content

Commit 67123a6

Browse files
fix(server): clear stale remote status after local branch changes
1 parent a1503cb commit 67123a6

2 files changed

Lines changed: 66 additions & 4 deletions

File tree

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,64 @@ describe("VcsStatusBroadcaster", () => {
186186
assert.isNull(refreshed.pr);
187187
assert.equal(state.localInvalidationCalls, 1);
188188
assert.equal(state.remoteStatusCalls, 1);
189-
assert.equal(state.remoteInvalidationCalls, 0);
189+
assert.equal(state.remoteInvalidationCalls, 1);
190190
assert.deepStrictEqual((yield* Fiber.join(events))[1], {
191-
_tag: "localUpdated",
191+
_tag: "snapshot",
192+
local: state.currentLocalStatus,
193+
remote: null,
194+
});
195+
assert.isNull((yield* broadcaster.getStatus({ cwd: "/repo" })).pr);
196+
const snapshot = yield* broadcaster
197+
.streamStatus({ cwd: "/repo", includeRemote: false })
198+
.pipe(Stream.take(1), Stream.runCollect);
199+
assert.deepStrictEqual(snapshot[0], {
200+
_tag: "snapshot",
192201
local: state.currentLocalStatus,
202+
remote: null,
193203
});
194204
}).pipe(Effect.provide(layerTestFor(state)));
195205
});
196206

207+
it.effect("clears the previous branch's remote status after an in-flight PR refresh", () => {
208+
const remoteReadStarted = Deferred.makeUnsafe<void>();
209+
const releaseRemoteRead = Deferred.makeUnsafe<void>();
210+
const state = {
211+
currentLocalStatus: baseLocalStatus,
212+
currentRemoteStatus: remoteStatusWithPr,
213+
localStatusCalls: 0,
214+
remoteStatusCalls: 0,
215+
localInvalidationCalls: 0,
216+
remoteInvalidationCalls: 0,
217+
beforeRemoteStatus: Effect.void,
218+
};
219+
220+
return Effect.gen(function* () {
221+
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
222+
yield* broadcaster.getStatus({ cwd: "/repo" });
223+
state.beforeRemoteStatus = Deferred.succeed(remoteReadStarted, undefined).pipe(
224+
Effect.andThen(Deferred.await(releaseRemoteRead)),
225+
);
226+
const remoteRefresh = yield* broadcaster
227+
.refreshPullRequestStatus("/repo")
228+
.pipe(Effect.forkScoped);
229+
yield* Deferred.await(remoteReadStarted);
230+
state.currentLocalStatus = { ...baseLocalStatus, refName: "main" };
231+
const localRefresh = yield* broadcaster
232+
.refreshStatus("/repo", { localOnly: true })
233+
.pipe(Effect.forkScoped);
234+
yield* Deferred.succeed(releaseRemoteRead, undefined);
235+
yield* Fiber.join(remoteRefresh);
236+
yield* Fiber.join(localRefresh);
237+
238+
const status = yield* broadcaster.getStatus({ cwd: "/repo" });
239+
assert.equal(status.refName, "main");
240+
assert.isNull(status.pr);
241+
assert.equal(status.aheadCount, 0);
242+
assert.equal(status.behindCount, 0);
243+
assert.equal(state.remoteStatusCalls, 2);
244+
}).pipe(Effect.provide(layerTestFor(state)));
245+
});
246+
197247
it.effect.skipIf(!symlinksSupported)(
198248
"automatically pulls an enabled clean default branch when status detects it is behind",
199249
() => {

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,20 @@ export const make = Effect.gen(function* () {
513513
)(function* (rawCwd, options) {
514514
const cwd = yield* withFileSystem(normalizeCwd(rawCwd));
515515
if (options?.localOnly) {
516-
const local = yield* refreshLocalStatusCore(cwd);
517-
return mergeGitStatusParts(local, null);
516+
return yield* withRemoteWriteLock(
517+
cwd,
518+
Effect.gen(function* () {
519+
yield* workflow.invalidateLocalStatus(cwd);
520+
const local = yield* workflow.localStatus({ cwd });
521+
const previous = yield* getCachedStatus(cwd);
522+
if (previous?.local?.value.refName !== local.refName) {
523+
yield* workflow.invalidateRemoteStatus(cwd);
524+
return yield* updateCachedStatus(cwd, local, null, { publish: true });
525+
}
526+
yield* updateCachedLocalStatus(cwd, local, { publish: true });
527+
return mergeGitStatusParts(local, null);
528+
}),
529+
);
518530
}
519531
// invalidateStatus (not the two partial invalidations) so an explicit
520532
// refresh also bypasses GitManager's slow PR-lookup cache.

0 commit comments

Comments
 (0)