History

Merge remote-tracking branch 'origin/codex/effect-lint-storage-postgres-tests' into codex/effect-lint-integration

Rhys Sullivan committed 6 months ago

Commit d56487f2 parents 282e7c6 987638b1 file · +24 −12Browse files

Unified · Split

packages/core/storage-postgres/src/index.test.ts+24−12
@@ -7,7 +7,7 @@ · 6 unmodified lines
77 // cloud test DB on 5434.
88
99 import { describe, expect, it } from "@effect/vitest";
10−import { Effect } from "effect";
10+import { Data, Effect } from "effect";
1111 import postgres from "postgres";
1212 import { drizzle } from "drizzle-orm/postgres-js";
1313 import { relations } from "drizzle-orm";
@@ -21,7 +21,7 @@ import { · 7 unmodified lines
2121 jsonb,
2222 } from "drizzle-orm/pg-core";
2323
24−import type { DBAdapter } from "@executor-js/storage-core";
24+import type { DBAdapter, StorageFailure } from "@executor-js/storage-core";
2525 import {
2626 conformanceSchema,
2727 runAdapterConformance,
@@ -31,6 +31,13 @@ import { makePostgresAdapter } from "./index"; · 3 unmodified lines
3131
3232 const url = "postgresql://postgres:postgres@127.0.0.1:5435/postgres";
3333
34+class PostgresTestDatabaseError extends Data.TaggedError(
35+ "PostgresTestDatabaseError",
36+)<{
37+ readonly message: string;
38+ readonly cause: unknown;
39+}> {}
40+
3441 // max=1 so BEGIN/COMMIT sent via `db.execute(sql.raw(...))` always hit
3542 // the same connection — postgres.js with a larger pool rejects unsafe
3643 // transaction control that isn't bound to a single reserved client.
@@ -135,9 +142,10 @@ const createConformanceTables = Effect.tryPromise({ · 98 unmodified lines
135142 );
136143 },
137144 catch: (cause) =>
138− new Error(
139− `failed to create postgres conformance tables: ${String(cause)}`,
140− ),
145+ new PostgresTestDatabaseError({
146+ message: "failed to create postgres conformance tables",
147+ cause,
148+ }),
141149 });
142150
143151 const resetTables = Effect.gen(function* () {
@@ -145,18 +153,19 @@ const resetTables = Effect.gen(function* () { · 1 unmodified line
145153 try: () =>
146154 sql`DROP TABLE IF EXISTS "source", "tag", "source_tag", "with_defaults", "blob" CASCADE`.then(
147155 () => undefined,
148− ),
156+ ),
149157 catch: (cause) =>
150− new Error(
151− `failed to reset postgres conformance tables: ${String(cause)}`,
152− ),
158+ new PostgresTestDatabaseError({
159+ message: "failed to reset postgres conformance tables",
160+ cause,
161+ }),
153162 });
154163 yield* createConformanceTables;
155164 });
156165
157166 const withAdapter = <A, E>(
158167 fn: (adapter: DBAdapter) => Effect.Effect<A, E>,
159−): Effect.Effect<A, E | Error> =>
168+): Effect.Effect<A, E | StorageFailure | PostgresTestDatabaseError> =>
160169 Effect.gen(function* () {
161170 yield* resetTables;
162171 const db = drizzle(sql, { schema: conformanceTables });
@@ -165,7 +174,7 @@ const withAdapter = <A, E>( · 2 unmodified lines
165174 schema: conformanceSchema,
166175 });
167176 return yield* fn(adapter);
168− }) as Effect.Effect<A, E | Error>;
177+ });
169178
170179 runAdapterConformance("postgres", withAdapter);
171180
@@ -191,7 +200,10 @@ const resetScopedTable = Effect.tryPromise({ · 19 unmodified lines
191200 );
192201 },
193202 catch: (cause) =>
194− new Error(`failed to reset scoped_item table: ${String(cause)}`),
203+ new PostgresTestDatabaseError({
204+ message: "failed to reset scoped_item table",
205+ cause,
206+ }),
195207 });
196208
197209 const makeScopedAdapter = () =>