forked from RhysSullivan/executor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresets-reachable.test.ts
More file actions
222 lines (198 loc) · 8.39 KB
/
Copy pathpresets-reachable.test.ts
File metadata and controls
222 lines (198 loc) · 8.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
import { describe, expect, it } from "@effect/vitest";
import { Effect } from "effect";
import { FetchHttpClient } from "@effect/platform";
import { createExecutor, makeTestConfig } from "../packages/core/sdk/src/index";
import { openApiPlugin } from "../packages/plugins/openapi/src/sdk/plugin";
import { parse } from "../packages/plugins/openapi/src/sdk/parse";
import { mcpPlugin } from "../packages/plugins/mcp/src/sdk/plugin";
import { graphqlPlugin } from "../packages/plugins/graphql/src/sdk/plugin";
import { introspect } from "../packages/plugins/graphql/src/sdk/introspect";
import { googleDiscoveryPlugin } from "../packages/plugins/google-discovery/src/sdk/plugin";
import { extractGoogleDiscoveryManifest } from "../packages/plugins/google-discovery/src/sdk/document";
import { openApiPresets } from "../packages/plugins/openapi/src/sdk/presets";
import { mcpPresets } from "../packages/plugins/mcp/src/sdk/presets";
import { graphqlPresets } from "../packages/plugins/graphql/src/sdk/presets";
import { googleDiscoveryPresets } from "../packages/plugins/google-discovery/src/sdk/presets";
// ---------------------------------------------------------------------------
// All presets with plugin metadata
// ---------------------------------------------------------------------------
const allPresets = [
...openApiPresets.map((p) => ({ ...p, plugin: "openapi" as const })),
...mcpPresets.map((p) => ({ ...p, plugin: "mcp" as const })),
...graphqlPresets.map((p) => ({ ...p, plugin: "graphql" as const })),
...googleDiscoveryPresets.map((p) => ({ ...p, plugin: "google-discovery" as const })),
];
// ---------------------------------------------------------------------------
// OpenAPI presets — parse the spec through the SDK
// ---------------------------------------------------------------------------
describe("openapi presets parse as valid specs", () => {
for (const preset of openApiPresets) {
it.effect(
preset.name,
() =>
Effect.gen(function* () {
const doc = yield* parse(preset.url);
expect(doc).toBeDefined();
expect(doc.openapi).toBeDefined();
}),
{ timeout: 30_000 },
);
}
});
// ---------------------------------------------------------------------------
// GraphQL presets — introspect the endpoint (auth-required = 401 is ok)
// ---------------------------------------------------------------------------
describe("graphql presets are reachable endpoints", () => {
for (const preset of graphqlPresets) {
it.effect(
preset.name,
() =>
Effect.gen(function* () {
const result = yield* introspect(preset.url).pipe(
Effect.provide(FetchHttpClient.layer),
Effect.map((r) => ({ ok: true as const, schema: r })),
Effect.catchAll((err) =>
Effect.succeed({
ok: false as const,
message: String(err),
}),
),
);
if (result.ok) {
// Public endpoint — introspection succeeded
expect(result.schema.__schema).toBeDefined();
expect(result.schema.__schema.types.length).toBeGreaterThan(0);
} else {
// Auth-required — should fail with 401/403, not 404/timeout
expect(
result.message,
`${preset.name} should fail with auth error, not: ${result.message}`,
).toMatch(/401|403|Unauthorized|Forbidden|auth/i);
}
}),
{ timeout: 15_000 },
);
}
});
// ---------------------------------------------------------------------------
// MCP presets — probe the endpoint (POST to verify it's alive)
// ---------------------------------------------------------------------------
const remoteMcpPresets = mcpPresets.filter((p) => !("transport" in p && p.transport === "stdio"));
describe("mcp presets are reachable endpoints", () => {
for (const preset of remoteMcpPresets) {
it.effect(
preset.name,
() =>
Effect.gen(function* () {
// Simple POST probe — MCP endpoints reject malformed requests
// but return non-404 status codes proving the service is up
const response = yield* Effect.tryPromise(() =>
fetch(preset.url, {
method: "POST",
signal: AbortSignal.timeout(10_000),
headers: { "Content-Type": "application/json" },
body: "{}",
redirect: "follow",
}),
);
expect(
response.status !== 404 && response.status !== 502 && response.status !== 503,
`${preset.name} returned ${response.status} — endpoint appears down`,
).toBe(true);
}),
{ timeout: 15_000 },
);
}
});
// ---------------------------------------------------------------------------
// Google Discovery presets — parse through the SDK manifest extractor
// ---------------------------------------------------------------------------
describe("google discovery presets parse as valid manifests", () => {
for (const preset of googleDiscoveryPresets) {
it.effect(
preset.name,
() =>
Effect.gen(function* () {
const text = yield* Effect.tryPromise(() =>
fetch(preset.url, { signal: AbortSignal.timeout(10_000) }).then((r) => r.text()),
);
const manifest = yield* extractGoogleDiscoveryManifest(text);
expect(manifest.service).toBeTruthy();
expect(manifest.version).toBeTruthy();
expect(manifest.methods.length).toBeGreaterThan(0);
}),
{ timeout: 15_000 },
);
}
});
// ---------------------------------------------------------------------------
// Detection — full executor pipeline, only for presets that don't need auth
// ---------------------------------------------------------------------------
const publicPresets = allPresets.filter(
(p) =>
// Skip auth-required endpoints that won't pass detection without credentials
!["github-graphql", "linear", "monday", "stripe"].includes(p.id) &&
// Skip stdio presets (not HTTP-reachable)
!("transport" in p && (p as Record<string, unknown>).transport === "stdio") &&
// Skip host-scoped Google Discovery URLs (forms.googleapis.com/$discovery/...)
// — the detector only recognises the central directory pattern today
!["google-forms", "google-keep"].includes(p.id) &&
// Skip endpoints where detection is flaky due to timeout or misdetection
// (these are detect() implementation issues, not preset issues)
!["firecrawl", "gitlab"].includes(p.id),
);
describe("public preset URLs are detected by the correct plugin", () => {
const makeExecutor = () =>
createExecutor(
makeTestConfig({
plugins: [openApiPlugin(), mcpPlugin(), graphqlPlugin(), googleDiscoveryPlugin()] as const,
}),
);
for (const preset of publicPresets) {
it.effect(
`[${preset.plugin}] ${preset.name}`,
() =>
Effect.gen(function* () {
const executor = yield* makeExecutor();
const results = yield* executor.sources.detect(preset.url);
expect(
results.length,
`No detection results for ${preset.name} (${preset.url})`,
).toBeGreaterThan(0);
const expectedKinds: Record<string, string> = {
openapi: "openapi",
mcp: "mcp",
graphql: "graphql",
"google-discovery": "googleDiscovery",
};
const best = results[0]!;
expect(best.kind).toBe(expectedKinds[preset.plugin]);
}),
{ timeout: 30_000 },
);
}
});
// ---------------------------------------------------------------------------
// Icons
// ---------------------------------------------------------------------------
describe("preset icons are reachable", () => {
const presetsWithIcons = allPresets.filter((p) => p.icon);
for (const preset of presetsWithIcons) {
it.effect(
`[${preset.plugin}] ${preset.name} icon`,
() =>
Effect.gen(function* () {
const response = yield* Effect.tryPromise(() =>
fetch(preset.icon!, {
method: "GET",
signal: AbortSignal.timeout(10_000),
headers: { "User-Agent": "executor-preset-test" },
redirect: "follow",
}),
);
expect(response.ok, `${preset.name} icon returned ${response.status}`).toBe(true);
}),
{ timeout: 15_000 },
);
}
});