@ai-dev-tools/csharp-copilot-core 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai-dev-tools-csharp-copilot-core-0.0.19.tgz +0 -0
- package/azure-pipelines.yml +52 -0
- package/out/analyze/cecil.d.ts +1 -0
- package/out/analyze/cecil.js +42 -0
- package/out/analyze/cecil.js.map +1 -0
- package/out/analyze/checkCodeSyntax.d.ts +7 -0
- package/out/analyze/checkCodeSyntax.js +67 -0
- package/out/analyze/checkCodeSyntax.js.map +1 -0
- package/out/analyze/generateCodeDependency.d.ts +6 -0
- package/out/analyze/generateCodeDependency.js +122 -0
- package/out/analyze/generateCodeDependency.js.map +1 -0
- package/out/analyze/installAnalyzerTool.d.ts +1 -0
- package/out/analyze/installAnalyzerTool.js +82 -0
- package/out/analyze/installAnalyzerTool.js.map +1 -0
- package/out/atmpCache/deps/EplantRequestCategoryCondition_Conditions_Eplant_Workflows_SharedSegmentsPlugins_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +281 -0
- package/out/atmpCache/deps/IdentitySelectAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/deps/SqmidHelperTests_Utils_HttpRequestParser_Overview_Workflows_SharedSegmentsTests_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +1 -0
- package/out/atmpCache/deps/SqmidHelper_Utils_HttpRequestParser_Overview_Workflows_SharedSegmentsPlugins_SharedSegments_SharedSegments_CSServiceFundamental_code_D.deps +1 -0
- package/out/atmpCache/deps/ToListCountAnalyzerTests_ToListinatorTests_test_AIUnitTestExample_code_d.deps +4037 -0
- package/out/atmpCache/deps/ToListCountAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/deps/ToListCountCodeFixProvider_ToListinatorCodeFixes_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/deps/ToListForEachAnalyzer_ToListinatorAnalyzers_src_AIUnitTestExample_code_d.deps +1 -0
- package/out/atmpCache/dllref/ToListinatorTests_ToListinatorTests_test_AIUnitTestExample_code_d.dllref +202 -0
- package/out/batch/generateCodeTests.d.ts +6 -0
- package/out/batch/generateCodeTests.js +147 -0
- package/out/batch/generateCodeTests.js.map +1 -0
- package/out/batch/getFolderCodeFile.d.ts +1 -0
- package/out/batch/getFolderCodeFile.js +19 -0
- package/out/batch/getFolderCodeFile.js.map +1 -0
- package/out/batch/getProjectCodeFile.d.ts +4 -0
- package/out/batch/getProjectCodeFile.js +87 -0
- package/out/batch/getProjectCodeFile.js.map +1 -0
- package/out/batch/getSolutionCodeFile.d.ts +8 -0
- package/out/batch/getSolutionCodeFile.js +70 -0
- package/out/batch/getSolutionCodeFile.js.map +1 -0
- package/out/benchmark/formatToMarkdown.d.ts +2 -0
- package/out/benchmark/formatToMarkdown.js +101 -0
- package/out/benchmark/formatToMarkdown.js.map +1 -0
- package/out/benchmark/generateBenchmarkReport.d.ts +1 -0
- package/out/benchmark/generateBenchmarkReport.js +82 -0
- package/out/benchmark/generateBenchmarkReport.js.map +1 -0
- package/out/codeCoverage/codeCoverage.d.ts +6 -0
- package/out/codeCoverage/codeCoverage.js +35 -0
- package/out/codeCoverage/codeCoverage.js.map +1 -0
- package/out/codeCoverage/codeCoverageReport.d.ts +6 -0
- package/out/codeCoverage/codeCoverageReport.js +72 -0
- package/out/codeCoverage/codeCoverageReport.js.map +1 -0
- package/out/codeCoverage/extractCodeCoverageInfo.d.ts +2 -0
- package/out/codeCoverage/extractCodeCoverageInfo.js +80 -0
- package/out/codeCoverage/extractCodeCoverageInfo.js.map +1 -0
- package/out/codeCoverage/generateCodeCoverageReport.d.ts +1 -0
- package/out/codeCoverage/generateCodeCoverageReport.js +27 -0
- package/out/codeCoverage/generateCodeCoverageReport.js.map +1 -0
- package/out/codeCoverage/getCodeCoverageSetting.d.ts +1 -0
- package/out/codeCoverage/getCodeCoverageSetting.js +58 -0
- package/out/codeCoverage/getCodeCoverageSetting.js.map +1 -0
- package/out/codeCoverage/reportTool.d.ts +2 -0
- package/out/codeCoverage/reportTool.js +22 -0
- package/out/codeCoverage/reportTool.js.map +1 -0
- package/out/codeCoverage/simplifyCoverageXml.d.ts +2 -0
- package/out/codeCoverage/simplifyCoverageXml.js +116 -0
- package/out/codeCoverage/simplifyCoverageXml.js.map +1 -0
- package/out/codebk/250804prompt/buildAfGuidelines.liquid +15 -0
- package/out/codebk/250804prompt/general/generalBuildAutofixGuidelines.liquid +13 -0
- package/out/codebk/250804prompt/general/generalUtGuidelines.liquid +18 -0
- package/out/codebk/250804prompt/generateUtAutoFix.liquid +19 -0
- package/out/codebk/250804prompt/generateUtGuidelines.liquid +13 -0
- package/out/codebk/250804prompt/generateUtSystem.liquid +5 -0
- package/out/codebk/250804prompt/generateUtUserInput.liquid +27 -0
- package/out/codebk/250804prompt/testAfGuidelines.liquid +6 -0
- package/out/codebk/250804prompt/xap/xapBuildAutofixGuidelines.liquid +13 -0
- package/out/codebk/250804prompt/xap/xapCodeCodeDependency.liquid +0 -0
- package/out/codebk/250804prompt/xap/xapCodeSample.liquid +38 -0
- package/out/codebk/250804prompt/xap/xapUtGuideline-240804.liquid +36 -0
- package/out/codebk/250804prompt/xap/xapUtGuideline.liquid +36 -0
- package/out/codebk/childProcessManager.d.ts +1 -0
- package/out/codebk/childProcessManager.js +50 -0
- package/out/codebk/childProcessManager.js.map +1 -0
- package/out/codebk/msBuidSpawn.d.ts +1 -0
- package/out/codebk/msBuidSpawn.js +58 -0
- package/out/codebk/msBuidSpawn.js.map +1 -0
- package/out/codebk/msBuild.d.ts +1 -0
- package/out/codebk/msBuild.js +123 -0
- package/out/codebk/msBuild.js.map +1 -0
- package/out/codebk/old/generateXapTestAutoFix.liquid +12 -0
- package/out/codebk/old/generateXapTestGuidelines-fm.liquid +68 -0
- package/out/codebk/old/generateXapTestGuidelines.liquid +28 -0
- package/out/codebk/old/xapGuideline-fm.liquid +149 -0
- package/out/codebk/old/xapGuideline.liquid +37 -0
- package/out/codebk/oldExec/checkCodeSyntax.d.ts +1 -0
- package/out/codebk/oldExec/checkCodeSyntax.js +81 -0
- package/out/codebk/oldExec/checkCodeSyntax.js.map +1 -0
- package/out/codebk/oldExec/codeCoverage.d.ts +1 -0
- package/out/codebk/oldExec/codeCoverage.js +54 -0
- package/out/codebk/oldExec/codeCoverage.js.map +1 -0
- package/out/codebk/oldExec/codeCoverageReport.d.ts +1 -0
- package/out/codebk/oldExec/codeCoverageReport.js +64 -0
- package/out/codebk/oldExec/codeCoverageReport.js.map +1 -0
- package/out/codebk/oldExec/containsMethods.d.ts +1 -0
- package/out/codebk/oldExec/containsMethods.js +74 -0
- package/out/codebk/oldExec/containsMethods.js.map +1 -0
- package/out/codebk/oldExec/generateCodeDependency.d.ts +1 -0
- package/out/codebk/oldExec/generateCodeDependency.js +95 -0
- package/out/codebk/oldExec/generateCodeDependency.js.map +1 -0
- package/out/codebk/oldExec/msBuild.d.ts +1 -0
- package/out/codebk/oldExec/msBuild.js +53 -0
- package/out/codebk/oldExec/msBuild.js.map +1 -0
- package/out/codebk/oldExec/vsTest.d.ts +1 -0
- package/out/codebk/oldExec/vsTest.js +71 -0
- package/out/codebk/oldExec/vsTest.js.map +1 -0
- package/out/codebk/prompts/general/generalUnitTestGuidelines-20250702.liquid +56 -0
- package/out/codebk/prompts/generateXapTestGuidelines-20250704.liquid +21 -0
- package/out/codebk/prompts/generateXapTestGuidelines-o.liquid +29 -0
- package/out/codebk/prompts/xap/xapGuideline-o.liquid +45 -0
- package/out/codebk/testbuildkill.d.ts +1 -0
- package/out/codebk/testbuildkill.js +37 -0
- package/out/codebk/testbuildkill.js.map +1 -0
- package/out/command/index.d.ts +2 -0
- package/out/command/index.js +85 -0
- package/out/command/index.js.map +1 -0
- package/out/command/utGenWrapper.d.ts +3 -0
- package/out/command/utGenWrapper.js +40 -0
- package/out/command/utGenWrapper.js.map +1 -0
- package/out/exit/childProcessManager.d.ts +2 -0
- package/out/exit/childProcessManager.js +43 -0
- package/out/exit/childProcessManager.js.map +1 -0
- package/out/exit/setupProcessSignalHandler.d.ts +1 -0
- package/out/exit/setupProcessSignalHandler.js +18 -0
- package/out/exit/setupProcessSignalHandler.js.map +1 -0
- package/out/gen/autoFix.d.ts +4 -0
- package/out/gen/autoFix.js +125 -0
- package/out/gen/autoFix.js.map +1 -0
- package/out/gen/csharpUtGen.d.ts +2 -0
- package/out/gen/csharpUtGen.js +151 -0
- package/out/gen/csharpUtGen.js.map +1 -0
- package/out/gen/ensureValidLLMResponse.d.ts +1 -0
- package/out/gen/ensureValidLLMResponse.js +19 -0
- package/out/gen/ensureValidLLMResponse.js.map +1 -0
- package/out/gen/postGen/extractCodeFromResponse.d.ts +1 -0
- package/out/gen/postGen/extractCodeFromResponse.js +37 -0
- package/out/gen/postGen/extractCodeFromResponse.js.map +1 -0
- package/out/gen/postGen/postGenProcess.d.ts +1 -0
- package/out/gen/postGen/postGenProcess.js +36 -0
- package/out/gen/postGen/postGenProcess.js.map +1 -0
- package/out/gen/postGen/removeComments.d.ts +1 -0
- package/out/gen/postGen/removeComments.js +92 -0
- package/out/gen/postGen/removeComments.js.map +1 -0
- package/out/gen/postGen/removeSingleLines.d.ts +1 -0
- package/out/gen/postGen/removeSingleLines.js +28 -0
- package/out/gen/postGen/removeSingleLines.js.map +1 -0
- package/out/gen/postGen/repairRequiredNameSpaces.d.ts +1 -0
- package/out/gen/postGen/repairRequiredNameSpaces.js +116 -0
- package/out/gen/postGen/repairRequiredNameSpaces.js.map +1 -0
- package/out/gen/postGen/validateTestCode.d.ts +1 -0
- package/out/gen/postGen/validateTestCode.js +14 -0
- package/out/gen/postGen/validateTestCode.js.map +1 -0
- package/out/gen/preGen/excludeFileName.d.ts +1 -0
- package/out/gen/preGen/excludeFileName.js +49 -0
- package/out/gen/preGen/excludeFileName.js.map +1 -0
- package/out/gen/preGen/excludeSpecificTag.d.ts +1 -0
- package/out/gen/preGen/excludeSpecificTag.js +18 -0
- package/out/gen/preGen/excludeSpecificTag.js.map +1 -0
- package/out/gen/preGen/preGenProcess.d.ts +1 -0
- package/out/gen/preGen/preGenProcess.js +22 -0
- package/out/gen/preGen/preGenProcess.js.map +1 -0
- package/out/gen/preGen/validateCode.d.ts +3 -0
- package/out/gen/preGen/validateCode.js +62 -0
- package/out/gen/preGen/validateCode.js.map +1 -0
- package/out/index.d.ts +2 -0
- package/out/index.js +8 -0
- package/out/index.js.map +1 -0
- package/out/llm/model/Gpt4o.d.ts +1 -0
- package/out/llm/model/Gpt4o.js +91 -0
- package/out/llm/model/Gpt4o.js.map +1 -0
- package/out/llm/model/claude4.d.ts +1 -0
- package/out/llm/model/claude4.js +3 -0
- package/out/llm/model/claude4.js.map +1 -0
- package/out/llm/preparePrompt.d.ts +2 -0
- package/out/llm/preparePrompt.js +110 -0
- package/out/llm/preparePrompt.js.map +1 -0
- package/out/llm/prompt/buildAfGuidelines.liquid +15 -0
- package/out/llm/prompt/general/generalBuildAutofixGuidelines.liquid +13 -0
- package/out/llm/prompt/general/generalUtGuidelines.liquid +16 -0
- package/out/llm/prompt/generateUtAutoFix.liquid +19 -0
- package/out/llm/prompt/generateUtDependency.liquid +3 -0
- package/out/llm/prompt/generateUtGuidelines.liquid +29 -0
- package/out/llm/prompt/generateUtSystem.liquid +5 -0
- package/out/llm/prompt/generateUtTemplate.liquid +30 -0
- package/out/llm/prompt/generateUtUserInput.liquid +4 -0
- package/out/llm/prompt/testAfGuidelines.liquid +6 -0
- package/out/llm/prompt/userCustomPrompt.liquid +0 -0
- package/out/llm/prompt/xap/xapBuildAutofixGuidelines.liquid +13 -0
- package/out/llm/prompt/xap/xapCodeCodeDependency.liquid +0 -0
- package/out/llm/prompt/xap/xapCodeSample.liquid +38 -0
- package/out/llm/prompt/xap/xapUtGuideline-240804.liquid +36 -0
- package/out/llm/prompt/xap/xapUtGuideline.liquid +37 -0
- package/out/llm/sendRequestToLLM.d.ts +4 -0
- package/out/llm/sendRequestToLLM.js +12 -0
- package/out/llm/sendRequestToLLM.js.map +1 -0
- package/out/llm/sendRequestToSelfHostLLM.d.ts +4 -0
- package/out/llm/sendRequestToSelfHostLLM.js +41 -0
- package/out/llm/sendRequestToSelfHostLLM.js.map +1 -0
- package/out/metrics/appInsightTelemetry.d.ts +6 -0
- package/out/metrics/appInsightTelemetry.js +77 -0
- package/out/metrics/appInsightTelemetry.js.map +1 -0
- package/out/metrics/machineId.d.ts +11 -0
- package/out/metrics/machineId.js +85 -0
- package/out/metrics/machineId.js.map +1 -0
- package/out/setup/setup.d.ts +1 -0
- package/out/setup/setup.js +10 -0
- package/out/setup/setup.js.map +1 -0
- package/out/setup/setupConsole.d.ts +1 -0
- package/out/setup/setupConsole.js +23 -0
- package/out/setup/setupConsole.js.map +1 -0
- package/out/setup/setupLLMRequest.d.ts +2 -0
- package/out/setup/setupLLMRequest.js +10 -0
- package/out/setup/setupLLMRequest.js.map +1 -0
- package/out/tools/devenvcom.cmd +13 -0
- package/out/tools/devenvexe.cmd +13 -0
- package/out/tools/msbuildexe.cmd +13 -0
- package/out/tools/vstestexe.cmd +13 -0
- package/out/types/benchmark.d.ts +11 -0
- package/out/types/benchmark.js +3 -0
- package/out/types/benchmark.js.map +1 -0
- package/out/types/buildResult.d.ts +8 -0
- package/out/types/buildResult.js +3 -0
- package/out/types/buildResult.js.map +1 -0
- package/out/types/constants.d.ts +3 -0
- package/out/types/constants.js +7 -0
- package/out/types/constants.js.map +1 -0
- package/out/types/genResult.d.ts +10 -0
- package/out/types/genResult.js +3 -0
- package/out/types/genResult.js.map +1 -0
- package/out/types/testResult.d.ts +12 -0
- package/out/types/testResult.js +3 -0
- package/out/types/testResult.js.map +1 -0
- package/out/types/verifyResult.d.ts +8 -0
- package/out/types/verifyResult.js +3 -0
- package/out/types/verifyResult.js.map +1 -0
- package/out/utils/checkTestProject.d.ts +2 -0
- package/out/utils/checkTestProject.js +79 -0
- package/out/utils/checkTestProject.js.map +1 -0
- package/out/utils/checkXapCode.d.ts +2 -0
- package/out/utils/checkXapCode.js +59 -0
- package/out/utils/checkXapCode.js.map +1 -0
- package/out/utils/delay.d.ts +1 -0
- package/out/utils/delay.js +7 -0
- package/out/utils/delay.js.map +1 -0
- package/out/utils/detectTestFramework.d.ts +1 -0
- package/out/utils/detectTestFramework.js +32 -0
- package/out/utils/detectTestFramework.js.map +1 -0
- package/out/utils/fileUtils.d.ts +2 -0
- package/out/utils/fileUtils.js +42 -0
- package/out/utils/fileUtils.js.map +1 -0
- package/out/utils/generateCodeSha256.d.ts +1 -0
- package/out/utils/generateCodeSha256.js +46 -0
- package/out/utils/generateCodeSha256.js.map +1 -0
- package/out/utils/getCodeStructurePath.d.ts +5 -0
- package/out/utils/getCodeStructurePath.js +155 -0
- package/out/utils/getCodeStructurePath.js.map +1 -0
- package/out/utils/getOrCreateDir.d.ts +2 -0
- package/out/utils/getOrCreateDir.js +63 -0
- package/out/utils/getOrCreateDir.js.map +1 -0
- package/out/utils/getTestCodeInfo.d.ts +2 -0
- package/out/utils/getTestCodeInfo.js +121 -0
- package/out/utils/getTestCodeInfo.js.map +1 -0
- package/out/utils/getTestFile.d.ts +13 -0
- package/out/utils/getTestFile.js +295 -0
- package/out/utils/getTestFile.js.map +1 -0
- package/out/utils/parseBuildResult.d.ts +3 -0
- package/out/utils/parseBuildResult.js +44 -0
- package/out/utils/parseBuildResult.js.map +1 -0
- package/out/utils/parseSyntaxCheckResult.d.ts +2 -0
- package/out/utils/parseSyntaxCheckResult.js +38 -0
- package/out/utils/parseSyntaxCheckResult.js.map +1 -0
- package/out/utils/parseVstestResult.d.ts +3 -0
- package/out/utils/parseVstestResult.js +61 -0
- package/out/utils/parseVstestResult.js.map +1 -0
- package/out/utils/removeFailedTestMethods.d.ts +3 -0
- package/out/utils/removeFailedTestMethods.js +207 -0
- package/out/utils/removeFailedTestMethods.js.map +1 -0
- package/out/utils/runCommand.d.ts +1 -0
- package/out/utils/runCommand.js +14 -0
- package/out/utils/runCommand.js.map +1 -0
- package/out/utils/spawnExec.d.ts +1 -0
- package/out/utils/spawnExec.js +80 -0
- package/out/utils/spawnExec.js.map +1 -0
- package/out/utils/verifyBuildErrorCausedFile.d.ts +1 -0
- package/out/utils/verifyBuildErrorCausedFile.js +60 -0
- package/out/utils/verifyBuildErrorCausedFile.js.map +1 -0
- package/out/utils/verifyTestCode.d.ts +2 -0
- package/out/utils/verifyTestCode.js +25 -0
- package/out/utils/verifyTestCode.js.map +1 -0
- package/out/utils/writeGenCode.d.ts +1 -0
- package/out/utils/writeGenCode.js +50 -0
- package/out/utils/writeGenCode.js.map +1 -0
- package/out/vs/msBuild.d.ts +13 -0
- package/out/vs/msBuild.js +81 -0
- package/out/vs/msBuild.js.map +1 -0
- package/out/vs/vsTest.d.ts +15 -0
- package/out/vs/vsTest.js +107 -0
- package/out/vs/vsTest.js.map +1 -0
- package/out/vs/vsTools.d.ts +7 -0
- package/out/vs/vsTools.js +177 -0
- package/out/vs/vsTools.js.map +1 -0
- package/out/vsPlugin/getVsPluginVerifyResult.d.ts +2 -0
- package/out/vsPlugin/getVsPluginVerifyResult.js +41 -0
- package/out/vsPlugin/getVsPluginVerifyResult.js.map +1 -0
- package/out/vsPlugin/interactionConstants.d.ts +2 -0
- package/out/vsPlugin/interactionConstants.js +10 -0
- package/out/vsPlugin/interactionConstants.js.map +1 -0
- package/out/vsPlugin/sendStdToVsPlugin.d.ts +1 -0
- package/out/vsPlugin/sendStdToVsPlugin.js +12 -0
- package/out/vsPlugin/sendStdToVsPlugin.js.map +1 -0
- package/out/vsPlugin/stdListener.d.ts +3 -0
- package/out/vsPlugin/stdListener.js +57 -0
- package/out/vsPlugin/stdListener.js.map +1 -0
- package/package.json +33 -0
- package/tools/devenvcom.cmd +13 -0
- package/tools/devenvexe.cmd +13 -0
- package/tools/msbuildexe.cmd +13 -0
- package/tools/vstestexe.cmd +13 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCodeStructurePath.js","sourceRoot":"","sources":["../../src/utils/getC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CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,+HAA+H;IAC/H,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACnD,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CACrD,CAAC;IAEF,KAAK,MAAM,YAAY,IAAI,OAAO,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QAC1E,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YACzB,OAAO,OAAO,CAAC;QACnB,CAAC;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,MAAM,CAAC,CAAC;AAC/D,CAAC;AAED,SAAgB,eAAe,CAAC,UAAkB;IAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,yBAAyB,UAAU,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAEzD,OAAO,UAAU,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AAChD,CAAC;AAGD,0JAA0J;AAC1J,oDAAoD","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nimport { XMLParser } from 'fast-xml-parser';\r\n\r\nexport function getSourceFileProjectDir(sourceCodePath: string) {\r\n let currentDir = path.dirname(sourceCodePath);\r\n\r\n while (currentDir !== path.dirname(currentDir)) {\r\n const files = fs.readdirSync(currentDir);\r\n if (files.some(file => file.endsWith('.csproj'))) {\r\n return currentDir;\r\n }\r\n currentDir = path.dirname(currentDir);\r\n }\r\n\r\n // Check root directory\r\n const rootFiles = fs.readdirSync(currentDir);\r\n if (rootFiles.some(file => file.endsWith('.csproj'))) {\r\n return currentDir;\r\n }\r\n\r\n return null; // No .csproj file found\r\n}\r\n\r\nexport function getSourceFileCsprojFilePath(sourceCodePath: string) {\r\n let currentDir = path.dirname(sourceCodePath);\r\n\r\n while (currentDir !== path.dirname(currentDir)) {\r\n const files = fs.readdirSync(currentDir);\r\n const csprojFilePaths = files.filter(file => file.endsWith('.csproj'));\r\n if (csprojFilePaths?.length > 0) {\r\n return path.join(currentDir, csprojFilePaths[0]);\r\n }\r\n currentDir = path.dirname(currentDir);\r\n }\r\n\r\n // Check root directory\r\n const rootFiles = fs.readdirSync(currentDir);\r\n if (rootFiles.some(file => file.endsWith('.csproj'))) {\r\n return currentDir;\r\n }\r\n\r\n return null; // No .csproj file found\r\n}\r\n\r\n// export function getSourceFileProjectName(sourceCodePath: string) {\r\n// const projectPath = getSourceFileProjectPath(sourceCodePath);\r\n// if (!projectPath) {\r\n// console.warn(`No .csproj file found for ${sourceCodePath}`);\r\n// return null;\r\n// }\r\n\r\n// const projectName = path.basename(projectPath, '.csproj');\r\n// return projectName;\r\n// }\r\n\r\n// detect .git folder in the dir hierarchy of csFilePath, if exist, it's the code repo root\r\nexport function getCodeRepoRoot(csFilePath: string) {\r\n const rootDir = path.parse(csFilePath).root;\r\n let currentDir = path.dirname(csFilePath);;\r\n\r\n while (currentDir !== rootDir) {\r\n if (fs.existsSync(path.join(currentDir, \".git\"))) {\r\n return currentDir;\r\n }\r\n currentDir = path.dirname(currentDir);\r\n }\r\n\r\n console.log(`No .git folder found in the dir hierarchy of ${csFilePath}. Assuming root is ${rootDir}`);\r\n return rootDir;\r\n}\r\n\r\n// export function getTestProjectDll(testProjectPath: string) {\r\n// const testProjectDir = path.dirname(testProjectPath);\r\n// const testProjectName = path.basename(testProjectPath, '.csproj');\r\n// const dllName = `${testProjectName}.dll`;\r\n// const dllPath = path.join(testProjectDir, 'bin', 'Debug', dllName);\r\n// return dllPath;\r\n// }\r\n\r\n\r\nexport function getAssemblyName(csprojPath: string): string {\r\n const xmlContent = fs.readFileSync(csprojPath, \"utf-8\");\r\n const parser = new XMLParser();\r\n const parsed = parser.parse(xmlContent);\r\n\r\n const project = parsed.Project;\r\n if (!project) {\r\n throw new Error(\"can't parse .csproj 文件\");\r\n }\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.AssemblyName) {\r\n return group.AssemblyName;\r\n }\r\n }\r\n\r\n return path.basename(csprojPath, \".csproj\");\r\n}\r\n\r\nfunction getDllPath(outputDir: string, assemblyName: string): string {\r\n if (!fs.existsSync(outputDir)) {\r\n throw new Error(`The output dir doesn't exist: ${outputDir}`);\r\n }\r\n\r\n // xap dll path: \"D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\bin\\Debug\\SharedSegments.Tests.dll\"\r\n const dllPath = path.join(outputDir, `${assemblyName}.dll`);\r\n if (fs.existsSync(dllPath)) {\r\n return dllPath;\r\n }\r\n\r\n // general dll path: \"D:\\code\\ai-dev-tools\\csharp-ut-copilot\\CSharpAnalyzer\\CSharpAnalyzer\\bin\\Debug\\net8.0\\CSharpAnalyzer.dll\"\r\n const subdirs = fs.readdirSync(outputDir).filter((f) =>\r\n fs.statSync(path.join(outputDir, f)).isDirectory()\r\n );\r\n\r\n for (const frameworkDir of subdirs) {\r\n const dllPath = path.join(outputDir, frameworkDir, `${assemblyName}.dll`);\r\n if (fs.existsSync(dllPath)) {\r\n return dllPath;\r\n }\r\n }\r\n\r\n throw new Error(`can't get dll file: ${assemblyName}.dll`);\r\n}\r\n\r\nexport function getBuiltDllPath(csprojPath: string): string {\r\n if (!fs.existsSync(csprojPath)) {\r\n throw new Error(`csproj doesn't exist: ${csprojPath}`);\r\n }\r\n\r\n const assemblyName = getAssemblyName(csprojPath);\r\n const projectDir = path.dirname(csprojPath);\r\n const outputBase = path.join(projectDir, \"bin\", \"Debug\");\r\n\r\n return getDllPath(outputBase, assemblyName);\r\n}\r\n\r\n\r\n// const dllPath = getBuiltDllPath(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\SharedSegments.Tests.csproj\");\r\n// console.log(`Test project DLL path: ${dllPath}`);"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getOrCreateDir = getOrCreateDir;
|
|
37
|
+
exports.getTmpCacheDir = getTmpCacheDir;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const TMPCACHE = '../atmpCache';
|
|
41
|
+
function getOrCreateDir(dir) {
|
|
42
|
+
try {
|
|
43
|
+
// Check if directory exists
|
|
44
|
+
if (!fs.existsSync(dir)) {
|
|
45
|
+
// Create directory recursively
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
console.log(`Directory created: ${dir}`);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.log(`Directory already exists: ${dir}`);
|
|
51
|
+
}
|
|
52
|
+
return dir;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error('Error processing directory:', error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function getTmpCacheDir(dir) {
|
|
59
|
+
const tmpCacheDir = path.join(__dirname, TMPCACHE, dir);
|
|
60
|
+
const resolvedPath = path.resolve(tmpCacheDir);
|
|
61
|
+
return getOrCreateDir(resolvedPath);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=getOrCreateDir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrCreateDir.js","sourceRoot":"","sources":["../../src/utils/getOrCreateDir.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wCAcC;AAED,wCAIC;AAxBD,uCAAyB;AACzB,2CAA6B;AAE7B,MAAM,QAAQ,GAAG,cAAc,CAAC;AAChC,SAAgB,cAAc,CAAC,GAAW;IACtC,IAAI,CAAC;QACD,4BAA4B;QAC5B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,+BAA+B;YAC/B,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,sBAAsB,GAAG,EAAE,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACxD,CAAC;AACL,CAAC;AAED,SAAgB,cAAc,CAAC,GAAW;IACtC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IACxD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,OAAO,cAAc,CAAC,YAAY,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nconst TMPCACHE = '../atmpCache';\r\nexport function getOrCreateDir(dir: string) {\r\n try {\r\n // Check if directory exists\r\n if (!fs.existsSync(dir)) {\r\n // Create directory recursively\r\n fs.mkdirSync(dir, { recursive: true });\r\n console.log(`Directory created: ${dir}`);\r\n } else {\r\n console.log(`Directory already exists: ${dir}`);\r\n }\r\n return dir;\r\n } catch (error) {\r\n console.error('Error processing directory:', error);\r\n }\r\n}\r\n\r\nexport function getTmpCacheDir(dir: string) {\r\n const tmpCacheDir = path.join(__dirname, TMPCACHE, dir);\r\n const resolvedPath = path.resolve(tmpCacheDir);\r\n return getOrCreateDir(resolvedPath);\r\n}"]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getTestCodeNamespace = getTestCodeNamespace;
|
|
37
|
+
exports.getTestClassName = getTestClassName;
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const getCodeStructurePath_1 = require("./getCodeStructurePath");
|
|
40
|
+
// get test code namespace from source code path
|
|
41
|
+
function getTestCodeNamespace(sourceCodePath) {
|
|
42
|
+
const sourceFileProjectPath = (0, getCodeStructurePath_1.getSourceFileProjectDir)(sourceCodePath);
|
|
43
|
+
const projectName = path.basename(sourceFileProjectPath, '.csproj');
|
|
44
|
+
const sourceFileName = path.basename(sourceCodePath);
|
|
45
|
+
const codeFileDir = sourceCodePath.replace(sourceFileProjectPath, "").replace(sourceFileName, "").replace(/\\/g, ".");
|
|
46
|
+
const namespacePart = codeFileDir.slice(1, -1);
|
|
47
|
+
return `${projectName}.Tests.${namespacePart}`;
|
|
48
|
+
}
|
|
49
|
+
function getTestClassName(testCode) {
|
|
50
|
+
const namespaceMatch = testCode.match(/namespace\s+([a-zA-Z0-9_.]+)/);
|
|
51
|
+
const classMatch = testCode.match(/class\s+([a-zA-Z0-9_]+)/);
|
|
52
|
+
if (namespaceMatch && classMatch) {
|
|
53
|
+
return `${namespaceMatch[1]}.${classMatch[1]}`;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
// export function extractSucceedTestCode(filePath: string, failedMethods: string[]) {
|
|
58
|
+
// const inputLines = fs.readFileSync(filePath, 'utf-8').split(/\r?\n/);
|
|
59
|
+
// const outputLines: string[] = [];
|
|
60
|
+
// let i = 0;
|
|
61
|
+
// while (i < inputLines.length) {
|
|
62
|
+
// const trimmed = inputLines[i].trim();
|
|
63
|
+
// if (trimmed !== '[TestMethod]') {
|
|
64
|
+
// outputLines.push(inputLines[i]);
|
|
65
|
+
// i++;
|
|
66
|
+
// continue;
|
|
67
|
+
// }
|
|
68
|
+
// const methodLine = inputLines[i + 1];
|
|
69
|
+
// const match = methodLine?.match(/public\s+void\s+(\w+)\s*\(\)/);
|
|
70
|
+
// if (!match) {
|
|
71
|
+
// outputLines.push(inputLines[i]);
|
|
72
|
+
// i++;
|
|
73
|
+
// continue;
|
|
74
|
+
// }
|
|
75
|
+
// const methodName = match[1];
|
|
76
|
+
// if (!failedMethods.includes(methodName)) {
|
|
77
|
+
// outputLines.push(inputLines[i]); // [TestMethod]
|
|
78
|
+
// outputLines.push(inputLines[i + 1]); // public void ...
|
|
79
|
+
// i += 2;
|
|
80
|
+
// continue;
|
|
81
|
+
// }
|
|
82
|
+
// i += 2;
|
|
83
|
+
// let braceCount = 0;
|
|
84
|
+
// let methodStarted = false;
|
|
85
|
+
// while (i < inputLines.length) {
|
|
86
|
+
// const line = inputLines[i];
|
|
87
|
+
// if (!methodStarted) {
|
|
88
|
+
// if (line.includes('{')) {
|
|
89
|
+
// braceCount += (line.match(/{/g) || []).length;
|
|
90
|
+
// braceCount -= (line.match(/}/g) || []).length;
|
|
91
|
+
// methodStarted = true;
|
|
92
|
+
// }
|
|
93
|
+
// } else {
|
|
94
|
+
// braceCount += (line.match(/{/g) || []).length;
|
|
95
|
+
// braceCount -= (line.match(/}/g) || []).length;
|
|
96
|
+
// }
|
|
97
|
+
// i++;
|
|
98
|
+
// if (methodStarted && braceCount === 0) {
|
|
99
|
+
// break;
|
|
100
|
+
// }
|
|
101
|
+
// }
|
|
102
|
+
// while (i < inputLines.length && inputLines[i].trim() === '') {
|
|
103
|
+
// i++;
|
|
104
|
+
// }
|
|
105
|
+
// const nextLine = inputLines[i]?.trim();
|
|
106
|
+
// if (nextLine === '[TestMethod]') {
|
|
107
|
+
// outputLines.push('');
|
|
108
|
+
// }
|
|
109
|
+
// console.log(`✅ Removed method: ${methodName}`);
|
|
110
|
+
// }
|
|
111
|
+
// return outputLines.join('\n');
|
|
112
|
+
// }
|
|
113
|
+
// D:\code\CS.Service.Fundamental\SharedSegments\SharedSegments\SharedSegments.Plugins\Workflows\Overview\HttpRequestParser\Utils\SqmidHelper.cs
|
|
114
|
+
// const namespace = generateTestCodeNamespacce("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelper.cs", "test code");
|
|
115
|
+
// console.log(namespace); // Outputs: SharedSegments.Tests.SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils
|
|
116
|
+
// const code = fs.readFileSync("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelperTests.cs", 'utf-8');
|
|
117
|
+
// const classname = getTestClassName(code);
|
|
118
|
+
// console.log(classname); // Outputs: SharedSegments.Tests.SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils.SqmidHelperTests
|
|
119
|
+
// const testCode = extractSucceedTestCode("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelperTests.cs", ["GetSqmidFromCookie_InvalidBlisIdFormat_ReturnsEmptyString", "GetSqmidFromCookie_MissingUsrLocCookie_ReturnsEmptyString"]);
|
|
120
|
+
// console.log(testCode);
|
|
121
|
+
//# sourceMappingURL=getTestCodeInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTestCodeInfo.js","sourceRoot":"","sources":["../../src/utils/getTestCodeInfo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,oDAOC;AAED,4CASC;AAvBD,2CAA6B;AAE7B,iEAAiE;AAEjE,gDAAgD;AAChD,SAAgB,oBAAoB,CAAC,cAAsB;IACvD,MAAM,qBAAqB,GAAG,IAAA,8CAAuB,EAAC,cAAc,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE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;AACrE,qEAAqE;AACrE,4CAA4C;AAC5C,oBAAoB;AACpB,uBAAuB;AACvB,iEAAiE;AACjE,iEAAiE;AACjE,gBAAgB;AAEhB,mBAAmB;AACnB,uDAAuD;AACvD,yBAAyB;AACzB,gBAAgB;AAChB,YAAY;AAEZ,yEAAyE;AACzE,mBAAmB;AACnB,YAAY;AAEZ,kDAAkD;AAClD,6CAA6C;AAC7C,oCAAoC;AACpC,YAAY;AAEZ,0DAA0D;AAC1D,QAAQ;AAER,qCAAqC;AACrC,IAAI;AACJ,gJAAgJ;AAChJ,wNAAwN;AACxN,6HAA6H;AAC7H,uMAAuM;AACvM,4CAA4C;AAC5C,8IAA8I;AAE9I,qUAAqU;AACrU,yBAAyB","sourcesContent":["import * as path from 'path';\r\n\r\nimport { getSourceFileProjectDir } from \"./getCodeStructurePath\";\r\n\r\n// get test code namespace from source code path\r\nexport function getTestCodeNamespace(sourceCodePath: string): string {\r\n const sourceFileProjectPath = getSourceFileProjectDir(sourceCodePath);\r\n const projectName = path.basename(sourceFileProjectPath, '.csproj');\r\n const sourceFileName = path.basename(sourceCodePath);\r\n const codeFileDir = sourceCodePath.replace(sourceFileProjectPath, \"\").replace(sourceFileName, \"\").replace(/\\\\/g, \".\");\r\n const namespacePart = codeFileDir.slice(1, -1);\r\n return `${projectName}.Tests.${namespacePart}`;\r\n}\r\n\r\nexport function getTestClassName(testCode: string): string {\r\n const namespaceMatch = testCode.match(/namespace\\s+([a-zA-Z0-9_.]+)/);\r\n const classMatch = testCode.match(/class\\s+([a-zA-Z0-9_]+)/);\r\n\r\n if (namespaceMatch && classMatch) {\r\n return `${namespaceMatch[1]}.${classMatch[1]}`;\r\n }\r\n\r\n return null;\r\n}\r\n\r\n\r\n// export function extractSucceedTestCode(filePath: string, failedMethods: string[]) {\r\n// const inputLines = fs.readFileSync(filePath, 'utf-8').split(/\\r?\\n/);\r\n// const outputLines: string[] = [];\r\n\r\n// let i = 0;\r\n// while (i < inputLines.length) {\r\n// const trimmed = inputLines[i].trim();\r\n\r\n// if (trimmed !== '[TestMethod]') {\r\n// outputLines.push(inputLines[i]);\r\n// i++;\r\n// continue;\r\n// }\r\n\r\n// const methodLine = inputLines[i + 1];\r\n// const match = methodLine?.match(/public\\s+void\\s+(\\w+)\\s*\\(\\)/);\r\n\r\n// if (!match) {\r\n// outputLines.push(inputLines[i]);\r\n// i++;\r\n// continue;\r\n// }\r\n\r\n// const methodName = match[1];\r\n\r\n// if (!failedMethods.includes(methodName)) {\r\n// outputLines.push(inputLines[i]); // [TestMethod]\r\n// outputLines.push(inputLines[i + 1]); // public void ...\r\n// i += 2;\r\n// continue;\r\n// }\r\n\r\n// i += 2;\r\n// let braceCount = 0;\r\n// let methodStarted = false;\r\n\r\n// while (i < inputLines.length) {\r\n// const line = inputLines[i];\r\n// if (!methodStarted) {\r\n// if (line.includes('{')) {\r\n// braceCount += (line.match(/{/g) || []).length;\r\n// braceCount -= (line.match(/}/g) || []).length;\r\n// methodStarted = true;\r\n// }\r\n// } else {\r\n// braceCount += (line.match(/{/g) || []).length;\r\n// braceCount -= (line.match(/}/g) || []).length;\r\n// }\r\n\r\n// i++;\r\n// if (methodStarted && braceCount === 0) {\r\n// break;\r\n// }\r\n// }\r\n\r\n// while (i < inputLines.length && inputLines[i].trim() === '') {\r\n// i++;\r\n// }\r\n\r\n// const nextLine = inputLines[i]?.trim();\r\n// if (nextLine === '[TestMethod]') {\r\n// outputLines.push('');\r\n// }\r\n\r\n// console.log(`✅ Removed method: ${methodName}`);\r\n// }\r\n\r\n// return outputLines.join('\\n');\r\n// }\r\n// D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Overview\\HttpRequestParser\\Utils\\SqmidHelper.cs\r\n// const namespace = generateTestCodeNamespacce(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelper.cs\", \"test code\");\r\n// console.log(namespace); // Outputs: SharedSegments.Tests.SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils\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// const classname = getTestClassName(code);\r\n// console.log(classname); // Outputs: SharedSegments.Tests.SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils.SqmidHelperTests\r\n\r\n// const testCode = extractSucceedTestCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelperTests.cs\", [\"GetSqmidFromCookie_InvalidBlisIdFormat_ReturnsEmptyString\", \"GetSqmidFromCookie_MissingUsrLocCookie_ReturnsEmptyString\"]);\r\n// console.log(testCode);"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function getExistingTestFile(sourceCodePath: string): {
|
|
2
|
+
testFilePath: string;
|
|
3
|
+
testProjectPath: string;
|
|
4
|
+
};
|
|
5
|
+
export declare function createTestFile(sourceCodePath: string): {
|
|
6
|
+
testFilePath: string;
|
|
7
|
+
testProjectPath: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function getOrCreatTestFile(sourceCodePath: string, testFilePath: string, isXapCode: boolean): {
|
|
10
|
+
testFilePath: string;
|
|
11
|
+
testProjectPath: any;
|
|
12
|
+
testFileExist: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getExistingTestFile = getExistingTestFile;
|
|
37
|
+
exports.createTestFile = createTestFile;
|
|
38
|
+
exports.getOrCreatTestFile = getOrCreatTestFile;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const path = __importStar(require("path"));
|
|
41
|
+
const getCodeStructurePath_1 = require("./getCodeStructurePath");
|
|
42
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
43
|
+
const TEST_NAME_REGEX = /(Test|Tests)/i;
|
|
44
|
+
const TEST_ATTR_REGEX = /\[(Fact|Theory|TestClass|TestMethod|Test)\]/;
|
|
45
|
+
function findAllCsprojFiles(dir, excludedPaths) {
|
|
46
|
+
const results = [];
|
|
47
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
const fullPath = path.join(dir, entry.name);
|
|
50
|
+
if (entry.name === ".vs" || excludedPaths.includes(fullPath)) {
|
|
51
|
+
continue; // Skip excluded paths
|
|
52
|
+
}
|
|
53
|
+
if (entry.isDirectory()) {
|
|
54
|
+
results.push(...findAllCsprojFiles(fullPath, excludedPaths));
|
|
55
|
+
}
|
|
56
|
+
else if (entry.isFile() && entry.name.endsWith('.csproj')) {
|
|
57
|
+
results.push(fullPath);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
function isXapTestProject(csprojPath) {
|
|
63
|
+
try {
|
|
64
|
+
const content = fs.readFileSync(csprojPath, 'utf-8');
|
|
65
|
+
const parser = new fast_xml_parser_1.XMLParser({ ignoreAttributes: false, ignoreDeclaration: true });
|
|
66
|
+
const json = parser.parse(content);
|
|
67
|
+
const project = json.Project;
|
|
68
|
+
const propertyGroups = Array.isArray(project.PropertyGroup)
|
|
69
|
+
? project.PropertyGroup
|
|
70
|
+
: [project.PropertyGroup];
|
|
71
|
+
for (const group of propertyGroups) {
|
|
72
|
+
if (group.XapProjectType === 'TestProject') {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
console.error(`Failed to parse ${csprojPath}: ${err.message}`);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
function isGeneralTestProject(csprojPath) {
|
|
83
|
+
try {
|
|
84
|
+
const content = fs.readFileSync(csprojPath, 'utf-8');
|
|
85
|
+
// 1. package reference (test framework)
|
|
86
|
+
const referencesTestFramework = /<PackageReference\s+Include="(xunit|nunit|MSTest\.TestFramework|Microsoft\.NET\.Test\.Sdk)"/i.test(content);
|
|
87
|
+
// 2. file name *.Tests.csproj
|
|
88
|
+
const fileNameHasTests = (/\.Tests\.csproj$/i.test(path.basename(csprojPath))) || (/\.Test\.csproj$/i.test(path.basename(csprojPath)));
|
|
89
|
+
// 3. path contains Tests
|
|
90
|
+
const pathHasTests = /[\\/](Tests?|UnitTests?|IntegrationTests?)[\\/]/i.test(csprojPath);
|
|
91
|
+
// 4. Project SDK is test type (optional)
|
|
92
|
+
const sdkIsTestSdk = /<Project\s+Sdk="Microsoft\.NET\.Test\.Sdk"/i.test(content);
|
|
93
|
+
// 组合判断
|
|
94
|
+
return referencesTestFramework || sdkIsTestSdk || fileNameHasTests || pathHasTests;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
console.error(`⚠️ can't read csproj file: ${csprojPath}`);
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function isFalconUnitTestProject(csprojPath) {
|
|
102
|
+
const xmlContent = fs.readFileSync(csprojPath, 'utf-8');
|
|
103
|
+
const parser = new fast_xml_parser_1.XMLParser({
|
|
104
|
+
ignoreAttributes: false,
|
|
105
|
+
attributeNamePrefix: ''
|
|
106
|
+
});
|
|
107
|
+
const parsed = parser.parse(xmlContent);
|
|
108
|
+
// get PackageReference node
|
|
109
|
+
const project = parsed.Project;
|
|
110
|
+
const itemGroups = Array.isArray(project.ItemGroup) ? project.ItemGroup : [project.ItemGroup];
|
|
111
|
+
let isFalconUnitTestProject = false;
|
|
112
|
+
for (const group of itemGroups) {
|
|
113
|
+
const refs = group.PackageReference;
|
|
114
|
+
if (!refs)
|
|
115
|
+
continue;
|
|
116
|
+
// PackageReference
|
|
117
|
+
const refList = Array.isArray(refs) ? refs : [refs];
|
|
118
|
+
for (const ref of refList) {
|
|
119
|
+
if (ref.Include === 'Microsoft.Falcon.CodeAnalyzers') {
|
|
120
|
+
isFalconUnitTestProject = true;
|
|
121
|
+
console.log('Found Microsoft.Falcon.CodeAnalyzers');
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (isFalconUnitTestProject)
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
// if (!isFalconUnitTestProject) {
|
|
129
|
+
// console.log('Microsoft.Falcon.CodeAnalyzers not found');
|
|
130
|
+
// }
|
|
131
|
+
return isFalconUnitTestProject;
|
|
132
|
+
}
|
|
133
|
+
function isProjectNameMatchedTestProject(csprojPath, projectAssemblyName, projectName) {
|
|
134
|
+
const testProjectName = path.basename(csprojPath, '.csproj').toLowerCase();
|
|
135
|
+
const fileNameEndWithTests = testProjectName.endsWith('.tests') || testProjectName.endsWith('.test') || testProjectName.endsWith('.unittest') || testProjectName.endsWith('.unittests');
|
|
136
|
+
if (testProjectName.startsWith(projectName.toLowerCase()) && fileNameEndWithTests) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
const testProjectAssemblyName = (0, getCodeStructurePath_1.getAssemblyName)(csprojPath);
|
|
140
|
+
return testProjectAssemblyName?.toLowerCase()?.startsWith(projectAssemblyName.toLowerCase()) && fileNameEndWithTests;
|
|
141
|
+
}
|
|
142
|
+
function findTestProjectFromCsFile(csFilePath) {
|
|
143
|
+
let currentDir = path.dirname(csFilePath);
|
|
144
|
+
const repoRoot = (0, getCodeStructurePath_1.getCodeRepoRoot)(csFilePath);
|
|
145
|
+
const projectFilePath = (0, getCodeStructurePath_1.getSourceFileCsprojFilePath)(csFilePath);
|
|
146
|
+
const projectName = path.basename(projectFilePath, '.csproj');
|
|
147
|
+
const projectAssemblyName = (0, getCodeStructurePath_1.getAssemblyName)(projectFilePath);
|
|
148
|
+
const excludedPaths = [currentDir];
|
|
149
|
+
const repoRootParentPath = path.dirname(repoRoot);
|
|
150
|
+
// Start from the parent directory of the source file, because test project is usually in the parent directory
|
|
151
|
+
currentDir = path.dirname(currentDir);
|
|
152
|
+
while (currentDir !== repoRootParentPath) {
|
|
153
|
+
const csprojFiles = findAllCsprojFiles(currentDir, excludedPaths);
|
|
154
|
+
for (const csproj of csprojFiles) {
|
|
155
|
+
if (isProjectNameMatchedTestProject(csproj, projectAssemblyName, projectName)) {
|
|
156
|
+
return csproj;
|
|
157
|
+
}
|
|
158
|
+
else if (isXapTestProject(csproj)) {
|
|
159
|
+
return csproj;
|
|
160
|
+
}
|
|
161
|
+
else if (isFalconUnitTestProject(csproj)) {
|
|
162
|
+
const filename = path.basename(csproj, '.csproj').toLowerCase();
|
|
163
|
+
if (filename.endsWith('unittest') || filename.endsWith('unittests')) {
|
|
164
|
+
return csproj;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else if (isGeneralTestProject(csproj)) {
|
|
168
|
+
return csproj;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// Add current directory to excluded paths to avoid re-checking
|
|
172
|
+
excludedPaths.push(currentDir);
|
|
173
|
+
currentDir = path.dirname(currentDir);
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
function findPossibleTestFiles(testProjectDir, className) {
|
|
178
|
+
const results = [];
|
|
179
|
+
const stack = [testProjectDir];
|
|
180
|
+
while (stack.length > 0) {
|
|
181
|
+
const currentDir = stack.pop();
|
|
182
|
+
const entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
if (entry.name === "bin" || entry.name === "obj") {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
188
|
+
if (entry.isDirectory()) {
|
|
189
|
+
stack.push(fullPath);
|
|
190
|
+
}
|
|
191
|
+
else if (entry.isFile() && entry.name.endsWith('.cs') && entry.name.includes(className)) {
|
|
192
|
+
results.push(fullPath);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return results;
|
|
197
|
+
}
|
|
198
|
+
function fileContainsTestAttributes(filePath) {
|
|
199
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
200
|
+
return TEST_ATTR_REGEX.test(content);
|
|
201
|
+
}
|
|
202
|
+
function getExistingTestFile(sourceCodePath) {
|
|
203
|
+
const absPath = path.resolve(sourceCodePath);
|
|
204
|
+
const testProjectPath = findTestProjectFromCsFile(absPath);
|
|
205
|
+
if (!testProjectPath) {
|
|
206
|
+
console.error(`No test project found for ${sourceCodePath}`);
|
|
207
|
+
return { testFilePath: null, testProjectPath: null };
|
|
208
|
+
}
|
|
209
|
+
const testProjectDir = path.dirname(testProjectPath);
|
|
210
|
+
const className = path.basename(sourceCodePath, '.cs');
|
|
211
|
+
const candidateFiles = findPossibleTestFiles(testProjectDir, className);
|
|
212
|
+
for (const testFilePath of candidateFiles) {
|
|
213
|
+
if (TEST_NAME_REGEX.test(path.basename(testFilePath))) {
|
|
214
|
+
return { testFilePath, testProjectPath };
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return { testFilePath: null, testProjectPath: testProjectPath };
|
|
218
|
+
}
|
|
219
|
+
function createXapTestProject(sourceCodePath) {
|
|
220
|
+
}
|
|
221
|
+
function createTestFile(sourceCodePath) {
|
|
222
|
+
const testProjectPath = findTestProjectFromCsFile(sourceCodePath);
|
|
223
|
+
if (!testProjectPath) {
|
|
224
|
+
console.error(`No test project found for ${sourceCodePath}`);
|
|
225
|
+
return { testFilePath: null, testProjectPath: null };
|
|
226
|
+
}
|
|
227
|
+
const sourceFileName = path.basename(sourceCodePath, '.cs');
|
|
228
|
+
const testFileName = `${sourceFileName}Tests.cs`;
|
|
229
|
+
const sourceFileProjectPath = (0, getCodeStructurePath_1.getSourceFileProjectDir)(sourceCodePath);
|
|
230
|
+
const sourceFileDir = path.dirname(sourceCodePath);
|
|
231
|
+
const testFileRelativePath = sourceFileDir.replace(sourceFileProjectPath, "");
|
|
232
|
+
const testProjecDir = path.dirname(testProjectPath);
|
|
233
|
+
const testFilePath = path.join(testProjecDir, testFileRelativePath, testFileName);
|
|
234
|
+
const testFileDir = path.dirname(testFilePath);
|
|
235
|
+
// Create all missing directories recursively
|
|
236
|
+
fs.mkdirSync(testFileDir, { recursive: true });
|
|
237
|
+
console.log(`Created test file dir at ${testFilePath}`);
|
|
238
|
+
return { testFilePath, testProjectPath };
|
|
239
|
+
}
|
|
240
|
+
function getOrCreatTestFile(sourceCodePath, testFilePath, isXapCode) {
|
|
241
|
+
let finalTestFilePath = testFilePath;
|
|
242
|
+
let finalTestProjectPath;
|
|
243
|
+
let testFileExist = !!testFilePath && fs.existsSync(testFilePath);
|
|
244
|
+
// if outputPath param is not provided, try to find an existing test file
|
|
245
|
+
// if no existing test file found, create a new one in test project
|
|
246
|
+
if (!testFilePath || testFilePath.trim() === '') {
|
|
247
|
+
console.log(' Output path is missing. outputPath:', testFilePath, ', start looking for existing test project');
|
|
248
|
+
let result = getExistingTestFile(sourceCodePath);
|
|
249
|
+
if (result.testFilePath) {
|
|
250
|
+
testFileExist = true;
|
|
251
|
+
console.log(`Found existing test file: ${result.testFilePath}`);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
console.log('No existing test file found, creating a new one.');
|
|
255
|
+
result = createTestFile(sourceCodePath);
|
|
256
|
+
}
|
|
257
|
+
finalTestFilePath = result.testFilePath;
|
|
258
|
+
finalTestProjectPath = result.testProjectPath;
|
|
259
|
+
}
|
|
260
|
+
return { testFilePath: finalTestFilePath, testProjectPath: finalTestProjectPath, testFileExist };
|
|
261
|
+
}
|
|
262
|
+
// Example usage
|
|
263
|
+
// const csFilePath = "D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\LocationDetection\\AudienceResponseParser.cs";
|
|
264
|
+
// const csFilePath = "D:\\code\\msnews-experiences\\experiences\\weather-right-rail\\src\\WeatherRightRail.connector.ts";
|
|
265
|
+
// const testProjectPath = "D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Tests\\SharedSegments.Tests.csproj";
|
|
266
|
+
// if (!csFilePath) {
|
|
267
|
+
// console.error('Usage: ts-node findTestFile.ts path/to/your/file.cs');
|
|
268
|
+
// process.exit(1);
|
|
269
|
+
// }
|
|
270
|
+
// const start = Date.now();
|
|
271
|
+
// const testFilePath = getExistingTestFile(csFilePath);
|
|
272
|
+
// console.log(`Test file for ${csFilePath}:`, testFilePath ?? 'No test file found');
|
|
273
|
+
// console.log(`Search completed in ${(Date.now() - start) / 1000} seconds`);
|
|
274
|
+
// createXapTestFile(csFilePath);
|
|
275
|
+
// const repoDir = getCodeRepoRoot("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\LocationDetection\\AudienceResponseParser.cs");
|
|
276
|
+
// console.log(`Code repository root directory: ${repoDir}`);
|
|
277
|
+
// const result = getExistingTestFile("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Eplant\\EplantConfigManager.cs");
|
|
278
|
+
// console.log(`Test file path: ${result.testFilePath}`);
|
|
279
|
+
// console.log(`Test project path: ${result.testProjectPath}`);
|
|
280
|
+
// falcon test project
|
|
281
|
+
// const isFlaconUt = isFalconUnitTestProject("D:\\code\\WeatherNotification\\services\\WeatherUserInterest\\tests\\UnitTests\\Microsoft.Falcon.WeatherUserInterest.UnitTests.csproj");
|
|
282
|
+
// console.log(`Is Falcon Unit Test Project: ${isFlaconUt}`);
|
|
283
|
+
// const testProject = findTestProjectFromCsFile("D:\\code\\WeatherNotification\\services\\WeatherUserInterest\\src\\Service\\Microsoft.Falcon.WeatherUserInterest.csproj");
|
|
284
|
+
// console.log(`Test project path: ${testProject}`);
|
|
285
|
+
// const testFilePath = getOrCreatTestFile("D:\\code\\WeatherNotification\\services\\WeatherUserInterest\\src\\Service\\Components\\IUserInterestTable.cs", undefined, false);
|
|
286
|
+
// console.log(`Test file path: ${testFilePath.testFilePath}`);
|
|
287
|
+
// ads projects
|
|
288
|
+
// const testProjectPath = findTestProjectFromCsFile("D:\\code\\UCMDynamics\\private\\DynamicCode\\Plugin\\UCMDynamics.AppointmentPlugin\\AppointmentOperation.cs");
|
|
289
|
+
// console.log(`Test project path: ${testProjectPath}`);
|
|
290
|
+
// const isValid = isGeneralTestProject("D:\\code\\UCMDynamics\\private\\DynamicCode\\Plugin\\UcmDynamics.AppointmentPlugin\\UcmDynamics.AppointmentPlugin.csproj");
|
|
291
|
+
// // const isValid = isGeneralTestProject("D:\\code\\UCMDynamics\\private\\DynamicCode\\Plugin\\UcmDynamics.AppointmentPlugin.Tests\\UcmDynamics.AppointmentPlugin.Tests.csproj");
|
|
292
|
+
// console.log(`Is General Test Project: ${isValid}`);
|
|
293
|
+
// const testProjectPath = findTestProjectFromCsFile("D:\\code\\AIUnitTestExample\\src\\ToListinator.Analyzers\\ToListCountAnalyzer.cs");
|
|
294
|
+
// console.log(`Test project path: ${testProjectPath}`);
|
|
295
|
+
//# sourceMappingURL=getTestFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTestFile.js","sourceRoot":"","sources":["../../src/utils/getTestFile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8LA,kDAoBC;AAKD,wCAkBC;AAED,gDAsBC;AAjQD,uCAAyB;AACzB,2CAA6B;AAE7B,iEAAgI;AAEhI,qDAA4C;AAE5C,MAAM,eAAe,GAAG,eAAe,CAAC;AACxC,MAAM,eAAe,GAAG,6CAA6C,CAAC;AAEtE,SAAS,kBAAkB,CAAC,GAAW,EAAE,aAAuB;IAC5D,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7D,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,GA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qF;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}`);"]}
|