@ai-dev-tools/csharp-copilot-core 0.0.33 → 0.0.34

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 (69) hide show
  1. package/out/batch/generateCodeTests.js +22 -6
  2. package/out/batch/generateCodeTests.js.map +1 -1
  3. package/out/changedFilesProcessor/processChangedFiles.d.ts +9 -0
  4. package/out/changedFilesProcessor/processChangedFiles.js +156 -0
  5. package/out/changedFilesProcessor/processChangedFiles.js.map +1 -0
  6. package/out/codebk/prompts/buildAfGuidelines_20251226.liquid +15 -0
  7. package/out/codebk/prompts/general/generalUtGuidelines_20251226.liquid +16 -0
  8. package/out/codebk/prompts/xap/xapUtGuideline_20251225.liquid +37 -0
  9. package/out/codebk/prompts/xap/xapUtGuideline_20251226.liquid +49 -0
  10. package/out/command/index.js +32 -0
  11. package/out/command/index.js.map +1 -1
  12. package/out/command/utGenWrapper.js +85 -4
  13. package/out/command/utGenWrapper.js.map +1 -1
  14. package/out/gen/autoFix.d.ts +2 -2
  15. package/out/gen/autoFix.js +88 -31
  16. package/out/gen/autoFix.js.map +1 -1
  17. package/out/gen/csharpUtGen.d.ts +1 -1
  18. package/out/gen/csharpUtGen.js +16 -13
  19. package/out/gen/csharpUtGen.js.map +1 -1
  20. package/out/gen/ensureValidLLMResponse.d.ts +5 -1
  21. package/out/gen/ensureValidLLMResponse.js +15 -3
  22. package/out/gen/ensureValidLLMResponse.js.map +1 -1
  23. package/out/gen/postGen/postGenMoreUTProcess.d.ts +25 -0
  24. package/out/gen/postGen/postGenMoreUTProcess.js +502 -0
  25. package/out/gen/postGen/postGenMoreUTProcess.js.map +1 -0
  26. package/out/gen/postGen/postGenProcess.d.ts +1 -1
  27. package/out/gen/postGen/postGenProcess.js +7 -7
  28. package/out/gen/postGen/postGenProcess.js.map +1 -1
  29. package/out/gen/postGen/repairRequiredNameSpaces.d.ts +17 -0
  30. package/out/gen/postGen/repairRequiredNameSpaces.js +87 -20
  31. package/out/gen/postGen/repairRequiredNameSpaces.js.map +1 -1
  32. package/out/llm/preparePrompt.d.ts +2 -1
  33. package/out/llm/preparePrompt.js +38 -4
  34. package/out/llm/preparePrompt.js.map +1 -1
  35. package/out/llm/prompt/buildAfGuidelines.liquid +8 -8
  36. package/out/llm/prompt/general/generalUtGuidelines.liquid +3 -0
  37. package/out/llm/prompt/moreUT/generateMoreUTSourceCode.liquid +4 -0
  38. package/out/llm/prompt/moreUT/generateMoreUtAutoFix.liquid +45 -0
  39. package/out/llm/prompt/moreUT/generateMoreUtTemplate.liquid +115 -0
  40. package/out/llm/prompt/moreUT/generateMoreUtTestCode.liquid +5 -0
  41. package/out/llm/prompt/moreUT/utGenerationGuidelines.liquid +15 -0
  42. package/out/llm/prompt/xap/xapUtGuideline.liquid +66 -15
  43. package/out/types/changedFilesResult.d.ts +37 -0
  44. package/out/types/changedFilesResult.js +3 -0
  45. package/out/types/changedFilesResult.js.map +1 -0
  46. package/out/types/constants.d.ts +1 -0
  47. package/out/types/constants.js +2 -1
  48. package/out/types/constants.js.map +1 -1
  49. package/out/types/genResult.d.ts +1 -1
  50. package/out/types/genResult.js.map +1 -1
  51. package/out/utils/checkXapCode.d.ts +1 -1
  52. package/out/utils/checkXapCode.js +14 -2
  53. package/out/utils/checkXapCode.js.map +1 -1
  54. package/out/utils/fileUtils.d.ts +1 -0
  55. package/out/utils/fileUtils.js +13 -0
  56. package/out/utils/fileUtils.js.map +1 -1
  57. package/out/utils/getCodeStructurePath.d.ts +4 -0
  58. package/out/utils/getCodeStructurePath.js +30 -0
  59. package/out/utils/getCodeStructurePath.js.map +1 -1
  60. package/out/utils/getTestFile.d.ts +18 -8
  61. package/out/utils/getTestFile.js +734 -59
  62. package/out/utils/getTestFile.js.map +1 -1
  63. package/out/utils/removeFailedTestMethods.d.ts +8 -0
  64. package/out/utils/removeFailedTestMethods.js +363 -0
  65. package/out/utils/removeFailedTestMethods.js.map +1 -1
  66. package/out/utils/verifyGeneratedCode.d.ts +2 -0
  67. package/out/utils/verifyGeneratedCode.js +17 -0
  68. package/out/utils/verifyGeneratedCode.js.map +1 -0
  69. package/package.json +4 -3
@@ -3,22 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.postGenProcess = postGenProcess;
4
4
  const extractCodeFromResponse_1 = require("./extractCodeFromResponse");
5
5
  const removeSingleLines_1 = require("./removeSingleLines");
6
- const removeComments_1 = require("./removeComments");
7
6
  const repairRequiredNameSpaces_1 = require("./repairRequiredNameSpaces");
8
7
  const validateTestCode_1 = require("./validateTestCode");
9
- const addAiAnnotation_1 = require("./addAiAnnotation");
10
- function postGenProcess(generatedCode, testFramework, isXapCode) {
8
+ function postGenProcess(generatedCode, testFramework, isXapCode, sourceCode) {
11
9
  if (!isValidTestCode(generatedCode)) {
12
10
  return undefined;
13
11
  }
14
12
  let testCode = (0, extractCodeFromResponse_1.extractCodeFromResponse)(generatedCode);
15
- testCode = (0, removeComments_1.removeTestCodeComments)(testCode);
13
+ // testCode = removeTestCodeComments(testCode);
16
14
  testCode = (0, removeSingleLines_1.removeCSharpOnlyLines)(testCode);
17
15
  testCode = (0, repairRequiredNameSpaces_1.repairRequiredNameSpaces)(testCode, testFramework);
18
16
  if (isXapCode) {
19
17
  testCode = xapCodePostGenProcess(testCode);
20
18
  }
21
- testCode = (0, addAiAnnotation_1.addAiAnnotation)(testCode);
19
+ // Repair using aliases from source code if provided
20
+ if (sourceCode) {
21
+ testCode = (0, repairRequiredNameSpaces_1.repairUsingStatements)(testCode, sourceCode);
22
+ }
23
+ // testCode = addAiAnnotation(testCode);
22
24
  console.log(`Post generation process completed, code length: ${testCode.length}`);
23
25
  return testCode;
24
26
  }
@@ -34,6 +36,4 @@ function isValidTestCode(testCode) {
34
36
  const isValid = (0, validateTestCode_1.validateTestCode)(testCode);
35
37
  return isValid;
36
38
  }
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
39
  //# sourceMappingURL=postGenProcess.js.map
@@ -1 +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"]}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gB,EAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import { extractCodeFromResponse } from \"./extractCodeFromResponse\";\r\nimport { removeCSharpOnlyLines } from \"./removeSingleLines\";\r\nimport { repairRequiredNameSpaces, repairXapRequiredNameSpaces, repairUsingStatements } from \"./repairRequiredNameSpaces\";\r\nimport { validateTestCode } from \"./validateTestCode\";\r\n\r\nexport function postGenProcess(generatedCode: string, testFramework: string, isXapCode: boolean, sourceCode?: string): 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 // Repair using aliases from source code if provided\r\n if (sourceCode) {\r\n testCode = repairUsingStatements(testCode, sourceCode);\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"]}
@@ -1,2 +1,19 @@
1
+ export declare const XAP_REQUIRED_USINGS: string[];
1
2
  export declare function repairRequiredNameSpaces(code: string, testFramework: string): string;
2
3
  export declare function repairXapRequiredNameSpaces(code: string): string;
