History

Clean core API typed boundaries

Rhys Sullivan committed 6 months ago

Commit b953a1f1 parent b039b6e2 files · +14 −9Browse files

Unified · Split

2 files
  1. packages/core/api/src/handlers/tools.ts +1 −1
  2. packages/core/api/src/oauth-popup.test.ts +13 −8
packages/core/api/src/handlers/tools.ts+1−1
@@ -35,7 +35,7 @@ export const ToolsHandlers = HttpApiBuilder.group(ExecutorApi, "tools", (handler · 34 unmodified lines
3535 const executor = yield* ExecutorService;
3636 const schema = yield* executor.tools.schema(path.toolId);
3737 if (schema === null) {
38− return yield* Effect.fail(new ToolNotFoundError({ toolId: path.toolId }));
38+ return yield* new ToolNotFoundError({ toolId: path.toolId });
3939 }
4040 return schema;
4141 })),
packages/core/api/src/oauth-popup.test.ts+13−8
@@ -6,7 +6,7 @@ · 5 unmodified lines
66 // ---------------------------------------------------------------------------
77
88 import { describe, expect, it } from "@effect/vitest";
9−import { Effect } from "effect";
9+import { Data, Effect, Schema } from "effect";
1010
1111 import {
1212 OAUTH_POPUP_MESSAGE_TYPE,
@@ -169,16 +169,21 @@ describe("runOAuthCallback", () => { · 156 unmodified lines
169169 });
170170
171171 it("renders a failure popup when completeOAuth fails and uses toErrorMessage", async () => {
172− class DomainError {
173− readonly _tag = "DomainError";
174− constructor(readonly message: string) {}
175− }
172+ class DomainError extends Data.TaggedError("DomainError")<{
173+ readonly message: string;
174+ }> {}
175+ const isDomainError = Schema.is(Schema.Struct({
176+ _tag: Schema.Literal("DomainError"),
177+ message: Schema.String,
178+ }));
176179 const html = await Effect.runPromise(
177180 runOAuthCallback<GoogleAuth, DomainError, never>({
178− complete: () => Effect.fail(new DomainError("Code expired")),
181+ complete: () => Effect.fail(new DomainError({ message: "Code expired" })),
179182 urlParams: { state: "s1" },
180− toErrorMessage: (error) =>
181− error instanceof DomainError ? error.message : "unknown",
183+ toErrorMessage: (error) => {
184+ // oxlint-disable-next-line executor/no-unknown-error-message -- boundary: schema guard narrows the unknown popup callback error to the public test message
185+ return isDomainError(error) ? error.message : "unknown";
186+ },
182187 channelName: "c",
183188 }),
184189 );