@ai-dev-tools/csharp-copilot-core 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/out/analyze/cecil.d.ts +1 -0
  2. package/out/analyze/cecil.js +42 -0
  3. package/out/analyze/cecil.js.map +1 -0
  4. package/out/analyze/checkCodeSyntax.d.ts +7 -0
  5. package/out/analyze/checkCodeSyntax.js +67 -0
  6. package/out/analyze/checkCodeSyntax.js.map +1 -0
  7. package/out/analyze/generateCodeDependency.d.ts +6 -0
  8. package/out/analyze/generateCodeDependency.js +127 -0
  9. package/out/analyze/generateCodeDependency.js.map +1 -0
  10. package/out/analyze/installAnalyzerTool.d.ts +1 -0
  11. package/out/analyze/installAnalyzerTool.js +83 -0
  12. package/out/analyze/installAnalyzerTool.js.map +1 -0
  13. package/out/batch/generateCodeTests.d.ts +6 -0
  14. package/out/batch/generateCodeTests.js +163 -0
  15. package/out/batch/generateCodeTests.js.map +1 -0
  16. package/out/batch/getFolderCodeFile.d.ts +1 -0
  17. package/out/batch/getFolderCodeFile.js +19 -0
  18. package/out/batch/getFolderCodeFile.js.map +1 -0
  19. package/out/batch/getProjectCodeFile.d.ts +4 -0
  20. package/out/batch/getProjectCodeFile.js +86 -0
  21. package/out/batch/getProjectCodeFile.js.map +1 -0
  22. package/out/batch/getSolutionCodeFile.d.ts +8 -0
  23. package/out/batch/getSolutionCodeFile.js +70 -0
  24. package/out/batch/getSolutionCodeFile.js.map +1 -0
  25. package/out/benchmark/formatToMarkdown.d.ts +2 -0
  26. package/out/benchmark/formatToMarkdown.js +101 -0
  27. package/out/benchmark/formatToMarkdown.js.map +1 -0
  28. package/out/benchmark/generateBenchmarkReport.d.ts +1 -0
  29. package/out/benchmark/generateBenchmarkReport.js +82 -0
  30. package/out/benchmark/generateBenchmarkReport.js.map +1 -0
  31. package/out/codeCoverage/codeCoverage.d.ts +6 -0
  32. package/out/codeCoverage/codeCoverage.js +39 -0
  33. package/out/codeCoverage/codeCoverage.js.map +1 -0
  34. package/out/codeCoverage/codeCoverageReport.d.ts +6 -0
  35. package/out/codeCoverage/codeCoverageReport.js +76 -0
  36. package/out/codeCoverage/codeCoverageReport.js.map +1 -0
  37. package/out/codeCoverage/extractCodeCoverageInfo.d.ts +2 -0
  38. package/out/codeCoverage/extractCodeCoverageInfo.js +81 -0
  39. package/out/codeCoverage/extractCodeCoverageInfo.js.map +1 -0
  40. package/out/codeCoverage/extractCoverageReportPath.d.ts +1 -0
  41. package/out/codeCoverage/extractCoverageReportPath.js +25 -0
  42. package/out/codeCoverage/extractCoverageReportPath.js.map +1 -0
  43. package/out/codeCoverage/generateCodeCoverageReport.d.ts +1 -0
  44. package/out/codeCoverage/generateCodeCoverageReport.js +30 -0
  45. package/out/codeCoverage/generateCodeCoverageReport.js.map +1 -0
  46. package/out/codeCoverage/getCodeCoverageSetting.d.ts +1 -0
  47. package/out/codeCoverage/getCodeCoverageSetting.js +58 -0
  48. package/out/codeCoverage/getCodeCoverageSetting.js.map +1 -0
  49. package/out/codeCoverage/reportTool.d.ts +2 -0
  50. package/out/codeCoverage/reportTool.js +23 -0
  51. package/out/codeCoverage/reportTool.js.map +1 -0
  52. package/out/codeCoverage/simplifyCoverageXml.d.ts +2 -0
  53. package/out/codeCoverage/simplifyCoverageXml.js +117 -0
  54. package/out/codeCoverage/simplifyCoverageXml.js.map +1 -0
  55. package/out/codebk/250804prompt/buildAfGuidelines.liquid +15 -0
  56. package/out/codebk/250804prompt/general/generalBuildAutofixGuidelines.liquid +13 -0
  57. package/out/codebk/250804prompt/general/generalUtGuidelines.liquid +18 -0
  58. package/out/codebk/250804prompt/generateUtAutoFix.liquid +19 -0
  59. package/out/codebk/250804prompt/generateUtGuidelines.liquid +13 -0
  60. package/out/codebk/250804prompt/generateUtSystem.liquid +5 -0
  61. package/out/codebk/250804prompt/generateUtUserInput.liquid +27 -0
  62. package/out/codebk/250804prompt/testAfGuidelines.liquid +6 -0
  63. package/out/codebk/250804prompt/xap/xapBuildAutofixGuidelines.liquid +13 -0
  64. package/out/codebk/250804prompt/xap/xapCodeCodeDependency.liquid +0 -0
  65. package/out/codebk/250804prompt/xap/xapCodeSample.liquid +38 -0
  66. package/out/codebk/250804prompt/xap/xapUtGuideline-240804.liquid +36 -0
  67. package/out/codebk/250804prompt/xap/xapUtGuideline.liquid +36 -0
  68. package/out/codebk/childProcessManager.d.ts +1 -0
  69. package/out/codebk/childProcessManager.js +50 -0
  70. package/out/codebk/childProcessManager.js.map +1 -0
  71. package/out/codebk/msBuidSpawn.d.ts +1 -0
  72. package/out/codebk/msBuidSpawn.js +58 -0
  73. package/out/codebk/msBuidSpawn.js.map +1 -0
  74. package/out/codebk/msBuild.d.ts +1 -0
  75. package/out/codebk/msBuild.js +123 -0
  76. package/out/codebk/msBuild.js.map +1 -0
  77. package/out/codebk/old/generateXapTestAutoFix.liquid +12 -0
  78. package/out/codebk/old/generateXapTestGuidelines-fm.liquid +68 -0
  79. package/out/codebk/old/generateXapTestGuidelines.liquid +28 -0
  80. package/out/codebk/old/xapGuideline-fm.liquid +149 -0
  81. package/out/codebk/old/xapGuideline.liquid +37 -0
  82. package/out/codebk/oldExec/checkCodeSyntax.d.ts +1 -0
  83. package/out/codebk/oldExec/checkCodeSyntax.js +81 -0
  84. package/out/codebk/oldExec/checkCodeSyntax.js.map +1 -0
  85. package/out/codebk/oldExec/codeCoverage.d.ts +1 -0
  86. package/out/codebk/oldExec/codeCoverage.js +54 -0
  87. package/out/codebk/oldExec/codeCoverage.js.map +1 -0
  88. package/out/codebk/oldExec/codeCoverageReport.d.ts +1 -0
  89. package/out/codebk/oldExec/codeCoverageReport.js +64 -0
  90. package/out/codebk/oldExec/codeCoverageReport.js.map +1 -0
  91. package/out/codebk/oldExec/containsMethods.d.ts +1 -0
  92. package/out/codebk/oldExec/containsMethods.js +74 -0
  93. package/out/codebk/oldExec/containsMethods.js.map +1 -0
  94. package/out/codebk/oldExec/generateCodeDependency.d.ts +1 -0
  95. package/out/codebk/oldExec/generateCodeDependency.js +95 -0
  96. package/out/codebk/oldExec/generateCodeDependency.js.map +1 -0
  97. package/out/codebk/oldExec/msBuild.d.ts +1 -0
  98. package/out/codebk/oldExec/msBuild.js +53 -0
  99. package/out/codebk/oldExec/msBuild.js.map +1 -0
  100. package/out/codebk/oldExec/vsTest.d.ts +1 -0
  101. package/out/codebk/oldExec/vsTest.js +71 -0
  102. package/out/codebk/oldExec/vsTest.js.map +1 -0
  103. package/out/codebk/prompts/general/generalUnitTestGuidelines-20250702.liquid +56 -0
  104. package/out/codebk/prompts/generateXapTestGuidelines-20250704.liquid +21 -0
  105. package/out/codebk/prompts/generateXapTestGuidelines-o.liquid +29 -0
  106. package/out/codebk/prompts/xap/xapGuideline-o.liquid +45 -0
  107. package/out/codebk/testbuildkill.d.ts +1 -0
  108. package/out/codebk/testbuildkill.js +37 -0
  109. package/out/codebk/testbuildkill.js.map +1 -0
  110. package/out/command/index.d.ts +2 -0
  111. package/out/command/index.js +90 -0
  112. package/out/command/index.js.map +1 -0
  113. package/out/command/utGenWrapper.d.ts +3 -0
  114. package/out/command/utGenWrapper.js +53 -0
  115. package/out/command/utGenWrapper.js.map +1 -0
  116. package/out/exit/childProcessManager.d.ts +2 -0
  117. package/out/exit/childProcessManager.js +43 -0
  118. package/out/exit/childProcessManager.js.map +1 -0
  119. package/out/exit/setupProcessSignalHandler.d.ts +1 -0
  120. package/out/exit/setupProcessSignalHandler.js +18 -0
  121. package/out/exit/setupProcessSignalHandler.js.map +1 -0
  122. package/out/gen/autoFix.d.ts +4 -0
  123. package/out/gen/autoFix.js +129 -0
  124. package/out/gen/autoFix.js.map +1 -0
  125. package/out/gen/csharpUtGen.d.ts +2 -0
  126. package/out/gen/csharpUtGen.js +125 -0
  127. package/out/gen/csharpUtGen.js.map +1 -0
  128. package/out/gen/ensureValidLLMResponse.d.ts +1 -0
  129. package/out/gen/ensureValidLLMResponse.js +19 -0
  130. package/out/gen/ensureValidLLMResponse.js.map +1 -0
  131. package/out/gen/postGen/addAiAnnotation.d.ts +1 -0
  132. package/out/gen/postGen/addAiAnnotation.js +57 -0
  133. package/out/gen/postGen/addAiAnnotation.js.map +1 -0
  134. package/out/gen/postGen/extractCodeFromResponse.d.ts +1 -0
  135. package/out/gen/postGen/extractCodeFromResponse.js +38 -0
  136. package/out/gen/postGen/extractCodeFromResponse.js.map +1 -0
  137. package/out/gen/postGen/postGenProcess.d.ts +1 -0
  138. package/out/gen/postGen/postGenProcess.js +39 -0
  139. package/out/gen/postGen/postGenProcess.js.map +1 -0
  140. package/out/gen/postGen/removeComments.d.ts +1 -0
  141. package/out/gen/postGen/removeComments.js +92 -0
  142. package/out/gen/postGen/removeComments.js.map +1 -0
  143. package/out/gen/postGen/removeSingleLines.d.ts +1 -0
  144. package/out/gen/postGen/removeSingleLines.js +29 -0
  145. package/out/gen/postGen/removeSingleLines.js.map +1 -0
  146. package/out/gen/postGen/repairRequiredNameSpaces.d.ts +2 -0
  147. package/out/gen/postGen/repairRequiredNameSpaces.js +142 -0
  148. package/out/gen/postGen/repairRequiredNameSpaces.js.map +1 -0
  149. package/out/gen/postGen/validateTestCode.d.ts +1 -0
  150. package/out/gen/postGen/validateTestCode.js +14 -0
  151. package/out/gen/postGen/validateTestCode.js.map +1 -0
  152. package/out/gen/preGen/excludeFileName.d.ts +1 -0
  153. package/out/gen/preGen/excludeFileName.js +49 -0
  154. package/out/gen/preGen/excludeFileName.js.map +1 -0
  155. package/out/gen/preGen/excludeSpecificTag.d.ts +1 -0
  156. package/out/gen/preGen/excludeSpecificTag.js +19 -0
  157. package/out/gen/preGen/excludeSpecificTag.js.map +1 -0
  158. package/out/gen/preGen/preGenProcess.d.ts +1 -0
  159. package/out/gen/preGen/preGenProcess.js +22 -0
  160. package/out/gen/preGen/preGenProcess.js.map +1 -0
  161. package/out/gen/preGen/validateCode.d.ts +3 -0
  162. package/out/gen/preGen/validateCode.js +63 -0
  163. package/out/gen/preGen/validateCode.js.map +1 -0
  164. package/out/index.d.ts +3 -0
  165. package/out/index.js +10 -0
  166. package/out/index.js.map +1 -0
  167. package/out/llm/model/Gpt.d.ts +1 -0
  168. package/out/llm/model/Gpt.js +93 -0
  169. package/out/llm/model/Gpt.js.map +1 -0
  170. package/out/llm/preparePrompt.d.ts +2 -0
  171. package/out/llm/preparePrompt.js +135 -0
  172. package/out/llm/preparePrompt.js.map +1 -0
  173. package/out/llm/prompt/buildAfGuidelines.liquid +15 -0
  174. package/out/llm/prompt/general/generalBuildAutofixGuidelines.liquid +13 -0
  175. package/out/llm/prompt/general/generalUtGuidelines.liquid +16 -0
  176. package/out/llm/prompt/generateUtAutoFix.liquid +23 -0
  177. package/out/llm/prompt/generateUtDependency.liquid +3 -0
  178. package/out/llm/prompt/generateUtSystem.liquid +5 -0
  179. package/out/llm/prompt/generateUtTemplate.liquid +32 -0
  180. package/out/llm/prompt/generateUtUserInput.liquid +4 -0
  181. package/out/llm/prompt/xap/xapBuildAutofixGuidelines.liquid +13 -0
  182. package/out/llm/prompt/xap/xapCodeCodeDependency.liquid +0 -0
  183. package/out/llm/prompt/xap/xapCodeSample.liquid +38 -0
  184. package/out/llm/prompt/xap/xapUtGuideline.liquid +37 -0
  185. package/out/llm/sendRequestToLLM.d.ts +4 -0
  186. package/out/llm/sendRequestToLLM.js +9 -0
  187. package/out/llm/sendRequestToLLM.js.map +1 -0
  188. package/out/llm/sendRequestToSelfHostLLM.d.ts +4 -0
  189. package/out/llm/sendRequestToSelfHostLLM.js +41 -0
  190. package/out/llm/sendRequestToSelfHostLLM.js.map +1 -0
  191. package/out/metrics/appInsightTelemetry.d.ts +6 -0
  192. package/out/metrics/appInsightTelemetry.js +77 -0
  193. package/out/metrics/appInsightTelemetry.js.map +1 -0
  194. package/out/metrics/machineId.d.ts +11 -0
  195. package/out/metrics/machineId.js +85 -0
  196. package/out/metrics/machineId.js.map +1 -0
  197. package/out/setup/setup.d.ts +1 -0
  198. package/out/setup/setup.js +10 -0
  199. package/out/setup/setup.js.map +1 -0
  200. package/out/setup/setupConsole.d.ts +1 -0
  201. package/out/setup/setupConsole.js +23 -0
  202. package/out/setup/setupConsole.js.map +1 -0
  203. package/out/setup/setupLLMRequest.d.ts +2 -0
  204. package/out/setup/setupLLMRequest.js +10 -0
  205. package/out/setup/setupLLMRequest.js.map +1 -0
  206. package/out/tools/devenvcom.cmd +13 -0
  207. package/out/tools/devenvexe.cmd +13 -0
  208. package/out/tools/msbuildexe.cmd +13 -0
  209. package/out/tools/vstestexe.cmd +13 -0
  210. package/out/types/benchmark.d.ts +11 -0
  211. package/out/types/benchmark.js +3 -0
  212. package/out/types/benchmark.js.map +1 -0
  213. package/out/types/buildResult.d.ts +8 -0
  214. package/out/types/buildResult.js +3 -0
  215. package/out/types/buildResult.js.map +1 -0
  216. package/out/types/constants.d.ts +10 -0
  217. package/out/types/constants.js +14 -0
  218. package/out/types/constants.js.map +1 -0
  219. package/out/types/genResult.d.ts +10 -0
  220. package/out/types/genResult.js +3 -0
  221. package/out/types/genResult.js.map +1 -0
  222. package/out/types/testResult.d.ts +12 -0
  223. package/out/types/testResult.js +3 -0
  224. package/out/types/testResult.js.map +1 -0
  225. package/out/types/verifyResult.d.ts +8 -0
  226. package/out/types/verifyResult.js +3 -0
  227. package/out/types/verifyResult.js.map +1 -0
  228. package/out/utils/checkTestProject.d.ts +2 -0
  229. package/out/utils/checkTestProject.js +79 -0
  230. package/out/utils/checkTestProject.js.map +1 -0
  231. package/out/utils/checkXapCode.d.ts +2 -0
  232. package/out/utils/checkXapCode.js +59 -0
  233. package/out/utils/checkXapCode.js.map +1 -0
  234. package/out/utils/delay.d.ts +1 -0
  235. package/out/utils/delay.js +7 -0
  236. package/out/utils/delay.js.map +1 -0
  237. package/out/utils/detectTestFramework.d.ts +1 -0
  238. package/out/utils/detectTestFramework.js +33 -0
  239. package/out/utils/detectTestFramework.js.map +1 -0
  240. package/out/utils/fileUtils.d.ts +2 -0
  241. package/out/utils/fileUtils.js +42 -0
  242. package/out/utils/fileUtils.js.map +1 -0
  243. package/out/utils/generateCodeSha256.d.ts +1 -0
  244. package/out/utils/generateCodeSha256.js +46 -0
  245. package/out/utils/generateCodeSha256.js.map +1 -0
  246. package/out/utils/getCodeStructurePath.d.ts +5 -0
  247. package/out/utils/getCodeStructurePath.js +155 -0
  248. package/out/utils/getCodeStructurePath.js.map +1 -0
  249. package/out/utils/getOrCreateDir.d.ts +2 -0
  250. package/out/utils/getOrCreateDir.js +63 -0
  251. package/out/utils/getOrCreateDir.js.map +1 -0
  252. package/out/utils/getTestCodeInfo.d.ts +2 -0
  253. package/out/utils/getTestCodeInfo.js +121 -0
  254. package/out/utils/getTestCodeInfo.js.map +1 -0
  255. package/out/utils/getTestFile.d.ts +13 -0
  256. package/out/utils/getTestFile.js +297 -0
  257. package/out/utils/getTestFile.js.map +1 -0
  258. package/out/utils/parseBuildResult.d.ts +3 -0
  259. package/out/utils/parseBuildResult.js +45 -0
  260. package/out/utils/parseBuildResult.js.map +1 -0
  261. package/out/utils/parseSyntaxCheckResult.d.ts +2 -0
  262. package/out/utils/parseSyntaxCheckResult.js +39 -0
  263. package/out/utils/parseSyntaxCheckResult.js.map +1 -0
  264. package/out/utils/parseVstestResult.d.ts +3 -0
  265. package/out/utils/parseVstestResult.js +62 -0
  266. package/out/utils/parseVstestResult.js.map +1 -0
  267. package/out/utils/removeFailedTestMethods.d.ts +3 -0
  268. package/out/utils/removeFailedTestMethods.js +208 -0
  269. package/out/utils/removeFailedTestMethods.js.map +1 -0
  270. package/out/utils/runCommand.d.ts +1 -0
  271. package/out/utils/runCommand.js +14 -0
  272. package/out/utils/runCommand.js.map +1 -0
  273. package/out/utils/spawnExec.d.ts +1 -0
  274. package/out/utils/spawnExec.js +80 -0
  275. package/out/utils/spawnExec.js.map +1 -0
  276. package/out/utils/verifyBuildErrorCausedFile.d.ts +1 -0
  277. package/out/utils/verifyBuildErrorCausedFile.js +60 -0
  278. package/out/utils/verifyBuildErrorCausedFile.js.map +1 -0
  279. package/out/utils/verifyTestCode.d.ts +2 -0
  280. package/out/utils/verifyTestCode.js +25 -0
  281. package/out/utils/verifyTestCode.js.map +1 -0
  282. package/out/utils/writeFailedVerifyResult.d.ts +1 -0
  283. package/out/utils/writeFailedVerifyResult.js +67 -0
  284. package/out/utils/writeFailedVerifyResult.js.map +1 -0
  285. package/out/utils/writeGenCode.d.ts +1 -0
  286. package/out/utils/writeGenCode.js +63 -0
  287. package/out/utils/writeGenCode.js.map +1 -0
  288. package/out/vs/msBuild.d.ts +13 -0
  289. package/out/vs/msBuild.js +49 -0
  290. package/out/vs/msBuild.js.map +1 -0
  291. package/out/vs/vsTest.d.ts +15 -0
  292. package/out/vs/vsTest.js +75 -0
  293. package/out/vs/vsTest.js.map +1 -0
  294. package/out/vs/vsTools.d.ts +7 -0
  295. package/out/vs/vsTools.js +177 -0
  296. package/out/vs/vsTools.js.map +1 -0
  297. package/out/vsPlugin/getVsPluginVerifyResult.d.ts +2 -0
  298. package/out/vsPlugin/getVsPluginVerifyResult.js +41 -0
  299. package/out/vsPlugin/getVsPluginVerifyResult.js.map +1 -0
  300. package/out/vsPlugin/interactionConstants.d.ts +2 -0
  301. package/out/vsPlugin/interactionConstants.js +10 -0
  302. package/out/vsPlugin/interactionConstants.js.map +1 -0
  303. package/out/vsPlugin/sendStdToVsPlugin.d.ts +1 -0
  304. package/out/vsPlugin/sendStdToVsPlugin.js +12 -0
  305. package/out/vsPlugin/sendStdToVsPlugin.js.map +1 -0
  306. package/out/vsPlugin/stdListener.d.ts +3 -0
  307. package/out/vsPlugin/stdListener.js +57 -0
  308. package/out/vsPlugin/stdListener.js.map +1 -0
  309. package/package.json +1 -1
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.autoFixTestCode = autoFixTestCode;
4
+ exports.generateAutoFixCode = generateAutoFixCode;
5
+ exports.autoRetryTestCode = autoRetryTestCode;
6
+ const checkCodeSyntax_1 = require("../analyze/checkCodeSyntax");
7
+ const ensureValidLLMResponse_1 = require("./ensureValidLLMResponse");
8
+ const postGenProcess_1 = require("./postGen/postGenProcess");
9
+ const preparePrompt_1 = require("../llm/preparePrompt");
10
+ const verifyBuildErrorCausedFile_1 = require("../utils/verifyBuildErrorCausedFile");
11
+ const verifyTestCode_1 = require("../utils/verifyTestCode");
12
+ const getVsPluginVerifyResult_1 = require("../vsPlugin/getVsPluginVerifyResult");
13
+ const writeGenCode_1 = require("../utils/writeGenCode");
14
+ const fileUtils_1 = require("../utils/fileUtils");
15
+ const writeFailedVerifyResult_1 = require("../utils/writeFailedVerifyResult");
16
+ const getCodeStructurePath_1 = require("../utils/getCodeStructurePath");
17
+ async function autoFixTestCode(prompts, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, isVsPlugin, retryTimes = 3, isBenchmark = false) {
18
+ const startTime = Date.now();
19
+ let generatedCode = testCode;
20
+ let testResult;
21
+ let buildResult;
22
+ let errorMessage;
23
+ let isBuildFailure = true;
24
+ try {
25
+ const sourceCodeProjectPath = (0, getCodeStructurePath_1.getSourceFileCsprojFilePath)(sourceCodePath);
26
+ for (let i = 0; i <= retryTimes; i++) {
27
+ // write generated code, to review and improve code quality
28
+ isBenchmark && (0, writeGenCode_1.writeGenCode)(sourceCodePath, generatedCode, i, sourceCodeProjectPath);
29
+ // for case: generatedCode is invalid, just retry instead of auto fix process
30
+ if (!generatedCode) {
31
+ console.error(`Generated code is invalid, try to regenerate. \nGenerated code: \n${generatedCode}`);
32
+ generatedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompts, testFramework, isXapCode);
33
+ // extract valid code from LLM response
34
+ generatedCode = (0, postGenProcess_1.postGenProcess)(generatedCode, testFramework, isXapCode);
35
+ continue;
36
+ }
37
+ // analyze generated code issue before verify: build, because build will cost much time.
38
+ const syntaxResult = await (0, checkCodeSyntax_1.checkCodeSyntax)(testFilePath);
39
+ if (syntaxResult.success) {
40
+ // if generated code passed the syntax check, verify the generated test code
41
+ // const { success, message, buildErrors, vsTestResult } = await verifyTestCode(generatedCode, testProjectPath);
42
+ const verifyResult = await verifyGeneratedCode(generatedCode, testProjectPath, testFilePath, isVsPlugin);
43
+ errorMessage = verifyResult.message;
44
+ testResult = verifyResult.testResult;
45
+ buildResult = verifyResult.buildErrors;
46
+ isBuildFailure = !testResult;
47
+ // if build errors caused by other code files instead of generate test code, abort generation
48
+ const validBuildError = (0, verifyBuildErrorCausedFile_1.verifyBuildErrorCausedFile)(testFilePath, buildResult);
49
+ if (!validBuildError) {
50
+ console.error("Due to build errors caused by other code files, abort generation, please fix it first.");
51
+ return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };
52
+ }
53
+ if (verifyResult.success) {
54
+ console.log("XapUt code generated successfully");
55
+ return { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };
56
+ }
57
+ console.error("Failed to verifyTestCode, error:", errorMessage);
58
+ }
59
+ else {
60
+ buildResult = syntaxResult.buildErrors;
61
+ errorMessage = syntaxResult.message;
62
+ console.error("Failed to check the generated UT code syntax, error:", errorMessage);
63
+ }
64
+ isBenchmark && (0, writeFailedVerifyResult_1.writeFailedVerifyResult)(sourceCodePath, i, sourceCodeProjectPath, errorMessage, !testResult);
65
+ // keep test failed tast cases in test file automatically
66
+ // if (!isBuildFailure && vsTestRes.passed !== 0) {
67
+ // console.log("remove failed test cases in test file");
68
+ // removeFailedTestCasesInTestFile(vsTestRes, testCodePath);
69
+ // return { success: true, testCode: generatedCode };
70
+ // }
71
+ if (i === retryTimes) {
72
+ console.error(`Failed to generate ut code after ${retryTimes} attempts.`);
73
+ break;
74
+ }
75
+ // case: vs plugin no response or msbuild/vstest failed.
76
+ if (!buildResult && !testResult) {
77
+ console.error("!!!Verify process failed, retrying...");
78
+ continue;
79
+ }
80
+ generatedCode = await generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, testFramework, isXapCode);
81
+ }
82
+ console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);
83
+ return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };
84
+ }
85
+ catch (error) {
86
+ console.error("Error during auto-fix process:", error);
87
+ return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
88
+ }
89
+ }
90
+ async function verifyGeneratedCode(generatedCode, testProjectPath, testFilePath, isVsPlugin = false) {
91
+ if (isVsPlugin) {
92
+ const vsVerifyResult = await (0, getVsPluginVerifyResult_1.verifyTestCodeByVsPlugin)(testFilePath);
93
+ return vsVerifyResult;
94
+ }
95
+ else {
96
+ // verifyResult: { success, message, buildErrors, vsTestResult }
97
+ const verifyResult = await (0, verifyTestCode_1.verifyTestCode)(generatedCode, testProjectPath);
98
+ return verifyResult;
99
+ }
100
+ }
101
+ async function generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, testFramework, isXapCode) {
102
+ console.log("start auto-fix process...");
103
+ const autofixPrompt = (0, preparePrompt_1.prepareUtAutoFixPrompt)(prompts, generatedCode, errorMessage, isBuildFailure);
104
+ // get valid code from LLM response with retry
105
+ const newGeneratedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(autofixPrompt, testFramework, isXapCode);
106
+ // if generate code is valid, write test code to test project
107
+ !!newGeneratedCode && (0, fileUtils_1.writeTestCode)(newGeneratedCode, testFilePath);
108
+ return newGeneratedCode;
109
+ }
110
+ // use for quick dev test
111
+ async function autoRetryTestCode(prompts, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, retryTimes = 3) {
112
+ const startTime = Date.now();
113
+ let generatedCode = testCode;
114
+ let vsTestRes;
115
+ for (let i = 0; i <= retryTimes; i++) {
116
+ if (i === retryTimes) {
117
+ console.error(`Failed to generate XapUt code after ${retryTimes} attempts.`);
118
+ break;
119
+ }
120
+ const autofixPrompt = prompts;
121
+ // get valid code from LLM response
122
+ generatedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(autofixPrompt, testFramework, isXapCode);
123
+ // write test code to test project
124
+ (0, fileUtils_1.writeTestCode)(generatedCode, testFilePath);
125
+ }
126
+ console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);
127
+ return { success: true, testFilePath: testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: vsTestRes };
128
+ }
129
+ //# sourceMappingURL=autoFix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoFix.js","sourceRoot":"","sources":["../../src/gen/autoFix.ts"],"names":[],"mappings":";;AAcA,0CA8FC;AAkBD,kDAmBC;AAID,8CA8BC;AAjLD,gEAA6D;AAC7D,qEAAkE;AAClE,6DAA0D;AAC1D,wDAA8D;AAC9D,oFAAiF;AACjF,4DAAyD;AACzD,iFAA+E;AAC/E,wDAAqD;AACrD,kDAAmD;AACnD,8EAA2E;AAC3E,wEAA4E;AAErE,KAAK,UAAU,eAAe,CACjC,OAAc,EACd,cAAsB,EACtB,QAAgB,EAChB,eAAuB,EACvB,YAAoB,EACpB,aAAqB,EACrB,SAAkB,EAClB,UAAmB,EACnB,aAAqB,CAAC,EACtB,cAAuB,KAAK;IAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,aAAa,GAAG,QAAQ,CAAC;IAC7B,IAAI,UAAU,CAAC;IACf,IAAI,WAAW,CAAC;IAChB,IAAI,YAAY,CAAC;IACjB,IAAI,cAAc,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC;QACD,MAAM,qBAAqB,GAAG,IAAA,kDAA2B,EAAC,cAAc,CAAC,CAAC;QAC1E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,2DAA2D;YAC3D,WAAW,IAAI,IAAA,2BAAY,EAAC,cAAc,EAAE,aAAa,EAAE,CAAC,EAAE,qBAAqB,CAAC,CAAC;YAErF,6EAA6E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AC;IAEtB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,aAAa,GAAG,QAAQ,CAAC;IAC7B,IAAI,SAAS,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,uCAAuC,UAAU,YAAY,CAAC,CAAC;YAC7E,MAAM;QACV,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,CAAC;QAC9B,mCAAmC;QACnC,aAAa,GAAG,MAAM,IAAA,+CAAsB,EAAC,aAAa,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QACtF,kCAAkC;QAClC,IAAA,yBAAa,EAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;IAExE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAClJ,CAAC","sourcesContent":["import { GenResult } from \"../types/genResult\";\r\nimport { VerifyResult } from \"../types/verifyResult\";\r\nimport { checkCodeSyntax } from \"../analyze/checkCodeSyntax\";\r\nimport { ensureValidLLMResponse } from \"./ensureValidLLMResponse\";\r\nimport { postGenProcess } from \"./postGen/postGenProcess\";\r\nimport { prepareUtAutoFixPrompt } from \"../llm/preparePrompt\";\r\nimport { verifyBuildErrorCausedFile } from \"../utils/verifyBuildErrorCausedFile\";\r\nimport { verifyTestCode } from \"../utils/verifyTestCode\";\r\nimport { verifyTestCodeByVsPlugin } from \"../vsPlugin/getVsPluginVerifyResult\";\r\nimport { writeGenCode } from \"../utils/writeGenCode\";\r\nimport { writeTestCode } from \"../utils/fileUtils\";\r\nimport { writeFailedVerifyResult } from \"../utils/writeFailedVerifyResult\";\r\nimport { getSourceFileCsprojFilePath } from \"../utils/getCodeStructurePath\";\r\n\r\nexport async function autoFixTestCode(\r\n prompts: any[],\r\n sourceCodePath: string,\r\n testCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n testFramework: string,\r\n isXapCode: boolean,\r\n isVsPlugin: boolean,\r\n retryTimes: number = 3,\r\n isBenchmark: boolean = false\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n let generatedCode = testCode;\r\n let testResult;\r\n let buildResult;\r\n let errorMessage;\r\n let isBuildFailure = true;\r\n try {\r\n const sourceCodeProjectPath = getSourceFileCsprojFilePath(sourceCodePath);\r\n for (let i = 0; i <= retryTimes; i++) {\r\n // write generated code, to review and improve code quality\r\n isBenchmark && writeGenCode(sourceCodePath, generatedCode, i, sourceCodeProjectPath);\r\n\r\n // for case: generatedCode is invalid, just retry instead of auto fix process\r\n if (!generatedCode) {\r\n console.error(`Generated code is invalid, try to regenerate. \\nGenerated code: \\n${generatedCode}`);\r\n generatedCode = await ensureValidLLMResponse(prompts, testFramework, isXapCode);\r\n // extract valid code from LLM response\r\n generatedCode = postGenProcess(generatedCode, testFramework, isXapCode);\r\n continue;\r\n }\r\n\r\n // analyze generated code issue before verify: build, because build will cost much time.\r\n const syntaxResult = await checkCodeSyntax(testFilePath);\r\n if (syntaxResult.success) {\r\n // if generated code passed the syntax check, verify the generated test code\r\n // const { success, message, buildErrors, vsTestResult } = await verifyTestCode(generatedCode, testProjectPath);\r\n const verifyResult = await verifyGeneratedCode(generatedCode, testProjectPath, testFilePath, isVsPlugin);\r\n errorMessage = verifyResult.message;\r\n testResult = verifyResult.testResult;\r\n buildResult = verifyResult.buildErrors;\r\n isBuildFailure = !testResult;\r\n\r\n // if build errors caused by other code files instead of generate test code, abort generation\r\n const validBuildError = verifyBuildErrorCausedFile(testFilePath, buildResult);\r\n if (!validBuildError) {\r\n console.error(\"Due to build errors caused by other code files, abort generation, please fix it first.\");\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n }\r\n\r\n if (verifyResult.success) {\r\n console.log(\"XapUt code generated successfully\");\r\n return { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n }\r\n\r\n console.error(\"Failed to verifyTestCode, error:\", errorMessage);\r\n } else {\r\n buildResult = syntaxResult.buildErrors;\r\n errorMessage = syntaxResult.message;\r\n console.error(\"Failed to check the generated UT code syntax, error:\", errorMessage);\r\n }\r\n\r\n isBenchmark && writeFailedVerifyResult(sourceCodePath, i, sourceCodeProjectPath, errorMessage, !testResult);\r\n // keep test failed tast cases in test file automatically\r\n // if (!isBuildFailure && vsTestRes.passed !== 0) {\r\n // console.log(\"remove failed test cases in test file\");\r\n // removeFailedTestCasesInTestFile(vsTestRes, testCodePath);\r\n // return { success: true, testCode: generatedCode };\r\n // }\r\n\r\n if (i === retryTimes) {\r\n console.error(`Failed to generate ut code after ${retryTimes} attempts.`);\r\n break;\r\n }\r\n\r\n // case: vs plugin no response or msbuild/vstest failed.\r\n if (!buildResult && !testResult) {\r\n console.error(\"!!!Verify process failed, retrying...\");\r\n continue;\r\n }\r\n\r\n generatedCode = await generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, testFramework, isXapCode);\r\n }\r\n\r\n console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);\r\n\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n } catch (error) {\r\n console.error(\"Error during auto-fix process:\", error);\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n\r\n }\r\n}\r\n\r\nasync function verifyGeneratedCode(\r\n generatedCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n isVsPlugin: boolean = false\r\n): Promise<VerifyResult> {\r\n if (isVsPlugin) {\r\n const vsVerifyResult = await verifyTestCodeByVsPlugin(testFilePath);\r\n return vsVerifyResult;\r\n } else {\r\n // verifyResult: { success, message, buildErrors, vsTestResult }\r\n const verifyResult = await verifyTestCode(generatedCode, testProjectPath);\r\n return verifyResult;\r\n }\r\n}\r\n\r\nexport async function generateAutoFixCode(\r\n prompts: any[],\r\n generatedCode: string,\r\n errorMessage: string,\r\n isBuildFailure: boolean,\r\n testFilePath: string,\r\n testFramework: string,\r\n isXapCode: boolean\r\n): Promise<string> {\r\n console.log(\"start auto-fix process...\");\r\n const autofixPrompt = prepareUtAutoFixPrompt(prompts, generatedCode, errorMessage, isBuildFailure);\r\n\r\n // get valid code from LLM response with retry\r\n const newGeneratedCode = await ensureValidLLMResponse(autofixPrompt, testFramework, isXapCode);\r\n\r\n // if generate code is valid, write test code to test project\r\n !!newGeneratedCode && writeTestCode(newGeneratedCode, testFilePath);\r\n\r\n return newGeneratedCode;\r\n}\r\n\r\n\r\n// use for quick dev test\r\nexport async function autoRetryTestCode(\r\n prompts: any[],\r\n sourceCodePath: string,\r\n testCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n testFramework: string,\r\n isXapCode: boolean,\r\n retryTimes: number = 3\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n let generatedCode = testCode;\r\n let vsTestRes;\r\n for (let i = 0; i <= retryTimes; i++) {\r\n if (i === retryTimes) {\r\n console.error(`Failed to generate XapUt code after ${retryTimes} attempts.`);\r\n break;\r\n }\r\n\r\n const autofixPrompt = prompts;\r\n // get valid code from LLM response\r\n generatedCode = await ensureValidLLMResponse(autofixPrompt, testFramework, isXapCode);\r\n // write test code to test project\r\n writeTestCode(generatedCode, testFilePath);\r\n }\r\n\r\n console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);\r\n\r\n return { success: true, testFilePath: testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: vsTestRes };\r\n}"]}
@@ -0,0 +1,2 @@
1
+ import { GenResult } from '../types/genResult';
2
+ export declare function generateCsharpUtCode(sourceCodePath: string, testCodePath: string, enableAutoFix: boolean, keepFailedTests: boolean, source?: string, isBenchmark?: boolean, nugetPackagePath?: string): Promise<GenResult>;
@@ -0,0 +1,125 @@
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, nugetPackagePath = null) {
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, nugetPackagePath);
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}. Please check if the test project exists.`);
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
+ // call LLM service to gen code with retry
87
+ const testCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompt, testFramework, isXapCode);
88
+ // write test code to test project
89
+ // To run vstest, need to write the test code to test project first, then build the test project and run the tests
90
+ (0, fileUtils_1.writeTestCode)(testCode, testFilePath);
91
+ // autofix
92
+ let autoFixResult = { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
93
+ if (enableAutoFix) {
94
+ const isVsPlugin = source === constants_1.CSVSPLUGIN;
95
+ autoFixResult = await (0, autoFix_1.autoFixTestCode)(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);
96
+ // autoFixResult = await autoRetryTestCode(prompt, sourceCode, testCode, testProjectPath, testFilePath, isXapTest);
97
+ }
98
+ if (autoFixResult.success) {
99
+ console.log(`Generate UT success time: ${(Date.now() - startTime) / 1000} seconds`);
100
+ return autoFixResult;
101
+ }
102
+ // if retry max times or test generation failed, and keepFailedTests is false, delete failed test file or remove failed test methods
103
+ if (!keepFailedTests) {
104
+ // keep succeed test code, or delete test file
105
+ if (!autoFixResult.testResult || autoFixResult.testResult.passed === 0) {
106
+ !testFileExist && (0, fileUtils_1.deleteTestFileIfExists)(testFilePath);
107
+ console.log(`Failed to generate csharp test code, deleted test file: ${testFilePath}`);
108
+ }
109
+ else {
110
+ (0, removeFailedTestMethods_1.removeFailedTestCasesInTestFile)(autoFixResult.testResult, testFilePath);
111
+ console.log(`write succeed test code to file: ${testFilePath}`);
112
+ }
113
+ }
114
+ else {
115
+ console.log(`keep failed test file: ${testFilePath}`);
116
+ }
117
+ console.log(`Generate UT failed time: ${(Date.now() - startTime) / 1000} seconds`);
118
+ return autoFixResult;
119
+ }
120
+ // generateCsharpUtCode("D:\\code\\IndexServe\\private\\indexserve\\RecommendationEngine\\RecoPS\\PSTableClient\\PSTableClient.cs", undefined, false, true, false);
121
+ // generateCsharpUtCode("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelper.cs", undefined, true, true, false);
122
+ // generateCsharpUtCode("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Eplant\\ResponseBuilders\\EplantMigrateResponseBuilder.cs", undefined, true, true, true);
123
+ // generateCsharpUtCode("D:\\code\\UCMDynamics\\private\\DynamicCode\\Plugin\\UCMDynamics.AppointmentPlugin\\AppointmentOperation.cs", undefined, false, true, false);
124
+ // generateCsharpUtCode("D:\\code\\AIUnitTestExample\\src\\ToListinator.Analyzers\\ToListCountAnalyzer.cs", undefined, true, true, false);
125
+ //# sourceMappingURL=csharpUtGen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csharpUtGen.js","sourceRoot":"","sources":["../../src/gen/csharpUtGen.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,oDAwFC;AA7GD,uCAAyB;AACzB,2CAA6B;AAE7B,kDAA6D;AAC7D,kDAA2E;AAG3E,uCAA4C;AAC5C,wDAAqD;AACrD,sEAAmE;AACnE,qEAAkE;AAClE,8EAA2E;AAC3E,sDAA0D;AAC1D,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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 nugetPackagePath: string = null\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, nugetPackagePath);\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}. Please check if the test project exists.`);\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\r\n // call LLM service to gen code with retry\r\n const testCode = await ensureValidLLMResponse(prompt, testFramework, 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, testFramework, 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(`Generate 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(`Generate 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"]}
@@ -0,0 +1 @@
1
+ export declare function ensureValidLLMResponse(prompt: any[], testFramework: string, 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, testFramework, 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, testFramework, 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,aAAqB,EAAE,SAAkB,EAAE,aAAqB,CAAC;IACzH,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,aAAa,EAAE,SAAS,CAAC,CAAC;QACzE,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[], testFramework: string, 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, testFramework, 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 addAiAnnotation(code: string): string;
@@ -0,0 +1,57 @@
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.addAiAnnotation = addAiAnnotation;
37
+ const constants_1 = require("../../types/constants");
38
+ const util = __importStar(require("util"));
39
+ function addAiAnnotation(code) {
40
+ const lines = code.split(constants_1.LINESEPARATOR);
41
+ if (code.includes(constants_1.AICONTRIBUTED)) {
42
+ const aiAnnotationTagIndex = lines.findIndex(line => line.startsWith(constants_1.AICONTRIBUTED));
43
+ lines.splice(aiAnnotationTagIndex, 1);
44
+ }
45
+ const currentDate = new Date().toISOString().split('T')[0];
46
+ const aiAnnotationTemplate = '/* %s-%s */';
47
+ const aiAnnotation = util.format(aiAnnotationTemplate, constants_1.AICONTRIBUTED, currentDate);
48
+ const namespaceIndex = lines.findIndex(line => line.startsWith(constants_1.NAMESPACE));
49
+ if (namespaceIndex !== -1) {
50
+ lines.splice(namespaceIndex, 0, aiAnnotation);
51
+ return lines.join('\n');
52
+ }
53
+ else {
54
+ return aiAnnotation + '\n' + code;
55
+ }
56
+ }
57
+ //# sourceMappingURL=addAiAnnotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addAiAnnotation.js","sourceRoot":"","sources":["../../../src/gen/postGen/addAiAnnotation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,0CAmBC;AAtBD,qDAAgF;AAChF,2CAA6B;AAE7B,SAAgB,eAAe,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,yBAAa,CAAC,CAAC;IACxC,IAAI,IAAI,CAAC,QAAQ,CAAC,yBAAa,CAAC,EAAE,CAAC;QAC/B,MAAM,oBAAoB,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,yBAAa,CAAC,CAAC,CAAC;QACrF,KAAK,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3D,MAAM,oBAAoB,GAAG,aAAa,CAAC;IAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,yBAAa,EAAE,WAAW,CAAC,CAAC;IAEnF,MAAM,cAAc,GAAG,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,qBAAS,CAAC,CAAC,CAAC;IAC3E,IAAI,cAAc,KAAK,CAAC,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC;QAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;SACI,CAAC;QACF,OAAO,YAAY,GAAG,IAAI,GAAG,IAAI,CAAC;IACtC,CAAC;AACL,CAAC","sourcesContent":["import { LINESEPARATOR, AICONTRIBUTED, NAMESPACE } from '../../types/constants';\r\nimport * as util from 'util';\r\n\r\nexport function addAiAnnotation(code: string): string {\r\n const lines = code.split(LINESEPARATOR);\r\n if (code.includes(AICONTRIBUTED)) {\r\n const aiAnnotationTagIndex = lines.findIndex(line => line.startsWith(AICONTRIBUTED));\r\n lines.splice(aiAnnotationTagIndex, 1);\r\n }\r\n\r\n const currentDate = new Date().toISOString().split('T')[0];\r\n const aiAnnotationTemplate = '/* %s-%s */';\r\n const aiAnnotation = util.format(aiAnnotationTemplate, AICONTRIBUTED, currentDate);\r\n\r\n const namespaceIndex = lines.findIndex(line => line.startsWith(NAMESPACE));\r\n if (namespaceIndex !== -1) {\r\n lines.splice(namespaceIndex, 0, aiAnnotation);\r\n return lines.join('\\n');\r\n }\r\n else {\r\n return aiAnnotation + '\\n' + code;\r\n }\r\n}"]}
@@ -0,0 +1 @@
1
+ export declare function extractCodeFromResponse(response: string): string;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractCodeFromResponse = extractCodeFromResponse;
4
+ const constants_1 = require("../../types/constants");
5
+ const regexList = [
6
+ /```(?:C#|csharp|CSharp|json|mermaid)?([\s\S]*?)(\n?```\n*|$)/g,
7
+ /```([\s\S]*?)(\n?```\n*|$)/g,
8
+ /```C#\s*([\s\S]*?)```/gi
9
+ ];
10
+ function extractCodeFromResponse(response) {
11
+ if (!response) {
12
+ return '';
13
+ }
14
+ const text = response.trim();
15
+ for (const regex of regexList) {
16
+ let testCode = getRegexResult(text, regex);
17
+ if (!!testCode) {
18
+ return testCode;
19
+ }
20
+ }
21
+ const lines = text.split(constants_1.LINESEPARATOR);
22
+ const hasMarkdown = lines.some(line => line.startsWith('#'));
23
+ if (hasMarkdown) {
24
+ return '';
25
+ }
26
+ return text;
27
+ }
28
+ function getRegexResult(response, regex) {
29
+ const match = regex.exec(response);
30
+ if (!match || match.length < 2) {
31
+ return null;
32
+ }
33
+ return match[1].trim();
34
+ }
35
+ // 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```';
36
+ // const code = extractCode(input);
37
+ // console.log(code);
38
+ //# sourceMappingURL=extractCodeFromResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractCodeFromResponse.js","sourceRoot":"","sources":["../../../src/gen/postGen/extractCodeFromResponse.ts"],"names":[],"mappings":";;AAQA,0DAkBC;AA1BD,qDAAsD;AAEtD,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,yBAAa,CAAC,CAAC;IACxC,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":["import { LINESEPARATOR } from \"../../types/constants\";\r\n\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(LINESEPARATOR);\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, testFramework: string, isXapCode: boolean): string;
@@ -0,0 +1,39 @@
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
+ const addAiAnnotation_1 = require("./addAiAnnotation");
10
+ function postGenProcess(generatedCode, testFramework, isXapCode) {
11
+ if (!isValidTestCode(generatedCode)) {
12
+ return undefined;
13
+ }
14
+ let testCode = (0, extractCodeFromResponse_1.extractCodeFromResponse)(generatedCode);
15
+ testCode = (0, removeComments_1.removeTestCodeComments)(testCode);
16
+ testCode = (0, removeSingleLines_1.removeCSharpOnlyLines)(testCode);
17
+ testCode = (0, repairRequiredNameSpaces_1.repairRequiredNameSpaces)(testCode, testFramework);
18
+ if (isXapCode) {
19
+ testCode = xapCodePostGenProcess(testCode);
20
+ }
21
+ testCode = (0, addAiAnnotation_1.addAiAnnotation)(testCode);
22
+ console.log(`Post generation process completed, code length: ${testCode.length}`);
23
+ return testCode;
24
+ }
25
+ function xapCodePostGenProcess(testCode) {
26
+ const processedCode = (0, repairRequiredNameSpaces_1.repairXapRequiredNameSpaces)(testCode);
27
+ return processedCode;
28
+ }
29
+ function isValidTestCode(testCode) {
30
+ if (!testCode || testCode.trim() === '') {
31
+ return false; // Empty code is not valid
32
+ }
33
+ // Check if the test code contains any test attributes or using statements
34
+ const isValid = (0, validateTestCode_1.validateTestCode)(testCode);
35
+ return isValid;
36
+ }
37
+ // const code = fs.readFileSync("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelperTests.cs", 'utf-8');
38
+ // postGenProcess(code, false);
39
+ //# sourceMappingURL=postGenProcess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postGenProcess.js","sourceRoot":"","sources":["../../../src/gen/postGen/postGenProcess.ts"],"names":[],"mappings":";;AAOA,wCAiBC;AAxBD,uEAAoE;AACpE,2DAA4D;AAC5D,qDAA0D;AAC1D,yEAAmG;AACnG,yDAAsD;AACtD,uDAAoD;AAEpD,SAAgB,cAAc,CAAC,aAAqB,EAAE,aAAqB,EAAE,SAAkB;IAC3F,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,QAAQ,GAAG,IAAA,mDAAwB,EAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAC7D,IAAI,SAAS,EAAE,CAAC;QACZ,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED,QAAQ,GAAG,IAAA,iCAAe,EAAC,QAAQ,CAAC,CAAC;IAErC,OAAO,CAAC,GAAG,CAAC,mDAAmD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAClF,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC3C,MAAM,aAAa,GAAG,IAAA,sDAA2B,EAAC,QAAQ,CAAC,CAAC;IAC5D,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 { extractCodeFromResponse } from \"./extractCodeFromResponse\";\r\nimport { removeCSharpOnlyLines } from \"./removeSingleLines\";\r\nimport { removeTestCodeComments } from \"./removeComments\";\r\nimport { repairRequiredNameSpaces, repairXapRequiredNameSpaces } from \"./repairRequiredNameSpaces\";\r\nimport { validateTestCode } from \"./validateTestCode\";\r\nimport { addAiAnnotation } from \"./addAiAnnotation\";\r\n\r\nexport function postGenProcess(generatedCode: string, testFramework: 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 testCode = repairRequiredNameSpaces(testCode, testFramework);\r\n if (isXapCode) {\r\n testCode = xapCodePostGenProcess(testCode);\r\n }\r\n\r\n testCode = addAiAnnotation(testCode);\r\n\r\n console.log(`Post generation process completed, code length: ${testCode.length}`);\r\n return testCode;\r\n}\r\n\r\nfunction xapCodePostGenProcess(testCode: string): string {\r\n const processedCode = repairXapRequiredNameSpaces(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