4
+ /**
5
+ * Detect the using statement insertion position and indentation in the code.
6
+ * Returns the insert index and the indentation string.
7
+ */
8
+ export declare function detectUsingInsertPosition(lines: string[]): {
9
+ insertIndex: number;
10
+ indent: string;
11
+ };
12
+ /**
13
+ * Extract using Statements from source code and add them to test code if the alias is used.
14
+ * Handles patterns like: using Partner = Partnerhub.PDP.Partner;
15
+ * @param testCode The generated test code
16
+ * @param sourceCode The original source code
17
+ * @returns The test code with missing using aliases added
18
+ */
19
+ export declare function repairUsingStatements(testCode: string, sourceCode: string): string;
@@ -1,9 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XAP_REQUIRED_USINGS = void 0;
3
4
  exports.repairRequiredNameSpaces = repairRequiredNameSpaces;
4
5
  exports.repairXapRequiredNameSpaces = repairXapRequiredNameSpaces;
6
+ exports.detectUsingInsertPosition = detectUsingInsertPosition;
7
+ exports.repairUsingStatements = repairUsingStatements;
5
8
  const constants_1 = require("../../types/constants");
6
9
  const constants_2 = require("../../types/constants");
10
+ exports.XAP_REQUIRED_USINGS = [
11
+ "using System;",
12
+ "using System.Threading.Tasks;",
13
+ "using System.Collections.Generic;",
14
+ "using Xap.ExecutionFramework;",
15
+ "using Xap.PluginFramework;",
16
+ ];
7
17
  function repairRequiredNameSpaces(code, testFramework) {
8
18
  const testFrameworkUsing = getTestFrameworkNameSpaces(testFramework);
9
19
  const requiredUsings = [
@@ -13,39 +23,50 @@ function repairRequiredNameSpaces(code, testFramework) {
13
23
  return code;
14
24
  }
15
25
  function repairXapRequiredNameSpaces(code) {
16
- const xapUsings = [
17
- "using System;",
18
- "using System.Threading.Tasks;",
19
- "using System.Collections.Generic;",
20
- "using Xap.ExecutionFramework;",
21
- "using Xap.PluginFramework;",
22
- "using EMPTY = Microsoft.Bing.Xap.Plugins.Void;",
23
- ];
24
- code = repairMissingUsings(code, xapUsings);
26
+ const requiredUsings = [...exports.XAP_REQUIRED_USINGS];
27
+ // Only add XapBondRelatedNamespace if code contains XapBlob (case-sensitive)
28
+ if (code.includes('XapBlob')) {
29
+ requiredUsings.push(constants_1.XapBondRelatedNamespace);
30
+ }
31
+ code = repairMissingUsings(code, requiredUsings);
25
32
  return code;
26
33
  }
34
+ /**
35
+ * Detect the using statement insertion position and indentation in the code.
36
+ * Returns the insert index and the indentation string.
37
+ */
38
+ function detectUsingInsertPosition(lines) {
39
+ const firstUsingIndex = lines.findIndex(line => line.trim().startsWith('using '));
40
+ if (firstUsingIndex !== -1) {
41
+ // There are existing using statements - insert before the first one and use its indentation
42
+ const match = lines[firstUsingIndex].match(/^(\s*)/);
43
+ const indent = match ? match[1] : '';
44
+ return { insertIndex: firstUsingIndex, indent };
45
+ }
46
+ else {
47
+ // No using statements found - insert at the beginning (before namespace or at top)
48
+ const namespaceIndex = lines.findIndex(line => line.trim().startsWith('namespace '));
49
+ const insertIndex = namespaceIndex !== -1 ? namespaceIndex : 0;
50
+ return { insertIndex, indent: '' };
51
+ }
52
+ }
27
53
  function repairMissingUsings(code, requiredUsings) {
28
- // get all using lines
54
+ // get all using lines (trimmed to compare)
29
55
  const usingRegex = /^\s*using\s+[^\r\n;]+;/gm;
30
56
  const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());
31
57
  const missingUsings = requiredUsings.filter(req => !existingUsings.includes(req));
32
58
  if (missingUsings.length === 0) {
33
59
  return code;
34
60
  }
35
- // find the end of the using block: the first non-using line, or the end of the file
36
61
  const lines = code.split(constants_2.LINESEPARATOR);
37
- let insertIndex = 0;
38
- for (let i = 0; i < lines.length; i++) {
39
- if (!lines[i].trim().startsWith("using") && lines[i].trim() !== "") {
40
- insertIndex = i;
41
- break;
42
- }
43
- insertIndex = i + 1;
44
- }
62
+ // Use the common function to detect insert position and indentation
63
+ const { insertIndex, indent } = detectUsingInsertPosition(lines);
64
+ // Apply indentation to missing usings
65
+ const indentedMissingUsings = missingUsings.map(u => indent + u);
45
66
  // build new code
46
67
  const newLines = [
47
68
  ...lines.slice(0, insertIndex),
48
- ...missingUsings,
69
+ ...indentedMissingUsings,
49
70
  ...lines.slice(insertIndex)
50
71
  ];
51
72
  console.log("repaired namespaces:", missingUsings);
@@ -63,6 +84,52 @@ function getTestFrameworkNameSpaces(testFramework) {
63
84
  };
64
85
  return FRAMEWORK_USINGS[testFramework] || msTestUsing;
65
86
  }
87
+ /**
88
+ * Extract using Statements from source code and add them to test code if the alias is used.
89
+ * Handles patterns like: using Partner = Partnerhub.PDP.Partner;
90
+ * @param testCode The generated test code
91
+ * @param sourceCode The original source code
92
+ * @returns The test code with missing using aliases added
93
+ */
94
+ function repairUsingStatements(testCode, sourceCode) {
95
+ if (!sourceCode || !testCode) {
96
+ return testCode;
97
+ }
98
+ // Extract using aliases from source code
99
+ // Pattern: using AliasName = Namespace.Type;
100
+ const usingAliasRegex = /^\s*using\s+(\w+)\s*=\s*([^;]+);/gm;
101
+ const sourceAliases = new Map();
102
+ let match;
103
+ while ((match = usingAliasRegex.exec(sourceCode)) !== null) {
104
+ const aliasName = match[1];
105
+ const fullStatement = match[0].trim();
106
+ sourceAliases.set(aliasName, fullStatement);
107
+ }
108
+ if (sourceAliases.size === 0) {
109
+ return testCode;
110
+ }
111
+ // Check which aliases are used in test code but not defined
112
+ const missingAliases = [];
113
+ const existingUsings = testCode.match(/^\s*using\s+.+;/gm) || [];
114
+ const existingUsingsTrimmed = existingUsings.map(u => u.trim());
115
+ for (const [aliasName, fullStatement] of sourceAliases) {
116
+ // Check if alias is used in test code (as a type name, using word boundary)
117
+ const aliasUsagePattern = new RegExp(`\\b${aliasName}\\b`);
118
+ if (aliasUsagePattern.test(testCode)) {
119
+ // Check if the using alias is already in test code
120
+ if (!existingUsingsTrimmed.includes(fullStatement)) {
121
+ missingAliases.push(fullStatement);
122
+ }
123
+ }
124
+ }
125
+ if (missingAliases.length === 0) {
126
+ return testCode;
127
+ }
128
+ // Add missing aliases
129
+ const result = repairMissingUsings(testCode, missingAliases);
130
+ console.log("repaired using aliases:", missingAliases);
131
+ return result;
132
+ }
66
133
  // const code = `
67
134
  // using Microsoft.VisualStudio.TestTools.UnitTesting;
68
135
  // using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;
@@ -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F;AACpF,IAAI;AACJ,kBAAkB;AAClB,oCAAoC;AACpC,QAAQ;AACR,uBAAuB;AACvB,uFAAuF;AACvF,YAAY;AACZ,yBAAyB;AACzB,2DAA2D;AAC3D,gBAAgB;AAChB,mHAAmH;AACnH,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,wDAAwD;AACxD,YAAY;AAEZ,uBAAuB;AACvB,iFAAiF;AACjF,YAAY;AACZ,yBAAyB;AACzB,2DAA2D;AAC3D,gBAAgB;AAChB,qDAAqD;AACrD,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qCAAqC;AACrC,YAAY;AAEZ,uBAAuB;AACvB,2EAA2E;AAC3E,YAAY;AACZ,yBAAyB;AACzB,8DAA8D;AAE9D,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AAEZ,uBAAuB;AACvB,0EAA0E;AAC1E,YAAY;AACZ,yBAAyB;AACzB,0DAA0D;AAE1D,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AAEZ,uBAAuB;AACvB,mFAAmF;AACnF,YAAY;AACZ,yBAAyB;AACzB,2DAA2D;AAC3D,gBAAgB;AAChB,mCAAmC;AACnC,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AACZ,QAAQ;AACR,IAAI;AACJ,KAAK;AAEL,sDAAsD;AACtD,4BAA4B","sourcesContent":["import { MSTESTFRAMEWORK, NUNITTESTFRAMEWORK, XUNITTESTFRAMEWORK } from '../../types/constants';\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport { LINESEPARATOR } from '../../types/constants';\r\n\r\nexport function repairRequiredNameSpaces(code: string, testFramework: string): string {\r\n const testFrameworkUsing = getTestFrameworkNameSpaces(testFramework);\r\n const requiredUsings = [\r\n testFrameworkUsing,\r\n ];\r\n\r\n code = repairMissingUsings(code, requiredUsings);\r\n return code;\r\n}\r\n\r\nexport function repairXapRequiredNameSpaces(code: string): string {\r\n const xapUsings = [\r\n \"using System;\",\r\n \"using System.Threading.Tasks;\",\r\n \"using System.Collections.Generic;\",\r\n \"using Xap.ExecutionFramework;\",\r\n \"using Xap.PluginFramework;\",\r\n \"using EMPTY = Microsoft.Bing.Xap.Plugins.Void;\",\r\n ];\r\n\r\n code = repairMissingUsings(code, xapUsings);\r\n return code;\r\n}\r\n\r\nfunction repairMissingUsings(code: string, requiredUsings: string[]): string {\r\n // get all using lines\r\n const usingRegex = /^\\s*using\\s+[^\\r\\n;]+;/gm;\r\n const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());\r\n\r\n const missingUsings = requiredUsings.filter(req => !existingUsings.includes(req));\r\n\r\n if (missingUsings.length === 0) {\r\n return code;\r\n }\r\n\r\n // find the end of the using block: the first non-using line, or the end of the file\r\n const lines = code.split(LINESEPARATOR);\r\n let insertIndex = 0;\r\n\r\n for (let i = 0; i < lines.length; i++) {\r\n if (!lines[i].trim().startsWith(\"using\") && lines[i].trim() !== \"\") {\r\n insertIndex = i;\r\n break;\r\n }\r\n insertIndex = i + 1;\r\n }\r\n\r\n // build new code\r\n const newLines = [\r\n ...lines.slice(0, insertIndex),\r\n ...missingUsings,\r\n ...lines.slice(insertIndex)\r\n ];\r\n\r\n console.log(\"repaired namespaces:\", missingUsings);\r\n\r\n return newLines.join('\\n');\r\n}\r\n\r\nfunction getTestFrameworkNameSpaces(testFramework: string): string {\r\n const msTestUsing = \"using Microsoft.VisualStudio.TestTools.UnitTesting;\";\r\n\r\n if (!testFramework) {\r\n return msTestUsing;\r\n }\r\n\r\n const FRAMEWORK_USINGS = {\r\n [MSTESTFRAMEWORK]: msTestUsing,\r\n [NUNITTESTFRAMEWORK]: \"using NUnit.Framework;\",\r\n [XUNITTESTFRAMEWORK]: \"using Xunit;\"\r\n } as const;\r\n\r\n return FRAMEWORK_USINGS[testFramework] || msTestUsing;\r\n}\r\n\r\n\r\n\r\n// const code = `\r\n// using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\r\n// using System;\r\n// using System.Collections.Generic;\r\n// using System.Text;\r\n// using Moq;\r\n\r\n// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils\r\n// {\r\n// [TestClass]\r\n// public class SqmidHelperTests\r\n// {\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"BID=\" + Convert.ToBase64String(Encoding.UTF8.GetBytes(\"test_decodedBlisId_test\")) }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(\"decodedBlisId\", result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"SomeOtherValue=123\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.IsNull(result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>();\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// IDictionary<string, string> cookies = null;\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n// }\r\n// }\r\n// `;\r\n\r\n// const cleanedCode = repairRequiredNameSpaces(code);\r\n// console.log(cleanedCode);"]}
1
+ {"version":3,"file":"repairRequiredNameSpaces.js","sourceRoot":"","sources":["../../../src/gen/postGen/repairRequiredNameSpaces.ts"],"names":[],"mappings":";;;AAaA,4DAQC;AAED,kEAQC;AAMD,8DAcC;AAwDD,sDA6CC;AAxJD,qDAAyH;AAGzH,qDAAsD;AAEzC,QAAA,mBAAmB,GAAG;IAC/B,eAAe;IACf,+BAA+B;IAC/B,mCAAmC;IACnC,+BAA+B;IAC/B,4BAA4B;CAC/B,CAAC;AAEF,SAAgB,wBAAwB,CAAC,IAAY,EAAE,aAAqB;IACxE,MAAM,kBAAkB,GAAG,0BAA0B,CAAC,aAAa,CAAC,CAAC;IACrE,MAAM,cAAc,GAAG;QACnB,kBAAkB;KACrB,CAAC;IAEF,IAAI,GAAG,mBAAmB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,2BAA2B,CAAC,IAAY;IACpD,MAAM,cAAc,GAAG,CAAC,GAAG,2BAAmB,CAAC,CAAC;IAChD,6EAA6E;IAC7E,IAAI,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,cAAc,CAAC,IAAI,CAAC,mCAAuB,CAAC,CAAC;IACjD,CAAC;IACD,IAAI,GAAG,mBAAmB,CA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mCAAmC;AACnC,iBAAiB;AAEjB,qBAAqB;AACrB,oEAAoE;AAEpE,wBAAwB;AACxB,qDAAqD;AACrD,YAAY;AACZ,QAAQ;AACR,IAAI;AACJ,KAAK;AAEL,sDAAsD;AACtD,4BAA4B","sourcesContent":["import { MSTESTFRAMEWORK, NUNITTESTFRAMEWORK, XUNITTESTFRAMEWORK, XapBondRelatedNamespace } from '../../types/constants';\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport { LINESEPARATOR } from '../../types/constants';\r\n\r\nexport const XAP_REQUIRED_USINGS = [\r\n \"using System;\",\r\n \"using System.Threading.Tasks;\",\r\n \"using System.Collections.Generic;\",\r\n \"using Xap.ExecutionFramework;\",\r\n \"using Xap.PluginFramework;\",\r\n];\r\n\r\nexport function repairRequiredNameSpaces(code: string, testFramework: string): string {\r\n const testFrameworkUsing = getTestFrameworkNameSpaces(testFramework);\r\n const requiredUsings = [\r\n testFrameworkUsing,\r\n ];\r\n\r\n code = repairMissingUsings(code, requiredUsings);\r\n return code;\r\n}\r\n\r\nexport function repairXapRequiredNameSpaces(code: string): string {\r\n const requiredUsings = [...XAP_REQUIRED_USINGS];\r\n // Only add XapBondRelatedNamespace if code contains XapBlob (case-sensitive)\r\n if (code.includes('XapBlob')) {\r\n requiredUsings.push(XapBondRelatedNamespace);\r\n }\r\n code = repairMissingUsings(code, requiredUsings);\r\n return code;\r\n}\r\n\r\n/**\r\n * Detect the using statement insertion position and indentation in the code.\r\n * Returns the insert index and the indentation string.\r\n */\r\nexport function detectUsingInsertPosition(lines: string[]): { insertIndex: number, indent: string } {\r\n const firstUsingIndex = lines.findIndex(line => line.trim().startsWith('using '));\r\n \r\n if (firstUsingIndex !== -1) {\r\n // There are existing using statements - insert before the first one and use its indentation\r\n const match = lines[firstUsingIndex].match(/^(\\s*)/);\r\n const indent = match ? match[1] : '';\r\n return { insertIndex: firstUsingIndex, indent };\r\n } else {\r\n // No using statements found - insert at the beginning (before namespace or at top)\r\n const namespaceIndex = lines.findIndex(line => line.trim().startsWith('namespace '));\r\n const insertIndex = namespaceIndex !== -1 ? namespaceIndex : 0;\r\n return { insertIndex, indent: '' };\r\n }\r\n}\r\n\r\nfunction repairMissingUsings(code: string, requiredUsings: string[]): string {\r\n // get all using lines (trimmed to compare)\r\n const usingRegex = /^\\s*using\\s+[^\\r\\n;]+;/gm;\r\n const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());\r\n\r\n const missingUsings = requiredUsings.filter(req => !existingUsings.includes(req));\r\n\r\n if (missingUsings.length === 0) {\r\n return code;\r\n }\r\n\r\n const lines = code.split(LINESEPARATOR);\r\n \r\n // Use the common function to detect insert position and indentation\r\n const { insertIndex, indent } = detectUsingInsertPosition(lines);\r\n \r\n // Apply indentation to missing usings\r\n const indentedMissingUsings = missingUsings.map(u => indent + u);\r\n\r\n // build new code\r\n const newLines = [\r\n ...lines.slice(0, insertIndex),\r\n ...indentedMissingUsings,\r\n ...lines.slice(insertIndex)\r\n ];\r\n\r\n console.log(\"repaired namespaces:\", missingUsings);\r\n\r\n return newLines.join('\\n');\r\n}\r\n\r\nfunction getTestFrameworkNameSpaces(testFramework: string): string {\r\n const msTestUsing = \"using Microsoft.VisualStudio.TestTools.UnitTesting;\";\r\n\r\n if (!testFramework) {\r\n return msTestUsing;\r\n }\r\n\r\n const FRAMEWORK_USINGS = {\r\n [MSTESTFRAMEWORK]: msTestUsing,\r\n [NUNITTESTFRAMEWORK]: \"using NUnit.Framework;\",\r\n [XUNITTESTFRAMEWORK]: \"using Xunit;\"\r\n } as const;\r\n\r\n return FRAMEWORK_USINGS[testFramework] || msTestUsing;\r\n}\r\n\r\n/**\r\n * Extract using Statements from source code and add them to test code if the alias is used.\r\n * Handles patterns like: using Partner = Partnerhub.PDP.Partner;\r\n * @param testCode The generated test code\r\n * @param sourceCode The original source code\r\n * @returns The test code with missing using aliases added\r\n */\r\nexport function repairUsingStatements(testCode: string, sourceCode: string): string {\r\n if (!sourceCode || !testCode) {\r\n return testCode;\r\n }\r\n\r\n // Extract using aliases from source code\r\n // Pattern: using AliasName = Namespace.Type;\r\n const usingAliasRegex = /^\\s*using\\s+(\\w+)\\s*=\\s*([^;]+);/gm;\r\n const sourceAliases: Map<string, string> = new Map();\r\n \r\n let match;\r\n while ((match = usingAliasRegex.exec(sourceCode)) !== null) {\r\n const aliasName = match[1];\r\n const fullStatement = match[0].trim();\r\n sourceAliases.set(aliasName, fullStatement);\r\n }\r\n\r\n if (sourceAliases.size === 0) {\r\n return testCode;\r\n }\r\n\r\n // Check which aliases are used in test code but not defined\r\n const missingAliases: string[] = [];\r\n const existingUsings = testCode.match(/^\\s*using\\s+.+;/gm) || [];\r\n const existingUsingsTrimmed = existingUsings.map(u => u.trim());\r\n\r\n for (const [aliasName, fullStatement] of sourceAliases) {\r\n // Check if alias is used in test code (as a type name, using word boundary)\r\n const aliasUsagePattern = new RegExp(`\\\\b${aliasName}\\\\b`);\r\n if (aliasUsagePattern.test(testCode)) {\r\n // Check if the using alias is already in test code\r\n if (!existingUsingsTrimmed.includes(fullStatement)) {\r\n missingAliases.push(fullStatement);\r\n }\r\n }\r\n }\r\n\r\n if (missingAliases.length === 0) {\r\n return testCode;\r\n }\r\n\r\n // Add missing aliases\r\n const result = repairMissingUsings(testCode, missingAliases);\r\n console.log(\"repaired using aliases:\", missingAliases);\r\n return result;\r\n}\r\n\r\n\r\n\r\n// const code = `\r\n// using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\r\n// using System;\r\n// using System.Collections.Generic;\r\n// using System.Text;\r\n// using Moq;\r\n\r\n// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils\r\n// {\r\n// [TestClass]\r\n// public class SqmidHelperTests\r\n// {\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"BID=\" + Convert.ToBase64String(Encoding.UTF8.GetBytes(\"test_decodedBlisId_test\")) }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(\"decodedBlisId\", result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"SomeOtherValue=123\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.IsNull(result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>();\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// IDictionary<string, string> cookies = null;\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n// }\r\n// }\r\n// `;\r\n\r\n// const cleanedCode = repairRequiredNameSpaces(code);\r\n// console.log(cleanedCode);"]}
@@ -1,2 +1,3 @@
1
- export declare function prepareUtGenPrompt(sourceCodePath: string, sourceCode: string, dependency: string, isXapTest: boolean, testFramework: string): any[];
1
+ export declare function prepareUtGenPrompt(sourceCodePath: string, sourceCode: string, dependency: string, isXapTest: boolean, testFramework: string, testFileExist: boolean, testFilePath?: string): any[];
2
2
  export declare function prepareUtAutoFixPrompt(prompts: any[], testCode: string, verifyError: string, isBuildFailure: boolean): any[];
3
+ export declare function prepareMoreUtAutoFixPrompt(sourceCode: string, dependency: string, testCode: string, verifyError: string, isBuildFailure: boolean, isXapTest: boolean): any[];
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.prepareUtGenPrompt = prepareUtGenPrompt;
37
37
  exports.prepareUtAutoFixPrompt = prepareUtAutoFixPrompt;
38
+ exports.prepareMoreUtAutoFixPrompt = prepareMoreUtAutoFixPrompt;
38
39
  const fs = __importStar(require("fs"));
39
40
  const path = __importStar(require("path"));
40
41
  const util = __importStar(require("util"));
@@ -44,10 +45,10 @@ const liquid = new liquidjs_1.Liquid({
44
45
  root: path.resolve(__dirname, 'prompt'), // Set root to current directory
45
46
  extname: '.liquid' // Treat included files as Markdown
46
47
  });
47
- function prepareUtGenPrompt(sourceCodePath, sourceCode, dependency, isXapTest, testFramework) {
48
+ function prepareUtGenPrompt(sourceCodePath, sourceCode, dependency, isXapTest, testFramework, testFileExist, testFilePath) {
48
49
  const prompts = [];
49
50
  // prepare system prompt
50
- const systemPrompt = prepareUtGenSystemPrompt(isXapTest, testFramework);
51
+ const systemPrompt = prepareUtGenSystemPrompt(isXapTest, testFramework, testFileExist);
51
52
  prompts.push(systemPrompt);
52
53
  // prepare user prompt
53
54
  const userPrompt = prepareUserInputPrompt(sourceCode, sourceCodePath, dependency);
@@ -57,6 +58,11 @@ function prepareUtGenPrompt(sourceCodePath, sourceCode, dependency, isXapTest, t
57
58
  const codeDependencyPrompt = prepareCodeDenpendencyPrompt(sourceCode, dependency);
58
59
  prompts.push({ role: 'user', content: codeDependencyPrompt });
59
60
  }
61
+ // prepare test code prompt when test file exists
62
+ if (testFileExist && testFilePath) {
63
+ const testCodePrompt = prepareOriginalTestCodePrompt(testFilePath);
64
+ prompts.push({ role: 'user', content: testCodePrompt });
65
+ }
60
66
  return prompts;
61
67
  }
62
68
  function prepareUserInputPrompt(sourceCode, sourceCodePath, dependency) {
@@ -77,6 +83,13 @@ function prepareCodeDenpendencyPrompt(sourceCode, dependency) {
77
83
  const dependencyPrompt = liquid.parseAndRenderSync(dependencyPromptTemplate, { dependency });
78
84
  return dependencyPrompt;
79
85
  }
86
+ function prepareOriginalTestCodePrompt(testFilePath) {
87
+ const testCode = fs.readFileSync(testFilePath, 'utf8');
88
+ const testCodePromptPath = path.join(__dirname, 'prompt', 'moreUT', 'generateMoreUtTestCode.liquid');
89
+ const testCodePromptTemplate = fs.readFileSync(testCodePromptPath, 'utf8');
90
+ const testCodePrompt = liquid.parseAndRenderSync(testCodePromptTemplate, { testCode });
91
+ return testCodePrompt;
92
+ }
80
93
  function prepareUtAutoFixPrompt(prompts, testCode, verifyError, isBuildFailure) {
81
94
  // const prompts = [];
82
95
  // prepare system prompt
@@ -91,8 +104,29 @@ function prepareUtAutoFixPrompt(prompts, testCode, verifyError, isBuildFailure)
91
104
  autofixPrompts.push({ role: 'user', content: autofixPrompt });
92
105
  return autofixPrompts;
93
106
  }
94
- function prepareUtGenSystemPrompt(isXapTest, testFramework) {
95
- const systemPrompt = composeSystemPromptTemplate('generateUtTemplate.liquid', isXapTest, testFramework);
107
+ function prepareMoreUtAutoFixPrompt(sourceCode, dependency, testCode, verifyError, isBuildFailure, isXapTest) {
108
+ const prompts = [];
109
+ // prepare autofix prompt as system prompt
110
+ const autofixPromptPath = path.join(__dirname, 'prompt', 'moreUT', 'generateMoreUtAutoFix.liquid');
111
+ const systemPromptTemplate = fs.readFileSync(autofixPromptPath, 'utf8');
112
+ const renderedSystemPrompt = liquid.parseAndRenderSync(systemPromptTemplate, { isBuildFailure, isXapCode: isXapTest });
113
+ const systemPrompt = util.format(renderedSystemPrompt, testCode, verifyError);
114
+ prompts.push({ role: 'system', content: systemPrompt });
115
+ // prepare user input prompt (source code)
116
+ const sourceCodePromptPath = path.join(__dirname, 'prompt', 'moreUT', 'generateMoreUTSourceCode.liquid');
117
+ const sourceCodePromptTemplate = fs.readFileSync(sourceCodePromptPath, 'utf8');
118
+ const userPrompt = liquid.parseAndRenderSync(sourceCodePromptTemplate, { sourceCode });
119
+ prompts.push({ role: 'user', content: userPrompt });
120
+ // prepare code dependency prompt
121
+ if (!!dependency) {
122
+ const codeDependencyPrompt = prepareCodeDenpendencyPrompt(sourceCode, dependency);
123
+ prompts.push({ role: 'user', content: codeDependencyPrompt });
124
+ }
125
+ return prompts;
126
+ }
127
+ function prepareUtGenSystemPrompt(isXapTest, testFramework, testFileExist) {
128
+ const template = testFileExist ? 'moreUT/generateMoreUtTemplate.liquid' : 'generateUtTemplate.liquid';
129
+ const systemPrompt = composeSystemPromptTemplate(template, isXapTest, testFramework);
96
130
  return { role: 'system', content: systemPrompt };
97
131
  }
98
132
  function composeSystemPromptTemplate(template, isXapTest, testFramework) {
@@ -1 +1 @@
1
- {"version":3,"file":"preparePrompt.js","sourceRoot":"","sources":["../../src/llm/preparePrompt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,gDAiBC;AAwBD,wDAeC;AArED,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA6B;AAE7B,uCAAkC;AAGlC,2BAA2B;AAC3B,MAAM,MAAM,GAAG,IAAI,iBAAM,CAAC;IACzB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,gCAAgC;IACzE,OAAO,EAAE,SAAS,CAAC,mCAAmC;CACtD,CAAC,CAAC;AAEH,SAAgB,kBAAkB,CAAC,cAAsB,EAAE,UAAkB,EAAE,UAAkB,EAAE,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AAsB;IACtB,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAChE,MAAM,iBAAiB,GAAG,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;IAEnE,mDAAmD;IACnD,MAAM,eAAe,GAAG,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;IAEnG,OAAO,eAAe,CAAC;AACxB,CAAC;AAED,6EAA6E;AAC7E,2EAA2E;AAE3E,gGAAgG;AAChG,+FAA+F;AAG/F,uEAAuE;AACvE,4DAA4D;AAC5D,mFAAmF;AACnF,qEAAqE;AACrE,wBAAwB;AAExB,eAAe;AACf,mCAAmC;AACnC,+TAA+T;AAC/T,gBAAgB;AAChB,YAAY;AACZ,8BAA8B;AAC9B,47GAA47G;AAC57G,uCAAuC;AACvC,aAAa;AACb,YAAY;AACZ,8BAA8B;AAC9B,kGAAkG;AAClG,aAAa;AACb,eAAe;AACf,iCAAiC;AACjC,yGAAyG;AACzG,eAAe;AACf,SAAS;AACT,sBAAsB;AACtB,IAAI","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\nimport * as util from 'util';\r\n\r\nimport { Liquid } from 'liquidjs';\r\nimport { getTestCodeNamespace } from '../utils/getTestCodeInfo';\r\n\r\n// Initialize Liquid engine\r\nconst liquid = new Liquid({\r\n\troot: path.resolve(__dirname, 'prompt'), // Set root to current directory\r\n\textname: '.liquid' // Treat included files as Markdown\r\n});\r\n\r\nexport function prepareUtGenPrompt(sourceCodePath: string, sourceCode: string, dependency: string, isXapTest: boolean, testFramework: string): any[] {\r\n\tconst prompts = [];\r\n\t// prepare system prompt\r\n\tconst systemPrompt = prepareUtGenSystemPrompt(isXapTest, testFramework);\r\n\tprompts.push(systemPrompt);\r\n\r\n\t// prepare user prompt\r\n\tconst userPrompt = prepareUserInputPrompt(sourceCode, sourceCodePath, dependency);\r\n\tprompts.push({ role: 'user', content: userPrompt });\r\n\r\n\t// prepare code dependency prompt\r\n\tif (!!dependency) {\r\n\t\tconst codeDependencyPrompt = prepareCodeDenpendencyPrompt(sourceCode, dependency);\r\n\t\tprompts.push({ role: 'user', content: codeDependencyPrompt });\r\n\t}\r\n\r\n\treturn prompts;\r\n}\r\n\r\nfunction prepareUserInputPrompt(sourceCode: string, sourceCodePath: string, dependency: string): string {\r\n\t// prepare user prompt\r\n\t// const userPromptPath = path.join(__dirname, 'prompt', 'generateUtUserInput.liquid');\r\n\t// const userPromptTemplate = fs.readFileSync(userPromptPath, 'utf8');\r\n\t// const namespace = getTestCodeNamespace(sourceCodePath);\r\n\t// const userPrompt = liquid.parseAndRenderSync(userPromptTemplate, { namespace, sourceCode, dependency });\r\n\t// return userPrompt;\r\n\r\n\tconst userPromptPath = path.join(__dirname, 'prompt', 'generateUtUserInput.liquid');\r\n\tconst userPromptTemplate = fs.readFileSync(userPromptPath, 'utf8');\r\n\tconst userPrompt = liquid.parseAndRenderSync(userPromptTemplate, { sourceCode });\r\n\r\n\treturn userPrompt;\r\n}\r\n\r\nfunction prepareCodeDenpendencyPrompt(sourceCode: string, dependency: string): string {\r\n\tconst dependencyPromptPath = path.join(__dirname, 'prompt', 'generateUtDependency.liquid');\r\n\tconst dependencyPromptTemplate = fs.readFileSync(dependencyPromptPath, 'utf8');\r\n\tconst dependencyPrompt = liquid.parseAndRenderSync(dependencyPromptTemplate, { dependency });\r\n\treturn dependencyPrompt;\r\n}\r\n\r\nexport function prepareUtAutoFixPrompt(prompts: any[], testCode: string, verifyError: string, isBuildFailure: boolean) {\r\n\t// const prompts = [];\r\n\t// prepare system prompt\r\n\t// const systemPrompt = prepareUtGenSystemPrompt(isXapTest);\r\n\t// prompts.push(systemPrompt);\r\n\tconst autofixPrompts = prompts || [];\r\n\r\n\t// prepare autofix prompt\r\n\tconst autofixPromptPath = path.join(__dirname, 'prompt', 'generateUtAutoFix.liquid');\r\n\tconst userPromptTemplate = fs.readFileSync(autofixPromptPath, 'utf8');\r\n\tconst renderedTemplate = liquid.parseAndRenderSync(userPromptTemplate, { isBuildFailure });\r\n\tconst autofixPrompt = util.format(renderedTemplate, testCode, verifyError);\r\n\tautofixPrompts.push({ role: 'user', content: autofixPrompt });\r\n\r\n\treturn autofixPrompts;\r\n}\r\n\r\nfunction prepareUtGenSystemPrompt(isXapTest: boolean, testFramework: string) {\r\n\tconst systemPrompt = composeSystemPromptTemplate('generateUtTemplate.liquid', isXapTest, testFramework);\r\n\treturn { role: 'system', content: systemPrompt };\r\n}\r\n\r\nfunction composeSystemPromptTemplate(template: string, isXapTest: boolean, testFramework: string) {\r\n\t// get prompt template\r\n\tconst promptTemplate = path.join(__dirname, 'prompt', template);\r\n\tconst mainPromptContent = fs.readFileSync(promptTemplate, 'utf-8');\r\n\r\n\t// render Liquid template(handle {% include %} tag)\r\n\tconst renderedContent = liquid.parseAndRenderSync(mainPromptContent, { isXapTest, testFramework });\r\n\r\n\treturn renderedContent;\r\n}\r\n\r\n// prepareUtGenSystemPrompt(false, \"MSTest\"); // Initialize the system prompt\r\n// prepareUtGenSystemPrompt(true, \"XUnit\"); // Initialize the system prompt\r\n\r\n// prepareUtAutoFixPrompt(\"\", \"\", \"\", \"MSBuild Errors\", true); // Initialize the auto-fix prompt\r\n// prepareUtAutoFixPrompt(\"\", \"\", \"\", \"VSTest result\", true); // Initialize the auto-fix prompt\r\n\r\n\r\n// function getPrompts(sourceCodePath, testFramework, codeDependency) {\r\n// const code = fs.readFileSync(sourceCodePath, 'utf8');\r\n// let guidancePromt = fs.readFileSync(\"D:\\\\atmp\\\\promptiteration.md\", 'utf8');\r\n// guidancePromt = guidancePromt.replace(\"xUnit\", testFramework);\r\n// const prompts = [\r\n\r\n// // {\r\n// // \"role\": \"system\",\r\n// // \"content\": \"Keep your answers short and impersonal.\\nUse Markdown formatting in your answers.\\nMake sure to include the programming language name at the start of the Markdown code blocks.\\nAvoid wrapping the whole response in triple backticks.\\nYou can only give one reply for each conversation turn.\"\r\n// // },\r\n// {\r\n// \"role\": \"user\",\r\n// // \"content\": \"You are Roo, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.\\n\\n====\\n\\nRULES\\n\\n- MUST use xUnit test framework to generate test code.\\n- **MUST NOT** contain any comments or explanations in test code.\\n- Ensure the test code MUST has no syntax errors.\\n- Test public methods of class in source code only.\\n- **MUST NOT** access private members (fields or methods) of the source class in test code.\\n- Test method names must follow the pattern: [MethodName]_[Scenario]_[ExpectedResult].\\n- Return the test code in the format: ```C#\\n{Test code}\\n```.\\n- Mock all dependent methods, classes, and values not included in the user input using the Moq library.\\n- MUST include Test code in a namespace declaration and place all `using` statements above the namespace declaration.\\n- MUST import source code in the test code.\\n- MUST import all required .Net namespaces if any .Net class or interface are used in the test code. Like:\\n - .NET built-in types (e.g., `List<T>`, `IEnumerable<T>`, `Task`, `Assert`, `Moq.Mock`, etc.).\\n - Any attribute classes (e.g., `[TestMethod]`, `[TestClass]`, etc.).\\n - Any LINQ or threading related classes (e.g., `System.Linq`, `System.Threading.Tasks`).\\n- All assignments and method arguments in test code MUST strictly match the declared types.\\n- When generating code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.\\n- Do not ask for more information than necessary. Use your knowledge to accomplish the user's request efficiently and effectively.\\n- The user will provide the source code directly in their message.\\n- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.\\n\\n====\\n\\nOBJECTIVE\\n\\nYou accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.\\n\\n- **MUST** analyze the provided code and verify its logic by following these steps:\\n 1. Describe the functionality of each public method, including its inputs, outputs, and key logic.\\n 2. Identify all possible execution paths for public methods, including normal cases, edge cases, and error conditions.\\n 3. Explain any conditional branches, loops, or exception handling for public methods in the code.\\n 4. Based on this analysis, generate unit test cases that cover all identified execution paths, ensuring that mock data and assertions align with the code's logic.\\n- **MUST** remove all code analysis information in responsed test code.\\n- Absolutely forbidden to contains any other information in response except the test code.\\n- **MUST NOT** generate tests for the methods that are attributed with **[ExcludeFromCodeCoverage]**.\\n- **MUST NOT** generate tests for **private** methods.\\n- Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.\\n- Work through these goals sequentially, each goal should correspond to a distinct step in your problem-solving process.\\n\\n====\\n\\nUSER'S CUSTOM INSTRUCTIONS\\n\\nThe following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.\\n\\nLanguage Preference:\\nYou should always speak and think in the English language.\"\r\n// \"content\": guidancePromt\r\n// },\r\n// {\r\n// \"role\": \"user\",\r\n// \"content\": `generate unit test for the following csharp code:\\n\\`\\`\\`${code}\\`\\`\\``\r\n// },\r\n// // {\r\n// // \"role\": \"user\",\r\n// // \"content\": `following are the code dependencies of the source code:\\n${codeDependency}`\r\n// // }\r\n// ];\r\n// return prompts;\r\n// }\r\n"]}
1
+ {"version":3,"file":"preparePrompt.js","sourceRoot":"","sources":["../../src/llm/preparePrompt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,gDAuBC;AAgCD,wDAeC;AAED,gEA8BC;AAnHD,uCAAyB;AACzB,2CAA6B;AAC7B,2CAA6B;AAE7B,uCAAkC;AAGlC,2BAA2B;AAC3B,MAAM,MAAM,GAAG,IAAI,iBAAM,CAAC;IACzB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,gCAAgC;IACzE,OAAO,EAAE,SAAS,CAAC,mCAAmC;CACtD,CAAC,CAAC;AAEH,SAAgB,kBAAkB,CAAC,cAAsB,EAAE,UAAkB,EAAE,UAAkB,EAAE,SAAkB,EAAE,aAAqB,EAAE,aAAsB,EAAE,YAAqB;IAC1L,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,wBAAwB;IACxB,MAAM,YAAY,GAAG,wBAAwB,CAAC,SAAS,EAAE,aAAa,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AACf,mCAAmC;AACnC,+TAA+T;AAC/T,gBAAgB;AAChB,YAAY;AACZ,8BAA8B;AAC9B,47GAA47G;AAC57G,uCAAuC;AACvC,aAAa;AACb,YAAY;AACZ,8BAA8B;AAC9B,kGAAkG;AAClG,aAAa;AACb,eAAe;AACf,iCAAiC;AACjC,yGAAyG;AACzG,eAAe;AACf,SAAS;AACT,sBAAsB;AACtB,IAAI","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\nimport * as util from 'util';\r\n\r\nimport { Liquid } from 'liquidjs';\r\nimport { getTestCodeNamespace } from '../utils/getTestCodeInfo';\r\n\r\n// Initialize Liquid engine\r\nconst liquid = new Liquid({\r\n\troot: path.resolve(__dirname, 'prompt'), // Set root to current directory\r\n\textname: '.liquid' // Treat included files as Markdown\r\n});\r\n\r\nexport function prepareUtGenPrompt(sourceCodePath: string, sourceCode: string, dependency: string, isXapTest: boolean, testFramework: string, testFileExist: boolean, testFilePath?: string): any[] {\r\n\tconst prompts = [];\r\n\t// prepare system prompt\r\n\tconst systemPrompt = prepareUtGenSystemPrompt(isXapTest, testFramework, testFileExist);\r\n\tprompts.push(systemPrompt);\r\n\r\n\t// prepare user prompt\r\n\tconst userPrompt = prepareUserInputPrompt(sourceCode, sourceCodePath, dependency);\r\n\tprompts.push({ role: 'user', content: userPrompt });\r\n\r\n\t// prepare code dependency prompt\r\n\tif (!!dependency) {\r\n\t\tconst codeDependencyPrompt = prepareCodeDenpendencyPrompt(sourceCode, dependency);\r\n\t\tprompts.push({ role: 'user', content: codeDependencyPrompt });\r\n\t}\r\n\r\n\t// prepare test code prompt when test file exists\r\n\tif (testFileExist && testFilePath) {\r\n\t\tconst testCodePrompt = prepareOriginalTestCodePrompt(testFilePath);\r\n\t\tprompts.push({ role: 'user', content: testCodePrompt });\r\n\t}\r\n\r\n\treturn prompts;\r\n}\r\n\r\nfunction prepareUserInputPrompt(sourceCode: string, sourceCodePath: string, dependency: string): string {\r\n\t// prepare user prompt\r\n\t// const userPromptPath = path.join(__dirname, 'prompt', 'generateUtUserInput.liquid');\r\n\t// const userPromptTemplate = fs.readFileSync(userPromptPath, 'utf8');\r\n\t// const namespace = getTestCodeNamespace(sourceCodePath);\r\n\t// const userPrompt = liquid.parseAndRenderSync(userPromptTemplate, { namespace, sourceCode, dependency });\r\n\t// return userPrompt;\r\n\r\n\tconst userPromptPath = path.join(__dirname, 'prompt', 'generateUtUserInput.liquid');\r\n\tconst userPromptTemplate = fs.readFileSync(userPromptPath, 'utf8');\r\n\tconst userPrompt = liquid.parseAndRenderSync(userPromptTemplate, { sourceCode });\r\n\r\n\treturn userPrompt;\r\n}\r\n\r\nfunction prepareCodeDenpendencyPrompt(sourceCode: string, dependency: string): string {\r\n\tconst dependencyPromptPath = path.join(__dirname, 'prompt', 'generateUtDependency.liquid');\r\n\tconst dependencyPromptTemplate = fs.readFileSync(dependencyPromptPath, 'utf8');\r\n\tconst dependencyPrompt = liquid.parseAndRenderSync(dependencyPromptTemplate, { dependency });\r\n\treturn dependencyPrompt;\r\n}\r\n\r\nfunction prepareOriginalTestCodePrompt(testFilePath: string): string {\r\n\tconst testCode = fs.readFileSync(testFilePath, 'utf8');\r\n\tconst testCodePromptPath = path.join(__dirname, 'prompt', 'moreUT', 'generateMoreUtTestCode.liquid');\r\n\tconst testCodePromptTemplate = fs.readFileSync(testCodePromptPath, 'utf8');\r\n\tconst testCodePrompt = liquid.parseAndRenderSync(testCodePromptTemplate, { testCode });\r\n\treturn testCodePrompt;\r\n}\r\n\r\nexport function prepareUtAutoFixPrompt(prompts: any[], testCode: string, verifyError: string, isBuildFailure: boolean) {\r\n\t// const prompts = [];\r\n\t// prepare system prompt\r\n\t// const systemPrompt = prepareUtGenSystemPrompt(isXapTest);\r\n\t// prompts.push(systemPrompt);\r\n\tconst autofixPrompts = prompts || [];\r\n\r\n\t// prepare autofix prompt\r\n\tconst autofixPromptPath = path.join(__dirname, 'prompt', 'generateUtAutoFix.liquid');\r\n\tconst userPromptTemplate = fs.readFileSync(autofixPromptPath, 'utf8');\r\n\tconst renderedTemplate = liquid.parseAndRenderSync(userPromptTemplate, { isBuildFailure });\r\n\tconst autofixPrompt = util.format(renderedTemplate, testCode, verifyError);\r\n\tautofixPrompts.push({ role: 'user', content: autofixPrompt });\r\n\r\n\treturn autofixPrompts;\r\n}\r\n\r\nexport function prepareMoreUtAutoFixPrompt(\r\n\tsourceCode: string,\r\n\tdependency: string,\r\n\ttestCode: string,\r\n\tverifyError: string,\r\n\tisBuildFailure: boolean,\r\n\tisXapTest: boolean,\r\n): any[] {\r\n\tconst prompts: any[] = [];\r\n\r\n\t// prepare autofix prompt as system prompt\r\n\tconst autofixPromptPath = path.join(__dirname, 'prompt', 'moreUT', 'generateMoreUtAutoFix.liquid');\r\n\tconst systemPromptTemplate = fs.readFileSync(autofixPromptPath, 'utf8');\r\n\tconst renderedSystemPrompt = liquid.parseAndRenderSync(systemPromptTemplate, { isBuildFailure, isXapCode: isXapTest });\r\n\tconst systemPrompt = util.format(renderedSystemPrompt, testCode, verifyError);\r\n\tprompts.push({ role: 'system', content: systemPrompt });\r\n\r\n\t// prepare user input prompt (source code)\r\n\tconst sourceCodePromptPath = path.join(__dirname, 'prompt', 'moreUT', 'generateMoreUTSourceCode.liquid');\r\n\tconst sourceCodePromptTemplate = fs.readFileSync(sourceCodePromptPath, 'utf8');\r\n\tconst userPrompt = liquid.parseAndRenderSync(sourceCodePromptTemplate, { sourceCode });\r\n\tprompts.push({ role: 'user', content: userPrompt });\r\n\r\n\t// prepare code dependency prompt\r\n\tif (!!dependency) {\r\n\t\tconst codeDependencyPrompt = prepareCodeDenpendencyPrompt(sourceCode, dependency);\r\n\t\tprompts.push({ role: 'user', content: codeDependencyPrompt });\r\n\t}\r\n\r\n\treturn prompts;\r\n}\r\n\r\nfunction prepareUtGenSystemPrompt(isXapTest: boolean, testFramework: string, testFileExist: boolean) {\r\n\tconst template = testFileExist ? 'moreUT/generateMoreUtTemplate.liquid' : 'generateUtTemplate.liquid';\r\n\tconst systemPrompt = composeSystemPromptTemplate(template, isXapTest, testFramework);\r\n\treturn { role: 'system', content: systemPrompt };\r\n}\r\n\r\nfunction composeSystemPromptTemplate(template: string, isXapTest: boolean, testFramework: string) {\r\n\t// get prompt template\r\n\tconst promptTemplate = path.join(__dirname, 'prompt', template);\r\n\tconst mainPromptContent = fs.readFileSync(promptTemplate, 'utf-8');\r\n\r\n\t// render Liquid template(handle {% include %} tag)\r\n\tconst renderedContent = liquid.parseAndRenderSync(mainPromptContent, { isXapTest, testFramework });\r\n\r\n\treturn renderedContent;\r\n}\r\n\r\n// prepareUtGenSystemPrompt(false, \"MSTest\"); // Initialize the system prompt\r\n// prepareUtGenSystemPrompt(true, \"XUnit\"); // Initialize the system prompt\r\n\r\n// prepareUtAutoFixPrompt(\"\", \"\", \"\", \"MSBuild Errors\", true); // Initialize the auto-fix prompt\r\n// prepareUtAutoFixPrompt(\"\", \"\", \"\", \"VSTest result\", true); // Initialize the auto-fix prompt\r\n\r\n\r\n// function getPrompts(sourceCodePath, testFramework, codeDependency) {\r\n// const code = fs.readFileSync(sourceCodePath, 'utf8');\r\n// let guidancePromt = fs.readFileSync(\"D:\\\\atmp\\\\promptiteration.md\", 'utf8');\r\n// guidancePromt = guidancePromt.replace(\"xUnit\", testFramework);\r\n// const prompts = [\r\n\r\n// // {\r\n// // \"role\": \"system\",\r\n// // \"content\": \"Keep your answers short and impersonal.\\nUse Markdown formatting in your answers.\\nMake sure to include the programming language name at the start of the Markdown code blocks.\\nAvoid wrapping the whole response in triple backticks.\\nYou can only give one reply for each conversation turn.\"\r\n// // },\r\n// {\r\n// \"role\": \"user\",\r\n// // \"content\": \"You are Roo, a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.\\n\\n====\\n\\nRULES\\n\\n- MUST use xUnit test framework to generate test code.\\n- **MUST NOT** contain any comments or explanations in test code.\\n- Ensure the test code MUST has no syntax errors.\\n- Test public methods of class in source code only.\\n- **MUST NOT** access private members (fields or methods) of the source class in test code.\\n- Test method names must follow the pattern: [MethodName]_[Scenario]_[ExpectedResult].\\n- Return the test code in the format: ```C#\\n{Test code}\\n```.\\n- Mock all dependent methods, classes, and values not included in the user input using the Moq library.\\n- MUST include Test code in a namespace declaration and place all `using` statements above the namespace declaration.\\n- MUST import source code in the test code.\\n- MUST import all required .Net namespaces if any .Net class or interface are used in the test code. Like:\\n - .NET built-in types (e.g., `List<T>`, `IEnumerable<T>`, `Task`, `Assert`, `Moq.Mock`, etc.).\\n - Any attribute classes (e.g., `[TestMethod]`, `[TestClass]`, etc.).\\n - Any LINQ or threading related classes (e.g., `System.Linq`, `System.Threading.Tasks`).\\n- All assignments and method arguments in test code MUST strictly match the declared types.\\n- When generating code, always consider the context in which the code is being used. Ensure that your changes are compatible with the existing codebase and that they follow the project's coding standards and best practices.\\n- Do not ask for more information than necessary. Use your knowledge to accomplish the user's request efficiently and effectively.\\n- The user will provide the source code directly in their message.\\n- Your goal is to try to accomplish the user's task, NOT engage in a back and forth conversation.\\n\\n====\\n\\nOBJECTIVE\\n\\nYou accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.\\n\\n- **MUST** analyze the provided code and verify its logic by following these steps:\\n 1. Describe the functionality of each public method, including its inputs, outputs, and key logic.\\n 2. Identify all possible execution paths for public methods, including normal cases, edge cases, and error conditions.\\n 3. Explain any conditional branches, loops, or exception handling for public methods in the code.\\n 4. Based on this analysis, generate unit test cases that cover all identified execution paths, ensuring that mock data and assertions align with the code's logic.\\n- **MUST** remove all code analysis information in responsed test code.\\n- Absolutely forbidden to contains any other information in response except the test code.\\n- **MUST NOT** generate tests for the methods that are attributed with **[ExcludeFromCodeCoverage]**.\\n- **MUST NOT** generate tests for **private** methods.\\n- Analyze the user's task and set clear, achievable goals to accomplish it. Prioritize these goals in a logical order.\\n- Work through these goals sequentially, each goal should correspond to a distinct step in your problem-solving process.\\n\\n====\\n\\nUSER'S CUSTOM INSTRUCTIONS\\n\\nThe following additional instructions are provided by the user, and should be followed to the best of your ability without interfering with the TOOL USE guidelines.\\n\\nLanguage Preference:\\nYou should always speak and think in the English language.\"\r\n// \"content\": guidancePromt\r\n// },\r\n// {\r\n// \"role\": \"user\",\r\n// \"content\": `generate unit test for the following csharp code:\\n\\`\\`\\`${code}\\`\\`\\``\r\n// },\r\n// // {\r\n// // \"role\": \"user\",\r\n// // \"content\": `following are the code dependencies of the source code:\\n${codeDependency}`\r\n// // }\r\n// ];\r\n// return prompts;\r\n// }\r\n"]}
@@ -1,15 +1,15 @@
1
1
  # Build Failure Fix Guideline:
2
2
  - Case 1: The type or namespace name '{Class/Type}' does not exist in the namespace '{namespace}' (are you missing an assembly reference?)
3
3
  Solution: Check the source code, code dependencies. Add the required `using` statements or assembly references.
4
- - Case 2: No overload for method 'Execute' takes {number} arguments
5
- Solution: Refer to section [The method parameters of Execute in Xap instance are different from the source code.] of Xap Unit Test Guidelines, Adjust the method parameters to match the correct overload as per the source code.
6
- - Case 3: [CS0144] Cannot create an instance of the abstract type or interface '{class / bondstucture}'
4
+ - Case 2: [CS0144] Cannot create an instance of the abstract type or interface '{class / bondstucture}'
7
5
  Solution: use ExecutionServices.CreateInstance<I{ClassName}>() to create Xap class instance or use ExecutionServices.CreateInstance<{StructName}>() to create Bond struct instance.
8
- - Case 4: [CS1503] cannot convert from '{Class / Bond type}' to '{Class / Bond type}'
6
+ - Case 3: [CS1503] cannot convert from '{Class / Bond type}' to '{Class / Bond type}'
9
7
  Solution: Do explicitly type convert.
10
- - Case 5: [CS0037] Cannot convert null to '{Class / Bond type}' because it is a non-nullable value type
8
+ - Case 4: [CS0037] Cannot convert null to '{Class / Bond type}' because it is a non-nullable value type
11
9
  Solution: MUST assign non-null and valid value.
12
- - Case 6: [CS0246] The type or namespace name '{class / interface}' could not be found (are you missing a using directive or an assembly reference?)
10
+ - Case 5: [CS0246] The type or namespace name '{class / interface}' could not be found (are you missing a using directive or an assembly reference?)
13
11
  Solution: MUST import the **namespace** of {class / interface}
14
- - Case 7: [CS1501] No overload for method 'Execute' takes 2 arguments
15
- Solution: - The parameters of **Execute** method with types: **PluginServices**, **PluginOutput<T>**, or decorated with **[ConfigFile("{configFileName}")]** MUST be deleted when using Xap class instance to call it.
12
+ - Case 6: [CS1501] No overload for method 'Execute' takes {number} arguments
13
+ Solution: The parameters of **Execute** method with types: **PluginServices**, **PluginOutput<T>**, **CollectionPluginOutput<IEnumerable<T>>**, or decorated with **[ConfigFile("{configFileName}")]** MUST be deleted when using Xap class instance to call it.
14
+ - Case 7: [CA2000] Call System.IDisposable.Dispose on object created before all references to it are out of scope
15
+ Solution: Add "using" keyword before the variable declaration on that line, keep everything else unchanged.
@@ -2,11 +2,14 @@
2
2
 
3
3
  - MUST use {{testFramework}} test framework to generate tests.
4
4
  - **MUST NOT** contain any comments or explanations in test code.
5
+ - **MUST** preserve any copyright or file header information from the given source code.
5
6
  - Ensure the test code MUST has no syntax errors.
6
7
  - Test method names must follow the pattern: [MethodName]_[Scenario]_[ExpectedResult].
7
8
  - Return the test code in the format: ```C#\n{Test code}\n```.
8
9
  - MUST include Test code in a namespace declaration and place all `using` statements above the namespace declaration.
9
10
  - MUST import source code namespace in test code.
11
+ - MUST import all namespaces from source code that are used in test code (e.g., types used in method parameters, return values, or mock setups).
12
+ - MUST import all using aliases from source code that are used in test code. If source code contains `using Alias = SomeNamespace.SomeType;` and test code uses `Alias`, MUST include this using alias statement.
10
13
  - MUST import all required .Net namespaces if any .Net class or interface are used in the test code. Like:
11
14
  - .NET built-in types (e.g., `List<T>`, `IEnumerable<T>`, `Task`, `Assert`, `Moq.Mock`, etc.).
12
15
  - Any attribute classes (e.g., `[TestMethod]`, `[TestClass]`, etc.).
@@ -0,0 +1,4 @@
1
+ The source code to be tested:
2
+ ```csharp
3
+ {{ sourceCode }}
4
+ ```
@@ -0,0 +1,45 @@
1
+ {%- if isBuildFailure -%}
2
+ {%- assign failedStage = "MSBuild" -%}
3
+ {%- assign failedTitle = "MSBuild failure errors:" -%}
4
+ {%- else -%}
5
+ {%- assign failedStage = "vstest" -%}
6
+ {%- assign failedTitle = "vstest failure test errors:" -%}
7
+ {%- endif -%}
8
+
9
+ You are a highly skilled software engineer specializing in C# unit testing with extensive knowledge in test frameworks, test patterns, and best practices.
10
+
11
+ ## TASK
12
+ Fix the unit test code that failed to {{failedStage}}. The user will provide the source code and its dependencies.
13
+
14
+ ## RULES
15
+ - Return the **complete** fixed test file, not just the changed parts.
16
+ - **ONLY fix the test method(s) that contain the error line(s)**. Do NOT modify, refactor, or change any other test methods.
17
+ - Test methods that do NOT have errors must remain exactly unchanged - do not rename, restructure, or "improve" them.
18
+ - Only fix the errors mentioned in the error messages.
19
+ - **Keep existing comments unchanged**. Do NOT add new comments or explanations in the code.
20
+ - Ensure all `using` statements are at the top of the file.
21
+ - Ensure the code has no syntax errors.
22
+
23
+ The following are the guidelines used when generating the test code. You may refer to them when fixing the test code:
24
+
25
+ {%- include 'moreUT/utGenerationGuidelines' -%}
26
+
27
+ ## OUTPUT FORMAT
28
+ Return the fixed test code in the format:
29
+ ```C#
30
+ {Complete test code}
31
+ ```
32
+
33
+ ====
34
+
35
+ Current test code (needs fixing):
36
+ %s
37
+
38
+ ====
39
+
40
+ {{failedTitle}}:
41
+ %s
42
+
43
+ {% if isBuildFailure %}
44
+ {%- include 'buildAfGuidelines' -%}
45
+ {%- endif -%}