every-plugin 0.0.6 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -13
- package/dist/errors.js +10 -10
- package/dist/plugin.d.ts +98 -44
- package/dist/plugin.js +17 -15
- package/dist/runtime/errors.d.ts +22 -1
- package/dist/runtime/errors.d.ts.map +1 -1
- package/dist/runtime/errors.js +8 -6
- package/dist/runtime/index.d.ts +68 -16
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +126 -27
- package/dist/runtime/mf.test.d.ts +2 -0
- package/dist/runtime/mf.test.d.ts.map +1 -0
- package/dist/runtime/mf.test.js +135 -0
- package/dist/runtime/runtime.test.d.ts +1 -1
- package/dist/runtime/runtime.test.js +366 -296
- package/dist/runtime/services/module-federation.service.d.ts +36 -9
- package/dist/runtime/services/module-federation.service.d.ts.map +1 -1
- package/dist/runtime/services/module-federation.service.js +122 -99
- package/dist/runtime/services/plugin.service.d.ts +66 -13
- package/dist/runtime/services/plugin.service.d.ts.map +1 -1
- package/dist/runtime/services/plugin.service.js +330 -122
- package/dist/runtime/services/secrets.service.d.ts +29 -9
- package/dist/runtime/services/secrets.service.d.ts.map +1 -1
- package/dist/runtime/services/secrets.service.js +30 -26
- package/dist/runtime/services.d.ts +1 -2
- package/dist/runtime/services.d.ts.map +1 -1
- package/dist/runtime/services.js +0 -1
- package/dist/runtime/streaming.d.ts +29 -0
- package/dist/runtime/streaming.d.ts.map +1 -0
- package/dist/runtime/streaming.js +59 -0
- package/dist/runtime/streaming.test.d.ts +2 -0
- package/dist/runtime/streaming.test.d.ts.map +1 -0
- package/dist/runtime/streaming.test.js +271 -0
- package/dist/runtime/test-utils.d.ts +3 -0
- package/dist/runtime/test-utils.d.ts.map +1 -0
- package/dist/runtime/test-utils.js +13 -0
- package/dist/runtime/types.d.ts +27 -27
- package/dist/runtime/validation.d.ts +1 -1
- package/dist/runtime/validation.d.ts.map +1 -1
- package/dist/runtime/validation.js +14 -11
- package/dist/source.d.ts +62 -190
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +32 -85
- package/package.json +7 -3
- package/dist/runtime/runtime.d.ts +0 -58
- package/dist/runtime/runtime.d.ts.map +0 -1
- package/dist/runtime/runtime.js +0 -75
- package/dist/runtime/services/plugin-cache.service.d.ts +0 -18
- package/dist/runtime/services/plugin-cache.service.d.ts.map +0 -1
- package/dist/runtime/services/plugin-cache.service.js +0 -55
|
@@ -1,308 +1,378 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Duration, Effect } from "effect";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
3
|
+
import { createPluginRuntime, PluginRuntime } from "./index";
|
|
4
|
+
|
|
4
5
|
// Local template plugin for testing
|
|
5
6
|
const TEST_REGISTRY = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
"test-plugin": {
|
|
8
|
+
remoteUrl: "http://localhost:3000/remoteEntry.js",
|
|
9
|
+
type: "transformer",
|
|
10
|
+
version: "0.0.1",
|
|
11
|
+
description: "Local template plugin for testing",
|
|
12
|
+
},
|
|
13
|
+
"invalid-plugin": {
|
|
14
|
+
remoteUrl: "https://invalid-plugin-url-that-does-not-exist.com/plugin.js",
|
|
15
|
+
type: "transformer",
|
|
16
|
+
version: "1.0.0",
|
|
17
|
+
description: "Invalid plugin for testing error handling",
|
|
18
|
+
},
|
|
12
19
|
};
|
|
13
20
|
const TEST_CONFIG = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
variables: {
|
|
22
|
+
baseUrl: "http://localhost:1337",
|
|
23
|
+
timeout: 5000,
|
|
24
|
+
},
|
|
25
|
+
secrets: {
|
|
26
|
+
apiKey: "{{API_KEY}}", // This will be hydrated from secrets config
|
|
27
|
+
},
|
|
21
28
|
};
|
|
22
29
|
const TEST_INPUT = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
query: "test query for processing",
|
|
31
|
+
options: {
|
|
32
|
+
limit: 2,
|
|
33
|
+
},
|
|
27
34
|
};
|
|
28
35
|
// Secrets configuration for hydration
|
|
29
36
|
const SECRETS_CONFIG = {
|
|
30
|
-
|
|
37
|
+
API_KEY: "test-api-key-value",
|
|
31
38
|
};
|
|
32
39
|
describe("Plugin Runtime Integration", () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
40
|
+
let runtime;
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
runtime = createPluginRuntime({
|
|
43
|
+
registry: TEST_REGISTRY,
|
|
44
|
+
secrets: SECRETS_CONFIG,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
afterEach(async () => {
|
|
48
|
+
if (runtime) {
|
|
49
|
+
await runtime.dispose();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
it("should create and execute plugin end-to-end", async () => {
|
|
53
|
+
// Execute the test within the runtime
|
|
54
|
+
const result = await runtime.runPromise(
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
57
|
+
// Create plugin (load → instantiate → initialize)
|
|
58
|
+
const initializedPlugin = yield* pluginRuntime.usePlugin(
|
|
59
|
+
"test-plugin",
|
|
60
|
+
TEST_CONFIG,
|
|
61
|
+
);
|
|
62
|
+
// Verify plugin was initialized
|
|
63
|
+
expect(initializedPlugin).toBeDefined();
|
|
64
|
+
expect(initializedPlugin.metadata.pluginId).toBe("test-plugin");
|
|
65
|
+
expect(initializedPlugin.plugin).toBeDefined();
|
|
66
|
+
// Execute plugin
|
|
67
|
+
const output = yield* pluginRuntime.executePlugin(
|
|
68
|
+
initializedPlugin,
|
|
69
|
+
TEST_INPUT,
|
|
70
|
+
);
|
|
71
|
+
return output;
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
// Validate output structure
|
|
75
|
+
expect(result).toBeDefined();
|
|
76
|
+
expect(typeof result).toBe("object");
|
|
77
|
+
const typedResult = result;
|
|
78
|
+
// Verify success wrapper structure
|
|
79
|
+
expect(typedResult).toHaveProperty("success");
|
|
80
|
+
expect(typedResult).toHaveProperty("data");
|
|
81
|
+
expect(typedResult.success).toBe(true);
|
|
82
|
+
// Verify data content
|
|
83
|
+
expect(typedResult.data).toHaveProperty("results");
|
|
84
|
+
expect(typedResult.data).toHaveProperty("count");
|
|
85
|
+
expect(Array.isArray(typedResult.data.results)).toBe(true);
|
|
86
|
+
expect(typedResult.data.count).toBe(2); // Should match the limit we set
|
|
87
|
+
expect(typedResult.data.results).toHaveLength(2);
|
|
88
|
+
// Verify results contain processed query
|
|
89
|
+
expect(typedResult.data.results[0]).toHaveProperty("id");
|
|
90
|
+
expect(typedResult.data.results[0]).toHaveProperty("content");
|
|
91
|
+
expect(typedResult.data.results[0].content).toContain(
|
|
92
|
+
"test query for processing",
|
|
93
|
+
);
|
|
94
|
+
expect(typedResult.data.results[1].content).toContain(
|
|
95
|
+
"test query for processing",
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
it("should handle plugin lifecycle correctly", async () => {
|
|
99
|
+
await runtime.runPromise(
|
|
100
|
+
Effect.gen(function* () {
|
|
101
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
102
|
+
// Test individual lifecycle steps
|
|
103
|
+
// 1. Load plugin
|
|
104
|
+
const pluginConstructor =
|
|
105
|
+
yield* pluginRuntime.loadPlugin("test-plugin");
|
|
106
|
+
expect(pluginConstructor).toBeDefined();
|
|
107
|
+
expect(pluginConstructor.metadata.pluginId).toBe("test-plugin");
|
|
108
|
+
// 2. Instantiate plugin
|
|
109
|
+
const pluginInstance =
|
|
110
|
+
yield* pluginRuntime.instantiatePlugin(pluginConstructor);
|
|
111
|
+
expect(pluginInstance).toBeDefined();
|
|
112
|
+
expect(pluginInstance.plugin).toBeDefined();
|
|
113
|
+
expect(pluginInstance.metadata.pluginId).toBe("test-plugin");
|
|
114
|
+
// 3. Initialize plugin
|
|
115
|
+
const initializedPlugin = yield* pluginRuntime.initializePlugin(
|
|
116
|
+
pluginInstance,
|
|
117
|
+
TEST_CONFIG,
|
|
118
|
+
);
|
|
119
|
+
expect(initializedPlugin).toBeDefined();
|
|
120
|
+
expect(initializedPlugin.config).toBeDefined();
|
|
121
|
+
// 4. Execute plugin
|
|
122
|
+
const output = yield* pluginRuntime.executePlugin(
|
|
123
|
+
initializedPlugin,
|
|
124
|
+
TEST_INPUT,
|
|
125
|
+
);
|
|
126
|
+
expect(output).toBeDefined();
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
it("should handle secret hydration", async () => {
|
|
131
|
+
const configWithSecrets = {
|
|
132
|
+
variables: {
|
|
133
|
+
baseUrl: "http://localhost:1337",
|
|
134
|
+
timeout: 10000,
|
|
135
|
+
},
|
|
136
|
+
secrets: {
|
|
137
|
+
apiKey: "{{API_KEY}}", // This should be hydrated
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
const secretsConfig = {
|
|
141
|
+
API_KEY: "hydrated-api-key-value",
|
|
142
|
+
};
|
|
143
|
+
const runtime = createPluginRuntime({
|
|
144
|
+
registry: TEST_REGISTRY,
|
|
145
|
+
secrets: secretsConfig,
|
|
146
|
+
});
|
|
147
|
+
await runtime.runPromise(
|
|
148
|
+
Effect.gen(function* () {
|
|
149
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
150
|
+
const initializedPlugin = yield* pluginRuntime.usePlugin(
|
|
151
|
+
"test-plugin",
|
|
152
|
+
configWithSecrets,
|
|
153
|
+
);
|
|
154
|
+
// Verify secrets were hydrated in the config
|
|
155
|
+
expect(initializedPlugin.config).toBeDefined();
|
|
156
|
+
// Verify the config structure and that secrets were hydrated
|
|
157
|
+
const config = initializedPlugin.config;
|
|
158
|
+
expect(config).toHaveProperty("secrets");
|
|
159
|
+
expect(config.secrets).toHaveProperty("apiKey");
|
|
160
|
+
expect(config.secrets.apiKey).toBe("hydrated-api-key-value");
|
|
161
|
+
// Verify variables are also present
|
|
162
|
+
expect(config).toHaveProperty("variables");
|
|
163
|
+
expect(config.variables.baseUrl).toBe("http://localhost:1337");
|
|
164
|
+
expect(config.variables.timeout).toBe(10000);
|
|
165
|
+
// Verify the plugin was successfully initialized with hydrated secrets
|
|
166
|
+
// by executing it to ensure it works with the hydrated config
|
|
167
|
+
const output = yield* pluginRuntime.executePlugin(
|
|
168
|
+
initializedPlugin,
|
|
169
|
+
TEST_INPUT,
|
|
170
|
+
);
|
|
171
|
+
expect(output).toBeDefined();
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
});
|
|
175
|
+
it("should handle validation error for missing apiKey", async () => {
|
|
176
|
+
const configWithoutApiKey = {
|
|
177
|
+
variables: {
|
|
178
|
+
baseUrl: "http://localhost:1337",
|
|
179
|
+
timeout: 5000,
|
|
180
|
+
},
|
|
181
|
+
secrets: {
|
|
182
|
+
// Missing required apiKey
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
const result = await runtime.runPromise(
|
|
186
|
+
Effect.gen(function* () {
|
|
187
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
188
|
+
return yield* pluginRuntime
|
|
189
|
+
.usePlugin("test-plugin", configWithoutApiKey)
|
|
190
|
+
.pipe(
|
|
191
|
+
Effect.catchTag("PluginRuntimeError", (error) => {
|
|
192
|
+
// Should catch validation error
|
|
193
|
+
expect(error.operation).toBe("validate-config");
|
|
194
|
+
expect(error.retryable).toBe(false);
|
|
195
|
+
expect(error.pluginId).toBe("test-plugin");
|
|
196
|
+
expect(error.cause).toBeDefined();
|
|
197
|
+
// The error should mention the missing apiKey
|
|
198
|
+
const errorMessage = error.cause?.message || "";
|
|
199
|
+
// Zod validation errors might be in JSON format, so check for both formats
|
|
200
|
+
const lowerMessage = errorMessage.toLowerCase();
|
|
201
|
+
const hasApiKeyError =
|
|
202
|
+
lowerMessage.includes("api key") ||
|
|
203
|
+
lowerMessage.includes("apikey") ||
|
|
204
|
+
lowerMessage.includes("required");
|
|
205
|
+
expect(hasApiKeyError).toBe(true);
|
|
206
|
+
console.debug("Caught expected validation error:", {
|
|
207
|
+
operation: error.operation,
|
|
208
|
+
pluginId: error.pluginId,
|
|
209
|
+
retryable: error.retryable,
|
|
210
|
+
cause: error.cause?.message,
|
|
211
|
+
});
|
|
212
|
+
return Effect.succeed("validation-error-handled-properly");
|
|
213
|
+
}),
|
|
214
|
+
Effect.catchAll((unexpectedError) => {
|
|
215
|
+
console.error("Unexpected error type:", unexpectedError);
|
|
216
|
+
expect.fail(
|
|
217
|
+
`Expected PluginRuntimeError but got: ${unexpectedError._tag || typeof unexpectedError}`,
|
|
218
|
+
);
|
|
219
|
+
return Effect.succeed("should-not-reach-here");
|
|
220
|
+
}),
|
|
221
|
+
);
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
expect(result).toBe("validation-error-handled-properly");
|
|
225
|
+
});
|
|
226
|
+
it("should handle runtime shutdown gracefully", async () => {
|
|
227
|
+
const runtime = createPluginRuntime({
|
|
228
|
+
registry: TEST_REGISTRY,
|
|
229
|
+
secrets: SECRETS_CONFIG,
|
|
230
|
+
});
|
|
231
|
+
await runtime.runPromise(
|
|
232
|
+
Effect.gen(function* () {
|
|
233
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
234
|
+
// Test shutdown
|
|
235
|
+
yield* pluginRuntime.shutdown();
|
|
236
|
+
// Shutdown should complete without errors
|
|
237
|
+
expect(true).toBe(true); // If we reach here, shutdown was successful
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
it("should handle invalid remoteUrl with proper error handling", async () => {
|
|
242
|
+
const result = await runtime.runPromise(
|
|
243
|
+
Effect.gen(function* () {
|
|
244
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
245
|
+
return yield* pluginRuntime.usePlugin("invalid-plugin", {}).pipe(
|
|
246
|
+
Effect.catchTag("PluginRuntimeError", (error) => {
|
|
247
|
+
expect(error.operation).toBe("register-remote");
|
|
248
|
+
expect(error.retryable).toBe(true);
|
|
249
|
+
expect(error.pluginId).toBe("invalid-plugin");
|
|
250
|
+
expect(error.cause).toBeDefined();
|
|
251
|
+
console.debug("Caught expected PluginRuntimeError:", {
|
|
252
|
+
operation: error.operation,
|
|
253
|
+
pluginId: error.pluginId,
|
|
254
|
+
retryable: error.retryable,
|
|
255
|
+
cause: error.cause?.message,
|
|
256
|
+
});
|
|
257
|
+
return Effect.succeed("error-handled-properly");
|
|
258
|
+
}),
|
|
259
|
+
Effect.catchAll((unexpectedError) => {
|
|
260
|
+
// If any other error type is thrown, fail the test
|
|
261
|
+
console.error("Unexpected error type:", unexpectedError);
|
|
262
|
+
expect.fail(
|
|
263
|
+
`Expected PluginRuntimeError but got: ${unexpectedError._tag || typeof unexpectedError}`,
|
|
264
|
+
);
|
|
265
|
+
return Effect.succeed("should-not-reach-here");
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
}),
|
|
269
|
+
);
|
|
270
|
+
expect(result).toBe("error-handled-properly");
|
|
271
|
+
});
|
|
272
|
+
it("should handle plugin not found in registry", async () => {
|
|
273
|
+
// Empty registry to test missing plugin
|
|
274
|
+
const EMPTY_REGISTRY = {};
|
|
275
|
+
const runtime = createPluginRuntime({
|
|
276
|
+
registry: EMPTY_REGISTRY,
|
|
277
|
+
secrets: {},
|
|
278
|
+
});
|
|
279
|
+
const result = await runtime.runPromise(
|
|
280
|
+
Effect.gen(function* () {
|
|
281
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
282
|
+
return yield* pluginRuntime.loadPlugin("non-existent-plugin").pipe(
|
|
283
|
+
Effect.catchTag("PluginRuntimeError", (error) => {
|
|
284
|
+
// Validate error properties
|
|
285
|
+
expect(error.operation).toBe("load-plugin");
|
|
286
|
+
expect(error.retryable).toBe(false);
|
|
287
|
+
expect(error.pluginId).toBe("non-existent-plugin");
|
|
288
|
+
expect(error.cause).toBeDefined();
|
|
289
|
+
expect(error.cause?.message).toContain("not found in registry");
|
|
290
|
+
// Log error details for debugging
|
|
291
|
+
console.debug(
|
|
292
|
+
"Caught expected PluginRuntimeError for missing plugin:",
|
|
293
|
+
{
|
|
294
|
+
operation: error.operation,
|
|
295
|
+
pluginId: error.pluginId,
|
|
296
|
+
retryable: error.retryable,
|
|
297
|
+
cause: error.cause?.message,
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
// Return success to make test pass
|
|
301
|
+
return Effect.succeed("plugin-not-found-handled-properly");
|
|
302
|
+
}),
|
|
303
|
+
Effect.catchAll((unexpectedError) => {
|
|
304
|
+
// If any other error type is thrown, fail the test
|
|
305
|
+
console.error("Unexpected error type:", unexpectedError);
|
|
306
|
+
expect.fail(
|
|
307
|
+
`Expected PluginRuntimeError but got: ${unexpectedError._tag || typeof unexpectedError}`,
|
|
308
|
+
);
|
|
309
|
+
return Effect.succeed("should-not-reach-here");
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
314
|
+
expect(result).toBe("plugin-not-found-handled-properly");
|
|
315
|
+
});
|
|
316
|
+
it("should handle constructor instantiation failure", async () => {
|
|
317
|
+
// Registry with real remote that should fail during instantiation/initialization
|
|
318
|
+
const REAL_REMOTE_REGISTRY = {
|
|
319
|
+
"simple-transform": {
|
|
320
|
+
remoteUrl:
|
|
321
|
+
"https://unpkg.com/@curatedotfun/simple-transform@latest/dist/remoteEntry.js",
|
|
322
|
+
type: "transformer",
|
|
323
|
+
version: "latest",
|
|
324
|
+
description: "Real remote plugin for testing constructor failure",
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
const runtime = createPluginRuntime({
|
|
328
|
+
registry: REAL_REMOTE_REGISTRY,
|
|
329
|
+
secrets: {},
|
|
330
|
+
});
|
|
331
|
+
const result = await runtime.runPromise(
|
|
332
|
+
Effect.gen(function* () {
|
|
333
|
+
const pluginRuntime = yield* PluginRuntime;
|
|
334
|
+
return yield* pluginRuntime.usePlugin("simple-transform", {}).pipe(
|
|
335
|
+
Effect.timeout(Duration.seconds(1)), // Timeout after 3 seconds
|
|
336
|
+
Effect.catchTag("PluginRuntimeError", (error) => {
|
|
337
|
+
// Validate error properties
|
|
338
|
+
expect(["load-remote"]).toContain(error.operation);
|
|
339
|
+
expect(error.retryable).toBe(false);
|
|
340
|
+
expect(error.pluginId).toBe("simple-transform");
|
|
341
|
+
expect(error.cause).toBeDefined();
|
|
342
|
+
// Log error details for debugging
|
|
343
|
+
console.debug(
|
|
344
|
+
"Caught expected PluginRuntimeError for constructor failure:",
|
|
345
|
+
{
|
|
346
|
+
operation: error.operation,
|
|
347
|
+
pluginId: error.pluginId,
|
|
348
|
+
retryable: error.retryable,
|
|
349
|
+
cause: error.cause?.message,
|
|
350
|
+
},
|
|
351
|
+
);
|
|
352
|
+
// Return success to make test pass
|
|
353
|
+
return Effect.succeed("constructor-failure-handled-properly");
|
|
354
|
+
}),
|
|
355
|
+
Effect.catchTag("TimeoutException", () => {
|
|
356
|
+
// Handle timeout as expected failure - remote is too slow
|
|
357
|
+
console.debug(
|
|
358
|
+
"Plugin creation timed out - treating as expected failure",
|
|
359
|
+
);
|
|
360
|
+
return Effect.succeed("timeout-handled-properly");
|
|
361
|
+
}),
|
|
362
|
+
Effect.catchAll((unexpectedError) => {
|
|
363
|
+
// If any other error type is thrown, fail the test
|
|
364
|
+
console.error("Unexpected error type:", unexpectedError);
|
|
365
|
+
expect.fail(
|
|
366
|
+
`Expected PluginRuntimeError or TimeoutException but got: ${unexpectedError._tag || typeof unexpectedError}`,
|
|
367
|
+
);
|
|
368
|
+
return Effect.succeed("should-not-reach-here");
|
|
369
|
+
}),
|
|
370
|
+
);
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
373
|
+
expect([
|
|
374
|
+
"constructor-failure-handled-properly",
|
|
375
|
+
"timeout-handled-properly",
|
|
376
|
+
]).toContain(result);
|
|
377
|
+
});
|
|
308
378
|
});
|