TypeScript
fix(client-runtime): checking out a pull request refreshes cached branch lists (#29161)
Alex Southwell4494faa27053
diff --git a/packages/client-runtime/src/state/git.ts b/packages/client-runtime/src/state/git.tsindex ddce3ca4da8..18940290a99 100644--- a/packages/client-runtime/src/state/git.ts+++ b/packages/client-runtime/src/state/git.ts@@ -3,10 +3,12 @@ import { Atom } from "effect/reactivity";import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";import type { EnvironmentRegistry } from "../connection/registry.ts";+import * as Persistence from "../platform/persistence.ts";import { vcsCommandConcurrency, vcsCommandScheduler } from "./vcsCommandScheduler.ts";+import { invalidateCachedVcsRefs } from "./vcsRefInvalidation.ts";export function createGitEnvironmentAtoms<R, E>(- runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,+ runtime: Atom.AtomRuntime<EnvironmentRegistry | Persistence.EnvironmentCacheStore | R, E>,) {return {pullRequestResolution: createEnvironmentRpcQueryAtomFamily(runtime, {@@ -18,6 +20,8 @@ export function createGitEnvironmentAtoms<R, E>(tag: WS_METHODS.gitPreparePullRequestThread,scheduler: vcsCommandScheduler,concurrency: vcsCommandConcurrency,+ onSettled: ({ environmentId, input }, registry) =>+ invalidateCachedVcsRefs(registry, { environmentId, cwd: input.cwd }),}),};}diff --git a/packages/client-runtime/src/state/vcs.test.ts b/packages/client-runtime/src/state/vcs.test.tsindex e46ab146c0c..cdbda234222 100644--- a/packages/client-runtime/src/state/vcs.test.ts+++ b/packages/client-runtime/src/state/vcs.test.ts@@ -34,6 +34,7 @@ import * as Persistence from "../platform/persistence.ts";import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";import type { WsRpcProtocolClient } from "../rpc/protocol.ts";import type { RpcSession } from "../rpc/session.ts";+import { createGitEnvironmentAtoms } from "./git.ts";import {commitVcsRefsRefresh,@@ -316,6 +317,8 @@ describe("cached VCS refs", () => {const client = {[WS_METHODS.vcsPull]: () => Effect.fail(expectedError),[WS_METHODS.vcsRefreshStatus]: () => Effect.void,+ [WS_METHODS.gitPreparePullRequestThread]: () =>+ Effect.succeed({ branch: "feature/pr", worktreePath: null }),} as unknown as WsRpcProtocolClient;const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({target: TARGET,@@ -371,6 +374,17 @@ describe("cached VCS refs", () => {expect(AsyncResult.isSuccess(refreshResult)).toBe(true);expect(yield* Ref.get(clears)).toBe(2);expect(registry.get(vcsRefsCacheStateAtom(TARGET)).revision).toBe(2);++ const prepareResult = yield* Effect.promise(() =>+ createGitEnvironmentAtoms(runtime).preparePullRequestThread.run(registry, {+ environmentId: TARGET.environmentId,+ input: { cwd: "/repo", reference: "42", mode: "local" },+ }),+ );++ expect(AsyncResult.isSuccess(prepareResult)).toBe(true);+ expect(yield* Ref.get(clears)).toBe(3);+ expect(registry.get(vcsRefsCacheStateAtom(TARGET)).revision).toBe(3);}),),);