@qcentriq/mcp 0.4.5 → 0.5.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 (3) hide show
  1. package/README.md +7 -7
  2. package/dist/index.js +119 -55
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -14,7 +14,7 @@ Connect your AI coding assistants (**Cursor**, **Claude Desktop**, **VS Code Cli
14
14
  - **Remote Cloud Discovery & Diagnostics**: Instantly query test cases, groups, run logs, failure stack traces, and environment variables via authenticated REST client endpoints.
15
15
  - **Local Playwright Test Execution**: Safely execute tests locally with `pytest` without triggering unwanted cloud runners. Supports headless and headed modes across Chromium, Firefox, and WebKit.
16
16
  - **Smart Environment Setup**: Probes installed local Python package managers (`uv`, `poetry`, `conda`, or standard `venv`) and generates ready-to-run setup commands (prefers `uv` for lightning-fast setup).
17
- - **Direct Workspace Script Saving**: Download test scripts and their helper files into a dedicated `qcentriq_tests/` workspace directory (kept apart from your own `tests/`, so an existing `conftest.py` is never overwritten). Before each local run there, `qcentriq_run_local_test` refreshes the `conftest.py` QCentriq cloud runs use with path traversal protections.
17
+ - **Direct Workspace Script Saving**: Download test scripts and their helper files, nested folders included, into a per-group `qcentriq_tests/<group_id>/` workspace directory (kept apart from your own `tests/`, so an existing `conftest.py` is never overwritten). Before each local run there, `qcentriq_run_local_test` refreshes the `conftest.py` QCentriq cloud runs use with path traversal protections.
18
18
  - **Zero-Leak Redaction**: Automatically filters all outgoing tool payloads, masking API keys (`qc_...`), bearer tokens, and URL credentials before sending them to the LLM.
19
19
  - **Strict Stdio Isolation**: Protocol JSON-RPC frames communicate cleanly over `stdout`, while all diagnostic logs route to `stderr`.
20
20
 
@@ -240,7 +240,7 @@ The QCentriq MCP Server cleanly separates **remote cloud discovery/diagnostics**
240
240
  | `qcentriq_list_tests` | Discover test cases and test groups with status, priority, and update timestamps. Script availability is highlighted. | `project_id` *(uuid)*, `group_id` *(uuid)*, `priority` *("low"\|"medium"\|"high"\|"critical")*, `test_type` *("web"\|"api"\|"mobile")*, `limit` *(int)*, `offset` *(int)* |
241
241
  | `qcentriq_get_test` | Retrieve full test case definitions, step descriptions, preconditions, latest execution diagnostics, and error stack traces. | `test_case_id` *(uuid, required)*, `project_id` *(uuid)* |
242
242
  | `qcentriq_get_test_groups` | Discover and inspect test groups, member test cases, test counts, and script availability. | `project_id` *(uuid)*, `group_id` *(uuid)*, `limit` *(int)*, `offset` *(int)* |
243
- | `qcentriq_download_script` | Download Playwright Python test script and its helper files and save them to `./qcentriq_tests/` (the same directory `qcentriq_save_script` uses). Pass `save_to_disk=false` to only return the content. | `group_id` *(uuid, required)*, `project_id` *(uuid)*, `include_fixtures` *(bool, default true)*, `save_to_disk` *(bool, default true)*, `destination_dir` *(string, default "./qcentriq_tests")* |
243
+ | `qcentriq_download_script` | Download a group's Playwright Python test script and its helper files and save them to `./qcentriq_tests/<group_id>/`, each helper at its relative path (e.g. `pages/login_page.py`). Pass `save_to_disk=false` to only return the content. | `group_id` *(uuid, required)*, `project_id` *(uuid)*, `include_fixtures` *(bool, default true)*, `save_to_disk` *(bool, default true)*, `destination_dir` *(string, default "./qcentriq_tests"; the group folder is created inside it)* |
244
244
  | `qcentriq_get_environment` | Retrieve target environment configuration, base URL (`BASE_URL`), environment variables, and required secret variable names for local execution. | `project_id` *(uuid)*, `environment_id` *(uuid)*, `environment_name` *(string)* |
245
245
  | `qcentriq_get_test_run_logs` | Fetch execution history, logs, stdout/stderr, and stack traces across single-case and suite runs. | `test_case_id` *(uuid, required)*, `project_id` *(uuid)*, `run_id` *(uuid)*, `status` *("failed"\|"passed"\|"error")*, `latest_only` *(bool)*, `from_date` *(ISO date)*, `to_date` *(ISO date)*, `limit` *(int)*, `offset` *(int)* |
246
246
 
@@ -254,7 +254,7 @@ Both write tools send to QCentriq as soon as they are called; your MCP client's
254
254
  | :--- | :--- | :--- |
255
255
  | `qcentriq_get_authoring_guide` | Fetch the contract for plans and scripts: the TaskPlan JSON schema, the `${VAR}` environment-variable convention, the `@allure.id` rules, and the available conftest fixtures. Read-only. | — |
256
256
  | `qcentriq_create_plan` | Create test groups and test cases from an authored plan. Returns one UUID per created test case. A case whose flow failed in the browser can be created with `status: "blocked"` and an evidence `block_reason`; QCentriq re-validates it live and keeps it blocked only if it sees the same failure (`block_source` shows `client` until then). **Writes.** | `plan` *(object, required)*, `project_id` *(uuid)* |
257
- | `qcentriq_save_group_script` | Validate and store a test script for a group, replacing the existing one. Every unblocked case in the group must appear exactly once as `@allure.id('<case_id>')`; blocked cases may be left out. Only uploads a script that passed `qcentriq_run_local_test` with this exact content (see [Local pass before upload](#-security--privacy)). Checked against the version from the last download or save of the group in this session, so someone else's newer edit is refused as a conflict instead of overwritten. **Writes.** | `group_id` *(uuid, required)*, `content` *(string, required)*, `project_id` *(uuid)*, `filename` *(string)*, `fixtures` *(array)* |
257
+ | `qcentriq_save_group_script` | Validate and store a test script for a group, replacing the existing one. Every unblocked case in the group must appear exactly once as `@allure.id('<case_id>')`; blocked cases may be left out. Only uploads a script that passed `qcentriq_run_local_test` with this exact content (see [Local pass before upload](#-security--privacy)). Checked against the version from the last download or save of the group in this session, so someone else's newer edit is refused as a conflict instead of overwritten. `fixtures` is the group's complete helper set, each `file_name` relative to the script's folder: helpers left out are deleted, and a save that leaves out a helper still in the folder is refused. **Writes.** | `group_id` *(uuid, required)*, `content` *(string, required)*, `project_id` *(uuid)*, `filename` *(string)*, `fixtures` *(array)* |
258
258
  | `qcentriq_update_test_case` | Edit an existing test case (title, description, priority, preconditions, steps, expected result, target URL) instead of creating a duplicate. Requires `last_updated_at` from `qcentriq_get_test`; a newer edit by someone else is refused as a conflict. Reports `script_stale` when the change means the group script needs updating. Blocked status is not editable. **Writes.** | `test_case_id` *(uuid, required)*, `expected_last_updated_at` *(string, required)*, plus the fields to change, `project_id` *(uuid)* |
259
259
  | `qcentriq_recheck_blocked_case` | Ask QCentriq to re-validate a blocked test case against the live site. QCentriq's own agent decides the verdict: `active` unblocks the case and adds it to the group script (in a group whose script you wrote, you add the test yourself), `blocked` refreshes `block_reason`. The caller cannot set the verdict. Can take several minutes (client timeout 7 min). **Writes.** | `test_case_id` *(uuid, required)*, `project_id` *(uuid)* |
260
260
 
@@ -263,7 +263,7 @@ Both write tools send to QCentriq as soon as they are called; your MCP client's
263
263
  | Tool Name | Description | Key Arguments |
264
264
  | :--- | :--- | :--- |
265
265
  | `qcentriq_get_setup_instructions` | Detect which Python package managers (`uv`, `poetry`, `conda`, `venv`) are installed on the local system and return step-by-step commands to create a virtual environment matching the QCentriq runner container. If none are installed, the steps start by installing `uv`. *(Read-only instructions, never runs commands).* | `preferred_manager` *("uv"\|"poetry"\|"conda"\|"venv")*, `working_dir` *(string)*, `env_name` *(string, default "qcentriq-tests")*, `python_version` *(string, default "3.12")*, `playwright_version` *(string, default "1.56.0")* |
266
- | `qcentriq_save_script` | Save downloaded test scripts and fixtures directly into the local workspace (defaults to `./qcentriq_tests/`) with path traversal guards. | `file_name` *(string, required)*, `content` *(string, required)*, `conftest_content` *(string)*, `destination_dir` *(string, default "./qcentriq_tests")* |
266
+ | `qcentriq_save_script` | Save a test script and its helper files (at their relative paths) directly into the local workspace (defaults to `./qcentriq_tests/`; use `./qcentriq_tests/<group_id>/` for a group) with path traversal guards. | `file_name` *(string, required)*, `content` *(string, required)*, `fixtures` *(array)*, `destination_dir` *(string, default "./qcentriq_tests")* |
267
267
  | `qcentriq_run_local_test` | Run the test locally via `pytest`. Captures stdout, stderr, execution duration, and exit codes without triggering cloud runners. A whole-file pass qualifies that exact script for `qcentriq_save_group_script`. If no Python package manager is installed, it tells you to install `uv` first. | `file_path` *(string, required)*, `test_name` *(string)*, `headless` *(bool, default true)*, `browser` *("chromium"\|"firefox"\|"webkit", default "chromium")*, `base_url` *(url)*, `env_vars` *(record)*, `extra_args` *(array)*, `timeout_seconds` *(int, default 60)*, `working_dir` *(string)* |
268
268
 
269
269
 
@@ -297,15 +297,15 @@ sequenceDiagram
297
297
  AI->>MCP: qcentriq_download_script(group_id="...")
298
298
  MCP->>API: GET /api/v1/mcp-client/groups/{id}/script
299
299
  API-->>MCP: Script & helper files
300
- MCP->>Local: Write qcentriq_tests/test_login.py
300
+ MCP->>Local: Write qcentriq_tests/<group_id>/test_login.py (+ helpers)
301
301
  MCP-->>AI: File paths confirmed
302
302
 
303
303
  AI->>Local: Inspect and update selector in test_login.py
304
- AI->>MCP: qcentriq_run_local_test(file_path="qcentriq_tests/test_login.py", headless=false)
304
+ AI->>MCP: qcentriq_run_local_test(file_path="qcentriq_tests/<group_id>/test_login.py", headless=false)
305
305
  MCP->>Local: Run pytest with Playwright
306
306
  Local-->>MCP: Test result (PASSED)
307
307
  MCP-->>AI: PASSED (exit code 0, 1.42s)
308
- AI->>User: "Fixed selector in qcentriq_tests/test_login.py and verified locally!"
308
+ AI->>User: "Fixed selector in qcentriq_tests/<group_id>/test_login.py and verified locally!"
309
309
  ```
310
310
 
311
311
 
package/dist/index.js CHANGED
@@ -117,24 +117,24 @@ var QCentriqApiClient = class {
117
117
  * Authenticated GET against the QCentriq backend (/api/v1/mcp-client/...).
118
118
  * Undefined and null params are left out of the query string.
119
119
  */
120
- async request(path6, params = {}) {
120
+ async request(path7, params = {}) {
121
121
  const query = new URLSearchParams();
122
122
  for (const [key, value] of Object.entries(params)) {
123
123
  if (value !== void 0 && value !== null) {
124
124
  query.set(key, String(value));
125
125
  }
126
126
  }
127
- return this.call("GET", path6, query);
127
+ return this.call("GET", path7, query);
128
128
  }
129
129
  /**
130
130
  * Authenticated JSON write against the QCentriq backend. `timeoutMs`
131
131
  * overrides the configured timeout for a call known to be slow.
132
132
  */
133
- async send(method, path6, body, opts = {}) {
134
- return this.call(method, path6, void 0, body, opts.timeoutMs);
133
+ async send(method, path7, body, opts = {}) {
134
+ return this.call(method, path7, void 0, body, opts.timeoutMs);
135
135
  }
136
- async call(method, path6, query, body, timeoutMs) {
137
- const cleanPath = path6.startsWith("/") ? path6 : `/${path6}`;
136
+ async call(method, path7, query, body, timeoutMs) {
137
+ const cleanPath = path7.startsWith("/") ? path7 : `/${path7}`;
138
138
  const qs = query?.toString();
139
139
  const url = `${this.config.baseUrl}/api/v1/mcp-client${cleanPath}${qs ? `?${qs}` : ""}`;
140
140
  logger.debug(`[mcp-client] HTTP ${method} ${url}`);
@@ -159,12 +159,12 @@ var QCentriqApiClient = class {
159
159
  * Issue a request that is aborted after the configured timeout, reporting
160
160
  * the timeout as such rather than as a bare AbortError.
161
161
  */
162
- async fetchWithTimeout(method, path6, url, init, timeoutMs) {
162
+ async fetchWithTimeout(method, path7, url, init, timeoutMs) {
163
163
  try {
164
164
  return await fetch(url, { ...init, method, signal: AbortSignal.timeout(timeoutMs) });
165
165
  } catch (err) {
166
166
  if (err?.name === "TimeoutError") {
167
- throw new Error(`${method} ${path6} timed out after ${timeoutMs}ms`);
167
+ throw new Error(`${method} ${path7} timed out after ${timeoutMs}ms`);
168
168
  }
169
169
  throw err;
170
170
  }
@@ -257,30 +257,70 @@ function registerGetTestGroupsTool(server, client, config) {
257
257
 
258
258
  // src/tools/download-script.ts
259
259
  import { z as z5 } from "zod";
260
+ import * as path3 from "path";
260
261
 
261
262
  // src/tools/save-script.ts
262
263
  import { z as z4 } from "zod";
264
+ import * as fs2 from "fs/promises";
265
+ import * as path2 from "path";
266
+
267
+ // src/local/group-files.ts
263
268
  import * as fs from "fs/promises";
264
269
  import * as path from "path";
270
+ var RESERVED_FILE_NAMES = /* @__PURE__ */ new Set(["conftest.py", "qc_inputs.json", "qc_state.json"]);
271
+ var PYTEST_CONFIG_NAMES = /* @__PURE__ */ new Set(["pytest.ini", "pyproject.toml", "tox.ini", "setup.cfg"]);
272
+ var HELPER_EXTENSIONS = /* @__PURE__ */ new Set([".py", ".json", ".txt", ".csv", ".yaml", ".yml", ".ini", ".cfg", ".toml"]);
273
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
274
+ var MAX_GROUP_HELPERS = 20;
275
+ var skippedFolder = (name) => name.startsWith(".") || name === "__pycache__";
276
+ function isGroupHelper(relative) {
277
+ const name = path.basename(relative);
278
+ const topLevel = !relative.includes("/");
279
+ if (topLevel && (name.startsWith("test_") && name.endsWith(".py") || PYTEST_CONFIG_NAMES.has(name))) return false;
280
+ return !RESERVED_FILE_NAMES.has(name) && HELPER_EXTENSIONS.has(path.extname(name).toLowerCase());
281
+ }
282
+ async function listGroupHelpers(dir) {
283
+ const found = [];
284
+ async function walk(relative) {
285
+ for (const entry of await fs.readdir(path.join(dir, relative), { withFileTypes: true })) {
286
+ if (found.length > MAX_GROUP_HELPERS) return;
287
+ const child = relative ? `${relative}/${entry.name}` : entry.name;
288
+ if (entry.isDirectory()) {
289
+ if (!skippedFolder(entry.name) && !(relative === "" && UUID.test(entry.name))) await walk(child);
290
+ } else if (entry.isFile() && isGroupHelper(child)) {
291
+ found.push(child);
292
+ }
293
+ }
294
+ }
295
+ await walk("");
296
+ return found.sort();
297
+ }
298
+ function resolveInside(dir, relative) {
299
+ const root = path.resolve(dir);
300
+ const target = path.resolve(root, relative);
301
+ return target.startsWith(root + path.sep) ? target : null;
302
+ }
303
+
304
+ // src/tools/save-script.ts
265
305
  var DEFAULT_SCRIPT_DIR = "./qcentriq_tests";
266
306
  function registerSaveScriptTool(server) {
267
307
  server.registerTool(
268
308
  "qcentriq_save_script",
269
309
  {
270
- description: "Save downloaded Playwright Python test script and fixtures directly to the local workspace disk so they can be run or edited locally.",
310
+ description: `Save a Playwright Python test script and its helper files to the local workspace so they can be run or edited locally. Keep each group in its own folder, '${DEFAULT_SCRIPT_DIR}/<group_id>/', as qcentriq_download_script does; helpers keep their relative paths there (e.g. 'pages/login_page.py'), with folders created as needed.`,
271
311
  inputSchema: z4.object({
272
312
  file_name: z4.string().describe("Target filename (e.g. 'test_login.py')."),
273
313
  content: z4.string().describe("Python test script source code."),
274
- conftest_content: z4.string().optional().describe("Accompanying conftest.py source code if present."),
275
- destination_dir: z4.string().default(DEFAULT_SCRIPT_DIR).describe(`Destination directory in the local workspace (default '${DEFAULT_SCRIPT_DIR}'). Kept separate from a project's own ./tests so an existing conftest.py is never overwritten.`)
314
+ fixtures: z4.array(z4.object({ file_name: z4.string(), content: z4.string() })).optional().describe("Helper files, each file_name a path relative to destination_dir (e.g. 'pages/login_page.py'). A path leaving destination_dir is refused."),
315
+ destination_dir: z4.string().default(DEFAULT_SCRIPT_DIR).describe(`Destination directory in the local workspace (default '${DEFAULT_SCRIPT_DIR}'; use '${DEFAULT_SCRIPT_DIR}/<group_id>' for a group). Kept separate from a project's own ./tests so an existing conftest.py is never overwritten.`)
276
316
  })
277
317
  },
278
318
  async (args) => {
279
319
  try {
280
- const savedFiles = await saveScriptFiles(args.destination_dir ?? DEFAULT_SCRIPT_DIR, args.file_name, args.content, args.conftest_content);
320
+ const savedFiles = await saveScriptFiles(args.destination_dir, args.file_name, args.content, args.fixtures);
281
321
  return jsonResult({
282
322
  status: "success",
283
- message: `Successfully saved ${savedFiles.length} file(s) to ${path.dirname(savedFiles[0])}`,
323
+ message: `Successfully saved ${savedFiles.length} file(s) to ${path2.dirname(savedFiles[0])}`,
284
324
  saved_files: savedFiles
285
325
  });
286
326
  } catch (err) {
@@ -289,22 +329,26 @@ function registerSaveScriptTool(server) {
289
329
  }
290
330
  );
291
331
  }
292
- async function saveScriptFiles(destinationDir, fileName, content, conftest) {
293
- const safeFileName = path.basename(fileName);
332
+ async function saveScriptFiles(destinationDir, fileName, content, helpers = []) {
333
+ const safeFileName = path2.basename(fileName);
294
334
  if (!safeFileName || safeFileName === "." || safeFileName === "..") {
295
335
  throw new Error(`Invalid file name: "${fileName}"`);
296
336
  }
297
- const targetDir = path.resolve(process.cwd(), destinationDir);
298
- await fs.mkdir(targetDir, { recursive: true });
299
- const scriptPath = path.join(targetDir, safeFileName);
300
- await fs.writeFile(scriptPath, content, "utf-8");
337
+ const targetDir = path2.resolve(process.cwd(), destinationDir);
338
+ const writes = helpers.map((helper) => {
339
+ const helperPath = resolveInside(targetDir, helper.file_name);
340
+ if (!helperPath) throw new Error(`Helper path "${helper.file_name}" leaves ${targetDir}`);
341
+ return { helperPath, content: helper.content };
342
+ });
343
+ await fs2.mkdir(targetDir, { recursive: true });
344
+ const scriptPath = path2.join(targetDir, safeFileName);
345
+ await fs2.writeFile(scriptPath, content, "utf-8");
301
346
  logger.info(`Saved test script to: ${scriptPath}`);
302
347
  const saved = [scriptPath];
303
- if (conftest) {
304
- const conftestPath = path.join(targetDir, "conftest.py");
305
- await fs.writeFile(conftestPath, conftest, "utf-8");
306
- logger.info(`Saved conftest.py to: ${conftestPath}`);
307
- saved.push(conftestPath);
348
+ for (const { helperPath, content: helperContent } of writes) {
349
+ await fs2.mkdir(path2.dirname(helperPath), { recursive: true });
350
+ await fs2.writeFile(helperPath, helperContent, "utf-8");
351
+ saved.push(helperPath);
308
352
  }
309
353
  return saved;
310
354
  }
@@ -314,13 +358,13 @@ function registerDownloadScriptTool(server, client, config, versions) {
314
358
  server.registerTool(
315
359
  "qcentriq_download_script",
316
360
  {
317
- description: `Download test group script and accompanying helper files for local test execution and editing (qcentriq_run_local_test supplies the QCentriq conftest.py). By default the files are written to '${DEFAULT_SCRIPT_DIR}', the same directory qcentriq_save_script uses, and their paths are returned in saved_files.`,
361
+ description: `Download a test group's script and its helper files (page objects, utilities, test data) for local test execution and editing (qcentriq_run_local_test supplies the QCentriq conftest.py). By default they are written to the group's own folder, '${DEFAULT_SCRIPT_DIR}/<group_id>/', each helper at its path relative to that folder (e.g. 'pages/login_page.py'), and their paths are returned in saved_files. Edit and run the script there: qcentriq_save_group_script uploads the folder's complete helper set, and any helper missing from a save is deleted.`,
318
362
  inputSchema: z5.object({
319
363
  group_id: z5.uuid().describe("UUID of the target test group."),
320
364
  project_id: z5.uuid().optional().describe("Optional project UUID (inferred from API key if omitted)."),
321
365
  include_fixtures: z5.boolean().default(true).describe("Whether to retrieve accompanying helper files (default True)."),
322
366
  save_to_disk: z5.boolean().default(true).describe("Saves the downloaded test script and fixtures to destination_dir (default True). Set false to only return the content."),
323
- destination_dir: z5.string().default(DEFAULT_SCRIPT_DIR).describe(`Destination directory when save_to_disk is true (default '${DEFAULT_SCRIPT_DIR}'). Kept separate from a project's own ./tests so an existing conftest.py is never overwritten.`)
367
+ destination_dir: z5.string().default(DEFAULT_SCRIPT_DIR).describe(`Directory the group's folder is created in when save_to_disk is true (default '${DEFAULT_SCRIPT_DIR}'); files go to <destination_dir>/<group_id>/. Kept separate from a project's own ./tests so an existing conftest.py is never overwritten.`)
324
368
  })
325
369
  },
326
370
  async (args) => {
@@ -335,8 +379,9 @@ function registerDownloadScriptTool(server, client, config, versions) {
335
379
  }
336
380
  if (data?.script_version) versions.set(args.group_id, data.script_version);
337
381
  if (!args.save_to_disk || !data?.file_name || !data?.content) return jsonResult(data);
382
+ const groupDir = path3.join(args.destination_dir, args.group_id);
338
383
  try {
339
- data.saved_files = await saveScriptFiles(args.destination_dir, data.file_name, data.content, data.conftest_content);
384
+ data.saved_files = await saveScriptFiles(groupDir, data.file_name, data.content, data.fixtures ?? []);
340
385
  return jsonResult(data);
341
386
  } catch (writeErr) {
342
387
  logger.warn(`Failed to write downloaded script to disk: ${writeErr.message}`);
@@ -345,7 +390,7 @@ function registerDownloadScriptTool(server, client, config, versions) {
345
390
  content: [
346
391
  {
347
392
  type: "text",
348
- text: `The script was downloaded but could not be saved to "${args.destination_dir}": ${writeErr.message}. The downloaded content follows; save it with qcentriq_save_script.`
393
+ text: `The script was downloaded but could not be saved to "${groupDir}": ${writeErr.message}. The downloaded content follows; save it with qcentriq_save_script.`
349
394
  },
350
395
  ...jsonResult(data).content
351
396
  ]
@@ -454,8 +499,7 @@ import { z as z10 } from "zod";
454
499
 
455
500
  // src/local/passing-runs.ts
456
501
  import { createHash } from "crypto";
457
- import * as fs2 from "fs/promises";
458
- import * as path2 from "path";
502
+ import * as fs3 from "fs/promises";
459
503
  var PassingRunLedger = class {
460
504
  runs = /* @__PURE__ */ new Map();
461
505
  record(content, run) {
@@ -480,16 +524,16 @@ function reportsPassedTests(stdout) {
480
524
  }
481
525
  async function fixtureMismatch(run, fixtures) {
482
526
  for (const fixture of fixtures) {
483
- const localPath = path2.resolve(run.dir, fixture.file_name);
484
- if (path2.dirname(localPath) !== run.dir) {
485
- return `companion file "${fixture.file_name}" is not a plain file name next to the script`;
527
+ const localPath = resolveInside(run.dir, fixture.file_name);
528
+ if (!localPath) {
529
+ return `companion file "${fixture.file_name}" is not inside the script's folder (${run.dir})`;
486
530
  }
487
531
  let local;
488
532
  let modifiedAt;
489
533
  try {
490
- [local, modifiedAt] = await Promise.all([fs2.readFile(localPath, "utf-8"), fs2.stat(localPath).then((s) => s.mtimeMs)]);
534
+ [local, modifiedAt] = await Promise.all([fs3.readFile(localPath, "utf-8"), fs3.stat(localPath).then((s) => s.mtimeMs)]);
491
535
  } catch {
492
- return `companion file "${fixture.file_name}" was not next to the script (${run.dir}) when it passed`;
536
+ return `companion file "${fixture.file_name}" was not in the script's folder (${run.dir}) when it passed`;
493
537
  }
494
538
  if (local !== fixture.content) {
495
539
  return `companion file "${fixture.file_name}" differs from ${localPath}, which the passing run used`;
@@ -498,13 +542,27 @@ async function fixtureMismatch(run, fixtures) {
498
542
  return `companion file "${fixture.file_name}" changed after the passing run`;
499
543
  }
500
544
  }
545
+ let helpers;
546
+ try {
547
+ helpers = await listGroupHelpers(run.dir);
548
+ } catch {
549
+ return `the script's folder (${run.dir}) can no longer be read`;
550
+ }
551
+ if (helpers.length > MAX_GROUP_HELPERS) {
552
+ return `the script's folder (${run.dir}) holds more than ${MAX_GROUP_HELPERS} helper files; keep each group in its own folder, qcentriq_tests/<group_id>/`;
553
+ }
554
+ const sent = new Set(fixtures.map((f) => f.file_name));
555
+ const missing = helpers.filter((helper) => !sent.has(helper));
556
+ if (missing.length) {
557
+ return `in the script's folder (${run.dir}) but not in fixtures: ${missing.join(", ")}. A save replaces the group's whole helper set, so a helper left out would be deleted from QCentriq; pass every helper in fixtures, or delete the ones the script no longer uses`;
558
+ }
501
559
  return null;
502
560
  }
503
561
 
504
562
  // src/local/environment-setup.ts
505
563
  import { spawn } from "child_process";
506
- import * as fs3 from "fs/promises";
507
- import * as path3 from "path";
564
+ import * as fs4 from "fs/promises";
565
+ import * as path4 from "path";
508
566
  var MANAGER_PRIORITY = ["uv", "poetry", "conda", "venv"];
509
567
  var PROBE_TIMEOUT_MS = 5e3;
510
568
  var DEFAULT_PYTHON_VERSION = "3.12";
@@ -567,7 +625,7 @@ async function probePython() {
567
625
  }
568
626
  async function fileExists(filePath) {
569
627
  try {
570
- await fs3.access(filePath);
628
+ await fs4.access(filePath);
571
629
  return true;
572
630
  } catch {
573
631
  return false;
@@ -584,7 +642,7 @@ async function detectProjectFiles(workingDir) {
584
642
  ];
585
643
  const found = [];
586
644
  for (const candidate of candidates) {
587
- if (await fileExists(path3.join(workingDir, candidate))) {
645
+ if (await fileExists(path4.join(workingDir, candidate))) {
588
646
  found.push(candidate);
589
647
  }
590
648
  }
@@ -735,7 +793,7 @@ function detectActiveEnvironment() {
735
793
  return null;
736
794
  }
737
795
  async function buildEnvironmentSetupPlan(params = {}) {
738
- const workingDir = params.workingDir ? path3.resolve(params.workingDir) : process.cwd();
796
+ const workingDir = params.workingDir ? path4.resolve(params.workingDir) : process.cwd();
739
797
  const [packageManagers, projectFiles] = await Promise.all([detectPackageManagers(), detectProjectFiles(workingDir)]);
740
798
  const availability = new Map(packageManagers.map((m) => [m.name, m.available]));
741
799
  const preferred = params.preferredManager;
@@ -801,18 +859,18 @@ function registerSaveGroupScriptTool(server, client, config, passingRuns, versio
801
859
  server.registerTool(
802
860
  "qcentriq_save_group_script",
803
861
  {
804
- description: "Save a test script you wrote back to QCentriq so the cloud runner executes exactly what you ran locally. Only a script that passed qcentriq_run_local_test as a whole file, with this exact content, is uploaded; each fixture must match the file next to it when it ran. The script is validated before it is stored: valid Python, and every unblocked test case in the group present exactly once as @allure.id('<case_id>') (blocked cases may be left out) \u2014 no duplicates, no ids from other groups. A rejection names the offending id or line so you can correct it. The save is checked against the version from your last qcentriq_download_script (or save) of this group, so if someone else changed the script since, it is refused rather than overwritten; download again, reapply your change and save. conftest.py cannot be saved; QCentriq provides it. Requires the 'test:write' scope.",
862
+ description: "Save a test script you wrote back to QCentriq so the cloud runner executes exactly what you ran locally. Only a script that passed qcentriq_run_local_test as a whole file, with this exact content, is uploaded. Keep the script and its helpers in the group's folder, qcentriq_tests/<group_id>/; helpers may sit in nested folders and are imported normally (e.g. from pages.login_page import LoginPage). Pass every helper in that folder in fixtures, each file_name its path relative to the folder (e.g. 'pages/login_page.py') and matching the file the passing run used: a save replaces the group's whole helper set, so a helper left out is deleted, and a save that leaves out a helper still in the folder is refused. The script is validated before it is stored: valid Python, and every unblocked test case in the group present exactly once as @allure.id('<case_id>') (blocked cases may be left out) \u2014 no duplicates, no ids from other groups. A rejection names the offending id or line so you can correct it. The save is checked against the version from your last qcentriq_download_script (or save) of this group, so if someone else changed the script since, it is refused rather than overwritten; download again, reapply your change and save. conftest.py cannot be saved; QCentriq provides it. Requires the 'test:write' scope.",
805
863
  inputSchema: z10.object({
806
864
  group_id: z10.uuid().describe("UUID of the target test group."),
807
865
  content: z10.string().describe("The Python test script source."),
808
866
  project_id: z10.uuid().optional().describe("Optional project UUID (inferred from the API key if omitted)."),
809
867
  filename: z10.string().optional().describe("Optional script filename; derived from the group title if omitted."),
810
- fixtures: z10.array(z10.object({ file_name: z10.string(), content: z10.string() })).optional().describe("Companion files to store next to the script (page objects, test data). conftest.py is rejected.")
868
+ fixtures: z10.array(z10.object({ file_name: z10.string(), content: z10.string() })).optional().describe("The group's complete helper set (page objects, utilities, test data), each file_name relative to the script's folder, e.g. 'pages/login_page.py'. Replaces every helper stored before. conftest.py is rejected.")
811
869
  }),
812
870
  annotations: {
813
871
  readOnlyHint: false,
814
872
  destructiveHint: true,
815
- // Replaces the group's existing script.
873
+ // Replaces the group's script and its whole helper set.
816
874
  idempotentHint: true,
817
875
  // Saving the same content twice leaves the same state.
818
876
  openWorldHint: false
@@ -934,12 +992,12 @@ function registerUpdateTestCaseTool(server, client, config) {
934
992
 
935
993
  // src/tools/local-run.ts
936
994
  import { z as z13 } from "zod";
937
- import * as fs4 from "fs/promises";
938
- import * as path5 from "path";
995
+ import * as fs5 from "fs/promises";
996
+ import * as path6 from "path";
939
997
 
940
998
  // src/local/runner.ts
941
999
  import { spawn as spawn2 } from "child_process";
942
- import * as path4 from "path";
1000
+ import * as path5 from "path";
943
1001
  function buildTestEnv(params) {
944
1002
  const env = {
945
1003
  ...process.env,
@@ -962,7 +1020,7 @@ function buildTestEnv(params) {
962
1020
  function resolvePytestCommand() {
963
1021
  const venv = process.env.VIRTUAL_ENV;
964
1022
  if (!venv) return "pytest";
965
- return process.platform === "win32" ? path4.join(venv, "Scripts", "pytest.exe") : path4.join(venv, "bin", "pytest");
1023
+ return process.platform === "win32" ? path5.join(venv, "Scripts", "pytest.exe") : path5.join(venv, "bin", "pytest");
966
1024
  }
967
1025
  function killProcessTree(child) {
968
1026
  if (child.pid && process.platform !== "win32") {
@@ -1006,7 +1064,7 @@ function attempt(cmd, args, cwd, env, timeoutMs) {
1006
1064
  }
1007
1065
  async function runLocalPytest(params) {
1008
1066
  const startTime = Date.now();
1009
- const cwd = params.workingDir ? path4.resolve(params.workingDir) : process.cwd();
1067
+ const cwd = params.workingDir ? path5.resolve(params.workingDir) : process.cwd();
1010
1068
  const timeoutSeconds = params.timeoutSeconds || 60;
1011
1069
  const args = [params.filePath];
1012
1070
  if (params.testName) {
@@ -1062,7 +1120,7 @@ function registerLocalRunTool(server, client, passingRuns) {
1062
1120
  server.registerTool(
1063
1121
  "qcentriq_run_local_test",
1064
1122
  {
1065
- description: "Execute a downloaded Playwright/pytest test script locally in the developer's environment. Runs pytest as a local subprocess (in qcentriq_tests/ it first refreshes the conftest.py QCentriq cloud runs use) and returns stdout, stderr, exit code, and test diagnostics without using QCentriq cloud runners. A script must pass here, as a whole file (no test_name or other test filters), before qcentriq_save_group_script will upload it.",
1123
+ description: "Execute a downloaded Playwright/pytest test script locally in the developer's environment. Runs pytest as a local subprocess (in qcentriq_tests/ or any folder below it, it first refreshes the conftest.py QCentriq cloud runs use) and returns stdout, stderr, exit code, and test diagnostics without using QCentriq cloud runners. A script must pass here, as a whole file (no test_name or other test filters), before qcentriq_save_group_script will upload it.",
1066
1124
  inputSchema: z13.object({
1067
1125
  file_path: z13.string().describe("Path to the local test file to run (e.g. 'tests/test_login.py')."),
1068
1126
  test_name: z13.string().optional().describe("Optional specific test function name or expression to run (passed to pytest -k)."),
@@ -1078,10 +1136,10 @@ function registerLocalRunTool(server, client, passingRuns) {
1078
1136
  },
1079
1137
  async (args) => {
1080
1138
  try {
1081
- const scriptPath = path5.resolve(args.working_dir ?? process.cwd(), args.file_path.split("::")[0]);
1082
- const ownDir = path5.basename(path5.dirname(scriptPath)) === path5.basename(DEFAULT_SCRIPT_DIR) ? path5.dirname(scriptPath) : null;
1139
+ const scriptPath = path6.resolve(args.working_dir ?? process.cwd(), args.file_path.split("::")[0]);
1140
+ const ownDir = qcentriqDirAbove(path6.dirname(scriptPath));
1083
1141
  if (ownDir) await refreshConftest(client, ownDir);
1084
- const content = await fs4.readFile(scriptPath, "utf-8").catch(() => null);
1142
+ const content = await fs5.readFile(scriptPath, "utf-8").catch(() => null);
1085
1143
  const startedAt = Date.now();
1086
1144
  const result = await runLocalPytest({
1087
1145
  filePath: args.file_path,
@@ -1095,7 +1153,7 @@ function registerLocalRunTool(server, client, passingRuns) {
1095
1153
  timeoutSeconds: args.timeout_seconds,
1096
1154
  workingDir: args.working_dir
1097
1155
  });
1098
- if (ownDir) await fs4.rm(path5.join(ownDir, "qc_state.json"), { force: true });
1156
+ if (ownDir) await fs5.rm(path6.join(ownDir, "qc_state.json"), { force: true });
1099
1157
  const statusText = result.passed ? "PASSED" : "FAILED";
1100
1158
  const summary = [
1101
1159
  `Local Test Run Result: ${statusText} (exit code ${result.exitCode})`,
@@ -1110,7 +1168,7 @@ function registerLocalRunTool(server, client, passingRuns) {
1110
1168
  ];
1111
1169
  const next = await nextStep(result, args, content !== null);
1112
1170
  if (next.uploadable && content !== null) {
1113
- passingRuns.record(content, { filePath: scriptPath, dir: path5.dirname(scriptPath), startedAt });
1171
+ passingRuns.record(content, { filePath: scriptPath, dir: path6.dirname(scriptPath), startedAt });
1114
1172
  }
1115
1173
  if (next.text) summary.push("", next.text);
1116
1174
  return { isError: !result.passed, content: [{ type: "text", text: summary.join("\n") }] };
@@ -1120,10 +1178,16 @@ function registerLocalRunTool(server, client, passingRuns) {
1120
1178
  }
1121
1179
  );
1122
1180
  }
1181
+ function qcentriqDirAbove(dir) {
1182
+ for (let d = dir; ; d = path6.dirname(d)) {
1183
+ if (path6.basename(d) === path6.basename(DEFAULT_SCRIPT_DIR)) return d;
1184
+ if (path6.dirname(d) === d) return null;
1185
+ }
1186
+ }
1123
1187
  async function refreshConftest(client, dir) {
1124
1188
  try {
1125
1189
  const { content } = await client.request("/conftest");
1126
- await fs4.writeFile(path5.join(dir, "conftest.py"), content, "utf-8");
1190
+ await fs5.writeFile(path6.join(dir, "conftest.py"), content, "utf-8");
1127
1191
  } catch (err) {
1128
1192
  logger.warn(`Could not refresh conftest.py: ${err.message}`);
1129
1193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qcentriq/mcp",
3
- "version": "0.4.5",
3
+ "version": "0.5.0",
4
4
  "description": "Official Model Context Protocol (MCP) server for QCentriq automated test discovery, diagnostics, and execution.",
5
5
  "type": "module",
6
6
  "bin": {