@skyramp/mcp 0.2.8 → 0.2.150-rc.ldw-
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/commands/commandLibrary.d.ts +1 -0
- package/build/commands/commandLibrary.js +17 -14
- package/build/commands/localDevTestChangesCommand.d.ts +15 -0
- package/build/commands/localDevTestChangesCommand.js +188 -0
- package/build/index.js +74 -13
- package/build/prompts/enhance-assertions/sharedAssertionRules.d.ts +1 -0
- package/build/prompts/enhance-assertions/sharedAssertionRules.js +17 -0
- package/build/prompts/initialize-workspace/initializeWorkspacePrompt.js +7 -6
- package/build/prompts/local-dev/local-dev-plan.d.ts +25 -0
- package/build/prompts/local-dev/local-dev-plan.js +413 -0
- package/build/prompts/local-dev/local-dev-prompts.d.ts +4 -0
- package/build/prompts/local-dev/local-dev-prompts.js +155 -0
- package/build/prompts/prompt-utils.d.ts +8 -0
- package/build/prompts/prompt-utils.js +33 -0
- package/build/prompts/sut-setup/modes/adaptWorkflowPrompt.js +3 -1
- package/build/prompts/sut-setup/modes/dockerComposePrompt.js +3 -1
- package/build/prompts/sut-setup/shared.d.ts +20 -0
- package/build/prompts/sut-setup/shared.js +69 -7
- package/build/prompts/test-recommendation/analysisOutputPrompt.js +21 -29
- package/build/prompts/test-recommendation/analysisOutputPrompt.test.js +0 -28
- package/build/prompts/test-recommendation/test-recommendation-prompt.js +41 -4
- package/build/prompts/test-recommendation/test-recommendation-prompt.test.js +16 -1
- package/build/prompts/testbot/testbot-prompts.d.ts +0 -5
- package/build/prompts/testbot/testbot-prompts.js +4 -34
- package/build/resources/testbotResource.js +2 -1
- package/build/services/TestExecutionService.d.ts +2 -1
- package/build/services/TestExecutionService.js +9 -9
- package/build/services/TestExecutionService.test.js +42 -1
- package/build/services/TestGenerationService.d.ts +2 -2
- package/build/tool-phases.js +4 -0
- package/build/tools/code-refactor/enhanceAssertionsTool.js +42 -18
- package/build/tools/enrichTestWithMocksTool.d.ts +15 -0
- package/build/tools/enrichTestWithMocksTool.js +413 -0
- package/build/tools/enrichTestWithMocksTool.test.d.ts +1 -0
- package/build/tools/enrichTestWithMocksTool.test.js +60 -0
- package/build/tools/executeSkyrampTestTool.d.ts +4 -0
- package/build/tools/executeSkyrampTestTool.js +39 -18
- package/build/tools/executeSkyrampTestTool.test.d.ts +1 -0
- package/build/tools/executeSkyrampTestTool.test.js +16 -0
- package/build/tools/generate-tests/batchMockGenerationTool.d.ts +79 -0
- package/build/tools/generate-tests/batchMockGenerationTool.js +395 -0
- package/build/tools/generate-tests/generateContractRestTool.js +2 -2
- package/build/tools/generate-tests/generateMockRestTool.d.ts +56 -6
- package/build/tools/generate-tests/generateMockRestTool.js +193 -21
- package/build/tools/generateEnrichedIntegrationTestTool.d.ts +24 -0
- package/build/tools/generateEnrichedIntegrationTestTool.js +209 -0
- package/build/tools/localDevWorkflowFixes.test.d.ts +1 -0
- package/build/tools/localDevWorkflowFixes.test.js +144 -0
- package/build/tools/one-click/oneClickTool.d.ts +10 -0
- package/build/tools/one-click/oneClickTool.js +177 -21
- package/build/tools/one-click/oneClickTool.test.d.ts +1 -0
- package/build/tools/one-click/oneClickTool.test.js +172 -0
- package/build/tools/preflightMockCheckTool.d.ts +2 -0
- package/build/tools/preflightMockCheckTool.js +91 -0
- package/build/tools/test-management/analyzeChangesTool.d.ts +2 -1
- package/build/tools/test-management/analyzeChangesTool.js +59 -38
- package/build/tools/workspace/initializeWorkspaceTool.js +2 -9
- package/build/tools/workspace/initializeWorkspaceTool.test.js +9 -4
- package/build/types/OneClickCommands.d.ts +1 -1
- package/build/types/RepositoryAnalysis.d.ts +117 -0
- package/build/types/RepositoryAnalysis.js +16 -2
- package/build/types/TestTypes.d.ts +11 -2
- package/build/types/TestTypes.js +11 -1
- package/build/utils/analyze-openapi.js +18 -1
- package/build/utils/analyze-openapi.test.d.ts +1 -0
- package/build/utils/analyze-openapi.test.js +19 -0
- package/build/utils/branchDiff.d.ts +17 -1
- package/build/utils/branchDiff.js +96 -14
- package/build/utils/branchDiff.test.d.ts +1 -0
- package/build/utils/branchDiff.test.js +107 -0
- package/build/utils/docker.test.js +1 -1
- package/build/utils/featureFlags.d.ts +15 -1
- package/build/utils/featureFlags.js +19 -2
- package/build/utils/featureFlags.test.js +57 -2
- package/build/utils/grpcMockValidation.d.ts +1 -0
- package/build/utils/grpcMockValidation.js +49 -0
- package/build/utils/grpcMockValidation.test.d.ts +1 -0
- package/build/utils/grpcMockValidation.test.js +41 -0
- package/build/utils/httpMethodValidation.d.ts +4 -0
- package/build/utils/httpMethodValidation.js +13 -0
- package/build/utils/mockCompatibility.d.ts +49 -0
- package/build/utils/mockCompatibility.js +80 -0
- package/build/utils/mockCompatibility.test.d.ts +1 -0
- package/build/utils/mockCompatibility.test.js +88 -0
- package/build/utils/versions.d.ts +3 -3
- package/build/utils/versions.js +1 -1
- package/build/workspace/workspace.d.ts +35 -21
- package/build/workspace/workspace.js +8 -4
- package/build/workspace/workspace.test.js +65 -6
- package/package.json +2 -2
|
@@ -357,8 +357,8 @@ const TOOL_NAME = "skyramp_contract_test_generation";
|
|
|
357
357
|
const MODES_SECTION = CONSUMER_MODE_ENABLED
|
|
358
358
|
? `**Modes:**
|
|
359
359
|
- Default (no mode set): both \`providerMode\` and \`consumerMode\` default to false. This generates both provider and consumer contract tests — equivalent to setting both modes to true.
|
|
360
|
-
- \`providerMode\`: set to true ONLY if the user explicitly requests a provider-side contract test. Optionally specify \`providerOutput\` for the output file path.
|
|
361
|
-
- \`consumerMode\`: set to true ONLY if the user explicitly requests a consumer-side contract test. Optionally specify \`consumerOutput\` for the output file path.
|
|
360
|
+
- \`providerMode\`: set to true ONLY if the user explicitly requests a provider-side contract test. Optionally specify \`providerOutput\` for the output file path. Provider tests hit the real endpoint — no mocks.
|
|
361
|
+
- \`consumerMode\`: set to true ONLY if the user explicitly requests a consumer-side contract test. Optionally specify \`consumerOutput\` for the output file path. Consumer tests include mocks wired inline (\`client.apply_mock(mock)\` in the test function) — no separate \`skyramp_enrich_test_with_mocks\` call needed.
|
|
362
362
|
- Both \`providerMode\` and \`consumerMode\` can be enabled simultaneously to generate both sides.`
|
|
363
363
|
: `**Mode:**
|
|
364
364
|
- Only provider-side contract tests are generated. Pass \`providerMode: true\` (or omit it — the tool always behaves as provider-only). Optionally specify \`providerOutput\` for the output file path.`;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import {
|
|
2
|
+
import { MockProtocol } from "../../types/TestTypes.js";
|
|
3
|
+
export { MockProtocol } from "../../types/TestTypes.js";
|
|
3
4
|
import { TestGenerationService } from "../../services/TestGenerationService.js";
|
|
4
5
|
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
export declare const MOCK_PROTOCOL_EXAMPLES = "\n<example protocol=\"rest\">\nGenerate a REST mock for one HTTP endpoint. Required fields: protocol=\"rest\", endpointURL, method. Use apiSchema with an empty method only when intentionally generating all schema methods.\n{\n \"protocol\": \"rest\",\n \"endpointURL\": \"http://payment-service:5001/orders/:order_id/payment_authorizations\",\n \"method\": \"PUT\",\n \"requestAware\": true,\n \"requestData\": \"{\"payment_method_id\":\"pm_123\"}\",\n \"responseData\": \"{\"accepted\":true}\",\n \"responseStatusCode\": \"200\"\n}\n</example>\n\n<example protocol=\"grpc\">\nGenerate a gRPC mock. Required fields: protocol=\"grpc\", endpointURL as host:port, protoPath, grpcServiceName. method is the RPC method name; omit or leave empty to generate all service methods. responseData must be a successful protobuf-shaped response, not a gRPC status error.\n{\n \"protocol\": \"grpc\",\n \"endpointURL\": \"profile-service:50051\",\n \"protoPath\": \"/repo/proto/profiles.proto\",\n \"grpcServiceName\": \"ProfileService\",\n \"method\": \"GetProfile\",\n \"responseData\": \"{\"eligible\":true}\"\n}\n</example>\n\n<example protocol=\"kafka-producer\">\nGenerate a Kafka producer validation mock. Required fields: protocol=\"kafka\", endpointURL as broker host:port, kafkaTopic, and requestData. Do not pass method or responseData.\n{\n \"protocol\": \"kafka\",\n \"endpointURL\": \"broker:9092\",\n \"kafkaTopic\": \"events\",\n \"requestData\": \"{\"name\":\"order.created\"}\"\n}\n</example>\n\n<example protocol=\"kafka-consumer\">\nGenerate a Kafka consumer message mock. Required fields: protocol=\"kafka\", endpointURL as broker host:port, kafkaTopic, and responseData. Do not pass method or requestData.\n{\n \"protocol\": \"kafka\",\n \"endpointURL\": \"broker:9092\",\n \"kafkaTopic\": \"events\",\n \"responseData\": \"{\"accepted\":true}\"\n}\n</example>";
|
|
5
7
|
type MockParams = {
|
|
8
|
+
protocol?: MockProtocol;
|
|
6
9
|
endpointURL?: string;
|
|
10
|
+
protoPath?: string;
|
|
11
|
+
grpcServiceName?: string;
|
|
12
|
+
protobufExtraFiles?: string[];
|
|
13
|
+
protobufExtraImportPath?: string[];
|
|
14
|
+
kafkaTopic?: string;
|
|
7
15
|
method?: string;
|
|
8
16
|
apiSchema?: string;
|
|
9
17
|
responseData?: string;
|
|
@@ -29,13 +37,18 @@ type MockParams = {
|
|
|
29
37
|
prompt?: string;
|
|
30
38
|
};
|
|
31
39
|
export declare class MockGenerationService extends TestGenerationService {
|
|
32
|
-
protected getTestType():
|
|
40
|
+
protected getTestType(): "mock";
|
|
33
41
|
generateTest(params: MockParams & Record<string, any>): Promise<CallToolResult>;
|
|
34
42
|
private buildReorganizationInstructions;
|
|
43
|
+
protected validateInputs(params: MockParams & Record<string, any>): CallToolResult;
|
|
35
44
|
protected buildGenerationOptions(params: MockParams): {
|
|
36
|
-
uri: string | undefined;
|
|
37
45
|
method: string | undefined;
|
|
38
|
-
|
|
46
|
+
url: string | undefined;
|
|
47
|
+
protoPath: string | undefined;
|
|
48
|
+
service: string | undefined;
|
|
49
|
+
extraFiles: string[];
|
|
50
|
+
extraImports: string[];
|
|
51
|
+
protocol: MockProtocol;
|
|
39
52
|
language: string;
|
|
40
53
|
framework: string;
|
|
41
54
|
output: string | undefined;
|
|
@@ -48,17 +61,54 @@ export declare class MockGenerationService extends TestGenerationService {
|
|
|
48
61
|
k8sNamespace: string | undefined;
|
|
49
62
|
k8sConfig: string | undefined;
|
|
50
63
|
k8sContext: string | undefined;
|
|
64
|
+
responseData: string | undefined;
|
|
65
|
+
entrypoint: string;
|
|
66
|
+
} | {
|
|
67
|
+
url: string | undefined;
|
|
68
|
+
topic: string | undefined;
|
|
51
69
|
requestData: string | undefined;
|
|
70
|
+
protocol: MockProtocol;
|
|
71
|
+
language: string;
|
|
72
|
+
framework: string;
|
|
73
|
+
output: string | undefined;
|
|
74
|
+
outputDir: string;
|
|
75
|
+
force: boolean;
|
|
76
|
+
deployDashboard: boolean | undefined;
|
|
77
|
+
runtime: string | undefined;
|
|
78
|
+
dockerNetwork: string | undefined;
|
|
79
|
+
dockerWorkerPort: string;
|
|
80
|
+
k8sNamespace: string | undefined;
|
|
81
|
+
k8sConfig: string | undefined;
|
|
82
|
+
k8sContext: string | undefined;
|
|
52
83
|
responseData: string | undefined;
|
|
84
|
+
entrypoint: string;
|
|
85
|
+
} | {
|
|
86
|
+
method: string;
|
|
87
|
+
uri: string | undefined;
|
|
88
|
+
apiSchema: string[];
|
|
89
|
+
requestData: string | undefined;
|
|
53
90
|
responseStatusCode: string | undefined;
|
|
54
91
|
formParams: string | undefined;
|
|
55
92
|
requestAware: boolean | undefined;
|
|
56
93
|
traceFilePath: string | undefined;
|
|
57
|
-
entrypoint: string;
|
|
58
94
|
mockPort: number;
|
|
59
95
|
optionalFields: boolean;
|
|
96
|
+
protocol: MockProtocol;
|
|
97
|
+
language: string;
|
|
98
|
+
framework: string;
|
|
99
|
+
output: string | undefined;
|
|
100
|
+
outputDir: string;
|
|
101
|
+
force: boolean;
|
|
102
|
+
deployDashboard: boolean | undefined;
|
|
103
|
+
runtime: string | undefined;
|
|
104
|
+
dockerNetwork: string | undefined;
|
|
105
|
+
dockerWorkerPort: string;
|
|
106
|
+
k8sNamespace: string | undefined;
|
|
107
|
+
k8sConfig: string | undefined;
|
|
108
|
+
k8sContext: string | undefined;
|
|
109
|
+
responseData: string | undefined;
|
|
110
|
+
entrypoint: string;
|
|
60
111
|
};
|
|
61
112
|
protected executeGeneration(generateOptions: any): Promise<string>;
|
|
62
113
|
}
|
|
63
114
|
export declare function registerMockTool(server: McpServer): void;
|
|
64
|
-
export {};
|
|
@@ -1,18 +1,93 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { baseSchema,
|
|
2
|
+
import { baseSchema, MockProtocol, MOCK_TYPE } from "../../types/TestTypes.js";
|
|
3
|
+
export { MockProtocol } from "../../types/TestTypes.js";
|
|
3
4
|
import { TestGenerationService } from "../../services/TestGenerationService.js";
|
|
4
5
|
import { AnalyticsService } from "../../services/AnalyticsService.js";
|
|
5
6
|
import { getEntryPoint } from "../../utils/telemetry.js";
|
|
7
|
+
import { getRestMockMethodValidationError, normalizeRestMockMethod, } from "../../utils/httpMethodValidation.js";
|
|
8
|
+
import { getGrpcMockResponseValidationError } from "../../utils/grpcMockValidation.js";
|
|
9
|
+
import { isLocalDevEnabled } from "../../utils/featureFlags.js";
|
|
10
|
+
export const MOCK_PROTOCOL_EXAMPLES = `
|
|
11
|
+
<example protocol="rest">
|
|
12
|
+
Generate a REST mock for one HTTP endpoint. Required fields: protocol="rest", endpointURL, method. Use apiSchema with an empty method only when intentionally generating all schema methods.
|
|
13
|
+
{
|
|
14
|
+
"protocol": "rest",
|
|
15
|
+
"endpointURL": "http://payment-service:5001/orders/:order_id/payment_authorizations",
|
|
16
|
+
"method": "PUT",
|
|
17
|
+
"requestAware": true,
|
|
18
|
+
"requestData": "{\"payment_method_id\":\"pm_123\"}",
|
|
19
|
+
"responseData": "{\"accepted\":true}",
|
|
20
|
+
"responseStatusCode": "200"
|
|
21
|
+
}
|
|
22
|
+
</example>
|
|
23
|
+
|
|
24
|
+
<example protocol="grpc">
|
|
25
|
+
Generate a gRPC mock. Required fields: protocol="grpc", endpointURL as host:port, protoPath, grpcServiceName. method is the RPC method name; omit or leave empty to generate all service methods. responseData must be a successful protobuf-shaped response, not a gRPC status error.
|
|
26
|
+
{
|
|
27
|
+
"protocol": "grpc",
|
|
28
|
+
"endpointURL": "profile-service:50051",
|
|
29
|
+
"protoPath": "/repo/proto/profiles.proto",
|
|
30
|
+
"grpcServiceName": "ProfileService",
|
|
31
|
+
"method": "GetProfile",
|
|
32
|
+
"responseData": "{\"eligible\":true}"
|
|
33
|
+
}
|
|
34
|
+
</example>
|
|
35
|
+
|
|
36
|
+
<example protocol="kafka-producer">
|
|
37
|
+
Generate a Kafka producer validation mock. Required fields: protocol="kafka", endpointURL as broker host:port, kafkaTopic, and requestData. Do not pass method or responseData.
|
|
38
|
+
{
|
|
39
|
+
"protocol": "kafka",
|
|
40
|
+
"endpointURL": "broker:9092",
|
|
41
|
+
"kafkaTopic": "events",
|
|
42
|
+
"requestData": "{\"name\":\"order.created\"}"
|
|
43
|
+
}
|
|
44
|
+
</example>
|
|
45
|
+
|
|
46
|
+
<example protocol="kafka-consumer">
|
|
47
|
+
Generate a Kafka consumer message mock. Required fields: protocol="kafka", endpointURL as broker host:port, kafkaTopic, and responseData. Do not pass method or requestData.
|
|
48
|
+
{
|
|
49
|
+
"protocol": "kafka",
|
|
50
|
+
"endpointURL": "broker:9092",
|
|
51
|
+
"kafkaTopic": "events",
|
|
52
|
+
"responseData": "{\"accepted\":true}"
|
|
53
|
+
}
|
|
54
|
+
</example>`;
|
|
6
55
|
const mockSchema = {
|
|
56
|
+
protocol: z
|
|
57
|
+
.nativeEnum(MockProtocol)
|
|
58
|
+
.default(MockProtocol.Rest)
|
|
59
|
+
.describe("Protocol for the mock to generate. Use 'rest' for HTTP/OpenAPI mocks, 'grpc' for protobuf/gRPC mocks, and 'kafka' for Kafka topic mocks. See <example> blocks in the tool description for protocol-specific required fields."),
|
|
7
60
|
endpointURL: z
|
|
8
61
|
.string()
|
|
9
|
-
.describe("
|
|
10
|
-
"
|
|
11
|
-
"
|
|
62
|
+
.describe("For REST: the base URL or endpoint URL to generate a mock for. " +
|
|
63
|
+
"For gRPC: the target service address as host:port (for example, profile-service:50051); do not include http://. " +
|
|
64
|
+
"For Kafka: the broker address as host:port (for example, broker:9092); do not include http://. " +
|
|
65
|
+
"If only a base URL is provided (e.g., https://api.example.com) and an apiSchema is given, REST mocks will be generated for ALL endpoints and methods in the schema — do NOT append paths to the URL. " +
|
|
66
|
+
"Only include a specific path (e.g., https://api.example.com/api/v1/products) if the user explicitly requests mocking a single REST endpoint."),
|
|
67
|
+
protoPath: z
|
|
68
|
+
.string()
|
|
69
|
+
.optional()
|
|
70
|
+
.describe("Required for protocol='grpc'. Absolute or repo-relative path to the .proto file that defines the gRPC service."),
|
|
71
|
+
grpcServiceName: z
|
|
72
|
+
.string()
|
|
73
|
+
.optional()
|
|
74
|
+
.describe("Required for protocol='grpc'. gRPC service name from the proto file, e.g. Greeter or ProfileService."),
|
|
75
|
+
protobufExtraFiles: z
|
|
76
|
+
.array(z.string())
|
|
77
|
+
.optional()
|
|
78
|
+
.describe("Optional extra .proto files needed to compile the primary proto for gRPC mocks."),
|
|
79
|
+
protobufExtraImportPath: z
|
|
80
|
+
.array(z.string())
|
|
81
|
+
.optional()
|
|
82
|
+
.describe("Optional extra import directories used when compiling protobuf files for gRPC mocks."),
|
|
83
|
+
kafkaTopic: z
|
|
84
|
+
.string()
|
|
85
|
+
.optional()
|
|
86
|
+
.describe("Required for protocol='kafka'. Kafka topic name to mock, e.g. order.created or orders."),
|
|
12
87
|
method: z
|
|
13
|
-
.
|
|
88
|
+
.string()
|
|
14
89
|
.default("")
|
|
15
|
-
.describe('HTTP method to mock
|
|
90
|
+
.describe('For REST: HTTP method to mock; required unless apiSchema is provided for schema-wide generation. Empty string ("") with apiSchema mocks ALL available schema methods. For gRPC: RPC method name to mock; empty string generates all service methods. For Kafka: MUST be empty; use kafkaTopic for the topic name.'),
|
|
16
91
|
apiSchema: z
|
|
17
92
|
.string()
|
|
18
93
|
.default("")
|
|
@@ -20,16 +95,18 @@ const mockSchema = {
|
|
|
20
95
|
responseData: z
|
|
21
96
|
.string()
|
|
22
97
|
.optional()
|
|
23
|
-
.describe("
|
|
98
|
+
.describe("REST/gRPC: sample response body data to return. Kafka: consumer messages to inject. Provide inline JSON/YAML or an absolute file path prefixed with '@' (e.g., @/absolute/path/to/file)."),
|
|
24
99
|
responseStatusCode: z
|
|
25
100
|
.string()
|
|
26
101
|
.default("")
|
|
27
|
-
.refine((val) => !val || /^\d{3}$/.test(val), {
|
|
102
|
+
.refine((val) => !val || /^\d{3}$/.test(val), {
|
|
103
|
+
message: "Must be a 3-digit HTTP status code (e.g., '200', '201') or empty string",
|
|
104
|
+
})
|
|
28
105
|
.describe("HTTP status code the mock should return (e.g., '200', '201'). DO NOT ASSUME a status code if not provided."),
|
|
29
106
|
requestData: z
|
|
30
107
|
.string()
|
|
31
108
|
.default("")
|
|
32
|
-
.describe("
|
|
109
|
+
.describe("REST: request body sample for request-aware matching. Kafka: producer validation payload/schema. Provide inline JSON/YAML or an absolute file path prefixed with '@' (e.g., @/absolute/path/to/file)."),
|
|
33
110
|
formParams: z
|
|
34
111
|
.string()
|
|
35
112
|
.default("")
|
|
@@ -42,17 +119,18 @@ const mockSchema = {
|
|
|
42
119
|
.string()
|
|
43
120
|
.optional()
|
|
44
121
|
.describe("MUST be absolute path to a trace file (e.g., /path/to/trace.json) to generate the mock from captured traffic."),
|
|
45
|
-
...(({ authHeader, insecure, ...rest }) => rest)(baseSchema.shape),
|
|
122
|
+
...(({ authHeader: _authHeader, insecure: _insecure, ...rest }) => rest)(baseSchema.shape),
|
|
46
123
|
};
|
|
47
124
|
export class MockGenerationService extends TestGenerationService {
|
|
48
125
|
getTestType() {
|
|
49
|
-
return
|
|
126
|
+
return MOCK_TYPE;
|
|
50
127
|
}
|
|
51
128
|
async generateTest(params) {
|
|
52
129
|
const result = await super.generateTest(params);
|
|
53
130
|
if (result.isError)
|
|
54
131
|
return result;
|
|
55
|
-
if (!params.apiSchema
|
|
132
|
+
if (!params.apiSchema ||
|
|
133
|
+
(params.protocol ?? MockProtocol.Rest) !== MockProtocol.Rest)
|
|
56
134
|
return result;
|
|
57
135
|
return {
|
|
58
136
|
...result,
|
|
@@ -123,11 +201,68 @@ This file must:
|
|
|
123
201
|
- Do NOT modify any mock logic, response data, or function signatures — only reorganize and add import/export wiring.
|
|
124
202
|
`;
|
|
125
203
|
}
|
|
126
|
-
|
|
204
|
+
validateInputs(params) {
|
|
205
|
+
const result = super.validateInputs(params);
|
|
206
|
+
const protocol = params.protocol ?? MockProtocol.Rest;
|
|
207
|
+
if (protocol === MockProtocol.Rest) {
|
|
208
|
+
const methodError = getRestMockMethodValidationError(params.method);
|
|
209
|
+
if (methodError) {
|
|
210
|
+
result.content.push({
|
|
211
|
+
type: "text",
|
|
212
|
+
text: `Error: ${methodError}.`,
|
|
213
|
+
});
|
|
214
|
+
result.isError = true;
|
|
215
|
+
}
|
|
216
|
+
if (!params.apiSchema && !params.method) {
|
|
217
|
+
result.content.push({
|
|
218
|
+
type: "text",
|
|
219
|
+
text: "Error: REST mock method is required unless apiSchema is provided for schema-wide generation.",
|
|
220
|
+
});
|
|
221
|
+
result.isError = true;
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
const missing = [];
|
|
226
|
+
if (protocol === MockProtocol.Grpc) {
|
|
227
|
+
if (!params.protoPath)
|
|
228
|
+
missing.push("protoPath is required for protocol='grpc'");
|
|
229
|
+
if (!params.grpcServiceName)
|
|
230
|
+
missing.push("grpcServiceName is required for protocol='grpc'");
|
|
231
|
+
const grpcResponseError = getGrpcMockResponseValidationError(params.responseData);
|
|
232
|
+
if (grpcResponseError)
|
|
233
|
+
missing.push(grpcResponseError);
|
|
234
|
+
}
|
|
235
|
+
if (protocol === MockProtocol.Kafka) {
|
|
236
|
+
if (!params.kafkaTopic) {
|
|
237
|
+
missing.push("kafkaTopic is required for protocol='kafka'");
|
|
238
|
+
}
|
|
239
|
+
if (params.method) {
|
|
240
|
+
missing.push("Kafka mock method must be empty; use kafkaTopic for the topic name. Produce validation uses requestData and consumer messages use responseData");
|
|
241
|
+
}
|
|
242
|
+
const hasRequestData = Boolean(params.requestData && params.requestData.trim());
|
|
243
|
+
const hasResponseData = Boolean(params.responseData && params.responseData.trim());
|
|
244
|
+
if (hasRequestData === hasResponseData) {
|
|
245
|
+
missing.push("Kafka mock requires exactly one of requestData (producer validation) or responseData (consumer messages)");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (missing.length === 0) {
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
127
251
|
return {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
252
|
+
content: [
|
|
253
|
+
...result.content,
|
|
254
|
+
{
|
|
255
|
+
type: "text",
|
|
256
|
+
text: `Error: ${missing.join("; ")}.`,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
isError: true,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
buildGenerationOptions(params) {
|
|
263
|
+
const protocol = params.protocol ?? MockProtocol.Rest;
|
|
264
|
+
const common = {
|
|
265
|
+
protocol,
|
|
131
266
|
language: params.language ?? "python",
|
|
132
267
|
framework: params.framework ??
|
|
133
268
|
(params.language === "typescript" || params.language === "javascript"
|
|
@@ -143,20 +278,51 @@ This file must:
|
|
|
143
278
|
k8sNamespace: params.k8sNamespace,
|
|
144
279
|
k8sConfig: params.k8sConfig,
|
|
145
280
|
k8sContext: params.k8sContext,
|
|
146
|
-
requestData: params.requestData,
|
|
147
281
|
responseData: params.responseData,
|
|
282
|
+
entrypoint: getEntryPoint(),
|
|
283
|
+
};
|
|
284
|
+
if (protocol === MockProtocol.Grpc) {
|
|
285
|
+
return {
|
|
286
|
+
...common,
|
|
287
|
+
method: params.method,
|
|
288
|
+
url: params.endpointURL,
|
|
289
|
+
protoPath: params.protoPath,
|
|
290
|
+
service: params.grpcServiceName,
|
|
291
|
+
extraFiles: params.protobufExtraFiles ?? [],
|
|
292
|
+
extraImports: params.protobufExtraImportPath ?? [],
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
if (protocol === MockProtocol.Kafka) {
|
|
296
|
+
return {
|
|
297
|
+
...common,
|
|
298
|
+
url: params.endpointURL,
|
|
299
|
+
topic: params.kafkaTopic,
|
|
300
|
+
requestData: params.requestData?.trim() ? params.requestData : undefined,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
...common,
|
|
305
|
+
method: normalizeRestMockMethod(params.method),
|
|
306
|
+
uri: params.endpointURL,
|
|
307
|
+
apiSchema: params.apiSchema ? [params.apiSchema] : [],
|
|
308
|
+
requestData: params.requestData,
|
|
148
309
|
responseStatusCode: params.responseStatusCode,
|
|
149
310
|
formParams: params.formParams,
|
|
150
311
|
requestAware: params.requestAware,
|
|
151
312
|
traceFilePath: params.trace,
|
|
152
|
-
entrypoint: getEntryPoint(),
|
|
153
313
|
mockPort: params.mockPort ?? 0,
|
|
154
314
|
optionalFields: params.optionalFields ?? false,
|
|
155
315
|
};
|
|
156
316
|
}
|
|
157
317
|
async executeGeneration(generateOptions) {
|
|
158
318
|
try {
|
|
159
|
-
const
|
|
319
|
+
const protocol = generateOptions.protocol ?? MockProtocol.Rest;
|
|
320
|
+
const client = this.client;
|
|
321
|
+
const result = protocol === MockProtocol.Grpc
|
|
322
|
+
? await client.generateGrpcMock(generateOptions)
|
|
323
|
+
: protocol === MockProtocol.Kafka
|
|
324
|
+
? await client.generateKafkaMock(generateOptions)
|
|
325
|
+
: await client.generateRestMock(generateOptions);
|
|
160
326
|
if (result && result.length > 0) {
|
|
161
327
|
const lowerResult = result.toLowerCase();
|
|
162
328
|
if (!lowerResult.includes("success")) {
|
|
@@ -177,12 +343,18 @@ ${result}`;
|
|
|
177
343
|
}
|
|
178
344
|
}
|
|
179
345
|
}
|
|
346
|
+
const LOCAL_DEV_GUARD = `
|
|
347
|
+
**LOCAL-DEV GUARD:** If the user asked to run a local-dev workflow, test local changes, validate a feature branch, test against a base/prod/main branch, or mock downstream services for local testing, do NOT start with this tool. First call \`skyramp_one_click_tool\` with workflow \`local_dev_test_changes\`, \`callingAgent\` set to the current MCP client, \`repositoryPath\`, and \`baseBranch\`; that workflow installs skills, initializes the workspace, analyzes the diff, and then calls mock generation at the correct phase.
|
|
348
|
+
`;
|
|
349
|
+
function getLocalDevGuard() {
|
|
350
|
+
return isLocalDevEnabled() ? LOCAL_DEV_GUARD : "";
|
|
351
|
+
}
|
|
180
352
|
const TOOL_NAME = "skyramp_mock_generation";
|
|
181
353
|
export function registerMockTool(server) {
|
|
182
354
|
server.registerTool(TOOL_NAME, {
|
|
183
|
-
description:
|
|
355
|
+
description: `${getLocalDevGuard()}Generate a mock server implementation using Skyramp's deterministic mock generation platform.
|
|
184
356
|
|
|
185
|
-
Mocks simulate
|
|
357
|
+
Mocks simulate REST, gRPC, or Kafka dependencies so that consumers can develop and test against them without requiring a live backend. They are useful for parallel development, isolating dependencies, and simulating edge-case responses.
|
|
186
358
|
|
|
187
359
|
**IMPORTANT: If an apiSchema parameter (OpenAPI/Swagger file path or URL) is provided, DO NOT attempt to read or analyze the file contents. Simply pass the path/URL to the tool — the backend will handle reading and processing the schema file.**
|
|
188
360
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* skyramp_generate_enriched_integration_test
|
|
5
|
+
*
|
|
6
|
+
* Combines integration test generation (from a scenario file) and mock enrichment
|
|
7
|
+
* into a single atomic operation. Eliminates the need to call
|
|
8
|
+
* skyramp_integration_test_generation and skyramp_enrich_test_with_mocks separately.
|
|
9
|
+
*/
|
|
10
|
+
export declare function registerGenerateEnrichedIntegrationTestTool(server: McpServer): void;
|
|
11
|
+
export declare function executeGenerateEnrichedIntegrationTest(params: {
|
|
12
|
+
scenarioFile: string;
|
|
13
|
+
mockFiles: string[];
|
|
14
|
+
scenarioName: string;
|
|
15
|
+
outputDir: string;
|
|
16
|
+
output?: string;
|
|
17
|
+
runtime?: string;
|
|
18
|
+
dockerNetwork?: string;
|
|
19
|
+
authHeader?: string;
|
|
20
|
+
authScheme?: string;
|
|
21
|
+
language?: string;
|
|
22
|
+
framework?: string;
|
|
23
|
+
traceComments?: string[];
|
|
24
|
+
}): Promise<CallToolResult>;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SkyrampClient } from "@skyramp/skyramp";
|
|
3
|
+
import { logger } from "../utils/logger.js";
|
|
4
|
+
import { injectMockImports } from "./enrichTestWithMocksTool.js";
|
|
5
|
+
import { isAuthorizationHeaderName } from "../utils/workspaceAuth.js";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
const TOOL_NAME = "skyramp_generate_enriched_integration_test";
|
|
9
|
+
const enrichedIntegrationTestSchema = {
|
|
10
|
+
scenarioFile: z
|
|
11
|
+
.string()
|
|
12
|
+
.describe("Absolute path to the scenario JSON file (from skyramp_batch_scenario_test_generation). Used as trace input for integration test generation."),
|
|
13
|
+
mockFiles: z
|
|
14
|
+
.array(z.string())
|
|
15
|
+
.describe("Absolute paths to the generated mock files (from skyramp_mock_generation or skyramp_batch_mock_generation) that this test needs."),
|
|
16
|
+
scenarioName: z
|
|
17
|
+
.string()
|
|
18
|
+
.describe("Human-readable scenario name (e.g., order-happy-path). Used as the SCENARIO_NAME constant in the enriched test."),
|
|
19
|
+
outputDir: z
|
|
20
|
+
.string()
|
|
21
|
+
.describe("Absolute path to the directory where the test file will be written."),
|
|
22
|
+
output: z
|
|
23
|
+
.string()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Output test file name (e.g., order_happy_path_integration_test.py). Derived from scenario if omitted."),
|
|
26
|
+
runtime: z
|
|
27
|
+
.string()
|
|
28
|
+
.optional()
|
|
29
|
+
.default("docker")
|
|
30
|
+
.describe("Runtime environment: 'docker' or 'k8s'. Defaults to docker."),
|
|
31
|
+
dockerNetwork: z
|
|
32
|
+
.string()
|
|
33
|
+
.optional()
|
|
34
|
+
.describe("Docker network name for the test runtime."),
|
|
35
|
+
authHeader: z
|
|
36
|
+
.string()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe("HTTP header that carries the auth credential (e.g., Authorization, X-Api-Key)."),
|
|
39
|
+
authScheme: z
|
|
40
|
+
.string()
|
|
41
|
+
.optional()
|
|
42
|
+
.describe("Auth scheme prefix (e.g., Bearer). Mapped to authType for the backend."),
|
|
43
|
+
language: z
|
|
44
|
+
.string()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Programming language for the generated test (e.g., python, typescript)."),
|
|
47
|
+
framework: z
|
|
48
|
+
.string()
|
|
49
|
+
.optional()
|
|
50
|
+
.describe("Test framework (e.g., pytest, playwright)."),
|
|
51
|
+
traceComments: z
|
|
52
|
+
.array(z.string())
|
|
53
|
+
.optional()
|
|
54
|
+
.describe("Optional trace comments showing how mock values flow to assertions."),
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* skyramp_generate_enriched_integration_test
|
|
58
|
+
*
|
|
59
|
+
* Combines integration test generation (from a scenario file) and mock enrichment
|
|
60
|
+
* into a single atomic operation. Eliminates the need to call
|
|
61
|
+
* skyramp_integration_test_generation and skyramp_enrich_test_with_mocks separately.
|
|
62
|
+
*/
|
|
63
|
+
export function registerGenerateEnrichedIntegrationTestTool(server) {
|
|
64
|
+
server.registerTool(TOOL_NAME, {
|
|
65
|
+
description: "Generate an integration test from a scenario file AND enrich it with mock imports in one step. " +
|
|
66
|
+
"Combines skyramp_integration_test_generation + skyramp_enrich_test_with_mocks into a single call. " +
|
|
67
|
+
"Use this after skyramp_batch_scenario_test_generation and skyramp_batch_mock_generation to " +
|
|
68
|
+
"produce a fully wired test file ready for execution.",
|
|
69
|
+
inputSchema: enrichedIntegrationTestSchema,
|
|
70
|
+
}, async (params) => {
|
|
71
|
+
return executeGenerateEnrichedIntegrationTest(params);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export async function executeGenerateEnrichedIntegrationTest(params) {
|
|
75
|
+
const { scenarioFile, mockFiles, scenarioName, outputDir, output, runtime, dockerNetwork, authHeader, authScheme, language, framework, traceComments, } = params;
|
|
76
|
+
try {
|
|
77
|
+
// Step 1: Validate language — enrichment currently supports Python only
|
|
78
|
+
if (language && language !== "python") {
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: "text",
|
|
83
|
+
text: `**Error:** Mock enrichment is currently supported only for Python tests; received language "${language}". Use \`skyramp_integration_test_generation\` followed by \`skyramp_enrich_test_with_mocks\` for non-Python languages.`,
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
isError: true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Step 1b: Validate scenarioFile exists
|
|
90
|
+
if (!fs.existsSync(scenarioFile)) {
|
|
91
|
+
return {
|
|
92
|
+
content: [
|
|
93
|
+
{
|
|
94
|
+
type: "text",
|
|
95
|
+
text: `**Error:** Scenario file not found: ${scenarioFile}`,
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
isError: true,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// Step 1b: Validate mock files exist
|
|
102
|
+
const missingFiles = mockFiles.filter((f) => !fs.existsSync(f));
|
|
103
|
+
if (missingFiles.length > 0) {
|
|
104
|
+
return {
|
|
105
|
+
content: [
|
|
106
|
+
{
|
|
107
|
+
type: "text",
|
|
108
|
+
text: `**Error:** Mock files not found:\n` +
|
|
109
|
+
missingFiles.map((f) => ` - ${f}`).join("\n") +
|
|
110
|
+
`\n\nGenerate them first with \`skyramp_batch_mock_generation\`.`,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
isError: true,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// Step 2: Generate the integration test
|
|
117
|
+
// Normalize auth params: the Go CLI treats --auth-type and --auth-header as
|
|
118
|
+
// mutually exclusive when authHeader is the standard Authorization header.
|
|
119
|
+
// Mirror TestGenerationService.executeGeneration() normalization:
|
|
120
|
+
// if authScheme is set and authHeader is Authorization, use authType only.
|
|
121
|
+
let resolvedAuthHeader = authHeader;
|
|
122
|
+
const resolvedAuthType = authScheme;
|
|
123
|
+
if (resolvedAuthType !== undefined && isAuthorizationHeaderName(resolvedAuthHeader || "")) {
|
|
124
|
+
resolvedAuthHeader = undefined;
|
|
125
|
+
}
|
|
126
|
+
const client = new SkyrampClient();
|
|
127
|
+
const result = await client.generateRestTest({
|
|
128
|
+
traceFilePath: scenarioFile,
|
|
129
|
+
outputDir,
|
|
130
|
+
output,
|
|
131
|
+
runtime,
|
|
132
|
+
force: true,
|
|
133
|
+
dockerNetwork,
|
|
134
|
+
authHeader: resolvedAuthHeader,
|
|
135
|
+
authType: resolvedAuthType,
|
|
136
|
+
language,
|
|
137
|
+
framework,
|
|
138
|
+
testType: "integration",
|
|
139
|
+
});
|
|
140
|
+
// Check if generation succeeded
|
|
141
|
+
if (!result || !result.toLowerCase().includes("success")) {
|
|
142
|
+
return {
|
|
143
|
+
content: [
|
|
144
|
+
{
|
|
145
|
+
type: "text",
|
|
146
|
+
text: `**Error:** Integration test generation failed: ${result || "no output from backend"}`,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
isError: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// Step 3: Determine the test file path and read it
|
|
153
|
+
const testFileName = output || deriveTestFileName(scenarioFile, language);
|
|
154
|
+
const testFilePath = path.join(outputDir, testFileName);
|
|
155
|
+
if (!fs.existsSync(testFilePath)) {
|
|
156
|
+
return {
|
|
157
|
+
content: [
|
|
158
|
+
{
|
|
159
|
+
type: "text",
|
|
160
|
+
text: `**Error:** Generated test file not found at expected path: ${testFilePath}\n` +
|
|
161
|
+
`Backend output: ${result}`,
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
isError: true,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const testContent = fs.readFileSync(testFilePath, "utf-8");
|
|
168
|
+
// Step 4: Enrich with mock imports
|
|
169
|
+
const enrichedContent = injectMockImports(testContent, testFilePath, scenarioName, mockFiles, traceComments);
|
|
170
|
+
// Step 5: Write the enriched content back
|
|
171
|
+
fs.writeFileSync(testFilePath, enrichedContent);
|
|
172
|
+
logger.info(`Generated and enriched integration test: ${testFilePath}`, {
|
|
173
|
+
scenarioName,
|
|
174
|
+
mockFileCount: mockFiles.length,
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
content: [
|
|
178
|
+
{
|
|
179
|
+
type: "text",
|
|
180
|
+
text: [
|
|
181
|
+
`**Integration test generated and enriched with mocks for scenario "${scenarioName}".**\n`,
|
|
182
|
+
`**Test file:** ${testFilePath}`,
|
|
183
|
+
`**Mock files imported:** ${mockFiles.length}`,
|
|
184
|
+
...mockFiles.map((f) => ` - ${path.basename(f)}`),
|
|
185
|
+
`\nThe test is ready for execution with: \`skyramp_execute_test({testFile: "${testFilePath}", ...})\``,
|
|
186
|
+
].join("\n"),
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
logger.error(`Failed to generate enriched integration test: ${error.message}`);
|
|
193
|
+
return {
|
|
194
|
+
content: [
|
|
195
|
+
{
|
|
196
|
+
type: "text",
|
|
197
|
+
text: `**Failed to generate enriched integration test:** ${error.message}`,
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
isError: true,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function deriveTestFileName(scenarioFile, language) {
|
|
205
|
+
const base = path.basename(scenarioFile, ".json");
|
|
206
|
+
const name = base.replace(/^scenario_/, "").replace(/[^a-zA-Z0-9]/g, "_");
|
|
207
|
+
const ext = language === "typescript" || language === "javascript" ? ".spec.ts" : ".py";
|
|
208
|
+
return `${name}_integration_test${ext}`;
|
|
209
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|