@msalaam/xray-qe-toolkit 1.4.0 → 1.4.1
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/.env.example +23 -9
- package/README.md +721 -1434
- package/bin/cli.js +92 -69
- package/commands/createExecution.js +112 -23
- package/commands/createPlan.js +121 -0
- package/commands/editJson.js +1 -1
- package/commands/genPipeline.js +1 -1
- package/commands/genTests.js +18 -18
- package/commands/importResults.js +107 -74
- package/commands/init.js +258 -70
- package/commands/pullTests.js +128 -0
- package/commands/pushTests.js +87 -43
- package/commands/status.js +108 -0
- package/commands/syncFolders.js +62 -0
- package/commands/validate.js +136 -0
- package/lib/config.js +50 -13
- package/lib/index.js +43 -4
- package/lib/playwrightConverter.js +91 -173
- package/lib/testCaseBuilder.js +116 -55
- package/lib/xrayClient.js +779 -202
- package/package.json +6 -8
- package/schema/business-rules.schema.json +110 -0
- package/schema/tests.schema.json +42 -16
- package/templates/README.template.md +570 -169
- package/templates/SPEC-DRIVEN-APPROACH.md +372 -0
- package/templates/azure-pipelines.yml +129 -77
- package/templates/business-rules.yaml +83 -0
- package/templates/resources-README.md +112 -0
- package/templates/tests.json +69 -51
- package/commands/compareOpenapi.js +0 -78
- package/commands/genPostman.js +0 -70
- package/commands/updateSnapshot.js +0 -34
- package/lib/postmanGenerator.js +0 -304
- package/templates/knowledge-README.md +0 -121
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Resources — AI Test Generation Sources
|
|
2
|
+
|
|
3
|
+
This folder contains documentation and specifications used by the AI agent to generate test cases for Xray.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Folder Structure
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
resources/
|
|
11
|
+
├── api-specs/ OpenAPI/Swagger specifications (YAML/JSON)
|
|
12
|
+
├── requirements/ Business requirements, acceptance criteria, logic docs
|
|
13
|
+
└── tickets/ Exported JIRA tickets, Confluence pages, user stories
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Supported File Types
|
|
19
|
+
|
|
20
|
+
### `api-specs/`
|
|
21
|
+
- **OpenAPI 3.x / Swagger 2.0** — `.yaml`, `.yml`, `.json`
|
|
22
|
+
- **GraphQL schemas** — `.graphql`, `.gql`
|
|
23
|
+
|
|
24
|
+
Files in this folder drive model, service, assertion, and spec generation via the spec-driven workflow.
|
|
25
|
+
|
|
26
|
+
### `requirements/`
|
|
27
|
+
- **Markdown** — `.md`
|
|
28
|
+
- **Plain text** — `.txt`
|
|
29
|
+
- **Word documents** — `.docx`
|
|
30
|
+
- **PDFs** — `.pdf`
|
|
31
|
+
|
|
32
|
+
Business logic, acceptance criteria, workflow descriptions, and domain rules. Used to generate test scenarios, edge cases, and validation logic.
|
|
33
|
+
|
|
34
|
+
### `tickets/`
|
|
35
|
+
- **JIRA exports** — `.json`, `.xml`
|
|
36
|
+
- **Confluence HTML exports** — `.html`
|
|
37
|
+
- **User stories** — `.md`, `.txt`
|
|
38
|
+
|
|
39
|
+
Ticket acceptance criteria and linked documentation. Used to ensure test coverage aligns with stories and epics.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## How the AI Agent Uses These Files
|
|
44
|
+
|
|
45
|
+
1. **Test Case Generation** (AI agent reads these files and populates `tests.json`)
|
|
46
|
+
- Reads `openapi.yaml` (API shape) and `business-rules.yaml` (domain rules)
|
|
47
|
+
- Produces `tests.json` entries with stable `test_id` values for Xray traceability
|
|
48
|
+
- Each `business-rules.yaml` rule maps 1:1 to a `tests.json` entry
|
|
49
|
+
- See **[SPEC-DRIVEN-APPROACH.md](../SPEC-DRIVEN-APPROACH.md)** for the full workflow
|
|
50
|
+
|
|
51
|
+
2. **Xray Sync** (after `tests.json` is generated)
|
|
52
|
+
- `npx xqt validate` then `npx xqt push-tests`
|
|
53
|
+
- Creates Xray Test issues + Test Sets in Jira
|
|
54
|
+
- Populates `xray-mapping.json` with issue keys
|
|
55
|
+
|
|
56
|
+
3. **Playwright Test Creation** (after Xray sync)
|
|
57
|
+
- Copilot skill reads `tests.json` + `xray-mapping.json`
|
|
58
|
+
- Creates one Playwright `test()` call per `tests.json` entry
|
|
59
|
+
- Real Jira keys in test titles from day one
|
|
60
|
+
|
|
61
|
+
4. **Continuous Refinement**
|
|
62
|
+
- As you add/update specs and business rules, re-run the generation workflow
|
|
63
|
+
- The toolkit is **idempotent** — existing tests are updated, retired rules get `skip: true`
|
|
64
|
+
- Always validate before pushing: `npx xqt validate` then `npx xqt push-tests`
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Best Practices
|
|
69
|
+
|
|
70
|
+
✅ **DO:**
|
|
71
|
+
- Keep specs up to date with your API implementation
|
|
72
|
+
- Organize files by feature/domain for easier tracking
|
|
73
|
+
- Use descriptive filenames (e.g., `auth-api-v2.yaml`, `payment-flows.md`)
|
|
74
|
+
- Commit this folder to source control (Git)
|
|
75
|
+
|
|
76
|
+
⚠️ **DON'T:**
|
|
77
|
+
- Store credentials or secrets in these files
|
|
78
|
+
- Include massive binary files (>10MB) — extract relevant sections
|
|
79
|
+
- Mix unrelated specs in the same file
|
|
80
|
+
- Forget to update specs when the API changes
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Example Workflow
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 1. Add your OpenAPI spec
|
|
88
|
+
cp ~/Downloads/my-api.yaml resources/openapi.yaml
|
|
89
|
+
|
|
90
|
+
# 2. Populate business rules (or generate a draft from the spec)
|
|
91
|
+
# Use Copilot + SPEC-DRIVEN-APPROACH.md to generate resources/business-rules.yaml
|
|
92
|
+
|
|
93
|
+
# 3. Validate knowledge artifacts
|
|
94
|
+
npx xqt validate --schema business-rules
|
|
95
|
+
|
|
96
|
+
# 4. Use Copilot (spec-driven workflow) to generate models, services, assertions, and specs
|
|
97
|
+
# See SPEC-DRIVEN-APPROACH.md for the full step-by-step
|
|
98
|
+
|
|
99
|
+
# 5. Validate tests.json
|
|
100
|
+
npx xqt validate
|
|
101
|
+
|
|
102
|
+
# 6. Push tests to Xray
|
|
103
|
+
npx xqt push-tests
|
|
104
|
+
|
|
105
|
+
# 7. Run tests and import results
|
|
106
|
+
npx playwright test
|
|
107
|
+
npx xqt import-results --file test-results/results.json
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
**Note:** This folder is the knowledge input for the spec-driven workflow. See **[SPEC-DRIVEN-APPROACH.md](../SPEC-DRIVEN-APPROACH.md)** for the complete greenfield/brownfield generation process.
|
package/templates/tests.json
CHANGED
|
@@ -1,74 +1,92 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
2
|
+
"testPlan": {
|
|
3
|
+
"key": "",
|
|
4
|
+
"summary": "My Service — Test Plan"
|
|
5
5
|
},
|
|
6
6
|
"tests": [
|
|
7
7
|
{
|
|
8
|
-
"test_id": "TC-
|
|
8
|
+
"test_id": "TC-MYSVC-BR-001",
|
|
9
|
+
"type": "api",
|
|
10
|
+
"skip": false,
|
|
11
|
+
"tags": ["smoke", "regression"],
|
|
12
|
+
"folder": "/MyService/HealthCheck/Validation",
|
|
13
|
+
"testSet": "Health Check",
|
|
14
|
+
"requirementKeys": [],
|
|
15
|
+
"xray": {
|
|
16
|
+
"summary": "Service returns 200 OK when healthy",
|
|
17
|
+
"description": "Given Service is running with all dependencies reachable, when GET /health is called, then Response is 200 with body { \"status\": \"ok\" }",
|
|
18
|
+
"testType": "Generic",
|
|
19
|
+
"definition": "Automated Playwright API test: GET /health — Service returns 200 OK when healthy",
|
|
20
|
+
"priority": "High",
|
|
21
|
+
"labels": ["smoke", "regression"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"test_id": "TC-MYSVC-BR-002",
|
|
26
|
+
"type": "api",
|
|
27
|
+
"skip": false,
|
|
28
|
+
"tags": ["regression", "security"],
|
|
29
|
+
"folder": "/MyService/ExampleFeature/Authorization",
|
|
30
|
+
"testSet": "Example Feature",
|
|
31
|
+
"requirementKeys": [],
|
|
32
|
+
"xray": {
|
|
33
|
+
"summary": "Unauthenticated requests are rejected",
|
|
34
|
+
"description": "Given No Authorization header is provided, when Any protected endpoint is called, then Response is 401 Unauthorized",
|
|
35
|
+
"testType": "Generic",
|
|
36
|
+
"definition": "Automated Playwright API test: GET /api/v1/resource — Unauthenticated requests are rejected",
|
|
37
|
+
"priority": "Highest",
|
|
38
|
+
"labels": ["regression", "security"]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"test_id": "TC-MYSVC-BR-003",
|
|
9
43
|
"type": "api",
|
|
10
44
|
"skip": false,
|
|
11
45
|
"tags": ["regression", "smoke"],
|
|
46
|
+
"folder": "/MyService/ExampleFeature/BusinessLogic",
|
|
47
|
+
"testSet": "Example Feature",
|
|
48
|
+
"requirementKeys": [],
|
|
12
49
|
"xray": {
|
|
13
|
-
"summary": "
|
|
14
|
-
"description": "
|
|
50
|
+
"summary": "Valid resource creation returns 201 with resource id",
|
|
51
|
+
"description": "Given Authenticated user with create permission, when POST /api/v1/resource with valid body, then Response is 201 with { \"id\": \"<uuid>\" } and Location header",
|
|
52
|
+
"testType": "Generic",
|
|
53
|
+
"definition": "Automated Playwright API test: POST /api/v1/resource — Valid resource creation returns 201 with resource id",
|
|
15
54
|
"priority": "High",
|
|
16
|
-
"labels": ["
|
|
17
|
-
"steps": [
|
|
18
|
-
{
|
|
19
|
-
"action": "Send GET request to /api/resource with valid parameters",
|
|
20
|
-
"data": "Method: GET, Headers: Authorization: Bearer {token}, Params: id=1",
|
|
21
|
-
"expected_result": "API returns HTTP 200 with resource object"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"action": "Validate response body structure",
|
|
25
|
-
"data": "Response body JSON",
|
|
26
|
-
"expected_result": "Response contains expected fields: id, name, status"
|
|
27
|
-
}
|
|
28
|
-
]
|
|
55
|
+
"labels": ["regression", "smoke"]
|
|
29
56
|
}
|
|
30
57
|
},
|
|
31
58
|
{
|
|
32
|
-
"test_id": "TC-
|
|
59
|
+
"test_id": "TC-MYSVC-BR-004",
|
|
33
60
|
"type": "api",
|
|
34
61
|
"skip": false,
|
|
35
|
-
"tags": ["regression", "
|
|
62
|
+
"tags": ["regression", "edge"],
|
|
63
|
+
"folder": "/MyService/ExampleFeature/Validation",
|
|
64
|
+
"testSet": "Example Feature",
|
|
65
|
+
"requirementKeys": [],
|
|
36
66
|
"xray": {
|
|
37
|
-
"summary": "
|
|
38
|
-
"description": "
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
"action": "Send POST request to /api/resource with missing required fields",
|
|
44
|
-
"data": "Method: POST, Headers: Authorization: Bearer {token}, Body: {}",
|
|
45
|
-
"expected_result": "API returns HTTP 400 Bad Request"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"action": "Validate error response body",
|
|
49
|
-
"data": "Response body JSON",
|
|
50
|
-
"expected_result": "Response contains 'error' field with a descriptive message string"
|
|
51
|
-
}
|
|
52
|
-
]
|
|
67
|
+
"summary": "Missing required fields return 400 with field-level errors",
|
|
68
|
+
"description": "Given Authenticated user, when POST /api/v1/resource with missing required fields, then Response is 400 with errors array listing each missing field",
|
|
69
|
+
"testType": "Generic",
|
|
70
|
+
"definition": "Automated Playwright API test: POST /api/v1/resource — Missing required fields return 400 with field-level errors",
|
|
71
|
+
"priority": "High",
|
|
72
|
+
"labels": ["regression", "edge"]
|
|
53
73
|
}
|
|
54
74
|
},
|
|
55
75
|
{
|
|
56
|
-
"test_id": "TC-
|
|
76
|
+
"test_id": "TC-MYSVC-BR-005",
|
|
57
77
|
"type": "api",
|
|
58
|
-
"skip":
|
|
59
|
-
"tags": ["
|
|
78
|
+
"skip": false,
|
|
79
|
+
"tags": ["regression", "edge"],
|
|
80
|
+
"folder": "/MyService/ExampleFeature/Edge",
|
|
81
|
+
"testSet": "Example Feature",
|
|
82
|
+
"requirementKeys": [],
|
|
60
83
|
"xray": {
|
|
61
|
-
"summary": "
|
|
62
|
-
"description": "
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
"action": "Send POST request to /api/resource with large payload",
|
|
68
|
-
"data": "Method: POST, Headers: Authorization: Bearer {token}, Body: large JSON array with 1000 items",
|
|
69
|
-
"expected_result": "API returns HTTP 200 within 3000ms"
|
|
70
|
-
}
|
|
71
|
-
]
|
|
84
|
+
"summary": "Resource id not found returns 404",
|
|
85
|
+
"description": "Given Authenticated user, when GET /api/v1/resource/{id} with non-existent id, then Response is 404 with standard error body",
|
|
86
|
+
"testType": "Generic",
|
|
87
|
+
"definition": "Automated Playwright API test: GET /api/v1/resource/{id} — Resource id not found returns 404",
|
|
88
|
+
"priority": "Medium",
|
|
89
|
+
"labels": ["regression", "edge"]
|
|
72
90
|
}
|
|
73
91
|
}
|
|
74
92
|
]
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { diff } from 'openapi-diff';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Compare two OpenAPI specs and detect breaking changes.
|
|
7
|
-
* @param {string} currentPath - Path to the current (live) OpenAPI spec.
|
|
8
|
-
* @param {string} snapshotPath - Path to the approved QA snapshot.
|
|
9
|
-
* @param {string|null} reportPath - Optional path to write a JSON diff report.
|
|
10
|
-
*/
|
|
11
|
-
export async function compareOpenApiSpecs(currentPath, snapshotPath, reportPath = null) {
|
|
12
|
-
const resolvedCurrent = path.resolve(currentPath);
|
|
13
|
-
const resolvedSnapshot = path.resolve(snapshotPath);
|
|
14
|
-
|
|
15
|
-
if (!fs.existsSync(resolvedCurrent)) {
|
|
16
|
-
throw new Error(`Current OpenAPI spec not found: ${resolvedCurrent}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!fs.existsSync(resolvedSnapshot)) {
|
|
20
|
-
throw new Error(`Snapshot OpenAPI spec not found: ${resolvedSnapshot}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const currentSpec = fs.readFileSync(resolvedCurrent, 'utf-8');
|
|
24
|
-
const snapshotSpec = fs.readFileSync(resolvedSnapshot, 'utf-8');
|
|
25
|
-
|
|
26
|
-
const result = await diff({
|
|
27
|
-
sourceSpec: { content: snapshotSpec }, // approved baseline
|
|
28
|
-
destinationSpec: { content: currentSpec } // proposed change
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const summary = {
|
|
32
|
-
breaking: result.breakingDifferencesFound,
|
|
33
|
-
breakingDifferences: result.breakingDifferences,
|
|
34
|
-
nonBreakingDifferences: result.nonBreakingDifferences
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
if (reportPath && result.breakingDifferencesFound) {
|
|
38
|
-
const resolvedReport = path.resolve(reportPath);
|
|
39
|
-
fs.writeFileSync(resolvedReport, JSON.stringify(summary, null, 2), 'utf-8');
|
|
40
|
-
console.log(`📄 Diff report written to: ${resolvedReport}`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return summary;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export default async function compareOpenapi(opts) {
|
|
47
|
-
const { current, snapshot, report } = opts;
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const result = await compareOpenApiSpecs(current, snapshot, report || null);
|
|
51
|
-
|
|
52
|
-
if (result.breaking) {
|
|
53
|
-
console.error('\n❌ Breaking changes detected:\n');
|
|
54
|
-
console.error(JSON.stringify(result.breakingDifferences, null, 2));
|
|
55
|
-
|
|
56
|
-
const count = result.breakingDifferences?.length ?? 0;
|
|
57
|
-
console.error(`\n${count} breaking difference(s) found.`);
|
|
58
|
-
|
|
59
|
-
if (!report) {
|
|
60
|
-
console.error('\nTip: use --report <path> to save a full diff report as a pipeline artifact.');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const nonBreaking = result.nonBreakingDifferences?.length ?? 0;
|
|
67
|
-
console.log('\n✅ No breaking changes detected.');
|
|
68
|
-
|
|
69
|
-
if (nonBreaking > 0) {
|
|
70
|
-
console.log(`ℹ️ ${nonBreaking} non-breaking difference(s) found (safe to proceed).`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
process.exit(0);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
console.error(`\n❌ ${err.message}`);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
}
|
package/commands/genPostman.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Command: xray-qe gen-postman [--base-url <url>] [--ai] [--spec <path>] [--knowledge <path>]
|
|
3
|
-
*
|
|
4
|
-
* Generates a Postman Collection v2.1 JSON file from tests.json.
|
|
5
|
-
* Optionally uses xray-mapping.json to embed JIRA keys for better traceability.
|
|
6
|
-
* With --ai flag, enables AI-assisted generation (requires connected provider).
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import fs from "node:fs";
|
|
10
|
-
import logger, { setVerbose } from "../lib/logger.js";
|
|
11
|
-
import { loadConfig } from "../lib/config.js";
|
|
12
|
-
import { generate } from "../lib/postmanGenerator.js";
|
|
13
|
-
import { loadMapping } from "../lib/testCaseBuilder.js";
|
|
14
|
-
|
|
15
|
-
export default async function genPostman(opts = {}) {
|
|
16
|
-
if (opts.verbose) setVerbose(true);
|
|
17
|
-
|
|
18
|
-
logger.rocket("@msalaam/xray-qe-toolkit — Generate Postman Collection\n");
|
|
19
|
-
|
|
20
|
-
const cfg = loadConfig({ envPath: opts.env });
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(cfg.testsPath)) {
|
|
23
|
-
logger.error(`tests.json not found at ${cfg.testsPath}`);
|
|
24
|
-
logger.info("Run 'npx xray-qe init' to create a starter tests.json");
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const testsConfig = JSON.parse(fs.readFileSync(cfg.testsPath, "utf8"));
|
|
29
|
-
|
|
30
|
-
// Load mapping to embed JIRA keys when available
|
|
31
|
-
const mapping = loadMapping(cfg.mappingPath);
|
|
32
|
-
|
|
33
|
-
// Filter out skipped tests
|
|
34
|
-
const filteredConfig = {
|
|
35
|
-
...testsConfig,
|
|
36
|
-
tests: (testsConfig.tests || []).filter((t) => !t.skip),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// AI flag handling
|
|
40
|
-
if (opts.ai) {
|
|
41
|
-
logger.info("🤖 AI-assisted generation enabled");
|
|
42
|
-
logger.warn("AI provider not yet connected — using schema-driven generation as fallback");
|
|
43
|
-
logger.blank();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Knowledge path override
|
|
47
|
-
const knowledgePath = opts.knowledge || cfg.knowledgePath;
|
|
48
|
-
if (opts.knowledge) {
|
|
49
|
-
logger.info(`Using custom knowledge path: ${knowledgePath}`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Spec file handling (schema-driven generation without AI)
|
|
53
|
-
if (opts.spec && fs.existsSync(opts.spec)) {
|
|
54
|
-
logger.info(`Using OpenAPI spec: ${opts.spec}`);
|
|
55
|
-
logger.info("📝 Schema-driven endpoint inference enabled");
|
|
56
|
-
// TODO: Parse OpenAPI spec and enhance endpoint/method/body inference
|
|
57
|
-
logger.blank();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
generate(filteredConfig, cfg.collectionPath, {
|
|
61
|
-
baseUrl: opts.baseUrl || "{{baseUrl}}",
|
|
62
|
-
mapping: mapping,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
logger.blank();
|
|
66
|
-
logger.success(`Collection saved to ${cfg.collectionPath}`);
|
|
67
|
-
logger.info("Import into Postman or run with Newman:");
|
|
68
|
-
console.log(` npx newman run ${cfg.collectionPath}`);
|
|
69
|
-
logger.blank();
|
|
70
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fse from 'fs-extra';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Copy the current OpenAPI spec over the snapshot baseline.
|
|
6
|
-
* This is intentionally a manual, explicit action — never called automatically.
|
|
7
|
-
*
|
|
8
|
-
* @param {string} currentPath - Path to the current (live) OpenAPI spec.
|
|
9
|
-
* @param {string} snapshotPath - Path to the snapshot file to overwrite.
|
|
10
|
-
*/
|
|
11
|
-
export async function updateSnapshot(currentPath, snapshotPath) {
|
|
12
|
-
const resolvedCurrent = path.resolve(currentPath);
|
|
13
|
-
const resolvedSnapshot = path.resolve(snapshotPath);
|
|
14
|
-
|
|
15
|
-
if (!(await fse.pathExists(resolvedCurrent))) {
|
|
16
|
-
throw new Error(`Current OpenAPI spec not found: ${resolvedCurrent}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
await fse.copy(resolvedCurrent, resolvedSnapshot, { overwrite: true });
|
|
20
|
-
console.log(`✅ Snapshot updated: ${resolvedSnapshot}`);
|
|
21
|
-
console.log(` Source: ${resolvedCurrent}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export default async function updateSnapshotCmd(opts) {
|
|
25
|
-
const { current, snapshot } = opts;
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
await updateSnapshot(current, snapshot);
|
|
29
|
-
console.log('\nBaseline established. Commit the updated snapshot to your test repo to record the new contract.');
|
|
30
|
-
} catch (err) {
|
|
31
|
-
console.error(`\n❌ ${err.message}`);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
}
|