@ai-dev-tools/csharp-copilot-core 0.0.19
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/ai-dev-tools-csharp-copilot-core-0.0.19.tgz +0 -0
- package/azure-pipelines.yml +52 -0
- package/out/analyze/cecil.d.ts +1 -0
- package/out/analyze/cecil.js +42 -0
- package/out/analyze/cecil.js.map +1 -0
- package/out/analyze/checkCodeSyntax.d.ts +7 -0
- package/out/analyze/checkCodeSyntax.js +67 -0
- package/out/analyze/checkCodeSyntax.js.map +1 -0
- package/out/analyze/generateCodeDependency.d.ts +6 -0
- package/out/analyze/generateCodeDependency.js +122 -0
- package/out/analyze/generateCodeDependency.js.map +1 -0
- package/out/analyze/installAnalyzerTool.d.ts +1 -0
- package/out/analyze/installAnalyzerTool.js +82 -0
- package/out/analyze/installAnalyzerTool.js.map +1 -0
- package/out/atmpCache/deps/EplantRequestCategoryCondition_Conditions_Eplant_Workflows_SharedSegmentsPlugins_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +281 -0
- package/out/atmpCache/deps/IdentitySelectAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/deps/SqmidHelperTests_Utils_HttpRequestParser_Overview_Workflows_SharedSegmentsTests_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +1 -0
- package/out/atmpCache/deps/SqmidHelper_Utils_HttpRequestParser_Overview_Workflows_SharedSegmentsPlugins_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +1 -0
- package/out/atmpCache/deps/ToListCountAnalyzerTests_ToListinatorTests_test_AIUnitTestExample_code_d.deps +4037 -0
- package/out/atmpCache/deps/ToListCountAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/deps/ToListCountCodeFixProvider_ToListinatorCodeFixes_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/deps/ToListForEachAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/dllref/ToListinatorTests_ToListinatorTests_test_AIUnitTestExample_code_d.dllref +202 -0
- package/out/batch/generateCodeTests.d.ts +6 -0
- package/out/batch/generateCodeTests.js +147 -0
- package/out/batch/generateCodeTests.js.map +1 -0
- package/out/batch/getFolderCodeFile.d.ts +1 -0
- package/out/batch/getFolderCodeFile.js +19 -0
- package/out/batch/getFolderCodeFile.js.map +1 -0
- package/out/batch/getProjectCodeFile.d.ts +4 -0
- package/out/batch/getProjectCodeFile.js +87 -0
- package/out/batch/getProjectCodeFile.js.map +1 -0
- package/out/batch/getSolutionCodeFile.d.ts +8 -0
- package/out/batch/getSolutionCodeFile.js +70 -0
- package/out/batch/getSolutionCodeFile.js.map +1 -0
- package/out/benchmark/formatToMarkdown.d.ts +2 -0
- package/out/benchmark/formatToMarkdown.js +101 -0
- package/out/benchmark/formatToMarkdown.js.map +1 -0
- package/out/benchmark/generateBenchmarkReport.d.ts +1 -0
- package/out/benchmark/generateBenchmarkReport.js +82 -0
- package/out/benchmark/generateBenchmarkReport.js.map +1 -0
- package/out/codeCoverage/codeCoverage.d.ts +6 -0
- package/out/codeCoverage/codeCoverage.js +35 -0
- package/out/codeCoverage/codeCoverage.js.map +1 -0
- package/out/codeCoverage/codeCoverageReport.d.ts +6 -0
- package/out/codeCoverage/codeCoverageReport.js +72 -0
- package/out/codeCoverage/codeCoverageReport.js.map +1 -0
- package/out/codeCoverage/extractCodeCoverageInfo.d.ts +2 -0
- package/out/codeCoverage/extractCodeCoverageInfo.js +80 -0
- package/out/codeCoverage/extractCodeCoverageInfo.js.map +1 -0
- package/out/codeCoverage/generateCodeCoverageReport.d.ts +1 -0
- package/out/codeCoverage/generateCodeCoverageReport.js +27 -0
- package/out/codeCoverage/generateCodeCoverageReport.js.map +1 -0
- package/out/codeCoverage/getCodeCoverageSetting.d.ts +1 -0
- package/out/codeCoverage/getCodeCoverageSetting.js +58 -0
- package/out/codeCoverage/getCodeCoverageSetting.js.map +1 -0
- package/out/codeCoverage/reportTool.d.ts +2 -0
- package/out/codeCoverage/reportTool.js +22 -0
- package/out/codeCoverage/reportTool.js.map +1 -0
- package/out/codeCoverage/simplifyCoverageXml.d.ts +2 -0
- package/out/codeCoverage/simplifyCoverageXml.js +116 -0
- package/out/codeCoverage/simplifyCoverageXml.js.map +1 -0
- package/out/codebk/250804prompt/buildAfGuidelines.liquid +15 -0
- package/out/codebk/250804prompt/general/generalBuildAutofixGuidelines.liquid +13 -0
- package/out/codebk/250804prompt/general/generalUtGuidelines.liquid +18 -0
- package/out/codebk/250804prompt/generateUtAutoFix.liquid +19 -0
- package/out/codebk/250804prompt/generateUtGuidelines.liquid +13 -0
- package/out/codebk/250804prompt/generateUtSystem.liquid +5 -0
- package/out/codebk/250804prompt/generateUtUserInput.liquid +27 -0
- package/out/codebk/250804prompt/testAfGuidelines.liquid +6 -0
- package/out/codebk/250804prompt/xap/xapBuildAutofixGuidelines.liquid +13 -0
- package/out/codebk/250804prompt/xap/xapCodeCodeDependency.liquid +0 -0
- package/out/codebk/250804prompt/xap/xapCodeSample.liquid +38 -0
- package/out/codebk/250804prompt/xap/xapUtGuideline-240804.liquid +36 -0
- package/out/codebk/250804prompt/xap/xapUtGuideline.liquid +36 -0
- package/out/codebk/childProcessManager.d.ts +1 -0
- package/out/codebk/childProcessManager.js +50 -0
- package/out/codebk/childProcessManager.js.map +1 -0
- package/out/codebk/msBuidSpawn.d.ts +1 -0
- package/out/codebk/msBuidSpawn.js +58 -0
- package/out/codebk/msBuidSpawn.js.map +1 -0
- package/out/codebk/msBuild.d.ts +1 -0
- package/out/codebk/msBuild.js +123 -0
- package/out/codebk/msBuild.js.map +1 -0
- package/out/codebk/old/generateXapTestAutoFix.liquid +12 -0
- package/out/codebk/old/generateXapTestGuidelines-fm.liquid +68 -0
- package/out/codebk/old/generateXapTestGuidelines.liquid +28 -0
- package/out/codebk/old/xapGuideline-fm.liquid +149 -0
- package/out/codebk/old/xapGuideline.liquid +37 -0
- package/out/codebk/oldExec/checkCodeSyntax.d.ts +1 -0
- package/out/codebk/oldExec/checkCodeSyntax.js +81 -0
- package/out/codebk/oldExec/checkCodeSyntax.js.map +1 -0
- package/out/codebk/oldExec/codeCoverage.d.ts +1 -0
- package/out/codebk/oldExec/codeCoverage.js +54 -0
- package/out/codebk/oldExec/codeCoverage.js.map +1 -0
- package/out/codebk/oldExec/codeCoverageReport.d.ts +1 -0
- package/out/codebk/oldExec/codeCoverageReport.js +64 -0
- package/out/codebk/oldExec/codeCoverageReport.js.map +1 -0
- package/out/codebk/oldExec/containsMethods.d.ts +1 -0
- package/out/codebk/oldExec/containsMethods.js +74 -0
- package/out/codebk/oldExec/containsMethods.js.map +1 -0
- package/out/codebk/oldExec/generateCodeDependency.d.ts +1 -0
- package/out/codebk/oldExec/generateCodeDependency.js +95 -0
- package/out/codebk/oldExec/generateCodeDependency.js.map +1 -0
- package/out/codebk/oldExec/msBuild.d.ts +1 -0
- package/out/codebk/oldExec/msBuild.js +53 -0
- package/out/codebk/oldExec/msBuild.js.map +1 -0
- package/out/codebk/oldExec/vsTest.d.ts +1 -0
- package/out/codebk/oldExec/vsTest.js +71 -0
- package/out/codebk/oldExec/vsTest.js.map +1 -0
- package/out/codebk/prompts/general/generalUnitTestGuidelines-20250702.liquid +56 -0
- package/out/codebk/prompts/generateXapTestGuidelines-20250704.liquid +21 -0
- package/out/codebk/prompts/generateXapTestGuidelines-o.liquid +29 -0
- package/out/codebk/prompts/xap/xapGuideline-o.liquid +45 -0
- package/out/codebk/testbuildkill.d.ts +1 -0
- package/out/codebk/testbuildkill.js +37 -0
- package/out/codebk/testbuildkill.js.map +1 -0
- package/out/command/index.d.ts +2 -0
- package/out/command/index.js +85 -0
- package/out/command/index.js.map +1 -0
- package/out/command/utGenWrapper.d.ts +3 -0
- package/out/command/utGenWrapper.js +40 -0
- package/out/command/utGenWrapper.js.map +1 -0
- package/out/exit/childProcessManager.d.ts +2 -0
- package/out/exit/childProcessManager.js +43 -0
- package/out/exit/childProcessManager.js.map +1 -0
- package/out/exit/setupProcessSignalHandler.d.ts +1 -0
- package/out/exit/setupProcessSignalHandler.js +18 -0
- package/out/exit/setupProcessSignalHandler.js.map +1 -0
- package/out/gen/autoFix.d.ts +4 -0
- package/out/gen/autoFix.js +125 -0
- package/out/gen/autoFix.js.map +1 -0
- package/out/gen/csharpUtGen.d.ts +2 -0
- package/out/gen/csharpUtGen.js +151 -0
- package/out/gen/csharpUtGen.js.map +1 -0
- package/out/gen/ensureValidLLMResponse.d.ts +1 -0
- package/out/gen/ensureValidLLMResponse.js +19 -0
- package/out/gen/ensureValidLLMResponse.js.map +1 -0
- package/out/gen/postGen/extractCodeFromResponse.d.ts +1 -0
- package/out/gen/postGen/extractCodeFromResponse.js +37 -0
- package/out/gen/postGen/extractCodeFromResponse.js.map +1 -0
- package/out/gen/postGen/postGenProcess.d.ts +1 -0
- package/out/gen/postGen/postGenProcess.js +36 -0
- package/out/gen/postGen/postGenProcess.js.map +1 -0
- package/out/gen/postGen/removeComments.d.ts +1 -0
- package/out/gen/postGen/removeComments.js +92 -0
- package/out/gen/postGen/removeComments.js.map +1 -0
- package/out/gen/postGen/removeSingleLines.d.ts +1 -0
- package/out/gen/postGen/removeSingleLines.js +28 -0
- package/out/gen/postGen/removeSingleLines.js.map +1 -0
- package/out/gen/postGen/repairRequiredNameSpaces.d.ts +1 -0
- package/out/gen/postGen/repairRequiredNameSpaces.js +116 -0
- package/out/gen/postGen/repairRequiredNameSpaces.js.map +1 -0
- package/out/gen/postGen/validateTestCode.d.ts +1 -0
- package/out/gen/postGen/validateTestCode.js +14 -0
- package/out/gen/postGen/validateTestCode.js.map +1 -0
- package/out/gen/preGen/excludeFileName.d.ts +1 -0
- package/out/gen/preGen/excludeFileName.js +49 -0
- package/out/gen/preGen/excludeFileName.js.map +1 -0
- package/out/gen/preGen/excludeSpecificTag.d.ts +1 -0
- package/out/gen/preGen/excludeSpecificTag.js +18 -0
- package/out/gen/preGen/excludeSpecificTag.js.map +1 -0
- package/out/gen/preGen/preGenProcess.d.ts +1 -0
- package/out/gen/preGen/preGenProcess.js +22 -0
- package/out/gen/preGen/preGenProcess.js.map +1 -0
- package/out/gen/preGen/validateCode.d.ts +3 -0
- package/out/gen/preGen/validateCode.js +62 -0
- package/out/gen/preGen/validateCode.js.map +1 -0
- package/out/index.d.ts +2 -0
- package/out/index.js +8 -0
- package/out/index.js.map +1 -0
- package/out/llm/model/Gpt4o.d.ts +1 -0
- package/out/llm/model/Gpt4o.js +91 -0
- package/out/llm/model/Gpt4o.js.map +1 -0
- package/out/llm/model/claude4.d.ts +1 -0
- package/out/llm/model/claude4.js +3 -0
- package/out/llm/model/claude4.js.map +1 -0
- package/out/llm/preparePrompt.d.ts +2 -0
- package/out/llm/preparePrompt.js +110 -0
- package/out/llm/preparePrompt.js.map +1 -0
- package/out/llm/prompt/buildAfGuidelines.liquid +15 -0
- package/out/llm/prompt/general/generalBuildAutofixGuidelines.liquid +13 -0
- package/out/llm/prompt/general/generalUtGuidelines.liquid +16 -0
- package/out/llm/prompt/generateUtAutoFix.liquid +19 -0
- package/out/llm/prompt/generateUtDependency.liquid +3 -0
- package/out/llm/prompt/generateUtGuidelines.liquid +29 -0
- package/out/llm/prompt/generateUtSystem.liquid +5 -0
- package/out/llm/prompt/generateUtTemplate.liquid +30 -0
- package/out/llm/prompt/generateUtUserInput.liquid +4 -0
- package/out/llm/prompt/testAfGuidelines.liquid +6 -0
- package/out/llm/prompt/userCustomPrompt.liquid +0 -0
- package/out/llm/prompt/xap/xapBuildAutofixGuidelines.liquid +13 -0
- package/out/llm/prompt/xap/xapCodeCodeDependency.liquid +0 -0
- package/out/llm/prompt/xap/xapCodeSample.liquid +38 -0
- package/out/llm/prompt/xap/xapUtGuideline-240804.liquid +36 -0
- package/out/llm/prompt/xap/xapUtGuideline.liquid +37 -0
- package/out/llm/sendRequestToLLM.d.ts +4 -0
- package/out/llm/sendRequestToLLM.js +12 -0
- package/out/llm/sendRequestToLLM.js.map +1 -0
- package/out/llm/sendRequestToSelfHostLLM.d.ts +4 -0
- package/out/llm/sendRequestToSelfHostLLM.js +41 -0
- package/out/llm/sendRequestToSelfHostLLM.js.map +1 -0
- package/out/metrics/appInsightTelemetry.d.ts +6 -0
- package/out/metrics/appInsightTelemetry.js +77 -0
- package/out/metrics/appInsightTelemetry.js.map +1 -0
- package/out/metrics/machineId.d.ts +11 -0
- package/out/metrics/machineId.js +85 -0
- package/out/metrics/machineId.js.map +1 -0
- package/out/setup/setup.d.ts +1 -0
- package/out/setup/setup.js +10 -0
- package/out/setup/setup.js.map +1 -0
- package/out/setup/setupConsole.d.ts +1 -0
- package/out/setup/setupConsole.js +23 -0
- package/out/setup/setupConsole.js.map +1 -0
- package/out/setup/setupLLMRequest.d.ts +2 -0
- package/out/setup/setupLLMRequest.js +10 -0
- package/out/setup/setupLLMRequest.js.map +1 -0
- package/out/tools/devenvcom.cmd +13 -0
- package/out/tools/devenvexe.cmd +13 -0
- package/out/tools/msbuildexe.cmd +13 -0
- package/out/tools/vstestexe.cmd +13 -0
- package/out/types/benchmark.d.ts +11 -0
- package/out/types/benchmark.js +3 -0
- package/out/types/benchmark.js.map +1 -0
- package/out/types/buildResult.d.ts +8 -0
- package/out/types/buildResult.js +3 -0
- package/out/types/buildResult.js.map +1 -0
- package/out/types/constants.d.ts +3 -0
- package/out/types/constants.js +7 -0
- package/out/types/constants.js.map +1 -0
- package/out/types/genResult.d.ts +10 -0
- package/out/types/genResult.js +3 -0
- package/out/types/genResult.js.map +1 -0
- package/out/types/testResult.d.ts +12 -0
- package/out/types/testResult.js +3 -0
- package/out/types/testResult.js.map +1 -0
- package/out/types/verifyResult.d.ts +8 -0
- package/out/types/verifyResult.js +3 -0
- package/out/types/verifyResult.js.map +1 -0
- package/out/utils/checkTestProject.d.ts +2 -0
- package/out/utils/checkTestProject.js +79 -0
- package/out/utils/checkTestProject.js.map +1 -0
- package/out/utils/checkXapCode.d.ts +2 -0
- package/out/utils/checkXapCode.js +59 -0
- package/out/utils/checkXapCode.js.map +1 -0
- package/out/utils/delay.d.ts +1 -0
- package/out/utils/delay.js +7 -0
- package/out/utils/delay.js.map +1 -0
- package/out/utils/detectTestFramework.d.ts +1 -0
- package/out/utils/detectTestFramework.js +32 -0
- package/out/utils/detectTestFramework.js.map +1 -0
- package/out/utils/fileUtils.d.ts +2 -0
- package/out/utils/fileUtils.js +42 -0
- package/out/utils/fileUtils.js.map +1 -0
- package/out/utils/generateCodeSha256.d.ts +1 -0
- package/out/utils/generateCodeSha256.js +46 -0
- package/out/utils/generateCodeSha256.js.map +1 -0
- package/out/utils/getCodeStructurePath.d.ts +5 -0
- package/out/utils/getCodeStructurePath.js +155 -0
- package/out/utils/getCodeStructurePath.js.map +1 -0
- package/out/utils/getOrCreateDir.d.ts +2 -0
- package/out/utils/getOrCreateDir.js +63 -0
- package/out/utils/getOrCreateDir.js.map +1 -0
- package/out/utils/getTestCodeInfo.d.ts +2 -0
- package/out/utils/getTestCodeInfo.js +121 -0
- package/out/utils/getTestCodeInfo.js.map +1 -0
- package/out/utils/getTestFile.d.ts +13 -0
- package/out/utils/getTestFile.js +295 -0
- package/out/utils/getTestFile.js.map +1 -0
- package/out/utils/parseBuildResult.d.ts +3 -0
- package/out/utils/parseBuildResult.js +44 -0
- package/out/utils/parseBuildResult.js.map +1 -0
- package/out/utils/parseSyntaxCheckResult.d.ts +2 -0
- package/out/utils/parseSyntaxCheckResult.js +38 -0
- package/out/utils/parseSyntaxCheckResult.js.map +1 -0
- package/out/utils/parseVstestResult.d.ts +3 -0
- package/out/utils/parseVstestResult.js +61 -0
- package/out/utils/parseVstestResult.js.map +1 -0
- package/out/utils/removeFailedTestMethods.d.ts +3 -0
- package/out/utils/removeFailedTestMethods.js +207 -0
- package/out/utils/removeFailedTestMethods.js.map +1 -0
- package/out/utils/runCommand.d.ts +1 -0
- package/out/utils/runCommand.js +14 -0
- package/out/utils/runCommand.js.map +1 -0
- package/out/utils/spawnExec.d.ts +1 -0
- package/out/utils/spawnExec.js +80 -0
- package/out/utils/spawnExec.js.map +1 -0
- package/out/utils/verifyBuildErrorCausedFile.d.ts +1 -0
- package/out/utils/verifyBuildErrorCausedFile.js +60 -0
- package/out/utils/verifyBuildErrorCausedFile.js.map +1 -0
- package/out/utils/verifyTestCode.d.ts +2 -0
- package/out/utils/verifyTestCode.js +25 -0
- package/out/utils/verifyTestCode.js.map +1 -0
- package/out/utils/writeGenCode.d.ts +1 -0
- package/out/utils/writeGenCode.js +50 -0
- package/out/utils/writeGenCode.js.map +1 -0
- package/out/vs/msBuild.d.ts +13 -0
- package/out/vs/msBuild.js +81 -0
- package/out/vs/msBuild.js.map +1 -0
- package/out/vs/vsTest.d.ts +15 -0
- package/out/vs/vsTest.js +107 -0
- package/out/vs/vsTest.js.map +1 -0
- package/out/vs/vsTools.d.ts +7 -0
- package/out/vs/vsTools.js +177 -0
- package/out/vs/vsTools.js.map +1 -0
- package/out/vsPlugin/getVsPluginVerifyResult.d.ts +2 -0
- package/out/vsPlugin/getVsPluginVerifyResult.js +41 -0
- package/out/vsPlugin/getVsPluginVerifyResult.js.map +1 -0
- package/out/vsPlugin/interactionConstants.d.ts +2 -0
- package/out/vsPlugin/interactionConstants.js +10 -0
- package/out/vsPlugin/interactionConstants.js.map +1 -0
- package/out/vsPlugin/sendStdToVsPlugin.d.ts +1 -0
- package/out/vsPlugin/sendStdToVsPlugin.js +12 -0
- package/out/vsPlugin/sendStdToVsPlugin.js.map +1 -0
- package/out/vsPlugin/stdListener.d.ts +3 -0
- package/out/vsPlugin/stdListener.js +57 -0
- package/out/vsPlugin/stdListener.js.map +1 -0
- package/package.json +33 -0
- package/tools/devenvcom.cmd +13 -0
- package/tools/devenvexe.cmd +13 -0
- package/tools/msbuildexe.cmd +13 -0
- package/tools/vstestexe.cmd +13 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateCsharpUtCode = generateCsharpUtCode;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const constants_1 = require("../types/constants");
|
|
40
|
+
const fileUtils_1 = require("../utils/fileUtils");
|
|
41
|
+
const autoFix_1 = require("./autoFix");
|
|
42
|
+
const checkXapCode_1 = require("../utils/checkXapCode");
|
|
43
|
+
const detectTestFramework_1 = require("../utils/detectTestFramework");
|
|
44
|
+
const ensureValidLLMResponse_1 = require("./ensureValidLLMResponse");
|
|
45
|
+
const generateCodeDependency_1 = require("../analyze/generateCodeDependency");
|
|
46
|
+
const getTestFile_1 = require("../utils/getTestFile");
|
|
47
|
+
const installAnalyzerTool_1 = require("../analyze/installAnalyzerTool");
|
|
48
|
+
const preGenProcess_1 = require("./preGen/preGenProcess");
|
|
49
|
+
const preparePrompt_1 = require("../llm/preparePrompt");
|
|
50
|
+
const removeFailedTestMethods_1 = require("../utils/removeFailedTestMethods");
|
|
51
|
+
const appInsightTelemetry_1 = require("../metrics/appInsightTelemetry");
|
|
52
|
+
const RETRYTIMES = 3;
|
|
53
|
+
async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix, keepFailedTests, source = constants_1.CSHARPUTGEN, isBenchmark = false) {
|
|
54
|
+
const startTime = Date.now();
|
|
55
|
+
console.log(`*****************Generating C# unit test code for: ${sourceCodePath}*****************`);
|
|
56
|
+
console.log(`Current work dir: ${process.cwd()}`);
|
|
57
|
+
// send usage metrics
|
|
58
|
+
(0, appInsightTelemetry_1.sendUserUsageEvent)(source);
|
|
59
|
+
sourceCodePath = path.normalize(sourceCodePath);
|
|
60
|
+
if (!fs.existsSync(sourceCodePath)) {
|
|
61
|
+
console.error(`Source code file not found: ${sourceCodePath}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// install nuget cli tool to analyze code
|
|
65
|
+
(0, installAnalyzerTool_1.installOrUpdateAnalyzerTool)();
|
|
66
|
+
let sourceCode = fs.readFileSync(sourceCodePath, 'utf-8');
|
|
67
|
+
// check if source code is xap code, if so, use xap code generation prompt
|
|
68
|
+
const isXapCode = (0, checkXapCode_1.checkXapCode)(sourceCode);
|
|
69
|
+
sourceCode = await (0, preGenProcess_1.preGenProcess)(sourceCode, sourceCodePath, isXapCode);
|
|
70
|
+
if (!sourceCode) {
|
|
71
|
+
console.error(`Skip generate test for source code: ${sourceCodePath}`);
|
|
72
|
+
return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
|
|
73
|
+
}
|
|
74
|
+
// get code dependencies
|
|
75
|
+
let codeDependency = await (0, generateCodeDependency_1.generateCodeDependency)(sourceCodePath);
|
|
76
|
+
// detect existing test file or create a new one by source code path
|
|
77
|
+
const { testFilePath, testProjectPath, testFileExist } = (0, getTestFile_1.getOrCreatTestFile)(sourceCodePath, testCodePath, isXapCode);
|
|
78
|
+
if (!testFilePath || !testProjectPath) {
|
|
79
|
+
console.error(`Failed to get or create test file for source code: ${sourceCodePath}`);
|
|
80
|
+
return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
|
|
81
|
+
}
|
|
82
|
+
// get test framework
|
|
83
|
+
const testFramework = (0, detectTestFramework_1.detectTestFramework)(testProjectPath);
|
|
84
|
+
// prepare prompt
|
|
85
|
+
let prompt = (0, preparePrompt_1.prepareUtGenPrompt)(sourceCodePath, sourceCode, codeDependency, isXapCode, testFramework);
|
|
86
|
+
// let prompt = getPrompts(sourceCodePath, testFramework, codeDependency);
|
|
87
|
+
// call LLM service to gen code with retry
|
|
88
|
+
const testCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompt, isXapCode);
|
|
89
|
+
// write test code to test project
|
|
90
|
+
// To run vstest, need to write the test code to test project first, then build the test project and run the tests
|
|
91
|
+
(0, fileUtils_1.writeTestCode)(testCode, testFilePath);
|
|
92
|
+
// autofix
|
|
93
|
+
let autoFixResult = { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
|
|
94
|
+
if (enableAutoFix) {
|
|
95
|
+
const isVsPlugin = source === constants_1.CSVSPLUGIN;
|
|
96
|
+
autoFixResult = await (0, autoFix_1.autoFixTestCode)(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);
|
|
97
|
+
// autoFixResult = await autoRetryTestCode(prompt, sourceCode, testCode, testProjectPath, testFilePath, isXapTest);
|
|
98
|
+
}
|
|
99
|
+
if (autoFixResult.success) {
|
|
100
|
+
console.log(`Gerate UT success time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
101
|
+
return autoFixResult;
|
|
102
|
+
}
|
|
103
|
+
// if retry max times or test generation failed, and keepFailedTests is false, delete failed test file or remove failed test methods
|
|
104
|
+
if (!keepFailedTests) {
|
|
105
|
+
// keep succeed test code, or delete test file
|
|
106
|
+
if (!autoFixResult.testResult || autoFixResult.testResult.passed === 0) {
|
|
107
|
+
!testFileExist && (0, fileUtils_1.deleteTestFileIfExists)(testFilePath);
|
|
108
|
+
console.log(`Failed to generate csharp test code, deleted test file: ${testFilePath}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
(0, removeFailedTestMethods_1.removeFailedTestCasesInTestFile)(autoFixResult.testResult, testFilePath);
|
|
112
|
+
console.log(`write succeed test code to file: ${testFilePath}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.log(`keep failed test file: ${testFilePath}`);
|
|
117
|
+
}
|
|
118
|
+
console.log(`Gerate UT failed time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
119
|
+
return autoFixResult;
|
|
120
|
+
}
|
|
121
|
+
// generateCsharpUtCode("D:\\code\\IndexServe\\private\\indexserve\\RecommendationEngine\\RecoPS\\PSTableClient\\PSTableClient.cs", undefined, false, true, false);
|
|
122
|
+
// generateCsharpUtCode("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelper.cs", undefined, true, true, false);
|
|
123
|
+
// generateCsharpUtCode("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Eplant\\ResponseBuilders\\EplantMigrateResponseBuilder.cs", undefined, true, true, true);
|
|
124
|
+
// generateCsharpUtCode("D:\\code\\UCMDynamics\\private\\DynamicCode\\Plugin\\UCMDynamics.AppointmentPlugin\\AppointmentOperation.cs", undefined, false, true, false);
|
|
125
|
+
// generateCsharpUtCode("D:\\code\\AIUnitTestExample\\src\\ToListinator.Analyzers\\ToListCountAnalyzer.cs", undefined, true, true, false);
|
|
126
|
+
// function getPrompts(sourceCodePath, testFramework, codeDependency) {
|
|
127
|
+
// const code = fs.readFileSync(sourceCodePath, 'utf8');
|
|
128
|
+
// let guidancePromt = fs.readFileSync("D:\\atmp\\promptiteration.md", 'utf8');
|
|
129
|
+
// guidancePromt = guidancePromt.replace("xUnit", testFramework);
|
|
130
|
+
// const prompts = [
|
|
131
|
+
// // {
|
|
132
|
+
// // "role": "system",
|
|
133
|
+
// // "content": "Keep your answers short and impersonal.\nUse Markdown formatting in your answers.\nMake sure to include the programming language name at the start of the Markdown code blocks.\nAvoid wrapping the whole response in triple backticks.\nYou can only give one reply for each conversation turn."
|
|
134
|
+
// // },
|
|
135
|
+
// {
|
|
136
|
+
// "role": "user",
|
|
137
|
+
// // "content": "You are Roo, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.\n\n====\n\nRULES\n\n- MUST use xUnit test framework to generate test code.\n- **MUST NOT** contain any comments or explanations in test code.\n- Ensure the test code MUST has no syntax errors.\n- Test public methods of class in source code only.\n- **MUST NOT** access private members (fields or methods) of the source class in test code.\n- Test method names must follow the pattern: [MethodName]_[Scenario]_[ExpectedResult].\n- Return the test code in the format: ```C#\n{Test code}\n```.\n- Mock all dependent methods, classes, and values not included in the user input using the Moq library.\n- MUST include Test code in a namespace declaration and place all `using` statements above the namespace declaration.\n- MUST import source code in the test code.\n- MUST import all required .Net namespaces if any .Net class or interface are used in the test code. Like:\n - .NET built-in types (e.g., `List<T>`, `IEnumerable<T>`, `Task`, `Assert`, `Moq.Mock`, etc.).\n - Any attribute classes (e.g., `[TestMethod]`, `[TestClass]`, etc.).\n - Any LINQ or threading related classes (e.g., `System.Linq`, `System.Threading.Tasks`).\n- All assignments and method arguments in test code MUST strictly match the declared types.\n- When generating code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.\n- Do not ask for more information than necessary. Use your knowledge to accomplish the user's request efficiently and effectively.\n- The user will provide the source code directly in their message.\n- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.\n\n====\n\nOBJECTIVE\n\nYou accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.\n\n- **MUST** analyze the provided code and verify its logic by following these steps:\n 1. Describe the functionality of each public method, including its inputs, outputs, and key logic.\n 2. Identify all possible execution paths for public methods, including normal cases, edge cases, and error conditions.\n 3. Explain any conditional branches, loops, or exception handling for public methods in the code.\n 4. Based on this analysis, generate unit test cases that cover all identified execution paths, ensuring that mock data and assertions align with the code's logic.\n- **MUST** remove all code analysis information in responsed test code.\n- Absolutely forbidden to contains any other information in response except the test code.\n- **MUST NOT** generate tests for the methods that are attributed with **[ExcludeFromCodeCoverage]**.\n- **MUST NOT** generate tests for **private** methods.\n- Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.\n- Work through these goals sequentially, each goal should correspond to a distinct step in your problem-solving process.\n\n====\n\nUSER'S CUSTOM INSTRUCTIONS\n\nThe following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.\n\nLanguage Preference:\nYou should always speak and think in the English language."
|
|
138
|
+
// "content": guidancePromt
|
|
139
|
+
// },
|
|
140
|
+
// {
|
|
141
|
+
// "role": "user",
|
|
142
|
+
// "content": `generate unit test for the following csharp code:\n\`\`\`${code}\`\`\``
|
|
143
|
+
// },
|
|
144
|
+
// // {
|
|
145
|
+
// // "role": "user",
|
|
146
|
+
// // "content": `following are the code dependencies of the source code:\n${codeDependency}`
|
|
147
|
+
// // }
|
|
148
|
+
// ];
|
|
149
|
+
// return prompts;
|
|
150
|
+
// }
|
|
151
|
+
//# sourceMappingURL=csharpUtGen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csharpUtGen.js","sourceRoot":"","sources":["../../src/gen/csharpUtGen.ts"],"names":[],"mappings":"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","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nimport { CSHARPUTGEN, CSVSPLUGIN } from '../types/constants';\r\nimport { deleteTestFileIfExists, writeTestCode } from \"../utils/fileUtils\";\r\n\r\nimport { GenResult } from '../types/genResult';\r\nimport { autoFixTestCode } from './autoFix';\r\nimport { checkXapCode } from '../utils/checkXapCode';\r\nimport { detectTestFramework } from '../utils/detectTestFramework';\r\nimport { ensureValidLLMResponse } from './ensureValidLLMResponse';\r\nimport { generateCodeDependency } from '../analyze/generateCodeDependency';\r\nimport { getOrCreatTestFile } from '../utils/getTestFile';\r\nimport { installOrUpdateAnalyzerTool } from '../analyze/installAnalyzerTool';\r\nimport { preGenProcess } from './preGen/preGenProcess';\r\nimport { prepareUtGenPrompt } from '../llm/preparePrompt';\r\nimport { removeFailedTestCasesInTestFile } from '../utils/removeFailedTestMethods';\r\nimport { sendUserUsageEvent } from '../metrics/appInsightTelemetry';\r\n\r\nconst RETRYTIMES = 3;\r\n\r\nexport async function generateCsharpUtCode(\r\n sourceCodePath: string,\r\n testCodePath: string,\r\n enableAutoFix: boolean,\r\n keepFailedTests: boolean,\r\n source: string = CSHARPUTGEN,\r\n isBenchmark: boolean = false\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n console.log(`*****************Generating C# unit test code for: ${sourceCodePath}*****************`);\r\n console.log(`Current work dir: ${process.cwd()}`);\r\n\r\n // send usage metrics\r\n sendUserUsageEvent(source);\r\n\r\n sourceCodePath = path.normalize(sourceCodePath);\r\n if (!fs.existsSync(sourceCodePath)) {\r\n console.error(`Source code file not found: ${sourceCodePath}`);\r\n return;\r\n }\r\n\r\n // install nuget cli tool to analyze code\r\n installOrUpdateAnalyzerTool();\r\n\r\n let sourceCode = fs.readFileSync(sourceCodePath, 'utf-8');\r\n\r\n // check if source code is xap code, if so, use xap code generation prompt\r\n const isXapCode = checkXapCode(sourceCode);\r\n\r\n sourceCode = await preGenProcess(sourceCode, sourceCodePath, isXapCode);\r\n if (!sourceCode) {\r\n console.error(`Skip generate test for source code: ${sourceCodePath}`);\r\n return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n }\r\n\r\n // get code dependencies\r\n let codeDependency = await generateCodeDependency(sourceCodePath);\r\n\r\n // detect existing test file or create a new one by source code path\r\n const { testFilePath, testProjectPath, testFileExist } = getOrCreatTestFile(sourceCodePath, testCodePath, isXapCode);\r\n if (!testFilePath || !testProjectPath) {\r\n console.error(`Failed to get or create test file for source code: ${sourceCodePath}`);\r\n return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n }\r\n\r\n // get test framework\r\n const testFramework = detectTestFramework(testProjectPath);\r\n\r\n // prepare prompt\r\n let prompt = prepareUtGenPrompt(sourceCodePath, sourceCode, codeDependency, isXapCode, testFramework);\r\n // let prompt = getPrompts(sourceCodePath, testFramework, codeDependency);\r\n\r\n // call LLM service to gen code with retry\r\n const testCode = await ensureValidLLMResponse(prompt, isXapCode);\r\n\r\n // write test code to test project\r\n // To run vstest, need to write the test code to test project first, then build the test project and run the tests\r\n writeTestCode(testCode, testFilePath);\r\n\r\n // autofix\r\n let autoFixResult: GenResult = { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n if (enableAutoFix) {\r\n const isVsPlugin = source === CSVSPLUGIN;\r\n autoFixResult = await autoFixTestCode(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);\r\n // autoFixResult = await autoRetryTestCode(prompt, sourceCode, testCode, testProjectPath, testFilePath, isXapTest);\r\n }\r\n\r\n if (autoFixResult.success) {\r\n console.log(`Gerate UT success time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return autoFixResult;\r\n }\r\n\r\n // if retry max times or test generation failed, and keepFailedTests is false, delete failed test file or remove failed test methods\r\n if (!keepFailedTests) {\r\n // keep succeed test code, or delete test file\r\n if (!autoFixResult.testResult || autoFixResult.testResult.passed === 0) {\r\n !testFileExist && deleteTestFileIfExists(testFilePath);\r\n console.log(`Failed to generate csharp test code, deleted test file: ${testFilePath}`);\r\n } else {\r\n removeFailedTestCasesInTestFile(autoFixResult.testResult, testFilePath);\r\n console.log(`write succeed test code to file: ${testFilePath}`);\r\n }\r\n } else {\r\n console.log(`keep failed test file: ${testFilePath}`);\r\n }\r\n console.log(`Gerate UT failed time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return autoFixResult;\r\n}\r\n\r\n// generateCsharpUtCode(\"D:\\\\code\\\\IndexServe\\\\private\\\\indexserve\\\\RecommendationEngine\\\\RecoPS\\\\PSTableClient\\\\PSTableClient.cs\", undefined, false, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelper.cs\", undefined, true, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Eplant\\\\ResponseBuilders\\\\EplantMigrateResponseBuilder.cs\", undefined, true, true, true);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UCMDynamics.AppointmentPlugin\\\\AppointmentOperation.cs\", undefined, false, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\AIUnitTestExample\\\\src\\\\ToListinator.Analyzers\\\\ToListCountAnalyzer.cs\", undefined, true, true, false);\r\n\r\n// function getPrompts(sourceCodePath, testFramework, codeDependency) {\r\n// const code = fs.readFileSync(sourceCodePath, 'utf8');\r\n// let guidancePromt = fs.readFileSync(\"D:\\\\atmp\\\\promptiteration.md\", 'utf8');\r\n// guidancePromt = guidancePromt.replace(\"xUnit\", testFramework);\r\n// const prompts = [\r\n\r\n// // {\r\n// // \"role\": \"system\",\r\n// // \"content\": \"Keep your answers short and impersonal.\\nUse Markdown formatting in your answers.\\nMake sure to include the programming language name at the start of the Markdown code blocks.\\nAvoid wrapping the whole response in triple backticks.\\nYou can only give one reply for each conversation turn.\"\r\n// // },\r\n// {\r\n// \"role\": \"user\",\r\n// // \"content\": \"You are Roo, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.\\n\\n====\\n\\nRULES\\n\\n- MUST use xUnit test framework to generate test code.\\n- **MUST NOT** contain any comments or explanations in test code.\\n- Ensure the test code MUST has no syntax errors.\\n- Test public methods of class in source code only.\\n- **MUST NOT** access private members (fields or methods) of the source class in test code.\\n- Test method names must follow the pattern: [MethodName]_[Scenario]_[ExpectedResult].\\n- Return the test code in the format: ```C#\\n{Test code}\\n```.\\n- Mock all dependent methods, classes, and values not included in the user input using the Moq library.\\n- MUST include Test code in a namespace declaration and place all `using` statements above the namespace declaration.\\n- MUST import source code in the test code.\\n- MUST import all required .Net namespaces if any .Net class or interface are used in the test code. Like:\\n - .NET built-in types (e.g., `List<T>`, `IEnumerable<T>`, `Task`, `Assert`, `Moq.Mock`, etc.).\\n - Any attribute classes (e.g., `[TestMethod]`, `[TestClass]`, etc.).\\n - Any LINQ or threading related classes (e.g., `System.Linq`, `System.Threading.Tasks`).\\n- All assignments and method arguments in test code MUST strictly match the declared types.\\n- When generating code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.\\n- Do not ask for more information than necessary. Use your knowledge to accomplish the user's request efficiently and effectively.\\n- The user will provide the source code directly in their message.\\n- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.\\n\\n====\\n\\nOBJECTIVE\\n\\nYou accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.\\n\\n- **MUST** analyze the provided code and verify its logic by following these steps:\\n 1. Describe the functionality of each public method, including its inputs, outputs, and key logic.\\n 2. Identify all possible execution paths for public methods, including normal cases, edge cases, and error conditions.\\n 3. Explain any conditional branches, loops, or exception handling for public methods in the code.\\n 4. Based on this analysis, generate unit test cases that cover all identified execution paths, ensuring that mock data and assertions align with the code's logic.\\n- **MUST** remove all code analysis information in responsed test code.\\n- Absolutely forbidden to contains any other information in response except the test code.\\n- **MUST NOT** generate tests for the methods that are attributed with **[ExcludeFromCodeCoverage]**.\\n- **MUST NOT** generate tests for **private** methods.\\n- Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.\\n- Work through these goals sequentially, each goal should correspond to a distinct step in your problem-solving process.\\n\\n====\\n\\nUSER'S CUSTOM INSTRUCTIONS\\n\\nThe following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.\\n\\nLanguage Preference:\\nYou should always speak and think in the English language.\"\r\n// \"content\": guidancePromt\r\n// },\r\n// {\r\n// \"role\": \"user\",\r\n// \"content\": `generate unit test for the following csharp code:\\n\\`\\`\\`${code}\\`\\`\\``\r\n// },\r\n// // {\r\n// // \"role\": \"user\",\r\n// // \"content\": `following are the code dependencies of the source code:\\n${codeDependency}`\r\n// // }\r\n// ];\r\n// return prompts;\r\n// }\r\n\r\n\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ensureValidLLMResponse(prompt: any[], isXapCode: boolean, retryTimes?: number): Promise<string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureValidLLMResponse = ensureValidLLMResponse;
|
|
4
|
+
const postGenProcess_1 = require("./postGen/postGenProcess");
|
|
5
|
+
const sendRequestToLLM_1 = require("../llm/sendRequestToLLM");
|
|
6
|
+
async function ensureValidLLMResponse(prompt, isXapCode, retryTimes = 3) {
|
|
7
|
+
for (let i = 0; i < retryTimes; i++) {
|
|
8
|
+
// call LLM service to gen code
|
|
9
|
+
const { content: generatedCode } = await (0, sendRequestToLLM_1.sendRequestToLLM)(prompt);
|
|
10
|
+
// extract valid code from LLM response
|
|
11
|
+
const testCode = (0, postGenProcess_1.postGenProcess)(generatedCode, isXapCode);
|
|
12
|
+
if (!!testCode) {
|
|
13
|
+
return testCode;
|
|
14
|
+
}
|
|
15
|
+
console.log(`Failed to generate valid test code, retrying... (${i + 1}/${retryTimes})`);
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ensureValidLLMResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ensureValidLLMResponse.js","sourceRoot":"","sources":["../../src/gen/ensureValidLLMResponse.ts"],"names":[],"mappings":";;AAGA,wDAcC;AAjBD,6DAA0D;AAC1D,8DAA2D;AAEpD,KAAK,UAAU,sBAAsB,CAAC,MAAa,EAAE,SAAkB,EAAE,aAAqB,CAAC;IAClG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,+BAA+B;QAC/B,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,mCAAgB,EAAC,MAAM,CAAC,CAAC;QAElE,uCAAuC;QACvC,MAAM,QAAQ,GAAG,IAAA,+BAAc,EAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QAC1D,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import { postGenProcess } from \"./postGen/postGenProcess\";\r\nimport { sendRequestToLLM } from \"../llm/sendRequestToLLM\";\r\n\r\nexport async function ensureValidLLMResponse(prompt: any[], isXapCode: boolean, retryTimes: number = 3): Promise<string> {\r\n for (let i = 0; i < retryTimes; i++) {\r\n // call LLM service to gen code\r\n const { content: generatedCode } = await sendRequestToLLM(prompt);\r\n \r\n // extract valid code from LLM response\r\n const testCode = postGenProcess(generatedCode, isXapCode);\r\n if (!!testCode) {\r\n return testCode;\r\n }\r\n console.log(`Failed to generate valid test code, retrying... (${i + 1}/${retryTimes})`);\r\n }\r\n\r\n return undefined;\r\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extractCodeFromResponse(response: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractCodeFromResponse = extractCodeFromResponse;
|
|
4
|
+
const regexList = [
|
|
5
|
+
/```(?:C#|csharp|CSharp|json|mermaid)?([\s\S]*?)(\n?```\n*|$)/g,
|
|
6
|
+
/```([\s\S]*?)(\n?```\n*|$)/g,
|
|
7
|
+
/```C#\s*([\s\S]*?)```/gi
|
|
8
|
+
];
|
|
9
|
+
function extractCodeFromResponse(response) {
|
|
10
|
+
if (!response) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
const text = response.trim();
|
|
14
|
+
for (const regex of regexList) {
|
|
15
|
+
let testCode = getRegexResult(text, regex);
|
|
16
|
+
if (!!testCode) {
|
|
17
|
+
return testCode;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const lines = text.split(/\r?\n/);
|
|
21
|
+
const hasMarkdown = lines.some(line => line.startsWith('#'));
|
|
22
|
+
if (hasMarkdown) {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
function getRegexResult(response, regex) {
|
|
28
|
+
const match = regex.exec(response);
|
|
29
|
+
if (!match || match.length < 2) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return match[1].trim();
|
|
33
|
+
}
|
|
34
|
+
// const input = '```C#\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\nusing Moq;\nusing System;\nusing System.Collections.Generic;\nusing SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\n\nnamespace SharedSegments.Tests\n{\n [TestClass]\n public class SqmidHelperTests\n {\n [TestMethod]\n public void GetSqmidFromCookie_CookieWithValidBlisId_ReturnsDecodedSqmid()\n {\n var cookies = new Dictionary<string, string>\n {\n { \"USRLOC\", \"BID=QlJfU01JRA==\" }\n };\n\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\n\n Assert.AreEqual(\"SMID\", result);\n }\n\n [TestMethod]\n public void GetSqmidFromCookie_CookieWithoutBlisId_ReturnsNull()\n {\n var cookies = new Dictionary<string, string>\n {\n { \"USRLOC\", \"ANOTHERDATA=123\" }\n };\n\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\n\n Assert.IsNull(result);\n }\n\n [TestMethod]\n public void GetSqmidFromCookie_CookieWithEmptyValues_ReturnsEmptyString()\n {\n var cookies = new Dictionary<string, string>\n {\n { \"USRLOC\", \"BID=\" }\n };\n\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n [TestMethod]\n public void GetSqmidFromCookie_InvalidBase64BlisId_ThrowsArgumentException_ReturnsEmptyString()\n {\n var cookies = new Dictionary<string, string>\n {\n { \"USRLOC\", \"BID=InvalidBase64\" }\n };\n\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n [TestMethod]\n public void GetSqmidFromCookie_NoLocationCookie_ReturnsEmptyString()\n {\n var cookies = new Dictionary<string, string>();\n\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n [TestMethod]\n public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\n {\n var result = SqmidHelper.GetSqmidFromCookie(null);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n [TestMethod]\n public void DecodeBlisId_ValidBase64_ReturnsExpectedValue()\n {\n var blisId = \"QlJfU01JRA==\";\n\n var result = InvokeDecodeBlisId(blisId);\n\n Assert.AreEqual(\"SMID\", result);\n }\n\n [TestMethod]\n public void DecodeBlisId_InvalidBase64_ReturnsEmptyString()\n {\n var blisId = \"InvalidBase64\";\n\n var result = InvokeDecodeBlisId(blisId);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n [TestMethod]\n public void DecodeBlisId_EmptyBlisId_ReturnsEmptyString()\n {\n var blisId = string.Empty;\n\n var result = InvokeDecodeBlisId(blisId);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n [TestMethod]\n public void DecodeBlisId_NullBlisId_ReturnsEmptyString()\n {\n var result = InvokeDecodeBlisId(null);\n\n Assert.AreEqual(string.Empty, result);\n }\n\n private string InvokeDecodeBlisId(string blisId)\n {\n var method = typeof(SqmidHelper).GetMethod(\"DecodeBlisId\", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);\n return (string)method.Invoke(null, new object[] { blisId });\n }\n }\n}\n```';
|
|
35
|
+
// const code = extractCode(input);
|
|
36
|
+
// console.log(code);
|
|
37
|
+
//# sourceMappingURL=extractCodeFromResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractCodeFromResponse.js","sourceRoot":"","sources":["../../../src/gen/postGen/extractCodeFromResponse.ts"],"names":[],"mappings":";;AAOA,0DAkBC;AAxBD,MAAM,SAAS,GAAG;IACd,+DAA+D;IAC/D,6BAA6B;IAC7B,yBAAyB;CAC5B,CAAC;AAEF,SAAgB,uBAAuB,CAAC,QAAgB;IACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACd,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7B,KAAK,MAAM,KAAK,IAAI,SAAS,EAAE,CAAC;QAC5B,IAAI,QAAQ,GAAG,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QACpB,CAAC;IACL,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7D,IAAI,WAAW,EAAE,CAAC;QACd,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB,EAAE,KAAa;IACnD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3B,CAAC;AAED,+qHAA+qH;AAC/qH,mCAAmC;AACnC,qBAAqB","sourcesContent":["\r\nconst regexList = [\r\n /```(?:C#|csharp|CSharp|json|mermaid)?([\\s\\S]*?)(\\n?```\\n*|$)/g,\r\n /```([\\s\\S]*?)(\\n?```\\n*|$)/g,\r\n /```C#\\s*([\\s\\S]*?)```/gi\r\n];\r\n\r\nexport function extractCodeFromResponse(response: string): string {\r\n if (!response) {\r\n return '';\r\n }\r\n const text = response.trim();\r\n for (const regex of regexList) {\r\n let testCode = getRegexResult(text, regex);\r\n if (!!testCode) {\r\n return testCode;\r\n }\r\n }\r\n\r\n const lines = text.split(/\\r?\\n/);\r\n const hasMarkdown = lines.some(line => line.startsWith('#'));\r\n if (hasMarkdown) {\r\n return '';\r\n }\r\n return text;\r\n}\r\n\r\nfunction getRegexResult(response: string, regex: RegExp): string | null {\r\n const match = regex.exec(response);\r\n if (!match || match.length < 2) {\r\n return null;\r\n }\r\n return match[1].trim();\r\n}\r\n\r\n// const input = '```C#\\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\\nusing Moq;\\nusing System;\\nusing System.Collections.Generic;\\nusing SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\\n\\nnamespace SharedSegments.Tests\\n{\\n [TestClass]\\n public class SqmidHelperTests\\n {\\n [TestMethod]\\n public void GetSqmidFromCookie_CookieWithValidBlisId_ReturnsDecodedSqmid()\\n {\\n var cookies = new Dictionary<string, string>\\n {\\n { \\\"USRLOC\\\", \\\"BID=QlJfU01JRA==\\\" }\\n };\\n\\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\\n\\n Assert.AreEqual(\\\"SMID\\\", result);\\n }\\n\\n [TestMethod]\\n public void GetSqmidFromCookie_CookieWithoutBlisId_ReturnsNull()\\n {\\n var cookies = new Dictionary<string, string>\\n {\\n { \\\"USRLOC\\\", \\\"ANOTHERDATA=123\\\" }\\n };\\n\\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\\n\\n Assert.IsNull(result);\\n }\\n\\n [TestMethod]\\n public void GetSqmidFromCookie_CookieWithEmptyValues_ReturnsEmptyString()\\n {\\n var cookies = new Dictionary<string, string>\\n {\\n { \\\"USRLOC\\\", \\\"BID=\\\" }\\n };\\n\\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n [TestMethod]\\n public void GetSqmidFromCookie_InvalidBase64BlisId_ThrowsArgumentException_ReturnsEmptyString()\\n {\\n var cookies = new Dictionary<string, string>\\n {\\n { \\\"USRLOC\\\", \\\"BID=InvalidBase64\\\" }\\n };\\n\\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n [TestMethod]\\n public void GetSqmidFromCookie_NoLocationCookie_ReturnsEmptyString()\\n {\\n var cookies = new Dictionary<string, string>();\\n\\n var result = SqmidHelper.GetSqmidFromCookie(cookies);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n [TestMethod]\\n public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\\n {\\n var result = SqmidHelper.GetSqmidFromCookie(null);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n [TestMethod]\\n public void DecodeBlisId_ValidBase64_ReturnsExpectedValue()\\n {\\n var blisId = \\\"QlJfU01JRA==\\\";\\n\\n var result = InvokeDecodeBlisId(blisId);\\n\\n Assert.AreEqual(\\\"SMID\\\", result);\\n }\\n\\n [TestMethod]\\n public void DecodeBlisId_InvalidBase64_ReturnsEmptyString()\\n {\\n var blisId = \\\"InvalidBase64\\\";\\n\\n var result = InvokeDecodeBlisId(blisId);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n [TestMethod]\\n public void DecodeBlisId_EmptyBlisId_ReturnsEmptyString()\\n {\\n var blisId = string.Empty;\\n\\n var result = InvokeDecodeBlisId(blisId);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n [TestMethod]\\n public void DecodeBlisId_NullBlisId_ReturnsEmptyString()\\n {\\n var result = InvokeDecodeBlisId(null);\\n\\n Assert.AreEqual(string.Empty, result);\\n }\\n\\n private string InvokeDecodeBlisId(string blisId)\\n {\\n var method = typeof(SqmidHelper).GetMethod(\\\"DecodeBlisId\\\", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);\\n return (string)method.Invoke(null, new object[] { blisId });\\n }\\n }\\n}\\n```';\r\n// const code = extractCode(input);\r\n// console.log(code);\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function postGenProcess(generatedCode: string, isXapCode: boolean): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postGenProcess = postGenProcess;
|
|
4
|
+
const extractCodeFromResponse_1 = require("./extractCodeFromResponse");
|
|
5
|
+
const removeSingleLines_1 = require("./removeSingleLines");
|
|
6
|
+
const removeComments_1 = require("./removeComments");
|
|
7
|
+
const repairRequiredNameSpaces_1 = require("./repairRequiredNameSpaces");
|
|
8
|
+
const validateTestCode_1 = require("./validateTestCode");
|
|
9
|
+
function postGenProcess(generatedCode, isXapCode) {
|
|
10
|
+
if (!isValidTestCode(generatedCode)) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
let testCode = (0, extractCodeFromResponse_1.extractCodeFromResponse)(generatedCode);
|
|
14
|
+
testCode = (0, removeComments_1.removeTestCodeComments)(testCode);
|
|
15
|
+
testCode = (0, removeSingleLines_1.removeCSharpOnlyLines)(testCode);
|
|
16
|
+
if (isXapCode) {
|
|
17
|
+
testCode = xapCodePostGenProcess(testCode);
|
|
18
|
+
}
|
|
19
|
+
console.log(`Post generation process completed, code length: ${testCode.length}`);
|
|
20
|
+
return testCode;
|
|
21
|
+
}
|
|
22
|
+
function xapCodePostGenProcess(testCode) {
|
|
23
|
+
const processedCode = (0, repairRequiredNameSpaces_1.repairRequiredNameSpaces)(testCode);
|
|
24
|
+
return processedCode;
|
|
25
|
+
}
|
|
26
|
+
function isValidTestCode(testCode) {
|
|
27
|
+
if (!testCode || testCode.trim() === '') {
|
|
28
|
+
return false; // Empty code is not valid
|
|
29
|
+
}
|
|
30
|
+
// Check if the test code contains any test attributes or using statements
|
|
31
|
+
const isValid = (0, validateTestCode_1.validateTestCode)(testCode);
|
|
32
|
+
return isValid;
|
|
33
|
+
}
|
|
34
|
+
// const code = fs.readFileSync("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelperTests.cs", 'utf-8');
|
|
35
|
+
// postGenProcess(code, false);
|
|
36
|
+
//# sourceMappingURL=postGenProcess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postGenProcess.js","sourceRoot":"","sources":["../../../src/gen/postGen/postGenProcess.ts"],"names":[],"mappings":";;AAQA,wCAaC;AAnBD,uEAAoE;AACpE,2DAA4D;AAC5D,qDAA0D;AAC1D,yEAAsE;AACtE,yDAAsD;AAEtD,SAAgB,cAAc,CAAC,aAAqB,EAAE,SAAkB;IACpE,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;QAClC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,QAAQ,GAAG,IAAA,iDAAuB,EAAC,aAAa,CAAC,CAAC;IACtD,QAAQ,GAAG,IAAA,uCAAsB,EAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAA,yCAAqB,EAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,SAAS,EAAE,CAAC;QACZ,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,mDAAmD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAClF,OAAO,QAAQ,CAAC;AACpB,CAAC;AAGD,SAAS,qBAAqB,CAAC,QAAgB;IAC3C,MAAM,aAAa,GAAG,IAAA,mDAAwB,EAAC,QAAQ,CAAC,CAAC;IACzD,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACrC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC,CAAC,0BAA0B;IAC5C,CAAC;IACD,0EAA0E;IAC1E,MAAM,OAAO,GAAG,IAAA,mCAAgB,EAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,uMAAuM;AACvM,+BAA+B","sourcesContent":["import * as fs from 'fs';\r\n\r\nimport { extractCodeFromResponse } from \"./extractCodeFromResponse\";\r\nimport { removeCSharpOnlyLines } from \"./removeSingleLines\";\r\nimport { removeTestCodeComments } from \"./removeComments\";\r\nimport { repairRequiredNameSpaces } from \"./repairRequiredNameSpaces\";\r\nimport { validateTestCode } from \"./validateTestCode\";\r\n\r\nexport function postGenProcess(generatedCode: string, isXapCode: boolean): string {\r\n if (!isValidTestCode(generatedCode)) {\r\n return undefined;\r\n }\r\n \r\n let testCode = extractCodeFromResponse(generatedCode);\r\n testCode = removeTestCodeComments(testCode);\r\n testCode = removeCSharpOnlyLines(testCode);\r\n if (isXapCode) {\r\n testCode = xapCodePostGenProcess(testCode);\r\n }\r\n console.log(`Post generation process completed, code length: ${testCode.length}`);\r\n return testCode;\r\n}\r\n\r\n\r\nfunction xapCodePostGenProcess(testCode: string): string {\r\n const processedCode = repairRequiredNameSpaces(testCode);\r\n return processedCode;\r\n}\r\n\r\nfunction isValidTestCode(testCode: string): boolean {\r\n if (!testCode || testCode.trim() === '') {\r\n return false; // Empty code is not valid\r\n }\r\n // Check if the test code contains any test attributes or using statements\r\n const isValid = validateTestCode(testCode);\r\n return isValid;\r\n}\r\n\r\n// const code = fs.readFileSync(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelperTests.cs\", 'utf-8');\r\n// postGenProcess(code, false);\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeTestCodeComments(code: string): string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// todo: remove line:
|
|
3
|
+
// C#(just contains C# in a line)
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.removeTestCodeComments = removeTestCodeComments;
|
|
6
|
+
function removeTestCodeComments(code) {
|
|
7
|
+
// Remove multi-line comments (/* ... */)
|
|
8
|
+
let cleanedCode = code.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
9
|
+
// Remove single-line comments (// ...)
|
|
10
|
+
cleanedCode = cleanedCode.replace(/\/\/.*$/gm, '');
|
|
11
|
+
// Remove extra blank lines that might result from comment removal, only left at most one blank line
|
|
12
|
+
// cleanedCode = cleanedCode.replace(/\n\s*\n/g, '\n');
|
|
13
|
+
cleanedCode = cleanedCode.replace(/(\r?\n){3,}/g, '\n\n');
|
|
14
|
+
return cleanedCode.trim();
|
|
15
|
+
}
|
|
16
|
+
// const code = `
|
|
17
|
+
// using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
18
|
+
// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;
|
|
19
|
+
// using System;
|
|
20
|
+
// using System.Collections.Generic;
|
|
21
|
+
// using System.Text;
|
|
22
|
+
// using Moq;
|
|
23
|
+
// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils
|
|
24
|
+
// {
|
|
25
|
+
// [TestClass]
|
|
26
|
+
// public class SqmidHelperTests
|
|
27
|
+
// {
|
|
28
|
+
// [TestMethod]
|
|
29
|
+
// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()
|
|
30
|
+
// {
|
|
31
|
+
// // Arrange
|
|
32
|
+
// var cookies = new Dictionary<string, string>
|
|
33
|
+
// {
|
|
34
|
+
// { "USRLOC", "BID=" + Convert.ToBase64String(Encoding.UTF8.GetBytes("test_decodedBlisId_test")) }
|
|
35
|
+
// };
|
|
36
|
+
// // Act
|
|
37
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
38
|
+
// // Assert
|
|
39
|
+
// Assert.AreEqual("decodedBlisId", result);
|
|
40
|
+
// }
|
|
41
|
+
// [TestMethod]
|
|
42
|
+
// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()
|
|
43
|
+
// {
|
|
44
|
+
// // Arrange
|
|
45
|
+
// var cookies = new Dictionary<string, string>
|
|
46
|
+
// {
|
|
47
|
+
// { "USRLOC", "SomeOtherValue=123" }
|
|
48
|
+
// };
|
|
49
|
+
// // Act
|
|
50
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
51
|
+
// // Assert
|
|
52
|
+
// Assert.IsNull(result);
|
|
53
|
+
// }
|
|
54
|
+
// [TestMethod]
|
|
55
|
+
// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()
|
|
56
|
+
// {
|
|
57
|
+
// // Arrange
|
|
58
|
+
// var cookies = new Dictionary<string, string>();
|
|
59
|
+
// // Act
|
|
60
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
61
|
+
// // Assert
|
|
62
|
+
// Assert.AreEqual(string.Empty, result);
|
|
63
|
+
// }
|
|
64
|
+
// [TestMethod]
|
|
65
|
+
// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()
|
|
66
|
+
// {
|
|
67
|
+
// // Arrange
|
|
68
|
+
// IDictionary<string, string> cookies = null;
|
|
69
|
+
// // Act
|
|
70
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
71
|
+
// // Assert
|
|
72
|
+
// Assert.AreEqual(string.Empty, result);
|
|
73
|
+
// }
|
|
74
|
+
// [TestMethod]
|
|
75
|
+
// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()
|
|
76
|
+
// {
|
|
77
|
+
// // Arrange
|
|
78
|
+
// var cookies = new Dictionary<string, string>
|
|
79
|
+
// {
|
|
80
|
+
// { "USRLOC", "" }
|
|
81
|
+
// };
|
|
82
|
+
// // Act
|
|
83
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
84
|
+
// // Assert
|
|
85
|
+
// Assert.AreEqual(string.Empty, result);
|
|
86
|
+
// }
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// `;
|
|
90
|
+
// const cleanedCode = removeTestCodeComments(code);
|
|
91
|
+
// console.log(cleanedCode);
|
|
92
|
+
//# sourceMappingURL=removeComments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeComments.js","sourceRoot":"","sources":["../../../src/gen/postGen/removeComments.ts"],"names":[],"mappings":";AAAA,qBAAqB;AACrB,iCAAiC;;AAEjC,wDAYC;AAZD,SAAgB,sBAAsB,CAAC,IAAY;IAC/C,yCAAyC;IACzC,IAAI,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;IAExD,uCAAuC;IACvC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEnD,oGAAoG;IACpG,uDAAuD;IACvD,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAE1D,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED,iBAAiB;AACjB,sDAAsD;AACtD,2EAA2E;AAC3E,gBAAgB;AAChB,oCAAoC;AACpC,qBAAqB;AACrB,aAAa;AAEb,oFAAoF;AACpF,IAAI;AACJ,kBAAkB;AAClB,oCAAoC;AACpC,QAAQ;AACR,uBAAuB;AACvB,uFAAuF;AACvF,YAAY;AACZ,yBAAyB;AACzB,2DAA2D;AAC3D,gBAAgB;AAChB,mHAAmH;AACnH,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,wDAAwD;AACxD,YAAY;AAEZ,uBAAuB;AACvB,iFAAiF;AACjF,YAAY;AACZ,yBAAyB;AACzB,2DAA2D;AAC3D,gBAAgB;AAChB,qDAAqD;AACrD,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qCAAqC;AACrC,YAAY;AAEZ,uBAAuB;AACvB,2EAA2E;AAC3E,YAAY;AACZ,yBAAyB;AACzB,8DAA8D;AAE9D,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AAEZ,uBAAuB;AACvB,0EAA0E;AAC1E,YAAY;AACZ,yBAAyB;AACzB,0DAA0D;AAE1D,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AAEZ,uBAAuB;AACvB,mFAAmF;AACnF,YAAY;AACZ,yBAAyB;AACzB,2DAA2D;AAC3D,gBAAgB;AAChB,mCAAmC;AACnC,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AACZ,QAAQ;AACR,IAAI;AACJ,KAAK;AAEL,oDAAoD;AACpD,4BAA4B","sourcesContent":["// todo: remove line:\r\n// C#(just contains C# in a line)\r\n\r\nexport function removeTestCodeComments(code: string): string {\r\n // Remove multi-line comments (/* ... */)\r\n let cleanedCode = code.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '');\r\n \r\n // Remove single-line comments (// ...)\r\n cleanedCode = cleanedCode.replace(/\\/\\/.*$/gm, '');\r\n \r\n // Remove extra blank lines that might result from comment removal, only left at most one blank line\r\n // cleanedCode = cleanedCode.replace(/\\n\\s*\\n/g, '\\n');\r\n cleanedCode = cleanedCode.replace(/(\\r?\\n){3,}/g, '\\n\\n');\r\n\r\n return cleanedCode.trim();\r\n}\r\n\r\n// const code = `\r\n// using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\r\n// using System;\r\n// using System.Collections.Generic;\r\n// using System.Text;\r\n// using Moq;\r\n\r\n// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils\r\n// {\r\n// [TestClass]\r\n// public class SqmidHelperTests\r\n// {\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"BID=\" + Convert.ToBase64String(Encoding.UTF8.GetBytes(\"test_decodedBlisId_test\")) }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(\"decodedBlisId\", result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"SomeOtherValue=123\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.IsNull(result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>();\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// IDictionary<string, string> cookies = null;\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n// }\r\n// }\r\n// `;\r\n\r\n// const cleanedCode = removeTestCodeComments(code);\r\n// console.log(cleanedCode);"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeCSharpOnlyLines(generatedCode: string): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeCSharpOnlyLines = removeCSharpOnlyLines;
|
|
4
|
+
const illegalSingleLines = [
|
|
5
|
+
'c#',
|
|
6
|
+
'csharp',
|
|
7
|
+
'```',
|
|
8
|
+
'```c#',
|
|
9
|
+
'```csharp',
|
|
10
|
+
];
|
|
11
|
+
function removeCSharpOnlyLines(generatedCode) {
|
|
12
|
+
const lines = generatedCode.split(/\r?\n/);
|
|
13
|
+
const filteredLines = lines.map(line => {
|
|
14
|
+
// remove trailing spaces and tabs
|
|
15
|
+
const trimmedLine = line.trim();
|
|
16
|
+
if (trimmedLine.length === 0) {
|
|
17
|
+
return trimmedLine; // keep empty lines
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return line;
|
|
21
|
+
}
|
|
22
|
+
}).filter(line => {
|
|
23
|
+
const lowerCasedLine = line.toLowerCase();
|
|
24
|
+
return !illegalSingleLines.includes(lowerCasedLine);
|
|
25
|
+
});
|
|
26
|
+
return filteredLines.join('\n');
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=removeSingleLines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeSingleLines.js","sourceRoot":"","sources":["../../../src/gen/postGen/removeSingleLines.ts"],"names":[],"mappings":";;AAOA,sDAiBC;AAxBD,MAAM,kBAAkB,GAAG;IACvB,IAAI;IACJ,QAAQ;IACR,KAAK;IACL,OAAO;IACP,WAAW;CACd,CAAC;AACF,SAAgB,qBAAqB,CAAC,aAAqB;IACvD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3C,MAAM,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QAE/B,kCAAkC;QAClC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAChC,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,WAAW,CAAC,CAAC,mBAAmB;QAC3C,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1C,OAAO,CAAC,kBAAkB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC","sourcesContent":["const illegalSingleLines = [\r\n 'c#',\r\n 'csharp',\r\n '```',\r\n '```c#',\r\n '```csharp',\r\n];\r\nexport function removeCSharpOnlyLines(generatedCode: string): string {\r\n const lines = generatedCode.split(/\\r?\\n/);\r\n const filteredLines = lines.map(line => \r\n {\r\n // remove trailing spaces and tabs\r\n const trimmedLine = line.trim();\r\n if (trimmedLine.length === 0) {\r\n return trimmedLine; // keep empty lines\r\n } else {\r\n return line;\r\n }\r\n }).filter(line => {\r\n const lowerCasedLine = line.toLowerCase();\r\n return !illegalSingleLines.includes(lowerCasedLine);\r\n });\r\n\r\n return filteredLines.join('\\n');\r\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function repairRequiredNameSpaces(code: string): string;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.repairRequiredNameSpaces = repairRequiredNameSpaces;
|
|
4
|
+
function repairRequiredNameSpaces(code) {
|
|
5
|
+
const requiredUsings = [
|
|
6
|
+
"using Xap.ExecutionFramework;",
|
|
7
|
+
"using Xap.PluginFramework;",
|
|
8
|
+
"using System;",
|
|
9
|
+
"using System.Threading.Tasks;",
|
|
10
|
+
"using System.Collections.Generic;",
|
|
11
|
+
"using EMPTY = Microsoft.Bing.Xap.Plugins.Void;",
|
|
12
|
+
"using Microsoft.VisualStudio.TestTools.UnitTesting;"
|
|
13
|
+
];
|
|
14
|
+
// get all using lines
|
|
15
|
+
const usingRegex = /^\s*using\s+[^\r\n;]+;/gm;
|
|
16
|
+
const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());
|
|
17
|
+
const missingUsings = requiredUsings.filter(req => !existingUsings.includes(req));
|
|
18
|
+
if (missingUsings.length === 0) {
|
|
19
|
+
return code;
|
|
20
|
+
}
|
|
21
|
+
// find the end of the using block: the first non-using line, or the end of the file
|
|
22
|
+
const lines = code.split(/\r?\n/);
|
|
23
|
+
let insertIndex = 0;
|
|
24
|
+
for (let i = 0; i < lines.length; i++) {
|
|
25
|
+
if (!lines[i].trim().startsWith("using") && lines[i].trim() !== "") {
|
|
26
|
+
insertIndex = i;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
insertIndex = i + 1;
|
|
30
|
+
}
|
|
31
|
+
// build new code
|
|
32
|
+
const newLines = [
|
|
33
|
+
...lines.slice(0, insertIndex),
|
|
34
|
+
...missingUsings,
|
|
35
|
+
...lines.slice(insertIndex)
|
|
36
|
+
];
|
|
37
|
+
console.log("repaired namespaces:", missingUsings);
|
|
38
|
+
return newLines.join('\n');
|
|
39
|
+
}
|
|
40
|
+
// const code = `
|
|
41
|
+
// using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
42
|
+
// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;
|
|
43
|
+
// using System;
|
|
44
|
+
// using System.Collections.Generic;
|
|
45
|
+
// using System.Text;
|
|
46
|
+
// using Moq;
|
|
47
|
+
// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils
|
|
48
|
+
// {
|
|
49
|
+
// [TestClass]
|
|
50
|
+
// public class SqmidHelperTests
|
|
51
|
+
// {
|
|
52
|
+
// [TestMethod]
|
|
53
|
+
// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()
|
|
54
|
+
// {
|
|
55
|
+
// // Arrange
|
|
56
|
+
// var cookies = new Dictionary<string, string>
|
|
57
|
+
// {
|
|
58
|
+
// { "USRLOC", "BID=" + Convert.ToBase64String(Encoding.UTF8.GetBytes("test_decodedBlisId_test")) }
|
|
59
|
+
// };
|
|
60
|
+
// // Act
|
|
61
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
62
|
+
// // Assert
|
|
63
|
+
// Assert.AreEqual("decodedBlisId", result);
|
|
64
|
+
// }
|
|
65
|
+
// [TestMethod]
|
|
66
|
+
// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()
|
|
67
|
+
// {
|
|
68
|
+
// // Arrange
|
|
69
|
+
// var cookies = new Dictionary<string, string>
|
|
70
|
+
// {
|
|
71
|
+
// { "USRLOC", "SomeOtherValue=123" }
|
|
72
|
+
// };
|
|
73
|
+
// // Act
|
|
74
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
75
|
+
// // Assert
|
|
76
|
+
// Assert.IsNull(result);
|
|
77
|
+
// }
|
|
78
|
+
// [TestMethod]
|
|
79
|
+
// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()
|
|
80
|
+
// {
|
|
81
|
+
// // Arrange
|
|
82
|
+
// var cookies = new Dictionary<string, string>();
|
|
83
|
+
// // Act
|
|
84
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
85
|
+
// // Assert
|
|
86
|
+
// Assert.AreEqual(string.Empty, result);
|
|
87
|
+
// }
|
|
88
|
+
// [TestMethod]
|
|
89
|
+
// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()
|
|
90
|
+
// {
|
|
91
|
+
// // Arrange
|
|
92
|
+
// IDictionary<string, string> cookies = null;
|
|
93
|
+
// // Act
|
|
94
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
95
|
+
// // Assert
|
|
96
|
+
// Assert.AreEqual(string.Empty, result);
|
|
97
|
+
// }
|
|
98
|
+
// [TestMethod]
|
|
99
|
+
// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()
|
|
100
|
+
// {
|
|
101
|
+
// // Arrange
|
|
102
|
+
// var cookies = new Dictionary<string, string>
|
|
103
|
+
// {
|
|
104
|
+
// { "USRLOC", "" }
|
|
105
|
+
// };
|
|
106
|
+
// // Act
|
|
107
|
+
// var result = SqmidHelper.GetSqmidFromCookie(cookies);
|
|
108
|
+
// // Assert
|
|
109
|
+
// Assert.AreEqual(string.Empty, result);
|
|
110
|
+
// }
|
|
111
|
+
// }
|
|
112
|
+
// }
|
|
113
|
+
// `;
|
|
114
|
+
// const cleanedCode = repairRequiredNameSpaces(code);
|
|
115
|
+
// console.log(cleanedCode);
|
|
116
|
+
//# sourceMappingURL=repairRequiredNameSpaces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"repairRequiredNameSpaces.js","sourceRoot":"","sources":["../../../src/gen/postGen/repairRequiredNameSpaces.ts"],"names":[],"mappings":"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","sourcesContent":["import fs from 'fs';\r\nimport path from 'path';\r\n\r\nexport function repairRequiredNameSpaces(code: string): string {\r\n const requiredUsings = [\r\n \"using Xap.ExecutionFramework;\",\r\n \"using Xap.PluginFramework;\",\r\n \"using System;\",\r\n \"using System.Threading.Tasks;\",\r\n \"using System.Collections.Generic;\",\r\n \"using EMPTY = Microsoft.Bing.Xap.Plugins.Void;\",\r\n \"using Microsoft.VisualStudio.TestTools.UnitTesting;\"\r\n ];\r\n\r\n // get all using lines\r\n const usingRegex = /^\\s*using\\s+[^\\r\\n;]+;/gm;\r\n const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());\r\n\r\n const missingUsings = requiredUsings.filter(req => !existingUsings.includes(req));\r\n\r\n if (missingUsings.length === 0) {\r\n return code;\r\n }\r\n\r\n // find the end of the using block: the first non-using line, or the end of the file\r\n const lines = code.split(/\\r?\\n/);\r\n let insertIndex = 0;\r\n\r\n for (let i = 0; i < lines.length; i++) {\r\n if (!lines[i].trim().startsWith(\"using\") && lines[i].trim() !== \"\") {\r\n insertIndex = i;\r\n break;\r\n }\r\n insertIndex = i + 1;\r\n }\r\n\r\n // build new code\r\n const newLines = [\r\n ...lines.slice(0, insertIndex),\r\n ...missingUsings,\r\n ...lines.slice(insertIndex)\r\n ];\r\n\r\n console.log(\"repaired namespaces:\", missingUsings);\r\n\r\n return newLines.join('\\n');\r\n}\r\n\r\n\r\n// const code = `\r\n// using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\r\n// using System;\r\n// using System.Collections.Generic;\r\n// using System.Text;\r\n// using Moq;\r\n\r\n// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils\r\n// {\r\n// [TestClass]\r\n// public class SqmidHelperTests\r\n// {\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"BID=\" + Convert.ToBase64String(Encoding.UTF8.GetBytes(\"test_decodedBlisId_test\")) }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(\"decodedBlisId\", result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"SomeOtherValue=123\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.IsNull(result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>();\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// IDictionary<string, string> cookies = null;\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n// }\r\n// }\r\n// `;\r\n\r\n// const cleanedCode = repairRequiredNameSpaces(code);\r\n// console.log(cleanedCode);"]}
|