@flowspec-qa/runner 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.
Files changed (42) hide show
  1. package/dist/commands/auth.d.ts +3 -0
  2. package/dist/commands/auth.d.ts.map +1 -0
  3. package/dist/commands/auth.js +61 -0
  4. package/dist/commands/auth.js.map +1 -0
  5. package/dist/commands/doctor.d.ts +3 -0
  6. package/dist/commands/doctor.d.ts.map +1 -0
  7. package/dist/commands/doctor.js +126 -0
  8. package/dist/commands/doctor.js.map +1 -0
  9. package/dist/commands/mcp-server.d.ts +3 -0
  10. package/dist/commands/mcp-server.d.ts.map +1 -0
  11. package/dist/commands/mcp-server.js +115 -0
  12. package/dist/commands/mcp-server.js.map +1 -0
  13. package/dist/commands/projects.d.ts +3 -0
  14. package/dist/commands/projects.d.ts.map +1 -0
  15. package/dist/commands/projects.js +30 -0
  16. package/dist/commands/projects.js.map +1 -0
  17. package/dist/commands/results.d.ts +3 -0
  18. package/dist/commands/results.d.ts.map +1 -0
  19. package/dist/commands/results.js +31 -0
  20. package/dist/commands/results.js.map +1 -0
  21. package/dist/commands/run.d.ts +3 -0
  22. package/dist/commands/run.d.ts.map +1 -0
  23. package/dist/commands/run.js +124 -0
  24. package/dist/commands/run.js.map +1 -0
  25. package/dist/commands/suites.d.ts +3 -0
  26. package/dist/commands/suites.d.ts.map +1 -0
  27. package/dist/commands/suites.js +40 -0
  28. package/dist/commands/suites.js.map +1 -0
  29. package/dist/index.d.ts +3 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +23 -0
  32. package/dist/index.js.map +1 -0
  33. package/package.json +25 -0
  34. package/src/commands/auth.ts +65 -0
  35. package/src/commands/doctor.ts +134 -0
  36. package/src/commands/mcp-server.ts +140 -0
  37. package/src/commands/projects.ts +31 -0
  38. package/src/commands/results.ts +34 -0
  39. package/src/commands/run.ts +142 -0
  40. package/src/commands/suites.ts +41 -0
  41. package/src/index.ts +26 -0
  42. package/tsconfig.json +8 -0
