Open History to see the last commit
1import { vi } from "vite-plus/test";
2import {
3 EnvironmentId,
4 AuthSourceControlWriteScope,
5 WS_METHODS,
6 VcsProcessExitError,
7 type VcsListRefsResult,
8} from "@t3tools/contracts";
9import { describe, expect, it } from "@effect/vitest";
10import * as Deferred from "effect/Deferred";
11import * as Effect from "effect/Effect";
12import * as Fiber from "effect/Fiber";
13import * as Layer from "effect/Layer";
14import * as Logger from "effect/Logger";
15import * as Option from "effect/Option";
16import * as Queue from "effect/Queue";
17import * as Ref from "effect/Ref";
18import * as Stream from "effect/Stream";
19import * as SubscriptionRef from "effect/SubscriptionRef";
20import * as TestClock from "effect/testing/TestClock";
21import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
22
23import {
24 AVAILABLE_CONNECTION_STATE,
25 PrimaryConnectionTarget,
26 type PreparedConnection,
27 type SupervisorConnectionState,
28} from "../connection/model.ts";
29import * as EnvironmentRegistry from "../connection/registry.ts";
30import * as EnvironmentSupervisor from "../connection/supervisor.ts";
31import * as Persistence from "../platform/persistence.ts";
32import { EnvironmentRpcUnavailableError } from "../rpc/client.ts";
33import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
34import type { RpcSession } from "../rpc/session.ts";
35
36import {
37 commitVcsRefsRefresh,
38 createVcsEnvironmentAtoms,
39 makeCachedVcsRefsChanges,
40} from "./vcs.ts";
41import {
42 invalidateCachedVcsRefs,
43 invalidateVcsRefs,
44 vcsRefsCacheStateAtom,
45} from "./vcsRefInvalidation.ts";
46
47const TARGET = new PrimaryConnectionTarget({
48 environmentId: EnvironmentId.make("environment-1"),
49 label: "Test environment",
50 httpBaseUrl: "https://environment.example.test",
51 wsBaseUrl: "wss://environment.example.test",
52});
53
54const CONNECTED_CONNECTION_STATE: SupervisorConnectionState = {
55 ...AVAILABLE_CONNECTION_STATE,
56 desired: true,
57 network: "online",
58 phase: "connected",
59 attempt: 1,
60 generation: 1,
61};
62
63const CACHED_REFS: VcsListRefsResult = {
64 refs: [
65 {
66 name: "main",
67 current: true,
68 isDefault: true,
69 worktreePath: "/repo",
70 },
71 ],
72 isRepo: true,
73 hasPrimaryRemote: true,
74 nextCursor: null,
75 totalCount: 1,
76};
77
78const LIVE_REFS: VcsListRefsResult = {
79 ...CACHED_REFS,
80 refs: [
81 {
82 name: "release",
83 current: true,
84 isDefault: true,
85 worktreePath: "/repo",
86 },
87 ],
88};
89
90function session(client: WsRpcProtocolClient): RpcSession {
91 return {
92 client,
93 initialConfig: Effect.never,
94 subscribeServerConfig: (input) => client.subscribeServerConfig(input),
95 ready: Effect.void,
96 probe: Effect.void,
97 inboundFrames: Effect.succeed(0),
98 closed: Effect.never,
99 };
100}
101
102function cacheWithRefs(
103 refs: Option.Option<VcsListRefsResult>,
104 overrides: Partial<Persistence.EnvironmentCacheStore["Service"]> = {},
105) {
106 return Persistence.EnvironmentCacheStore.of({
107 loadShell: () => Effect.succeedNone,
108 saveShell: () => Effect.void,
109 loadThread: () => Effect.succeedNone,
110 saveThread: () => Effect.void,
111 removeThread: () => Effect.void,
112 loadServerConfig: () => Effect.succeedNone,
113 saveServerConfig: () => Effect.void,
114 loadVcsRefs: () => Effect.succeed(refs),
115 saveVcsRefs: () => Effect.void,
116 removeVcsRefs: () => Effect.void,
117 clearVcsRefs: () => Effect.void,
118 clear: () => Effect.void,
119 ...overrides,
120 });
121}
122
123describe("cached VCS refs", () => {
124 it("invalidates all ref streams in the mutated environment", () => {
125 const registry = AtomRegistry.make();
126 const environment = {
127 environmentId: TARGET.environmentId,
128 };
129 const otherEnvironment = {
130 environmentId: EnvironmentId.make("environment-2"),
131 };
132
133 expect(registry.get(vcsRefsCacheStateAtom(environment))).toEqual({
134 revision: 0,
135 persistedCacheReadable: true,
136 });
137 expect(registry.get(vcsRefsCacheStateAtom(otherEnvironment))).toEqual({
138 revision: 0,
139 persistedCacheReadable: true,
140 });
141
142 invalidateVcsRefs(registry, environment);
143
144 expect(registry.get(vcsRefsCacheStateAtom(environment))).toEqual({
145 revision: 1,
146 persistedCacheReadable: true,
147 });
148 expect(registry.get(vcsRefsCacheStateAtom(otherEnvironment))).toEqual({
149 revision: 0,
150 persistedCacheReadable: true,
151 });
152 registry.dispose();
153 });
154
155 it.effect("does not repersist a refresh superseded by ref invalidation", () =>
156 Effect.scoped(
157 Effect.gen(function* () {
158 const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
159 Effect.sync(() => registry.dispose()),
160 );
161 const saved = yield* Ref.make<ReadonlyArray<VcsListRefsResult>>([]);
162 const clears = yield* Ref.make(0);
163 const revisionsObservedDuringClear = yield* Ref.make<ReadonlyArray<number>>([]);
164 const cache = cacheWithRefs(Option.none(), {
165 saveVcsRefs: (_environmentId, _cwd, refs) =>
166 Ref.update(saved, (current) => [...current, refs]),
167 clearVcsRefs: () =>
168 Effect.all([
169 Ref.update(clears, (count) => count + 1),
170 Ref.update(revisionsObservedDuringClear, (current) => [
171 ...current,
172 registry.get(vcsRefsCacheStateAtom(TARGET)).revision,
173 ]),
174 ]).pipe(Effect.asVoid),
175 });
176
177 yield* invalidateCachedVcsRefs(registry, {
178 environmentId: TARGET.environmentId,
179 cwd: "/repo-worktree",
180 }).pipe(Effect.provideService(Persistence.EnvironmentCacheStore, cache));
181
182 expect(
183 yield* commitVcsRefsRefresh(registry, cache, {
184 environmentId: TARGET.environmentId,
185 cwd: "/repo",
186 refs: CACHED_REFS,
187 expectedRevision: 0,
188 persist: true,
189 }),
190 ).toBe(false);
191
192 expect(yield* Ref.get(saved)).toEqual([]);
193 expect(yield* Ref.get(clears)).toBe(1);
194 expect(yield* Ref.get(revisionsObservedDuringClear)).toEqual([0]);
195 expect(registry.get(vcsRefsCacheStateAtom(TARGET))).toEqual({
196 revision: 1,
197 persistedCacheReadable: true,
198 });
199
200 expect(
201 yield* commitVcsRefsRefresh(registry, cache, {
202 environmentId: TARGET.environmentId,
203 cwd: "/repo",
204 refs: LIVE_REFS,
205 expectedRevision: 1,
206 persist: true,
207 }),
208 ).toBe(true);
209 expect(yield* Ref.get(saved)).toEqual([LIVE_REFS]);
210 }),
211 ),
212 );
213
214 it.effect("invalidates persisted refs when ref-affecting commands settle", () =>
215 Effect.scoped(
216 Effect.gen(function* () {
217 const expectedError = new EnvironmentRpcUnavailableError({
218 environmentId: TARGET.environmentId,
219 message: "pull failed after fetching refs",
220 });
221 const client = {
222 [WS_METHODS.vcsPull]: () => Effect.fail(expectedError),
223 [WS_METHODS.vcsRefreshStatus]: () => Effect.void,
224 } as unknown as WsRpcProtocolClient;
225 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
226 target: TARGET,
227 state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
228 session: yield* SubscriptionRef.make(Option.some(session(client))),
229 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
230 connect: Effect.void,
231 disconnect: Effect.void,
232 retryNow: Effect.void,
233 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
234 const run: EnvironmentRegistry.EnvironmentRegistry["Service"]["run"] = (
235 _environmentId,
236 effect,
237 ) => Effect.provideService(effect, EnvironmentSupervisor.EnvironmentSupervisor, supervisor);
238 const environmentRegistry = EnvironmentRegistry.EnvironmentRegistry.of({
239 run,
240 } as unknown as EnvironmentRegistry.EnvironmentRegistry["Service"]);
241 const clears = yield* Ref.make(0);
242 const runtime = Atom.runtime(
243 Layer.merge(
244 Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry),
245 Layer.succeed(
246 Persistence.EnvironmentCacheStore,
247 cacheWithRefs(Option.none(), {
248 clearVcsRefs: () => Ref.update(clears, (count) => count + 1),
249 }),
250 ),
251 ),
252 );
253 const atoms = createVcsEnvironmentAtoms(runtime);
254 const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
255 Effect.sync(() => registry.dispose()),
256 );
257
258 const result = yield* Effect.promise(() =>
259 atoms.pull.run(registry, {
260 environmentId: TARGET.environmentId,
261 input: { cwd: "/repo" },
262 }),
263 );
264
265 expect(AsyncResult.isFailure(result)).toBe(true);
266 expect(yield* Ref.get(clears)).toBe(1);
267 expect(registry.get(vcsRefsCacheStateAtom(TARGET)).revision).toBe(1);
268
269 const refreshResult = yield* Effect.promise(() =>
270 atoms.refreshStatus.run(registry, {
271 environmentId: TARGET.environmentId,
272 input: { cwd: "/repo" },
273 }),
274 );
275
276 expect(AsyncResult.isSuccess(refreshResult)).toBe(true);
277 expect(yield* Ref.get(clears)).toBe(2);
278 expect(registry.get(vcsRefsCacheStateAtom(TARGET)).revision).toBe(2);
279 }),
280 ),
281 );
282
283 it.effect("suppresses persisted snapshots after an environment-wide clear fails", () =>
284 Effect.scoped(
285 Effect.gen(function* () {
286 const registry = yield* Effect.acquireRelease(Effect.sync(AtomRegistry.make), (registry) =>
287 Effect.sync(() => registry.dispose()),
288 );
289 const persisted = yield* Ref.make<Option.Option<VcsListRefsResult>>(
290 Option.some(CACHED_REFS),
291 );
292 const loads = yield* Ref.make(0);
293 const clearAttempts = yield* Ref.make(0);
294 const cache = cacheWithRefs(Option.none(), {
295 loadVcsRefs: () =>
296 Ref.update(loads, (count) => count + 1).pipe(Effect.andThen(Ref.get(persisted))),
297 saveVcsRefs: (_environmentId, _cwd, refs) => Ref.set(persisted, Option.some(refs)),
298 clearVcsRefs: () =>
299 Ref.updateAndGet(clearAttempts, (count) => count + 1).pipe(
300 Effect.flatMap((attempt) =>
301 attempt === 1
302 ? Effect.fail(
303 new Persistence.ConnectionPersistenceError({
304 operation: "clear-vcs-refs",
305 message: "storage unavailable",
306 }),
307 )
308 : Ref.set(persisted, Option.none()),
309 ),
310 ),
311 });
312
313 yield* invalidateCachedVcsRefs(registry, {
314 environmentId: TARGET.environmentId,
315 cwd: "/repo",
316 }).pipe(Effect.provideService(Persistence.EnvironmentCacheStore, cache));
317
318 const state = registry.get(vcsRefsCacheStateAtom(TARGET));
319 expect(state).toEqual({
320 revision: 1,
321 persistedCacheReadable: false,
322 });
323
324 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
325 target: TARGET,
326 state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
327 session: yield* SubscriptionRef.make(Option.none<RpcSession>()),
328 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
329 connect: Effect.void,
330 disconnect: Effect.void,
331 retryNow: Effect.void,
332 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
333 const refs = yield* Stream.unwrap(
334 makeCachedVcsRefsChanges(
335 { cwd: "/repo", limit: 100 },
336 state.revision,
337 registry,
338 state.persistedCacheReadable,
339 ).pipe(
340 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
341 Effect.provideService(Persistence.EnvironmentCacheStore, cache),
342 ),
343 ).pipe(Stream.runHead, Effect.forkChild({ startImmediately: true }));
344
345 yield* Effect.yieldNow;
346 expect(yield* Ref.get(loads)).toBe(0);
347 yield* Fiber.interrupt(refs);
348 expect(registry.get(vcsRefsCacheStateAtom(TARGET))).toEqual(state);
349
350 expect(
351 yield* commitVcsRefsRefresh(registry, cache, {
352 environmentId: TARGET.environmentId,
353 cwd: "/repo",
354 refs: LIVE_REFS,
355 expectedRevision: state.revision,
356 persist: true,
357 }),
358 ).toBe(true);
359 const recoveredState = registry.get(vcsRefsCacheStateAtom(TARGET));
360 expect(recoveredState).toEqual({
361 revision: 1,
362 persistedCacheReadable: true,
363 });
364 expect(yield* Ref.get(clearAttempts)).toBe(2);
365
366 const recoveredRefs = yield* Stream.unwrap(
367 makeCachedVcsRefsChanges(
368 { cwd: "/repo", limit: 100 },
369 recoveredState.revision,
370 registry,
371 recoveredState.persistedCacheReadable,
372 ).pipe(
373 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
374 Effect.provideService(Persistence.EnvironmentCacheStore, cache),
375 ),
376 ).pipe(Stream.runHead);
377
378 expect(Option.getOrThrow(recoveredRefs)).toEqual(LIVE_REFS);
379 expect(yield* Ref.get(loads)).toBe(1);
380 }),
381 ),
382 );
383
384 it.effect("loads an unfiltered branch list without a connection", () =>
385 Effect.scoped(
386 Effect.gen(function* () {
387 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
388 target: TARGET,
389 state: yield* SubscriptionRef.make(AVAILABLE_CONNECTION_STATE),
390 session: yield* SubscriptionRef.make(Option.none<RpcSession>()),
391 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
392 connect: Effect.void,
393 disconnect: Effect.void,
394 retryNow: Effect.void,
395 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
396 const refs = yield* Stream.unwrap(
397 makeCachedVcsRefsChanges({ cwd: "/repo", limit: 100 }).pipe(
398 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
399 Effect.provideService(
400 Persistence.EnvironmentCacheStore,
401 cacheWithRefs(Option.some(CACHED_REFS)),
402 ),
403 ),
404 ).pipe(Stream.runHead);
405
406 expect(Option.getOrThrow(refs)).toEqual(CACHED_REFS);
407 }),
408 ),
409 );
410
411 it.effect("waits silently for a session while the connection phase is still connected", () =>
412 Effect.scoped(
413 Effect.gen(function* () {
414 const logs: unknown[] = [];
415 const logger = Logger.make(({ message }) => logs.push(message));
416 const liveSession = yield* SubscriptionRef.make(Option.none<RpcSession>());
417 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
418 target: TARGET,
419 state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
420 session: liveSession,
421 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
422 connect: Effect.void,
423 disconnect: Effect.void,
424 retryNow: Effect.void,
425 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
426 const refs = yield* Stream.unwrap(
427 makeCachedVcsRefsChanges({ cwd: "/repo", limit: 100 }).pipe(
428 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
429 Effect.provideService(
430 Persistence.EnvironmentCacheStore,
431 cacheWithRefs(Option.some(CACHED_REFS)),
432 ),
433 ),
434 ).pipe(
435 Stream.take(2),
436 Stream.runCollect,
437 Effect.provide(Logger.layer([logger], { mergeWithExisting: false })),
438 Effect.forkChild({ startImmediately: true }),
439 );
440
441 yield* TestClock.adjust("1 minute");
442 expect(logs).toEqual([]);
443
444 const client = {
445 [WS_METHODS.vcsListRefs]: () => Effect.succeed(LIVE_REFS),
446 } as unknown as WsRpcProtocolClient;
447 yield* SubscriptionRef.set(liveSession, Option.some(session(client)));
448 expect(yield* Fiber.join(refs)).toEqual([CACHED_REFS, LIVE_REFS]);
449 expect(logs).toEqual([]);
450 }),
451 ),
452 );
453
454 it.effect("cancels an in-flight refresh and restarts when the RPC session changes", () =>
455 Effect.scoped(
456 Effect.gen(function* () {
457 const started = yield* Deferred.make<void>();
458 const interrupted = yield* Deferred.make<void>();
459 const calls = yield* Ref.make(0);
460 const interruptions = yield* Ref.make(0);
461 const client = {
462 [WS_METHODS.vcsListRefs]: () =>
463 Ref.updateAndGet(calls, (count) => count + 1).pipe(
464 Effect.flatMap((count) =>
465 count === 1
466 ? Deferred.succeed(started, undefined).pipe(
467 Effect.andThen(Effect.never),
468 Effect.onInterrupt(() =>
469 Ref.update(interruptions, (interruptions) => interruptions + 1).pipe(
470 Effect.andThen(Deferred.succeed(interrupted, undefined)),
471 ),
472 ),
473 )
474 : Effect.succeed(LIVE_REFS),
475 ),
476 ),
477 } as unknown as WsRpcProtocolClient;
478 const liveSession = yield* SubscriptionRef.make(Option.some(session(client)));
479 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
480 target: TARGET,
481 state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
482 session: liveSession,
483 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
484 connect: Effect.void,
485 disconnect: Effect.void,
486 retryNow: Effect.void,
487 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
488
489 const fiber = yield* Stream.unwrap(
490 makeCachedVcsRefsChanges({ cwd: "/repo", limit: 100 }).pipe(
491 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
492 Effect.provideService(Persistence.EnvironmentCacheStore, cacheWithRefs(Option.none())),
493 ),
494 ).pipe(Stream.runHead, Effect.forkChild);
495
496 yield* Deferred.await(started);
497 yield* SubscriptionRef.set(liveSession, Option.none());
498 yield* Deferred.await(interrupted);
499 expect(yield* Ref.get(interruptions)).toBe(1);
500
501 yield* SubscriptionRef.set(liveSession, Option.some(session(client)));
502 expect(Option.getOrThrow(yield* Fiber.join(fiber))).toEqual(LIVE_REFS);
503 expect(yield* Ref.get(calls)).toBe(2);
504 }),
505 ),
506 );
507
508 it.effect("retries Git failures and cancels pending retries when the session is removed", () =>
509 Effect.scoped(
510 Effect.gen(function* () {
511 const calls = yield* Ref.make(0);
512 const warnings = yield* Queue.unbounded<unknown>();
513 const logger = Logger.make(({ message }) => Queue.offerUnsafe(warnings, message));
514 const failure = new VcsProcessExitError({
515 operation: "listRefs",
516 command: "git",
517 cwd: "/repo",
518 exitCode: 128,
519 detail: "Could not read refs.",
520 });
521 const client = {
522 [WS_METHODS.vcsListRefs]: () =>
523 Ref.updateAndGet(calls, (count) => count + 1).pipe(
524 Effect.flatMap((count) =>
525 count < 3 ? Effect.fail(failure) : Effect.succeed(LIVE_REFS),
526 ),
527 ),
528 } as unknown as WsRpcProtocolClient;
529 const liveSession = yield* SubscriptionRef.make(Option.some(session(client)));
530 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
531 target: TARGET,
532 state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
533 session: liveSession,
534 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
535 connect: Effect.void,
536 disconnect: Effect.void,
537 retryNow: Effect.void,
538 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
539 const refs = yield* Stream.unwrap(
540 makeCachedVcsRefsChanges({ cwd: "/repo", limit: 100 }).pipe(
541 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
542 Effect.provideService(
543 Persistence.EnvironmentCacheStore,
544 cacheWithRefs(Option.some(CACHED_REFS)),
545 ),
546 ),
547 ).pipe(
548 Stream.take(2),
549 Stream.runCollect,
550 Effect.provide(Logger.layer([logger], { mergeWithExisting: false })),
551 Effect.forkChild({ startImmediately: true }),
552 );
553
554 yield* Queue.take(warnings);
555 expect(yield* Ref.get(calls)).toBe(1);
556 yield* TestClock.adjust("1 second");
557 expect(yield* Ref.get(calls)).toBe(2);
558 expect(yield* Queue.size(warnings)).toBe(1);
559
560 yield* SubscriptionRef.set(liveSession, Option.none());
561 yield* TestClock.adjust("1 minute");
562 expect(yield* Ref.get(calls)).toBe(2);
563 expect(yield* Queue.size(warnings)).toBe(1);
564
565 yield* SubscriptionRef.set(liveSession, Option.some(session(client)));
566 expect(yield* Fiber.join(refs)).toEqual([CACHED_REFS, LIVE_REFS]);
567 expect(yield* Ref.get(calls)).toBe(3);
568 }),
569 ),
570 );
571
572 it.effect("emits persisted refs before a live refresh", () =>
573 Effect.scoped(
574 Effect.gen(function* () {
575 const client = {
576 [WS_METHODS.vcsListRefs]: () => Effect.succeed(LIVE_REFS),
577 } as unknown as WsRpcProtocolClient;
578 const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
579 target: TARGET,
580 state: yield* SubscriptionRef.make(CONNECTED_CONNECTION_STATE),
581 session: yield* SubscriptionRef.make(Option.some(session(client))),
582 prepared: yield* SubscriptionRef.make(Option.none<PreparedConnection>()),
583 connect: Effect.void,
584 disconnect: Effect.void,
585 retryNow: Effect.void,
586 } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
587
588 const refs = yield* Stream.unwrap(
589 makeCachedVcsRefsChanges({ cwd: "/repo", limit: 100 }).pipe(
590 Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
591 Effect.provideService(
592 Persistence.EnvironmentCacheStore,
593 cacheWithRefs(Option.some(CACHED_REFS)),
594 ),
595 ),
596 ).pipe(Stream.take(2), Stream.runCollect);
597
598 expect(refs).toEqual([CACHED_REFS, LIVE_REFS]);
599 }),
600 ),
601 );
602});
603
604vi.mock("./session.ts", () => ({
605 createEnvironmentSessionAtoms: () => ({ sessionStateAtom: grantedSessions }),
606}));
607const grantedSessions = Atom.family((_id: EnvironmentId) =>
608 Atom.make(
609 AsyncResult.success({
610 authenticated: true,
611 auth: {
612 policy: "remote-reachable",
613 bootstrapMethods: [],
614 sessionMethods: [],
615 sessionCookieName: "test",
616 },
617 scopes: [AuthSourceControlWriteScope],
618 }),
619 ),
620);