@msalaam/xray-qe-toolkit 1.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.
package/README.md ADDED
@@ -0,0 +1,893 @@
1
+ # @msalaam/xray-qe-toolkit
2
+
3
+ > Full QE workflow toolkit for Xray Cloud integration — test management, Postman generation, CI pipeline scaffolding, and browser-based review gates.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ - [Overview](#overview)
10
+ - [Prerequisites](#prerequisites)
11
+ - [Installation](#installation)
12
+ - [AI Setup (Optional)](#ai-setup-optional)
13
+ - [Quick Start](#quick-start)
14
+ - [CLI Commands](#cli-commands)
15
+ - [init](#xray-qe-init)
16
+ - [gen-tests](#xray-qe-gen-tests)
17
+ - [edit-json](#xray-qe-edit-json)
18
+ - [push-tests](#xray-qe-push-tests)
19
+ - [gen-postman](#xray-qe-gen-postman)
20
+ - [create-execution](#xray-qe-create-execution)
21
+ - [import-results](#xray-qe-import-results)
22
+ - [gen-pipeline](#xray-qe-gen-pipeline)
23
+ - [mcp-server](#xray-qe-mcp-server)
24
+ - [Configuration](#configuration)
25
+ - [Environment Variables (.env)](#environment-variables-env)
26
+ - [Project Config (.xrayrc)](#project-config-xrayrc)
27
+ - [File Reference](#file-reference)
28
+ - [tests.json](#testsjson)
29
+ - [xray-mapping.json](#xray-mappingjson)
30
+ - [Multi-Company Test Format](#multi-company-test-format)
31
+ - [Jira/Xray Project Setup](#jiraxray-project-setup)
32
+ - [QE Workflow](#qe-workflow)
33
+ - [Building Regression Packs](#building-regression-packs)
34
+ - [Idempotent Push](#idempotent-push)
35
+ - [Programmatic API](#programmatic-api)
36
+ - [Troubleshooting](#troubleshooting)
37
+
38
+ ---
39
+
40
+ ## Overview
41
+
42
+ `@msalaam/xray-qe-toolkit` (XQT) is a modular, CLI-driven toolkit for Xray Cloud and JIRA-based QE workflows. It provides:
43
+
44
+ 1. **`tests.json`** as the single source-of-truth for test logic
45
+ 2. **Browser-based QE review gate** (`edit-json`) for human governance before any push
46
+ 3. **Idempotent push** — updates existing tests, creates new ones, skips duplicates
47
+ 4. **Postman collection generation** from test definitions
48
+ 5. **CI pipeline template** for Azure DevOps (Newman + Xray import)
49
+ 6. **Modular architecture** — every function is importable for programmatic use
50
+ 7. **AI-ready scaffolds** — optional AI assistance for test generation (manual workflow fully supported)
51
+
52
+ ### QE Review Gate Philosophy
53
+
54
+ **The knowledge/ folder is your single source of truth** — OpenAPI specs, requirements docs, JIRA tickets, and business logic live here. The toolkit uses these sources to generate test cases with AI assistance.
55
+
56
+ **Nothing is pushed to Xray until a QE manually reviews and approves** via the `edit-json` command. This ensures quality governance and prevents untested automation from reaching Xray Cloud.
57
+
58
+ ```
59
+ init → populate knowledge/ → gen-tests (AI) → edit-json (QE gate) → push-tests → gen-postman (AI) → CI (run + import)
60
+ ```
61
+
62
+ **Generated tests are scaffolds** — always review and enhance before pushing to Xray.
63
+
64
+ ---
65
+
66
+ ## Prerequisites
67
+
68
+ - **Node.js** >= 18.0.0
69
+ - **npm** >= 8.0.0
70
+ - **Xray Cloud** API Key (from Xray > Settings > API Keys)
71
+ - **JIRA Cloud** API Token (from https://id.atlassian.com/manage-profile/security/api-tokens)
72
+ - Both credentials must belong to the **same JIRA user** (Xray impersonation requirement)
73
+
74
+ ---
75
+
76
+ ## Installation
77
+
78
+ ### From npm (public)
79
+
80
+ ```bash
81
+ # Install as dev dependency
82
+ npm install --save-dev @msalaam/xray-qe-toolkit
83
+ ```
84
+
85
+ ### Verify installation
86
+
87
+ ```bash
88
+ npx xqt --version
89
+ npx xqt --help
90
+ ```
91
+
92
+ ---
93
+
94
+ ## AI Setup (Optional)
95
+
96
+ **AI is completely optional.** The toolkit works fully without AI — you can create and edit tests manually using the `edit-json` UI editor.
97
+
98
+ ### Current AI Status
99
+
100
+ 🚧 **All AI features are scaffolds** — ready for implementation but not yet connected to AI providers.
101
+
102
+ **What's included:**
103
+ - ✅ `--ai` flags in `gen-tests` and `gen-postman` commands
104
+ - ✅ `knowledge/` folder scanner for API specs, requirements, tickets
105
+ - ✅ MCP (Model Context Protocol) server scaffold in `mcp/server.js`
106
+ - ✅ VS Code chat participant extension scaffold in `.vscode/xray-qe-participant/`
107
+ - ❌ **Not included:** Actual AI provider connections (Azure OpenAI, GitHub Copilot, etc.)
108
+
109
+ ### To Enable AI Features (Future)
110
+
111
+ Choose one of three integration paths:
112
+
113
+ #### Option 1: MCP Server (for GitHub Copilot CLI/Desktop)
114
+
115
+ 1. Implement AI provider in `mcp/server.js` (Azure OpenAI, Anthropic, etc.)
116
+ 2. Configure MCP client to connect to toolkit server
117
+ 3. Start server: `npx xqt mcp-server`
118
+ 4. Use `gen-tests --ai` with AI provider connected
119
+
120
+ **Requires:** MCP client setup, AI provider API keys (Azure OpenAI, etc.)
121
+
122
+ #### Option 2: VS Code Chat Participant (for GitHub Copilot in VS Code)
123
+
124
+ 1. Implement AI provider in `.vscode/xray-qe-participant/extension.js`
125
+ 2. Install extension: Copy folder to `~/.vscode/extensions/`
126
+ 3. Reload VS Code
127
+ 4. Use `@xray-qe` in chat with commands like `/generate`, `/postman`
128
+
129
+ **Requires:** GitHub Copilot subscription, VS Code extension development
130
+
131
+ #### Option 3: Direct CLI Integration
132
+
133
+ 1. Modify `commands/genTests.js` to call your preferred AI service directly
134
+ 2. Add provider credentials to `.env` (e.g., `AZURE_OPENAI_KEY`)
135
+ 3. Use `gen-tests --ai` with integrated provider
136
+
137
+ **Requires:** AI provider API keys, custom implementation
138
+
139
+ ### Manual Workflow (No AI Required)
140
+
141
+ **This workflow works TODAY without any AI setup:**
142
+
143
+ ```bash
144
+ # 1. Create tests manually using the UI editor
145
+ npx xqt init
146
+ npx xqt edit-json # Create tests from scratch or edit templates
147
+
148
+ # 2. Push to Xray
149
+ npx xqt push-tests
150
+
151
+ # 3. Generate Postman collection (no AI)
152
+ npx xqt gen-postman # Uses tests.json + xray-mapping.json directly
153
+
154
+ # 4. Run in CI
155
+ newman run collection.postman.json
156
+ ```
157
+
158
+ **All AI features gracefully degrade** — without AI, commands provide helpful guidance for manual workflows.
159
+
160
+ ---
161
+
162
+ ## Quick Start
163
+
164
+ ### With AI (Future — Requires Setup)
165
+
166
+ ```bash
167
+ # 1. Initialize project with knowledge/ folder and starter files
168
+ npx xqt init
169
+
170
+ # 2. Configure credentials
171
+ cp .env.example .env
172
+ # Edit .env with your Xray + JIRA credentials
173
+
174
+ # 3. Add your API specs and requirements to knowledge/ folder
175
+ # See knowledge/README.md for supported file types
176
+
177
+ # 4. Set up AI provider (see "AI Setup" section above)
178
+ # ... implement AI connection in MCP server or VS Code extension ...
179
+
180
+ # 5. Generate test cases from knowledge sources (AI-assisted)
181
+ npx xqt gen-tests --ai
182
+
183
+ # 6. QE review gate — review and refine generated tests
184
+ npx xqt edit-json
185
+
186
+ # 7. Push approved tests to Xray Cloud
187
+ npx xqt push-tests
188
+
189
+ # 8. Generate Postman collection (AI-enhanced assertions)
190
+ npx xqt gen-postman --ai
191
+
192
+ # 9. Generate CI pipeline
193
+ npx xqt gen-pipeline
194
+
195
+ # 10. Run tests in CI
196
+ newman run collection.postman.json --reporters cli,junit
197
+ npx xqt import-results --file results.xml --testExecKey QE-123
198
+ ```
199
+
200
+ ### Without AI (Works Today)
201
+
202
+ ```bash
203
+ # 1. Initialize project
204
+ npx xqt init
205
+
206
+ # 2. Configure credentials
207
+ cp .env.example .env
208
+ # Edit .env with your Xray + JIRA credentials
209
+
210
+ # 3. Create tests manually using UI editor
211
+ npx xqt edit-json
212
+ # - Click "Add Test" to create new tests
213
+ # - Use knowledge/ docs as reference (manual review)
214
+ # - Save when ready
215
+
216
+ # 4. Push to Xray Cloud
217
+ npx xqt push-tests
218
+
219
+ # 5. Generate Postman collection (from tests.json)
220
+ npx xqt gen-postman
221
+
222
+ # 6. Generate CI pipeline
223
+ npx xqt gen-pipeline
224
+
225
+ # 7. Run tests in CI
226
+ newman run collection.postman.json --reporters cli,junit
227
+ npx xqt import-results --file results.xml --testExecKey QE-123
228
+ ```
229
+
230
+ ---
231
+
232
+ ## CLI Commands
233
+
234
+ All commands support these global options:
235
+
236
+ | Option | Description |
237
+ |---------------|------------------------------------|
238
+ | `--verbose` | Enable debug output |
239
+ | `--env <path>`| Custom path to .env file |
240
+ | `--version` | Show version number |
241
+ | `--help` | Show help for any command |
242
+
243
+ ---
244
+
245
+ ### `xray-qe init`
246
+
247
+ Scaffold a new project with starter templates.
248
+
249
+ ```bash
250
+ npx xqt init
251
+ ```
252
+
253
+ **Cknowledge/` folder with subdirectories (`api-specs/`, `requirements/`, `tickets/`)
254
+ - `knowledge/README.md` — guide for organizing documentation
255
+ - `tests.json` — starter test definitions (marked as scaffolds)
256
+ - `xray-mapping.json` — empty mapping file
257
+ - `.env.example` — environment variable template
258
+ - `.xrayrc` — project-level config
259
+
260
+ Existing files are **never overwritten** — the command skips them with a warning.
261
+
262
+ ---
263
+
264
+ ### `xray-qe gen-tests`
265
+
266
+ Generate test cases from `knowledge/` folder documentation (AI-assisted or manual guidance).
267
+
268
+ ```bash
269
+ # AI-assisted generation (requires AI provider setup — see "AI Setup" section)
270
+ npx xqt gen-tests --ai
271
+
272
+ # Focus on a specific OpenAPI spec
273
+ npx xqt gen-tests --ai --spec knowledge/api-specs/users-api.yaml
274
+
275
+ # Use a custom knowledge folder
276
+ npx xqt gen-tests --ai --knowledge ./docs
277
+
278
+ # Fetch and analyze a JIRA ticket
279
+ npx xqt gen-tests --ai --ticket APIEE-123
280
+
281
+ # Generate from a prompt
282
+ npx xqt gen-tests --ai --prompt "Generate tests for user authentication flows"
283
+ ```
284
+
285
+ | Option | Description | Required |
286
+ |---------------------|--------------------------------------------|----------|
287
+ | `--ai` | Enable AI-assisted generation | Yes |
288
+ | `--spec <path>` | OpenAPI/Swagger spec file | No |
289
+ | `--knowledge <path>`| Custom knowledge folder path | No |
290
+ | `--ticket <key>` | JIRA ticket key to fetch and analyze | No |
291
+ | `--prompt <text>` | Natural language prompt | No |
292
+
293
+ **Output:** Appends generated tests to `tests.json` (or creates it if it doesn't exist)
294
+
295
+ **🚧 AI Provider Required:** The `--ai` flag currently shows a scaffold message. To enable actual AI generation, implement an AI provider connection (see [AI Setup](#ai-setup-optional)).
296
+
297
+ **Without AI:** Run `gen-tests` without `--ai` for manual creation guidance, or use `edit-json` to create tests directly in the UI editor.
298
+
299
+ Existing files are **never overwritten** — the command skips them with a warning.
300
+
301
+ ---
302
+
303
+ ### `xray-qe edit-json`
304
+
305
+ Launch the browser-based QE review gate editor.
306
+
307
+ ```bash
308
+ npx xqt edit-json
309
+ npx xqt edit-json --port 3000
310
+ ```
311
+
312
+ | Option | Description | Default |
313
+ |-----------------|------------------------------------------|---------|
314
+ | `--port <n>` | Port for local editor server | Random |
315
+
316
+ **Features:**
317
+ - Add, edit, delete tests in a visual editor
318
+ - Tag tests: `regression`, `smoke`, `edge`, `critical`, `integration`, `e2e`, `security`, `performance`
319
+ - Toggle skip/push per test
320
+ - View Xray mapping status (which tests are already pushed)
321
+ - Real-time validation
322
+ - "Save & Exit" writes `tests.json` and shuts down the server
323
+
324
+ **Important:** This is the QE governance gate. Nothing is pushed to Xray until the QE saves and explicitly runs `push-tests`.
325
+
326
+ ---
327
+
328
+ ### `xray-qe push-tests`
329
+
330
+ Push or update tests in Xray Cloud from `tests.json`.
331
+
332
+ ```bash
333
+ # Create new Test Execution and link all tests
334
+ npx xqt push-tests
335
+
336
+ # Link tests to an existing Test Execution
337
+ npx xqt push-tests --testExecKey QE-123
338
+
339
+ # Push tests without creating/linking any execution
340
+ npx xqt push-tests --skip-exec
341
+ ```
342
+
343
+ | Option | Description |
344
+ |---------------------|----------------------------------------------------|
345
+ | `--testExecKey <key>` | Link to an existing Test Execution instead of creating new |
346
+ | `--skip-exec` | Don't create or link any Test Execution |
347
+
348
+ **Behavior:**
349
+ - Tests with `"skip": true` are excluded
350
+ - Tests already in `xray-mapping.json` are **updated** (summary, description, labels, priority, steps)
351
+ - New tests are **created** with type set to "Automated"
352
+ - Mapping is saved incrementally (crash-safe)
353
+ - 300ms rate-limit delay between API calls
354
+
355
+ ---
356
+
357
+ ### `xray-qe gen-postman`
358
+
359
+ Generate a Postman Collection v2.1 JSON from `tests.json` (works with or without AI).
360
+
361
+ ```bash
362
+ # Generate collection with JIRA keys embedded (run after push-tests)
363
+ npx xqt gen-postman
364
+
365
+ # Use a custom base URL
366
+ npx xqt gen-postman --base-url https://api.example.com
367
+
368
+ # AI-enhanced generation with better assertions
369
+ npx xqt gen-postman --ai
370
+
371
+ # Schema-driven generation from OpenAPI spec (no AI needed)
372
+ npx xqt gen-postman --spec knowledge/api-specs/api.yaml
373
+
374
+ # Use custom knowledge folder
375
+ npx xqt gen-postman --knowledge ./docs
376
+ ```
377
+
378
+ | Option | Description | Default |
379
+ |---------------------|---------------------------------|-----------------|
380
+ | `--base-url <url>` | Base URL for API requests | `{{baseUrl}}` |
381
+ | `--ai` | Enable AI-enhanced assertions | No |
382
+ | `--spec <path>` | OpenAPI spec for schema-driven generation | No |
383
+ | `--knowledge <path>`| Custom knowledge folder path | `knowledge/` |
384
+
385
+ **Output:** `collection.postman.json` in project root
386
+
387
+ **Behavior:**
388
+ - Only generates for tests with `type: "api"` (or unset, for backward compatibility)
389
+ - Embeds JIRA keys from `xray-mapping.json` when available (e.g., `[APIEE-6933] Test Summary`)
390
+ - Falls back to `test_id` if not yet pushed to Xray
391
+ - Each test becomes a folder, each step becomes a request with:
392
+ - Inferred HTTP method and endpoint from step data
393
+ - Pre-request scripts with step context
394
+ - Test scripts with assertions inferred from expected results
395
+ - SCAFFOLD markers for manual enhancement
396
+
397
+ **Important:** Generated collections are **starting points** — review and enhance assertions, environment variables, and edge cases before use.
398
+
399
+ ---
400
+
401
+ ### `xray-qe create-execution`
402
+
403
+ Create a standalone Test Execution issue in JIRA.
404
+
405
+ ```bash
406
+ npx xqt create-execution --summary "Sprint 24 Regression" --description "Full API regression"
407
+ npx xqt create-execution --summary "Feature XYZ" --issue QE-123
408
+ ```
409
+
410
+ | Option | Description | Required |
411
+ |---------------------|--------------------------------------------|----------|
412
+ | `--summary <text>` | Test Execution summary/title | Yes |
413
+ | `--description <text>` | Description | No |
414
+ | `--issue <key>` | Parent issue key to link the execution to | No |
415
+
416
+ ---
417
+
418
+ ### `xray-qe import-results`
419
+
420
+ Import JUnit/Newman XML results into Xray Cloud. Designed for CI — no human interaction.
421
+
422
+ ```bash
423
+ npx xqt import-results --file results.xml --testExecKey QE-123
424
+ ```
425
+
426
+ | Option | Description | Required |
427
+ |---------------------|--------------------------------------------|----------|
428
+ | `--file <path>` | Path to the JUnit/Newman results XML file | Yes |
429
+ | `--testExecKey <key>` | Test Execution to associate results with | Yes |
430
+
431
+ ---
432
+
433
+ ### `xray-qe gen-pipeline`
434
+
435
+ Generate an Azure Pipelines YAML template.
436
+
437
+ ```bash
438
+ npx xqt gen-pipeline
439
+ npx xqt gen-pipeline --output ci/azure-pipelines.yml
440
+ ```
441
+
442
+ | Option | Description | Default |
443
+ |---------------------|----------------------|------------------------|
444
+ | `--output <path>` | Output file path | `azure-pipelines.yml` |
445
+
446
+ The generated pipeline:
447
+ - Installs Node.js and dependencies
448
+ - Runs Newman against `collection.postman.json`
449
+ - Calls `import-results` with environment variables
450
+ - Publishes JUnit test results
451
+
452
+ **Note:** `edit-json` and QE review logic are NOT in the CI pipeline. Those happen pre-commit.
453
+
454
+ ---
455
+
456
+ ### `xray-qe mcp-server`
457
+
458
+ Start a Model Context Protocol server for GitHub Copilot agent-mode integration.
459
+
460
+ ```bash
461
+ # Start MCP server in stdio mode (for agent integration)
462
+ npx xqt mcp-server
463
+
464
+ # Start in HTTP mode for testing (optional)
465
+ npx xqt mcp-server --port 3100
466
+ ```
467
+
468
+ | Option | Description | Default |
469
+ |---------------------|----------------------|------------------------|
470
+ | `--port <n>` | HTTP port (testing) | stdio mode |
471
+
472
+ **MCP Tools Exposed:**
473
+ - `generate_test_cases` — Generate tests from knowledge/ sources
474
+ - `generate_postman` — Generate Postman collection with AI assertions
475
+ - `analyze_knowledge` — List and summarize knowledge sources
476
+ - `push_tests` — Push test cases to Xray Cloud
477
+ - `analyze_spec` — Parse OpenAPI spec and extract endpoints
478
+
479
+ **Status:** 🚧 Scaffold ready — AI provider connection not yet implemented. See [AI Setup](#ai-setup-optional) for implementation guidance.
480
+
481
+ **Learn more:** [Model Context Protocol](https://modelcontextprotocol.io/)
482
+
483
+ **Alternative:** `.vscode/xray-qe-participant/` contains a VS Code chat participant scaffold for GitHub Copilot integration.
484
+
485
+ ---
486
+
487
+ ## Configuration
488
+
489
+ ### Environment Variables (.env)
490
+
491
+ Create a `.env` file in your project root (or copy `.env.example`):
492
+
493
+ | Variable | Required | Description |
494
+ |-------------------|----------|------------------------------------------------|
495
+ | `XRAY_ID` | Yes | Xray Cloud API Client ID |
496
+ | `XRAY_SECRET` | Yes | Xray Cloud API Client Secret |
497
+ | `JIRA_PROJECT_KEY` | Yes | JIRA project key (e.g., `APIEE`, `QE`) |
498
+ | `JIRA_URL` | Yes | JIRA instance URL (e.g., `https://your-domain.atlassian.net`) |
499
+ | `JIRA_API_TOKEN` | Yes | JIRA API token |
500
+ | `JIRA_EMAIL` | Yes | JIRA user email (must match Xray API Key owner) |
501
+ | `XRAY_GRAPHQL_URL` | No | Region-specific GraphQL endpoint (default: US) |
502
+
503
+ **Region-specific GraphQL endpoints:**
504
+
505
+ | Region | URL |
506
+ |--------|-----|
507
+ | US (default) | `https://us.xray.cloud.getxray.app/api/v2/graphql` |
508
+ | EU | `https://eu.xray.cloud.getxray.app/api/v2/graphql` |
509
+ | AU | `https://au.xray.cloud.getxray.app/api/v2/graphql` |
510
+
511
+ ### Project Config (.xrayrc)
512
+
513
+ Optional JSON file for non-sensitive project settings:
514
+
515
+ ```json
516
+ {
517
+ "testsPath": "tests.json",
518
+ "mappingPath": "xray-mapping.json",
519
+ "collectionPath": "collection.postman.json"
520
+ }
521
+ ```
522
+
523
+ ---
524
+
525
+ ## File Reference
526
+
527
+ ### tests.json
528
+
529
+ Source-of-truth for test definitions. Created by `init`, edited by `edit-json`, consumed by `push-tests` and `gen-postman`.
530
+
531
+ ```json
532
+ {
533
+ "testExecution": {
534
+ "summary": "Sprint 24 - Automated Regression Suite",
535
+ "description": "API regression tests for Sprint 24 release"
536
+ },
537
+ "tests": [
538
+ {
539
+ "test_id": "TC-API-GET-001",
540
+ "skip": false,
541
+ "tags": ["regression", "smoke"],
542
+ "xray": {
543
+ "summary": "Verify GET /api/resource returns 200",
544
+ "description": "Test that the API returns expected data.",
545
+ "priority": "High",
546
+ "labels": ["API", "GET", "Regression"],
547
+ "steps": [
548
+ {
549
+ "action": "Send GET request to /api/resource/123",
550
+ "data": "Method: GET, Headers: Authorization: Bearer {token}",
551
+ "expected_result": "200 OK with resource object"
552
+ }
553
+ ]
554
+ }
555
+ }
556
+ ]
557
+ }
558
+ ```
559
+
560
+ **Fields:**
561
+
562
+ | Field | Type | Required | Description |
563
+ |-------|------|----------|-------------|
564
+ | `test_id` | string | Yes | Unique identifier (alphanumeric, hyphens, underscores) |
565
+ | `skip` | boolean | No | If `true`, excluded from `push-tests` |
566
+ | `tags` | string[] | No | QE tags: `regression`, `smoke`, `edge`, `critical`, etc. |
567
+ | `xray.summary` | string | Yes | JIRA issue title |
568
+ | `xray.description` | string | No | JIRA issue description |
569
+ | `xray.priority` | string | No | `Highest`, `High`, `Medium`, `Low`, `Lowest` |
570
+ | `xray.labels` | string[] | No | JIRA labels |
571
+ | `xray.steps[].action` | string | Yes | What action to perform |
572
+ | `xray.steps[].data` | string | No | Input data / parameters |
573
+ | `xray.steps[].expected_result` | string | Yes | Expected outcome |
574
+
575
+ ### xray-mapping.json
576
+
577
+ Maps `test_id` → JIRA issue `{ key, id }`. Generated by `push-tests`, used for idempotent updates.
578
+
579
+ ```json
580
+ {
581
+ "TC-API-GET-001": { "key": "APIEE-6933", "id": "1865623" },
582
+ "TC-API-POST-001": { "key": "APIEE-6934", "id": "1865627" },
583
+ "_testexecution": { "key": "APIEE-6941", "id": "1865637" }
584
+ }
585
+ ```
586
+
587
+ ---
588
+
589
+ ## Multi-Company Test Format
590
+
591
+ This toolkit pushes tests into **one JIRA project per run** (via `JIRA_PROJECT_KEY`). For multiple companies, use consistent naming and keep per-company configs and files.
592
+
593
+ **Recommended conventions:**
594
+ - `test_id`: Prefix with company + domain + sequence, e.g. `ACME-BILLING-PAYMENTS-001`
595
+ - `xray.summary`: Start with company or product tag, e.g. `[ACME] Payments - create invoice`
596
+ - `xray.labels`: Add `company:<slug>`, `system:<slug>`, `team:<slug>` for filtering
597
+ - `testExecution.summary`: Include company + release/sprint, e.g. `ACME - Sprint 12 Regression`
598
+
599
+ **Example snippet:**
600
+
601
+ ```json
602
+ {
603
+ "testExecution": {
604
+ "summary": "ACME - Sprint 12 Regression"
605
+ },
606
+ "tests": [
607
+ {
608
+ "test_id": "ACME-BILLING-PAYMENTS-001",
609
+ "tags": ["regression", "smoke"],
610
+ "xray": {
611
+ "summary": "[ACME] Payments - create invoice",
612
+ "labels": ["company:acme", "system:billing", "team:payments"],
613
+ "steps": [
614
+ {
615
+ "action": "Send POST /payments/invoices",
616
+ "expected_result": "201 Created"
617
+ }
618
+ ]
619
+ }
620
+ }
621
+ ]
622
+ }
623
+ ```
624
+
625
+ **Per-company setup options:**
626
+ - **Separate folders (recommended):** run `xray-qe init` once per company and keep `tests.json`, `xray-mapping.json`, `.env`, and `.xrayrc` isolated.
627
+ - **Shared repo:** use a company-specific `.env` and `.xrayrc` (swap before running). Example `.xrayrc`:
628
+
629
+ ```json
630
+ {
631
+ "testsPath": "tests.acme.json",
632
+ "mappingPath": "xray-mapping.acme.json",
633
+ "collectionPath": "collection.acme.postman.json"
634
+ }
635
+ ```
636
+
637
+ ---
638
+
639
+ ## Jira/Xray Project Setup
640
+
641
+ Use this checklist to align a new team's board and Xray configuration with the toolkit:
642
+
643
+ 1. **Create a JIRA project** per company or business unit (Software or Service project).
644
+ 2. **Enable Xray** for the project and confirm issue types: **Test** and **Test Execution** (optional: Test Plan).
645
+ 3. **Configure screens/fields** to include Summary, Description, Priority, Labels, and Test Steps.
646
+ 4. **Set permissions** so the API user can create/edit Test and Test Execution issues.
647
+ 5. **Define components/labels** that match your naming conventions (company, system, team).
648
+ 6. **Create a board** with a filter like `project = KEY AND issuetype in (Test, "Test Execution")` and use components/labels for swimlanes.
649
+
650
+ ---
651
+
652
+ ## QE Workflow
653
+
654
+ ```
655
+ ┌─────────────────────────────────────────────────────────────────────────┐
656
+ │ QE WORKFLOW (LOCAL) │
657
+ │ │
658
+ │ 1. npx xqt init ← scaffold project + knowledge/ folder │
659
+ │ 2. Configure .env ← credentials │
660
+ │ 3. Populate knowledge/ ← add API specs, requirements, tickets │
661
+ │ • knowledge/api-specs/ (OpenAPI, Swagger) │
662
+ │ • knowledge/requirements/ (BRDs, logic docs) │
663
+ │ • knowledge/tickets/ (JIRA exports, Confluence) │
664
+ │ 4. npx xqt gen-tests --ai ← AI generates test cases from knowledge│
665
+ │ 5. npx xqt edit-json ← QE REVIEW GATE (browser UI) │
666
+ │ • Review AI-generated tests │
667
+ │ • Add/edit/delete tests │
668
+ │ • Tag tests (regression, critical, etc.) │
669
+ │ • Mark skip/push per test │
670
+ │ • Save & Exit │
671
+ │ 6. npx xqt push-tests ← push to Xray Cloud │
672
+ │ 7. npx xqt gen-postman --ai ← generate Postman collection │
673
+ │ 8. git commit & push ← CI picks up from here │
674
+ │ │
675
+ ├─────────────────────────────────────────────────────────────────────────┤
676
+ │ CI PIPELINE (AUTOMATED) │
677
+ │ │
678
+ │ 9. npm ci ← install deps │
679
+ │ 10. newman run collection.postman.json --reporters junit │
680
+ │ 11. npx xqt import-results --file results.xml --testExecKey QE-123│
681
+ │ │
682
+ └─────────────────────────────────────────────────────────────────────────┘
683
+ ```
684
+
685
+ ---
686
+
687
+ ## Building Regression Packs
688
+
689
+ Regression packs are curated test suites that verify your system still works after changes. The toolkit makes it easy to build and maintain regression packs using tags, AI-generated tests, and idempotent push.
690
+
691
+ ### 1. Organize Knowledge Sources by Domain
692
+
693
+ ```
694
+ knowledge/
695
+ ├── api-specs/
696
+ │ ├── auth-api.yaml ← Authentication domain
697
+ │ ├── users-api.yaml ← User management
698
+ │ └── payments-api.yaml ← Payment processing
699
+ ├── requirements/
700
+ │ ├── auth-flows.md
701
+ │ ├── user-roles.md
702
+ │ └── payment-validation.md
703
+ └── tickets/
704
+ ├── APIEE-123.json ← Login epic
705
+ ├── APIEE-456.json ← Payment refactor epic
706
+ └── confluence-sso.html
707
+ ```
708
+
709
+ ### 2. Generate Tests by Domain
710
+
711
+ ```bash
712
+ # Generate auth tests from auth spec
713
+ npx xqt gen-tests --ai --spec knowledge/api-specs/auth-api.yaml
714
+
715
+ # Generate payment tests
716
+ npx xqt gen-tests --ai --spec knowledge/api-specs/payments-api.yaml
717
+
718
+ # Generate from a specific ticket
719
+ npx xqt gen-tests --ai --ticket APIEE-123
720
+ ```
721
+
722
+ ### 3. Tag Tests for Pack Categorization
723
+
724
+ Use `edit-json` to assign tags:
725
+
726
+ | Tag | Purpose |
727
+ |-----|---------|
728
+ | `regression` | Full regression pack — all core functionality |
729
+ | `smoke` | Smoke test pack — critical paths only |
730
+ | `critical` | Critical business flows (subset of regression) |
731
+ | `edge` | Edge case and error handling tests |
732
+ | `integration` | Multi-system integration tests |
733
+ | `security` | Security and auth tests |
734
+ | `performance` | Performance/load tests |
735
+
736
+ **Example workflow:**
737
+ 1. Generate tests: `npx xqt gen-tests --ai`
738
+ 2. Open editor: `npx xqt edit-json`
739
+ 3. Add `regression` tag to all tests
740
+ 4. Add `smoke` tag to critical path tests
741
+ 5. Add `critical` tag to business-critical tests
742
+ 6. Save and push to Xray
743
+
744
+ ### 4. Filter and Run Specific Packs
745
+
746
+ **In tests.json:**
747
+ ```json
748
+ {
749
+ "tests": [
750
+ {
751
+ "test_id": "001",
752
+ "type": "api",
753
+ "tags": ["regression", "smoke", "critical"]
754
+ },
755
+ {
756
+ "test_id": "002",
757
+ "type": "api",
758
+ "tags": ["regression", "edge"]
759
+ },
760
+ {
761
+ "test_id": "003",
762
+ "type": "api",
763
+ "tags": ["regression"],
764
+ "skip": true
765
+ }
766
+ ]
767
+ }
768
+ ```
769
+
770
+ **Filtering in edit-json:**
771
+ - Use the dropdown to filter by tag (e.g., show only `smoke` tests)
772
+ - Mark tests as `skip: true` to exclude from push/generation
773
+
774
+ **CI pipeline filtering:**
775
+ - Generate smoke pack: filter `tests.json` to `tags.includes("smoke")` before `gen-postman`
776
+ - Generate regression pack: filter to `tags.includes("regression")` and `skip !== true`
777
+ - Schedule different packs on different cadences (smoke nightly, regression weekly)
778
+
779
+ ### 5. Maintain Packs Over Sprints
780
+
781
+ **Idempotent push** keeps Xray in sync as your pack evolves:
782
+
783
+ | Sprint Change | Action | Result |
784
+ |---------------|--------|--------|
785
+ | API endpoint added | `gen-tests --ai --spec new-api.yaml` → `edit-json` → `push-tests` | New tests created in Xray |
786
+ | Test assertion updated | Edit in `edit-json` → `push-tests` | Existing test updated in Xray |
787
+ | Test deprecated | Mark `skip: true` in `edit-json` → `push-tests` | Test excluded from future runs |
788
+ | Requirements changed | Update `knowledge/requirements/` → `gen-tests --ai` | Regenerate affected tests |
789
+
790
+ **Best practices:**
791
+ - ✅ Regenerate tests when specs change (toolkit updates existing tests)
792
+ - ✅ Use meaningful `test_id` values (`AUTH-LOGIN-001` instead of `001`)
793
+ - ✅ Commit `tests.json` and `xray-mapping.json` to source control
794
+ - ✅ Review AI-generated tests before pushing — they're scaffolds, not production-ready
795
+ - ✅ Keep `knowledge/` up to date with your latest specs and docs
796
+
797
+ ### 6. Example: Sprint Regression Pack Workflow
798
+
799
+ ```bash
800
+ # Sprint start: Generate tests from updated specs
801
+ npx xqt gen-tests --ai
802
+
803
+ # QE reviews and tags tests
804
+ npx xqt edit-json
805
+ # → Tag new tests with "regression"
806
+ # → Mark experimental tests as "skip"
807
+ # → Verify all critical paths have "smoke" tag
808
+
809
+ # Push to Xray (creates new, updates existing)
810
+ npx xqt push-tests
811
+
812
+ # Generate Postman collection for CI
813
+ npx xqt gen-postman --ai
814
+
815
+ # Commit regression pack to repo
816
+ git add tests.json xray-mapping.json collection.postman.json
817
+ git commit -m "Sprint 24 regression pack"
818
+
819
+ # CI runs nightly
820
+ newman run collection.postman.json --folder "[smoke]"
821
+ newman run collection.postman.json # Full regression weekly
822
+ ```
823
+
824
+ ---
825
+
826
+ ## Idempotent Push
827
+
828
+ `push-tests` checks `xray-mapping.json` before each operation:
829
+
830
+ | Scenario | Action |
831
+ |----------|--------|
832
+ | `test_id` not in mapping | **Create** new JIRA Test issue + steps |
833
+ | `test_id` in mapping | **Update** existing issue fields + replace steps |
834
+ | `skip: true` | **Skip** entirely |
835
+
836
+ This means you can safely run `push-tests` multiple times without creating duplicates.
837
+
838
+ ---
839
+
840
+ ## Programmatic API
841
+
842
+ All library functions are importable for custom scripts:
843
+
844
+ ```javascript
845
+ import {
846
+ loadConfig,
847
+ validateConfig,
848
+ authenticate,
849
+ createIssue,
850
+ buildAndPush,
851
+ generatePostmanCollection,
852
+ logger,
853
+ } from "@msalaam/xray-qe-toolkit";
854
+
855
+ const cfg = loadConfig();
856
+ validateConfig(cfg);
857
+
858
+ const token = await authenticate(cfg);
859
+ // ... use any exported function
860
+ ```
861
+
862
+ ---
863
+
864
+ ## Troubleshooting
865
+
866
+ ### "disallowed to impersonate" / "no valid active user exists"
867
+
868
+ Your `JIRA_EMAIL` doesn't match the Xray API Key owner.
869
+
870
+ **Fix:**
871
+ 1. Ensure `JIRA_EMAIL` matches the email of the user who created the Xray API Key
872
+ 2. Verify the user has an active Xray license
873
+ 3. Regenerate the Xray API Key with the same user as `JIRA_API_TOKEN`
874
+
875
+ ### "issueId provided is not valid" (transient)
876
+
877
+ Xray's GraphQL API needs time to index newly created JIRA issues. The toolkit automatically retries with exponential backoff (2s → 4s → 8s → 16s → 32s).
878
+
879
+ If it still fails after 5 retries, wait a minute and try again.
880
+
881
+ ### Rate limiting / 429 errors
882
+
883
+ The toolkit includes a 300ms delay between API calls. If you still hit rate limits, wait and retry. For very large test suites (100+), consider splitting across multiple runs.
884
+
885
+ ### Browser doesn't open for `edit-json`
886
+
887
+ In headless environments, copy the URL printed in the terminal and open it manually.
888
+
889
+ ---
890
+
891
+ ## License
892
+
893
+ See LICENSE.