GeezerVison is showing github.com — fix(client-runtime): branch picker shows branches changed outside T3 … · pingdotgg/t3code@1d80d0e
File treeExpand file treeCollapse file tree Open diff view settings packages/client-runtime/src/state
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.test.ts +93Lines changed: 93 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | AuthSourceControlWriteScope, | 5 | 5 | WS_METHODS, | 6 | 6 | VcsProcessExitError, | | 7 | + type VcsListRefsInput, | 7 | 8 | type VcsListRefsResult, | 8 | 9 | type VcsStatusResult, | 9 | 10 | } from "@t3tools/contracts"; | @@ -154,6 +155,98 @@ describe("cached VCS refs", () => { | 154 | 155 | registry.dispose(); | 155 | 156 | }); | 156 | 157 |
| | 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 | + | 157 | 250 | it.effect("does not repersist a refresh superseded by ref invalidation", () => | 158 | 251 | Effect.scoped( | 159 | 252 | Effect.gen(function* () { | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/vcs.ts +14-2Lines changed: 14 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,6 +33,9 @@ import { | 33 | 33 | withVcsRefsPersistenceLock, | 34 | 34 | } from "./vcsRefInvalidation.ts"; | 35 | 35 |
| | 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 | + | 36 | 39 | const OFFLINE_BRANCH_LIST_LIMIT = 100; | 37 | 40 | const VCS_REFS_IDLE_TTL_MS = 30_000; | 38 | 41 | const VCS_STATUS_IDLE_TTL_MS = 10_000; | @@ -143,9 +146,17 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange | 143 | 146 | ) | 144 | 147 | : Option.none<VcsListRefsResult>(); | 145 | 148 | 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}`, | 148 | 151 | ); | | 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)); | 149 | 160 | const persist = cache.saveVcsRefs(environmentId, input.cwd, refs).pipe( | 150 | 161 | Effect.catch((error) => | 151 | 162 | Effect.logWarning("Could not persist cached Git refs.").pipe( | @@ -168,6 +179,7 @@ export const makeCachedVcsRefsChanges = Effect.fn("CachedVcsRefsState.makeChange | 168 | 179 | expectedRevision, | 169 | 180 | persist: useCache, | 170 | 181 | }); | | 182 | + if (committed && bypassServerSnapshot) registry.set(revisionAtom, expectedRevision); | 171 | 183 | return committed ? Option.some(refs) : Option.none<VcsListRefsResult>(); | 172 | 184 | }); | 173 | 185 |
| |
|