forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtargets.ts
More file actions
396 lines (355 loc) · 11.8 KB
/
Copy pathtargets.ts
File metadata and controls
396 lines (355 loc) · 11.8 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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
import path from "node:path";
import fs from "node:fs";
import yaml from "js-yaml";
import type { LocalConfig } from "./config.js";
import { getPackageUrl } from "./config.js";
export type TestLevel = "smoke" | "d4" | "d5" | "d6" | "all";
export interface TestTarget {
slug: string;
/** Undefined means all demos for this slug. */
demo?: string;
level: TestLevel;
}
/**
* Manifest shape — subset of each integration's manifest.yaml that the
* CLI consumes. The full manifest has many more fields (category, logo,
* partner_docs, etc.) that aren't relevant for local test execution.
*/
interface Manifest {
slug: string;
name: string;
demos: Array<{ id: string; features?: string[] }>;
features?: string[];
/**
* Features the integration's framework architecturally cannot support
* (e.g. lacks graph-interrupt API). Propagated to D6 driver inputs so
* the harness reclassifies probe failures on these features as
* `skipped-incapable` instead of counting them as red.
*/
not_supported_features?: string[];
deployed?: boolean;
}
// ---------------------------------------------------------------------------
// Driver input types — these match the Zod inputSchema shapes declared in
// the actual probe drivers so the CLI can construct valid inputs without
// going through the driver module (which may pull in Playwright, etc.).
// ---------------------------------------------------------------------------
/**
* Liveness (smoke) driver input — mirrors the `discoverySmokeInputSchema`
* branch in `src/probes/drivers/liveness.ts`. The CLI always uses the
* discovery shape (key + name + publicUrl) rather than the static shape
* (key + url) because local port mapping naturally produces a base URL,
* not a full `/smoke` endpoint path.
*/
export interface SmokeInput {
key: string;
name: string;
publicUrl: string;
shape: "package";
[k: string]: unknown;
}
/**
* e2e-chat-tools (L4) driver input — mirrors the `inputSchema` in
* `src/probes/drivers/e2e-chat-tools.ts`. `backendUrl` or `publicUrl`
* is required (the schema has a `.refine()` enforcing this). The CLI
* sets `backendUrl` from local-ports and populates `demos` from the
* manifest so the driver knows which demo routes to exercise.
*/
export interface ChatToolsInput {
key: string;
backendUrl: string;
name: string;
demos: string[];
shape: "package";
[k: string]: unknown;
}
/**
* e2e-deep (D5) driver input — mirrors the `inputSchema` in
* `src/probes/drivers/e2e-deep.ts`. `backendUrl` or `publicUrl` is
* required. The CLI sets `backendUrl` from local-ports and populates
* `demos` from the manifest's top-level `features` array (registry IDs
* that the driver maps to D5 feature types via `demosToFeatureTypes()`).
*/
export interface DeepInput {
key: string;
backendUrl: string;
name: string;
demos: string[];
shape: "package";
}
/**
* e2e-full (D6) driver input — mirrors the `inputSchema` in
* `src/probes/drivers/e2e-full.ts`. Same shape as D5 (uses `demos`
* field) and runs ALL features (no sampling).
*/
export interface FullInput {
key: string;
backendUrl: string;
name: string;
demos: string[];
/**
* Manifest `not_supported_features` set — forwarded so the driver
* reclassifies failing probes on these features as `skipped-incapable`
* instead of red. Empty/undefined when the manifest omits the field.
*/
notSupportedFeatures?: string[];
shape: "package";
}
// ---------------------------------------------------------------------------
// Parsing & resolution
// ---------------------------------------------------------------------------
/**
* Parse a raw target string like `"crewai-crews"` or
* `"crewai-crews:agentic-chat"` into slug + optional demo.
*/
export function parseTarget(raw: string): { slug: string; demo?: string } {
const idx = raw.indexOf(":");
if (idx === -1) {
return { slug: raw };
}
return {
slug: raw.slice(0, idx),
demo: raw.slice(idx + 1) || undefined,
};
}
/** Return all slugs that have a local port mapping. */
export function listAvailableSlugs(config: LocalConfig): string[] {
return Object.keys(config.localPorts);
}
/**
* Load and parse an integration's manifest.yaml. Looks under
* `showcase/integrations/<slug>/manifest.yaml` first, then falls back
* to the legacy `showcase/packages/<slug>/manifest.yaml` path.
*/
export function loadManifest(slug: string, config: LocalConfig): Manifest {
const integrationsPath = path.join(
config.showcaseDir,
"integrations",
slug,
"manifest.yaml",
);
const packagesPath = path.join(
config.showcaseDir,
"packages",
slug,
"manifest.yaml",
);
let manifestPath: string;
if (fs.existsSync(integrationsPath)) {
manifestPath = integrationsPath;
} else if (fs.existsSync(packagesPath)) {
manifestPath = packagesPath;
} else {
throw new Error(
`Manifest not found for slug "${slug}". Checked:\n ${integrationsPath}\n ${packagesPath}`,
);
}
const raw = fs.readFileSync(manifestPath, "utf-8");
const parsed = yaml.load(raw, { schema: yaml.JSON_SCHEMA });
if (!parsed || typeof parsed !== "object") {
throw new Error(`Invalid manifest for ${slug}: expected YAML mapping`);
}
const manifest = parsed as Record<string, unknown>;
if (typeof manifest.slug !== "string") {
throw new Error(`Manifest for ${slug} missing required "slug" field`);
}
if (Array.isArray(manifest.demos)) {
for (const demo of manifest.demos) {
if (
typeof demo !== "object" ||
demo === null ||
typeof (demo as Record<string, unknown>).id !== "string"
) {
throw new Error(
`Invalid demo entry in manifest for ${slug}: each demo must have a string "id" field`,
);
}
}
}
if (manifest.features !== undefined && !Array.isArray(manifest.features)) {
throw new Error(
`Invalid "features" in manifest for ${slug}: expected array`,
);
}
if (
manifest.not_supported_features !== undefined &&
!Array.isArray(manifest.not_supported_features)
) {
throw new Error(
`Invalid "not_supported_features" in manifest for ${slug}: expected array`,
);
}
return {
slug: manifest.slug as string,
name: (manifest.name as string) ?? slug,
demos: Array.isArray(manifest.demos)
? (manifest.demos as Array<{ id: string; features?: string[] }>)
: [],
features: Array.isArray(manifest.features)
? (manifest.features as string[])
: undefined,
not_supported_features: Array.isArray(manifest.not_supported_features)
? (manifest.not_supported_features as string[])
: undefined,
deployed: manifest.deployed as boolean | undefined,
};
}
// ---------------------------------------------------------------------------
// Driver input builders
// ---------------------------------------------------------------------------
/**
* Build smoke (liveness) driver inputs for the given target.
*/
export function buildSmokeInputs(
target: TestTarget,
config: LocalConfig,
): SmokeInput[] {
const slugs = [target.slug];
return slugs.map((slug) => {
void loadManifest(slug, config); // ensures the slug is real
// The driver's `deriveSlug` for discovery-mode inputs takes
// `input.name` and strips a leading `showcase-` prefix. In production
// discovery `name` is the Railway service name (`showcase-<slug>`),
// so the derived slug matches the rest of the row keyspace
// (`smoke:<slug>`, `health:<slug>`, etc.). The CLI was previously
// passing `manifest.name` (the display name like "LangGraph (Python)")
// which stripped to itself, producing rows like
// `health:LangGraph (Python)` that didn't join with anything else
// on the dashboard. Use the showcase-prefixed slug shape to mirror
// production.
return {
key: `smoke:${slug}`,
name: `showcase-${slug}`,
publicUrl: getPackageUrl(slug, config),
shape: "package" as const,
};
});
}
/**
* Build e2e-chat-tools (L4) driver inputs. Reads each manifest to
* populate the `demos` array so the driver knows which demo routes to
* exercise. When `target.demo` is set, filters to just that demo.
*/
export function buildChatToolsInputs(
target: TestTarget,
config: LocalConfig,
): ChatToolsInput[] {
const slugs = [target.slug];
return slugs.map((slug) => {
const manifest = loadManifest(slug, config);
let demoIds = manifest.demos.map((d) => d.id);
if (target.demo) {
demoIds = demoIds.filter((id) => id === target.demo);
if (demoIds.length === 0) {
const available = manifest.demos.map((d) => d.id).join(", ");
throw new Error(
`Demo "${target.demo}" not found in ${slug}. Available: ${available}`,
);
}
}
return {
key: `d4:${slug}`,
backendUrl: getPackageUrl(slug, config),
name: manifest.name,
demos: demoIds,
shape: "package" as const,
};
});
}
/**
* Build e2e-deep (D5) driver inputs. Reads the manifest's top-level
* `features` array. When `target.demo` is set, filters features to
* just that demo ID (the features list in the manifest uses the same
* identifiers as demo IDs).
*/
export function buildDeepInputs(
target: TestTarget,
config: LocalConfig,
): DeepInput[] {
const slugs = [target.slug];
return slugs
.map((slug) => {
const manifest = loadManifest(slug, config);
let features = manifest.features ?? [];
if (target.demo) {
features = features.filter((f) => f === target.demo);
if (features.length === 0) {
const available = (manifest.features ?? []).join(", ");
throw new Error(
`Feature "${target.demo}" not found in ${slug}. Available: ${available}`,
);
}
}
return {
key: `d5-single-pill-e2e:${slug}`,
backendUrl: getPackageUrl(slug, config),
name: manifest.name,
demos: features,
shape: "package" as const,
};
})
.filter((input) => input.demos.length > 0);
}
/**
* Build e2e-full (D6) driver inputs. Same as D5 but uses the `d6:` key
* prefix and passes ALL features (no representative filter). When
* `target.demo` is set, filters features to just that demo ID.
*/
export function buildFullInputs(
target: TestTarget,
config: LocalConfig,
): FullInput[] {
const slugs = [target.slug];
return slugs
.map((slug) => {
const manifest = loadManifest(slug, config);
let features = manifest.features ?? [];
if (target.demo) {
features = features.filter((f) => f === target.demo);
if (features.length === 0) {
const available = (manifest.features ?? []).join(", ");
throw new Error(
`Feature "${target.demo}" not found in ${slug}. Available: ${available}`,
);
}
}
return {
key: `d6:${slug}`,
backendUrl: getPackageUrl(slug, config),
name: manifest.name,
demos: features,
notSupportedFeatures: manifest.not_supported_features,
shape: "package" as const,
};
})
.filter((input) => input.demos.length > 0);
}
/**
* Parse a raw target string, expand `"all"` to every slug with a local
* port mapping, and return a `TestTarget[]`.
*/
export function resolveTargets(
raw: string,
level: TestLevel,
config: LocalConfig,
): TestTarget[] {
const { slug, demo } = parseTarget(raw);
if (slug === "all" && demo) {
throw new Error(
'Cannot specify a demo filter with target "all". Use a specific slug instead.',
);
}
if (slug === "all") {
return listAvailableSlugs(config).map((s) => ({
slug: s,
level,
}));
}
// Validate the slug has a port mapping.
if (!config.localPorts[slug]) {
throw new Error(
`Unknown slug "${slug}". Available: ${listAvailableSlugs(config).join(", ")}`,
);
}
return [{ slug, demo, level }];
}