@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.
Files changed (99) hide show
  1. package/build/commands/commandLibrary.d.ts +1 -0
  2. package/build/commands/commandLibrary.js +20 -14
  3. package/build/commands/commandLibrary.test.d.ts +1 -0
  4. package/build/commands/commandLibrary.test.js +59 -0
  5. package/build/commands/localDevTestChangesCommand.d.ts +15 -0
  6. package/build/commands/localDevTestChangesCommand.js +188 -0
  7. package/build/index.js +77 -13
  8. package/build/prompts/enhance-assertions/sharedAssertionRules.d.ts +1 -0
  9. package/build/prompts/enhance-assertions/sharedAssertionRules.js +17 -0
  10. package/build/prompts/initialize-workspace/initializeWorkspacePrompt.js +9 -8
  11. package/build/prompts/local-dev/local-dev-plan.d.ts +25 -0
  12. package/build/prompts/local-dev/local-dev-plan.js +419 -0
  13. package/build/prompts/local-dev/local-dev-prompts.d.ts +4 -0
  14. package/build/prompts/local-dev/local-dev-prompts.js +157 -0
  15. package/build/prompts/prompt-utils.d.ts +8 -0
  16. package/build/prompts/prompt-utils.js +33 -0
  17. package/build/prompts/sut-setup/modes/adaptWorkflowPrompt.js +3 -1
  18. package/build/prompts/sut-setup/modes/dockerComposePrompt.js +3 -1
  19. package/build/prompts/sut-setup/shared.d.ts +20 -0
  20. package/build/prompts/sut-setup/shared.js +69 -7
  21. package/build/prompts/test-recommendation/analysisOutputPrompt.js +21 -29
  22. package/build/prompts/test-recommendation/analysisOutputPrompt.test.js +0 -28
  23. package/build/prompts/test-recommendation/test-recommendation-prompt.js +41 -4
  24. package/build/prompts/test-recommendation/test-recommendation-prompt.test.js +16 -1
  25. package/build/prompts/testbot/testbot-prompts.d.ts +0 -5
  26. package/build/prompts/testbot/testbot-prompts.js +4 -34
  27. package/build/resources/testbotResource.js +2 -1
  28. package/build/services/AnalyticsService.d.ts +1 -1
  29. package/build/services/TestExecutionService.d.ts +2 -1
  30. package/build/services/TestExecutionService.js +15 -10
  31. package/build/services/TestExecutionService.test.js +75 -1
  32. package/build/services/TestGenerationService.d.ts +2 -2
  33. package/build/tool-phases.js +4 -0
  34. package/build/tools/code-refactor/enhanceAssertionsTool.js +47 -18
  35. package/build/tools/enrichTestWithMocksTool.d.ts +28 -0
  36. package/build/tools/enrichTestWithMocksTool.js +726 -0
  37. package/build/tools/enrichTestWithMocksTool.test.d.ts +1 -0
  38. package/build/tools/enrichTestWithMocksTool.test.js +266 -0
  39. package/build/tools/executeSkyrampTestTool.d.ts +4 -0
  40. package/build/tools/executeSkyrampTestTool.js +48 -24
  41. package/build/tools/executeSkyrampTestTool.test.d.ts +1 -0
  42. package/build/tools/executeSkyrampTestTool.test.js +16 -0
  43. package/build/tools/generate-tests/batchMockGenerationTool.d.ts +85 -0
  44. package/build/tools/generate-tests/batchMockGenerationTool.js +432 -0
  45. package/build/tools/generate-tests/generateContractRestTool.js +2 -2
  46. package/build/tools/generate-tests/generateMockRestTool.d.ts +129 -6
  47. package/build/tools/generate-tests/generateMockRestTool.js +234 -22
  48. package/build/tools/generate-tests/loadTestSchema.d.ts +1 -1
  49. package/build/tools/generateEnrichedIntegrationTestTool.d.ts +24 -0
  50. package/build/tools/generateEnrichedIntegrationTestTool.js +225 -0
  51. package/build/tools/generateEnrichedIntegrationTestTool.test.d.ts +1 -0
  52. package/build/tools/generateEnrichedIntegrationTestTool.test.js +44 -0
  53. package/build/tools/localDevWorkflowFixes.test.d.ts +1 -0
  54. package/build/tools/localDevWorkflowFixes.test.js +255 -0
  55. package/build/tools/one-click/oneClickTool.d.ts +10 -0
  56. package/build/tools/one-click/oneClickTool.js +177 -21
  57. package/build/tools/one-click/oneClickTool.test.d.ts +1 -0
  58. package/build/tools/one-click/oneClickTool.test.js +172 -0
  59. package/build/tools/preflightMockCheckTool.d.ts +2 -0
  60. package/build/tools/preflightMockCheckTool.js +96 -0
  61. package/build/tools/submitReportTool.d.ts +14 -14
  62. package/build/tools/test-management/analyzeChangesTool.d.ts +2 -1
  63. package/build/tools/test-management/analyzeChangesTool.js +59 -38
  64. package/build/tools/trace/startTraceCollectionTool.js +3 -3
  65. package/build/tools/workspace/initializeWorkspaceTool.js +2 -9
  66. package/build/tools/workspace/initializeWorkspaceTool.test.js +9 -4
  67. package/build/types/OneClickCommands.d.ts +1 -1
  68. package/build/types/RepositoryAnalysis.d.ts +117 -0
  69. package/build/types/RepositoryAnalysis.js +16 -2
  70. package/build/types/TestExecution.d.ts +1 -0
  71. package/build/types/TestTypes.d.ts +20 -8
  72. package/build/types/TestTypes.js +19 -5
  73. package/build/utils/analyze-openapi.js +18 -1
  74. package/build/utils/analyze-openapi.test.d.ts +1 -0
  75. package/build/utils/analyze-openapi.test.js +19 -0
  76. package/build/utils/branchDiff.d.ts +17 -1
  77. package/build/utils/branchDiff.js +96 -14
  78. package/build/utils/branchDiff.test.d.ts +1 -0
  79. package/build/utils/branchDiff.test.js +109 -0
  80. package/build/utils/docker.test.js +1 -1
  81. package/build/utils/featureFlags.d.ts +20 -1
  82. package/build/utils/featureFlags.js +26 -2
  83. package/build/utils/featureFlags.test.js +57 -2
  84. package/build/utils/grpcMockValidation.d.ts +1 -0
  85. package/build/utils/grpcMockValidation.js +49 -0
  86. package/build/utils/grpcMockValidation.test.d.ts +1 -0
  87. package/build/utils/grpcMockValidation.test.js +41 -0
  88. package/build/utils/httpMethodValidation.d.ts +4 -0
  89. package/build/utils/httpMethodValidation.js +13 -0
  90. package/build/utils/mockCompatibility.d.ts +49 -0
  91. package/build/utils/mockCompatibility.js +82 -0
  92. package/build/utils/mockCompatibility.test.d.ts +1 -0
  93. package/build/utils/mockCompatibility.test.js +79 -0
  94. package/build/utils/versions.d.ts +3 -3
  95. package/build/utils/versions.js +1 -1
  96. package/build/workspace/workspace.d.ts +49 -35
  97. package/build/workspace/workspace.js +10 -5
  98. package/build/workspace/workspace.test.js +65 -6
  99. package/package.json +2 -2
