Skip to content

Commit 4494faa

Browse files
saphidclaude
andauthored
fix(client-runtime): checking out a pull request refreshes cached branch lists (#29161)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 50106ef commit 4494faa

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎packages/client-runtime/src/state/git.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { Atom } from "effect/reactivity";
33

44
import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";
55
import type { EnvironmentRegistry } from "../connection/registry.ts";
6+
import * as Persistence from "../platform/persistence.ts";
67
import { vcsCommandConcurrency, vcsCommandScheduler } from "./vcsCommandScheduler.ts";
8+
import { invalidateCachedVcsRefs } from "./vcsRefInvalidation.ts";
79

810
export function createGitEnvironmentAtoms<R, E>(
9-
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
11+
runtime: Atom.AtomRuntime<EnvironmentRegistry | Persistence.EnvironmentCacheStore | R, E>,
1012
) {
1113
return {
1214
pullRequestResolution: createEnvironmentRpcQueryAtomFamily(runtime, {
@@ -18,6 +20,8 @@ export function createGitEnvironmentAtoms<R, E>(
1820
tag: WS_METHODS.gitPreparePullRequestThread,
1921
scheduler: vcsCommandScheduler,
2022
concurrency: vcsCommandConcurrency,
23+
onSettled: ({ environmentId, input }, registry) =>
24+
invalidateCachedVcsRefs(registry, { environmentId, cwd: input.cwd }),
2125
}),
2226
};
2327
}

‎packages/client-runtime/src/state/vcs.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import * as Persistence from "../platform/persistence.ts";
3434
import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";
3535
import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
3636
import type { RpcSession } from "../rpc/session.ts";
37+
import { createGitEnvironmentAtoms } from "./git.ts";
3738

3839
import {
3940
commitVcsRefsRefresh,
@@ -316,6 +317,8 @@ describe("cached VCS refs", () => {
316317
const client = {
317318
[WS_METHODS.vcsPull]: () => Effect.fail(expectedError),
318319
[WS_METHODS.vcsRefreshStatus]: () => Effect.void,
320+
[WS_METHODS.gitPreparePullRequestThread]: () =>
321+
Effect.succeed({ branch: "feature/pr", worktreePath: null }),
319322
} as unknown as WsRpcProtocolClient;
320323
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
321324
target: TARGET,
@@ -371,6 +374,17 @@ describe("cached VCS refs", () => {
371374
expect(AsyncResult.isSuccess(refreshResult)).toBe(true);
372375
expect(yield* Ref.get(clears)).toBe(2);
373376
expect(registry.get(vcsRefsCacheStateAtom(TARGET)).revision).toBe(2);
377+
378+
const prepareResult = yield* Effect.promise(() =>
379+
createGitEnvironmentAtoms(runtime).preparePullRequestThread.run(registry, {
380+
environmentId: TARGET.environmentId,
381+
input: { cwd: "/repo", reference: "42", mode: "local" },
382+
}),
383+
);
384+
385+
expect(AsyncResult.isSuccess(prepareResult)).toBe(true);
386+
expect(yield* Ref.get(clears)).toBe(3);
387+
expect(registry.get(vcsRefsCacheStateAtom(TARGET)).revision).toBe(3);
374388
}),
375389
),
376390
);

0 commit comments

Comments
 (0)