GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(client-runtime): branch picker shows branches changed outside T3 … · pingdotgg/t3code@1d80d0e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/client-runtime/src/state
    • vcs.test.ts
    • vcs.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.test.ts
+93Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AuthSourceControlWriteScope,
55
WS_METHODS,
66
VcsProcessExitError,
7+
type VcsListRefsInput,
78
type VcsListRefsResult,
89
type VcsStatusResult,
910
} from "@t3tools/contracts";
@@ -154,6 +155,98 @@ describe("cached VCS refs", () => {
154155
registry.dispose();
155156
});
156157

158+
it.effect("bypasses the server ref snapshot when a mounted list is invalidated", () =>
159+
Effect.scoped(
160+
Effect.gen(function* () {
161+
const requests = yield* Queue.unbounded<VcsListRefsInput>();
162+
const client = {
163+
[WS_METHODS.vcsListRefs]: (input: VcsListRefsInput) =>
164+
Effect.sync(() => {
165+
Queue.offerUnsafe(requests, input);
166+
return LIVE_REFS;
167+
}),
168+
} as unknown as WsRpcProtocolClient;
169+
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
170+
target: TARGET,
171+
state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
172+
session: yield* SubscriptionRef.make(Option.some(session(client))),
173+
prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
174+
connect: Effect.void,
175+
disconnect: Effect.void,
176+
retryNow: Effect.void,
177+
} satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
178+
const followStream: EnvironmentRegistry.EnvironmentRegistry["Service"]["followStream"] = (
179+
_environmentId,
180+
stream,
181+
) => Stream.provideService(stream, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
182+
const environmentRegistry = EnvironmentRegistry.EnvironmentRegistry.of({
183+
followStream,
184+
} as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
185+
const runtime = Atom.runtime(
186+
Layer.merge(
187+
Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
188+
Layer.succeed(Persistence.EnvironmentCacheStore, cacheWithRefs(Option.none())),
189+
),
190+
);
191+
const atoms = createVcsEnvironmentAtoms(runtime);
192+
const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
193+
Effect.sync(() => registry.dispose()),
194+
);
195+
yield* Effect.acquireRelease(
196+
Effect.sync(() =>
197+
registry.mount(
198+
atoms.listRefs({
199+
environmentId: TARGET.environmentId,
200+
input: { cwd: "/repo", limit: 100 },
201+
}),
202+
),
203+
),
204+
(unmount) => Effect.sync(unmount),
205+
);
206+
207+
expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100 });
208+
209+
invalidateVcsRefs(registry, TARGET);
210+
211+
expect(yield* Queue.take(requests)).toEqual({ cwd: "/repo", limit: 100, refresh: true });
212+
213+
yield* Effect.acquireRelease(
214+
Effect.sync(() =>
215+
registry.mount(
216+
atoms.listRefs({
217+
environmentId: TARGET.environmentId,
218+
input: { cwd: "/other-repo", limit: 100 },
219+
}),
220+
),
221+
),
222+
(unmount) => Effect.sync(unmount),
223+
);
224+
expect(yield* Queue.take(requests)).toEqual({
225+
cwd: "/other-repo",
226+
limit: 100,
227+
refresh: true,
228+
});
229+
230+
yield* Effect.acquireRelease(
231+
Effect.sync(() =>
232+
registry.mount(
233+
atoms.listRefs({
234+
environmentId: TARGET.environmentId,
235+
input: { cwd: "/other-repo", query: "release", limit: 100 },
236+
}),
237+
),
238+
),
239+
(unmount) => Effect.sync(unmount),
240+
);
241+
expect(yield* Queue.take(requests)).toEqual({
242+
cwd: "/other-repo",
243+
query: "release",
244+
limit: 100,
245+
});
246+
}),
247+
),
248+
);
249+
157250
it.effect("does not repersist a refresh superseded by ref invalidation", () =>
158251
Effect.scoped(
159252
Effect.gen(function* () {
Collapse file

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

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.ts
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import {
3333
withVcsRefsPersistenceLock,
3434
} from "./vcsRefInvalidation.ts";
3535

36+
// Share freshness across search and pagination keys, but keep it local to this registry.
37+
const serverRefsRevisionAtom = Atom.family((_key: string) => Atom.make(0).pipe(Atom.keepAlive));
38+
3639
const OFFLINE_BRANCH_LIST_LIMIT = 100;
3740
const VCS_REFS_IDLE_TTL_MS = 30_000;
3841
const VCS_STATUS_IDLE_TTL_MS = 10_000;
@@ -143,9 +146,17 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
143146
)
144147
: Option.none<VcsListRefsResult>();
145148
const refresh = Effect.fn("CachedVcsRefsState.refresh")(function* () {
146-
const refs = yield* request(WS_METHODS.vcsListRefs, input).pipe(
147-
Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
149+
const revisionAtom = serverRefsRevisionAtom(
150+
`${environmentId.length}:${environmentId}${input.cwd}`,
148151
);
152+
const bypassServerSnapshot =
153+
expectedRevision !== undefined &&
154+
registry !== undefined &&
155+
expectedRevision > registry.get(revisionAtom);
156+
const refs = yield* request(
157+
WS_METHODS.vcsListRefs,
158+
bypassServerSnapshot ? { ...input, refresh: true } : input,
159+
).pipe(Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor));
149160
const persist = cache.saveVcsRefs(environmentId, input.cwd, refs).pipe(
150161
Effect.catch((error) =>
151162
Effect.logWarning("Could not persist cached Git refs.").pipe(
@@ -168,6 +179,7 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange
168179
expectedRevision,
169180
persist: useCache,
170181
});
182+
if (committed && bypassServerSnapshot) registry.set(revisionAtom, expectedRevision);
171183
return committed ? Option.some(refs) : Option.none<VcsListRefsResult>();
172184
});
173185

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.