feat: export e2e tests for a chosen scenario version
CI / changes (pull_request) Successful in 14s
CI / server (pull_request) Successful in 2m25s
CI / client (pull_request) Successful in 1m35s
CI / image (pull_request) Skipped

- GET /scenarios/:id/export-e2e and the export_e2e_test MCP tool take
  an optional version, defaulting to the latest
- build the test project from that version's steps, name and timeout
- put the version in the zip name (<scenario>-vN-e2e-test.zip), the
  generated package name and the README heading
- the Export e2e test button exports the version being viewed
- document the e2e export in scenario.md and mcp.md
This commit is contained in:
ars9 committed 2026-10-08 18:37:33 +03:00
1 parent 14763103cf
commit 81164f8494
8 files changed
+102 -17

No files matched your search

+9 -3
View File
@@ -1343,15 +1343,21 @@ export class McpService {
"export_e2e_test",
{
description:
"Export a scenario as a standalone, plug-and-play Playwright e2e test project (package.json, playwright.config.ts, test.spec.ts, .env), zipped and returned as base64",
"Export one version of a scenario as a standalone, plug-and-play Playwright e2e test project (package.json, playwright.config.ts, test.spec.ts, .env), zipped and returned as base64",
inputSchema: {
id: z.uuid().describe("Scenario ID to export"),
version: z
.number()
.int()
.min(1)
.optional()
.describe("Scenario version to export. Defaults to the latest"),
},
},
async ({ id }) => {
async ({ id, version }) => {
try {
const { filename, buffer } =
await this.e2eExportService.buildE2eTestPackage(id);
await this.e2eExportService.buildE2eTestPackage(id, version);
return {
content: [
{
+16 -8
View File
@@ -42,8 +42,16 @@ export class E2eExportService {
private readonly snippetService: SnippetService,
) {}
async buildE2eTestPackage(scenarioId: string): Promise<{ filename: string; buffer: Buffer }> {
/** Builds the package for the latest version, or `version` when given. */
async buildE2eTestPackage(
scenarioId: string,
version?: number,
): Promise<{ filename: string; buffer: Buffer }> {
const scenario = await this.scenarioService.findOne(scenarioId);
const content = await this.scenarioService.findVersion(
scenarioId,
version ?? scenario.version,
);
const [credentialMap, snippetMap, attachedFiles] = await Promise.all([
this.scenarioService.buildCredentialMap(scenarioId),
this.snippetService.buildSnippetMap(),
@@ -51,10 +59,10 @@ export class E2eExportService {
]);
const envData = scenario.environment?.data ?? {};
const slug = slugify(scenario.name);
const slug = `${slugify(content.name)}-v${content.version}`;
const files: Record<string, string | Buffer> = {
"package.json": this.buildPackageJson(slug),
"playwright.config.ts": this.buildPlaywrightConfig(scenario.timeoutSeconds),
"playwright.config.ts": this.buildPlaywrightConfig(content.timeoutSeconds),
".env": this.buildEnvFile(envData),
"credentials.json": JSON.stringify(credentialMap, null, 2) + "\n",
".gitignore": [
@@ -65,7 +73,7 @@ export class E2eExportService {
".env",
"credentials.json",
].join("\n") + "\n",
"README.md": this.buildReadme(scenario.name, scenario.description),
"README.md": this.buildReadme(content.name, content.version, content.description),
};
// Bundle any files attached to the scenario so getScenarioFiles works offline.
@@ -97,7 +105,7 @@ export class E2eExportService {
// Bundle only the snippets actually referenced (directly or transitively via
// other snippets) by this scenario's steps, as individual .js files under snippets/.
const usedAliases = resolveUsedSnippetAliases(
scenario.steps.map((s) => s.execCode ?? ""),
content.steps.map((s) => s.execCode ?? ""),
snippetMap,
);
const snippetManifest: { alias: string; filename: string }[] = [];
@@ -116,7 +124,7 @@ export class E2eExportService {
snippetManifest.push({ alias, filename });
}
files["test.spec.ts"] = this.buildTestSpec(scenario, snippetManifest, fileManifest);
files["test.spec.ts"] = this.buildTestSpec(content, snippetManifest, fileManifest);
const buffer = await this.zip(files);
return { filename: `${slug}-e2e-test.zip`, buffer };
@@ -173,9 +181,9 @@ export default defineConfig({
);
}
private buildReadme(scenarioName: string, description: string | null): string {
private buildReadme(scenarioName: string, version: number, description: string | null): string {
const descriptionSection = description?.trim() ? `${description.trim()}\n\n` : "";
return `# ${scenarioName} - standalone e2e test
return `# ${scenarioName} (v${version}) - standalone e2e test
${descriptionSection}## Setup
+7 -2
View File
@@ -203,12 +203,17 @@ export class ScenarioController {
summary: "Export a scenario as a standalone, plug-and-play Playwright e2e test (zip)",
})
@ApiResponse({ status: 200, description: "Zip archive" })
@ApiResponse({ status: 404, description: "Scenario not found" })
@ApiResponse({ status: 404, description: "Scenario or version not found" })
async exportE2eTest(
@Param("id", ParseUUIDPipe) id: string,
@Query("version", new ParseIntPipe({ optional: true }))
version: number | undefined,
@Res() res: Response,
) {
const { filename, buffer } = await this.e2eExportService.buildE2eTestPackage(id);
const { filename, buffer } = await this.e2eExportService.buildE2eTestPackage(
id,
version,
);
res.setHeader("Content-Type", "application/zip");
res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
res.setHeader("Content-Length", buffer.length);