authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-10-05 21:42:09-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-05 21:42:09-07:00
logefeeb7737bed89bbfc6dc81662058f8ce7fba2ea
tree5a2ad66283b0f661de4f05b4d1ba65730c7e9239
parentc299308a832db382fce61233bd10a4bd13bbc60c
signature Signed by PGP key B5690EEEBB952194

refactor(web): import connection storage as a namespace in its test (#16315)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

1 files changed, 18 insertions(+), 21 deletions(-)

apps/web/src/connection/storage.test.ts+18-21
......@@ -12,12 +12,7 @@ import * as Schema from "effect/Schema";
1212import * as Stream from "effect/Stream";
1313import { afterEach, vi } from "vite-plus/test";
1414
15import {
16 makeBrowserGitHubRoutingPermissions,
17 makeCatalogBackend,
18 makeCatalogStore,
19 layer as connectionStorageLayer,
20} from "./storage";
15import * as ConnectionStorage from "./storage";
2116
2217const emptyCatalog = {
2318 schemaVersion: 1,
......@@ -35,12 +30,12 @@ afterEach(() => {
3530 vi.restoreAllMocks();
3631});
3732
38describe("makeCatalogStore", () => {
33describe("ConnectionStorage.makeCatalogStore", () => {
3934 it.effect("quarantines malformed catalogs and starts from an empty document", () =>
4035 Effect.gen(function* () {
4136 const writes: string[] = [];
4237 const quarantined: string[] = [];
43 const store = yield* makeCatalogStore({
38 const store = yield* ConnectionStorage.makeCatalogStore({
4439 read: Effect.succeed("{not-json"),
4540 write: (raw) => Effect.sync(() => writes.push(raw)),
4641 quarantine: (raw) => Effect.sync(() => quarantined.push(raw)),
......@@ -59,7 +54,7 @@ describe("makeCatalogStore", () => {
5954 reason: "remote-unavailable",
6055 detail: "permission denied",
6156 });
62 const store = yield* makeCatalogStore({
57 const store = yield* ConnectionStorage.makeCatalogStore({
6358 read: Effect.fail(failure),
6459 write: () => Effect.void,
6560 });
......@@ -74,7 +69,7 @@ const fixedHandle = (database: IDBDatabase) => ({
7469 invalidate: () => Effect.void,
7570});
7671
77describe("makeCatalogBackend", () => {
72describe("ConnectionStorage.makeCatalogBackend", () => {
7873 it.effect("reports a closed IndexedDB connection as a typed read and write failure", () =>
7974 Effect.gen(function* () {
8075 vi.stubGlobal("window", {});
......@@ -83,7 +78,7 @@ describe("makeCatalogBackend", () => {
8378 throw new DOMException("The database connection is closing.", "InvalidStateError");
8479 },
8580 } as unknown as IDBDatabase;
86 const backend = makeCatalogBackend(fixedHandle(database));
81 const backend = ConnectionStorage.makeCatalogBackend(fixedHandle(database));
8782
8883 const readError = yield* Effect.flip(backend.read);
8984 const writeError = yield* Effect.flip(backend.write("{}"));
......@@ -103,7 +98,7 @@ describe("makeCatalogBackend", () => {
10398 setConnectionCatalog,
10499 },
105100 });
106 const backend = makeCatalogBackend(fixedHandle({} as IDBDatabase));
101 const backend = ConnectionStorage.makeCatalogBackend(fixedHandle({} as IDBDatabase));
107102
108103 const error = yield* backend.write("{}").pipe(Effect.flip);
109104
......@@ -128,7 +123,7 @@ describe("makeCatalogBackend", () => {
128123 },
129124 }),
130125 });
131 const backend = makeCatalogBackend(
126 const backend = ConnectionStorage.makeCatalogBackend(
132127 fixedHandle({ transaction: () => transaction } as unknown as IDBDatabase),
133128 );
134129
......@@ -176,7 +171,7 @@ describe("environment cache removal", () => {
176171 ),
177172 yield* Effect.flip(cache.clearVcsRefs(EnvironmentId.make("env"))),
178173 ] as const;
179 }).pipe(Effect.provide(connectionStorageLayer));
174 }).pipe(Effect.provide(ConnectionStorage.layer));
180175
181176 expect(threadError.message).toContain("Commit aborted");
182177 expect(refsError.message).toContain("Commit aborted");
......@@ -201,7 +196,7 @@ describe("IndexedDB connection recovery", () => {
201196 cache.loadThread(EnvironmentId.make("env"), ThreadId.make("thread")),
202197 );
203198 expect(error.message).toContain("Storage is unavailable");
204 }).pipe(Effect.provide(connectionStorageLayer));
199 }).pipe(Effect.provide(ConnectionStorage.layer));
205200
206201 expect(open).toHaveBeenCalledOnce();
207202 }),
......@@ -254,7 +249,7 @@ describe("IndexedDB connection recovery", () => {
254249 );
255250 expect(recovered.every(Option.isNone)).toBe(true);
256251 expect(open).toHaveBeenCalledTimes(2);
257 }).pipe(Effect.provide(connectionStorageLayer));
252 }).pipe(Effect.provide(ConnectionStorage.layer));
258253
259254 expect(first.close).not.toHaveBeenCalled();
260255 expect(second.close).toHaveBeenCalledOnce();
......@@ -302,7 +297,7 @@ describe("IndexedDB connection closed without a close event", () => {
302297 const loaded = yield* cache.loadThread(EnvironmentId.make("env"), ThreadId.make("thread"));
303298 expect(Option.isNone(loaded)).toBe(true);
304299 expect(open).toHaveBeenCalledTimes(2);
305 }).pipe(Effect.provide(connectionStorageLayer));
300 }).pipe(Effect.provide(ConnectionStorage.layer));
306301 }),
307302 );
308303});
......@@ -329,8 +324,8 @@ describe("browser GitHub routing permissions", () => {
329324 };
330325 const firstBrowser = Object.assign(new EventTarget(), { localStorage });
331326 const secondBrowser = Object.assign(new EventTarget(), { localStorage });
332 const first = makeBrowserGitHubRoutingPermissions(firstBrowser);
333 const second = makeBrowserGitHubRoutingPermissions(secondBrowser);
327 const first = ConnectionStorage.makeBrowserGitHubRoutingPermissions(firstBrowser);
328 const second = ConnectionStorage.makeBrowserGitHubRoutingPermissions(secondBrowser);
334329 const entry = {
335330 target: new PrimaryConnectionTarget({
336331 environmentId: EnvironmentId.make("first"),
......@@ -352,7 +347,7 @@ describe("browser GitHub routing permissions", () => {
352347 yield* first.set(entry, "read-write");
353348 expect(yield* second.get(entry)).toBe("read-write");
354349 const oldPermissions = Option.getOrThrow(yield* Stream.runHead(first.changes));
355 const staleCatalog = yield* makeCatalogStore({
350 const staleCatalog = yield* ConnectionStorage.makeCatalogStore({
356351 read: Effect.succeed(
357352 encodeCatalog({ ...emptyCatalog, githubRoutingPermissions: oldPermissions }),
358353 ),
......@@ -377,7 +372,9 @@ describe("browser GitHub routing permissions", () => {
377372 yield* staleCatalog.update((document) => ({ ...document, accountId: "updated" }));
378373 expect(yield* second.get(entry)).toBe("off");
379374 expect(yield* first.get(other)).toBe("read");
380 expect(yield* makeBrowserGitHubRoutingPermissions(firstBrowser).get(entry)).toBe("off");
375 expect(
376 yield* ConnectionStorage.makeBrowserGitHubRoutingPermissions(firstBrowser).get(entry),
377 ).toBe("off");
381378
382379 yield* first.set(entry, "read-write");
383380 yield* second.forget(entry.target.environmentId);