@ai-dev-tools/test-copilot-core 1.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.
Files changed (328) hide show
  1. package/README.md +6 -0
  2. package/azure-pipelines.yml +51 -0
  3. package/out/cli/commands/appInsightTelemetry.d.ts +7 -0
  4. package/out/cli/commands/appInsightTelemetry.d.ts.map +1 -0
  5. package/out/cli/commands/appInsightTelemetry.js +76 -0
  6. package/out/cli/commands/appInsightTelemetry.js.map +1 -0
  7. package/out/cli/commands/cliConfig.d.ts +4 -0
  8. package/out/cli/commands/cliConfig.d.ts.map +1 -0
  9. package/out/cli/commands/cliConfig.js +68 -0
  10. package/out/cli/commands/cliConfig.js.map +1 -0
  11. package/out/cli/commands/prompt.d.ts +6 -0
  12. package/out/cli/commands/prompt.d.ts.map +1 -0
  13. package/out/cli/commands/prompt.js +29 -0
  14. package/out/cli/commands/prompt.js.map +1 -0
  15. package/out/cli/commands/ut.d.ts +14 -0
  16. package/out/cli/commands/ut.d.ts.map +1 -0
  17. package/out/cli/commands/ut.js +72 -0
  18. package/out/cli/commands/ut.js.map +1 -0
  19. package/out/cli/commands/utPipeCmdWrapper.d.ts +18 -0
  20. package/out/cli/commands/utPipeCmdWrapper.d.ts.map +1 -0
  21. package/out/cli/commands/utPipeCmdWrapper.js +37 -0
  22. package/out/cli/commands/utPipeCmdWrapper.js.map +1 -0
  23. package/out/cli/config/index.d.ts +15 -0
  24. package/out/cli/config/index.d.ts.map +1 -0
  25. package/out/cli/config/index.js +10 -0
  26. package/out/cli/config/index.js.map +1 -0
  27. package/out/cli/index.d.ts +3 -0
  28. package/out/cli/index.d.ts.map +1 -0
  29. package/out/cli/index.js +169 -0
  30. package/out/cli/index.js.map +1 -0
  31. package/out/cli/type.d.ts +11 -0
  32. package/out/cli/type.d.ts.map +1 -0
  33. package/out/cli/type.js +3 -0
  34. package/out/cli/type.js.map +1 -0
  35. package/out/cli/utils/ds.d.ts +3 -0
  36. package/out/cli/utils/ds.d.ts.map +1 -0
  37. package/out/cli/utils/ds.js +50 -0
  38. package/out/cli/utils/ds.js.map +1 -0
  39. package/out/cli/utils/gpt.d.ts +3 -0
  40. package/out/cli/utils/gpt.d.ts.map +1 -0
  41. package/out/cli/utils/gpt.js +63 -0
  42. package/out/cli/utils/gpt.js.map +1 -0
  43. package/out/core/analyze/cjs.d.ts +61 -0
  44. package/out/core/analyze/cjs.d.ts.map +1 -0
  45. package/out/core/analyze/cjs.js +358 -0
  46. package/out/core/analyze/cjs.js.map +1 -0
  47. package/out/core/analyze/class.d.ts +4 -0
  48. package/out/core/analyze/class.d.ts.map +1 -0
  49. package/out/core/analyze/class.js +32 -0
  50. package/out/core/analyze/class.js.map +1 -0
  51. package/out/core/analyze/declares.d.ts +7 -0
  52. package/out/core/analyze/declares.d.ts.map +1 -0
  53. package/out/core/analyze/declares.js +316 -0
  54. package/out/core/analyze/declares.js.map +1 -0
  55. package/out/core/analyze/deps.d.ts +8 -0
  56. package/out/core/analyze/deps.d.ts.map +1 -0
  57. package/out/core/analyze/deps.js +210 -0
  58. package/out/core/analyze/deps.js.map +1 -0
  59. package/out/core/analyze/functionComponent.d.ts +4 -0
  60. package/out/core/analyze/functionComponent.d.ts.map +1 -0
  61. package/out/core/analyze/functionComponent.js +77 -0
  62. package/out/core/analyze/functionComponent.js.map +1 -0
  63. package/out/core/analyze/functions.d.ts +4 -0
  64. package/out/core/analyze/functions.d.ts.map +1 -0
  65. package/out/core/analyze/functions.js +46 -0
  66. package/out/core/analyze/functions.js.map +1 -0
  67. package/out/core/analyze/index.d.ts +16 -0
  68. package/out/core/analyze/index.d.ts.map +1 -0
  69. package/out/core/analyze/index.js +149 -0
  70. package/out/core/analyze/index.js.map +1 -0
  71. package/out/core/analyze/index.type.d.ts +69 -0
  72. package/out/core/analyze/index.type.d.ts.map +1 -0
  73. package/out/core/analyze/index.type.js +14 -0
  74. package/out/core/analyze/index.type.js.map +1 -0
  75. package/out/core/analyze/utils/global.d.ts +2 -0
  76. package/out/core/analyze/utils/global.d.ts.map +1 -0
  77. package/out/core/analyze/utils/global.js +84 -0
  78. package/out/core/analyze/utils/global.js.map +1 -0
  79. package/out/core/analyzev2/declare/class.d.ts +4 -0
  80. package/out/core/analyzev2/declare/class.d.ts.map +1 -0
  81. package/out/core/analyzev2/declare/class.js +24 -0
  82. package/out/core/analyzev2/declare/class.js.map +1 -0
  83. package/out/core/analyzev2/declare/funcLike.d.ts +8 -0
  84. package/out/core/analyzev2/declare/funcLike.d.ts.map +1 -0
  85. package/out/core/analyzev2/declare/funcLike.js +71 -0
  86. package/out/core/analyzev2/declare/funcLike.js.map +1 -0
  87. package/out/core/analyzev2/declare/variable.d.ts +3 -0
  88. package/out/core/analyzev2/declare/variable.d.ts.map +1 -0
  89. package/out/core/analyzev2/declare/variable.js +15 -0
  90. package/out/core/analyzev2/declare/variable.js.map +1 -0
  91. package/out/core/analyzev2/file.d.ts +19 -0
  92. package/out/core/analyzev2/file.d.ts.map +1 -0
  93. package/out/core/analyzev2/file.js +449 -0
  94. package/out/core/analyzev2/file.js.map +1 -0
  95. package/out/core/analyzev2/index.d.ts +5 -0
  96. package/out/core/analyzev2/index.d.ts.map +1 -0
  97. package/out/core/analyzev2/index.js +30 -0
  98. package/out/core/analyzev2/index.js.map +1 -0
  99. package/out/core/analyzev2/type.d.ts +35 -0
  100. package/out/core/analyzev2/type.d.ts.map +1 -0
  101. package/out/core/analyzev2/type.js +3 -0
  102. package/out/core/analyzev2/type.js.map +1 -0
  103. package/out/core/config/index.d.ts +25 -0
  104. package/out/core/config/index.d.ts.map +1 -0
  105. package/out/core/config/index.js +14 -0
  106. package/out/core/config/index.js.map +1 -0
  107. package/out/core/constants.d.ts +9 -0
  108. package/out/core/constants.d.ts.map +1 -0
  109. package/out/core/constants.js +12 -0
  110. package/out/core/constants.js.map +1 -0
  111. package/out/core/features/common/base.d.ts +20 -0
  112. package/out/core/features/common/base.d.ts.map +1 -0
  113. package/out/core/features/common/base.js +77 -0
  114. package/out/core/features/common/base.js.map +1 -0
  115. package/out/core/features/common/types.d.ts +16 -0
  116. package/out/core/features/common/types.d.ts.map +1 -0
  117. package/out/core/features/common/types.js +12 -0
  118. package/out/core/features/common/types.js.map +1 -0
  119. package/out/core/features/generateFile.d.ts +31 -0
  120. package/out/core/features/generateFile.d.ts.map +1 -0
  121. package/out/core/features/generateFile.js +148 -0
  122. package/out/core/features/generateFile.js.map +1 -0
  123. package/out/core/features/generateSingle.d.ts +28 -0
  124. package/out/core/features/generateSingle.d.ts.map +1 -0
  125. package/out/core/features/generateSingle.js +149 -0
  126. package/out/core/features/generateSingle.js.map +1 -0
  127. package/out/core/features/index.d.ts +9 -0
  128. package/out/core/features/index.d.ts.map +1 -0
  129. package/out/core/features/index.js +16 -0
  130. package/out/core/features/index.js.map +1 -0
  131. package/out/core/features/lintFix.d.ts +2 -0
  132. package/out/core/features/lintFix.d.ts.map +1 -0
  133. package/out/core/features/lintFix.js +33 -0
  134. package/out/core/features/lintFix.js.map +1 -0
  135. package/out/core/features/mergeUTFile.d.ts +19 -0
  136. package/out/core/features/mergeUTFile.d.ts.map +1 -0
  137. package/out/core/features/mergeUTFile.js +63 -0
  138. package/out/core/features/mergeUTFile.js.map +1 -0
  139. package/out/core/features/removeFailedCases.d.ts +23 -0
  140. package/out/core/features/removeFailedCases.d.ts.map +1 -0
  141. package/out/core/features/removeFailedCases.js +81 -0
  142. package/out/core/features/removeFailedCases.js.map +1 -0
  143. package/out/core/features/updateSpec.d.ts +20 -0
  144. package/out/core/features/updateSpec.d.ts.map +1 -0
  145. package/out/core/features/updateSpec.js +98 -0
  146. package/out/core/features/updateSpec.js.map +1 -0
  147. package/out/core/features/validFix.d.ts +29 -0
  148. package/out/core/features/validFix.d.ts.map +1 -0
  149. package/out/core/features/validFix.js +219 -0
  150. package/out/core/features/validFix.js.map +1 -0
  151. package/out/core/generate/UTGen.d.ts +79 -0
  152. package/out/core/generate/UTGen.d.ts.map +1 -0
  153. package/out/core/generate/UTGen.js +795 -0
  154. package/out/core/generate/UTGen.js.map +1 -0
  155. package/out/core/llm/index.d.ts +9 -0
  156. package/out/core/llm/index.d.ts.map +1 -0
  157. package/out/core/llm/index.js +39 -0
  158. package/out/core/llm/index.js.map +1 -0
  159. package/out/core/llm/prompts/config.d.ts +6 -0
  160. package/out/core/llm/prompts/config.d.ts.map +1 -0
  161. package/out/core/llm/prompts/config.js +239 -0
  162. package/out/core/llm/prompts/config.js.map +1 -0
  163. package/out/core/llm/prompts/templates/common.d.ts +3 -0
  164. package/out/core/llm/prompts/templates/common.d.ts.map +1 -0
  165. package/out/core/llm/prompts/templates/common.js +27 -0
  166. package/out/core/llm/prompts/templates/common.js.map +1 -0
  167. package/out/core/llm/prompts/templates/fixCase.d.ts +4 -0
  168. package/out/core/llm/prompts/templates/fixCase.d.ts.map +1 -0
  169. package/out/core/llm/prompts/templates/fixCase.js +46 -0
  170. package/out/core/llm/prompts/templates/fixCase.js.map +1 -0
  171. package/out/core/llm/prompts/templates/fixLint.d.ts +3 -0
  172. package/out/core/llm/prompts/templates/fixLint.d.ts.map +1 -0
  173. package/out/core/llm/prompts/templates/fixLint.js +22 -0
  174. package/out/core/llm/prompts/templates/fixLint.js.map +1 -0
  175. package/out/core/llm/prompts/templates/genClassMemberUT.d.ts +5 -0
  176. package/out/core/llm/prompts/templates/genClassMemberUT.d.ts.map +1 -0
  177. package/out/core/llm/prompts/templates/genClassMemberUT.js +115 -0
  178. package/out/core/llm/prompts/templates/genClassMemberUT.js.map +1 -0
  179. package/out/core/llm/prompts/templates/genFuncUT.d.ts +4 -0
  180. package/out/core/llm/prompts/templates/genFuncUT.d.ts.map +1 -0
  181. package/out/core/llm/prompts/templates/genFuncUT.js +64 -0
  182. package/out/core/llm/prompts/templates/genFuncUT.js.map +1 -0
  183. package/out/core/llm/prompts/templates/mergeUT.d.ts +4 -0
  184. package/out/core/llm/prompts/templates/mergeUT.d.ts.map +1 -0
  185. package/out/core/llm/prompts/templates/mergeUT.js +106 -0
  186. package/out/core/llm/prompts/templates/mergeUT.js.map +1 -0
  187. package/out/core/llm/prompts/templates/msnStudio.d.ts +3 -0
  188. package/out/core/llm/prompts/templates/msnStudio.d.ts.map +1 -0
  189. package/out/core/llm/prompts/templates/msnStudio.js +36 -0
  190. package/out/core/llm/prompts/templates/msnStudio.js.map +1 -0
  191. package/out/core/llm/prompts/templates/snapshotUT.d.ts +4 -0
  192. package/out/core/llm/prompts/templates/snapshotUT.d.ts.map +1 -0
  193. package/out/core/llm/prompts/templates/snapshotUT.js +68 -0
  194. package/out/core/llm/prompts/templates/snapshotUT.js.map +1 -0
  195. package/out/core/llm/prompts/templates/updateSpecBlock.d.ts +3 -0
  196. package/out/core/llm/prompts/templates/updateSpecBlock.d.ts.map +1 -0
  197. package/out/core/llm/prompts/templates/updateSpecBlock.js +38 -0
  198. package/out/core/llm/prompts/templates/updateSpecBlock.js.map +1 -0
  199. package/out/core/llm/prompts/templates/updateSpecFile.d.ts +3 -0
  200. package/out/core/llm/prompts/templates/updateSpecFile.d.ts.map +1 -0
  201. package/out/core/llm/prompts/templates/updateSpecFile.js +30 -0
  202. package/out/core/llm/prompts/templates/updateSpecFile.js.map +1 -0
  203. package/out/core/llm/types.d.ts +80 -0
  204. package/out/core/llm/types.d.ts.map +1 -0
  205. package/out/core/llm/types.js +5 -0
  206. package/out/core/llm/types.js.map +1 -0
  207. package/out/core/quality/validateMockedTest.d.ts +3 -0
  208. package/out/core/quality/validateMockedTest.d.ts.map +1 -0
  209. package/out/core/quality/validateMockedTest.js +211 -0
  210. package/out/core/quality/validateMockedTest.js.map +1 -0
  211. package/out/core/utils/checkTestIgnore.d.ts +4 -0
  212. package/out/core/utils/checkTestIgnore.d.ts.map +1 -0
  213. package/out/core/utils/checkTestIgnore.js +52 -0
  214. package/out/core/utils/checkTestIgnore.js.map +1 -0
  215. package/out/core/utils/common.d.ts +4 -0
  216. package/out/core/utils/common.d.ts.map +1 -0
  217. package/out/core/utils/common.js +34 -0
  218. package/out/core/utils/common.js.map +1 -0
  219. package/out/core/utils/console.d.ts +8 -0
  220. package/out/core/utils/console.d.ts.map +1 -0
  221. package/out/core/utils/console.js +24 -0
  222. package/out/core/utils/console.js.map +1 -0
  223. package/out/core/utils/deps.d.ts +3 -0
  224. package/out/core/utils/deps.d.ts.map +1 -0
  225. package/out/core/utils/deps.js +58 -0
  226. package/out/core/utils/deps.js.map +1 -0
  227. package/out/core/utils/eslintRuleHandler.d.ts +3 -0
  228. package/out/core/utils/eslintRuleHandler.d.ts.map +1 -0
  229. package/out/core/utils/eslintRuleHandler.js +98 -0
  230. package/out/core/utils/eslintRuleHandler.js.map +1 -0
  231. package/out/core/utils/file.d.ts +18 -0
  232. package/out/core/utils/file.d.ts.map +1 -0
  233. package/out/core/utils/file.js +142 -0
  234. package/out/core/utils/file.js.map +1 -0
  235. package/out/core/utils/lint.d.ts +9 -0
  236. package/out/core/utils/lint.d.ts.map +1 -0
  237. package/out/core/utils/lint.js +95 -0
  238. package/out/core/utils/lint.js.map +1 -0
  239. package/out/core/utils/lru.d.ts +12 -0
  240. package/out/core/utils/lru.d.ts.map +1 -0
  241. package/out/core/utils/lru.js +47 -0
  242. package/out/core/utils/lru.js.map +1 -0
  243. package/out/core/utils/move.d.ts +12 -0
  244. package/out/core/utils/move.d.ts.map +1 -0
  245. package/out/core/utils/move.js +93 -0
  246. package/out/core/utils/move.js.map +1 -0
  247. package/out/core/utils/msnStudio.d.ts +13 -0
  248. package/out/core/utils/msnStudio.d.ts.map +1 -0
  249. package/out/core/utils/msnStudio.js +150 -0
  250. package/out/core/utils/msnStudio.js.map +1 -0
  251. package/out/core/utils/parseCustomizedCmd.d.ts +2 -0
  252. package/out/core/utils/parseCustomizedCmd.d.ts.map +1 -0
  253. package/out/core/utils/parseCustomizedCmd.js +32 -0
  254. package/out/core/utils/parseCustomizedCmd.js.map +1 -0
  255. package/out/core/utils/specBlock.d.ts +20 -0
  256. package/out/core/utils/specBlock.d.ts.map +1 -0
  257. package/out/core/utils/specBlock.js +231 -0
  258. package/out/core/utils/specBlock.js.map +1 -0
  259. package/out/core/utils/system.d.ts +13 -0
  260. package/out/core/utils/system.d.ts.map +1 -0
  261. package/out/core/utils/system.js +86 -0
  262. package/out/core/utils/system.js.map +1 -0
  263. package/out/core/utils/telemetry.d.ts +9 -0
  264. package/out/core/utils/telemetry.d.ts.map +1 -0
  265. package/out/core/utils/telemetry.js +32 -0
  266. package/out/core/utils/telemetry.js.map +1 -0
  267. package/out/core/utils/tsMorph.d.ts +13 -0
  268. package/out/core/utils/tsMorph.d.ts.map +1 -0
  269. package/out/core/utils/tsMorph.js +76 -0
  270. package/out/core/utils/tsMorph.js.map +1 -0
  271. package/out/core/valid/customizedLint.d.ts +2 -0
  272. package/out/core/valid/customizedLint.d.ts.map +1 -0
  273. package/out/core/valid/customizedLint.js +64 -0
  274. package/out/core/valid/customizedLint.js.map +1 -0
  275. package/out/core/valid/customizedTest.d.ts +3 -0
  276. package/out/core/valid/customizedTest.d.ts.map +1 -0
  277. package/out/core/valid/customizedTest.js +58 -0
  278. package/out/core/valid/customizedTest.js.map +1 -0
  279. package/out/core/valid/extractVitestConfig.d.ts +5 -0
  280. package/out/core/valid/extractVitestConfig.d.ts.map +1 -0
  281. package/out/core/valid/extractVitestConfig.js +97 -0
  282. package/out/core/valid/extractVitestConfig.js.map +1 -0
  283. package/out/core/valid/getViteConfig.d.ts +2 -0
  284. package/out/core/valid/getViteConfig.d.ts.map +1 -0
  285. package/out/core/valid/getViteConfig.js +65 -0
  286. package/out/core/valid/getViteConfig.js.map +1 -0
  287. package/out/core/valid/index.d.ts +15 -0
  288. package/out/core/valid/index.d.ts.map +1 -0
  289. package/out/core/valid/index.js +99 -0
  290. package/out/core/valid/index.js.map +1 -0
  291. package/out/core/valid/jest.d.ts +4 -0
  292. package/out/core/valid/jest.d.ts.map +1 -0
  293. package/out/core/valid/jest.js +121 -0
  294. package/out/core/valid/jest.js.map +1 -0
  295. package/out/core/valid/mock.d.ts +2 -0
  296. package/out/core/valid/mock.d.ts.map +1 -0
  297. package/out/core/valid/mock.js +149 -0
  298. package/out/core/valid/mock.js.map +1 -0
  299. package/out/core/valid/remove.d.ts +5 -0
  300. package/out/core/valid/remove.d.ts.map +1 -0
  301. package/out/core/valid/remove.js +109 -0
  302. package/out/core/valid/remove.js.map +1 -0
  303. package/out/core/valid/tag.d.ts +3 -0
  304. package/out/core/valid/tag.d.ts.map +1 -0
  305. package/out/core/valid/tag.js +91 -0
  306. package/out/core/valid/tag.js.map +1 -0
  307. package/out/core/valid/type.d.ts +83 -0
  308. package/out/core/valid/type.d.ts.map +1 -0
  309. package/out/core/valid/type.js +3 -0
  310. package/out/core/valid/type.js.map +1 -0
  311. package/out/core/valid/vitest.d.ts +3 -0
  312. package/out/core/valid/vitest.d.ts.map +1 -0
  313. package/out/core/valid/vitest.js +82 -0
  314. package/out/core/valid/vitest.js.map +1 -0
  315. package/out/index.d.ts +20 -0
  316. package/out/index.d.ts.map +1 -0
  317. package/out/index.js +60 -0
  318. package/out/index.js.map +1 -0
  319. package/out/setup.d.ts +11 -0
  320. package/out/setup.d.ts.map +1 -0
  321. package/out/setup.js +14 -0
  322. package/out/setup.js.map +1 -0
  323. package/out/types.d.ts +23 -0
  324. package/out/types.d.ts.map +1 -0
  325. package/out/types.js +3 -0
  326. package/out/types.js.map +1 -0
  327. package/package.json +39 -0
  328. package/package_devops.json +42 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lintFix.d.ts","sourceRoot":"","sources":["../../../src/core/features/lintFix.ts"],"names":[],"mappings":"AASA,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBA0B9F"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fixLintErrors = fixLintErrors;
