Skip to content

Commit ca0188a

Browse files
committed
fix(server): the initial poll does not auto-pull when the fetch interval is zero
1 parent 252ba70 commit ca0188a

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,63 @@ describe("VcsStatusBroadcaster", () => {
262262
}).pipe(Effect.provide(testLayer));
263263
});
264264

265+
it.effect("does not pull automatically on the initial poll when the interval is zero", () => {
266+
let pullCalls = 0;
267+
// Settles on the first remote update or pull, whichever the poll reaches.
268+
const settled = Deferred.makeUnsafe<void>();
269+
const behindRemote: VcsStatusRemoteResult = { ...baseRemoteStatus, behindCount: 2 };
270+
const testLayer = VcsStatusBroadcaster.layer.pipe(
271+
Layer.provideMerge(NodeServices.layer),
272+
Layer.provide(makeBackgroundPolicyLayer(() => true)),
273+
Layer.provide(
274+
Layer.succeed(VcsStatusBroadcaster.VcsAutoPullPolicy, {
275+
isEnabled: () => Effect.succeed(true),
276+
}),
277+
),
278+
Layer.provide(
279+
Layer.mock(GitWorkflowService.GitWorkflowService)({
280+
localStatus: () =>
281+
Effect.succeed({ ...baseLocalStatus, isDefaultRef: true, refName: "main" }),
282+
remoteStatus: () => Effect.succeed(behindRemote),
283+
invalidateLocalStatus: () => Effect.void,
284+
invalidateRemoteStatus: () => Effect.void,
285+
invalidateStatus: () => Effect.void,
286+
pullCurrentBranch: () =>
287+
Effect.sync(() => {
288+
pullCalls += 1;
289+
return { status: "pulled" as const, refName: "main", upstreamRef: "origin/main" };
290+
}).pipe(Effect.tap(() => Deferred.succeed(settled, undefined))),
291+
}),
292+
),
293+
);
294+
295+
return Effect.gen(function* () {
296+
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
297+
const scope = yield* Scope.make();
298+
let remoteUpdated: VcsStatusStreamEvent | undefined;
299+
yield* Stream.runForEach(
300+
broadcaster.streamStatus(
301+
{ cwd: "/repo" },
302+
{ automaticRemoteRefreshInterval: Effect.succeed(Duration.zero) },
303+
),
304+
(event) => {
305+
if (event._tag !== "remoteUpdated") return Effect.void;
306+
remoteUpdated = event;
307+
return Deferred.succeed(settled, undefined);
308+
},
309+
).pipe(Effect.forkIn(scope));
310+
311+
yield* Deferred.await(settled);
312+
assert.equal(pullCalls, 0);
313+
assert.deepStrictEqual(remoteUpdated, {
314+
_tag: "remoteUpdated",
315+
remote: behindRemote,
316+
} satisfies VcsStatusStreamEvent);
317+
318+
yield* Scope.close(scope, Exit.void);
319+
}).pipe(Effect.provide(testLayer));
320+
});
321+
265322
it.effect("reuses the cached VCS status across repeated reads", () => {
266323
const state = {
267324
currentLocalStatus: baseLocalStatus,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,11 @@ export const make = Effect.gen(function* () {
467467
}
468468
const previousRemote = (yield* getCachedStatus(cwd))?.remote?.value;
469469
const remote = yield* workflow.remoteStatus({ cwd }, options);
470-
const pulled = yield* maybeAutoPull(cwd, remote, options?.policyCwds ?? [cwd]);
470+
// Like refreshStatus: no automatic pull when nothing was fetched.
471+
const pulled =
472+
options?.refreshUpstream === false
473+
? null
474+
: yield* maybeAutoPull(cwd, remote, options?.policyCwds ?? [cwd]);
471475
if (pulled !== null) return pulled.remote;
472476
// Local status holds the Changes totals, which compare against remote refs. A fetch can
473477
// move them with no local trigger (a push from a terminal, a PR merged on the host), so

0 commit comments

Comments
 (0)