Skip to content

Commit 9a3936c

Browse files
committed
fix(server): skip the automatic pull too when the fetch interval is zero
A pull contacts the remote as much as a fetch does, and without a fetch the "behind" count it would act on is stale. A refresh with the interval at 0 now leaves the automatic pull alone as well.
1 parent 9ebe840 commit 9a3936c

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,56 @@ describe("VcsStatusBroadcaster", () => {
206206
},
207207
);
208208

209+
it.effect("does not pull automatically when periodic refreshes are disabled", () => {
210+
let remoteStatus: VcsStatusRemoteResult = { ...baseRemoteStatus, behindCount: 2 };
211+
let pullCalls = 0;
212+
const localStatus: VcsStatusLocalResult = {
213+
...baseLocalStatus,
214+
isDefaultRef: true,
215+
refName: "main",
216+
};
217+
const testLayer = VcsStatusBroadcaster.layer.pipe(
218+
Layer.provideMerge(NodeServices.layer),
219+
Layer.provide(makeBackgroundPolicyLayer(() => true)),
220+
Layer.provide(
221+
Layer.succeed(VcsStatusBroadcaster.VcsAutoPullPolicy, {
222+
isEnabled: () => Effect.succeed(true),
223+
}),
224+
),
225+
Layer.provide(
226+
Layer.mock(GitWorkflowService.GitWorkflowService)({
227+
localStatus: () => Effect.succeed(localStatus),
228+
remoteStatus: () => Effect.succeed(remoteStatus),
229+
invalidateLocalStatus: () => Effect.void,
230+
invalidateRemoteStatus: () => Effect.void,
231+
invalidateStatus: () => Effect.void,
232+
pullCurrentBranch: () =>
233+
Effect.sync(() => {
234+
pullCalls += 1;
235+
remoteStatus = { ...remoteStatus, behindCount: 0 };
236+
return { status: "pulled" as const, refName: "main", upstreamRef: "origin/main" };
237+
}),
238+
}),
239+
),
240+
);
241+
242+
return Effect.gen(function* () {
243+
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
244+
245+
// The cached upstream still says "behind", but nothing fetched, so a
246+
// focus refresh with the interval at 0 must not reach for the remote.
247+
const quiet = yield* broadcaster.refreshStatus("/repo", {
248+
automaticRemoteRefreshInterval: Effect.succeed(Duration.zero),
249+
});
250+
assert.equal(pullCalls, 0);
251+
assert.equal(quiet.behindCount, 2);
252+
253+
const pulled = yield* broadcaster.refreshStatus("/repo");
254+
assert.equal(pullCalls, 1);
255+
assert.equal(pulled.behindCount, 0);
256+
}).pipe(Effect.provide(testLayer));
257+
});
258+
209259
it.effect("reuses the cached VCS status across repeated reads", () => {
210260
const state = {
211261
currentLocalStatus: baseLocalStatus,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,9 @@ export const make = Effect.gen(function* () {
494494
[workflow.localStatus({ cwd }), workflow.remoteStatus({ cwd }, { refreshUpstream })],
495495
{ concurrency: "unbounded" },
496496
);
497-
const pulled = yield* maybeAutoPull(cwd, remote, [rawCwd]);
497+
// An automatic pull contacts the remote too, and without a fetch the
498+
// "behind" count it would act on is stale anyway.
499+
const pulled = refreshUpstream ? yield* maybeAutoPull(cwd, remote, [rawCwd]) : null;
498500
if (pulled !== null) return mergeGitStatusParts(pulled.local, pulled.remote);
499501
return yield* updateCachedStatus(cwd, local, remote, { publish: true });
500502
}),

0 commit comments

Comments
 (0)