7
+ const common_1 = require("../utils/common");
8
+ const llm_1 = require("../llm");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const console_1 = require("../utils/console");
11
+ const path_1 = __importDefault(require("path"));
12
+ async function fixLintErrors(filePath, lintErrors, testFramework) {
13
+ const fileExt = path_1.default.extname(filePath);
14
+ const testCode = fs_1.default.readFileSync(filePath, 'utf-8');
15
+ const lintFixPrompt = (0, llm_1.getPrompt)("FixLintErrors" /* PromptKey.FixLintErrors */, {
16
+ ["<<<TestFramework>>>" /* PromptPlaceholder.TestFramework */]: testFramework,
17
+ ["<<<Spec>>>" /* PromptPlaceholder.SpecCode */]: testCode,
18
+ ["<<<LintErrors>>>" /* PromptPlaceholder.LintErrors */]: lintErrors,
19
+ ["<<<Language>>>" /* PromptPlaceholder.Language */]: (0, common_1.getLanguage)(fileExt)
20
+ });
21
+ const res = await (0, llm_1.getLLMResponse)(lintFixPrompt);
22
+ if (!res.success) {
23
+ (0, console_1.getConsole)().error(` lint fix - Failed to get code from AI, res: ${JSON.stringify(res)}`);
24
+ return "";
25
+ }
26
+ let fixedTestCode = (0, common_1.extractCodeFromResponse)(res.content);
27
+ if (!fixedTestCode) {
28
+ (0, console_1.getConsole)().error(` lint fix - Failed to extract code from AI response, res.content: ${res.content}`);
29
+ return "";
30
+ }
31
+ return fixedTestCode;
32
+ }
33
+ //# sourceMappingURL=lintFix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lintFix.js","sourceRoot":"","sources":["../../../src/core/features/lintFix.ts"],"names":[],"mappings":";;;;;AASA,sCA0BC;AAlCD,4CAAuE;AACvE,gCAAmD;AAEnD,4CAAoB;AACpB,8CAA8C;AAE9C,gDAAwB;AAEjB,KAAK,UAAU,aAAa,CAAC,QAAgB,EAAE,UAAkB,EAAE,aAAqB;IAC3F,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,IAAA,eAAS,iDAE3B;QACI,6DAAiC,EAAE,aAAa;QAChD,+CAA4B,EAAE,QAAQ;QACtC,uDAA8B,EAAE,UAAU;QAC1C,mDAA4B,EAAE,IAAA,oBAAW,EAAC,OAAO,CAAC;KACrD,CACJ,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,IAAA,oBAAc,EAAC,aAAa,CAAC,CAAC;IAChD,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACf,IAAA,oBAAU,GAAE,CAAC,KAAK,CAAC,gDAAgD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1F,OAAO,EAAE,CAAC;IACd,CAAC;IAED,IAAI,aAAa,GAAG,IAAA,gCAAuB,EAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,CAAC,aAAa,EAAE,CAAC;QACjB,IAAA,oBAAU,GAAE,CAAC,KAAK,CAAC,qEAAqE,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACvG,OAAO,EAAE,CAAC;IACd,CAAC;IAED,OAAO,aAAa,CAAC;AACzB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { FeatureBase } from "./common/base";
2
+ export interface MergeUTFileParams {
3
+ sourceCodePath: string;
4
+ sourceSpecPath: string;
5
+ targetSpecPath: string;
6
+ }
7
+ export interface MergeUTFileResult {
8
+ success: boolean;
9
+ }
10
+ /**
11
+ * Generate new test for a single function/method.
12
+ * !! Assume there is no existing test for the function/method !!
13
+ */
14
+ export declare class MergeUTFile extends FeatureBase<MergeUTFileParams, MergeUTFileResult> {
15
+ protected task(): Promise<{
16
+ success: boolean;
17
+ }>;
18
+ }
19
+ //# sourceMappingURL=mergeUTFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeUTFile.d.ts","sourceRoot":"","sources":["../../../src/core/features/mergeUTFile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAO5C,MAAM,WAAW,iBAAiB;IAE9B,cAAc,EAAE,MAAM,CAAC;IAEvB,cAAc,EAAE,MAAM,CAAC;IAEvB,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAC9B,OAAO,EAAE,OAAO,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,WAAY,SAAQ,WAAW,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;cAC9D,IAAI;;;CAiDvB"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MergeUTFile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const base_1 = require("./common/base");
10
+ const file_1 = require("../utils/file");
11
+ const llm_1 = require("../llm");
12
+ const config_1 = require("../config");
13
+ const validFix_1 = require("./validFix");
14
+ const system_1 = require("../utils/system");
15
+ /**
16
+ * Generate new test for a single function/method.
17
+ * !! Assume there is no existing test for the function/method !!
18
+ */
19
+ class MergeUTFile extends base_1.FeatureBase {
20
+ async task() {
21
+ const { sourceCodePath, sourceSpecPath, targetSpecPath } = this.params;
22
+ const sourceCodeFilename = './' + path_1.default.basename(sourceCodePath);
23
+ const specRelativePath = (0, file_1.getNormalizedRelativePath)(sourceCodePath, sourceSpecPath);
24
+ const targetFileName = path_1.default.basename(targetSpecPath);
25
+ const targetFileRelativePath = (0, file_1.getNormalizedRelativePath)(sourceCodePath, targetSpecPath);
26
+ const separatedFileContent = fs_1.default.readFileSync(sourceSpecPath, 'utf-8');
27
+ let targetFileContent = '// Empty file';
28
+ if (fs_1.default.existsSync(targetSpecPath)) {
29
+ targetFileContent = fs_1.default.readFileSync(targetSpecPath, 'utf-8');
30
+ }
31
+ const prompt = (0, llm_1.getPrompt)("MergeUTFile" /* PromptKey.MergeUTFile */, {
32
+ ["<<<SourceFileName>>>" /* PromptPlaceholder.SourceFileName */]: sourceCodeFilename,
33
+ ["<<<SpecFileName>>>" /* PromptPlaceholder.SpecFileName */]: specRelativePath,
34
+ ["<<<TargetFilePath>>>" /* PromptPlaceholder.TargetFilePath */]: targetFileRelativePath,
35
+ ["<<<TestFramework>>>" /* PromptPlaceholder.TestFramework */]: (0, config_1.getConfig)().common.testFramework,
36
+ ["<<<Spec>>>" /* PromptPlaceholder.SpecCode */]: separatedFileContent,
37
+ ["<<<SpecTemplate>>>" /* PromptPlaceholder.SpecTemplate */]: targetFileContent,
38
+ });
39
+ this.progress({ message: `Start merging test file \`${specRelativePath}\` into \`${targetFileRelativePath}\`` });
40
+ const llmRes = await this.getCodeFromLLM(prompt);
41
+ const testRes = await this.runSubTask(validFix_1.ValidFix, {
42
+ sourceFilePath: sourceCodePath,
43
+ inputSpecCode: llmRes,
44
+ specFilePath: targetSpecPath.replace(targetFileName, `tmp.${targetFileName}`),
45
+ });
46
+ if (testRes.status === 'valid') {
47
+ this.progress({ message: 'Merging test file successful' });
48
+ fs_1.default.writeFileSync(targetSpecPath, llmRes, 'utf-8');
49
+ (0, system_1.removeFile)(sourceSpecPath);
50
+ return { success: true };
51
+ }
52
+ this.progress({
53
+ message: `Merging \`${specRelativePath} into ${targetFileRelativePath} failed`,
54
+ extra: {
55
+ title: 'Test error',
56
+ content: JSON.stringify(testRes.failedCases, null, 2),
57
+ }
58
+ });
59
+ return { success: false };
60
+ }
61
+ }
62
+ exports.MergeUTFile = MergeUTFile;
63
+ //# sourceMappingURL=mergeUTFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeUTFile.js","sourceRoot":"","sources":["../../../src/core/features/mergeUTFile.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,wCAA4C;AAC5C,wCAAuE;AACvE,gCAAiE;AACj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AAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,mBAAQ,EAAE;YAC5C,cAAc,EAAE,cAAc;YAC9B,aAAa,EAAE,MAAM;YACrB,YAAY,EAAE,cAAc,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,cAAc,EAAE,CAAC;SAChF,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC,CAAC;YAC3D,YAAE,CAAC,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAClD,IAAA,mBAAU,EAAC,cAAc,CAAC,CAAC;YAC3B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC;YACV,OAAO,EAAE,aAAa,gBAAgB,SAAS,sBAAsB,SAAS;YAC9E,KAAK,EAAE;gBACH,KAAK,EAAE,YAAY;gBACnB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;aACxD;SACJ,CAAC,CAAC;QACH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC;CACJ;AAlDD,kCAkDC"}
@@ -0,0 +1,23 @@
1
+ import { FeatureBase } from "./common/base";
2
+ import { FailedCaseDetails, TestOutput } from "../valid/type";
3
+ export interface RemoveFailedCasesParams {
4
+ inputSpecCode: string;
5
+ targetName: string;
6
+ inputFailedCases: FailedCaseDetails[];
7
+ sourceFilePath: string;
8
+ specFilePath?: string;
9
+ projectFolder?: string;
10
+ }
11
+ export interface RemoveFailedCasesResult {
12
+ code: string;
13
+ status: 'success' | 'failed' | 'error';
14
+ message?: string;
15
+ testResult?: TestOutput;
16
+ failedCases?: FailedCaseDetails[];
17
+ }
18
+ export declare class RemoveFailedCases extends FeatureBase<RemoveFailedCasesParams, RemoveFailedCasesResult> {
19
+ #private;
20
+ protected task(): Promise<RemoveFailedCasesResult>;
21
+ private validSpecCode;
22
+ }
23
+ //# sourceMappingURL=removeFailedCases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeFailedCases.d.ts","sourceRoot":"","sources":["../../../src/core/features/removeFailedCases.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK9D,MAAM,WAAW,uBAAuB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,iBAAiB,EAAE,CAAC;IACtC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,WAAW,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACrC;AAED,qBAAa,iBAAkB,SAAQ,WAAW,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;;cAKhF,IAAI,IAAI,OAAO,CAAC,uBAAuB,CAAC;YA4C1C,aAAa;CA6B9B"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RemoveFailedCases = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const base_1 = require("./common/base");
10
+ const valid_1 = require("../valid");
11
+ const system_1 = require("../utils/system");
12
+ const remove_1 = require("../valid/remove");
13
+ const config_1 = require("../config");
14
+ class RemoveFailedCases extends base_1.FeatureBase {
15
+ #sourceDir;
16
+ #pureFileName;
17
+ #fileSuffix;
18
+ async task() {
19
+ const { inputSpecCode, targetName, inputFailedCases, sourceFilePath, specFilePath } = this.params;
20
+ this.#sourceDir = path_1.default.dirname(sourceFilePath);
21
+ this.#fileSuffix = path_1.default.extname(sourceFilePath);
22
+ this.#pureFileName = path_1.default.basename(sourceFilePath, this.#fileSuffix);
23
+ let testCode = inputSpecCode;
24
+ let failedCases = inputFailedCases;
25
+ let retry = 0;
26
+ let success = false;
27
+ const maxRetry = 5;
28
+ this.progress({ message: `Starting to remove failed cases for ${targetName}` });
29
+ while (failedCases.length && retry < maxRetry) {
30
+ ++retry;
31
+ this.progress({ message: `Remove attempt ${retry}/${maxRetry}` });
32
+ const targets = new Set(failedCases.map(({ casePath }) => casePath));
33
+ if (failedCases.length) {
34
+ testCode = (0, remove_1.removeTestCases)(testCode, targets, {
35
+ deleteFailed: (0, config_1.getConfig)().common.removeFailedCases
36
+ });
37
+ }
38
+ const testResult = await this.validSpecCode(testCode, specFilePath, targetName);
39
+ if (testResult.success) {
40
+ success = true;
41
+ this.progress({ message: `Successfully removed failed cases` });
42
+ break;
43
+ }
44
+ const failedData = (0, valid_1.getFailedCase)(testResult, specFilePath ? path_1.default.basename(specFilePath) : `${targetName}.spec${this.#fileSuffix}`);
45
+ failedCases = failedData.cases;
46
+ }
47
+ return {
48
+ code: testCode,
49
+ status: success ? 'success' : 'failed',
50
+ failedCases: success ? [] : failedCases
51
+ };
52
+ }
53
+ async validSpecCode(testCode, expectedSpecFilePath, targetName) {
54
+ let isTmpFile = false;
55
+ let specPath = expectedSpecFilePath;
56
+ try {
57
+ // for new spec file and not saved yet, use tmp file
58
+ if (!specPath || !fs_1.default.existsSync(specPath)) {
59
+ isTmpFile = true;
60
+ const dir = path_1.default.dirname(expectedSpecFilePath || this.#sourceDir);
61
+ if (!fs_1.default.existsSync(dir)) {
62
+ fs_1.default.mkdirSync(dir, { recursive: true });
63
+ }
64
+ specPath = path_1.default.join(dir, `${this.#pureFileName}.${targetName}.tmp.spec${this.#fileSuffix}`);
65
+ fs_1.default.writeFileSync(specPath, testCode, 'utf-8');
66
+ }
67
+ const testResult = await (0, valid_1.runTest)(this.testFramework, specPath, {
68
+ projectFolder: this.params.projectFolder,
69
+ abortSignal: this.taskOptions.abortSignal,
70
+ });
71
+ return testResult;
72
+ }
73
+ finally {
74
+ if (isTmpFile) {
75
+ (0, system_1.removeFile)(specPath);
76
+ }
77
+ }
78
+ }
79
+ }
80
+ exports.RemoveFailedCases = RemoveFailedCases;
81
+ //# sourceMappingURL=removeFailedCases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeFailedCases.js","sourceRoot":"","sources":["../../../src/core/features/removeFailedCases.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,wCAA4C;AAC5C,oCAAkD;AAElD,4CAA6C;AAC7C,4CAAkD;AAClD,sCAAsC;AAmBtC,MAAa,iBAAkB,SAAQ,kBAA6D;IAChG,UAAU,CAAS;IACnB,aAAa,CAAS;IACtB,WAAW,CAAS;IAEV,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QAClG,IAAI,CAAC,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAChD,IAAI,CAAC,aAAa,GAAG,cAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAErE,IAAI,QAAQ,GAAG,aAAa,CAAC;QAC7B,IAAI,WAAW,GAAG,gBAAgB,CAAC;QACnC,IAAI,KA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I,SAAS,EAAE,CAAC;gBACZ,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC;YACzB,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AA9ED,8CA8EC"}
@@ -0,0 +1,20 @@
1
+ import { FeatureBase } from "./common/base";
2
+ import { UTGenerateResult } from "./common/types";
3
+ export interface UpdateSpecParams {
4
+ sourceCodeFilePath: string;
5
+ sourceCode: string;
6
+ specFilePath: string;
7
+ maxSpecCodeLength?: number;
8
+ testBlockStartLines?: number[];
9
+ }
10
+ export interface UpdateSpecResult {
11
+ code: string;
12
+ status: UTGenerateResult;
13
+ }
14
+ export declare class UpdateSpec extends FeatureBase<UpdateSpecParams, UpdateSpecResult> {
15
+ #private;
16
+ protected task(): Promise<UpdateSpecResult>;
17
+ private fixSpecFile;
18
+ private fixSpecBlock;
19
+ }
20
+ //# sourceMappingURL=updateSpec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateSpec.d.ts","sourceRoot":"","sources":["../../../src/core/features/updateSpec.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKlD,MAAM,WAAW,gBAAgB;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IAErB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,gBAAgB,CAAC;CAC5B;AAID,qBAAa,UAAW,SAAQ,WAAW,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;;cAI3D,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC;YAcnC,WAAW;YAmBX,YAAY;CAwD7B"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UpdateSpec = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const base_1 = require("./common/base");
10
+ const types_1 = require("./common/types");
11
+ const specBlock_1 = require("../utils/specBlock");
12
+ const common_1 = require("../utils/common");
13
+ const EMPTY_FLAG = 'NO_NEED_TO_CHANGE';
14
+ class UpdateSpec extends base_1.FeatureBase {
15
+ #sourceFileName;
16
+ #specRelativePath;
17
+ async task() {
18
+ const specCode = fs_1.default.readFileSync(this.params.specFilePath, 'utf-8');
19
+ this.#sourceFileName = path_1.default.basename(this.params.sourceCodeFilePath);
20
+ this.#specRelativePath = path_1.default.relative(this.params.sourceCodeFilePath, this.params.specFilePath);
21
+ const isTooLong = specCode.length > (this.params.maxSpecCodeLength || 40000);
22
+ let newSpecCode = await (isTooLong ? this.fixSpecBlock(this.params.specFilePath) : this.fixSpecFile(specCode));
23
+ return {
24
+ code: newSpecCode,
25
+ status: newSpecCode ? types_1.UTGenerateResult.Success : types_1.UTGenerateResult.Skipped,
26
+ };
27
+ }
28
+ async fixSpecFile(oldSpecCode) {
29
+ const messages = this.getPrompt("UpdateSpecFile" /* PromptKey.UpdateSpecFile */, {
30
+ ["<<<SourceFileName>>>" /* PromptPlaceholder.SourceFileName */]: this.#sourceFileName,
31
+ ["<<<SourceCode>>>" /* PromptPlaceholder.SourceCode */]: this.params.sourceCode,
32
+ ["<<<SpecFileName>>>" /* PromptPlaceholder.SpecFileName */]: this.#specRelativePath,
33
+ ["<<<Spec>>>" /* PromptPlaceholder.SpecCode */]: oldSpecCode,
34
+ ["<<<Language>>>" /* PromptPlaceholder.Language */]: (0, common_1.getLanguage)(this.#sourceFileName),
35
+ });
36
+ this.progress({ message: 'Generating code...' });
37
+ const newSpecCode = await this.getCodeFromLLM(messages, EMPTY_FLAG);
38
+ if (!newSpecCode) {
39
+ this.progress({ message: 'No need to update.', finish: 1 });
40
+ return;
41
+ }
42
+ return newSpecCode;
43
+ }
44
+ async fixSpecBlock(specPath) {
45
+ if (!this.params.testBlockStartLines?.length) {
46
+ this.progress({ message: 'Spec file is too large, cannot update, please provide test block start lines' });
47
+ return;
48
+ }
49
+ this.progress({ message: 'File is too large, splitting into blocks...' });
50
+ const { imports, blocks, updateBlocks } = (0, specBlock_1.getSpecBlocks)(specPath, this.params.testBlockStartLines);
51
+ this.progress({ message: `Found ${blocks.length} related blocks` });
52
+ const newContent = [];
53
+ let updateCount = 0;
54
+ const importStats = imports.join('\n');
55
+ for (const block of blocks) {
56
+ try {
57
+ this.progress({ message: `Generating code for ${block.type}("${block.name}")` });
58
+ const testDeps = block.mocks.concat(block.lifecycles).join('\n');
59
+ const codeExt = [importStats, testDeps].filter(el => !!el.trim()).join('\n');
60
+ const messages = this.getPrompt("UpdateSpecBlock" /* PromptKey.UpdateSpecBlock */, {
61
+ ["<<<SourceFileName>>>" /* PromptPlaceholder.SourceFileName */]: this.#sourceFileName,
62
+ ["<<<SourceCode>>>" /* PromptPlaceholder.SourceCode */]: this.params.sourceCode,
63
+ ["<<<SpecFileName>>>" /* PromptPlaceholder.SpecFileName */]: this.#specRelativePath,
64
+ ["<<<Spec>>>" /* PromptPlaceholder.SpecCode */]: block.body,
65
+ ["<<<CodeExtInfo>>>" /* PromptPlaceholder.CodeExtInfo */]: codeExt,
66
+ ["<<<Language>>>" /* PromptPlaceholder.Language */]: (0, common_1.getLanguage)(this.#sourceFileName),
67
+ });
68
+ const newSpecCode = await this.getCodeFromLLM(messages, EMPTY_FLAG);
69
+ if (!newSpecCode) {
70
+ this.progress({ message: 'No need to update' });
71
+ }
72
+ else {
73
+ updateCount++;
74
+ }
75
+ newContent.push(newSpecCode || block.body);
76
+ }
77
+ catch (error) {
78
+ this.progress({
79
+ message: `Error in generating code: ${error.message}`,
80
+ failed: true,
81
+ lastFailed: true,
82
+ extra: {
83
+ title: 'Failed to update spec block',
84
+ content: JSON.stringify(error, null, 2)
85
+ }
86
+ });
87
+ }
88
+ }
89
+ if (!updateCount) {
90
+ this.progress({ message: `No block updated` });
91
+ return;
92
+ }
93
+ this.progress({ message: `Updating ${this.#specRelativePath} with ${updateCount} blocks` });
94
+ return updateBlocks(newContent);
95
+ }
96
+ }
97
+ exports.UpdateSpec = UpdateSpec;
98
+ //# sourceMappingURL=updateSpec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateSpec.js","sourceRoot":"","sources":["../../../src/core/features/updateSpec.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,wCAA4C;AAC5C,0CAAkD;AAElD,kDAAmD;AACnD,4CAA8C;AAgB9C,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAEvC,MAAa,UAAW,SAAQ,kBAA+C;IAC3E,eAAe,CAAS;IACxB,iBAAiB,CAAS;IAEhB,KAAK,CAAC,IAAI;QAChB,MAAM,QAAQ,GAAG,YAAE,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAEpE,IAAI,CAAC,eAAe,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACrE,IAAI,CAAC,iBAAiB,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAEjG,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,KAAK,CAAC,CAAC;QAC7E,IAAI,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IA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;gBAEpE,IAAI,CAAC,WAAW,EAAE,CAAC;oBACf,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC,CAAC;gBACpD,CAAC;qBAAM,CAAC;oBACJ,WAAW,EAAE,CAAC;gBAClB,CAAC;gBACD,UAAU,CAAC,IAAI,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/C,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC,QAAQ,CAAC;oBACV,OAAO,EAAE,6BAA6B,KAAK,CAAC,OAAO,EAAE;oBACrD,MAAM,EAAE,IAAI;oBACZ,UAAU,EAAE,IAAI;oBAChB,KAAK,EAAE;wBACH,KAAK,EAAE,6BAA6B;wBACpC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;qBAC1C;iBACJ,CAAC,CAAC;YACP,CAAC;QACL,CAAC;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC,CAAC;YAC/C,OAAO;QACX,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,iBAAiB,SAAS,WAAW,SAAS,EAAE,CAAC,CAAC;QAC5F,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;CACJ;AA7FD,gCA6FC"}
@@ -0,0 +1,29 @@
1
+ import { FailedCaseDetails, TestOutput } from "../valid/type";
2
+ import { FeatureBase } from "./common/base";
3
+ export interface ValidFixParams {
4
+ targetName?: string;
5
+ sourceFilePath: string;
6
+ targetSourceCode?: string;
7
+ sourceMockCode?: string;
8
+ inputSpecCode?: string;
9
+ specFilePath?: string;
10
+ projectFolder?: string;
11
+ testFileSpecifier?: string;
12
+ maxRetry?: number;
13
+ }
14
+ export interface ValidFixResult {
15
+ code: string;
16
+ status: 'valid' | 'failed' | 'error';
17
+ message?: string;
18
+ testResult?: TestOutput;
19
+ failedCases?: FailedCaseDetails[];
20
+ isDataErrorOnly?: boolean;
21
+ }
22
+ export declare class ValidFix extends FeatureBase<ValidFixParams, ValidFixResult> {
23
+ #private;
24
+ protected task(): Promise<ValidFixResult>;
25
+ private validSpecCode;
26
+ private fixSpecCodeWithRetry;
27
+ private fixSpecCode;
28
+ }
29
+ //# sourceMappingURL=validFix.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validFix.d.ts","sourceRoot":"","sources":["../../../src/core/features/validFix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,MAAM,WAAW,cAAc;IAE3B,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,cAAc,EAAE,MAAM,CAAC;IAEvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,WAAW,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAClC,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,qBAAa,QAAS,SAAQ,WAAW,CAAC,cAAc,EAAE,cAAc,CAAC;;cAKrD,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC;YAqDjC,aAAa;YAuDb,oBAAoB;YA4DpB,WAAW;CAmD5B"}
@@ -0,0 +1,219 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ValidFix = void 0;
7
+ const valid_1 = require("../valid");
8
+ const base_1 = require("./common/base");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const common_1 = require("../utils/common");
11
+ const deps_1 = require("../utils/deps");
12
+ const tsMorph_1 = require("../utils/tsMorph");
13
+ const path_1 = __importDefault(require("path"));
14
+ const analyze_1 = require("../analyze");
15
+ const system_1 = require("../utils/system");
16
+ const move_1 = require("../utils/move");
17
+ class ValidFix extends base_1.FeatureBase {
18
+ #sourceDir;
19
+ #pureFileName;
20
+ #fileSuffix;
21
+ async task() {
22
+ const { inputSpecCode, sourceFilePath, specFilePath } = this.params;
23
+ this.#sourceDir = path_1.default.dirname(sourceFilePath);
24
+ this.#fileSuffix = path_1.default.extname(sourceFilePath);
25
+ this.#pureFileName = path_1.default.basename(sourceFilePath, this.#fileSuffix);
26
+ let specCode = inputSpecCode;
27
+ if (!specCode) {
28
+ if (!specFilePath) {
29
+ this.progress({ message: `No spec file found`, failed: true });
30
+ return {
31
+ code: '',
32
+ status: 'error',
33
+ message: `No spec file found`,
34
+ };
35
+ }
36
+ if (!fs_1.default.existsSync(specFilePath)) {
37
+ this.progress({ message: `Spec file not found`, failed: true });
38
+ return {
39
+ code: '',
40
+ status: 'error',
41
+ message: `Spec file not exists: ${specFilePath}`,
42
+ };
43
+ }
44
+ specCode = fs_1.default.readFileSync(specFilePath, 'utf-8');
45
+ }
46
+ const res = await this.validSpecCode(specCode, specFilePath);
47
+ const testResult = res.testResult;
48
+ let failedCases = res.failedCases;
49
+ let isDataErrorOnly = res.isDataErrorOnly;
50
+ if (testResult.success) {
51
+ return {
52
+ code: specCode,
53
+ status: 'valid',
54
+ };
55
+ }
56
+ if (!failedCases) {
57
+ const failedData = (0, valid_1.getFailedCase)(testResult, specFilePath ? path_1.default.basename(specFilePath) : undefined);
58
+ failedCases = failedData.cases;
59
+ isDataErrorOnly = failedData.isDataErrorOnly;
60
+ }
61
+ this.progress({ message: `Generate fix code` });
62
+ const result = await this.fixSpecCodeWithRetry(specCode, failedCases, isDataErrorOnly);
63
+ if (!result.testResult.success) {
64
+ this.progress({ message: `Test validation failed`, failed: true });
65
+ }
66
+ return result;
67
+ }
68
+ async validSpecCode(testCode, expectedSpecFilePath) {
69
+ let isTmpFile = false;
70
+ let specPath = expectedSpecFilePath;
71
+ try {
72
+ // for new spec file and not saved yet, use tmp file
73
+ if (!specPath || !fs_1.default.existsSync(specPath)) {
74
+ const { targetName } = this.params;
75
+ isTmpFile = true;
76
+ const dir = path_1.default.dirname(expectedSpecFilePath || this.#sourceDir);
77
+ if (!fs_1.default.existsSync(dir)) {
78
+ fs_1.default.mkdirSync(dir, { recursive: true });
79
+ }
80
+ const specName = `tmp.${this.#pureFileName}${targetName ? '.' + targetName : ''}.${this.params.testFileSpecifier}${this.#fileSuffix}`;
81
+ specPath = path_1.default.join(dir, specName);
82
+ // if test code and source code are in different dirs, adjust the import path
83
+ const testFileDir = path_1.default.dirname(specPath);
84
+ let finalCode = testCode;
85
+ finalCode = await (0, move_1.updateCodeReferences)(this.#sourceDir, testFileDir, specName, finalCode);
86
+ fs_1.default.writeFileSync(specPath, finalCode, 'utf-8');
87
+ }
88
+ this.progress({ message: 'Running test' });
89
+ const testResult = await (0, valid_1.runTest)(this.testFramework, specPath, {
90
+ projectFolder: this.params.projectFolder,
91
+ abortSignal: this.taskOptions.abortSignal,
92
+ });
93
+ if (testResult?.success) {
94
+ this.progress({ message: `All tests passed` });
95
+ }
96
+ else {
97
+ this.progress({ message: `Some tests failed` });
98
+ }
99
+ const specFileName = path_1.default.basename(specPath);
100
+ const failedData = testResult.success
101
+ ? {
102
+ cases: [],
103
+ isDataErrorOnly: false,
104
+ }
105
+ : (0, valid_1.getFailedCase)(testResult, path_1.default.basename(specFileName));
106
+ return {
107
+ failedCases: failedData.cases,
108
+ isDataErrorOnly: failedData.isDataErrorOnly || false,
109
+ testResult,
110
+ };
111
+ }
112
+ finally {
113
+ if (isTmpFile) {
114
+ (0, system_1.removeFile)(specPath);
115
+ }
116
+ }
117
+ }
118
+ async fixSpecCodeWithRetry(testCode, initialFailedCases, isDataErrorOnly) {
119
+ const maxRetry = this.params.maxRetry || 3;
120
+ let currentTestCode = testCode;
121
+ let currentFailedCases = initialFailedCases;
122
+ let currentIsDataErrorOnly = isDataErrorOnly;
123
+ for (let i = 0; i < maxRetry; i++) {
124
+ this.progress({
125
+ message: `(${i + 1}/${maxRetry}) Generating fix code`
126
+ });
127
+ const fixedCode = await this.fixSpecCode(currentTestCode, currentFailedCases, currentIsDataErrorOnly);
128
+ this.progress({ message: 'Start to run test' });
129
+ // Test the fixed code
130
+ const validRes = await this.validSpecCode(fixedCode, this.params.specFilePath);
131
+ if (validRes.testResult.success) {
132
+ this.progress({ message: `Fix successful after ${i + 1} attempts` });
133
+ return {
134
+ code: fixedCode,
135
+ status: 'valid',
136
+ testResult: validRes.testResult,
137
+ failedCases: validRes.failedCases,
138
+ isDataErrorOnly: validRes.isDataErrorOnly,
139
+ };
140
+ }
141
+ // If this is the last retry, return the result even if tests failed
142
+ if (i === maxRetry - 1) {
143
+ return {
144
+ code: fixedCode,
145
+ status: 'failed',
146
+ testResult: validRes.testResult,
147
+ failedCases: validRes.failedCases,
148
+ isDataErrorOnly: validRes.isDataErrorOnly,
149
+ };
150
+ }
151
+ // Prepare for next iteration
152
+ currentTestCode = fixedCode;
153
+ if (validRes.failedCases && validRes.failedCases.length > 0) {
154
+ currentFailedCases = validRes.failedCases;
155
+ const failedData = (0, valid_1.getFailedCase)(validRes.testResult, this.params.specFilePath ? path_1.default.basename(this.params.specFilePath) : undefined);
156
+ currentIsDataErrorOnly = failedData.isDataErrorOnly;
157
+ this.progress({
158
+ message: `(${i + 1}/${maxRetry}) Fix failed, retrying with ${currentFailedCases.length} failed cases`,
159
+ lastFailed: true
160
+ });
161
+ }
162
+ else {
163
+ // No specific failed cases found, but test still failed
164
+ this.progress({
165
+ message: `(${i + 1}/${maxRetry}) Fix failed with unknown errors, retrying`,
166
+ lastFailed: true
167
+ });
168
+ }
169
+ }
170
+ }
171
+ async fixSpecCode(testCode, cases, isDataErrorOnly) {
172
+ let repairPrompt;
173
+ if (isDataErrorOnly) {
174
+ repairPrompt = this.getPrompt("FixTestDataErrors" /* PromptKey.FixTestDataErrors */, {
175
+ ["<<<Spec>>>" /* PromptPlaceholder.SpecCode */]: testCode,
176
+ ["<<<TestErrors>>>" /* PromptPlaceholder.TestErrors */]: JSON.stringify((0, valid_1.getDataErrors)(testCode, cases)),
177
+ ["<<<Language>>>" /* PromptPlaceholder.Language */]: (0, common_1.getLanguage)(this.#fileSuffix),
178
+ ["<<<TestFramework>>>" /* PromptPlaceholder.TestFramework */]: this.testFramework,
179
+ });
180
+ }
181
+ else {
182
+ let { sourceFilePath, targetSourceCode, sourceMockCode, specFilePath, targetName } = this.params;
183
+ if (!targetSourceCode && sourceFilePath) {
184
+ if (targetName) {
185
+ const { project } = (0, tsMorph_1.getProject)(sourceFilePath);
186
+ const exportedList = await (0, analyze_1.read)(sourceFilePath, {
187
+ cachedProject: project
188
+ });
189
+ for (const data of exportedList) {
190
+ if (data.name === targetName) {
191
+ targetSourceCode = data.code;
192
+ sourceMockCode = (0, deps_1.getPackageMocks)(data.importDeclares);
193
+ break;
194
+ }
195
+ }
196
+ }
197
+ else {
198
+ targetSourceCode = fs_1.default.readFileSync(sourceFilePath, 'utf-8');
199
+ }
200
+ }
201
+ const specFileName = specFilePath
202
+ ? path_1.default.basename(specFilePath)
203
+ : `${this.#pureFileName}.spec${this.#fileSuffix}`;
204
+ repairPrompt = this.getPrompt("FixTestErrors" /* PromptKey.FixTestErrors */, {
205
+ ["<<<Spec>>>" /* PromptPlaceholder.SpecCode */]: testCode,
206
+ ["<<<SourceFileName>>>" /* PromptPlaceholder.SourceFileName */]: sourceFilePath,
207
+ ["<<<SpecFileName>>>" /* PromptPlaceholder.SpecFileName */]: specFileName,
208
+ ["<<<SourceCode>>>" /* PromptPlaceholder.SourceCode */]: targetSourceCode || '',
209
+ ["<<<MockCode>>>" /* PromptPlaceholder.MockCode */]: sourceMockCode || '',
210
+ ["<<<TestErrors>>>" /* PromptPlaceholder.TestErrors */]: JSON.stringify(cases),
211
+ ["<<<Language>>>" /* PromptPlaceholder.Language */]: (0, common_1.getLanguage)(this.#fileSuffix),
212
+ ["<<<TestFramework>>>" /* PromptPlaceholder.TestFramework */]: this.testFramework,
213
+ });
214
+ }
215
+ return await this.getCodeFromLLM(repairPrompt);
216
+ }
217
+ }
218
+ exports.ValidFix = ValidFix;
219
+ //# sourceMappingURL=validFix.js.map