| ... | ... | @@ -12,12 +12,7 @@ import * as Schema from "effect/Schema"; |
| 12 | 12 | import * as Stream from "effect/Stream"; |
| 13 | 13 | import { afterEach, vi } from "vite-plus/test"; |
| 14 | 14 | |
| 15 | | import { |
| 16 | | makeBrowserGitHubRoutingPermissions, |
| 17 | | makeCatalogBackend, |
| 18 | | makeCatalogStore, |
| 19 | | layer as connectionStorageLayer, |
| 20 | | } from "./storage"; |
| 15 | import * as ConnectionStorage from "./storage"; |
| 21 | 16 | |
| 22 | 17 | const emptyCatalog = { |
| 23 | 18 | schemaVersion: 1, |
| ... | ... | @@ -35,12 +30,12 @@ afterEach(() => { |
| 35 | 30 | vi.restoreAllMocks(); |
| 36 | 31 | }); |
| 37 | 32 | |
| 38 | | describe("makeCatalogStore", () => { |
| 33 | describe("ConnectionStorage.makeCatalogStore", () => { |
| 39 | 34 | it.effect("quarantines malformed catalogs and starts from an empty document", () => |
| 40 | 35 | Effect.gen(function* () { |
| 41 | 36 | const writes: string[] = []; |
| 42 | 37 | const quarantined: string[] = []; |
| 43 | | const store = yield* makeCatalogStore({ |
| 38 | const store = yield* ConnectionStorage.makeCatalogStore({ |
| 44 | 39 | read: Effect.succeed("{not-json"), |
| 45 | 40 | write: (raw) => Effect.sync(() => writes.push(raw)), |
| 46 | 41 | quarantine: (raw) => Effect.sync(() => quarantined.push(raw)), |
| ... | ... | @@ -59,7 +54,7 @@ describe("makeCatalogStore", () => { |
| 59 | 54 | reason: "remote-unavailable", |
| 60 | 55 | detail: "permission denied", |
| 61 | 56 | }); |
| 62 | | const store = yield* makeCatalogStore({ |
| 57 | const store = yield* ConnectionStorage.makeCatalogStore({ |
| 63 | 58 | read: Effect.fail(failure), |
| 64 | 59 | write: () => Effect.void, |
| 65 | 60 | }); |
| ... | ... | @@ -74,7 +69,7 @@ const fixedHandle = (database: IDBDatabase) => ({ |
| 74 | 69 | invalidate: () => Effect.void, |
| 75 | 70 | }); |
| 76 | 71 | |
| 77 | | describe("makeCatalogBackend", () => { |
| 72 | describe("ConnectionStorage.makeCatalogBackend", () => { |
| 78 | 73 | it.effect("reports a closed IndexedDB connection as a typed read and write failure", () => |
| 79 | 74 | Effect.gen(function* () { |
| 80 | 75 | vi.stubGlobal("window", {}); |
| ... | ... | @@ -83,7 +78,7 @@ describe("makeCatalogBackend", () => { |
| 83 | 78 | throw new DOMException("The database connection is closing.", "InvalidStateError"); |
| 84 | 79 | }, |
| 85 | 80 | } as unknown as IDBDatabase; |
| 86 | | const backend = makeCatalogBackend(fixedHandle(database)); |
| 81 | const backend = ConnectionStorage.makeCatalogBackend(fixedHandle(database)); |
| 87 | 82 | |
| 88 | 83 | const readError = yield* Effect.flip(backend.read); |
| 89 | 84 | const writeError = yield* Effect.flip(backend.write("{}")); |
| ... | ... | @@ -103,7 +98,7 @@ describe("makeCatalogBackend", () => { |
| 103 | 98 | setConnectionCatalog, |
| 104 | 99 | }, |
| 105 | 100 | }); |
| 106 | | const backend = makeCatalogBackend(fixedHandle({} as IDBDatabase)); |
| 101 | const backend = ConnectionStorage.makeCatalogBackend(fixedHandle({} as IDBDatabase)); |
| 107 | 102 | |
| 108 | 103 | const error = yield* backend.write("{}").pipe(Effect.flip); |
| 109 | 104 | |
| ... | ... | @@ -128,7 +123,7 @@ describe("makeCatalogBackend", () => { |
| 128 | 123 | }, |
| 129 | 124 | }), |
| 130 | 125 | }); |
| 131 | | const backend = makeCatalogBackend( |
| 126 | const backend = ConnectionStorage.makeCatalogBackend( |
| 132 | 127 | fixedHandle({ transaction: () => transaction } as unknown as IDBDatabase), |
| 133 | 128 | ); |
| 134 | 129 | |
| ... | ... | @@ -176,7 +171,7 @@ describe("environment cache removal", () => { |
| 176 | 171 | ), |
| 177 | 172 | yield* Effect.flip(cache.clearVcsRefs(EnvironmentId.make("env"))), |
| 178 | 173 | ] as const; |
| 179 | | }).pipe(Effect.provide(connectionStorageLayer)); |
| 174 | }).pipe(Effect.provide(ConnectionStorage.layer)); |
| 180 | 175 | |
| 181 | 176 | expect(threadError.message).toContain("Commit aborted"); |
| 182 | 177 | expect(refsError.message).toContain("Commit aborted"); |
| ... | ... | @@ -201,7 +196,7 @@ describe("IndexedDB connection recovery", () => { |
| 201 | 196 | cache.loadThread(EnvironmentId.make("env"), ThreadId.make("thread")), |
| 202 | 197 | ); |
| 203 | 198 | expect(error.message).toContain("Storage is unavailable"); |
| 204 | | }).pipe(Effect.provide(connectionStorageLayer)); |
| 199 | }).pipe(Effect.provide(ConnectionStorage.layer)); |
| 205 | 200 | |
| 206 | 201 | expect(open).toHaveBeenCalledOnce(); |
| 207 | 202 | }), |
| ... | ... | @@ -254,7 +249,7 @@ describe("IndexedDB connection recovery", () => { |
| 254 | 249 | ); |
| 255 | 250 | expect(recovered.every(Option.isNone)).toBe(true); |
| 256 | 251 | expect(open).toHaveBeenCalledTimes(2); |
| 257 | | }).pipe(Effect.provide(connectionStorageLayer)); |
| 252 | }).pipe(Effect.provide(ConnectionStorage.layer)); |
| 258 | 253 | |
| 259 | 254 | expect(first.close).not.toHaveBeenCalled(); |
| 260 | 255 | expect(second.close).toHaveBeenCalledOnce(); |
| ... | ... | @@ -302,7 +297,7 @@ describe("IndexedDB connection closed without a close event", () => { |
| 302 | 297 | const loaded = yield* cache.loadThread(EnvironmentId.make("env"), ThreadId.make("thread")); |
| 303 | 298 | expect(Option.isNone(loaded)).toBe(true); |
| 304 | 299 | expect(open).toHaveBeenCalledTimes(2); |
| 305 | | }).pipe(Effect.provide(connectionStorageLayer)); |
| 300 | }).pipe(Effect.provide(ConnectionStorage.layer)); |
| 306 | 301 | }), |
| 307 | 302 | ); |
| 308 | 303 | }); |
| ... | ... | @@ -329,8 +324,8 @@ describe("browser GitHub routing permissions", () => { |
| 329 | 324 | }; |
| 330 | 325 | const firstBrowser = Object.assign(new EventTarget(), { localStorage }); |
| 331 | 326 | 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); |
| 334 | 329 | const entry = { |
| 335 | 330 | target: new PrimaryConnectionTarget({ |
| 336 | 331 | environmentId: EnvironmentId.make("first"), |
| ... | ... | @@ -352,7 +347,7 @@ describe("browser GitHub routing permissions", () => { |
| 352 | 347 | yield* first.set(entry, "read-write"); |
| 353 | 348 | expect(yield* second.get(entry)).toBe("read-write"); |
| 354 | 349 | const oldPermissions = Option.getOrThrow(yield* Stream.runHead(first.changes)); |
| 355 | | const staleCatalog = yield* makeCatalogStore({ |
| 350 | const staleCatalog = yield* ConnectionStorage.makeCatalogStore({ |
| 356 | 351 | read: Effect.succeed( |
| 357 | 352 | encodeCatalog({ ...emptyCatalog, githubRoutingPermissions: oldPermissions }), |
| 358 | 353 | ), |
| ... | ... | @@ -377,7 +372,9 @@ describe("browser GitHub routing permissions", () => { |
| 377 | 372 | yield* staleCatalog.update((document) => ({ ...document, accountId: "updated" })); |
| 378 | 373 | expect(yield* second.get(entry)).toBe("off"); |
| 379 | 374 | 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"); |
| 381 | 378 | |
| 382 | 379 | yield* first.set(entry, "read-write"); |
| 383 | 380 | yield* second.forget(entry.target.environmentId); |