@skyramp/mcp 0.0.31 → 0.0.32
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/build/index.js +10 -5
- package/build/prompts/code-reuse.js +101 -0
- package/build/prompts/fix-error-prompt.js +29 -0
- package/build/prompts/modularization/integration-test-modularization.js +92 -0
- package/build/prompts/modularization/ui-test-modularization.js +177 -0
- package/build/prompts/testGenerationPrompt.js +76 -0
- package/build/services/ModularizationService.js +26 -5
- package/build/services/ScenarioGenerationService.js +167 -0
- package/build/services/TestGenerationService.js +31 -5
- package/build/tools/__tests__/codeReuseTool.test.js +266 -0
- package/build/tools/codeReuseTool.js +45 -0
- package/build/tools/executeSkyrampTestTool.js +1 -1
- package/build/tools/fixErrorTool.js +1 -1
- package/build/tools/generateContractRestTool.js +2 -2
- package/build/tools/generateE2ERestTool.js +3 -2
- package/build/tools/generateFuzzRestTool.js +2 -2
- package/build/tools/generateIntegrationRestTool.js +7 -2
- package/build/tools/generateLoadRestTool.js +2 -2
- package/build/tools/generateScenarioRestTool.js +81 -0
- package/build/tools/generateSmokeRestTool.js +2 -2
- package/build/tools/generateUIRestTool.js +3 -2
- package/build/tools/modularizationTool.js +12 -5
- package/build/tools/startTraceCollectionTool.js +4 -4
- package/build/tools/stopTraceCollectionTool.js +11 -5
- package/build/types/TestTypes.js +20 -0
- package/build/utils/utils.js +19 -0
- package/build/utils/utils.test.js +34 -1
- package/package.json +2 -2
- package/build/prompts/modularization-prompts.js +0 -281
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ScenarioGenerationService } from "../services/ScenarioGenerationService.js";
|
|
3
|
+
import { baseSchema } from "../types/TestTypes.js";
|
|
4
|
+
const scenarioTestSchema = {
|
|
5
|
+
scenarioName: z
|
|
6
|
+
.string()
|
|
7
|
+
.describe("Name of the test scenario with multiple steps. Describe the complete workflow you want to test, including all actions and their sequence.KEEP IT SHORT AND DESCRIPTIVE AS USED FOR FILE NAME"),
|
|
8
|
+
apiSchema: z
|
|
9
|
+
.string()
|
|
10
|
+
.describe("MUST be absolute path (/path/to/openapi.json) to the OpenAPI/Swagger schema file or a URL to the OpenAPI/Swagger schema file (e.g. https://demoshop.skyramp.dev/openapi.json). Required for accurate API mapping."),
|
|
11
|
+
baseURL: z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Base URL for the API endpoints (e.g., https://demoshop.skyramp.dev/api/v1). If not provided, will be extracted from the API schema."),
|
|
15
|
+
prompt: z.string().describe("The prompt user provided to generate the test"),
|
|
16
|
+
// AI-parsed parameters (required)
|
|
17
|
+
method: z
|
|
18
|
+
.string()
|
|
19
|
+
.describe("HTTP method (GET, POST, PUT, DELETE, etc.) parsed by AI from the scenario"),
|
|
20
|
+
path: z
|
|
21
|
+
.string()
|
|
22
|
+
.describe("API path (e.g., /api/v1/products, /api/v1/orders/{product_id}) parsed by AI from the scenario"),
|
|
23
|
+
// AI-parsed parameters (optional)
|
|
24
|
+
requestBody: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("JSON string of the request body parsed by AI from the scenario"),
|
|
28
|
+
responseBody: z
|
|
29
|
+
.string()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("JSON string of the response body parsed by AI from the scenario"),
|
|
32
|
+
statusCode: z
|
|
33
|
+
.number()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("HTTP status code (e.g., 200, 201, 204) parsed by AI from the scenario"),
|
|
36
|
+
outputDir: baseSchema.shape.outputDir,
|
|
37
|
+
};
|
|
38
|
+
export function registerScenarioTestTool(server) {
|
|
39
|
+
server.registerTool("skyramp_scenario_test_generation", {
|
|
40
|
+
description: `Generate a single trace request from AI-parsed scenario parameters.
|
|
41
|
+
|
|
42
|
+
This tool generates a single TraceRequest object using parameters that have been parsed by AI from a natural language scenario. The AI should analyze the scenario and provide structured parameters instead of relying on hardcoded parsing logic.
|
|
43
|
+
|
|
44
|
+
**What it does:**
|
|
45
|
+
1. **Accept AI-Parsed Data**: Takes structured parameters parsed by AI from natural language
|
|
46
|
+
2. **Generate Trace Request**: Creates a single TraceRequest object with proper format
|
|
47
|
+
3. **File Management**: Appends the request to an existing trace file or creates a new one
|
|
48
|
+
4. **Dynamic Source**: IF DNS NAME IS PROVIDED, USE IT FOR SOURCE IP AND PORT
|
|
49
|
+
|
|
50
|
+
**Output:**
|
|
51
|
+
Returns a single TraceRequest object with:
|
|
52
|
+
- Dynamic source IP and port
|
|
53
|
+
- Destination host (extracted from API schema)
|
|
54
|
+
- HTTP method and path (provided by AI)
|
|
55
|
+
- Request and response bodies (provided by AI or generated)
|
|
56
|
+
- Request and response headers
|
|
57
|
+
- Status code and timestamp
|
|
58
|
+
- Network details (port, scheme)
|
|
59
|
+
|
|
60
|
+
**AI Responsibilities:**
|
|
61
|
+
The AI should parse the natural language scenario and provide:
|
|
62
|
+
- HTTP method (POST, GET, PUT, DELETE)
|
|
63
|
+
- API path (e.g., /api/v1/products, /api/v1/products/{product_id})
|
|
64
|
+
- Request body (JSON string, if applicable)
|
|
65
|
+
- Response body (JSON string, if applicable)
|
|
66
|
+
- Status code (optional, defaults based on method)
|
|
67
|
+
- Entity details (name, price, quantity, ID as needed)
|
|
68
|
+
|
|
69
|
+
**Requirements:**
|
|
70
|
+
- Natural language scenario description
|
|
71
|
+
- API schema (OpenAPI/Swagger file or URL) for destination extraction
|
|
72
|
+
- AI-parsed HTTP method and path (required)
|
|
73
|
+
- AI-parsed request/response bodies (optional)
|
|
74
|
+
|
|
75
|
+
**Note:** This tool generates one request at a time. Call multiple times for multi-step scenarios.`,
|
|
76
|
+
inputSchema: scenarioTestSchema,
|
|
77
|
+
}, async (params) => {
|
|
78
|
+
const service = new ScenarioGenerationService();
|
|
79
|
+
return await service.parseScenario(params);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { baseTestSchema } from "../types/TestTypes.js";
|
|
1
|
+
import { baseTestSchema, TestType } from "../types/TestTypes.js";
|
|
2
2
|
import { TestGenerationService, } from "../services/TestGenerationService.js";
|
|
3
3
|
import z from "zod";
|
|
4
4
|
// Concrete implementations for each test type
|
|
5
5
|
export class SmokeTestService extends TestGenerationService {
|
|
6
6
|
getTestType() {
|
|
7
|
-
return
|
|
7
|
+
return TestType.SMOKE;
|
|
8
8
|
}
|
|
9
9
|
buildGenerationOptions(params) {
|
|
10
10
|
return super.buildBaseGenerationOptions(params);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { baseSchema, languageSchema } from "../types/TestTypes.js";
|
|
1
|
+
import { baseSchema, languageSchema, TestType, codeRefactoringSchema, } from "../types/TestTypes.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { TestGenerationService, } from "../services/TestGenerationService.js";
|
|
4
4
|
export class UITestService extends TestGenerationService {
|
|
5
5
|
getTestType() {
|
|
6
|
-
return
|
|
6
|
+
return TestType.UI;
|
|
7
7
|
}
|
|
8
8
|
buildGenerationOptions(params) {
|
|
9
9
|
const options = this.buildBaseGenerationOptions(params);
|
|
@@ -25,6 +25,7 @@ const uiTestSchema = {
|
|
|
25
25
|
output: baseSchema.shape.output,
|
|
26
26
|
outputDir: baseSchema.shape.outputDir,
|
|
27
27
|
force: baseSchema.shape.force,
|
|
28
|
+
...codeRefactoringSchema.shape,
|
|
28
29
|
};
|
|
29
30
|
export function registerUITestTool(server) {
|
|
30
31
|
server.registerTool("skyramp_ui_test_generation", {
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ModularizationService, } from "../services/ModularizationService.js";
|
|
3
2
|
import { logger } from "../utils/logger.js";
|
|
3
|
+
import { TestType } from "../types/TestTypes.js";
|
|
4
|
+
import { ModularizationService, } from "../services/ModularizationService.js";
|
|
4
5
|
const modularizationSchema = {
|
|
5
6
|
testFile: z
|
|
6
7
|
.string()
|
|
7
8
|
.describe("The test file to process with modularization principles applied"),
|
|
8
9
|
language: z.string().describe("The programming language of the test file"),
|
|
9
10
|
testType: z
|
|
10
|
-
.
|
|
11
|
-
.describe("
|
|
11
|
+
.enum([TestType.UI, TestType.E2E, TestType.INTEGRATION])
|
|
12
|
+
.describe("Specifies the type of test (UI, E2E, or Integration)"),
|
|
12
13
|
prompt: z
|
|
13
14
|
.string()
|
|
14
15
|
.describe("The prompt or code content to process with modularization principles applied"),
|
|
15
16
|
};
|
|
16
17
|
export function registerModularizationTool(server) {
|
|
17
18
|
server.registerTool("skyramp_modularization", {
|
|
18
|
-
description: `
|
|
19
|
-
|
|
19
|
+
description: `Provides modularization instructions and test file content. YOU MUST immediately modularize the code and write it back to the file. The tool returns:
|
|
20
|
+
1. Complete modularization instructions
|
|
21
|
+
2. The current test file content
|
|
22
|
+
3. Step-by-step requirements you must complete
|
|
23
|
+
|
|
24
|
+
After modularization, if errors remain, call skyramp_fix_errors.
|
|
25
|
+
|
|
26
|
+
CRITICAL: This tool expects you to complete the modularization by writing the refactored code back to the file.`,
|
|
20
27
|
inputSchema: modularizationSchema,
|
|
21
28
|
annotations: {
|
|
22
29
|
keywords: [
|
|
@@ -44,7 +44,7 @@ For detailed documentation visit: https://www.skyramp.dev/docs/load-test/advance
|
|
|
44
44
|
.describe("List of hosts or patterns that should bypass proxy during tracing"),
|
|
45
45
|
dockerNetwork: z
|
|
46
46
|
.string()
|
|
47
|
-
.default("")
|
|
47
|
+
.default("skyramp")
|
|
48
48
|
.describe("Docker network name to use for containerized trace collection"),
|
|
49
49
|
dockerWorkerPort: z
|
|
50
50
|
.number()
|
|
@@ -71,9 +71,9 @@ For detailed documentation visit: https://www.skyramp.dev/docs/load-test/advance
|
|
|
71
71
|
const client = new SkyrampClient();
|
|
72
72
|
const generateOptions = {
|
|
73
73
|
testType: "trace",
|
|
74
|
-
runtime: params.runtime
|
|
75
|
-
dockerNetwork: params.dockerNetwork
|
|
76
|
-
dockerWorkerPort:
|
|
74
|
+
runtime: params.runtime,
|
|
75
|
+
dockerNetwork: params.dockerNetwork,
|
|
76
|
+
dockerWorkerPort: params.dockerWorkerPort.toString(),
|
|
77
77
|
generateInclude: params.include,
|
|
78
78
|
generateExclude: params.exclude,
|
|
79
79
|
generateNoProxy: params.noProxy,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SkyrampClient } from "@skyramp/skyramp";
|
|
2
2
|
import { closeProxyTerminal } from "../utils/proxy-terminal.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { TELEMETRY_entrypoint_FIELD_NAME
|
|
4
|
+
import { TELEMETRY_entrypoint_FIELD_NAME } from "../utils/utils.js";
|
|
5
5
|
import { logger } from "../utils/logger.js";
|
|
6
6
|
import { baseSchema } from "../types/TestTypes.js";
|
|
7
7
|
import { existsSync, mkdirSync } from "fs";
|
|
@@ -22,13 +22,15 @@ For detailed documentation visit: https://www.skyramp.dev/docs/load-test/advance
|
|
|
22
22
|
inputSchema: {
|
|
23
23
|
traceOutputFile: z
|
|
24
24
|
.string()
|
|
25
|
-
.
|
|
25
|
+
.default("skyramp_traces.json")
|
|
26
|
+
.describe("File name to save the trace output file (e.g., skyramp_traces.json). This file will contain the collected backend trace data"),
|
|
26
27
|
playwrightEnabled: z
|
|
27
28
|
.boolean()
|
|
28
29
|
.describe("Whether Playwright was used for trace collection. Must match the setting used when starting trace collection"),
|
|
29
30
|
playwrightOutput: z
|
|
30
31
|
.string()
|
|
31
|
-
.
|
|
32
|
+
.default("skyramp_playwright.zip")
|
|
33
|
+
.describe("File name to save the Playwright output file (e.g., skyramp_playwright.zip). Only used when playwright is true"),
|
|
32
34
|
outputDir: baseSchema.shape.outputDir,
|
|
33
35
|
prompt: z
|
|
34
36
|
.string()
|
|
@@ -47,13 +49,17 @@ For detailed documentation visit: https://www.skyramp.dev/docs/load-test/advance
|
|
|
47
49
|
const client = new SkyrampClient();
|
|
48
50
|
try {
|
|
49
51
|
const stopTraceOptions = {
|
|
50
|
-
output: params.traceOutputFile
|
|
52
|
+
output: params.traceOutputFile,
|
|
51
53
|
workerContainerName: "skyramp-trace-worker",
|
|
52
54
|
playwright: params.playwrightEnabled ?? false,
|
|
53
|
-
playwrightOutput: params.playwrightOutput
|
|
55
|
+
playwrightOutput: params.playwrightOutput,
|
|
54
56
|
entrypoint: TELEMETRY_entrypoint_FIELD_NAME,
|
|
55
57
|
outputDir: params.outputDir,
|
|
56
58
|
};
|
|
59
|
+
// remove playwright trace file if playwright is disabled
|
|
60
|
+
if (!params.playwrightEnabled) {
|
|
61
|
+
stopTraceOptions.playwrightOutput = "";
|
|
62
|
+
}
|
|
57
63
|
// Check if output dir exists and if not create it.
|
|
58
64
|
if (!existsSync(params.outputDir)) {
|
|
59
65
|
mkdirSync(params.outputDir, { recursive: true });
|
package/build/types/TestTypes.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
export var TestType;
|
|
3
|
+
(function (TestType) {
|
|
4
|
+
TestType["SMOKE"] = "smoke";
|
|
5
|
+
TestType["FUZZ"] = "fuzz";
|
|
6
|
+
TestType["CONTRACT"] = "contract";
|
|
7
|
+
TestType["LOAD"] = "load";
|
|
8
|
+
TestType["INTEGRATION"] = "integration";
|
|
9
|
+
TestType["E2E"] = "e2e";
|
|
10
|
+
TestType["UI"] = "ui";
|
|
11
|
+
})(TestType || (TestType = {}));
|
|
2
12
|
export const languageSchema = z.object({
|
|
3
13
|
language: z
|
|
4
14
|
.string()
|
|
@@ -103,3 +113,13 @@ export const baseTestSchema = {
|
|
|
103
113
|
.describe("Expected HTTP response status code (e.g., '200', '201', '404'). DO NOT ASSUME STATUS CODE IF NOT PROVIDED"),
|
|
104
114
|
...baseSchema.shape,
|
|
105
115
|
};
|
|
116
|
+
export const codeRefactoringSchema = z.object({
|
|
117
|
+
codeReuse: z
|
|
118
|
+
.boolean()
|
|
119
|
+
.default(false)
|
|
120
|
+
.describe("Whether to reuse existing code"),
|
|
121
|
+
modularizeCode: z
|
|
122
|
+
.boolean()
|
|
123
|
+
.default(false)
|
|
124
|
+
.describe("Whether to modularize the code"),
|
|
125
|
+
});
|
package/build/utils/utils.js
CHANGED
|
@@ -12,6 +12,7 @@ export function IsValidKeyValueList(input) {
|
|
|
12
12
|
const regex = /^([a-zA-Z0-9_-]+)(,([a-zA-Z0-9_-]+))*$/;
|
|
13
13
|
return regex.test(input);
|
|
14
14
|
}
|
|
15
|
+
export const SKYRAMP_UTILS_HEADER = `Generated by Skyramp`;
|
|
15
16
|
export function getPathParameterValidationError(requiredPathParams) {
|
|
16
17
|
if (requiredPathParams.split(",").length > 1) {
|
|
17
18
|
return (`Please specify values for the following required path parameters: \n` +
|
|
@@ -116,3 +117,21 @@ export function validateRequestData(value) {
|
|
|
116
117
|
}
|
|
117
118
|
return null;
|
|
118
119
|
}
|
|
120
|
+
const COMMENT_PREFIX_MAP = {
|
|
121
|
+
python: "#",
|
|
122
|
+
java: "//",
|
|
123
|
+
javascript: "//",
|
|
124
|
+
typescript: "//",
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Generates a Skyramp header for generated files
|
|
128
|
+
* @param language The programming language for the file
|
|
129
|
+
* @returns The formatted header string
|
|
130
|
+
*/
|
|
131
|
+
export function generateSkyrampHeader(language) {
|
|
132
|
+
const now = new Date();
|
|
133
|
+
const timestamp = now.toISOString().replace("T", " ").replace("Z", "");
|
|
134
|
+
const timezone = now.toString().match(/\(([^)]+)\)$/)?.[1] || "UTC";
|
|
135
|
+
const commentPrefix = COMMENT_PREFIX_MAP[language] || "#";
|
|
136
|
+
return `${commentPrefix} ${SKYRAMP_UTILS_HEADER} on ${timestamp} ${timezone}\n\n`;
|
|
137
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
|
-
import { validateParams } from "./utils.js";
|
|
2
|
+
import { validateParams, generateSkyrampHeader } from "./utils.js";
|
|
3
3
|
describe("validateParams", () => {
|
|
4
4
|
it("should return null for valid comma-separated key=value pairs", () => {
|
|
5
5
|
const result = validateParams("foo=bar,baz=qux", "testField");
|
|
@@ -30,3 +30,36 @@ describe("validateParams", () => {
|
|
|
30
30
|
expect(result?.content?.[0].text).toMatch(/key=value/);
|
|
31
31
|
});
|
|
32
32
|
});
|
|
33
|
+
describe("generateSkyrampHeader", () => {
|
|
34
|
+
it("should generate correct header for Python", () => {
|
|
35
|
+
const header = generateSkyrampHeader("python");
|
|
36
|
+
expect(header).toMatch(/^# Generated by Skyramp v1\.2\.23 on/);
|
|
37
|
+
expect(header).toContain("\n\n");
|
|
38
|
+
});
|
|
39
|
+
it("should generate correct header for JavaScript", () => {
|
|
40
|
+
const header = generateSkyrampHeader("javascript");
|
|
41
|
+
expect(header).toMatch(/^\/\/ Generated by Skyramp v1\.2\.23 on/);
|
|
42
|
+
expect(header).toContain("\n\n");
|
|
43
|
+
});
|
|
44
|
+
it("should generate correct header for TypeScript", () => {
|
|
45
|
+
const header = generateSkyrampHeader("typescript");
|
|
46
|
+
expect(header).toMatch(/^\/\/ Generated by Skyramp v1\.2\.23 on/);
|
|
47
|
+
expect(header).toContain("\n\n");
|
|
48
|
+
});
|
|
49
|
+
it("should generate correct header for Java", () => {
|
|
50
|
+
const header = generateSkyrampHeader("java");
|
|
51
|
+
expect(header).toMatch(/^\/\/ Generated by Skyramp v1\.2\.23 on/);
|
|
52
|
+
expect(header).toContain("\n\n");
|
|
53
|
+
});
|
|
54
|
+
it("should generate correct header for unknown language", () => {
|
|
55
|
+
const header = generateSkyrampHeader("unknown");
|
|
56
|
+
expect(header).toMatch(/^# Generated by Skyramp v1\.2\.23 on/);
|
|
57
|
+
expect(header).toContain("\n\n");
|
|
58
|
+
});
|
|
59
|
+
it("should include timestamp in header", () => {
|
|
60
|
+
const header = generateSkyrampHeader("python");
|
|
61
|
+
// Check that the header contains a timestamp in the expected format
|
|
62
|
+
expect(header).toMatch(/on \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}/);
|
|
63
|
+
expect(header).toMatch(/Generated by Skyramp/);
|
|
64
|
+
});
|
|
65
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skyramp/mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@modelcontextprotocol/sdk": "^1.11.4",
|
|
45
|
-
"@skyramp/skyramp": "^1.2.
|
|
45
|
+
"@skyramp/skyramp": "^1.2.24",
|
|
46
46
|
"@playwright/test": "^1.55.0",
|
|
47
47
|
"dockerode": "^4.0.6",
|
|
48
48
|
"zod": "^3.25.3"
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
export function getModularizationPrompt(filePath, language) {
|
|
2
|
-
return `
|
|
3
|
-
**CRITICAL: Refactor code with modularization principles. Respond with complete, modularized code only WITHOUT ERRORS AND WRITTEN BACK TO THE FILE ${filePath}**
|
|
4
|
-
|
|
5
|
-
**CRITICAL: DO NOT CHANGE THE FUNCTIONALITY OF THE TESTS. ONLY MODULARIZE THE CODE.**
|
|
6
|
-
|
|
7
|
-
**ABSOLUTELY FORBIDDEN: DO NOT CREATE ANY INTERFACES, CLASSES, TYPES, OR NEW DATA STRUCTURES. USE INLINE TYPES ONLY.**
|
|
8
|
-
|
|
9
|
-
Only if NO existing function can be reused:
|
|
10
|
-
1. Group related lines logically (e.g., login steps together) to improve readability and parameterize the test function(s) with meaningful parameters to make it more flexible.
|
|
11
|
-
2. If functions are already modularized (like breakpoint_section_0, breakpoint_section_1), then rename them with meaningful names WITHOUT ANY OTHER CHANGES.
|
|
12
|
-
3. KEEP CHANGES TO A MINIMUM. DO NOT MODIFY THE FUNCTIONALITY OF THE TESTS. ONLY MODULARIZE THE CODE.
|
|
13
|
-
4. Parameterize the test function(s) with meaningful parameters to make it more flexible. Preserve the original order of code lines within each function.
|
|
14
|
-
5. Only extract reusable logical sections into helper functions. Use inline parameter types instead of creating interfaces or type definitions.
|
|
15
|
-
|
|
16
|
-
**IMPORT CLEANUP AFTER MODULARIZATION:**
|
|
17
|
-
After applying modularization principles:
|
|
18
|
-
1. **Analyze Remaining Imports**: Review all import statements at the top of the file
|
|
19
|
-
2. **Identify Unused Imports**: Check which imported modules, functions, or classes are no longer referenced in the modularized code
|
|
20
|
-
3. **Remove Unused Imports**: Delete any import statements that are not used in the final modularized code
|
|
21
|
-
4. **Preserve Required Imports**: Keep all imports that are actually used by the modularized functions
|
|
22
|
-
5. **Maintain Import Order**: Preserve the original ordering of remaining imports for consistency
|
|
23
|
-
|
|
24
|
-
**IMPORT REMOVAL RULES:**
|
|
25
|
-
- Only remove imports that are completely unused after modularization
|
|
26
|
-
- Keep imports used by any function, even if usage decreased
|
|
27
|
-
- Preserve imports for types used in function parameters (inline types)
|
|
28
|
-
- Do not remove imports for testing frameworks or utilities
|
|
29
|
-
- Maintain proper import syntax and formatting
|
|
30
|
-
|
|
31
|
-
**LANGUAGE-SPECIFIC IMPORT HANDLING:**
|
|
32
|
-
- **Python**: Remove unused import and from...import statements
|
|
33
|
-
- **JavaScript/TypeScript**: Remove unused import and require() statements
|
|
34
|
-
- **Java**: Remove unused import statements
|
|
35
|
-
- **All Languages**: Preserve framework-specific imports (testing libraries, etc.)
|
|
36
|
-
|
|
37
|
-
**CRITICAL CONSTRAINTS:**
|
|
38
|
-
- NO interfaces, classes, types, or data structures
|
|
39
|
-
- NO new test cases or logic
|
|
40
|
-
- NO additional files
|
|
41
|
-
- ONLY helper functions with inline types
|
|
42
|
-
- PRESERVE original functionality exactly
|
|
43
|
-
- REMOVE unused imports after modularization
|
|
44
|
-
- DO NOT CREATE/UPDATE package.json or requirements.txt or pom.xml or build.gradle file
|
|
45
|
-
|
|
46
|
-
**CRITICAL: If you skip any step, the modularization is incomplete. You MUST complete all steps before proceeding.FIX ERRORS IN MODULARIZED CODE USING skyramp_fix_errors TOOL**
|
|
47
|
-
`;
|
|
48
|
-
}
|
|
49
|
-
export function getFixErrorsPrompt() {
|
|
50
|
-
return `
|
|
51
|
-
**Fix errors in refactored code.**
|
|
52
|
-
|
|
53
|
-
1. **Parameter Passing:** Identify functions using variables from outside scope (like 'page' object). Pass these as parameters.
|
|
54
|
-
2. **Validate Correctness:** Ensure code is free of reference errors, undefined variables, runtime issues.
|
|
55
|
-
3. **Import Paths:** Ensure import paths are correct and there are no circular imports.
|
|
56
|
-
4. **Import Validation:** Ensure all remaining imports are necessary and no missing imports cause reference errors.
|
|
57
|
-
5. **Unused Import Cleanup:** Verify that unused imports were properly removed without breaking functionality.
|
|
58
|
-
6. **UI State Management:** Check for UI state conflicts, modal interference, or element interaction issues.
|
|
59
|
-
7. **Sequential Operations:** Ensure UI operations don't interfere with each other when called in sequence.
|
|
60
|
-
|
|
61
|
-
**IMPORT ERROR DEBUGGING:**
|
|
62
|
-
- Check for missing imports that cause undefined reference errors
|
|
63
|
-
- Verify that import removal didn't break existing functionality
|
|
64
|
-
- Ensure all imported modules are actually available in the project
|
|
65
|
-
- Confirm that import syntax is correct for the target language
|
|
66
|
-
|
|
67
|
-
**CRITICAL CONSTRAINTS:**
|
|
68
|
-
- DO NOT CREATE/UPDATE package.json or requirements.txt or pom.xml or build.gradle file
|
|
69
|
-
- NEVER create dependency management files, even when linting errors suggest missing dependencies
|
|
70
|
-
- Focus on fixing code errors within existing files only
|
|
71
|
-
|
|
72
|
-
**KEY: Variables not defined within function scope MUST be passed as parameters.**
|
|
73
|
-
**UI KEY: Helper functions that perform UI operations must be self-contained and not leave modals/dialogs open.**
|
|
74
|
-
**IMPORT KEY: All imports must be either used in the code or properly removed.**
|
|
75
|
-
**DEPENDENCY KEY: DO NOT create package.json, requirements.txt, or any dependency files regardless of linting errors.**
|
|
76
|
-
`;
|
|
77
|
-
}
|
|
78
|
-
export function getModularizationPromptForUI(filePath, language) {
|
|
79
|
-
return `
|
|
80
|
-
**CRITICAL: Refactor code with modularization principles. Respond with complete, modularized code only WITHOUT ERRORS AND WRITTEN BACK TO THE FILE ${filePath}**
|
|
81
|
-
|
|
82
|
-
**CRITICAL: DO NOT CHANGE THE FUNCTIONALITY OF THE TESTS. ONLY MODULARIZE THE CODE.**
|
|
83
|
-
|
|
84
|
-
**ABSOLUTELY FORBIDDEN: DO NOT CREATE ANY INTERFACES, CLASSES, TYPES, OR NEW DATA STRUCTURES. USE INLINE TYPES ONLY.**
|
|
85
|
-
|
|
86
|
-
**COMMON UI TEST FAILURE: Many UI tests fail after modularization because navigation steps between similar operations are incorrectly moved into helper functions. This breaks the test flow and causes timeouts.**
|
|
87
|
-
|
|
88
|
-
**COMMON CALCULATION FAILURE: UI tests fail when complex logic patterns (loops, conditionals, array handling) are incorrectly generalized in helper functions, causing wrong quantities, prices, or missing operations.**
|
|
89
|
-
|
|
90
|
-
**COMMON SELECTOR FAILURE: UI tests fail when specific selectors are generalized into generic ones, causing wrong elements to be clicked.**
|
|
91
|
-
|
|
92
|
-
**MANDATORY ANALYSIS BEFORE MODULARIZATION:**
|
|
93
|
-
Before creating any helper functions, identify ALL critical patterns in the original test:
|
|
94
|
-
- Look for patterns like: page.getByTestId("navbar-*").click()
|
|
95
|
-
- Look for patterns like: page.goto()
|
|
96
|
-
- Look for patterns like: page.goBack()
|
|
97
|
-
- Look for complex loops with conditionals or null handling
|
|
98
|
-
- Look for unique sequences that differ between similar operations
|
|
99
|
-
- Look for specific selector chains that target exact elements
|
|
100
|
-
- These MUST remain in the main test function in their EXACT original positions and logic
|
|
101
|
-
|
|
102
|
-
**CRITICAL RULE: If the original test performs operations in a specific sequence with unique logic for each step, DO NOT generalize this into a loop or helper function. Keep the exact original sequence.**
|
|
103
|
-
|
|
104
|
-
**SELECTOR PRESERVATION RULE: If the original test uses specific selector chains, DO NOT generalize them into generic selectors. Preserve the exact selector specificity.**
|
|
105
|
-
|
|
106
|
-
STEPS:
|
|
107
|
-
1. **PRESERVE EXACT UI SEQUENCE**: For UI TESTS, maintain the EXACT sequence of UI interactions. Do NOT extract steps that break the natural flow.
|
|
108
|
-
2. **CAREFUL EXTRACTION**: Only extract helper functions for COMPLETE, REPEATABLE workflows that do NOT include navigation between different pages/sections and do NOT contain complex conditional logic.
|
|
109
|
-
3. **PRESERVE UNIQUE STEPS**: If a workflow has unique steps (like clicking specific labels), DO NOT extract it into a generic helper function.
|
|
110
|
-
4. **PRESERVE COMPLEX LOGIC**: If the original test has loops, conditionals, or array processing with unique patterns, DO NOT generalize these - keep them exactly as written.
|
|
111
|
-
5. **PRESERVE SPECIFIC SELECTORS**: If the original test uses specific selector chains, maintain the exact same selectors in helper functions. Do not make them more generic.
|
|
112
|
-
6. **RESPONSE PROMISES**: Maintain the exact timing of response promise creation and awaiting. Do not move these into helper functions unless the entire request-response cycle is contained.
|
|
113
|
-
7. **PARAMETERIZATION**: When creating helper functions, ensure ALL required parameters (page, data objects, response promises) are passed correctly.
|
|
114
|
-
8. **VALIDATION**: Each extracted function must work independently without relying on external scope variables.
|
|
115
|
-
9. **PRESERVE ORIGINAL FLOW**: If the original code has different patterns for similar operations (like product creation), preserve those differences - they exist for a reason.
|
|
116
|
-
10. **NAVIGATION PRESERVATION**: CRITICAL - If the original test has navigation steps between similar operations (like clicking "navbar-products" between product creations), these MUST be preserved in the main test flow, NOT moved into helper functions.
|
|
117
|
-
|
|
118
|
-
**WHAT SHOULD BE EXTRACTED (SAFE TO EXTRACT):**
|
|
119
|
-
- Simple form filling sequences within a single page/modal
|
|
120
|
-
- Basic button clicking sequences within a single workflow that use the same specific selectors
|
|
121
|
-
- Simple data entry that doesn't change page state
|
|
122
|
-
- Basic assertions and validations within the same page context
|
|
123
|
-
|
|
124
|
-
**WHAT SHOULD NEVER BE EXTRACTED (KEEP IN MAIN TEST):**
|
|
125
|
-
- Navigation between pages (navbar clicks, page.goto)
|
|
126
|
-
- Steps that change the overall page context
|
|
127
|
-
- Sequences that span multiple pages or sections
|
|
128
|
-
- Any step that affects where the user is in the application
|
|
129
|
-
- Complex loops with conditionals or special handling
|
|
130
|
-
- Operations with unique patterns that differ between similar workflows
|
|
131
|
-
- Array processing with null handling or special indexing
|
|
132
|
-
- Button clicks with complex selector chains that are unique to specific contexts
|
|
133
|
-
|
|
134
|
-
**IMPORT CLEANUP AFTER MODULARIZATION:**
|
|
135
|
-
After applying modularization principles:
|
|
136
|
-
1. **Analyze Remaining Imports**: Review all import statements at the top of the file
|
|
137
|
-
2. **Identify Unused Imports**: Check which imported modules, functions, or classes are no longer referenced in the modularized code
|
|
138
|
-
3. **Remove Unused Imports**: Delete any import statements that are not used in the final modularized code
|
|
139
|
-
4. **Preserve Required Imports**: Keep all imports that are actually used by the modularized functions
|
|
140
|
-
5. **Maintain Import Order**: Preserve the original ordering of remaining imports for consistency
|
|
141
|
-
|
|
142
|
-
**UI-SPECIFIC IMPORT CONSIDERATIONS:**
|
|
143
|
-
- Preserve all Playwright/testing framework imports (page, expect, test, etc.)
|
|
144
|
-
- Keep UI-specific utility imports even if usage appears reduced
|
|
145
|
-
- Maintain browser-specific imports that may be needed for UI operations
|
|
146
|
-
- Do not remove imports for UI components or page object models
|
|
147
|
-
- Preserve imports for locators, selectors, and UI interaction utilities
|
|
148
|
-
|
|
149
|
-
**IMPORT REMOVAL RULES FOR UI TESTS:**
|
|
150
|
-
- Only remove imports that are completely unused after modularization
|
|
151
|
-
- Keep imports used by any function, even if usage decreased
|
|
152
|
-
- Preserve imports for types used in function parameters (inline types)
|
|
153
|
-
- Do not remove imports for testing frameworks or utilities
|
|
154
|
-
- Maintain proper import syntax and formatting
|
|
155
|
-
- Be extra cautious with UI framework imports - they may be used in ways not immediately obvious
|
|
156
|
-
|
|
157
|
-
**LANGUAGE-SPECIFIC UI IMPORT HANDLING:**
|
|
158
|
-
- **Python**: Remove unused import and from...import statements, but keep pytest, playwright imports
|
|
159
|
-
- **JavaScript/TypeScript**: Remove unused import and require() statements, but preserve @playwright/test imports
|
|
160
|
-
- **Java**: Remove unused import statements, but keep testing framework imports
|
|
161
|
-
- **All Languages**: Always preserve UI testing framework and browser automation imports
|
|
162
|
-
|
|
163
|
-
**CRITICAL CONSTRAINTS:**
|
|
164
|
-
- NO interfaces, classes, types, or data structures
|
|
165
|
-
- DO NOT CREATE/UPDATE package.json or requirements.txt or pom.xml or build.gradle file
|
|
166
|
-
- NO changes to the core UI interaction sequence
|
|
167
|
-
- NO extraction of partial workflows that depend on external state
|
|
168
|
-
- NO generalization of complex logic patterns into loops or helper functions
|
|
169
|
-
- NO generalization of specific selectors into generic ones
|
|
170
|
-
- ONLY extract COMPLETE, self-contained operations that occur within the same page context
|
|
171
|
-
- PRESERVE original functionality exactly
|
|
172
|
-
- DO NOT extract steps that have unique UI interactions
|
|
173
|
-
- DO NOT move navigation steps (like navbar clicks) into helper functions - keep them in the main test flow
|
|
174
|
-
- PRESERVE all navigation between similar operations exactly as in the original test
|
|
175
|
-
- PRESERVE all specific selector chains exactly as in the original test
|
|
176
|
-
- NAVIGATION STEPS MUST REMAIN IN THE MAIN TEST FUNCTION TO MAINTAIN PROPER PAGE STATE
|
|
177
|
-
- COMPLEX LOGIC PATTERNS MUST REMAIN IN THE MAIN TEST FUNCTION TO MAINTAIN EXACT BEHAVIOR
|
|
178
|
-
- SPECIFIC SELECTORS MUST BE PRESERVED TO ENSURE CORRECT ELEMENT TARGETING
|
|
179
|
-
- REMOVE unused imports after modularization (following UI-specific import rules)
|
|
180
|
-
|
|
181
|
-
**BEFORE SUBMITTING: Double-check that every navigation step, complex operation, and specific selector from the original test appears in the same position with the same logic in the main test function.**
|
|
182
|
-
|
|
183
|
-
**CRITICAL: If you skip any step, the modularization is incomplete. You MUST complete all steps before proceeding.FIX ERRORS IN MODULARIZED CODE USING skyramp_fix_errors TOOL**
|
|
184
|
-
`;
|
|
185
|
-
}
|
|
186
|
-
export function getFixErrorsPromptForUI() {
|
|
187
|
-
return `
|
|
188
|
-
**Fix errors in refactored code.**
|
|
189
|
-
|
|
190
|
-
**COMMON UI TEST TIMEOUT ERROR: Test timeouts often occur when navigation steps are incorrectly moved into helper functions, causing the page to be in the wrong state when trying to interact with elements.**
|
|
191
|
-
|
|
192
|
-
**COMMON UI TEST CALCULATION ERROR: Order totals, quantities, or other calculated values may be incorrect if the original test's unique logic was incorrectly generalized in helper functions.**
|
|
193
|
-
|
|
194
|
-
**COMMON UI TEST SELECTOR ERROR: Tests fail when specific selectors are replaced with generic ones, causing wrong elements to be clicked or interacted with.**
|
|
195
|
-
|
|
196
|
-
**IMMEDIATE TIMEOUT DEBUGGING STEPS:**
|
|
197
|
-
1. Compare the original test and modularized test side by side
|
|
198
|
-
2. Identify every navigation step in the original (navbar clicks, page.goto, etc.)
|
|
199
|
-
3. Verify each navigation step appears in the EXACT same position in the main test function
|
|
200
|
-
4. If any navigation step was moved into a helper function, move it back to the main test
|
|
201
|
-
|
|
202
|
-
**IMMEDIATE CALCULATION ERROR DEBUGGING STEPS:**
|
|
203
|
-
1. Compare the exact sequence of operations in the original vs modularized test
|
|
204
|
-
2. Check if helper functions are skipping steps that the original test performed
|
|
205
|
-
3. Verify that loops and conditional logic in helper functions match the original exactly
|
|
206
|
-
4. Look for cases where null/empty values in data arrays are handled differently
|
|
207
|
-
|
|
208
|
-
**IMMEDIATE SELECTOR ERROR DEBUGGING STEPS:**
|
|
209
|
-
1. Compare selectors in the original vs modularized test
|
|
210
|
-
2. Check if specific selector chains were replaced with generic selectors
|
|
211
|
-
3. Verify that helper functions use the same exact selectors as the original
|
|
212
|
-
4. Look for cases where container-specific selectors were made too generic
|
|
213
|
-
|
|
214
|
-
**DETAILED FIX STEPS:**
|
|
215
|
-
1. **UI Sequence Validation**: Verify that the exact UI interaction sequence from the original test is preserved. Check for missing clicks, form openings, or navigation steps.
|
|
216
|
-
2. **Navigation Step Preservation**: CRITICAL - Ensure all navigation steps between similar operations (like "navbar-products" clicks between product creations) are preserved in the main test flow, not moved into helper functions.
|
|
217
|
-
3. **Page State Debugging**: If test is timing out on element interactions, check if the page is in the expected state. Often this means navigation steps were incorrectly extracted.
|
|
218
|
-
4. **Logic Preservation**: If test has incorrect calculations or missing operations, check if helper functions are generalizing logic that should remain unique to each operation.
|
|
219
|
-
5. **Selector Preservation**: If test is clicking wrong elements or failing to find elements, check if specific selectors were made too generic in helper functions.
|
|
220
|
-
6. **Parameter Passing**: Identify functions using variables from outside scope (like 'page' object, response promises, test data). Pass these as parameters.
|
|
221
|
-
7. **Response Promise Timing**: Ensure response promises are created and awaited at the exact same points as the original test.
|
|
222
|
-
8. **Unique Workflow Preservation**: If the original test has unique steps for similar operations, ensure these are preserved and not generalized incorrectly.
|
|
223
|
-
9. **Complete Workflow Validation**: Ensure that extracted helper functions contain COMPLETE workflows, not partial steps that depend on external state.
|
|
224
|
-
10. **Page State Management**: Verify that helper functions don't assume specific page states - the main test should handle navigation between different pages/states.
|
|
225
|
-
11. **Import Validation**: Ensure all remaining imports are necessary and no missing imports cause reference errors.
|
|
226
|
-
12. **Unused Import Cleanup**: Verify that unused imports were properly removed without breaking UI test functionality.
|
|
227
|
-
13. **UI Framework Import Preservation**: Ensure that critical UI testing imports (Playwright, testing frameworks) were not accidentally removed.
|
|
228
|
-
14. **Validate Correctness**: Ensure code is free of reference errors, undefined variables, runtime issues.
|
|
229
|
-
15. **Import Paths**: Ensure import paths are correct and there are no circular imports.
|
|
230
|
-
|
|
231
|
-
**TIMEOUT DEBUGGING CHECKLIST:**
|
|
232
|
-
- Are all navigation steps (navbar clicks, page.goto) in the main test function?
|
|
233
|
-
- Do helper functions only contain self-contained operations without navigation?
|
|
234
|
-
- Is the page in the expected state before each helper function call?
|
|
235
|
-
- Are there any missing navigation steps between operations?
|
|
236
|
-
- Compare line-by-line: does the main test flow match the original test flow exactly?
|
|
237
|
-
|
|
238
|
-
**CALCULATION ERROR DEBUGGING CHECKLIST:**
|
|
239
|
-
- Are all operations from the original test being performed in the modularized version?
|
|
240
|
-
- Do helper functions handle null/empty values the same way as the original?
|
|
241
|
-
- Are loops and conditionals in helper functions exact matches to the original logic?
|
|
242
|
-
- Are quantities, prices, and other data values being processed identically?
|
|
243
|
-
|
|
244
|
-
**SELECTOR ERROR DEBUGGING CHECKLIST:**
|
|
245
|
-
- Are all selectors in helper functions exactly the same as in the original test?
|
|
246
|
-
- Were any specific container-based selectors replaced with generic ones?
|
|
247
|
-
- Do button clicks use the same selector specificity as the original?
|
|
248
|
-
- Are there any ambiguous selectors that could match multiple elements?
|
|
249
|
-
|
|
250
|
-
**IMPORT ERROR DEBUGGING CHECKLIST:**
|
|
251
|
-
- Are there any undefined reference errors due to missing imports?
|
|
252
|
-
- Were any critical UI framework imports (page, expect, test) accidentally removed?
|
|
253
|
-
- Do all remaining imports correspond to actually used functionality?
|
|
254
|
-
- Are import paths correct and accessible in the project structure?
|
|
255
|
-
- Were any imports removed that are used in non-obvious ways (like in string templates)?
|
|
256
|
-
|
|
257
|
-
**SPECIFIC FIX FOR COMMON ERRORS:**
|
|
258
|
-
If you see timeout on button clicks or element interactions:
|
|
259
|
-
- Check if navigation steps were moved into helper functions and move them back to main test
|
|
260
|
-
- Check if specific selectors were made generic and restore original selector specificity
|
|
261
|
-
- Verify the page is in the expected state before each interaction
|
|
262
|
-
|
|
263
|
-
If you see incorrect calculations or missing operations:
|
|
264
|
-
- Check if unique logic patterns were incorrectly generalized
|
|
265
|
-
- Verify all operations from original test are present in modularized version
|
|
266
|
-
- Look for null value handling differences
|
|
267
|
-
|
|
268
|
-
If you see import or reference errors:
|
|
269
|
-
- Check if critical UI framework imports were accidentally removed
|
|
270
|
-
- Verify all remaining imports are necessary and properly used
|
|
271
|
-
- Restore any imports needed for UI interactions, even if usage seems minimal
|
|
272
|
-
- Confirm import paths match the project structure
|
|
273
|
-
|
|
274
|
-
**KEY: Every UI interaction from the original test must be present in the modularized version.**
|
|
275
|
-
**CRITICAL: Helper functions should only contain COMPLETE, self-contained workflows.**
|
|
276
|
-
**NAVIGATION KEY: Navigation steps between operations must remain in the main test flow to maintain proper page state.**
|
|
277
|
-
**CALCULATION KEY: Unique logic patterns should not be generalized if they produce different results.**
|
|
278
|
-
**SELECTOR KEY: Specific selectors must be preserved to ensure correct element targeting.**
|
|
279
|
-
**IMPORT KEY: All necessary imports must be preserved, especially UI framework imports.**
|
|
280
|
-
`;
|
|
281
|
-
}
|