Skip to content

Commit 252ba70

Browse files
committed
fix(server): worktree handoff refresh respects a zero fetch interval
1 parent 30492c1 commit 252ba70

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

‎apps/server/src/mcp/WorktreeMcpService.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@t3tools/contracts";
1313
import * as Cause from "effect/Cause";
1414
import * as Deferred from "effect/Deferred";
15+
import * as Duration from "effect/Duration";
1516
import * as Effect from "effect/Effect";
1617
import * as Exit from "effect/Exit";
1718
import * as Fiber from "effect/Fiber";
@@ -88,6 +89,7 @@ interface HarnessOptions {
8889
readonly currentBranch?: string | null;
8990
readonly notARepo?: boolean;
9091
readonly newWorktreesStartFromOrigin?: boolean;
92+
readonly automaticGitFetchInterval?: Duration.Duration;
9193
readonly setupScript?: "started" | "no-script" | "fails" | "dies";
9294
readonly dispatchFails?: boolean;
9395
readonly dispatchDies?: boolean;
@@ -256,7 +258,9 @@ const makeHarness = (options: HarnessOptions = {}) => {
256258
workingTree: { files: [], insertions: 0, deletions: 0 },
257259
}),
258260
);
259-
const refreshStatus = vi.fn((_: string) => Effect.die("refreshStatus stub"));
261+
const refreshStatus = vi.fn<
262+
VcsStatusBroadcaster.VcsStatusBroadcaster["Service"]["refreshStatus"]
263+
>(() => Effect.die("refreshStatus stub"));
260264
const runForThread = vi.fn((input: { readonly worktreePath: string }) => {
261265
switch (options.setupScript ?? "started") {
262266
case "no-script":
@@ -313,6 +317,9 @@ const makeHarness = (options: HarnessOptions = {}) => {
313317
} satisfies Partial<ProjectService.ProjectService["Service"]>),
314318
ServerSettings.layerTest({
315319
newWorktreesStartFromOrigin: options.newWorktreesStartFromOrigin ?? false,
320+
...(options.automaticGitFetchInterval === undefined
321+
? {}
322+
: { automaticGitFetchInterval: options.automaticGitFetchInterval }),
316323
}),
317324
Layer.mock(GitWorkflowService.GitWorkflowService)({
318325
listRefs,
@@ -347,6 +354,7 @@ const makeHarness = (options: HarnessOptions = {}) => {
347354
deleteLocalBranch,
348355
localStatus,
349356
runForThread,
357+
refreshStatus,
350358
};
351359
};
352360

@@ -426,6 +434,27 @@ describe("t3_worktree_handoff", () => {
426434
});
427435
});
428436

437+
it.effect("refreshes the new worktree's status with the configured Git fetch interval", () =>
438+
Effect.gen(function* () {
439+
for (const [configured, expected] of [
440+
[Duration.zero, Duration.zero],
441+
[undefined, Duration.seconds(30)],
442+
] as const) {
443+
const harness = makeHarness(
444+
configured === undefined ? {} : { automaticGitFetchInterval: configured },
445+
);
446+
yield* runHandoff(harness, { branch: "feature/refresh" });
447+
448+
expect(harness.refreshStatus).toHaveBeenCalledTimes(1);
449+
const [cwd, refreshOptions] = harness.refreshStatus.mock.calls[0]!;
450+
expect(cwd).toBe("/worktrees/project/feature/refresh");
451+
const interval = refreshOptions?.automaticRemoteRefreshInterval;
452+
if (interval === undefined) return expect.fail("refreshStatus got no fetch interval");
453+
expect(Duration.toMillis(yield* interval)).toBe(Duration.toMillis(expected));
454+
}
455+
}),
456+
);
457+
429458
it.effect("skips the continuation when no continuationPrompt is given", () => {
430459
const harness = makeHarness();
431460
return Effect.gen(function* () {

‎apps/server/src/mcp/WorktreeMcpService.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
CommandId,
3+
DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL,
34
MessageId,
45
type ProjectId,
56
WorktreeMcpFailure,
@@ -9,6 +10,7 @@ import {
910
type WorktreeMcpSetupScriptStatus,
1011
type WorktreeMcpStatusResult,
1112
} from "@t3tools/contracts";
13+
import { resolveServerBackgroundActivitySettings } from "@t3tools/shared/backgroundActivitySettings";
1214
import * as Cause from "effect/Cause";
1315
import * as Context from "effect/Context";
1416
import * as Crypto from "effect/Crypto";
@@ -115,6 +117,15 @@ const make = Effect.gen(function* () {
115117
asOperationFailed("Unable to read server settings"),
116118
);
117119

120+
// The post-handoff status refresh honors the Git fetch interval, so a zero
121+
// interval keeps it from fetching, like the client's refresh RPC.
122+
const automaticGitFetchInterval = serverSettings.getSettings.pipe(
123+
Effect.map(
124+
(settings) => resolveServerBackgroundActivitySettings(settings).automaticGitFetchInterval,
125+
),
126+
Effect.orElseSucceed(() => DEFAULT_AUTOMATIC_GIT_FETCH_INTERVAL),
127+
);
128+
118129
const handoffIds = (scope: McpInvocationScope) =>
119130
crypto.randomUUIDv4.pipe(
120131
Effect.map((uuid) => {
@@ -379,7 +390,9 @@ const make = Effect.gen(function* () {
379390
const continuation = yield* recheckAndBind.pipe(Effect.andThen(queueContinuation));
380391

381392
yield* vcsStatusBroadcaster
382-
.refreshStatus(worktreePath)
393+
.refreshStatus(worktreePath, {
394+
automaticRemoteRefreshInterval: automaticGitFetchInterval,
395+
})
383396
.pipe(Effect.ignoreCause({ log: true }), Effect.forkDetach);
384397

385398
let setupScript: WorktreeMcpSetupScriptStatus = { status: "skipped" };

0 commit comments

Comments
 (0)