@@ -0,0 +1,40 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import { table } from 'table';
5
+ import { FlowSpecQAApi } from '@flowspec-qa/runner-core';
6
+ export function suitesCommand() {
7
+ const cmd = new Command('suites').description('Manage test suites');
8
+ cmd
9
+ .command('list')
10
+ .description('List available suites from FlowSpecQA')
11
+ .option('-e, --entity <entityId>', 'Filter by entity ID (e.g. HU-012)')
12
+ .action(async (opts) => {
13
+ const spinner = ora('Fetching suites...').start();
14
+ try {
15
+ const suites = await FlowSpecQAApi.listSuites(opts.entity);
16
+ spinner.stop();
17
+ if (suites.length === 0) {
18
+ console.log(chalk.yellow('No suites found. Generate automation code in FlowSpecQA first.'));
19
+ return;
20
+ }
21
+ const rows = [
22
+ [chalk.bold('Entity'), chalk.bold('Status'), chalk.bold('Mode'), chalk.bold('Suite ID')],
23
+ ...suites.map((s) => [
24
+ chalk.cyan(s.entity_id),
25
+ chalk.green(s.status ?? '—'),
26
+ chalk.magenta(s.mode ?? '—'),
27
+ chalk.dim(s.suite_id?.slice(0, 8) + '...'),
28
+ ]),
29
+ ];
30
+ console.log(table(rows));
31
+ console.log(chalk.dim(`Use 'flowspecqa run --suite <suite_id> --env <env>' to execute.`));
32
+ }
33
+ catch (err) {
34
+ spinner.fail(chalk.red(`✗ ${err.message}`));
35
+ process.exit(1);
36
+ }
37
+ });
38
+ return cmd;
39
+ }
40
+ //# sourceMappingURL=suites.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suites.js","sourceRoot":"","sources":["../../src/commands/suites.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,UAAU,aAAa;IAC3B,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;IAEpE,GAAG;SACA,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CAAC,uCAAuC,CAAC;SACpD,MAAM,CAAC,yBAAyB,EAAE,mCAAmC,CAAC;SACtE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACrB,MAAM,OAAO,GAAG,GAAG,CAAC,oBAAoB,CAAC,CAAC,KAAK,EAAE,CAAC;QAClD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC3D,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,gEAAgE,CAAC,CAAC,CAAC;gBAC5F,OAAO;YACT,CAAC;YACD,MAAM,IAAI,GAAG;gBACX,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACxF,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC;oBACxB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;oBACvB,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,CAAC;oBAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,CAAC;oBAC5B,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;iBAC3C,CAAC;aACH,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,iEAAiE,CAAC,CAAC,CAAC;QAC5F,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { authCommand } from './commands/auth.js';
4
+ import { projectsCommand } from './commands/projects.js';
5
+ import { suitesCommand } from './commands/suites.js';
6
+ import { runCommand } from './commands/run.js';
7
+ import { resultsCommand } from './commands/results.js';
8
+ import { mcpServerCommand } from './commands/mcp-server.js';
9
+ import { doctorCommand } from './commands/doctor.js';
10
+ const program = new Command();
11
+ program
12
+ .name('flowspecqa')
13
+ .description('FlowSpecQA Runner — download, execute, and upload test suites')
14
+ .version('0.1.0');
15
+ program.addCommand(authCommand());
16
+ program.addCommand(projectsCommand());
17
+ program.addCommand(suitesCommand());
18
+ program.addCommand(runCommand());
19
+ program.addCommand(resultsCommand());
20
+ program.addCommand(mcpServerCommand());
21
+ program.addCommand(doctorCommand());
22
+ program.parse(process.argv);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CAAC,+DAA+D,CAAC;KAC5E,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;AAClC,OAAO,CAAC,UAAU,CAAC,eAAe,EAAE,CAAC,CAAC;AACtC,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,CAAC;AACpC,OAAO,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC;AACrC,OAAO,CAAC,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;AACvC,OAAO,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC,CAAC;AAEpC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@flowspec-qa/runner",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "FlowSpecQA Runner CLI — download, execute, and upload test suites",
6
+ "bin": {
7
+ "flowspecqa": "dist/index.js",
8
+ "flowspec_runner": "dist/index.js"
9
+ },
10
+ "main": "dist/index.js",
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig.json",
13
+ "dev": "tsx src/index.ts",
14
+ "start": "node dist/index.js"
15
+ },
16
+ "dependencies": {
17
+ "@flowspec-qa/runner-core": "*",
18
+ "commander": "^12.0.0",
19
+ "inquirer": "^9.2.0",
20
+ "ora": "^8.0.1",
21
+ "chalk": "^5.3.0",
22
+ "table": "^6.8.1",
23
+ "@modelcontextprotocol/sdk": "^1.0.0"
24
+ }
25
+ }
@@ -0,0 +1,65 @@
1
+ import { Command } from 'commander';
2
+ import inquirer from 'inquirer';
3
+ import ora from 'ora';
4
+ import chalk from 'chalk';
5
+ import { login, logout, getAuthStatus, config } from '@flowspec-qa/runner-core';
6
+
7
+ export function authCommand(): Command {
8
+ const cmd = new Command('auth').description('Manage FlowSpecQA authentication');
9
+
10
+ cmd
11
+ .command('login')
12
+ .description('Authenticate with a FlowSpecQA API Key')
13
+ .option('-k, --key <apiKey>', 'API Key (or will be prompted)')
14
+ .option('--url <baseUrl>', 'FlowSpecQA SaaS base URL (default: https://api.flowspecqa.com)')
15
+ .action(async (opts) => {
16
+ if (opts.url) config.set('baseUrl', opts.url);
17
+
18
+ let apiKey = opts.key as string | undefined;
19
+ if (!apiKey) {
20
+ const ans = await inquirer.prompt([{
21
+ type: 'password',
22
+ name: 'apiKey',
23
+ message: 'Paste your FlowSpecQA API Key:',
24
+ mask: '*',
25
+ validate: (v: string) => v.length > 8 || 'API Key too short',
26
+ }]);
27
+ apiKey = ans.apiKey as string;
28
+ }
29
+
30
+ const spinner = ora('Authenticating...').start();
31
+ try {
32
+ await login(apiKey);
33
+ spinner.succeed(chalk.green('✓ Authenticated successfully'));
34
+ console.log(chalk.dim(` Config saved to: ${config.configPath}`));
35
+ } catch (err: any) {
36
+ spinner.fail(chalk.red(`✗ Authentication failed: ${err.message}`));
37
+ process.exit(1);
38
+ }
39
+ });
40
+
41
+ cmd
42
+ .command('logout')
43
+ .description('Remove stored credentials')
44
+ .action(() => {
45
+ logout();
46
+ console.log(chalk.yellow('Logged out. Credentials removed.'));
47
+ });
48
+
49
+ cmd
50
+ .command('status')
51
+ .description('Show current authentication status')
52
+ .action(() => {
53
+ const status = getAuthStatus();
54
+ if (!status.authenticated) {
55
+ console.log(chalk.red('✗ Not authenticated'));
56
+ console.log(chalk.dim(' Run: flowspecqa auth login --key <API_KEY>'));
57
+ return;
58
+ }
59
+ console.log(chalk.green('✓ Authenticated'));
60
+ console.log(` Key: ${chalk.cyan(status.maskedKey)}`);
61
+ console.log(` URL: ${chalk.dim(config.get('baseUrl'))}`);
62
+ });
63
+
64
+ return cmd;
65
+ }
@@ -0,0 +1,134 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { execa } from 'execa';
4
+ import { config } from '@flowspec-qa/runner-core';
5
+ import { apiClient } from '@flowspec-qa/runner-core';
6
+
7
+ interface Check {
8
+ label: string;
9
+ ok: boolean;
10
+ detail: string;
11
+ }
12
+
13
+ export function doctorCommand(): Command {
14
+ return new Command('doctor')
15
+ .description('Check that your environment is ready to run tests')
16
+ .action(async () => {
17
+ console.log(chalk.bold('\n🩺 FlowSpecQA Runner — Diagnostics\n'));
18
+ const checks: Check[] = [];
19
+
20
+ // 1. Node version
21
+ try {
22
+ const { stdout } = await execa('node', ['--version']);
23
+ const major = parseInt(stdout.replace('v', '').split('.')[0], 10);
24
+ const ok = major >= 18;
25
+ checks.push({
26
+ label: 'Node.js',
27
+ ok,
28
+ detail: ok ? `${stdout.trim()} ✓` : `${stdout.trim()} — se requiere v18 o superior`,
29
+ });
30
+ } catch {
31
+ checks.push({ label: 'Node.js', ok: false, detail: 'No encontrado — instálalo desde nodejs.org' });
32
+ }
33
+
34
+ // 2. npm
35
+ try {
36
+ const { stdout } = await execa('npm', ['--version']);
37
+ checks.push({ label: 'npm', ok: true, detail: `v${stdout.trim()} ✓` });
38
+ } catch {
39
+ checks.push({ label: 'npm', ok: false, detail: 'No encontrado' });
40
+ }
41
+
42
+ // 3. Playwright chromium browser
43
+ try {
44
+ const { stdout } = await execa('npx', ['playwright', '--version'], { reject: false });
45
+ const hasCr = stdout.includes('Version') || stdout.includes('playwright');
46
+ checks.push({
47
+ label: 'Playwright',
48
+ ok: hasCr,
49
+ detail: hasCr ? stdout.trim().split('\n')[0] + ' ✓' : 'No instalado — ejecuta: npx playwright install chromium',
50
+ });
51
+ } catch {
52
+ checks.push({
53
+ label: 'Playwright',
54
+ ok: false,
55
+ detail: 'No encontrado — ejecuta: npx playwright install chromium',
56
+ });
57
+ }
58
+
59
+ // 4. API Key configured
60
+ const apiKey = config.get('apiKey') as string | undefined;
61
+ const hasKey = !!apiKey && apiKey.startsWith('sk-smrt-');
62
+ checks.push({
63
+ label: 'API Key',
64
+ ok: hasKey,
65
+ detail: hasKey
66
+ ? `${apiKey!.slice(0, 12)}**** ✓`
67
+ : 'No configurada — ejecuta: flowspecqa auth login --url <URL> --key <TU_API_KEY>',
68
+ });
69
+
70
+ // 5. Base URL configured
71
+ const baseUrl = config.get('baseUrl') as string | undefined;
72
+ const hasUrl = !!baseUrl;
73
+ checks.push({
74
+ label: 'URL del servidor',
75
+ ok: hasUrl,
76
+ detail: hasUrl ? `${baseUrl} ✓` : 'No configurada',
77
+ });
78
+
79
+ // 6. Connectivity to FlowSpecQA SaaS
80
+ if (hasKey && hasUrl) {
81
+ try {
82
+ await apiClient.get('/api/config/projects');
83
+ checks.push({ label: 'Conectividad al servidor', ok: true, detail: `${baseUrl} responde ✓` });
84
+ } catch (err: any) {
85
+ checks.push({
86
+ label: 'Conectividad al servidor',
87
+ ok: false,
88
+ detail: `No se puede conectar a ${baseUrl} — ${err.message}`,
89
+ });
90
+ }
91
+ } else {
92
+ checks.push({ label: 'Conectividad al servidor', ok: false, detail: 'Requiere API Key configurada' });
93
+ }
94
+
95
+ // 7. Suite cache dir writable
96
+ const cacheDir = config.get('suiteCacheDir') as string;
97
+ try {
98
+ const fs = await import('fs');
99
+ fs.mkdirSync(cacheDir, { recursive: true });
100
+ checks.push({ label: 'Carpeta de caché', ok: true, detail: `${cacheDir} ✓` });
101
+ } catch {
102
+ checks.push({ label: 'Carpeta de caché', ok: false, detail: `No se puede escribir en ${cacheDir}` });
103
+ }
104
+
105
+ // 8. Maestro CLI (optional but needed for mobile)
106
+ try {
107
+ const { stdout } = await execa('maestro', ['--version']);
108
+ checks.push({ label: 'Maestro CLI', ok: true, detail: `v${stdout.trim()} ✓` });
109
+ } catch {
110
+ checks.push({
111
+ label: 'Maestro CLI',
112
+ ok: false,
113
+ detail: 'No encontrado — opcional, instalar para tests móviles: curl -Ls "https://get.maestro.mobile.dev" | bash',
114
+ });
115
+ }
116
+
117
+ // Print results
118
+ for (const c of checks) {
119
+ const icon = c.ok ? chalk.green('✔') : chalk.red('✖');
120
+ const label = chalk.bold(c.label.padEnd(25));
121
+ console.log(` ${icon} ${label} ${c.ok ? chalk.dim(c.detail) : chalk.yellow(c.detail)}`);
122
+ }
123
+
124
+ const failed = checks.filter((c) => !c.ok);
125
+ console.log('');
126
+ if (failed.length === 0) {
127
+ console.log(chalk.green.bold(' ✅ Todo en orden — puedes ejecutar tests.'));
128
+ } else {
129
+ console.log(chalk.red(` ❌ ${failed.length} problema(s) encontrado(s). Revisa los items marcados arriba.`));
130
+ process.exit(1);
131
+ }
132
+ console.log('');
133
+ });
134
+ }
@@ -0,0 +1,140 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
4
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
5
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
6
+ import {
7
+ FlowSpecQAApi,
8
+ downloadSuite,
9
+ executePlaywright,
10
+ executeCypress,
11
+ executeMaestro,
12
+ uploadResults,
13
+ } from '@flowspec-qa/runner-core';
14
+ import type { TestResultItem } from '@flowspec-qa/runner-core';
15
+
16
+
17
+ export function mcpServerCommand(): Command {
18
+ return new Command('mcp-server')
19
+ .description('Start a local MCP server exposing runner tools to AI agents (Cursor, Claude, etc.)')
20
+ .action(async () => {
21
+ const server = new Server(
22
+ { name: 'flowspecqa-runner', version: '0.1.0' },
23
+ { capabilities: { tools: {} } }
24
+ );
25
+
26
+ // ── Tool Definitions ─────────────────────────────────────────────────
27
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
28
+ tools: [
29
+ {
30
+ name: 'list_suites',
31
+ description: 'List test suites available in FlowSpecQA for a project or entity.',
32
+ inputSchema: {
33
+ type: 'object',
34
+ properties: {
35
+ entity_id: { type: 'string', description: 'Filter by entity ID (e.g. HU-012)' },
36
+ },
37
+ },
38
+ },
39
+ {
40
+ name: 'run_suite',
41
+ description: 'Download, execute locally, and upload results for a test suite. Client credentials stay local.',
42
+ inputSchema: {
43
+ type: 'object',
44
+ required: ['entity_id'],
45
+ properties: {
46
+ entity_id: { type: 'string', description: 'Entity ID to run (e.g. HU-012)' },
47
+ env_label: { type: 'string', description: 'Environment label (staging, qa, local)', default: 'local' },
48
+ base_url: { type: 'string', description: 'Base URL of the application under test (stays local, not uploaded)' },
49
+ grep: { type: 'string', description: 'Only run tests matching this pattern' },
50
+ skip_upload: { type: 'boolean', description: 'Execute without uploading results', default: false },
51
+ },
52
+ },
53
+ },
54
+ {
55
+ name: 'get_run_status',
56
+ description: 'Get the QA triage status of a test execution from FlowSpecQA.',
57
+ inputSchema: {
58
+ type: 'object',
59
+ required: ['entity_id'],
60
+ properties: {
61
+ entity_id: { type: 'string' },
62
+ },
63
+ },
64
+ },
65
+ ],
66
+ }));
67
+
68
+ // ── Tool Handlers ─────────────────────────────────────────────────────
69
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
70
+ const { name, arguments: args } = req.params;
71
+
72
+ // list_suites
73
+ if (name === 'list_suites') {
74
+ const suites = await FlowSpecQAApi.listSuites((args as any)?.entity_id);
75
+ return {
76
+ content: [{
77
+ type: 'text',
78
+ text: JSON.stringify(suites, null, 2),
79
+ }],
80
+ };
81
+ }
82
+
83
+ // run_suite
84
+ if (name === 'run_suite') {
85
+ const a = args as any;
86
+ const suites = await FlowSpecQAApi.listSuites(a.entity_id);
87
+ if (suites.length === 0) {
88
+ return { content: [{ type: 'text', text: `No suites found for entity: ${a.entity_id}` }] };
89
+ }
90
+ const suite = suites[0];
91
+ const local = await downloadSuite(suite.suite_id!, a.entity_id, suite.framework);
92
+
93
+ const envVars: Record<string, string> = {};
94
+ if (a.base_url) envVars['BASE_URL'] = a.base_url;
95
+
96
+ const fw = suite.framework ?? 'playwright_ts';
97
+ const execution = fw === 'cypress'
98
+ ? await executeCypress(local.suiteDir, { env: envVars, grepPattern: a.grep })
99
+ : fw === 'maestro'
100
+ ? await executeMaestro(local.suiteDir, { env: envVars, grepPattern: a.grep })
101
+ : await executePlaywright(local.suiteDir, { env: envVars, grepPattern: a.grep });
102
+
103
+ const summary = {
104
+ total: execution.results.length,
105
+ passed: execution.results.filter((r: TestResultItem) => r.status === 'pass').length,
106
+ failed: execution.results.filter((r: TestResultItem) => r.status === 'fail').length,
107
+ exec_id: null as string | null,
108
+ };
109
+
110
+
111
+ if (!a.skip_upload) {
112
+ const { execId } = await uploadResults(execution, {
113
+ runId: suite.suite_id!,
114
+ entityId: a.entity_id,
115
+ framework: suite.framework,
116
+ envLabel: a.env_label ?? 'local',
117
+ });
118
+ summary.exec_id = execId;
119
+ }
120
+
121
+
122
+ return { content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }] };
123
+ }
124
+
125
+ // get_run_status
126
+ if (name === 'get_run_status') {
127
+ const a = args as any;
128
+ const suites = await FlowSpecQAApi.listSuites(a.entity_id);
129
+ return { content: [{ type: 'text', text: JSON.stringify(suites, null, 2) }] };
130
+ }
131
+
132
+ return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true };
133
+ });
134
+
135
+ // Start MCP server over stdio
136
+ const transport = new StdioServerTransport();
137
+ await server.connect(transport);
138
+ console.error(chalk.dim('[flowspecqa-runner MCP server started on stdio]'));
139
+ });
140
+ }
@@ -0,0 +1,31 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { table } from 'table';
4
+ import { FlowSpecQAApi } from '@flowspec-qa/runner-core';
5
+
6
+ export function projectsCommand(): Command {
7
+ const cmd = new Command('projects').description('Manage projects');
8
+
9
+ cmd
10
+ .command('list')
11
+ .description('List all projects accessible with your API Key')
12
+ .action(async () => {
13
+ try {
14
+ const projects = await FlowSpecQAApi.listProjects();
15
+ if (projects.length === 0) {
16
+ console.log(chalk.yellow('No projects found.'));
17
+ return;
18
+ }
19
+ const rows = [
20
+ [chalk.bold('ID'), chalk.bold('Name'), chalk.bold('Entities')],
21
+ ...projects.map((p: any) => [chalk.cyan(p.id.slice(0, 8) + '...'), p.name, String(p.entity_count ?? '—')]),
22
+ ];
23
+ console.log(table(rows));
24
+ } catch (err: any) {
25
+ console.error(chalk.red(`✗ ${err.message}`));
26
+ process.exit(1);
27
+ }
28
+ });
29
+
30
+ return cmd;
31
+ }
@@ -0,0 +1,34 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import { table } from 'table';
4
+ import { listCachedSuites, evictSuite } from '@flowspec-qa/runner-core';
5
+
6
+ export function resultsCommand(): Command {
7
+ const cmd = new Command('results').description('Manage local results and cached suites');
8
+
9
+ cmd
10
+ .command('cache')
11
+ .description('List locally cached suites')
12
+ .action(() => {
13
+ const cached = listCachedSuites();
14
+ if (cached.length === 0) {
15
+ console.log(chalk.dim('No suites cached locally.'));
16
+ return;
17
+ }
18
+ const rows = [
19
+ [chalk.bold('Entity'), chalk.bold('Run ID'), chalk.bold('Path')],
20
+ ...cached.map((c: any) => [chalk.cyan(c.entityId), chalk.dim(c.runId.slice(0, 8) + '...'), chalk.dim(c.suiteDir)]),
21
+ ];
22
+ console.log(table(rows));
23
+ });
24
+
25
+ cmd
26
+ .command('evict <entityId> <runId>')
27
+ .description('Remove a cached suite from local disk')
28
+ .action((entityId: string, runId: string) => {
29
+ evictSuite(entityId, runId);
30
+ console.log(chalk.green(`✓ Evicted suite ${runId.slice(0, 8)}... for entity ${entityId}`));
31
+ });
32
+
33
+ return cmd;
34
+ }
@@ -0,0 +1,142 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import inquirer from 'inquirer';
5
+ import {
6
+ FlowSpecQAApi,
7
+ downloadSuite,
8
+ executePlaywright,
9
+ executeCypress,
10
+ executeMaestro,
11
+ uploadResults,
12
+ type TestResultItem,
13
+ } from '@flowspec-qa/runner-core';
14
+
15
+
16
+
17
+ export function runCommand(): Command {
18
+ const cmd = new Command('run')
19
+ .description('Download, execute, and upload a test suite')
20
+ .requiredOption('-e, --entity <entityId>', 'Entity ID (e.g. HU-012)')
21
+ .option('--env <label>', 'Environment label (e.g. staging, qa)', 'local')
22
+ .option('--base-url <url>', 'Base URL for the application under test')
23
+ .option('--workers <n>', 'Number of parallel test workers', '4')
24
+ .option('--headed', 'Run browser in headed mode', false)
25
+ .option('--grep <pattern>', 'Only run tests matching this pattern')
26
+ .option('--skip-upload', 'Execute locally without uploading results', false)
27
+ .option('--skip-security-check', 'Skip secret-detection before upload', false)
28
+ .action(async (opts) => {
29
+
30
+ // Step 1: Fetch available suites for entity
31
+ let spinner = ora('Fetching suite info...').start();
32
+ let suites;
33
+ try {
34
+ suites = await FlowSpecQAApi.listSuites(opts.entity);
35
+ spinner.stop();
36
+ } catch (err: any) {
37
+ spinner.fail(chalk.red(`✗ ${err.message}`));
38
+ process.exit(1);
39
+ }
40
+
41
+ if (suites.length === 0) {
42
+ console.log(chalk.yellow(`No suites found for entity: ${opts.entity}. Generate automation code in FlowSpecQA first.`));
43
+ process.exit(0);
44
+ }
45
+
46
+ // If multiple suites, let user pick
47
+ let suite = suites[0];
48
+ if (suites.length > 1) {
49
+ const ans = await inquirer.prompt([{
50
+ type: 'list',
51
+ name: 'suite',
52
+ message: 'Multiple suites available — pick one:',
53
+ choices: suites.map((s: any) => ({
54
+ name: `${s.entity_id} | ${s.mode ?? 'mixed'} | ${s.status ?? 'DRAFT'} | id: ${s.suite_id?.slice(0, 8)}`,
55
+ value: s,
56
+ })),
57
+ }]);
58
+ suite = ans.suite;
59
+ }
60
+
61
+ // Step 2: Download suite ZIP (use suite_id = TestSuite.id)
62
+ spinner = ora(`Downloading suite ${suite.suite_id?.slice(0, 8)}...`).start();
63
+ let local;
64
+ try {
65
+ local = await downloadSuite(suite.suite_id, opts.entity, suite.framework ?? 'playwright');
66
+ spinner.succeed(`Suite ready: ${chalk.dim(local.suiteDir)}`);
67
+ } catch (err: any) {
68
+ spinner.fail(chalk.red(`✗ Download failed: ${err.message}`));
69
+ process.exit(1);
70
+ }
71
+
72
+ // Step 3: Build env vars — client secrets stay local, never uploaded
73
+ const envVars: Record<string, string> = { ...process.env } as Record<string, string>;
74
+ if (opts.baseUrl) envVars['BASE_URL'] = opts.baseUrl;
75
+
76
+ // Step 4: Execute
77
+ spinner = ora(`Executing ${suite.framework ?? 'playwright'} tests (env: ${opts.env})...`).start();
78
+ let execution;
79
+ try {
80
+ const execOpts = {
81
+ env: envVars,
82
+ workers: parseInt(opts.workers, 10),
83
+ headed: opts.headed,
84
+ grepPattern: opts.grep,
85
+ };
86
+ const fw = suite.framework ?? 'playwright_ts';
87
+ execution = fw === 'cypress'
88
+ ? await executeCypress(local.suiteDir, execOpts)
89
+ : fw === 'maestro'
90
+ ? await executeMaestro(local.suiteDir, execOpts)
91
+ : await executePlaywright(local.suiteDir, execOpts);
92
+
93
+
94
+ const passed = execution.results.filter((r: TestResultItem) => r.status === 'pass').length;
95
+ const failed = execution.results.filter((r: TestResultItem) => r.status === 'fail').length;
96
+
97
+ const total = execution.results.length;
98
+ spinner.succeed(`Executed: ${chalk.green(passed + ' pass')} / ${chalk.red(failed + ' fail')} / ${total} total`);
99
+ } catch (err: any) {
100
+ spinner.fail(chalk.red(`✗ Execution error: ${err.message}`));
101
+ process.exit(1);
102
+ }
103
+
104
+ if (opts.skipUpload) {
105
+ console.log(chalk.yellow('\nSkipping upload (--skip-upload). Results not sent to FlowSpecQA.'));
106
+ printSummary(execution.results);
107
+ return;
108
+ }
109
+
110
+ // Step 5: Upload sanitized results (run_id = suite_id for traceability)
111
+ spinner = ora('Uploading sanitized results to FlowSpecQA...').start();
112
+ try {
113
+ const { execId } = await uploadResults(execution, {
114
+ runId: suite.suite_id, // use suite_id as the run reference
115
+ entityId: opts.entity,
116
+ framework: suite.framework ?? 'playwright',
117
+ envLabel: opts.env,
118
+ skipSecurityCheck: opts.skipSecurityCheck,
119
+ });
120
+ spinner.succeed(`Results uploaded — exec_id: ${chalk.cyan(execId)}`);
121
+ console.log(chalk.dim(`\nView results at: https://www.flowspecqa.com/results/${execId}`));
122
+ } catch (err: any) {
123
+ spinner.fail(chalk.red(`✗ Upload failed: ${err.message}`));
124
+ process.exit(1);
125
+ }
126
+
127
+ printSummary(execution.results);
128
+ });
129
+
130
+ return cmd;
131
+ }
132
+
133
+ function printSummary(results: Array<{ name: string; status: string; error?: string | null }>) {
134
+ const failed = results.filter((r: any) => r.status === 'fail');
135
+ if (failed.length > 0) {
136
+ console.log(chalk.red(`\n✗ ${failed.length} failing test(s):`));
137
+ for (const f of failed) {
138
+ console.log(` • ${chalk.yellow(f.name)}`);
139
+ if (f.error) console.log(` ${chalk.dim(f.error.split('\n')[0])}`);
140
+ }
141
+ }
142
+ }