@@ -0,0 +1,109 @@
1
+ import { jest } from "@jest/globals";
2
+ import { execFileSync } from "child_process";
3
+ import fs from "fs";
4
+ import os from "os";
5
+ import path from "path";
6
+ import { computeBranchDiff, normalizeProvidedBaseRef } from "./branchDiff.js";
7
+ jest.setTimeout(15000);
8
+ function git(cwd, args) {
9
+ execFileSync("git", args, { cwd, stdio: "ignore" });
10
+ }
11
+ describe("computeBranchDiff", () => {
12
+ let tmpDir;
13
+ beforeEach(() => {
14
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "skyramp-branch-diff-"));
15
+ git(tmpDir, ["init"]);
16
+ git(tmpDir, ["branch", "-m", "main"]);
17
+ fs.writeFileSync(path.join(tmpDir, "README.md"), "initial\n");
18
+ git(tmpDir, ["add", "README.md"]);
19
+ git(tmpDir, [
20
+ "-c",
21
+ "user.name=Test",
22
+ "-c",
23
+ "user.email=test@example.com",
24
+ "commit",
25
+ "-m",
26
+ "initial",
27
+ ]);
28
+ });
29
+ afterEach(() => {
30
+ fs.rmSync(tmpDir, { recursive: true, force: true });
31
+ });
32
+ it("classifies untracked files as both changed and new when including uncommitted changes", async () => {
33
+ fs.mkdirSync(path.join(tmpDir, "src"));
34
+ fs.writeFileSync(path.join(tmpDir, "src", "newEndpoint.ts"), "export const value = 1;\n");
35
+ const diff = await computeBranchDiff(tmpDir, "HEAD", true);
36
+ expect(diff.changedFiles).toContain("src/newEndpoint.ts");
37
+ expect(diff.newFiles).toContain("src/newEndpoint.ts");
38
+ });
39
+ it("prefers origin branch over local branch for uncommitted local-dev diffs", async () => {
40
+ const remoteDir = fs.mkdtempSync(path.join(os.tmpdir(), "skyramp-branch-diff-remote-"));
41
+ try {
42
+ git(remoteDir, ["init", "--bare"]);
43
+ git(tmpDir, ["remote", "add", "origin", remoteDir]);
44
+ git(tmpDir, ["push", "-u", "origin", "main"]);
45
+ fs.writeFileSync(path.join(tmpDir, "README.md"), "local main ahead\n");
46
+ git(tmpDir, ["add", "README.md"]);
47
+ git(tmpDir, [
48
+ "-c",
49
+ "user.name=Test",
50
+ "-c",
51
+ "user.email=test@example.com",
52
+ "commit",
53
+ "-m",
54
+ "local main ahead",
55
+ ]);
56
+ fs.writeFileSync(path.join(tmpDir, "local.txt"), "uncommitted\n");
57
+ const diff = await computeBranchDiff(tmpDir, "main", true);
58
+ expect(diff.baseBranch).toBe("origin/main");
59
+ expect(diff.changedFiles.join("\n")).not.toMatch(/^origin\//m);
60
+ expect(diff.changedFiles).toContain("README.md");
61
+ expect(diff.changedFiles).toContain("local.txt");
62
+ }
63
+ finally {
64
+ fs.rmSync(remoteDir, { recursive: true, force: true });
65
+ }
66
+ });
67
+ it("uses SHA-like base refs directly when including uncommitted changes", async () => {
68
+ const remoteDir = fs.mkdtempSync(path.join(os.tmpdir(), "skyramp-branch-diff-remote-"));
69
+ try {
70
+ git(remoteDir, ["init", "--bare"]);
71
+ git(tmpDir, ["remote", "add", "origin", remoteDir]);
72
+ git(tmpDir, ["push", "-u", "origin", "main"]);
73
+ const baseSha = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
74
+ cwd: tmpDir,
75
+ encoding: "utf8",
76
+ }).trim();
77
+ fs.writeFileSync(path.join(tmpDir, "README.md"), "local main ahead\n");
78
+ git(tmpDir, ["add", "README.md"]);
79
+ git(tmpDir, [
80
+ "-c",
81
+ "user.name=Test",
82
+ "-c",
83
+ "user.email=test@example.com",
84
+ "commit",
85
+ "-m",
86
+ "local main ahead",
87
+ ]);
88
+ git(tmpDir, ["branch", baseSha, "HEAD"]);
89
+ git(tmpDir, ["push", "origin", baseSha]);
90
+ fs.writeFileSync(path.join(tmpDir, "local.txt"), "uncommitted\n");
91
+ const diff = await computeBranchDiff(tmpDir, baseSha, true);
92
+ expect(diff.baseBranch).toBe(baseSha);
93
+ expect(diff.baseBranch).not.toMatch(/^origin\//);
94
+ expect(diff.changedFiles).toContain("local.txt");
95
+ }
96
+ finally {
97
+ fs.rmSync(remoteDir, { recursive: true, force: true });
98
+ }
99
+ });
100
+ it("trims provided base refs before using them", () => {
101
+ expect(normalizeProvidedBaseRef(" main ")).toBe("main");
102
+ });
103
+ it("rejects option-like provided base refs", () => {
104
+ expect(() => normalizeProvidedBaseRef("--output=/tmp/evil")).toThrow("refs must not start with '-'");
105
+ });
106
+ it("rejects provided base refs containing internal whitespace", () => {
107
+ expect(() => normalizeProvidedBaseRef("main --stat")).toThrow("refs must not contain whitespace");
108
+ });
109
+ });
@@ -55,7 +55,7 @@ describe("dockerImageExistsLocally", () => {
55
55
  });
