Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions packages/core/sdk/src/blob.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "@effect/vitest";
import { Cause, Effect, Exit } from "effect";
import { Effect } from "effect";

import { StorageError } from "@executor-js/storage-core";

Expand Down Expand Up @@ -75,15 +75,13 @@ describe("pluginBlobStore", () => {
Effect.gen(function* () {
const store = makeInMemoryBlobStore();
const plugin = pluginBlobStore(store, ["inner", "outer"], "my-plugin");
const result = yield* Effect.exit(
plugin.put("k", "v", { scope: "not-in-stack" }),
);
expect(Exit.isFailure(result)).toBe(true);
if (!Exit.isFailure(result)) return;
const reason = result.cause.reasons.find(Cause.isFailReason);
const err = reason?.error ?? null;
const err = yield* plugin
.put("k", "v", { scope: "not-in-stack" })
.pipe(Effect.flip);
expect(err).toBeInstanceOf(StorageError);
expect((err as StorageError).message).toContain("not in the");
expect(err).toMatchObject({
message: expect.stringContaining("not in the"),
});
// Write must not have reached the store.
expect(yield* store.get("not-in-stack/my-plugin", "k")).toBeNull();
}),
Expand All @@ -93,10 +91,10 @@ describe("pluginBlobStore", () => {
Effect.gen(function* () {
const store = makeInMemoryBlobStore();
const plugin = pluginBlobStore(store, ["inner"], "my-plugin");
const result = yield* Effect.exit(
plugin.delete("k", { scope: "not-in-stack" }),
);
expect(Exit.isFailure(result)).toBe(true);
const err = yield* plugin
.delete("k", { scope: "not-in-stack" })
.pipe(Effect.flip);
expect(err).toBeInstanceOf(StorageError);
}),
);
});
Expand Down
14 changes: 9 additions & 5 deletions packages/core/sdk/src/error-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// ---------------------------------------------------------------------------

import { describe, expect, it } from "@effect/vitest";
import { Effect } from "effect";
import { Effect, Predicate } from "effect";

import {
StorageError,
Expand Down Expand Up @@ -83,22 +83,26 @@ const baseConfig = (adapter: DBAdapter) => ({
describe("typed-error edge model — SDK", () => {
it.effect("StorageError propagates raw through the executor surface", () =>
Effect.gen(function* () {
const driverCause = new StorageError({
message: "driver kaboom",
cause: undefined,
});
const failure = new StorageError({
message: "backend lost its mind",
cause: new Error("driver kaboom"),
cause: driverCause,
});
const executor = yield* createExecutor(
baseConfig(makeFailingAdapter(failure)),
);

const result = yield* executor.tools.list().pipe(Effect.flip);
expect(result).toBeInstanceOf(StorageError);
expect(result._tag).toBe("StorageError");
expect(Predicate.isTagged(result, "StorageError")).toBe(true);
// Original cause preserved end-to-end.
const storageErr = result as StorageError;
expect(storageErr.message).toBe("backend lost its mind");
expect(storageErr.cause).toBeInstanceOf(Error);
expect((storageErr.cause as Error).message).toBe("driver kaboom");
expect(storageErr.cause).toBe(driverCause);
expect(driverCause.message).toBe("driver kaboom");
}),
);

Expand Down
15 changes: 10 additions & 5 deletions packages/core/sdk/src/schema-types.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "@effect/vitest";
import { Schema } from "effect";

import {
buildToolTypeScriptPreview,
schemaToTypeScriptPreview,
schemaToTypeScriptPreviewWithDefs,
} from "./schema-types";

const stripeBalanceTransactionsFixture = JSON.parse(
const StripeBalanceTransactionsFixture = Schema.Struct({
schema: Schema.Unknown,
defs: Schema.Record(Schema.String, Schema.Unknown),
});

const stripeBalanceTransactionsFixture = Schema.decodeUnknownSync(
Schema.fromJsonString(StripeBalanceTransactionsFixture),
)(
readFileSync(
new URL("./__fixtures__/stripe-get-balance-transactions-id.json", import.meta.url),
"utf8",
),
) as {
schema: unknown;
defs: Record<string, unknown>;
};
);

describe("schema-types", () => {
it("reuses referenced definitions instead of inlining them", () => {
Expand Down
Loading