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