@skyramp/mcp 0.2.8 → 0.2.150-rc.local.de
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 +18 -17
- package/build/commands/localDevTestChangesCommand.d.ts +15 -0
- package/build/commands/localDevTestChangesCommand.js +175 -0
- package/build/index.js +74 -13
- package/build/prompts/enhance-assertions/sharedAssertionRules.js +1 -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 +414 -0
- package/build/prompts/local-dev/local-dev-prompts.d.ts +4 -0
- package/build/prompts/local-dev/local-dev-prompts.js +152 -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 +79 -16
- package/build/prompts/test-recommendation/test-recommendation-prompt.js +41 -4
- package/build/prompts/test-recommendation/test-recommendation-prompt.test.js +34 -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 +10 -2
- package/build/services/TestExecutionService.js +220 -28
- package/build/services/TestExecutionService.test.js +447 -16
- package/build/services/TestGenerationService.d.ts +2 -2
- package/build/tool-phases.js +4 -0
- package/build/tools/code-refactor/enhanceAssertionsTool.js +34 -2
- package/build/tools/enrichTestWithMocksTool.d.ts +15 -0
- package/build/tools/enrichTestWithMocksTool.js +414 -0
- package/build/tools/enrichTestWithMocksTool.test.d.ts +1 -0
- package/build/tools/enrichTestWithMocksTool.test.js +397 -0
- package/build/tools/executeSkyrampTestTool.d.ts +3 -0
- package/build/tools/executeSkyrampTestTool.js +73 -18
- package/build/tools/executeSkyrampTestTool.test.d.ts +1 -0
- package/build/tools/executeSkyrampTestTool.test.js +111 -0
- package/build/tools/generate-tests/batchMockGenerationTool.d.ts +72 -0
- package/build/tools/generate-tests/batchMockGenerationTool.js +382 -0
- package/build/tools/generate-tests/batchMockGenerationTool.test.d.ts +1 -0
- package/build/tools/generate-tests/batchMockGenerationTool.test.js +514 -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/generate-tests/generateMockRestTool.test.d.ts +1 -0
- package/build/tools/generate-tests/generateMockRestTool.test.js +340 -0
- package/build/tools/generateEnrichedIntegrationTestTool.d.ts +24 -0
- package/build/tools/generateEnrichedIntegrationTestTool.js +209 -0
- package/build/tools/generateEnrichedIntegrationTestTool.test.d.ts +1 -0
- package/build/tools/generateEnrichedIntegrationTestTool.test.js +199 -0
- package/build/tools/one-click/oneClickTool.d.ts +10 -0
- package/build/tools/one-click/oneClickTool.js +182 -40
- package/build/tools/one-click/oneClickTool.test.d.ts +1 -0
- package/build/tools/one-click/oneClickTool.test.js +204 -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
|
@@ -14,6 +14,9 @@ export function parseChangedFilesFromDiff(rawDiff) {
|
|
|
14
14
|
return out;
|
|
15
15
|
}
|
|
16
16
|
/** Parse diff headers to find newly created and deleted files. */
|
|
17
|
+
function isShaLikeRef(ref) {
|
|
18
|
+
return /^[0-9a-f]{7,40}$/i.test(ref);
|
|
19
|
+
}
|
|
17
20
|
function parseNewAndDeletedFiles(rawDiff) {
|
|
18
21
|
const newFiles = [];
|
|
19
22
|
const deletedFiles = [];
|
|
@@ -34,24 +37,84 @@ function parseNewAndDeletedFiles(rawDiff) {
|
|
|
34
37
|
}
|
|
35
38
|
return { newFiles, deletedFiles };
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Normalize and validate a caller-provided base branch/ref before passing it
|
|
42
|
+
* to git. Reject option-like or ambiguous values so the ref is always treated
|
|
43
|
+
* as a revision name, not as a command-line flag.
|
|
44
|
+
*/
|
|
45
|
+
export function normalizeProvidedBaseRef(providedBaseBranch) {
|
|
46
|
+
if (providedBaseBranch === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const trimmed = providedBaseBranch.trim();
|
|
49
|
+
if (!trimmed)
|
|
50
|
+
return undefined;
|
|
51
|
+
if (trimmed.startsWith("-")) {
|
|
52
|
+
throw new Error(`Invalid base branch/ref "${providedBaseBranch}": refs must not start with '-'.`);
|
|
53
|
+
}
|
|
54
|
+
if (/\s/.test(trimmed) || trimmed.includes("\0")) {
|
|
55
|
+
throw new Error(`Invalid base branch/ref "${providedBaseBranch}": refs must not contain whitespace or NUL characters.`);
|
|
56
|
+
}
|
|
57
|
+
return trimmed;
|
|
58
|
+
}
|
|
59
|
+
async function tryDiff(git, ref, includeUncommitted = false) {
|
|
38
60
|
try {
|
|
39
|
-
|
|
61
|
+
// When includeUncommitted is true, diff the ref directly against the
|
|
62
|
+
// working tree so uncommitted/unstaged local changes are captured.
|
|
63
|
+
const diffRange = includeUncommitted ? ref : `${ref}...HEAD`;
|
|
64
|
+
const changedFilesRaw = await git.diff([diffRange, "--name-only"]);
|
|
40
65
|
const changedFiles = changedFilesRaw
|
|
41
66
|
.split("\n")
|
|
42
67
|
.map((f) => f.trim())
|
|
43
68
|
.filter((f) => f.length > 0);
|
|
44
|
-
const diffStat = await git.diff([
|
|
45
|
-
const fullDiff = await git.diff([
|
|
69
|
+
const diffStat = await git.diff([diffRange, "--stat"]);
|
|
70
|
+
const fullDiff = await git.diff([diffRange]);
|
|
46
71
|
const { newFiles, deletedFiles } = parseNewAndDeletedFiles(fullDiff);
|
|
47
|
-
|
|
72
|
+
// git diff does not include untracked files. Include them as both changed
|
|
73
|
+
// and new so endpoint classification treats newly created local files as new.
|
|
74
|
+
if (includeUncommitted) {
|
|
75
|
+
const statusResult = await git.status();
|
|
76
|
+
const untrackedFiles = statusResult.not_added ?? [];
|
|
77
|
+
if (untrackedFiles.length > 0) {
|
|
78
|
+
const changedSet = new Set(changedFiles);
|
|
79
|
+
const newSet = new Set(newFiles);
|
|
80
|
+
for (const file of untrackedFiles) {
|
|
81
|
+
if (!changedSet.has(file)) {
|
|
82
|
+
changedFiles.push(file);
|
|
83
|
+
changedSet.add(file);
|
|
84
|
+
}
|
|
85
|
+
if (!newSet.has(file)) {
|
|
86
|
+
newFiles.push(file);
|
|
87
|
+
newSet.add(file);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
changedFiles,
|
|
94
|
+
diffContent: fullDiff,
|
|
95
|
+
diffStat,
|
|
96
|
+
newFiles,
|
|
97
|
+
deletedFiles,
|
|
98
|
+
};
|
|
48
99
|
}
|
|
49
100
|
catch (err) {
|
|
50
|
-
logger.debug(`tryDiff against ${ref} failed`, {
|
|
101
|
+
logger.debug(`tryDiff against ${ref} failed`, {
|
|
102
|
+
error: err instanceof Error ? err.message : String(err),
|
|
103
|
+
});
|
|
51
104
|
return undefined;
|
|
52
105
|
}
|
|
53
106
|
}
|
|
54
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Compute the diff between a base reference and the current state.
|
|
109
|
+
*
|
|
110
|
+
* @param repositoryPath Absolute path to the git repository.
|
|
111
|
+
* @param providedBaseBranch A branch name, tag, or commit SHA to diff against.
|
|
112
|
+
* When omitted, the remote default branch is auto-detected.
|
|
113
|
+
* @param includeUncommitted When true, diffs against the working tree so
|
|
114
|
+
* uncommitted/unstaged changes are included. Defaults to false (CI mode
|
|
115
|
+
* that only considers committed changes via the three-dot form).
|
|
116
|
+
*/
|
|
117
|
+
export async function computeBranchDiff(repositoryPath, providedBaseBranch, includeUncommitted = false) {
|
|
55
118
|
const git = simpleGit(repositoryPath);
|
|
56
119
|
const isRepo = await git.checkIsRepo();
|
|
57
120
|
if (!isRepo) {
|
|
@@ -60,14 +123,32 @@ export async function computeBranchDiff(repositoryPath, providedBaseBranch) {
|
|
|
60
123
|
const branchInfo = await git.branch();
|
|
61
124
|
const currentBranch = branchInfo.current || "HEAD";
|
|
62
125
|
// Build candidate base refs in priority order:
|
|
63
|
-
// 1. Provided
|
|
64
|
-
// 2.
|
|
65
|
-
// 3.
|
|
126
|
+
// 1. Provided value used directly (supports SHAs, local branches, tags)
|
|
127
|
+
// 2. Provided value with origin/ prefix (remote branch)
|
|
128
|
+
// 3. Remote default branch auto-detected from available remotes
|
|
129
|
+
// 4. FETCH_HEAD — present in base_commit repos (git fetch --depth 1 origin <sha>)
|
|
66
130
|
// where no remote tracking branch is created
|
|
67
|
-
//
|
|
131
|
+
// 5. HEAD~1 — last resort for repos with no remote at all
|
|
68
132
|
const candidates = [];
|
|
69
|
-
|
|
70
|
-
|
|
133
|
+
const normalizedBaseBranch = normalizeProvidedBaseRef(providedBaseBranch);
|
|
134
|
+
if (normalizedBaseBranch) {
|
|
135
|
+
const isRemoteQualified = normalizedBaseBranch.startsWith("origin/");
|
|
136
|
+
const looksLikeSimpleBranch = !isRemoteQualified &&
|
|
137
|
+
!isShaLikeRef(normalizedBaseBranch) &&
|
|
138
|
+
!/[~^:@]/.test(normalizedBaseBranch);
|
|
139
|
+
if (includeUncommitted && looksLikeSimpleBranch) {
|
|
140
|
+
// Local-dev diffs should prefer the remote base branch when available;
|
|
141
|
+
// a developer's local main may be ahead of origin/main.
|
|
142
|
+
candidates.push(`origin/${normalizedBaseBranch}`);
|
|
143
|
+
candidates.push(normalizedBaseBranch);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
// Try the raw value first — handles commit SHAs, tags, and explicit local refs.
|
|
147
|
+
candidates.push(normalizedBaseBranch);
|
|
148
|
+
if (!isRemoteQualified) {
|
|
149
|
+
candidates.push(`origin/${normalizedBaseBranch}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
71
152
|
}
|
|
72
153
|
// Auto-detect remote default branch
|
|
73
154
|
try {
|
|
@@ -89,12 +170,13 @@ export async function computeBranchDiff(repositoryPath, providedBaseBranch) {
|
|
|
89
170
|
// Final fallback
|
|
90
171
|
candidates.push("HEAD~1");
|
|
91
172
|
for (const ref of candidates) {
|
|
92
|
-
const result = await tryDiff(git, ref);
|
|
173
|
+
const result = await tryDiff(git, ref, includeUncommitted);
|
|
93
174
|
if (result) {
|
|
94
175
|
logger.info("Branch diff computed", {
|
|
95
176
|
currentBranch,
|
|
96
177
|
baseBranch: ref,
|
|
97
178
|
changedFiles: result.changedFiles.length,
|
|
179
|
+
includeUncommitted,
|
|
98
180
|
});
|
|
99
181
|
return { currentBranch, baseBranch: ref, ...result };
|
|
100
182
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { execFileSync } from "child_process";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { computeBranchDiff, normalizeProvidedBaseRef } from "./branchDiff.js";
|
|
6
|
+
function git(cwd, args) {
|
|
7
|
+
execFileSync("git", args, { cwd, stdio: "ignore" });
|
|
8
|
+
}
|
|
9
|
+
describe("computeBranchDiff", () => {
|
|
10
|
+
let tmpDir;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "skyramp-branch-diff-"));
|
|
13
|
+
git(tmpDir, ["init"]);
|
|
14
|
+
git(tmpDir, ["branch", "-m", "main"]);
|
|
15
|
+
fs.writeFileSync(path.join(tmpDir, "README.md"), "initial\n");
|
|
16
|
+
git(tmpDir, ["add", "README.md"]);
|
|
17
|
+
git(tmpDir, [
|
|
18
|
+
"-c",
|
|
19
|
+
"user.name=Test",
|
|
20
|
+
"-c",
|
|
21
|
+
"user.email=test@example.com",
|
|
22
|
+
"commit",
|
|
23
|
+
"-m",
|
|
24
|
+
"initial",
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
it("classifies untracked files as both changed and new when including uncommitted changes", async () => {
|
|
31
|
+
fs.mkdirSync(path.join(tmpDir, "src"));
|
|
32
|
+
fs.writeFileSync(path.join(tmpDir, "src", "newEndpoint.ts"), "export const value = 1;\n");
|
|
33
|
+
const diff = await computeBranchDiff(tmpDir, "HEAD", true);
|
|
34
|
+
expect(diff.changedFiles).toContain("src/newEndpoint.ts");
|
|
35
|
+
expect(diff.newFiles).toContain("src/newEndpoint.ts");
|
|
36
|
+
});
|
|
37
|
+
it("prefers origin branch over local branch for uncommitted local-dev diffs", async () => {
|
|
38
|
+
const remoteDir = fs.mkdtempSync(path.join(os.tmpdir(), "skyramp-branch-diff-remote-"));
|
|
39
|
+
try {
|
|
40
|
+
git(remoteDir, ["init", "--bare"]);
|
|
41
|
+
git(tmpDir, ["remote", "add", "origin", remoteDir]);
|
|
42
|
+
git(tmpDir, ["push", "-u", "origin", "main"]);
|
|
43
|
+
fs.writeFileSync(path.join(tmpDir, "README.md"), "local main ahead\n");
|
|
44
|
+
git(tmpDir, ["add", "README.md"]);
|
|
45
|
+
git(tmpDir, [
|
|
46
|
+
"-c",
|
|
47
|
+
"user.name=Test",
|
|
48
|
+
"-c",
|
|
49
|
+
"user.email=test@example.com",
|
|
50
|
+
"commit",
|
|
51
|
+
"-m",
|
|
52
|
+
"local main ahead",
|
|
53
|
+
]);
|
|
54
|
+
fs.writeFileSync(path.join(tmpDir, "local.txt"), "uncommitted\n");
|
|
55
|
+
const diff = await computeBranchDiff(tmpDir, "main", true);
|
|
56
|
+
expect(diff.baseBranch).toBe("origin/main");
|
|
57
|
+
expect(diff.changedFiles.join("\n")).not.toMatch(/^origin\//m);
|
|
58
|
+
expect(diff.changedFiles).toContain("README.md");
|
|
59
|
+
expect(diff.changedFiles).toContain("local.txt");
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
fs.rmSync(remoteDir, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
it("uses SHA-like base refs directly when including uncommitted changes", async () => {
|
|
66
|
+
const remoteDir = fs.mkdtempSync(path.join(os.tmpdir(), "skyramp-branch-diff-remote-"));
|
|
67
|
+
try {
|
|
68
|
+
git(remoteDir, ["init", "--bare"]);
|
|
69
|
+
git(tmpDir, ["remote", "add", "origin", remoteDir]);
|
|
70
|
+
git(tmpDir, ["push", "-u", "origin", "main"]);
|
|
71
|
+
const baseSha = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
|
|
72
|
+
cwd: tmpDir,
|
|
73
|
+
encoding: "utf8",
|
|
74
|
+
}).trim();
|
|
75
|
+
fs.writeFileSync(path.join(tmpDir, "README.md"), "local main ahead\n");
|
|
76
|
+
git(tmpDir, ["add", "README.md"]);
|
|
77
|
+
git(tmpDir, [
|
|
78
|
+
"-c",
|
|
79
|
+
"user.name=Test",
|
|
80
|
+
"-c",
|
|
81
|
+
"user.email=test@example.com",
|
|
82
|
+
"commit",
|
|
83
|
+
"-m",
|
|
84
|
+
"local main ahead",
|
|
85
|
+
]);
|
|
86
|
+
git(tmpDir, ["branch", baseSha, "HEAD"]);
|
|
87
|
+
git(tmpDir, ["push", "origin", baseSha]);
|
|
88
|
+
fs.writeFileSync(path.join(tmpDir, "local.txt"), "uncommitted\n");
|
|
89
|
+
const diff = await computeBranchDiff(tmpDir, baseSha, true);
|
|
90
|
+
expect(diff.baseBranch).toBe(baseSha);
|
|
91
|
+
expect(diff.baseBranch).not.toMatch(/^origin\//);
|
|
92
|
+
expect(diff.changedFiles).toContain("local.txt");
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
fs.rmSync(remoteDir, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
it("trims provided base refs before using them", () => {
|
|
99
|
+
expect(normalizeProvidedBaseRef(" main ")).toBe("main");
|
|
100
|
+
});
|
|
101
|
+
it("rejects option-like provided base refs", () => {
|
|
102
|
+
expect(() => normalizeProvidedBaseRef("--output=/tmp/evil")).toThrow("refs must not start with '-'");
|
|
103
|
+
});
|
|
104
|
+
it("rejects provided base refs containing internal whitespace", () => {
|
|
105
|
+
expect(() => normalizeProvidedBaseRef("main --stat")).toThrow("refs must not contain whitespace");
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -55,7 +55,7 @@ describe("dockerImageExistsLocally", () => {
|
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
describe("pullDockerImage", () => {
|
|
58
|
-
const IMAGE = "skyramp/executor:v1.3.
|
|
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,14 @@ 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;
|
|
@@ -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,16 @@ 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
|
+
}
|
|
@@ -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
|
-
|
|
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}". 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}". 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;
|