Unified · Split
| @@ -0,0 +1 @@ | ||
| 1 | +# @executor-js/plugin-apps | |
| @@ -51,16 +51,13 @@ describe("in-process app tool executor", () => { · 50 unmodified lines | ||
| 51 | 51 | }, |
| 52 | 52 | }); |
| 53 | 53 | `); |
| 54 | − const exit = yield* makeInProcessAppToolExecutor() | |
| 54 | + const error = yield* makeInProcessAppToolExecutor() | |
| 55 | 55 | .collect(bundled.code, { |
| 56 | 56 | fileSlug: "sync-deals", |
| 57 | 57 | sourcePath: "tools/sync-deals.ts", |
| 58 | 58 | }) |
| 59 | − .pipe(Effect.exit); | |
| 60 | − expect(exit._tag).toBe("Failure"); | |
| 61 | − if (exit._tag === "Failure") { | |
| 62 | − expect(String(exit.cause)).toContain("nested.crm"); | |
| 63 | − } | |
| 59 | + .pipe(Effect.flip); | |
| 60 | + expect(error).toMatchObject({ message: expect.stringContaining("nested.crm") }); | |
| 64 | 61 | }), |
| 65 | 62 | ); |
| 66 | 63 | |
| @@ -106,14 +103,13 @@ describe("in-process app tool executor", () => { · 39 unmodified lines | ||
| 106 | 103 | }), |
| 107 | 104 | }; |
| 108 | 105 | `); |
| 109 | − const exit = yield* makeInProcessAppToolExecutor() | |
| 106 | + const error = yield* makeInProcessAppToolExecutor() | |
| 110 | 107 | .collect(bundled.code, { |
| 111 | 108 | fileSlug: "sync-deals", |
| 112 | 109 | sourcePath: "tools/sync-deals.ts", |
| 113 | 110 | }) |
| 114 | − .pipe(Effect.exit); | |
| 115 | − expect(exit._tag).toBe("Failure"); | |
| 116 | − if (exit._tag === "Failure") expect(String(exit.cause)).toContain("collides"); | |
| 111 | + .pipe(Effect.flip); | |
| 112 | + expect(error).toMatchObject({ message: expect.stringContaining("collides") }); | |
| 117 | 113 | }), |
| 118 | 114 | ); |
| 119 | 115 | |
| @@ -161,7 +157,7 @@ describe("in-process app tool executor", () => { · 41 unmodified lines | ||
| 161 | 157 | handler(input) { return input; }, |
| 162 | 158 | }); |
| 163 | 159 | `); |
| 164 | − const exit = yield* makeInProcessAppToolExecutor() | |
| 160 | + const error = yield* makeInProcessAppToolExecutor() | |
| 165 | 161 | .invoke( |
| 166 | 162 | bundled.code, |
| 167 | 163 | { toolName: "sync-deals" }, |
| @@ -171,9 +167,8 @@ describe("in-process app tool executor", () => { · 3 unmodified lines | ||
| 171 | 167 | timeoutMs: 1000, |
| 172 | 168 | }, |
| 173 | 169 | ) |
| 174 | − .pipe(Effect.exit); | |
| 175 | − expect(exit._tag).toBe("Failure"); | |
| 176 | − if (exit._tag === "Failure") expect(String(exit.cause)).toContain("validation failed"); | |
| 170 | + .pipe(Effect.flip); | |
| 171 | + expect(error).toMatchObject({ message: expect.stringContaining("validation failed") }); | |
| 177 | 172 | }), |
| 178 | 173 | ); |
| 179 | 174 | |
| @@ -191,7 +186,7 @@ describe("in-process app tool executor", () => { · 11 unmodified lines | ||
| 191 | 186 | }, |
| 192 | 187 | }); |
| 193 | 188 | `); |
| 194 | − const exit = yield* makeInProcessAppToolExecutor() | |
| 189 | + const error = yield* makeInProcessAppToolExecutor() | |
| 195 | 190 | .invoke( |
| 196 | 191 | bundled.code, |
| 197 | 192 | { toolName: "sync-deals" }, |
| @@ -201,9 +196,8 @@ describe("in-process app tool executor", () => { · 3 unmodified lines | ||
| 201 | 196 | timeoutMs: 1, |
| 202 | 197 | }, |
| 203 | 198 | ) |
| 204 | − .pipe(Effect.exit); | |
| 205 | − expect(exit._tag).toBe("Failure"); | |
| 206 | − if (exit._tag === "Failure") expect(String(exit.cause)).toContain("timed out"); | |
| 199 | + .pipe(Effect.flip); | |
| 200 | + expect(error).toMatchObject({ message: expect.stringContaining("timed out") }); | |
| 207 | 201 | }), |
| 208 | 202 | ); |
| 209 | 203 | }); |
| @@ -1,3 +1,4 @@ | ||
| 1 | +/* oxlint-disable executor/no-try-catch-or-throw, executor/no-double-cast, executor/no-promise-reject, executor/no-instanceof-tagged-error -- boundary: in-process dynamic-import backing converts JavaScript exceptions into typed AppExecutorError */ | |
| 1 | 2 | import { Buffer } from "node:buffer"; |
| 2 | 3 | import { Data, Effect } from "effect"; |
| 3 | 4 | import { z } from "zod"; |
| @@ -4,7 +4,7 @@ import { Effect } from "effect"; · 3 unmodified lines | ||
| 4 | 4 | import type { AppsStore } from "../plugin/store"; |
| 5 | 5 | import { makeInProcessAppToolExecutor } from "../executor/app-tool-executor"; |
| 6 | 6 | import type { AppDescriptor } from "./descriptor"; |
| 7 | −import { discover, PublishError } from "./discover"; | |
| 7 | +import { discover } from "./discover"; | |
| 8 | 8 | import { publish } from "./publish"; |
| 9 | 9 | |
| 10 | 10 | const encoder = new TextEncoder(); |
| @@ -75,9 +75,10 @@ describe("discover", () => { · 64 unmodified lines | ||
| 75 | 75 | ["skills/guide.md", ""], |
| 76 | 76 | ]), |
| 77 | 77 | ); |
| 78 | − expect(result).toBeInstanceOf(PublishError); | |
| 79 | − if (!(result instanceof PublishError)) return; | |
| 80 | − expect(result.diagnostics[0]?.path).toBe("tools/readme.md"); | |
| 78 | + expect(result).toMatchObject({ | |
| 79 | + _tag: "PublishError", | |
| 80 | + diagnostics: [{ path: "tools/readme.md" }], | |
| 81 | + }); | |
| 81 | 82 | }); |
| 82 | 83 | }); |
| 83 | 84 | |
| @@ -117,7 +118,7 @@ describe("publish", () => { · 33 unmodified lines | ||
| 117 | 118 | it.effect("rejects nondeterministic factories", () => |
| 118 | 119 | Effect.gen(function* () { |
| 119 | 120 | const store = makeMemoryStore(); |
| 120 | − const exit = yield* publish( | |
| 121 | + yield* publish( | |
| 121 | 122 | { store, executor: makeInProcessAppToolExecutor() }, |
| 122 | 123 | { |
| 123 | 124 | app: "crm", |
| @@ -139,8 +140,7 @@ describe("publish", () => { · 15 unmodified lines | ||
| 139 | 140 | ), |
| 140 | 141 | ], |
| 141 | 142 | }, |
| 142 | − ).pipe(Effect.exit); | |
| 143 | − expect(exit._tag).toBe("Failure"); | |
| 143 | + ).pipe(Effect.flip); | |
| 144 | 144 | expect(store.rows.size).toBe(0); |
| 145 | 145 | }), |
| 146 | 146 | ); |
| @@ -66,11 +66,13 @@ const toPublishError = ( · 65 unmodified lines | ||
| 66 | 66 | ): PublishError => |
| 67 | 67 | new PublishError({ |
| 68 | 68 | stage, |
| 69 | + // oxlint-disable-next-line executor/no-unknown-error-message -- typed AppExecutorError conversion keeps its stable diagnostic message | |
| 69 | 70 | message: cause.message, |
| 70 | 71 | diagnostics: |
| 71 | 72 | cause.diagnostics && cause.diagnostics.length > 0 |
| 72 | 73 | ? cause.diagnostics |
| 73 | − : [{ path, message: cause.message }], | |
| 74 | + : // oxlint-disable-next-line executor/no-unknown-error-message -- typed AppExecutorError conversion keeps its stable diagnostic message | |
| 75 | + [{ path, message: cause.message }], | |
| 74 | 76 | }); |
| 75 | 77 | |
| 76 | 78 | const toolDescriptor = (input: { |
| @@ -2,15 +2,11 @@ import { Data, Effect } from "effect"; · 1 unmodified line | ||
| 2 | 2 | import { ToolName, definePlugin, type PluginCtx, type ToolDef } from "@executor-js/sdk"; |
| 3 | 3 | |
| 4 | 4 | import { makeInProcessAppToolExecutor, type AppToolExecutor } from "../executor/app-tool-executor"; |
| 5 | −import { publish, type PublishInput } from "../pipeline/publish"; | |
| 5 | +import { publish } from "../pipeline/publish"; | |
| 6 | 6 | import { buildBridge, resolveIntegrationBindings } from "./bindings"; |
| 7 | 7 | import { makePluginCtxAppsResolver } from "./resolver"; |
| 8 | 8 | import { descriptorCollection, makeAppsStore, toolCollection, type AppsStore } from "./store"; |
| 9 | 9 | |
| 10 | −export interface AppsExtension { | |
| 11 | − readonly publish: (input: PublishInput) => Effect.Effect<unknown, unknown>; | |
| 12 | −} | |
| 13 | − | |
| 14 | 10 | const APPS_INTEGRATION = "apps"; |
| 15 | 11 | const APPS_CONNECTION = "published"; |
| 16 | 12 | |
| @@ -23,6 +19,13 @@ interface ProjectedToolSchema { · 6 unmodified lines | ||
| 23 | 19 | readonly outputSchema?: unknown; |
| 24 | 20 | } |
| 25 | 21 | |
| 22 | +const makeAppsExtension = (ctx: PluginCtx<AppsStore>, executor?: AppToolExecutor) => ({ | |
| 23 | + publish: (input: Parameters<typeof publish>[1]) => | |
| 24 | + publish({ store: ctx.storage, executor: executor ?? makeInProcessAppToolExecutor() }, input), | |
| 25 | +}); | |
| 26 | + | |
| 27 | +export type AppsExtension = ReturnType<typeof makeAppsExtension>; | |
| 28 | + | |
| 26 | 29 | export const makeAppsPlugin = (options?: { readonly executor?: AppToolExecutor }) => |
| 27 | 30 | definePlugin(() => ({ |
| 28 | 31 | id: "apps", |
| @@ -32,13 +35,7 @@ export const makeAppsPlugin = (options?: { readonly executor?: AppToolExecutor } · 3 unmodified lines | ||
| 32 | 35 | [toolCollection.name]: toolCollection, |
| 33 | 36 | }, |
| 34 | 37 | storage: ({ blobs, pluginStorage }) => makeAppsStore({ blobs, pluginStorage }), |
| 35 | − extension: (ctx: PluginCtx<AppsStore>): AppsExtension => ({ | |
| 36 | − publish: (input) => | |
| 37 | − publish( | |
| 38 | − { store: ctx.storage, executor: options?.executor ?? makeInProcessAppToolExecutor() }, | |
| 39 | − input, | |
| 40 | − ), | |
| 41 | − }), | |
| 38 | + extension: (ctx: PluginCtx<AppsStore>) => makeAppsExtension(ctx, options?.executor), | |
| 42 | 39 | staticSources: () => [ |
| 43 | 40 | { |
| 44 | 41 | id: "apps", |
| @@ -1,12 +1,7 @@ | ||
| 1 | 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | 2 | import { Effect } from "effect"; |
| 3 | 3 | |
| 4 | −import { | |
| 5 | − BindingError, | |
| 6 | − buildBridge, | |
| 7 | − resolveIntegrationBindings, | |
| 8 | − type ClientResolver, | |
| 9 | −} from "./bindings"; | |
| 4 | +import { buildBridge, resolveIntegrationBindings, type ClientResolver } from "./bindings"; | |
| 10 | 5 | |
| 11 | 6 | const resolver: ClientResolver = { |
| 12 | 7 | listConnections: ({ integration }) => |
| @@ -39,25 +34,23 @@ describe("integration bindings", () => { · 26 unmodified lines | ||
| 39 | 34 | |
| 40 | 35 | it.effect("fails unknown connection addresses as BindingError", () => |
| 41 | 36 | Effect.gen(function* () { |
| 42 | − const exit = yield* resolveIntegrationBindings( | |
| 37 | + const error = yield* resolveIntegrationBindings( | |
| 43 | 38 | { crm: { slug: "dealcloud" } }, |
| 44 | 39 | { crm: "tools.dealcloud.org.missing" }, |
| 45 | 40 | resolver, |
| 46 | − ).pipe(Effect.exit); | |
| 47 | − expect(exit._tag).toBe("Failure"); | |
| 48 | − if (exit._tag === "Failure") expect(String(exit.cause)).toContain("BindingError"); | |
| 41 | + ).pipe(Effect.flip); | |
| 42 | + expect(error).toMatchObject({ _tag: "BindingError" }); | |
| 49 | 43 | }), |
| 50 | 44 | ); |
| 51 | 45 | |
| 52 | 46 | it.effect("fails mismatched connection integrations as BindingError", () => |
| 53 | 47 | Effect.gen(function* () { |
| 54 | − const exit = yield* resolveIntegrationBindings( | |
| 48 | + const error = yield* resolveIntegrationBindings( | |
| 55 | 49 | { crm: { slug: "dealcloud" } }, |
| 56 | 50 | { crm: "tools.github.org.main" }, |
| 57 | 51 | resolver, |
| 58 | − ).pipe(Effect.exit); | |
| 59 | − expect(exit._tag).toBe("Failure"); | |
| 60 | − if (exit._tag === "Failure") expect(String(exit.cause)).toContain('not "dealcloud"'); | |
| 52 | + ).pipe(Effect.flip); | |
| 53 | + expect(error).toMatchObject({ message: expect.stringContaining('not "dealcloud"') }); | |
| 61 | 54 | }), |
| 62 | 55 | ); |
| 63 | 56 | |
| @@ -79,6 +72,8 @@ describe("integration bindings", () => { · 15 unmodified lines | ||
| 79 | 72 | bindings: { crm: "tools.dealcloud.org.main" }, |
| 80 | 73 | resolver, |
| 81 | 74 | }); |
| 82 | − await expect(bridge.call("github.repos.get", {})).rejects.toBeInstanceOf(BindingError); | |
| 75 | + await expect(bridge.call("github.repos.get", {})).rejects.toMatchObject({ | |
| 76 | + _tag: "BindingError", | |
| 77 | + }); | |
| 83 | 78 | }); |
| 84 | 79 | }); |
| @@ -104,12 +104,14 @@ export const buildBridge = (input: { · 103 unmodified lines | ||
| 104 | 104 | const decl = input.declared[field ?? ""]; |
| 105 | 105 | const connection = input.bindings[field ?? ""]; |
| 106 | 106 | if (!field || !decl || !connection || path.length === 0) { |
| 107 | − return Promise.reject( | |
| 108 | − new BindingError({ | |
| 109 | − role: field ?? "", | |
| 110 | − integration: decl?.slug ?? "", | |
| 111 | − message: `undeclared integration call: ${toolPath}`, | |
| 112 | − }), | |
| 107 | + return Effect.runPromise( | |
| 108 | + Effect.fail( | |
| 109 | + new BindingError({ | |
| 110 | + role: field ?? "", | |
| 111 | + integration: decl?.slug ?? "", | |
| 112 | + message: `undeclared integration call: ${toolPath}`, | |
| 113 | + }), | |
| 114 | + ), | |
| 113 | 115 | ); |
| 114 | 116 | } |
| 115 | 117 | return Effect.runPromise( |