56
56
  });
57
57
  describe("pullDockerImage", () => {
58
- const IMAGE = "skyramp/executor:v1.3.29";
58
+ const IMAGE = "skyramp/executor:v1.3.30";
59
59
  beforeEach(() => jest.clearAllMocks());
60
60
  describe("on amd64 host", () => {
61
61
  const originalArch = process.arch;
@@ -23,11 +23,14 @@
23
23
  * - Testbot recommendation prompts no longer suggest `consumerMode: true`
24
24
  * contract tests.
25
25
  *
26
- * When ON (`SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE=1`):
26
+ * When ON (`SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE=1` OR `SKYRAMP_FEATURE_LOCAL_DEV=1`):
27
27
  * - Restores the previous behavior: `consumerMode` / `consumerOutput` are
28
28
  * exposed on the input schema, recommendation prompts mention consumer
29
29
  * contract tests, and the SDK's "no mode set ⇒ generate both" default
30
30
  * is preserved.
31
+ *
32
+ * Local-dev implicitly enables this flag because consumer contract tests with
33
+ * inline mocks are the standard local-dev testing pattern.
31
34
  */
32
35
  export declare function isContractConsumerModeEnabled(): boolean;
33
36
  /**
@@ -35,3 +38,19 @@ export declare function isContractConsumerModeEnabled(): boolean;
35
38
  * (SKYRAMP_FEATURE_TESTBOT=1).
36
39
  */
37
40
  export declare function isTestbotEnabled(): boolean;
41
+ /**
42
+ * Returns true when the local-dev workflow is enabled
43
+ * (SKYRAMP_FEATURE_LOCAL_DEV=1).
44
+ *
45
+ * The local-dev workflow registers the `skyramp_local_dev` prompt and
46
+ * one-click routing, which diffs from a base commit against the current
47
+ * working state, generates mock configurations and backend tests, executes
48
+ * them locally, and reports results — without requiring a pull request or
49
+ * CI environment.
50
+ */
51
+ export declare function isLocalDevEnabled(): boolean;
52
+ /**
53
+ * Returns true when general one-click workflows are enabled
54
+ * (SKYRAMP_FEATURE_ONE_CLICK=1).
55
+ */
56
+ export declare function isOneClickEnabled(): boolean;
@@ -23,14 +23,18 @@
23
23
  * - Testbot recommendation prompts no longer suggest `consumerMode: true`
24
24
  * contract tests.
25
25
  *
26
- * When ON (`SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE=1`):
26
+ * When ON (`SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE=1` OR `SKYRAMP_FEATURE_LOCAL_DEV=1`):
27
27
  * - Restores the previous behavior: `consumerMode` / `consumerOutput` are
28
28
  * exposed on the input schema, recommendation prompts mention consumer
29
29
  * contract tests, and the SDK's "no mode set ⇒ generate both" default
30
30
  * is preserved.
31
+ *
32
+ * Local-dev implicitly enables this flag because consumer contract tests with
33
+ * inline mocks are the standard local-dev testing pattern.
31
34
  */
32
35
  export function isContractConsumerModeEnabled() {
33
- return process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE === "1";
36
+ return (process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE === "1" ||
37
+ isLocalDevEnabled());
34
38
  }
35
39
  /**
36
40
  * Returns true when running inside a TestBot environment
@@ -39,3 +43,23 @@ export function isContractConsumerModeEnabled() {
39
43
  export function isTestbotEnabled() {
40
44
  return process.env.SKYRAMP_FEATURE_TESTBOT === "1";
41
45
  }
46
+ /**
47
+ * Returns true when the local-dev workflow is enabled
48
+ * (SKYRAMP_FEATURE_LOCAL_DEV=1).
49
+ *
50
+ * The local-dev workflow registers the `skyramp_local_dev` prompt and
51
+ * one-click routing, which diffs from a base commit against the current
52
+ * working state, generates mock configurations and backend tests, executes
53
+ * them locally, and reports results — without requiring a pull request or
54
+ * CI environment.
55
+ */
56
+ export function isLocalDevEnabled() {
57
+ return process.env.SKYRAMP_FEATURE_LOCAL_DEV === "1";
58
+ }
59
+ /**
60
+ * Returns true when general one-click workflows are enabled
61
+ * (SKYRAMP_FEATURE_ONE_CLICK=1).
62
+ */
63
+ export function isOneClickEnabled() {
64
+ return process.env.SKYRAMP_FEATURE_ONE_CLICK === "1";
65
+ }
@@ -1,9 +1,15 @@
1
1
  import { resolveServiceDetailsRef } from "./utils.js";
2
- import { isTestbotEnabled } from "./featureFlags.js";
2
+ import { isContractConsumerModeEnabled, isLocalDevEnabled, isTestbotEnabled } from "./featureFlags.js";
3
3
  // Capture and restore the original env var so these tests don't pollute other
4
4
  // test suites or a developer's shell environment where the var may already be set.
5
5
  let originalTestbotEnv;
6
- beforeAll(() => { originalTestbotEnv = process.env.SKYRAMP_FEATURE_TESTBOT; });
6
+ let originalContractConsumerEnv;
7
+ let originalLocalDevEnv;
8
+ beforeAll(() => {
9
+ originalTestbotEnv = process.env.SKYRAMP_FEATURE_TESTBOT;
10
+ originalContractConsumerEnv = process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE;
11
+ originalLocalDevEnv = process.env.SKYRAMP_FEATURE_LOCAL_DEV;
12
+ });
7
13
  afterAll(() => {
8
14
  if (originalTestbotEnv === undefined) {
9
15
  delete process.env.SKYRAMP_FEATURE_TESTBOT;
@@ -11,6 +17,18 @@ afterAll(() => {
11
17
  else {
12
18
  process.env.SKYRAMP_FEATURE_TESTBOT = originalTestbotEnv;
13
19
  }
20
+ if (originalContractConsumerEnv === undefined) {
21
+ delete process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE;
22
+ }
23
+ else {
24
+ process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE = originalContractConsumerEnv;
25
+ }
26
+ if (originalLocalDevEnv === undefined) {
27
+ delete process.env.SKYRAMP_FEATURE_LOCAL_DEV;
28
+ }
29
+ else {
30
+ process.env.SKYRAMP_FEATURE_LOCAL_DEV = originalLocalDevEnv;
31
+ }
14
32
  });
15
33
  describe("isTestbotEnabled", () => {
16
34
  afterEach(() => {
@@ -32,6 +50,43 @@ describe("isTestbotEnabled", () => {
32
50
  expect(isTestbotEnabled()).toBe(false);
33
51
  });
34
52
  });
53
+ describe("isContractConsumerModeEnabled", () => {
54
+ afterEach(() => {
55
+ delete process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE;
56
+ delete process.env.SKYRAMP_FEATURE_LOCAL_DEV;
57
+ });
58
+ it("defaults to false when neither flag is set", () => {
59
+ expect(isContractConsumerModeEnabled()).toBe(false);
60
+ });
61
+ it('returns true when SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE is "1"', () => {
62
+ process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE = "1";
63
+ expect(isContractConsumerModeEnabled()).toBe(true);
64
+ });
65
+ it('returns true when SKYRAMP_FEATURE_LOCAL_DEV is "1" (local-dev implies consumer mode)', () => {
66
+ process.env.SKYRAMP_FEATURE_LOCAL_DEV = "1";
67
+ expect(isContractConsumerModeEnabled()).toBe(true);
68
+ });
69
+ it('returns false when SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE is "0"', () => {
70
+ process.env.SKYRAMP_FEATURE_CONTRACT_CONSUMER_MODE = "0";
71
+ expect(isContractConsumerModeEnabled()).toBe(false);
72
+ });
73
+ });
74
+ describe("isLocalDevEnabled", () => {
75
+ afterEach(() => {
76
+ delete process.env.SKYRAMP_FEATURE_LOCAL_DEV;
77
+ });
78
+ it('returns true when SKYRAMP_FEATURE_LOCAL_DEV is "1"', () => {
79
+ process.env.SKYRAMP_FEATURE_LOCAL_DEV = "1";
80
+ expect(isLocalDevEnabled()).toBe(true);
81
+ });
82
+ it("returns false when SKYRAMP_FEATURE_LOCAL_DEV is unset", () => {
83
+ expect(isLocalDevEnabled()).toBe(false);
84
+ });
85
+ it('returns false when SKYRAMP_FEATURE_LOCAL_DEV is "0"', () => {
86
+ process.env.SKYRAMP_FEATURE_LOCAL_DEV = "0";
87
+ expect(isLocalDevEnabled()).toBe(false);
88
+ });
89
+ });
35
90
  describe("resolveServiceDetailsRef", () => {
36
91
  afterEach(() => {
37
92
  delete process.env.SKYRAMP_FEATURE_TESTBOT;
@@ -0,0 +1 @@
1
+ export declare function getGrpcMockResponseValidationError(responseData?: string): string | null;
@@ -0,0 +1,49 @@
1
+ const GRPC_STATUS_ERROR_NAMES = new Set([
2
+ "CANCELLED",
3
+ "UNKNOWN",
4
+ "INVALID_ARGUMENT",
5
+ "DEADLINE_EXCEEDED",
6
+ "NOT_FOUND",
7
+ "ALREADY_EXISTS",
8
+ "PERMISSION_DENIED",
9
+ "RESOURCE_EXHAUSTED",
10
+ "FAILED_PRECONDITION",
11
+ "ABORTED",
12
+ "OUT_OF_RANGE",
13
+ "UNIMPLEMENTED",
14
+ "INTERNAL",
15
+ "UNAVAILABLE",
16
+ "DATA_LOSS",
17
+ "UNAUTHENTICATED",
18
+ ]);
19
+ export function getGrpcMockResponseValidationError(responseData) {
20
+ if (!responseData || responseData.trim().startsWith("@"))
21
+ return null;
22
+ let parsed;
23
+ try {
24
+ parsed = JSON.parse(responseData);
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
30
+ return null;
31
+ }
32
+ const record = parsed;
33
+ const candidate = record.error;
34
+ if (typeof candidate !== "string")
35
+ return null;
36
+ const normalized = normalizeGrpcStatusName(candidate);
37
+ if (!GRPC_STATUS_ERROR_NAMES.has(normalized))
38
+ return null;
39
+ return `gRPC mock responseData cannot simulate gRPC status errors such as "${normalized}". Use grpcStatusCode/grpcStatusMessage for gRPC status errors, generate a successful protobuf-shaped response, use a real failing service, or record this scenario as blocked`;
40
+ }
41
+ function normalizeGrpcStatusName(value) {
42
+ return value
43
+ .replace(/^GRPC::Status(?:::|\.)?/i, "")
44
+ .replace(/^GRPC::/i, "")
45
+ .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
46
+ .replace(/[\s.:-]+/g, "_")
47
+ .replace(/^_+|_+$/g, "")
48
+ .toUpperCase();
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { getGrpcMockResponseValidationError } from "./grpcMockValidation.js";
2
+ describe("getGrpcMockResponseValidationError", () => {
3
+ it.each([
4
+ ["UNAVAILABLE", "UNAVAILABLE"],
5
+ ["GRPC::Unavailable", "UNAVAILABLE"],
6
+ ["GRPC::Status::UNAVAILABLE", "UNAVAILABLE"],
7
+ ["GRPC::Status.UNAVAILABLE", "UNAVAILABLE"],
8
+ ["DeadlineExceeded", "DEADLINE_EXCEEDED"],
9
+ ])("rejects gRPC status error spelling %s", (input, normalized) => {
10
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ error: input }))).toBe(`gRPC mock responseData cannot simulate gRPC status errors such as "${normalized}". Use grpcStatusCode/grpcStatusMessage for gRPC status errors, generate a successful protobuf-shaped response, use a real failing service, or record this scenario as blocked`);
11
+ });
12
+ it("allows successful protobuf-shaped response bodies", () => {
13
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ tax_exempt: true, features: ["billing"] }))).toBeNull();
14
+ });
15
+ it("returns null when responseData is undefined or empty", () => {
16
+ expect(getGrpcMockResponseValidationError(undefined)).toBeNull();
17
+ expect(getGrpcMockResponseValidationError("")).toBeNull();
18
+ });
19
+ it("returns null when responseData is a file reference", () => {
20
+ expect(getGrpcMockResponseValidationError("@/repo/fixtures/response.json")).toBeNull();
21
+ });
22
+ it("returns null when responseData is a JSON array", () => {
23
+ expect(getGrpcMockResponseValidationError("[1, 2, 3]")).toBeNull();
24
+ });
25
+ it("returns null when responseData is JSON null", () => {
26
+ expect(getGrpcMockResponseValidationError("null")).toBeNull();
27
+ });
28
+ it("returns null when error field is a non-string value", () => {
29
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ error: 14 }))).toBeNull();
30
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ error: null }))).toBeNull();
31
+ });
32
+ it.each(["status", "code", "statusCode"])("allows bare application status fields in %s field", (field) => {
33
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ [field]: "NOT_FOUND" }))).toBeNull();
34
+ });
35
+ it("allows protobuf-shaped responses with application status fields", () => {
36
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ status: "INTERNAL", user_id: 123 }))).toBeNull();
37
+ });
38
+ it("returns null when error field is a non-status-code string", () => {
39
+ expect(getGrpcMockResponseValidationError(JSON.stringify({ error: "user not found" }))).toBeNull();
40
+ });
41
+ });
@@ -0,0 +1,4 @@
1
+ import { HttpMethod } from "../types/TestTypes.js";
2
+ export declare const REST_MOCK_HTTP_METHODS: HttpMethod[];
3
+ export declare function normalizeRestMockMethod(method?: string): string;
4
+ export declare function getRestMockMethodValidationError(method?: string): string | null;
@@ -0,0 +1,13 @@
1
+ import { HttpMethod } from "../types/TestTypes.js";
2
+ export const REST_MOCK_HTTP_METHODS = Object.values(HttpMethod);
3
+ export function normalizeRestMockMethod(method) {
4
+ return method ? method.trim().toUpperCase() : "";
5
+ }
6
+ export function getRestMockMethodValidationError(method) {
7
+ if (!method)
8
+ return null;
9
+ const normalized = normalizeRestMockMethod(method);
10
+ if (REST_MOCK_HTTP_METHODS.includes(normalized))
11
+ return null;
12
+ return `REST mock method must be one of ${REST_MOCK_HTTP_METHODS.join(", ")} or empty string (got "${method}")`;
13
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Mock Compatibility Pre-flight Check
3
+ *
4
+ * Validates mock protocol combinations BEFORE deployment to surface
5
+ * known incompatibilities early rather than at test execution time.
6
+ */
7
+ import { MockProtocol } from "../types/TestTypes.js";
8
+ export { MockProtocol };
9
+ /** Narrow view of a mock spec used only for protocol compatibility checking. */
10
+ export interface MockCompatibilitySpec {
11
+ protocol: MockProtocol;
12
+ endpointURL: string;
13
+ method?: string;
14
+ grpcServiceName?: string;
15
+ kafkaTopic?: string;
16
+ }
17
+ export interface CompatibilityWarning {
18
+ code: string;
19
+ message: string;
20
+ suggestion: string;
21
+ affectedMocks: string[];
22
+ /** When true, the affected mocks cannot intercept traffic and must not be generated or deployed. */
23
+ blocking?: boolean;
24
+ }
25
+ export interface CompatibilityResult {
26
+ compatible: boolean;
27
+ /** True when at least one warning is blocking — those mocks must be skipped entirely. */
28
+ hasBlockers: boolean;
29
+ warnings: CompatibilityWarning[];
30
+ }
31
+ export interface MockCompatibilityOptions {
32
+ /** Enable Docker local-dev checks that require mocks to intercept service DNS aliases. */
33
+ dockerLocalDev?: boolean;
34
+ }
35
+ /**
36
+ * Validates a set of mock specs for known protocol compatibility issues.
37
+ *
38
+ * Rules:
39
+ * - Any gRPC mock present → GRPC_PERSISTENT_CONN warning (DNS hijacking skips persistent conns)
40
+ * - Docker local-dev REST mock using loopback/host.docker.internal → REST_LOOPBACK_URL blocking warning
41
+ *
42
+ * REST mocks work correctly in Docker local-dev mode only when the mock URL uses
43
+ * the real Docker service hostname (e.g. "billing" from "http://billing:5001").
44
+ * The worker adds that hostname as a Docker network alias so DNS resolves to the mock server.
45
+ *
46
+ * `compatible` is false when any warning is blocking and the mock cannot intercept traffic.
47
+ * `hasBlockers` is true when at least one warning is blocking (mock must not be generated/deployed).
48
+ */
49
+ export declare function validateMockCompatibility(mocks: MockCompatibilitySpec[], options?: MockCompatibilityOptions): CompatibilityResult;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Mock Compatibility Pre-flight Check
3
+ *
4
+ * Validates mock protocol combinations BEFORE deployment to surface
5
+ * known incompatibilities early rather than at test execution time.
6
+ */
7
+ import { MockProtocol } from "../types/TestTypes.js";
8
+ export { MockProtocol };
9
+ function parseRestHostname(endpointURL) {
10
+ try {
11
+ const hostname = new URL(endpointURL).hostname.toLowerCase();
12
+ return hostname.startsWith("[") && hostname.endsWith("]")
13
+ ? hostname.slice(1, -1)
14
+ : hostname;
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ function isLoopbackRestEndpoint(endpointURL) {
21
+ const hostname = parseRestHostname(endpointURL);
22
+ return (hostname === "localhost" ||
23
+ hostname === "127.0.0.1" ||
24
+ hostname === "0.0.0.0" ||
25
+ hostname === "::1" ||
26
+ hostname === "host.docker.internal");
27
+ }
28
+ /**
29
+ * Validates a set of mock specs for known protocol compatibility issues.
30
+ *
31
+ * Rules:
32
+ * - Any gRPC mock present → GRPC_PERSISTENT_CONN warning (DNS hijacking skips persistent conns)
33
+ * - Docker local-dev REST mock using loopback/host.docker.internal → REST_LOOPBACK_URL blocking warning
34
+ *
35
+ * REST mocks work correctly in Docker local-dev mode only when the mock URL uses
36
+ * the real Docker service hostname (e.g. "billing" from "http://billing:5001").
37
+ * The worker adds that hostname as a Docker network alias so DNS resolves to the mock server.
38
+ *
39
+ * `compatible` is false when any warning is blocking and the mock cannot intercept traffic.
40
+ * `hasBlockers` is true when at least one warning is blocking (mock must not be generated/deployed).
41
+ */
42
+ export function validateMockCompatibility(mocks, options = {}) {
43
+ const warnings = [];
44
+ const restMocks = mocks.filter((m) => m.protocol === MockProtocol.Rest);
45
+ const grpcMocks = mocks.filter((m) => m.protocol === MockProtocol.Grpc);
46
+ const loopbackRestMocks = options.dockerLocalDev
47
+ ? restMocks.filter((m) => isLoopbackRestEndpoint(m.endpointURL))
48
+ : [];
49
+ if (loopbackRestMocks.length > 0) {
50
+ warnings.push({
51
+ code: "REST_LOOPBACK_URL",
52
+ message: "REST mocks for Docker local-dev must use the original Docker service hostname. " +
53
+ "Loopback hosts such as localhost, 127.0.0.1, 0.0.0.0, ::1, or host.docker.internal " +
54
+ "do not give the Skyramp worker the downstream service DNS alias it needs to intercept traffic.",
55
+ suggestion: "Use the real Docker service origin in endpointURL, for example http://ams:4000 or " +
56
+ "http://billing:5001. Do not use localhost, host.docker.internal, or the Skyramp worker address " +
57
+ "for deployable REST mocks.",
58
+ affectedMocks: loopbackRestMocks.map((m) => m.endpointURL),
59
+ blocking: true,
60
+ });
61
+ }
62
+ // Rule: gRPC mocks use DNS hijacking that doesn't intercept persistent connections
63
+ if (grpcMocks.length > 0) {
64
+ warnings.push({
65
+ code: "GRPC_PERSISTENT_CONN",
66
+ message: "gRPC mocks use DNS hijacking which does not intercept persistent connections. " +
67
+ "If the service under test establishes a gRPC connection before mocks are applied, " +
68
+ "the existing connection will bypass the mock.",
69
+ suggestion: "Apply gRPC mocks before the service under test starts, or restart " +
70
+ "the service after applying mocks so it establishes a new connection through the mock DNS. " +
71
+ "For Docker local-dev, also verify the worker has the original downstream hostname alias " +
72
+ "from endpointURL (for example, partner-accounts for partner-accounts:50051).",
73
+ affectedMocks: grpcMocks.map((m) => m.grpcServiceName || m.endpointURL),
74
+ });
75
+ }
76
+ const hasBlockers = warnings.some((w) => w.blocking);
77
+ return {
78
+ compatible: !hasBlockers,
79
+ hasBlockers,
80
+ warnings,
81
+ };
82
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,79 @@
1
+ import { validateMockCompatibility, MockProtocol } from "./mockCompatibility.js";
2
+ describe("validateMockCompatibility", () => {
3
+ it("REST-only mocks produce no warnings (DNS interception works correctly)", () => {
4
+ const mocks = [
5
+ { protocol: MockProtocol.Rest, endpointURL: "http://billing:5001/api/users", method: "GET" },
6
+ { protocol: MockProtocol.Rest, endpointURL: "http://ams:4000/api/orders", method: "POST" },
7
+ ];
8
+ const result = validateMockCompatibility(mocks);
9
+ expect(result.compatible).toBe(true);
10
+ expect(result.warnings).toHaveLength(0);
11
+ });
12
+ it("REST mocks using loopback URLs get a blocking REST_LOOPBACK_URL warning", () => {
13
+ const mocks = [
14
+ { protocol: MockProtocol.Rest, endpointURL: "http://localhost:8080/api/users", method: "GET" },
15
+ { protocol: MockProtocol.Rest, endpointURL: "http://host.docker.internal:4000/api/orders", method: "POST" },
16
+ { protocol: MockProtocol.Rest, endpointURL: "http://[::1]:8080/api/status", method: "GET" },
17
+ ];
18
+ const result = validateMockCompatibility(mocks, { dockerLocalDev: true });
19
+ expect(result.compatible).toBe(false);
20
+ expect(result.hasBlockers).toBe(true);
21
+ const warning = result.warnings.find((w) => w.code === "REST_LOOPBACK_URL");
22
+ expect(warning).toBeDefined();
23
+ expect(warning.blocking).toBe(true);
24
+ expect(warning.affectedMocks).toContain("http://localhost:8080/api/users");
25
+ expect(warning.affectedMocks).toContain("http://host.docker.internal:4000/api/orders");
26
+ expect(warning.affectedMocks).toContain("http://[::1]:8080/api/status");
27
+ });
28
+ it("does not block loopback REST URLs outside Docker local-dev preflight mode", () => {
29
+ const mocks = [
30
+ { protocol: MockProtocol.Rest, endpointURL: "http://localhost:8080/api/users", method: "GET" },
31
+ ];
32
+ const result = validateMockCompatibility(mocks);
33
+ expect(result.compatible).toBe(true);
34
+ expect(result.hasBlockers).toBe(false);
35
+ expect(result.warnings.find((w) => w.code === "REST_LOOPBACK_URL")).toBeUndefined();
36
+ });
37
+ it("Kafka mocks produce no compatibility warning when generation payload shape is valid", () => {
38
+ const mocks = [
39
+ { protocol: MockProtocol.Kafka, endpointURL: "redpanda:9092", kafkaTopic: "user-events" },
40
+ { protocol: MockProtocol.Rest, endpointURL: "http://ams:4000/api/users", method: "GET" },
41
+ ];
42
+ const result = validateMockCompatibility(mocks);
43
+ expect(result.compatible).toBe(true);
44
+ expect(result.hasBlockers).toBe(false);
45
+ expect(result.warnings.find((w) => w.code === "KAFKA_SDK_INCOMPATIBLE")).toBeUndefined();
46
+ });
47
+ it("gRPC mocks produce GRPC_PERSISTENT_CONN warning", () => {
48
+ const mocks = [
49
+ { protocol: MockProtocol.Grpc, endpointURL: "grpc://localhost:50051", grpcServiceName: "UserService" },
50
+ { protocol: MockProtocol.Rest, endpointURL: "http://ams:4000/api/users", method: "GET" },
51
+ ];
52
+ const result = validateMockCompatibility(mocks);
53
+ expect(result.compatible).toBe(true);
54
+ const grpcWarning = result.warnings.find((w) => w.code === "GRPC_PERSISTENT_CONN");
55
+ expect(grpcWarning).toBeDefined();
56
+ expect(grpcWarning.affectedMocks).toContain("UserService");
57
+ });
58
+ it("gRPC on non-8080 ports is allowed with only the persistent connection warning", () => {
59
+ const mocks = [
60
+ { protocol: MockProtocol.Grpc, endpointURL: "partner-accounts:50051", grpcServiceName: "PaymentService" },
61
+ ];
62
+ const result = validateMockCompatibility(mocks);
63
+ expect(result.compatible).toBe(true);
64
+ expect(result.hasBlockers).toBe(false);
65
+ expect(result.warnings).toHaveLength(1);
66
+ expect(result.warnings[0].code).toBe("GRPC_PERSISTENT_CONN");
67
+ expect(result.warnings.find((w) => w.code === "GRPC_PORT_MISMATCH")).toBeUndefined();
68
+ });
69
+ it("gRPC on port 8080 also gets only GRPC_PERSISTENT_CONN", () => {
70
+ const mocks = [
71
+ { protocol: MockProtocol.Grpc, endpointURL: "some-service:8080", grpcServiceName: "ProfileService" },
72
+ ];
73
+ const result = validateMockCompatibility(mocks);
74
+ expect(result.compatible).toBe(true);
75
+ expect(result.hasBlockers).toBe(false);
76
+ expect(result.warnings).toHaveLength(1);
77
+ expect(result.warnings[0].code).toBe("GRPC_PERSISTENT_CONN");
78
+ });
79
+ });
@@ -1,3 +1,3 @@
1
- export declare const SKYRAMP_IMAGE_VERSION = "v1.3.29";
2
- export declare const EXECUTOR_DOCKER_IMAGE = "skyramp/executor:v1.3.29";
3
- export declare const WORKER_DOCKER_IMAGE = "skyramp/worker:v1.3.29";
1
+ export declare const SKYRAMP_IMAGE_VERSION = "v1.3.30";
2
+ export declare const EXECUTOR_DOCKER_IMAGE = "skyramp/executor:v1.3.30";
3
+ export declare const WORKER_DOCKER_IMAGE = "skyramp/worker:v1.3.30";
@@ -1,3 +1,3 @@
1
- export const SKYRAMP_IMAGE_VERSION = "v1.3.29";
1
+ export const SKYRAMP_IMAGE_VERSION = "v1.3.30";
2
2
  export const EXECUTOR_DOCKER_IMAGE = `skyramp/executor:${SKYRAMP_IMAGE_VERSION}`;
3
3
  export const WORKER_DOCKER_IMAGE = `skyramp/worker:${SKYRAMP_IMAGE_VERSION}`;