@ai-dev-tools/csharp-copilot-core 0.0.19 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReadMe.md +172 -0
- package/out/analyze/generateCodeDependency.d.ts +1 -1
- package/out/analyze/generateCodeDependency.js +7 -3
- package/out/analyze/generateCodeDependency.js.map +1 -1
- package/out/batch/getProjectCodeFile.js +1 -2
- package/out/batch/getProjectCodeFile.js.map +1 -1
- package/out/codeCoverage/codeCoverage.js +5 -1
- package/out/codeCoverage/codeCoverage.js.map +1 -1
- package/out/codeCoverage/codeCoverageReport.js +5 -1
- package/out/codeCoverage/codeCoverageReport.js.map +1 -1
- package/out/codeCoverage/extractCoverageReportPath.d.ts +1 -0
- package/out/codeCoverage/extractCoverageReportPath.js +24 -0
- package/out/codeCoverage/extractCoverageReportPath.js.map +1 -0
- package/out/codeCoverage/generateCodeCoverageReport.js +3 -0
- package/out/codeCoverage/generateCodeCoverageReport.js.map +1 -1
- package/out/codeCoverage/simplifyCoverageXml.js +2 -1
- package/out/codeCoverage/simplifyCoverageXml.js.map +1 -1
- package/out/command/index.js +11 -2
- package/out/command/index.js.map +1 -1
- package/out/command/utGenWrapper.d.ts +1 -0
- package/out/command/utGenWrapper.js +8 -2
- package/out/command/utGenWrapper.js.map +1 -1
- package/out/gen/autoFix.d.ts +3 -3
- package/out/gen/autoFix.js +8 -8
- package/out/gen/autoFix.js.map +1 -1
- package/out/gen/csharpUtGen.d.ts +1 -1
- package/out/gen/csharpUtGen.js +7 -33
- package/out/gen/csharpUtGen.js.map +1 -1
- package/out/gen/ensureValidLLMResponse.d.ts +1 -1
- package/out/gen/ensureValidLLMResponse.js +2 -2
- package/out/gen/ensureValidLLMResponse.js.map +1 -1
- package/out/gen/postGen/postGenProcess.d.ts +1 -1
- package/out/gen/postGen/postGenProcess.js +3 -2
- package/out/gen/postGen/postGenProcess.js.map +1 -1
- package/out/gen/postGen/repairRequiredNameSpaces.d.ts +2 -1
- package/out/gen/postGen/repairRequiredNameSpaces.js +29 -4
- package/out/gen/postGen/repairRequiredNameSpaces.js.map +1 -1
- package/out/index.d.ts +1 -0
- package/out/index.js +3 -1
- package/out/index.js.map +1 -1
- package/out/llm/model/{Gpt4o.js → Gpt.js} +5 -3
- package/out/llm/model/Gpt.js.map +1 -0
- package/out/llm/preparePrompt.js +26 -1
- package/out/llm/preparePrompt.js.map +1 -1
- package/out/llm/prompt/generateUtAutoFix.liquid +5 -1
- package/out/llm/prompt/generateUtTemplate.liquid +2 -0
- package/out/llm/sendRequestToLLM.js +0 -3
- package/out/llm/sendRequestToLLM.js.map +1 -1
- package/out/llm/sendRequestToSelfHostLLM.js +4 -4
- package/out/llm/sendRequestToSelfHostLLM.js.map +1 -1
- package/out/types/constants.d.ts +3 -0
- package/out/types/constants.js +4 -1
- package/out/types/constants.js.map +1 -1
- package/out/utils/detectTestFramework.js +7 -6
- package/out/utils/detectTestFramework.js.map +1 -1
- package/out/utils/getTestFile.js +1 -1
- package/out/utils/getTestFile.js.map +1 -1
- package/out/vs/msBuild.js +3 -35
- package/out/vs/msBuild.js.map +1 -1
- package/out/vs/vsTest.js +3 -35
- package/out/vs/vsTest.js.map +1 -1
- package/package.json +4 -3
- package/publish/package.json +37 -0
- package/ai-dev-tools-csharp-copilot-core-0.0.19.tgz +0 -0
- package/out/atmpCache/deps/EplantRequestCategoryCondition_Conditions_Eplant_Workflows_SharedSegmentsPlugins_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +0 -281
- package/out/atmpCache/deps/IdentitySelectAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +0 -1
- package/out/atmpCache/deps/SqmidHelperTests_Utils_HttpRequestParser_Overview_Workflows_SharedSegmentsTests_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +0 -1
- package/out/atmpCache/deps/SqmidHelper_Utils_HttpRequestParser_Overview_Workflows_SharedSegmentsPlugins_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +0 -1
- package/out/atmpCache/deps/ToListCountAnalyzerTests_ToListinatorTests_test_AIUnitTestExample_code_d.deps +0 -4037
- package/out/atmpCache/deps/ToListCountAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +0 -1
- package/out/atmpCache/deps/ToListCountCodeFixProvider_ToListinatorCodeFixes_src_AIUnitTestExample_code_d.deps +0 -1
- package/out/atmpCache/deps/ToListForEachAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +0 -1
- package/out/atmpCache/dllref/ToListinatorTests_ToListinatorTests_test_AIUnitTestExample_code_d.dllref +0 -202
- package/out/llm/model/Gpt4o.js.map +0 -1
- package/out/llm/model/claude4.d.ts +0 -1
- package/out/llm/model/claude4.js +0 -3
- package/out/llm/model/claude4.js.map +0 -1
- package/out/llm/prompt/generateUtGuidelines.liquid +0 -29
- package/out/llm/prompt/testAfGuidelines.liquid +0 -6
- package/out/llm/prompt/userCustomPrompt.liquid +0 -0
- package/out/llm/prompt/xap/xapUtGuideline-240804.liquid +0 -36
- /package/out/llm/model/{Gpt4o.d.ts → Gpt.d.ts} +0 -0
package/out/llm/preparePrompt.js
CHANGED
|
@@ -53,7 +53,7 @@ function prepareUtGenPrompt(sourceCodePath, sourceCode, dependency, isXapTest, t
|
|
|
53
53
|
const userPrompt = prepareUserInputPrompt(sourceCode, sourceCodePath, dependency);
|
|
54
54
|
prompts.push({ role: 'user', content: userPrompt });
|
|
55
55
|
// prepare code dependency prompt
|
|
56
|
-
if (dependency) {
|
|
56
|
+
if (!!dependency) {
|
|
57
57
|
const codeDependencyPrompt = prepareCodeDenpendencyPrompt(sourceCode, dependency);
|
|
58
58
|
prompts.push({ role: 'user', content: codeDependencyPrompt });
|
|
59
59
|
}
|
|
@@ -107,4 +107,29 @@ function composeSystemPromptTemplate(template, isXapTest, testFramework) {
|
|
|
107
107
|
// prepareUtGenSystemPrompt(true, "XUnit"); // Initialize the system prompt
|
|
108
108
|
// prepareUtAutoFixPrompt("", "", "", "MSBuild Errors", true); // Initialize the auto-fix prompt
|
|
109
109
|
// prepareUtAutoFixPrompt("", "", "", "VSTest result", true); // Initialize the auto-fix prompt
|
|
110
|
+
// function getPrompts(sourceCodePath, testFramework, codeDependency) {
|
|
111
|
+
// const code = fs.readFileSync(sourceCodePath, 'utf8');
|
|
112
|
+
// let guidancePromt = fs.readFileSync("D:\\atmp\\promptiteration.md", 'utf8');
|
|
113
|
+
// guidancePromt = guidancePromt.replace("xUnit", testFramework);
|
|
114
|
+
// const prompts = [
|
|
115
|
+
// // {
|
|
116
|
+
// // "role": "system",
|
|
117
|
+
// // "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."
|
|
118
|
+
// // },
|
|
119
|
+
// {
|
|
120
|
+
// "role": "user",
|
|
121
|
+
// // "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."
|
|
122
|
+
// "content": guidancePromt
|
|
123
|
+
// },
|
|
124
|
+
// {
|
|
125
|
+
// "role": "user",
|
|
126
|
+
// "content": `generate unit test for the following csharp code:\n\`\`\`${code}\`\`\``
|
|
127
|
+
// },
|
|
128
|
+
// // {
|
|
129
|
+
// // "role": "user",
|
|
130
|
+
// // "content": `following are the code dependencies of the source code:\n${codeDependency}`
|
|
131
|
+
// // }
|
|
132
|
+
// ];
|
|
133
|
+
// return prompts;
|
|
134
|
+
// }
|
|
110
135
|
//# sourceMappingURL=preparePrompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preparePrompt.js","sourceRoot":"","sources":["../../src/llm/preparePrompt.ts"],"names":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AAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;IAE9D,OAAO,cAAc,CAAC;AACvB,CAAC;AAED,SAAS,wBAAwB,CAAC,SAAkB,EAAE,aAAqB;IAC1E,MAAM,YAAY,GAAG,2BAA2B,CAAC,2BAA2B,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IACxG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AAClD,CAAC;AAED,SAAS,2BAA2B,CAAC,QAAgB,EAAE,SAAkB,EAAE,aAAqB;IAC/F,sBAAsB;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","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"]}
|
|
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,IA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BAA2B,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IACxG,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;AAClD,CAAC;AAED,SAAS,2BAA2B,CAAC,QAAgB,EAAE,SAAkB,EAAE,aAAqB;IAC/F,sBAAsB;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"]}
|
|
@@ -6,11 +6,15 @@
|
|
|
6
6
|
{%- assign failedTitle = "vstest failure test errors:" -%}
|
|
7
7
|
{%- endif -%}
|
|
8
8
|
|
|
9
|
-
Your previously generated C# unit test code failed to {{failedStage}}.
|
|
9
|
+
Your previously generated C# unit test code failed to {{failedStage}}. Please fix and update the test code.
|
|
10
|
+
|
|
11
|
+
====
|
|
10
12
|
|
|
11
13
|
Your generated test code:
|
|
12
14
|
%s
|
|
13
15
|
|
|
16
|
+
====
|
|
17
|
+
|
|
14
18
|
{{failedTitle}}:
|
|
15
19
|
%s
|
|
16
20
|
|
|
@@ -17,8 +17,10 @@ OBJECTIVE
|
|
|
17
17
|
|
|
18
18
|
You are tasked to write unit tests, breaking it down into clear steps and working through them methodically.
|
|
19
19
|
|
|
20
|
+
- The most important goal is not just to generate correct C# unit test code, but also try your best to improve the code coverage. The higher the coverage rate, the better.
|
|
20
21
|
- Analyze the user's code and set clear, achievable goals to generate unit tests. Prioritize these goals in a logical order.
|
|
21
22
|
- Work through these goals sequentially, each goal should correspond to a distinct step in your problem-solving process.
|
|
23
|
+
- You are STRICTLY FORBIDDEN to contain analysis steps in your response. Just return the code using markdown formating in your response.
|
|
22
24
|
|
|
23
25
|
====
|
|
24
26
|
|
|
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.sendRequestToLLM = sendRequestToLLM;
|
|
4
4
|
const setupLLMRequest_1 = require("../setup/setupLLMRequest");
|
|
5
5
|
async function sendRequestToLLM(prompt, retryTimes = 3) {
|
|
6
|
-
const startTime = Date.now();
|
|
7
|
-
console.log(`Request to LLM...`);
|
|
8
6
|
const { success, content } = await (0, setupLLMRequest_1._sendRequestToLLM)(prompt);
|
|
9
|
-
console.log(`Retry max times, LLM response time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
10
7
|
return { success, content };
|
|
11
8
|
}
|
|
12
9
|
//# sourceMappingURL=sendRequestToLLM.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendRequestToLLM.js","sourceRoot":"","sources":["../../src/llm/sendRequestToLLM.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"sendRequestToLLM.js","sourceRoot":"","sources":["../../src/llm/sendRequestToLLM.ts"],"names":[],"mappings":";;AAEA,4CAGC;AALD,8DAA6D;AAEtD,KAAK,UAAU,gBAAgB,CAAC,MAAa,EAAE,aAAqB,CAAC;IACxE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,mCAAiB,EAAC,MAAM,CAAC,CAAC;IAC7D,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAChC,CAAC","sourcesContent":["import { _sendRequestToLLM } from \"../setup/setupLLMRequest\";\r\n\r\nexport async function sendRequestToLLM(prompt: any[], retryTimes: number = 3): Promise<{ success: boolean, content: string }> {\r\n const { success, content } = await _sendRequestToLLM(prompt);\r\n return { success, content };\r\n}"]}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sendRequestToSelfHostLLM = sendRequestToSelfHostLLM;
|
|
4
4
|
const delay_1 = require("../utils/delay");
|
|
5
|
-
const
|
|
5
|
+
const Gpt_1 = require("./model/Gpt");
|
|
6
6
|
async function sendRequestToSelfHostLLM(prompt, retryTimes = 3) {
|
|
7
7
|
const startTime = Date.now();
|
|
8
8
|
console.log(`Request to LLM...`);
|
|
9
9
|
for (let i = 0; i < retryTimes; i++) {
|
|
10
10
|
try {
|
|
11
|
-
const resp = await (0,
|
|
11
|
+
const resp = await (0, Gpt_1.getLLMResponse)(prompt);
|
|
12
12
|
// generate UT failed
|
|
13
13
|
if (!resp?.choices || resp.choices.length == 0 || !resp.choices[0]?.message?.content) {
|
|
14
14
|
const respStr = JSON.stringify(resp);
|
|
15
|
-
console.error("
|
|
15
|
+
console.error("sendRequestToSelfHostLLM Failed to generate XapUt code:", respStr);
|
|
16
16
|
if (respStr.includes("Rate limit is exceeded")) {
|
|
17
17
|
// wait for 30 seconds before retrying
|
|
18
18
|
await (0, delay_1.delay)(30000);
|
|
@@ -26,7 +26,7 @@ async function sendRequestToSelfHostLLM(prompt, retryTimes = 3) {
|
|
|
26
26
|
catch (error) {
|
|
27
27
|
console.error("Error occurred while generating XapUt code:", error);
|
|
28
28
|
// if prompt size > 128KB, don't need to retry, just return back
|
|
29
|
-
if (error
|
|
29
|
+
if (typeof error === 'object' && error?.code === "context_length_exceeded") {
|
|
30
30
|
console.error("Context length exceeded, please reduce the size of the prompt.");
|
|
31
31
|
return { success: false, content: "" };
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendRequestToSelfHostLLM.js","sourceRoot":"","sources":["../../src/llm/sendRequestToSelfHostLLM.ts"],"names":[],"mappings":";;AAGA,4DAiCC;AApCD,0CAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"sendRequestToSelfHostLLM.js","sourceRoot":"","sources":["../../src/llm/sendRequestToSelfHostLLM.ts"],"names":[],"mappings":";;AAGA,4DAiCC;AApCD,0CAAuC;AACvC,qCAA6C;AAEtC,KAAK,UAAU,wBAAwB,CAAC,MAAa,EAAE,aAAqB,CAAC;IAChF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,IAAA,oBAAc,EAAC,MAAM,CAAC,CAAC;YAC1C,qBAAqB;YACrB,IAAI,CAAC,IAAI,EAAE,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;gBACnF,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;gBACrC,OAAO,CAAC,KAAK,CAAC,yDAAyD,EAAE,OAAO,CAAC,CAAC;gBAClF,IAAI,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;oBAC7C,sCAAsC;oBACtC,MAAM,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;oBACnB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gBAC/B,CAAC;gBACD,SAAS;YACb,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;YAC7E,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;YACpE,gEAAgE;YAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,EAAE,IAAI,KAAK,yBAAyB,EAAE,CAAC;gBACzE,OAAO,CAAC,KAAK,CAAC,gEAAgE,CAAC,CAAC;gBAChF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAC,CAAC;YACzC,CAAC;iBAAM,CAAC;gBACJ,SAAS;YACb,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;IAC9F,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAC,CAAC;AACzC,CAAC","sourcesContent":["import { delay } from \"../utils/delay\";\r\nimport { getLLMResponse } from \"./model/Gpt\";\r\n\r\nexport async function sendRequestToSelfHostLLM(prompt: any[], retryTimes: number = 3): Promise<{success: boolean, content: string}> {\r\n const startTime = Date.now();\r\n console.log(`Request to LLM...`);\r\n for (let i = 0; i < retryTimes; i++) {\r\n try {\r\n const resp = await getLLMResponse(prompt);\r\n // generate UT failed\r\n if (!resp?.choices || resp.choices.length == 0 || !resp.choices[0]?.message?.content) {\r\n const respStr = JSON.stringify(resp);\r\n console.error(\"sendRequestToSelfHostLLM Failed to generate XapUt code:\", respStr);\r\n if (respStr.includes(\"Rate limit is exceeded\")) {\r\n // wait for 30 seconds before retrying\r\n await delay(30000);\r\n console.log(`delayed 30s`);\r\n }\r\n continue;\r\n }\r\n console.log(`LLM response time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return {success: true, content: resp.choices[0]?.message?.content};\r\n } catch (error) {\r\n console.error(\"Error occurred while generating XapUt code:\", error);\r\n // if prompt size > 128KB, don't need to retry, just return back\r\n if (typeof error === 'object' && error?.code === \"context_length_exceeded\") {\r\n console.error(\"Context length exceeded, please reduce the size of the prompt.\");\r\n return {success: false, content: \"\"};\r\n } else {\r\n continue;\r\n }\r\n }\r\n }\r\n\r\n console.log(`Retry max times, LLM response time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return {success: false, content: \"\"};\r\n}"]}
|
package/out/types/constants.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const CSVSPLUGIN = "csvsplugin";
|
|
2
2
|
export declare const CSHARPUTGEN = "csharpUtGen";
|
|
3
3
|
export declare const CSVSCODEPLUGIN = "csVsCodePlugin";
|
|
4
|
+
export declare const MSTESTFRAMEWORK = "MSTest";
|
|
5
|
+
export declare const NUNITTESTFRAMEWORK = "NUnit";
|
|
6
|
+
export declare const XUNITTESTFRAMEWORK = "xUnit";
|
package/out/types/constants.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CSVSCODEPLUGIN = exports.CSHARPUTGEN = exports.CSVSPLUGIN = void 0;
|
|
3
|
+
exports.XUNITTESTFRAMEWORK = exports.NUNITTESTFRAMEWORK = exports.MSTESTFRAMEWORK = exports.CSVSCODEPLUGIN = exports.CSHARPUTGEN = exports.CSVSPLUGIN = void 0;
|
|
4
4
|
exports.CSVSPLUGIN = 'csvsplugin';
|
|
5
5
|
exports.CSHARPUTGEN = 'csharpUtGen';
|
|
6
6
|
exports.CSVSCODEPLUGIN = 'csVsCodePlugin';
|
|
7
|
+
exports.MSTESTFRAMEWORK = 'MSTest';
|
|
8
|
+
exports.NUNITTESTFRAMEWORK = 'NUnit';
|
|
9
|
+
exports.XUNITTESTFRAMEWORK = 'xUnit';
|
|
7
10
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/types/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,YAAY,CAAC;AAC1B,QAAA,WAAW,GAAG,aAAa,CAAC;AAC5B,QAAA,cAAc,GAAG,gBAAgB,CAAC","sourcesContent":["export const CSVSPLUGIN = 'csvsplugin';\r\nexport const CSHARPUTGEN = 'csharpUtGen';\r\nexport const CSVSCODEPLUGIN = 'csVsCodePlugin';"]}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/types/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,YAAY,CAAC;AAC1B,QAAA,WAAW,GAAG,aAAa,CAAC;AAC5B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAClC,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,kBAAkB,GAAG,OAAO,CAAC;AAC7B,QAAA,kBAAkB,GAAG,OAAO,CAAC","sourcesContent":["export const CSVSPLUGIN = 'csvsplugin';\r\nexport const CSHARPUTGEN = 'csharpUtGen';\r\nexport const CSVSCODEPLUGIN = 'csVsCodePlugin';\r\nexport const MSTESTFRAMEWORK = 'MSTest';\r\nexport const NUNITTESTFRAMEWORK = 'NUnit';\r\nexport const XUNITTESTFRAMEWORK = 'xUnit';"]}
|
|
@@ -5,28 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.detectTestFramework = detectTestFramework;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const constants_1 = require("../types/constants");
|
|
8
9
|
function detectTestFramework(csprojPath) {
|
|
9
10
|
const frameworks = [];
|
|
10
11
|
const csprojXml = fs_1.default.readFileSync(csprojPath, "utf-8");
|
|
11
12
|
if (/PackageReference.+Include\s*=\s*["']MSTest\.TestFramework["']/i.test(csprojXml) ||
|
|
12
13
|
/PackageReference.+Include\s*=\s*["']MSTest\.TestAdapter["']/i.test(csprojXml)) {
|
|
13
|
-
return
|
|
14
|
+
return constants_1.MSTESTFRAMEWORK;
|
|
14
15
|
}
|
|
15
16
|
if (/PackageReference.+Include\s*=\s*["']NUnit["']/i.test(csprojXml) ||
|
|
16
17
|
/PackageReference.+Include\s*=\s*["']NUnit3TestAdapter["']/i.test(csprojXml)) {
|
|
17
|
-
return
|
|
18
|
+
return constants_1.NUNITTESTFRAMEWORK;
|
|
18
19
|
}
|
|
19
20
|
if (/PackageReference.+Include\s*=\s*["']xunit["']/i.test(csprojXml)) {
|
|
20
|
-
return
|
|
21
|
+
return constants_1.XUNITTESTFRAMEWORK;
|
|
21
22
|
}
|
|
22
23
|
if (frameworks.length === 0) {
|
|
23
24
|
console.error(`No recognized test framework found in ${csprojPath}. Defaulting to 'MSTest'.`);
|
|
24
25
|
}
|
|
25
|
-
return
|
|
26
|
+
return constants_1.MSTESTFRAMEWORK;
|
|
26
27
|
}
|
|
27
28
|
// detectTestFramework("D:\\code\\AIUnitTestExample\\test\\ToListinator.Tests\\ToListinator.Tests.csproj").forEach(framework => {
|
|
28
29
|
// console.log(`Detected test framework: ${framework}`);
|
|
29
30
|
// });
|
|
30
|
-
const test = detectTestFramework("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\SharedSegments.Plugins.csproj");
|
|
31
|
-
console.log(`Detected test framework: ${test}`);
|
|
31
|
+
// const test = detectTestFramework("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\SharedSegments.Plugins.csproj");
|
|
32
|
+
// console.log(`Detected test framework: ${test}`);
|
|
32
33
|
//# sourceMappingURL=detectTestFramework.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectTestFramework.js","sourceRoot":"","sources":["../../src/utils/detectTestFramework.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"detectTestFramework.js","sourceRoot":"","sources":["../../src/utils/detectTestFramework.ts"],"names":[],"mappings":";;;;;AAGA,kDAuBC;AA1BD,4CAAoB;AACpB,kDAA6F;AAE7F,SAAgB,mBAAmB,CAAC,UAAkB;IACrD,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,MAAM,SAAS,GAAG,YAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAEvD,IAAI,gEAAgE,CAAC,IAAI,CAAC,SAAS,CAAC;QACnF,8DAA8D,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACjF,OAAO,2BAAe,CAAC;IACxB,CAAC;IAED,IAAI,gDAAgD,CAAC,IAAI,CAAC,SAAS,CAAC;QACnE,4DAA4D,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/E,OAAO,8BAAkB,CAAC;IAC3B,CAAC;IAED,IAAI,gDAAgD,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACtE,OAAO,8BAAkB,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,CAAC,KAAK,CAAC,yCAAyC,UAAU,2BAA2B,CAAC,CAAC;IAC/F,CAAC;IAED,OAAO,2BAAe,CAAC;AACxB,CAAC;AAED,iIAAiI;AACjI,0DAA0D;AAC1D,MAAM;AAEN,+JAA+J;AAC/J,mDAAmD","sourcesContent":["import fs from 'fs';\r\nimport { MSTESTFRAMEWORK, NUNITTESTFRAMEWORK, XUNITTESTFRAMEWORK } from '../types/constants';\r\n\r\nexport function detectTestFramework(csprojPath: string): string {\r\n\tconst frameworks: string[] = [];\r\n\tconst csprojXml = fs.readFileSync(csprojPath, \"utf-8\");\r\n\r\n\tif (/PackageReference.+Include\\s*=\\s*[\"']MSTest\\.TestFramework[\"']/i.test(csprojXml) ||\r\n\t\t/PackageReference.+Include\\s*=\\s*[\"']MSTest\\.TestAdapter[\"']/i.test(csprojXml)) {\r\n\t\treturn MSTESTFRAMEWORK;\r\n\t}\r\n\r\n\tif (/PackageReference.+Include\\s*=\\s*[\"']NUnit[\"']/i.test(csprojXml) ||\r\n\t\t/PackageReference.+Include\\s*=\\s*[\"']NUnit3TestAdapter[\"']/i.test(csprojXml)) {\r\n\t\treturn NUNITTESTFRAMEWORK;\r\n\t}\r\n\r\n\tif (/PackageReference.+Include\\s*=\\s*[\"']xunit[\"']/i.test(csprojXml)) {\r\n\t\treturn XUNITTESTFRAMEWORK;\r\n\t}\r\n\r\n\tif (frameworks.length === 0) {\r\n\t\tconsole.error(`No recognized test framework found in ${csprojPath}. Defaulting to 'MSTest'.`);\r\n\t}\r\n\r\n\treturn MSTESTFRAMEWORK;\r\n}\r\n\r\n// detectTestFramework(\"D:\\\\code\\\\AIUnitTestExample\\\\test\\\\ToListinator.Tests\\\\ToListinator.Tests.csproj\").forEach(framework => {\r\n// console.log(`Detected test framework: ${framework}`);\r\n// });\r\n\r\n// const test = detectTestFramework(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\SharedSegments.Plugins.csproj\");\r\n// console.log(`Detected test framework: ${test}`);"]}
|
package/out/utils/getTestFile.js
CHANGED
|
@@ -94,7 +94,7 @@ function isGeneralTestProject(csprojPath) {
|
|
|
94
94
|
return referencesTestFramework || sdkIsTestSdk || fileNameHasTests || pathHasTests;
|
|
95
95
|
}
|
|
96
96
|
catch (err) {
|
|
97
|
-
console.error(
|
|
97
|
+
console.error(`can't read csproj file: ${csprojPath}`);
|
|
98
98
|
return false;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTestFile.js","sourceRoot":"","sources":["../../src/utils/getTestFile.ts"],"names":[],"mappings":";;;;;;;;;;;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J,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;YAChE,MAAM,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;QAC5C,CAAC;QACD,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,oBAAoB,GAAG,MAAM,CAAC,eAAe,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,CAAC;AAErG,CAAC;AAID,gBAAgB;AAChB,0KAA0K;AAC1K,0HAA0H;AAC1H,iJAAiJ;AACjJ,qBAAqB;AACrB,4EAA4E;AAC5E,uBAAuB;AACvB,IAAI;AAEJ,4BAA4B;AAC5B,wDAAwD;AACxD,qFAAqF;AACrF,6EAA6E;AAC7E,iCAAiC;AAEjC,wLAAwL;AACxL,6DAA6D;AAE7D,6KAA6K;AAC7K,yDAAyD;AACzD,+DAA+D;AAG/D,sBAAsB;AACtB,uLAAuL;AACvL,6DAA6D;AAC7D,4KAA4K;AAC5K,oDAAoD;AACpD,8KAA8K;AAC9K,+DAA+D;AAE/D,eAAe;AACf,oKAAoK;AACpK,wDAAwD;AACxD,oKAAoK;AACpK,mLAAmL;AACnL,sDAAsD;AAEtD,yIAAyI;AACzI,wDAAwD","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nimport { getAssemblyName, getCodeRepoRoot, getSourceFileCsprojFilePath, getSourceFileProjectDir } from './getCodeStructurePath';\r\n\r\nimport { XMLParser } from 'fast-xml-parser';\r\n\r\nconst TEST_NAME_REGEX = /(Test|Tests)/i;\r\nconst TEST_ATTR_REGEX = /\\[(Fact|Theory|TestClass|TestMethod|Test)\\]/;\r\n\r\nfunction findAllCsprojFiles(dir: string, excludedPaths: string[]): string[] {\r\n const results: string[] = [];\r\n const entries = fs.readdirSync(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = path.join(dir, entry.name);\r\n if (entry.name === \".vs\" || excludedPaths.includes(fullPath)) {\r\n continue; // Skip excluded paths\r\n }\r\n\r\n if (entry.isDirectory()) {\r\n results.push(...findAllCsprojFiles(fullPath, excludedPaths));\r\n } else if (entry.isFile() && entry.name.endsWith('.csproj')) {\r\n results.push(fullPath);\r\n }\r\n }\r\n\r\n return results;\r\n}\r\n\r\nfunction isXapTestProject(csprojPath: string): boolean {\r\n try {\r\n const content = fs.readFileSync(csprojPath, 'utf-8');\r\n const parser = new XMLParser({ ignoreAttributes: false, ignoreDeclaration: true });\r\n const json = parser.parse(content);\r\n const project = json.Project;\r\n\r\n const propertyGroups = Array.isArray(project.PropertyGroup)\r\n ? project.PropertyGroup\r\n : [project.PropertyGroup];\r\n\r\n for (const group of propertyGroups) {\r\n if (group.XapProjectType === 'TestProject') {\r\n return true;\r\n }\r\n }\r\n } catch (err: any) {\r\n console.error(`Failed to parse ${csprojPath}: ${err.message}`);\r\n }\r\n return false;\r\n}\r\n\r\nfunction isGeneralTestProject(csprojPath: string): boolean {\r\n try {\r\n const content = fs.readFileSync(csprojPath, 'utf-8');\r\n\r\n // 1. package reference (test framework)\r\n const referencesTestFramework = /<PackageReference\\s+Include=\"(xunit|nunit|MSTest\\.TestFramework|Microsoft\\.NET\\.Test\\.Sdk)\"/i.test(content);\r\n\r\n // 2. file name *.Tests.csproj\r\n const fileNameHasTests = (/\\.Tests\\.csproj$/i.test(path.basename(csprojPath))) || (/\\.Test\\.csproj$/i.test(path.basename(csprojPath)));\r\n\r\n // 3. path contains Tests\r\n const pathHasTests = /[\\\\/](Tests?|UnitTests?|IntegrationTests?)[\\\\/]/i.test(csprojPath);\r\n\r\n // 4. Project SDK is test type (optional)\r\n const sdkIsTestSdk = /<Project\\s+Sdk=\"Microsoft\\.NET\\.Test\\.Sdk\"/i.test(content);\r\n\r\n // 组合判断\r\n return referencesTestFramework || sdkIsTestSdk || fileNameHasTests || pathHasTests;\r\n } catch (err) {\r\n console.error(`⚠️ can't read csproj file: ${csprojPath}`);\r\n return false;\r\n }\r\n}\r\n\r\nfunction isFalconUnitTestProject(csprojPath: string): boolean {\r\n const xmlContent = fs.readFileSync(csprojPath, 'utf-8');\r\n\r\n const parser = new XMLParser({\r\n ignoreAttributes: false,\r\n attributeNamePrefix: ''\r\n });\r\n const parsed = parser.parse(xmlContent);\r\n\r\n // get PackageReference node\r\n const project = parsed.Project;\r\n const itemGroups = Array.isArray(project.ItemGroup) ? project.ItemGroup : [project.ItemGroup];\r\n\r\n let isFalconUnitTestProject = false;\r\n\r\n for (const group of itemGroups) {\r\n const refs = group.PackageReference;\r\n if (!refs) continue;\r\n\r\n // PackageReference\r\n const refList = Array.isArray(refs) ? refs : [refs];\r\n\r\n for (const ref of refList) {\r\n if (ref.Include === 'Microsoft.Falcon.CodeAnalyzers') {\r\n isFalconUnitTestProject = true;\r\n console.log('Found Microsoft.Falcon.CodeAnalyzers');\r\n break;\r\n }\r\n }\r\n\r\n if (isFalconUnitTestProject) break;\r\n }\r\n\r\n // if (!isFalconUnitTestProject) {\r\n // console.log('Microsoft.Falcon.CodeAnalyzers not found');\r\n // }\r\n\r\n return isFalconUnitTestProject;\r\n}\r\n\r\nfunction isProjectNameMatchedTestProject(csprojPath: string, projectAssemblyName: string, projectName: string) {\r\n const testProjectName = path.basename(csprojPath, '.csproj').toLowerCase();\r\n const fileNameEndWithTests = testProjectName.endsWith('.tests') || testProjectName.endsWith('.test') || testProjectName.endsWith('.unittest') || testProjectName.endsWith('.unittests');\r\n if (testProjectName.startsWith(projectName.toLowerCase()) && fileNameEndWithTests) {\r\n return true;\r\n }\r\n const testProjectAssemblyName = getAssemblyName(csprojPath);\r\n return testProjectAssemblyName?.toLowerCase()?.startsWith(projectAssemblyName.toLowerCase()) && fileNameEndWithTests;\r\n}\r\n\r\nfunction findTestProjectFromCsFile(csFilePath: string): string | null {\r\n let currentDir = path.dirname(csFilePath);\r\n const repoRoot = getCodeRepoRoot(csFilePath);\r\n const projectFilePath = getSourceFileCsprojFilePath(csFilePath);\r\n const projectName = path.basename(projectFilePath, '.csproj');\r\n const projectAssemblyName = getAssemblyName(projectFilePath);\r\n\r\n const excludedPaths: string[] = [currentDir];\r\n const repoRootParentPath = path.dirname(repoRoot);\r\n // Start from the parent directory of the source file, because test project is usually in the parent directory\r\n currentDir = path.dirname(currentDir);\r\n while (currentDir !== repoRootParentPath) {\r\n const csprojFiles = findAllCsprojFiles(currentDir, excludedPaths);\r\n for (const csproj of csprojFiles) {\r\n if (isProjectNameMatchedTestProject(csproj, projectAssemblyName, projectName)) {\r\n return csproj;\r\n } else if (isXapTestProject(csproj)) {\r\n return csproj;\r\n } else if (isFalconUnitTestProject(csproj)) {\r\n const filename = path.basename(csproj, '.csproj').toLowerCase();\r\n if (filename.endsWith('unittest') || filename.endsWith('unittests')) {\r\n return csproj;\r\n }\r\n } else if (isGeneralTestProject(csproj)) {\r\n return csproj;\r\n }\r\n }\r\n // Add current directory to excluded paths to avoid re-checking\r\n excludedPaths.push(currentDir);\r\n currentDir = path.dirname(currentDir);\r\n }\r\n\r\n return null;\r\n}\r\n\r\nfunction findPossibleTestFiles(testProjectDir: string, className: string): string[] {\r\n const results: string[] = [];\r\n const stack: string[] = [testProjectDir];\r\n\r\n while (stack.length > 0) {\r\n const currentDir = stack.pop()!;\r\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n if (entry.name === \"bin\" || entry.name === \"obj\") {\r\n continue;\r\n }\r\n const fullPath = path.join(currentDir, entry.name);\r\n if (entry.isDirectory()) {\r\n stack.push(fullPath);\r\n } else if (entry.isFile() && entry.name.endsWith('.cs') && entry.name.includes(className)) {\r\n results.push(fullPath);\r\n }\r\n }\r\n }\r\n\r\n return results;\r\n}\r\n\r\nfunction fileContainsTestAttributes(filePath: string): boolean {\r\n const content = fs.readFileSync(filePath, 'utf-8');\r\n return TEST_ATTR_REGEX.test(content);\r\n}\r\n\r\nexport function getExistingTestFile(sourceCodePath: string) {\r\n const absPath = path.resolve(sourceCodePath);\r\n const testProjectPath = findTestProjectFromCsFile(absPath);\r\n\r\n if (!testProjectPath) {\r\n console.error(`No test project found for ${sourceCodePath}`);\r\n return { testFilePath: null, testProjectPath: null };\r\n }\r\n\r\n const testProjectDir = path.dirname(testProjectPath);\r\n const className = path.basename(sourceCodePath, '.cs');\r\n const candidateFiles = findPossibleTestFiles(testProjectDir, className);\r\n\r\n for (const testFilePath of candidateFiles) {\r\n if (TEST_NAME_REGEX.test(path.basename(testFilePath))) {\r\n return { testFilePath, testProjectPath };\r\n }\r\n }\r\n\r\n return { testFilePath: null, testProjectPath: testProjectPath };\r\n}\r\n\r\nfunction createXapTestProject(sourceCodePath: string) {\r\n}\r\n\r\nexport function createTestFile(sourceCodePath: string) {\r\n const testProjectPath = findTestProjectFromCsFile(sourceCodePath);\r\n if (!testProjectPath) {\r\n console.error(`No test project found for ${sourceCodePath}`);\r\n return { testFilePath: null, testProjectPath: null };\r\n }\r\n const sourceFileName = path.basename(sourceCodePath, '.cs');\r\n const testFileName = `${sourceFileName}Tests.cs`;\r\n const sourceFileProjectPath = getSourceFileProjectDir(sourceCodePath);\r\n const sourceFileDir = path.dirname(sourceCodePath);\r\n const testFileRelativePath = sourceFileDir.replace(sourceFileProjectPath, \"\");\r\n const testProjecDir = path.dirname(testProjectPath);\r\n const testFilePath = path.join(testProjecDir, testFileRelativePath, testFileName);\r\n const testFileDir = path.dirname(testFilePath);\r\n // Create all missing directories recursively\r\n fs.mkdirSync(testFileDir, { recursive: true });\r\n console.log(`Created test file dir at ${testFilePath}`);\r\n return { testFilePath, testProjectPath };\r\n}\r\n\r\nexport function getOrCreatTestFile(sourceCodePath: string, testFilePath: string, isXapCode: boolean) {\r\n let finalTestFilePath = testFilePath;\r\n let finalTestProjectPath;\r\n let testFileExist = !!testFilePath && fs.existsSync(testFilePath);\r\n // if outputPath param is not provided, try to find an existing test file\r\n // if no existing test file found, create a new one in test project\r\n if (!testFilePath || testFilePath.trim() === '') {\r\n console.log(' Output path is missing. outputPath:', testFilePath, ', start looking for existing test project');\r\n let result = getExistingTestFile(sourceCodePath);\r\n if (result.testFilePath) {\r\n testFileExist = true;\r\n console.log(`Found existing test file: ${result.testFilePath}`);\r\n } else {\r\n console.log('No existing test file found, creating a new one.');\r\n result = createTestFile(sourceCodePath);\r\n }\r\n finalTestFilePath = result.testFilePath;\r\n finalTestProjectPath = result.testProjectPath;\r\n }\r\n\r\n return { testFilePath: finalTestFilePath, testProjectPath: finalTestProjectPath, testFileExist };\r\n\r\n}\r\n\r\n\r\n\r\n// Example usage\r\n// const csFilePath = \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\LocationDetection\\\\AudienceResponseParser.cs\";\r\n// const csFilePath = \"D:\\\\code\\\\msnews-experiences\\\\experiences\\\\weather-right-rail\\\\src\\\\WeatherRightRail.connector.ts\";\r\n// const testProjectPath = \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj\";\r\n// if (!csFilePath) {\r\n// console.error('Usage: ts-node findTestFile.ts path/to/your/file.cs');\r\n// process.exit(1);\r\n// }\r\n\r\n// const start = Date.now();\r\n// const testFilePath = getExistingTestFile(csFilePath);\r\n// console.log(`Test file for ${csFilePath}:`, testFilePath ?? 'No test file found');\r\n// console.log(`Search completed in ${(Date.now() - start) / 1000} seconds`);\r\n// createXapTestFile(csFilePath);\r\n\r\n// const repoDir = getCodeRepoRoot(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\LocationDetection\\\\AudienceResponseParser.cs\");\r\n// console.log(`Code repository root directory: ${repoDir}`);\r\n\r\n// const result = getExistingTestFile(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Eplant\\\\EplantConfigManager.cs\");\r\n// console.log(`Test file path: ${result.testFilePath}`);\r\n// console.log(`Test project path: ${result.testProjectPath}`);\r\n\r\n\r\n// falcon test project\r\n// const isFlaconUt = isFalconUnitTestProject(\"D:\\\\code\\\\WeatherNotification\\\\services\\\\WeatherUserInterest\\\\tests\\\\UnitTests\\\\Microsoft.Falcon.WeatherUserInterest.UnitTests.csproj\");\r\n// console.log(`Is Falcon Unit Test Project: ${isFlaconUt}`);\r\n// const testProject = findTestProjectFromCsFile(\"D:\\\\code\\\\WeatherNotification\\\\services\\\\WeatherUserInterest\\\\src\\\\Service\\\\Microsoft.Falcon.WeatherUserInterest.csproj\");\r\n// console.log(`Test project path: ${testProject}`);\r\n// const testFilePath = getOrCreatTestFile(\"D:\\\\code\\\\WeatherNotification\\\\services\\\\WeatherUserInterest\\\\src\\\\Service\\\\Components\\\\IUserInterestTable.cs\", undefined, false);\r\n// console.log(`Test file path: ${testFilePath.testFilePath}`);\r\n\r\n// ads projects\r\n// const testProjectPath = findTestProjectFromCsFile(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UCMDynamics.AppointmentPlugin\\\\AppointmentOperation.cs\");\r\n// console.log(`Test project path: ${testProjectPath}`);\r\n// const isValid = isGeneralTestProject(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UcmDynamics.AppointmentPlugin\\\\UcmDynamics.AppointmentPlugin.csproj\");\r\n// // const isValid = isGeneralTestProject(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UcmDynamics.AppointmentPlugin.Tests\\\\UcmDynamics.AppointmentPlugin.Tests.csproj\");\r\n// console.log(`Is General Test Project: ${isValid}`);\r\n\r\n// const testProjectPath = findTestProjectFromCsFile(\"D:\\\\code\\\\AIUnitTestExample\\\\src\\\\ToListinator.Analyzers\\\\ToListCountAnalyzer.cs\");\r\n// console.log(`Test project path: ${testProjectPath}`);"]}
|
|
1
|
+
{"version":3,"file":"getTestFile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,MAAM,CAAC,YAAY,EAAE,CAAC,CAAC;QACpE,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;YAChE,MAAM,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;QAC5C,CAAC;QACD,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,oBAAoB,GAAG,MAAM,CAAC,eAAe,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,CAAC;AAErG,CAAC;AAID,gBAAgB;AAChB,0KAA0K;AAC1K,0HAA0H;AAC1H,iJAAiJ;AACjJ,qBAAqB;AACrB,4EAA4E;AAC5E,uBAAuB;AACvB,IAAI;AAEJ,4BAA4B;AAC5B,wDAAwD;AACxD,qFAAqF;AACrF,6EAA6E;AAC7E,iCAAiC;AAEjC,wLAAwL;AACxL,6DAA6D;AAE7D,6KAA6K;AAC7K,yDAAyD;AACzD,+DAA+D;AAG/D,sBAAsB;AACtB,uLAAuL;AACvL,6DAA6D;AAC7D,4KAA4K;AAC5K,oDAAoD;AACpD,8KAA8K;AAC9K,+DAA+D;AAE/D,eAAe;AACf,oKAAoK;AACpK,wDAAwD;AACxD,oKAAoK;AACpK,mLAAmL;AACnL,sDAAsD;AAEtD,yIAAyI;AACzI,wDAAwD","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nimport { getAssemblyName, getCodeRepoRoot, getSourceFileCsprojFilePath, getSourceFileProjectDir } from './getCodeStructurePath';\r\n\r\nimport { XMLParser } from 'fast-xml-parser';\r\n\r\nconst TEST_NAME_REGEX = /(Test|Tests)/i;\r\nconst TEST_ATTR_REGEX = /\\[(Fact|Theory|TestClass|TestMethod|Test)\\]/;\r\n\r\nfunction findAllCsprojFiles(dir: string, excludedPaths: string[]): string[] {\r\n const results: string[] = [];\r\n const entries = fs.readdirSync(dir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n const fullPath = path.join(dir, entry.name);\r\n if (entry.name === \".vs\" || excludedPaths.includes(fullPath)) {\r\n continue; // Skip excluded paths\r\n }\r\n\r\n if (entry.isDirectory()) {\r\n results.push(...findAllCsprojFiles(fullPath, excludedPaths));\r\n } else if (entry.isFile() && entry.name.endsWith('.csproj')) {\r\n results.push(fullPath);\r\n }\r\n }\r\n\r\n return results;\r\n}\r\n\r\nfunction isXapTestProject(csprojPath: string): boolean {\r\n try {\r\n const content = fs.readFileSync(csprojPath, 'utf-8');\r\n const parser = new XMLParser({ ignoreAttributes: false, ignoreDeclaration: true });\r\n const json = parser.parse(content);\r\n const project = json.Project;\r\n\r\n const propertyGroups = Array.isArray(project.PropertyGroup)\r\n ? project.PropertyGroup\r\n : [project.PropertyGroup];\r\n\r\n for (const group of propertyGroups) {\r\n if (group.XapProjectType === 'TestProject') {\r\n return true;\r\n }\r\n }\r\n } catch (err: any) {\r\n console.error(`Failed to parse ${csprojPath}: ${err.message}`);\r\n }\r\n return false;\r\n}\r\n\r\nfunction isGeneralTestProject(csprojPath: string): boolean {\r\n try {\r\n const content = fs.readFileSync(csprojPath, 'utf-8');\r\n\r\n // 1. package reference (test framework)\r\n const referencesTestFramework = /<PackageReference\\s+Include=\"(xunit|nunit|MSTest\\.TestFramework|Microsoft\\.NET\\.Test\\.Sdk)\"/i.test(content);\r\n\r\n // 2. file name *.Tests.csproj\r\n const fileNameHasTests = (/\\.Tests\\.csproj$/i.test(path.basename(csprojPath))) || (/\\.Test\\.csproj$/i.test(path.basename(csprojPath)));\r\n\r\n // 3. path contains Tests\r\n const pathHasTests = /[\\\\/](Tests?|UnitTests?|IntegrationTests?)[\\\\/]/i.test(csprojPath);\r\n\r\n // 4. Project SDK is test type (optional)\r\n const sdkIsTestSdk = /<Project\\s+Sdk=\"Microsoft\\.NET\\.Test\\.Sdk\"/i.test(content);\r\n\r\n // 组合判断\r\n return referencesTestFramework || sdkIsTestSdk || fileNameHasTests || pathHasTests;\r\n } catch (err) {\r\n console.error(`can't read csproj file: ${csprojPath}`);\r\n return false;\r\n }\r\n}\r\n\r\nfunction isFalconUnitTestProject(csprojPath: string): boolean {\r\n const xmlContent = fs.readFileSync(csprojPath, 'utf-8');\r\n\r\n const parser = new XMLParser({\r\n ignoreAttributes: false,\r\n attributeNamePrefix: ''\r\n });\r\n const parsed = parser.parse(xmlContent);\r\n\r\n // get PackageReference node\r\n const project = parsed.Project;\r\n const itemGroups = Array.isArray(project.ItemGroup) ? project.ItemGroup : [project.ItemGroup];\r\n\r\n let isFalconUnitTestProject = false;\r\n\r\n for (const group of itemGroups) {\r\n const refs = group.PackageReference;\r\n if (!refs) continue;\r\n\r\n // PackageReference\r\n const refList = Array.isArray(refs) ? refs : [refs];\r\n\r\n for (const ref of refList) {\r\n if (ref.Include === 'Microsoft.Falcon.CodeAnalyzers') {\r\n isFalconUnitTestProject = true;\r\n console.log('Found Microsoft.Falcon.CodeAnalyzers');\r\n break;\r\n }\r\n }\r\n\r\n if (isFalconUnitTestProject) break;\r\n }\r\n\r\n // if (!isFalconUnitTestProject) {\r\n // console.log('Microsoft.Falcon.CodeAnalyzers not found');\r\n // }\r\n\r\n return isFalconUnitTestProject;\r\n}\r\n\r\nfunction isProjectNameMatchedTestProject(csprojPath: string, projectAssemblyName: string, projectName: string) {\r\n const testProjectName = path.basename(csprojPath, '.csproj').toLowerCase();\r\n const fileNameEndWithTests = testProjectName.endsWith('.tests') || testProjectName.endsWith('.test') || testProjectName.endsWith('.unittest') || testProjectName.endsWith('.unittests');\r\n if (testProjectName.startsWith(projectName.toLowerCase()) && fileNameEndWithTests) {\r\n return true;\r\n }\r\n const testProjectAssemblyName = getAssemblyName(csprojPath);\r\n return testProjectAssemblyName?.toLowerCase()?.startsWith(projectAssemblyName.toLowerCase()) && fileNameEndWithTests;\r\n}\r\n\r\nfunction findTestProjectFromCsFile(csFilePath: string): string | null {\r\n let currentDir = path.dirname(csFilePath);\r\n const repoRoot = getCodeRepoRoot(csFilePath);\r\n const projectFilePath = getSourceFileCsprojFilePath(csFilePath);\r\n const projectName = path.basename(projectFilePath, '.csproj');\r\n const projectAssemblyName = getAssemblyName(projectFilePath);\r\n\r\n const excludedPaths: string[] = [currentDir];\r\n const repoRootParentPath = path.dirname(repoRoot);\r\n // Start from the parent directory of the source file, because test project is usually in the parent directory\r\n currentDir = path.dirname(currentDir);\r\n while (currentDir !== repoRootParentPath) {\r\n const csprojFiles = findAllCsprojFiles(currentDir, excludedPaths);\r\n for (const csproj of csprojFiles) {\r\n if (isProjectNameMatchedTestProject(csproj, projectAssemblyName, projectName)) {\r\n return csproj;\r\n } else if (isXapTestProject(csproj)) {\r\n return csproj;\r\n } else if (isFalconUnitTestProject(csproj)) {\r\n const filename = path.basename(csproj, '.csproj').toLowerCase();\r\n if (filename.endsWith('unittest') || filename.endsWith('unittests')) {\r\n return csproj;\r\n }\r\n } else if (isGeneralTestProject(csproj)) {\r\n return csproj;\r\n }\r\n }\r\n // Add current directory to excluded paths to avoid re-checking\r\n excludedPaths.push(currentDir);\r\n currentDir = path.dirname(currentDir);\r\n }\r\n\r\n return null;\r\n}\r\n\r\nfunction findPossibleTestFiles(testProjectDir: string, className: string): string[] {\r\n const results: string[] = [];\r\n const stack: string[] = [testProjectDir];\r\n\r\n while (stack.length > 0) {\r\n const currentDir = stack.pop()!;\r\n const entries = fs.readdirSync(currentDir, { withFileTypes: true });\r\n\r\n for (const entry of entries) {\r\n if (entry.name === \"bin\" || entry.name === \"obj\") {\r\n continue;\r\n }\r\n const fullPath = path.join(currentDir, entry.name);\r\n if (entry.isDirectory()) {\r\n stack.push(fullPath);\r\n } else if (entry.isFile() && entry.name.endsWith('.cs') && entry.name.includes(className)) {\r\n results.push(fullPath);\r\n }\r\n }\r\n }\r\n\r\n return results;\r\n}\r\n\r\nfunction fileContainsTestAttributes(filePath: string): boolean {\r\n const content = fs.readFileSync(filePath, 'utf-8');\r\n return TEST_ATTR_REGEX.test(content);\r\n}\r\n\r\nexport function getExistingTestFile(sourceCodePath: string) {\r\n const absPath = path.resolve(sourceCodePath);\r\n const testProjectPath = findTestProjectFromCsFile(absPath);\r\n\r\n if (!testProjectPath) {\r\n console.error(`No test project found for ${sourceCodePath}`);\r\n return { testFilePath: null, testProjectPath: null };\r\n }\r\n\r\n const testProjectDir = path.dirname(testProjectPath);\r\n const className = path.basename(sourceCodePath, '.cs');\r\n const candidateFiles = findPossibleTestFiles(testProjectDir, className);\r\n\r\n for (const testFilePath of candidateFiles) {\r\n if (TEST_NAME_REGEX.test(path.basename(testFilePath))) {\r\n return { testFilePath, testProjectPath };\r\n }\r\n }\r\n\r\n return { testFilePath: null, testProjectPath: testProjectPath };\r\n}\r\n\r\nfunction createXapTestProject(sourceCodePath: string) {\r\n}\r\n\r\nexport function createTestFile(sourceCodePath: string) {\r\n const testProjectPath = findTestProjectFromCsFile(sourceCodePath);\r\n if (!testProjectPath) {\r\n console.error(`No test project found for ${sourceCodePath}`);\r\n return { testFilePath: null, testProjectPath: null };\r\n }\r\n const sourceFileName = path.basename(sourceCodePath, '.cs');\r\n const testFileName = `${sourceFileName}Tests.cs`;\r\n const sourceFileProjectPath = getSourceFileProjectDir(sourceCodePath);\r\n const sourceFileDir = path.dirname(sourceCodePath);\r\n const testFileRelativePath = sourceFileDir.replace(sourceFileProjectPath, \"\");\r\n const testProjecDir = path.dirname(testProjectPath);\r\n const testFilePath = path.join(testProjecDir, testFileRelativePath, testFileName);\r\n const testFileDir = path.dirname(testFilePath);\r\n // Create all missing directories recursively\r\n fs.mkdirSync(testFileDir, { recursive: true });\r\n console.log(`Created test file dir at ${testFilePath}`);\r\n return { testFilePath, testProjectPath };\r\n}\r\n\r\nexport function getOrCreatTestFile(sourceCodePath: string, testFilePath: string, isXapCode: boolean) {\r\n let finalTestFilePath = testFilePath;\r\n let finalTestProjectPath;\r\n let testFileExist = !!testFilePath && fs.existsSync(testFilePath);\r\n // if outputPath param is not provided, try to find an existing test file\r\n // if no existing test file found, create a new one in test project\r\n if (!testFilePath || testFilePath.trim() === '') {\r\n console.log(' Output path is missing. outputPath:', testFilePath, ', start looking for existing test project');\r\n let result = getExistingTestFile(sourceCodePath);\r\n if (result.testFilePath) {\r\n testFileExist = true;\r\n console.log(`Found existing test file: ${result.testFilePath}`);\r\n } else {\r\n console.log('No existing test file found, creating a new one.');\r\n result = createTestFile(sourceCodePath);\r\n }\r\n finalTestFilePath = result.testFilePath;\r\n finalTestProjectPath = result.testProjectPath;\r\n }\r\n\r\n return { testFilePath: finalTestFilePath, testProjectPath: finalTestProjectPath, testFileExist };\r\n\r\n}\r\n\r\n\r\n\r\n// Example usage\r\n// const csFilePath = \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\LocationDetection\\\\AudienceResponseParser.cs\";\r\n// const csFilePath = \"D:\\\\code\\\\msnews-experiences\\\\experiences\\\\weather-right-rail\\\\src\\\\WeatherRightRail.connector.ts\";\r\n// const testProjectPath = \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj\";\r\n// if (!csFilePath) {\r\n// console.error('Usage: ts-node findTestFile.ts path/to/your/file.cs');\r\n// process.exit(1);\r\n// }\r\n\r\n// const start = Date.now();\r\n// const testFilePath = getExistingTestFile(csFilePath);\r\n// console.log(`Test file for ${csFilePath}:`, testFilePath ?? 'No test file found');\r\n// console.log(`Search completed in ${(Date.now() - start) / 1000} seconds`);\r\n// createXapTestFile(csFilePath);\r\n\r\n// const repoDir = getCodeRepoRoot(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\LocationDetection\\\\AudienceResponseParser.cs\");\r\n// console.log(`Code repository root directory: ${repoDir}`);\r\n\r\n// const result = getExistingTestFile(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Eplant\\\\EplantConfigManager.cs\");\r\n// console.log(`Test file path: ${result.testFilePath}`);\r\n// console.log(`Test project path: ${result.testProjectPath}`);\r\n\r\n\r\n// falcon test project\r\n// const isFlaconUt = isFalconUnitTestProject(\"D:\\\\code\\\\WeatherNotification\\\\services\\\\WeatherUserInterest\\\\tests\\\\UnitTests\\\\Microsoft.Falcon.WeatherUserInterest.UnitTests.csproj\");\r\n// console.log(`Is Falcon Unit Test Project: ${isFlaconUt}`);\r\n// const testProject = findTestProjectFromCsFile(\"D:\\\\code\\\\WeatherNotification\\\\services\\\\WeatherUserInterest\\\\src\\\\Service\\\\Microsoft.Falcon.WeatherUserInterest.csproj\");\r\n// console.log(`Test project path: ${testProject}`);\r\n// const testFilePath = getOrCreatTestFile(\"D:\\\\code\\\\WeatherNotification\\\\services\\\\WeatherUserInterest\\\\src\\\\Service\\\\Components\\\\IUserInterestTable.cs\", undefined, false);\r\n// console.log(`Test file path: ${testFilePath.testFilePath}`);\r\n\r\n// ads projects\r\n// const testProjectPath = findTestProjectFromCsFile(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UCMDynamics.AppointmentPlugin\\\\AppointmentOperation.cs\");\r\n// console.log(`Test project path: ${testProjectPath}`);\r\n// const isValid = isGeneralTestProject(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UcmDynamics.AppointmentPlugin\\\\UcmDynamics.AppointmentPlugin.csproj\");\r\n// // const isValid = isGeneralTestProject(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UcmDynamics.AppointmentPlugin.Tests\\\\UcmDynamics.AppointmentPlugin.Tests.csproj\");\r\n// console.log(`Is General Test Project: ${isValid}`);\r\n\r\n// const testProjectPath = findTestProjectFromCsFile(\"D:\\\\code\\\\AIUnitTestExample\\\\src\\\\ToListinator.Analyzers\\\\ToListCountAnalyzer.cs\");\r\n// console.log(`Test project path: ${testProjectPath}`);"]}
|
package/out/vs/msBuild.js
CHANGED
|
@@ -1,48 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.runMsBuild = runMsBuild;
|
|
37
4
|
exports.buildErrorHandler = buildErrorHandler;
|
|
38
5
|
exports.buildCloseHandler = buildCloseHandler;
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
6
|
const parseBuildResult_1 = require("../utils/parseBuildResult");
|
|
41
7
|
const vsTools_1 = require("./vsTools");
|
|
42
8
|
const spawnExec_1 = require("../utils/spawnExec");
|
|
9
|
+
const getOrCreateDir_1 = require("../utils/getOrCreateDir");
|
|
10
|
+
const BuildCacheDir = "./build/";
|
|
43
11
|
function runMsBuild(projectPath) {
|
|
44
12
|
const args = [projectPath, '/t:Build', '/m', '/nr:true', '/v:minimal'];
|
|
45
|
-
const workDir =
|
|
13
|
+
const workDir = (0, getOrCreateDir_1.getTmpCacheDir)(BuildCacheDir);
|
|
46
14
|
return (0, spawnExec_1.runSpawn)(`${vsTools_1.msBuildPath}`, args, workDir, buildErrorHandler, buildCloseHandler);
|
|
47
15
|
}
|
|
48
16
|
function buildErrorHandler(error) {
|
package/out/vs/msBuild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msBuild.js","sourceRoot":"","sources":["../../src/vs/msBuild.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"msBuild.js","sourceRoot":"","sources":["../../src/vs/msBuild.ts"],"names":[],"mappings":";;AASA,gCAKC;AAED,8CAGC;AAED,8CAeC;AAlCD,gEAA8F;AAE9F,uCAAwC;AACxC,kDAA8C;AAC9C,4DAAyD;AAEzD,MAAM,aAAa,GAAG,UAAU,CAAA;AAChC,SAAgB,UAAU,CAAC,WAAmB;IAC1C,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;IAEvE,MAAM,OAAO,GAAG,IAAA,+BAAc,EAAC,aAAa,CAAC,CAAC;IAC9C,OAAO,IAAA,oBAAQ,EAAC,GAAG,qBAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,iBAAiB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import { formatMsbuildResultToMarkdown, parseMsbuildErrors } from '../utils/parseBuildResult';\r\n\r\nimport { msBuildPath } from './vsTools';\r\nimport { runSpawn } from '../utils/spawnExec';\r\nimport { getTmpCacheDir } from '../utils/getOrCreateDir';\r\n\r\nconst BuildCacheDir = \"./build/\"\r\nexport function runMsBuild(projectPath: string): Promise<any> {\r\n const args = [projectPath, '/t:Build', '/m', '/nr:true', '/v:minimal'];\r\n\r\n const workDir = getTmpCacheDir(BuildCacheDir);\r\n return runSpawn(`${msBuildPath}`, args, workDir, buildErrorHandler, buildCloseHandler);\r\n}\r\n\r\nexport function buildErrorHandler(error) {\r\n console.error(`buildErrorHandler - failed: ${error.message}`);\r\n return ({ success: false });\r\n}\r\n\r\nexport function buildCloseHandler(code, stdout, stderr) {\r\n if (code !== 0) {\r\n console.error(`Build failed with exit code ${code}`);\r\n const buildErrors = parseMsbuildErrors(stdout);\r\n const formattedBuildErrors = formatMsbuildResultToMarkdown(buildErrors);\r\n return { success: false, message: formattedBuildErrors, buildErrors: buildErrors };\r\n }\r\n\r\n if (stderr) {\r\n console.error(`Warnings/Errors:\\n${stdout}`);\r\n return { success: false, message: stdout, buildErrors: null };\r\n }\r\n\r\n console.log(`Build succeeded`);\r\n return { success: true, message: stdout, buildErrors: null };\r\n}\r\n\r\n\r\n// setupSignalHandlers();\r\n// runMsBuild('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj');\r\n// runMsBuild3('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj');\r\n\r\n// devenv \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /build Debug // incremental compile\r\n// devenv.com \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /build Debug // incremental compile\r\n// devenv.com \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /build Debug // incremental compile\r\n// devenv.com \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments.sln\" /build Debug // incremental compile\r\n// msbuild \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /t:Build /p:Configuration=Debug /m /v:minimal\r\n// msbuild \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /t:Build /p:Configuration=Debug /m /v:minimal\r\n// msbuild \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /t:Build /p:Configuration=Debug /m /v:minimal /nr:true\r\n\r\n// devenv.com \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments.sln\" /project \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\" /build Debug\r\n\r\n// devenvexe.cmd \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments.sln\" /build Debug /project \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\"\r\n// devenvcom.cmd \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments.sln\" /build Debug /project \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj\"\r\n\r\n// msbuildexe.cmd \\\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj\\\" /t:Build /m /nr:true /v:minimal\r\n// runMsBuild('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj');"]}
|
package/out/vs/vsTest.js
CHANGED
|
@@ -1,48 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.runSingleTestMethod = runSingleTestMethod;
|
|
37
4
|
exports.runTestClass = runTestClass;
|
|
38
5
|
exports.runTestCommand = runTestCommand;
|
|
39
6
|
exports.testErrorHandler = testErrorHandler;
|
|
40
7
|
exports.testCloseHandler = testCloseHandler;
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
8
|
const parseVstestResult_1 = require("../utils/parseVstestResult");
|
|
43
9
|
const spawnExec_1 = require("../utils/spawnExec");
|
|
44
10
|
const vsTools_1 = require("./vsTools");
|
|
11
|
+
const getOrCreateDir_1 = require("../utils/getOrCreateDir");
|
|
45
12
|
// const vstestPath = `"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\IDE\\Extensions\\TestPlatform\\vstest.console.exe"`;
|
|
13
|
+
const TestCacheDir = "./build/";
|
|
46
14
|
async function runSingleTestMethod(testDll, testMethod) {
|
|
47
15
|
// const cmd = `vstestexe.cmd "${testDll}" /Tests:${testMethod}`;
|
|
48
16
|
const args = [testDll, `/Tests:${testMethod}`];
|
|
@@ -59,7 +27,7 @@ async function runTestClass(testDll, className) {
|
|
|
59
27
|
// execCommand(cmd);
|
|
60
28
|
// }
|
|
61
29
|
function runTestCommand(args) {
|
|
62
|
-
const workDir =
|
|
30
|
+
const workDir = (0, getOrCreateDir_1.getTmpCacheDir)(TestCacheDir);
|
|
63
31
|
return (0, spawnExec_1.runSpawn)(`${vsTools_1.vstestPath}`, args, workDir, testErrorHandler, testCloseHandler);
|
|
64
32
|
}
|
|
65
33
|
function testErrorHandler(error) {
|
package/out/vs/vsTest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vsTest.js","sourceRoot":"","sources":["../../src/vs/vsTest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vsTest.js","sourceRoot":"","sources":["../../src/vs/vsTest.ts"],"names":[],"mappings":";;AASA,kDAIC;AAED,oCAIC;AAQD,wCAGC;AAED,4CAGC;AAED,4CAkBC;AAvDD,kE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AG,IAAA,gDAA4B,EAAC,UAAU,CAAC,CAAC;QACtE,IAAI,CAAC,gDAA4B,EAAE,CAAC;YACnC,qGAAqG;YACrG,OAAO,CAAC,KAAK,CAAC,kCAAkC,MAAM,EAAE,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAC;IACtE,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC;QACpC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9D,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAChC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC7D,CAAC;AAID,mNAAmN;AACnN,qFAAqF;AACrF,yBAAyB;AACzB,mOAAmO;AACnO,sEAAsE;AACtE,MAAM;AACN,8OAA8O;AAE9O,sMAAsM;AACtM,gOAAgO;AAChO,sQAAsQ;AACtQ,iQAAiQ;AACjQ,2OAA2O;AAE3O,wNAAwN;AACxN,sEAAsE;AACtE,MAAM;AACN,wQAAwQ;AACxQ,sQAAsQ;AACtQ,gQAAgQ;AAChQ,sEAAsE;AACtE,MAAM","sourcesContent":["import { formatVSTestResultToMarkdown, parseVSTestOutput } from '../utils/parseVstestResult';\r\n\r\nimport { runSpawn } from '../utils/spawnExec';\r\nimport { vstestPath } from './vsTools';\r\nimport { getTmpCacheDir } from '../utils/getOrCreateDir';\r\n\r\n// const vstestPath = `\"C:\\\\Program Files\\\\Microsoft Visual Studio\\\\2022\\\\Community\\\\Common7\\\\IDE\\\\Extensions\\\\TestPlatform\\\\vstest.console.exe\"`;\r\n\r\nconst TestCacheDir = \"./build/\"\r\nexport async function runSingleTestMethod(testDll: string, testMethod: string) {\r\n\t// const cmd = `vstestexe.cmd \"${testDll}\" /Tests:${testMethod}`;\r\n\tconst args = [testDll, `/Tests:${testMethod}`];\r\n\treturn await runTestCommand(args);\r\n}\r\n\r\nexport async function runTestClass(testDll: string, className: string) {\r\n\t// const cmd = `vstestexe.cmd \"${testDll}\" /TestCaseFilter:\"FullyQualifiedName~${className}\"`;\r\n\tconst args = [testDll, `/TestCaseFilter:FullyQualifiedName~${className}`];\r\n\treturn await runTestCommand(args);\r\n}\r\n\r\n// export function runTestFile(testDll: string, fullyQualifiedNames: string[]) {\r\n// \tconst testsArg = fullyQualifiedNames.map(name => `/Tests:${name}`).join(' ');\r\n// \tconst cmd = `vstest.console.exe \"${testDll}\" ${testsArg}`;\r\n// \texecCommand(cmd);\r\n// }\r\n\r\nexport function runTestCommand(args: string[]): Promise<any> {\r\n\tconst workDir = getTmpCacheDir(TestCacheDir);\r\n\treturn runSpawn(`${vstestPath}`, args, workDir, testErrorHandler, testCloseHandler);\r\n}\r\n\r\nexport function testErrorHandler(error) {\r\n\tconsole.error(`testErrorHandler - failed: ${error.message}`);\r\n\treturn ({ success: false });\r\n}\r\n\r\nexport function testCloseHandler(code, stdout, stderr) {\r\n\tif (code !== 0) {\r\n\t\tconsole.error(`vstest failed with exit code ${code}`);\r\n\t\tconst testResult = parseVSTestOutput(stdout);\r\n\t\tconst formatedVSTestResult = formatVSTestResultToMarkdown(testResult);\r\n\t\tif (!formatVSTestResultToMarkdown) {\r\n\t\t\t// case: .NET version is not correct! like You must install or update .NET to run this application...\r\n\t\t\tconsole.error(`Failed to parse vstest output: ${stdout}`);\r\n\t\t}\r\n\t\treturn { success: false, message: formatedVSTestResult, testResult };\r\n\t}\r\n\tif (stderr) {\r\n\t\tconsole.error(`STDERR:\\n${stdout}`);\r\n\t\treturn { success: false, message: stdout, testResult: null };\r\n\t}\r\n\r\n\tconsole.log(`vstest succeeded`);\r\n\treturn { success: true, message: stdout, testResult: null };\r\n}\r\n\r\n\r\n\r\n// runTestClass('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Tests.Weather.Plugin.AudienceResponseParserTests');\r\n// FullyQualifiedName~SharedSegments.Tests.Weather.Eplant.EplantMeResponseBuilderTest\r\n// setupSignalHandlers();\r\n// runTestClass('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Tests.Weather.Eplant.EplantMeResponseBuilderTest').then(result => {\r\n// \tconsole.log('Test Class Result:', result.success, result.message);\r\n// });\r\n// runSingleTestMethod('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Tests.Weather.Plugin.AudienceResponseParserTests.ResponseParserTests');\r\n\r\n// vstest.console.exe \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll\" /TestCaseFilter:\"FullyQualifiedName~${className}\"\r\n// vstest.console.exe \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll\" /Tests:SqmidHelperTests.GetSqmidFromCookie_ValidCookie_ReturnsDecodedBlisId\r\n// ./vstest.console.exe \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll\" /Tests:SharedSegments.Tests.Weather.Eplant.SqmidHelperTests.GetSqmidFromCookie_ValidCookie_ReturnsDecodedBlisId\r\n// .\\vstestexe.cmd \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll\" /Tests:SharedSegments.Tests.Weather.Eplant.SqmidHelperTests.GetSqmidFromCookie_ValidCookie_ReturnsDecodedBlisId\r\n//.\\vstestexe.cmd \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll\" /TestCaseFilter:\"FullyQualifiedName~SharedSegments.Tests.Weather.Eplant.SqmidHelperTests\"\r\n\r\n// runTestClass('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Tests.Weather.Eplant.SqmidHelperTests').then(result => {\r\n// \tconsole.log('Test Class Result:', result.success, result.message);\r\n// });\r\n// runSingleTestMethod('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Tests.Weather.Eplant.SqmidHelperTests.GetSqmidFromCookie_MissingUsrLocCookie_ReturnsEmptyString')\r\n// runSingleTestMethod('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Tests.Weather.Eplant.SqmidHelperTests.GetSqmidFromCookie_InvalidBase64Bid_ReturnsEmptyString');\r\n// runTestClass('D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\bin\\\\Debug\\\\SharedSegments.Tests.dll', 'SharedSegments.Plugins.Tests.Workflows.Eplant.Conditions.EplantRequestCategoryConditionTests').then(result => {\r\n// \tconsole.log('Test Class Result:', result.success, result.message);\r\n// });"]}
|