@ai-dev-tools/csharp-copilot-core 0.0.19 → 0.0.29
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 +174 -0
- package/devops/package.json +37 -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/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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateUtCode = generateUtCode;
|
|
4
4
|
exports.generateBatchUtCode = generateBatchUtCode;
|
|
5
|
+
exports.generateUtBenchmark = generateUtBenchmark;
|
|
5
6
|
exports.generateUtWithVsPlugin = generateUtWithVsPlugin;
|
|
6
7
|
const stdListener_1 = require("../vsPlugin/stdListener");
|
|
7
8
|
const constants_1 = require("../types/constants");
|
|
@@ -10,13 +11,18 @@ const csharpUtGen_1 = require("../gen/csharpUtGen");
|
|
|
10
11
|
async function generateUtCode(c) {
|
|
11
12
|
const autofix = c.autofix === 1;
|
|
12
13
|
const keepFailedTest = c.keepFailedTest === 1;
|
|
13
|
-
await (0, csharpUtGen_1.generateCsharpUtCode)(c.sourceCodePath, c.testCodePath, autofix, keepFailedTest, constants_1.
|
|
14
|
+
await (0, csharpUtGen_1.generateCsharpUtCode)(c.sourceCodePath, c.testCodePath, autofix, keepFailedTest, constants_1.CSHARPUTGEN, false, c.nugetPackagePath);
|
|
14
15
|
}
|
|
15
16
|
async function generateBatchUtCode(c) {
|
|
16
17
|
const autofix = c.autofix === 1;
|
|
17
18
|
const keepFailedTest = c.keepFailedTest === 1;
|
|
18
19
|
await (0, generateCodeTests_1.generateBatchTests)(c.sourceCodePath, autofix, keepFailedTest);
|
|
19
20
|
}
|
|
21
|
+
async function generateUtBenchmark(c) {
|
|
22
|
+
const autofix = c.autofix === 1;
|
|
23
|
+
const keepFailedTest = c.keepFailedTest === 1;
|
|
24
|
+
await (0, generateCodeTests_1.generateBatchTests)(c.sourceCodePath, autofix, keepFailedTest, true);
|
|
25
|
+
}
|
|
20
26
|
async function generateUtWithVsPlugin(c) {
|
|
21
27
|
try {
|
|
22
28
|
const autofix = c.autofix === 1;
|
|
@@ -24,7 +30,7 @@ async function generateUtWithVsPlugin(c) {
|
|
|
24
30
|
(0, stdListener_1.startStdListener)();
|
|
25
31
|
}
|
|
26
32
|
const keepFailedTest = c.keepFailedTest === 1;
|
|
27
|
-
await (0, csharpUtGen_1.generateCsharpUtCode)(c.sourceCodePath, c.testCodePath, autofix, keepFailedTest, constants_1.CSVSPLUGIN, true);
|
|
33
|
+
await (0, csharpUtGen_1.generateCsharpUtCode)(c.sourceCodePath, c.testCodePath, autofix, keepFailedTest, constants_1.CSVSPLUGIN, true, c.nugetPackagePath);
|
|
28
34
|
}
|
|
29
35
|
catch (error) {
|
|
30
36
|
console.error("Error generateUtWithVsPlugin:", error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utGenWrapper.js","sourceRoot":"","sources":["../../src/command/utGenWrapper.ts"],"names":[],"mappings":";;AAMA,wCAIC;AAED,kDAIC;AAED,wDAgBC;
|
|
1
|
+
{"version":3,"file":"utGenWrapper.js","sourceRoot":"","sources":["../../src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,cAAc,KAAK,CAAC,CAAC;QAC9C,MAAM,IAAA,kCAAoB,EAAC,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAU,EAAE,IAAI,EAAE,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAChI,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC;YAAS,CAAC;QACP,iDAAiD;QACjD,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,+BAAiB,EAAE,CAAC;YACvC,+BAAiB,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;IACL,CAAC;AACL,CAAC;AAGD,iNAAiN","sourcesContent":["import { readLineInterface, startStdListener } from \"../vsPlugin/stdListener\";\r\n\r\nimport { CSHARPUTGEN, CSVSPLUGIN } from \"../types/constants\";\r\nimport { generateBatchTests } from \"../batch/generateCodeTests\";\r\nimport { generateCsharpUtCode } from \"../gen/csharpUtGen\";\r\n\r\nexport async function generateUtCode(c) {\r\n const autofix = c.autofix === 1;\r\n const keepFailedTest = c.keepFailedTest === 1;\r\n await generateCsharpUtCode(c.sourceCodePath, c.testCodePath, autofix, keepFailedTest, CSHARPUTGEN, false, c.nugetPackagePath);\r\n}\r\n\r\nexport async function generateBatchUtCode(c) {\r\n const autofix = c.autofix === 1;\r\n const keepFailedTest = c.keepFailedTest === 1;\r\n await generateBatchTests(c.sourceCodePath, autofix, keepFailedTest);\r\n}\r\n\r\nexport async function generateUtBenchmark(c) {\r\n const autofix = c.autofix === 1;\r\n const keepFailedTest = c.keepFailedTest === 1;\r\n await generateBatchTests(c.sourceCodePath, autofix, keepFailedTest, true);\r\n}\r\n\r\nexport async function generateUtWithVsPlugin(c) {\r\n try {\r\n const autofix = c.autofix === 1;\r\n if (autofix) {\r\n startStdListener();\r\n }\r\n const keepFailedTest = c.keepFailedTest === 1;\r\n await generateCsharpUtCode(c.sourceCodePath, c.testCodePath, autofix, keepFailedTest, CSVSPLUGIN, true, c.nugetPackagePath);\r\n } catch (error) {\r\n console.error(\"Error generateUtWithVsPlugin:\", error);\r\n } finally {\r\n // Ensure the listener is closed after processing\r\n if (c.autofix === 1 && readLineInterface) {\r\n readLineInterface.close();\r\n }\r\n }\r\n}\r\n\r\n\r\n// generateUtCode({sourceCodePath: \"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelper.cs\", keepFailedTest: 1})"]}
|
package/out/gen/autoFix.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { GenResult } from "../types/genResult";
|
|
2
|
-
export declare function autoFixTestCode(prompts: any[], sourceCodePath: string, testCode: string, testProjectPath: string, testFilePath: string, isXapCode: boolean, isVsPlugin: boolean, retryTimes?: number, isBenchmark?: boolean): Promise<GenResult>;
|
|
3
|
-
export declare function generateAutoFixCode(prompts: any[], generatedCode: string, errorMessage: string, isBuildFailure: boolean, testFilePath: string, isXapCode: boolean): Promise<string>;
|
|
4
|
-
export declare function autoRetryTestCode(prompts: any[], sourceCodePath: string, testCode: string, testProjectPath: string, testFilePath: string, isXapCode: boolean, retryTimes?: number): Promise<GenResult>;
|
|
2
|
+
export declare function autoFixTestCode(prompts: any[], sourceCodePath: string, testCode: string, testProjectPath: string, testFilePath: string, testFramework: string, isXapCode: boolean, isVsPlugin: boolean, retryTimes?: number, isBenchmark?: boolean): Promise<GenResult>;
|
|
3
|
+
export declare function generateAutoFixCode(prompts: any[], generatedCode: string, errorMessage: string, isBuildFailure: boolean, testFilePath: string, testFramework: string, isXapCode: boolean): Promise<string>;
|
|
4
|
+
export declare function autoRetryTestCode(prompts: any[], sourceCodePath: string, testCode: string, testProjectPath: string, testFilePath: string, testFramework: string, isXapCode: boolean, retryTimes?: number): Promise<GenResult>;
|
package/out/gen/autoFix.js
CHANGED
|
@@ -12,7 +12,7 @@ const verifyTestCode_1 = require("../utils/verifyTestCode");
|
|
|
12
12
|
const getVsPluginVerifyResult_1 = require("../vsPlugin/getVsPluginVerifyResult");
|
|
13
13
|
const writeGenCode_1 = require("../utils/writeGenCode");
|
|
14
14
|
const fileUtils_1 = require("../utils/fileUtils");
|
|
15
|
-
async function autoFixTestCode(prompts, sourceCodePath, testCode, testProjectPath, testFilePath, isXapCode, isVsPlugin, retryTimes = 3, isBenchmark = false) {
|
|
15
|
+
async function autoFixTestCode(prompts, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, isVsPlugin, retryTimes = 3, isBenchmark = false) {
|
|
16
16
|
const startTime = Date.now();
|
|
17
17
|
let generatedCode = testCode;
|
|
18
18
|
let testResult;
|
|
@@ -26,9 +26,9 @@ async function autoFixTestCode(prompts, sourceCodePath, testCode, testProjectPat
|
|
|
26
26
|
// for case: generatedCode is invalid, just retry instead of auto fix process
|
|
27
27
|
if (!generatedCode) {
|
|
28
28
|
console.error(`Generated code is invalid, try to regenerate. \nGenerated code: \n${generatedCode}`);
|
|
29
|
-
generatedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompts, isXapCode);
|
|
29
|
+
generatedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompts, testFramework, isXapCode);
|
|
30
30
|
// extract valid code from LLM response
|
|
31
|
-
generatedCode = (0, postGenProcess_1.postGenProcess)(generatedCode, isXapCode);
|
|
31
|
+
generatedCode = (0, postGenProcess_1.postGenProcess)(generatedCode, testFramework, isXapCode);
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
// analyze generated code issue before verify: build, because build will cost much time.
|
|
@@ -73,7 +73,7 @@ async function autoFixTestCode(prompts, sourceCodePath, testCode, testProjectPat
|
|
|
73
73
|
console.error("!!!Verify process failed, retrying...");
|
|
74
74
|
continue;
|
|
75
75
|
}
|
|
76
|
-
generatedCode = await generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, isXapCode);
|
|
76
|
+
generatedCode = await generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, testFramework, isXapCode);
|
|
77
77
|
}
|
|
78
78
|
console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
79
79
|
return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };
|
|
@@ -94,17 +94,17 @@ async function verifyGeneratedCode(generatedCode, testProjectPath, testFilePath,
|
|
|
94
94
|
return verifyResult;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
async function generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, isXapCode) {
|
|
97
|
+
async function generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, testFramework, isXapCode) {
|
|
98
98
|
console.log("start auto-fix process...");
|
|
99
99
|
const autofixPrompt = (0, preparePrompt_1.prepareUtAutoFixPrompt)(prompts, generatedCode, errorMessage, isBuildFailure);
|
|
100
100
|
// get valid code from LLM response with retry
|
|
101
|
-
const newGeneratedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(autofixPrompt, isXapCode);
|
|
101
|
+
const newGeneratedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(autofixPrompt, testFramework, isXapCode);
|
|
102
102
|
// if generate code is valid, write test code to test project
|
|
103
103
|
!!newGeneratedCode && (0, fileUtils_1.writeTestCode)(newGeneratedCode, testFilePath);
|
|
104
104
|
return newGeneratedCode;
|
|
105
105
|
}
|
|
106
106
|
// use for quick dev test
|
|
107
|
-
async function autoRetryTestCode(prompts, sourceCodePath, testCode, testProjectPath, testFilePath, isXapCode, retryTimes = 3) {
|
|
107
|
+
async function autoRetryTestCode(prompts, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, retryTimes = 3) {
|
|
108
108
|
const startTime = Date.now();
|
|
109
109
|
let generatedCode = testCode;
|
|
110
110
|
let vsTestRes;
|
|
@@ -115,7 +115,7 @@ async function autoRetryTestCode(prompts, sourceCodePath, testCode, testProjectP
|
|
|
115
115
|
}
|
|
116
116
|
const autofixPrompt = prompts;
|
|
117
117
|
// get valid code from LLM response
|
|
118
|
-
generatedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(autofixPrompt, isXapCode);
|
|
118
|
+
generatedCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(autofixPrompt, testFramework, isXapCode);
|
|
119
119
|
// write test code to test project
|
|
120
120
|
(0, fileUtils_1.writeTestCode)(generatedCode, testFilePath);
|
|
121
121
|
}
|
package/out/gen/autoFix.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autoFix.js","sourceRoot":"","sources":["../../src/gen/autoFix.ts"],"names":[],"mappings":";;AAcA,0CA2FC;AAkBD,kDAkBC;AAID,8CA6BC;AA5KD,gEAA6D;AAC7D,qEAAkE;AAElE,6DAA0D;AAC1D,wDAA8D;AAE9D,oFAAiF;AACjF,4DAAyD;AACzD,iFAA+E;AAC/E,wDAAqD;AACrD,kDAAmD;AAE5C,KAAK,UAAU,eAAe,CACjC,OAAc,EACd,cAAsB,EACtB,QAAgB,EAChB,eAAuB,EACvB,YAAoB,EACpB,SAAkB,EAClB,UAAmB,EACnB,aAAqB,CAAC,EACtB,cAAuB,KAAK;IAE5B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,aAAa,GAAG,QAAQ,CAAC;IAC7B,IAAI,UAAU,CAAC;IACf,IAAI,WAAW,CAAC;IAChB,IAAI,YAAY,CAAC;IACjB,IAAI,cAAc,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;YACnC,2DAA2D;YAC3D,WAAW,IAAI,IAAA,2BAAY,EAAC,cAAc,EAAE,aAAa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G,CAAC,EAAE,CAAC,IAAI,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,uCAAuC,UAAU,YAAY,CAAC,CAAC;YAC7E,MAAM;QACV,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,CAAC;QAC9B,mCAAmC;QACnC,aAAa,GAAG,MAAM,IAAA,+CAAsB,EAAC,aAAa,EAAE,SAAS,CAAC,CAAC;QACvE,kCAAkC;QAClC,IAAA,yBAAa,EAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;IAExE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAClJ,CAAC","sourcesContent":["import { GenResult } from \"../types/genResult\";\r\nimport { VerifyResult } from \"../types/verifyResult\";\r\nimport { checkCodeSyntax } from \"../analyze/checkCodeSyntax\";\r\nimport { ensureValidLLMResponse } from \"./ensureValidLLMResponse\";\r\nimport { parseSyntaxCheckErrors } from \"../utils/parseSyntaxCheckResult\";\r\nimport { postGenProcess } from \"./postGen/postGenProcess\";\r\nimport { prepareUtAutoFixPrompt } from \"../llm/preparePrompt\";\r\nimport { sendRequestToLLM } from \"../llm/sendRequestToLLM\";\r\nimport { verifyBuildErrorCausedFile } from \"../utils/verifyBuildErrorCausedFile\";\r\nimport { verifyTestCode } from \"../utils/verifyTestCode\";\r\nimport { verifyTestCodeByVsPlugin } from \"../vsPlugin/getVsPluginVerifyResult\";\r\nimport { writeGenCode } from \"../utils/writeGenCode\";\r\nimport { writeTestCode } from \"../utils/fileUtils\";\r\n\r\nexport async function autoFixTestCode(\r\n prompts: any[],\r\n sourceCodePath: string,\r\n testCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n isXapCode: boolean,\r\n isVsPlugin: boolean,\r\n retryTimes: number = 3,\r\n isBenchmark: boolean = false\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n let generatedCode = testCode;\r\n let testResult;\r\n let buildResult;\r\n let errorMessage;\r\n let isBuildFailure = true;\r\n try {\r\n for (let i = 0; i <= retryTimes; i++) {\r\n // write generated code, to review and improve code quality\r\n isBenchmark && writeGenCode(sourceCodePath, generatedCode, i);\r\n\r\n // for case: generatedCode is invalid, just retry instead of auto fix process\r\n if (!generatedCode) {\r\n console.error(`Generated code is invalid, try to regenerate. \\nGenerated code: \\n${generatedCode}`);\r\n generatedCode = await ensureValidLLMResponse(prompts, isXapCode);\r\n // extract valid code from LLM response\r\n generatedCode = postGenProcess(generatedCode, isXapCode);\r\n continue;\r\n }\r\n\r\n // analyze generated code issue before verify: build, because build will cost much time.\r\n const syntaxResult = await checkCodeSyntax(testFilePath);\r\n if (syntaxResult.success) {\r\n // if generated code passed the syntax check, verify the generated test code\r\n // const { success, message, buildErrors, vsTestResult } = await verifyTestCode(generatedCode, testProjectPath);\r\n const verifyResult = await verifyGeneratedCode(generatedCode, testProjectPath, testFilePath, isVsPlugin);\r\n errorMessage = verifyResult.message;\r\n testResult = verifyResult.testResult;\r\n buildResult = verifyResult.buildErrors;\r\n isBuildFailure = !testResult;\r\n \r\n // if build errors caused by other code files instead of generate test code, abort generation\r\n const validBuildError = verifyBuildErrorCausedFile(testFilePath, buildResult);\r\n if (!validBuildError) {\r\n console.error(\"Due to build errors caused by other code files, abort generation, please fix it first.\");\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n }\r\n \r\n if (verifyResult.success) {\r\n console.log(\"XapUt code generated successfully\");\r\n return { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n }\r\n\r\n console.error(\"Failed to verifyTestCode, error:\", errorMessage);\r\n } else {\r\n buildResult = syntaxResult.buildErrors;\r\n errorMessage = syntaxResult.message;\r\n console.error(\"Failed to check the generated UT code syntax, error:\", errorMessage);\r\n }\r\n\r\n // keep test failed tast cases in test file automatically\r\n // if (!isBuildFailure && vsTestRes.passed !== 0) {\r\n // console.log(\"remove failed test cases in test file\");\r\n // removeFailedTestCasesInTestFile(vsTestRes, testCodePath);\r\n // return { success: true, testCode: generatedCode };\r\n // }\r\n\r\n if (i === retryTimes) {\r\n console.error(`Failed to generate ut code after ${retryTimes} attempts.`);\r\n break;\r\n }\r\n\r\n // case: vs plugin no response or msbuild/vstest failed.\r\n if (!buildResult && !testResult) {\r\n console.error(\"!!!Verify process failed, retrying...\");\r\n continue;\r\n }\r\n\r\n generatedCode = await generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, isXapCode);\r\n }\r\n\r\n console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);\r\n\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n } catch (error) {\r\n console.error(\"Error during auto-fix process:\", error);\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n\r\n }\r\n}\r\n\r\nasync function verifyGeneratedCode(\r\n generatedCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n isVsPlugin: boolean = false\r\n): Promise<VerifyResult> {\r\n if (isVsPlugin) {\r\n const vsVerifyResult = await verifyTestCodeByVsPlugin(testFilePath);\r\n return vsVerifyResult;\r\n } else {\r\n // verifyResult: { success, message, buildErrors, vsTestResult }\r\n const verifyResult = await verifyTestCode(generatedCode, testProjectPath);\r\n return verifyResult;\r\n }\r\n}\r\n\r\nexport async function generateAutoFixCode(\r\n prompts: any[],\r\n generatedCode: string,\r\n errorMessage: string,\r\n isBuildFailure: boolean,\r\n testFilePath: string,\r\n isXapCode: boolean\r\n): Promise<string> {\r\n console.log(\"start auto-fix process...\");\r\n const autofixPrompt = prepareUtAutoFixPrompt(prompts, generatedCode, errorMessage, isBuildFailure);\r\n\r\n // get valid code from LLM response with retry\r\n const newGeneratedCode = await ensureValidLLMResponse(autofixPrompt, isXapCode);\r\n\r\n // if generate code is valid, write test code to test project\r\n !!newGeneratedCode && writeTestCode(newGeneratedCode, testFilePath);\r\n\r\n return newGeneratedCode;\r\n}\r\n\r\n\r\n// use for quick dev test\r\nexport async function autoRetryTestCode(\r\n prompts: any[],\r\n sourceCodePath: string,\r\n testCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n isXapCode: boolean,\r\n retryTimes: number = 3\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n let generatedCode = testCode;\r\n let vsTestRes;\r\n for (let i = 0; i <= retryTimes; i++) {\r\n if (i === retryTimes) {\r\n console.error(`Failed to generate XapUt code after ${retryTimes} attempts.`);\r\n break;\r\n }\r\n\r\n const autofixPrompt = prompts;\r\n // get valid code from LLM response\r\n generatedCode = await ensureValidLLMResponse(autofixPrompt, isXapCode);\r\n // write test code to test project\r\n writeTestCode(generatedCode, testFilePath);\r\n }\r\n\r\n console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);\r\n\r\n return { success: true, testFilePath: testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: vsTestRes };\r\n}"]}
|
|
1
|
+
{"version":3,"file":"autoFix.js","sourceRoot":"","sources":["../../src/gen/autoFix.ts"],"names":[],"mappings":";;AAYA,0CA4FC;AAkBD,kDAmBC;AAID,8CA8BC;AA7KD,gEAA6D;AAC7D,qEAAkE;AAClE,6DAA0D;AAC1D,wDAA8D;AAC9D,oFAAiF;AACjF,4DAAyD;AACzD,iFAA+E;AAC/E,wDAAqD;AACrD,kDAAmD;AAE5C,KAAK,UAAU,eAAe,CACjC,OAAc,EACd,cAAsB,EACtB,QAAgB,EAChB,eAAuB,EACvB,YAAoB,EACpB,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["import { GenResult } from \"../types/genResult\";\r\nimport { VerifyResult } from \"../types/verifyResult\";\r\nimport { checkCodeSyntax } from \"../analyze/checkCodeSyntax\";\r\nimport { ensureValidLLMResponse } from \"./ensureValidLLMResponse\";\r\nimport { postGenProcess } from \"./postGen/postGenProcess\";\r\nimport { prepareUtAutoFixPrompt } from \"../llm/preparePrompt\";\r\nimport { verifyBuildErrorCausedFile } from \"../utils/verifyBuildErrorCausedFile\";\r\nimport { verifyTestCode } from \"../utils/verifyTestCode\";\r\nimport { verifyTestCodeByVsPlugin } from \"../vsPlugin/getVsPluginVerifyResult\";\r\nimport { writeGenCode } from \"../utils/writeGenCode\";\r\nimport { writeTestCode } from \"../utils/fileUtils\";\r\n\r\nexport async function autoFixTestCode(\r\n prompts: any[],\r\n sourceCodePath: string,\r\n testCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n testFramework: string,\r\n isXapCode: boolean,\r\n isVsPlugin: boolean,\r\n retryTimes: number = 3,\r\n isBenchmark: boolean = false\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n let generatedCode = testCode;\r\n let testResult;\r\n let buildResult;\r\n let errorMessage;\r\n let isBuildFailure = true;\r\n try {\r\n for (let i = 0; i <= retryTimes; i++) {\r\n // write generated code, to review and improve code quality\r\n isBenchmark && writeGenCode(sourceCodePath, generatedCode, i);\r\n\r\n // for case: generatedCode is invalid, just retry instead of auto fix process\r\n if (!generatedCode) {\r\n console.error(`Generated code is invalid, try to regenerate. \\nGenerated code: \\n${generatedCode}`);\r\n generatedCode = await ensureValidLLMResponse(prompts, testFramework, isXapCode);\r\n // extract valid code from LLM response\r\n generatedCode = postGenProcess(generatedCode, testFramework, isXapCode);\r\n continue;\r\n }\r\n\r\n // analyze generated code issue before verify: build, because build will cost much time.\r\n const syntaxResult = await checkCodeSyntax(testFilePath);\r\n if (syntaxResult.success) {\r\n // if generated code passed the syntax check, verify the generated test code\r\n // const { success, message, buildErrors, vsTestResult } = await verifyTestCode(generatedCode, testProjectPath);\r\n const verifyResult = await verifyGeneratedCode(generatedCode, testProjectPath, testFilePath, isVsPlugin);\r\n errorMessage = verifyResult.message;\r\n testResult = verifyResult.testResult;\r\n buildResult = verifyResult.buildErrors;\r\n isBuildFailure = !testResult;\r\n\r\n // if build errors caused by other code files instead of generate test code, abort generation\r\n const validBuildError = verifyBuildErrorCausedFile(testFilePath, buildResult);\r\n if (!validBuildError) {\r\n console.error(\"Due to build errors caused by other code files, abort generation, please fix it first.\");\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n }\r\n\r\n if (verifyResult.success) {\r\n console.log(\"XapUt code generated successfully\");\r\n return { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n }\r\n\r\n console.error(\"Failed to verifyTestCode, error:\", errorMessage);\r\n } else {\r\n buildResult = syntaxResult.buildErrors;\r\n errorMessage = syntaxResult.message;\r\n console.error(\"Failed to check the generated UT code syntax, error:\", errorMessage);\r\n }\r\n\r\n // keep test failed tast cases in test file automatically\r\n // if (!isBuildFailure && vsTestRes.passed !== 0) {\r\n // console.log(\"remove failed test cases in test file\");\r\n // removeFailedTestCasesInTestFile(vsTestRes, testCodePath);\r\n // return { success: true, testCode: generatedCode };\r\n // }\r\n\r\n if (i === retryTimes) {\r\n console.error(`Failed to generate ut code after ${retryTimes} attempts.`);\r\n break;\r\n }\r\n\r\n // case: vs plugin no response or msbuild/vstest failed.\r\n if (!buildResult && !testResult) {\r\n console.error(\"!!!Verify process failed, retrying...\");\r\n continue;\r\n }\r\n\r\n generatedCode = await generateAutoFixCode(prompts, generatedCode, errorMessage, isBuildFailure, testFilePath, testFramework, isXapCode);\r\n }\r\n\r\n console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);\r\n\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult, testResult };\r\n } catch (error) {\r\n console.error(\"Error during auto-fix process:\", error);\r\n return { success: false, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n\r\n }\r\n}\r\n\r\nasync function verifyGeneratedCode(\r\n generatedCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n isVsPlugin: boolean = false\r\n): Promise<VerifyResult> {\r\n if (isVsPlugin) {\r\n const vsVerifyResult = await verifyTestCodeByVsPlugin(testFilePath);\r\n return vsVerifyResult;\r\n } else {\r\n // verifyResult: { success, message, buildErrors, vsTestResult }\r\n const verifyResult = await verifyTestCode(generatedCode, testProjectPath);\r\n return verifyResult;\r\n }\r\n}\r\n\r\nexport async function generateAutoFixCode(\r\n prompts: any[],\r\n generatedCode: string,\r\n errorMessage: string,\r\n isBuildFailure: boolean,\r\n testFilePath: string,\r\n testFramework: string,\r\n isXapCode: boolean\r\n): Promise<string> {\r\n console.log(\"start auto-fix process...\");\r\n const autofixPrompt = prepareUtAutoFixPrompt(prompts, generatedCode, errorMessage, isBuildFailure);\r\n\r\n // get valid code from LLM response with retry\r\n const newGeneratedCode = await ensureValidLLMResponse(autofixPrompt, testFramework, isXapCode);\r\n\r\n // if generate code is valid, write test code to test project\r\n !!newGeneratedCode && writeTestCode(newGeneratedCode, testFilePath);\r\n\r\n return newGeneratedCode;\r\n}\r\n\r\n\r\n// use for quick dev test\r\nexport async function autoRetryTestCode(\r\n prompts: any[],\r\n sourceCodePath: string,\r\n testCode: string,\r\n testProjectPath: string,\r\n testFilePath: string,\r\n testFramework: string,\r\n isXapCode: boolean,\r\n retryTimes: number = 3\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n let generatedCode = testCode;\r\n let vsTestRes;\r\n for (let i = 0; i <= retryTimes; i++) {\r\n if (i === retryTimes) {\r\n console.error(`Failed to generate XapUt code after ${retryTimes} attempts.`);\r\n break;\r\n }\r\n\r\n const autofixPrompt = prompts;\r\n // get valid code from LLM response\r\n generatedCode = await ensureValidLLMResponse(autofixPrompt, testFramework, isXapCode);\r\n // write test code to test project\r\n writeTestCode(generatedCode, testFilePath);\r\n }\r\n\r\n console.log(`Autofix time: ${(Date.now() - startTime) / 1000} seconds`);\r\n\r\n return { success: true, testFilePath: testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: vsTestRes };\r\n}"]}
|
package/out/gen/csharpUtGen.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { GenResult } from '../types/genResult';
|
|
2
|
-
export declare function generateCsharpUtCode(sourceCodePath: string, testCodePath: string, enableAutoFix: boolean, keepFailedTests: boolean, source?: string, isBenchmark?: boolean): Promise<GenResult>;
|
|
2
|
+
export declare function generateCsharpUtCode(sourceCodePath: string, testCodePath: string, enableAutoFix: boolean, keepFailedTests: boolean, source?: string, isBenchmark?: boolean, nugetPackagePath?: string): Promise<GenResult>;
|
package/out/gen/csharpUtGen.js
CHANGED
|
@@ -50,7 +50,7 @@ const preparePrompt_1 = require("../llm/preparePrompt");
|
|
|
50
50
|
const removeFailedTestMethods_1 = require("../utils/removeFailedTestMethods");
|
|
51
51
|
const appInsightTelemetry_1 = require("../metrics/appInsightTelemetry");
|
|
52
52
|
const RETRYTIMES = 3;
|
|
53
|
-
async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix, keepFailedTests, source = constants_1.CSHARPUTGEN, isBenchmark = false) {
|
|
53
|
+
async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix, keepFailedTests, source = constants_1.CSHARPUTGEN, isBenchmark = false, nugetPackagePath = null) {
|
|
54
54
|
const startTime = Date.now();
|
|
55
55
|
console.log(`*****************Generating C# unit test code for: ${sourceCodePath}*****************`);
|
|
56
56
|
console.log(`Current work dir: ${process.cwd()}`);
|
|
@@ -72,20 +72,19 @@ async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix,
|
|
|
72
72
|
return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
|
|
73
73
|
}
|
|
74
74
|
// get code dependencies
|
|
75
|
-
let codeDependency = await (0, generateCodeDependency_1.generateCodeDependency)(sourceCodePath);
|
|
75
|
+
let codeDependency = await (0, generateCodeDependency_1.generateCodeDependency)(sourceCodePath, nugetPackagePath);
|
|
76
76
|
// detect existing test file or create a new one by source code path
|
|
77
77
|
const { testFilePath, testProjectPath, testFileExist } = (0, getTestFile_1.getOrCreatTestFile)(sourceCodePath, testCodePath, isXapCode);
|
|
78
78
|
if (!testFilePath || !testProjectPath) {
|
|
79
|
-
console.error(`Failed to get or create test file for source code: ${sourceCodePath}
|
|
79
|
+
console.error(`Failed to get or create test file for source code: ${sourceCodePath}. Please check if the test project exists.`);
|
|
80
80
|
return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
|
|
81
81
|
}
|
|
82
82
|
// get test framework
|
|
83
83
|
const testFramework = (0, detectTestFramework_1.detectTestFramework)(testProjectPath);
|
|
84
84
|
// prepare prompt
|
|
85
85
|
let prompt = (0, preparePrompt_1.prepareUtGenPrompt)(sourceCodePath, sourceCode, codeDependency, isXapCode, testFramework);
|
|
86
|
-
// let prompt = getPrompts(sourceCodePath, testFramework, codeDependency);
|
|
87
86
|
// call LLM service to gen code with retry
|
|
88
|
-
const testCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompt, isXapCode);
|
|
87
|
+
const testCode = await (0, ensureValidLLMResponse_1.ensureValidLLMResponse)(prompt, testFramework, isXapCode);
|
|
89
88
|
// write test code to test project
|
|
90
89
|
// To run vstest, need to write the test code to test project first, then build the test project and run the tests
|
|
91
90
|
(0, fileUtils_1.writeTestCode)(testCode, testFilePath);
|
|
@@ -93,11 +92,11 @@ async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix,
|
|
|
93
92
|
let autoFixResult = { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };
|
|
94
93
|
if (enableAutoFix) {
|
|
95
94
|
const isVsPlugin = source === constants_1.CSVSPLUGIN;
|
|
96
|
-
autoFixResult = await (0, autoFix_1.autoFixTestCode)(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);
|
|
95
|
+
autoFixResult = await (0, autoFix_1.autoFixTestCode)(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);
|
|
97
96
|
// autoFixResult = await autoRetryTestCode(prompt, sourceCode, testCode, testProjectPath, testFilePath, isXapTest);
|
|
98
97
|
}
|
|
99
98
|
if (autoFixResult.success) {
|
|
100
|
-
console.log(`
|
|
99
|
+
console.log(`Generate UT success time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
101
100
|
return autoFixResult;
|
|
102
101
|
}
|
|
103
102
|
// if retry max times or test generation failed, and keepFailedTests is false, delete failed test file or remove failed test methods
|
|
@@ -115,7 +114,7 @@ async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix,
|
|
|
115
114
|
else {
|
|
116
115
|
console.log(`keep failed test file: ${testFilePath}`);
|
|
117
116
|
}
|
|
118
|
-
console.log(`
|
|
117
|
+
console.log(`Generate UT failed time: ${(Date.now() - startTime) / 1000} seconds`);
|
|
119
118
|
return autoFixResult;
|
|
120
119
|
}
|
|
121
120
|
// generateCsharpUtCode("D:\\code\\IndexServe\\private\\indexserve\\RecommendationEngine\\RecoPS\\PSTableClient\\PSTableClient.cs", undefined, false, true, false);
|
|
@@ -123,29 +122,4 @@ async function generateCsharpUtCode(sourceCodePath, testCodePath, enableAutoFix,
|
|
|
123
122
|
// generateCsharpUtCode("D:\\code\\CS.Service.Fundamental\\SharedSegments\\SharedSegments\\SharedSegments.Plugins\\Workflows\\Eplant\\ResponseBuilders\\EplantMigrateResponseBuilder.cs", undefined, true, true, true);
|
|
124
123
|
// generateCsharpUtCode("D:\\code\\UCMDynamics\\private\\DynamicCode\\Plugin\\UCMDynamics.AppointmentPlugin\\AppointmentOperation.cs", undefined, false, true, false);
|
|
125
124
|
// generateCsharpUtCode("D:\\code\\AIUnitTestExample\\src\\ToListinator.Analyzers\\ToListCountAnalyzer.cs", undefined, true, true, false);
|
|
126
|
-
// function getPrompts(sourceCodePath, testFramework, codeDependency) {
|
|
127
|
-
// const code = fs.readFileSync(sourceCodePath, 'utf8');
|
|
128
|
-
// let guidancePromt = fs.readFileSync("D:\\atmp\\promptiteration.md", 'utf8');
|
|
129
|
-
// guidancePromt = guidancePromt.replace("xUnit", testFramework);
|
|
130
|
-
// const prompts = [
|
|
131
|
-
// // {
|
|
132
|
-
// // "role": "system",
|
|
133
|
-
// // "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."
|
|
134
|
-
// // },
|
|
135
|
-
// {
|
|
136
|
-
// "role": "user",
|
|
137
|
-
// // "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."
|
|
138
|
-
// "content": guidancePromt
|
|
139
|
-
// },
|
|
140
|
-
// {
|
|
141
|
-
// "role": "user",
|
|
142
|
-
// "content": `generate unit test for the following csharp code:\n\`\`\`${code}\`\`\``
|
|
143
|
-
// },
|
|
144
|
-
// // {
|
|
145
|
-
// // "role": "user",
|
|
146
|
-
// // "content": `following are the code dependencies of the source code:\n${codeDependency}`
|
|
147
|
-
// // }
|
|
148
|
-
// ];
|
|
149
|
-
// return prompts;
|
|
150
|
-
// }
|
|
151
125
|
//# sourceMappingURL=csharpUtGen.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csharpUtGen.js","sourceRoot":"","sources":["../../src/gen/csharpUtGen.ts"],"names":[],"mappings":";;;;;;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;IACjF,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,mKAAmK;AACnK,iNAAiN;AACjN,uNAAuN;AACvN,sKAAsK;AACtK,0IAA0I;AAE1I,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\n\r\nimport { CSHARPUTGEN, CSVSPLUGIN } from '../types/constants';\r\nimport { deleteTestFileIfExists, writeTestCode } from \"../utils/fileUtils\";\r\n\r\nimport { GenResult } from '../types/genResult';\r\nimport { autoFixTestCode } from './autoFix';\r\nimport { checkXapCode } from '../utils/checkXapCode';\r\nimport { detectTestFramework } from '../utils/detectTestFramework';\r\nimport { ensureValidLLMResponse } from './ensureValidLLMResponse';\r\nimport { generateCodeDependency } from '../analyze/generateCodeDependency';\r\nimport { getOrCreatTestFile } from '../utils/getTestFile';\r\nimport { installOrUpdateAnalyzerTool } from '../analyze/installAnalyzerTool';\r\nimport { preGenProcess } from './preGen/preGenProcess';\r\nimport { prepareUtGenPrompt } from '../llm/preparePrompt';\r\nimport { removeFailedTestCasesInTestFile } from '../utils/removeFailedTestMethods';\r\nimport { sendUserUsageEvent } from '../metrics/appInsightTelemetry';\r\n\r\nconst RETRYTIMES = 3;\r\n\r\nexport async function generateCsharpUtCode(\r\n sourceCodePath: string,\r\n testCodePath: string,\r\n enableAutoFix: boolean,\r\n keepFailedTests: boolean,\r\n source: string = CSHARPUTGEN,\r\n isBenchmark: boolean = false\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n console.log(`*****************Generating C# unit test code for: ${sourceCodePath}*****************`);\r\n console.log(`Current work dir: ${process.cwd()}`);\r\n\r\n // send usage metrics\r\n sendUserUsageEvent(source);\r\n\r\n sourceCodePath = path.normalize(sourceCodePath);\r\n if (!fs.existsSync(sourceCodePath)) {\r\n console.error(`Source code file not found: ${sourceCodePath}`);\r\n return;\r\n }\r\n\r\n // install nuget cli tool to analyze code\r\n installOrUpdateAnalyzerTool();\r\n\r\n let sourceCode = fs.readFileSync(sourceCodePath, 'utf-8');\r\n\r\n // check if source code is xap code, if so, use xap code generation prompt\r\n const isXapCode = checkXapCode(sourceCode);\r\n\r\n sourceCode = await preGenProcess(sourceCode, sourceCodePath, isXapCode);\r\n if (!sourceCode) {\r\n console.error(`Skip generate test for source code: ${sourceCodePath}`);\r\n return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n }\r\n\r\n // get code dependencies\r\n let codeDependency = await generateCodeDependency(sourceCodePath);\r\n\r\n // detect existing test file or create a new one by source code path\r\n const { testFilePath, testProjectPath, testFileExist } = getOrCreatTestFile(sourceCodePath, testCodePath, isXapCode);\r\n if (!testFilePath || !testProjectPath) {\r\n console.error(`Failed to get or create test file for source code: ${sourceCodePath}`);\r\n return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n }\r\n\r\n // get test framework\r\n const testFramework = detectTestFramework(testProjectPath);\r\n\r\n // prepare prompt\r\n let prompt = prepareUtGenPrompt(sourceCodePath, sourceCode, codeDependency, isXapCode, testFramework);\r\n // let prompt = getPrompts(sourceCodePath, testFramework, codeDependency);\r\n\r\n // call LLM service to gen code with retry\r\n const testCode = await ensureValidLLMResponse(prompt, isXapCode);\r\n\r\n // write test code to test project\r\n // To run vstest, need to write the test code to test project first, then build the test project and run the tests\r\n writeTestCode(testCode, testFilePath);\r\n\r\n // autofix\r\n let autoFixResult: GenResult = { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n if (enableAutoFix) {\r\n const isVsPlugin = source === CSVSPLUGIN;\r\n autoFixResult = await autoFixTestCode(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);\r\n // autoFixResult = await autoRetryTestCode(prompt, sourceCode, testCode, testProjectPath, testFilePath, isXapTest);\r\n }\r\n\r\n if (autoFixResult.success) {\r\n console.log(`Gerate UT success time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return autoFixResult;\r\n }\r\n\r\n // if retry max times or test generation failed, and keepFailedTests is false, delete failed test file or remove failed test methods\r\n if (!keepFailedTests) {\r\n // keep succeed test code, or delete test file\r\n if (!autoFixResult.testResult || autoFixResult.testResult.passed === 0) {\r\n !testFileExist && deleteTestFileIfExists(testFilePath);\r\n console.log(`Failed to generate csharp test code, deleted test file: ${testFilePath}`);\r\n } else {\r\n removeFailedTestCasesInTestFile(autoFixResult.testResult, testFilePath);\r\n console.log(`write succeed test code to file: ${testFilePath}`);\r\n }\r\n } else {\r\n console.log(`keep failed test file: ${testFilePath}`);\r\n }\r\n console.log(`Gerate UT failed time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return autoFixResult;\r\n}\r\n\r\n// generateCsharpUtCode(\"D:\\\\code\\\\IndexServe\\\\private\\\\indexserve\\\\RecommendationEngine\\\\RecoPS\\\\PSTableClient\\\\PSTableClient.cs\", undefined, false, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelper.cs\", undefined, true, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Eplant\\\\ResponseBuilders\\\\EplantMigrateResponseBuilder.cs\", undefined, true, true, true);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UCMDynamics.AppointmentPlugin\\\\AppointmentOperation.cs\", undefined, false, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\AIUnitTestExample\\\\src\\\\ToListinator.Analyzers\\\\ToListCountAnalyzer.cs\", undefined, true, true, false);\r\n\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\r\n\r\n"]}
|
|
1
|
+
{"version":3,"file":"csharpUtGen.js","sourceRoot":"","sources":["../../src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,4BAA4B,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,UAAU,CAAC,CAAC;IACnF,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,mKAAmK;AACnK,iNAAiN;AACjN,uNAAuN;AACvN,sKAAsK;AACtK,0IAA0I","sourcesContent":["import * as fs from 'fs';\r\nimport * as path from 'path';\r\n\r\nimport { CSHARPUTGEN, CSVSPLUGIN } from '../types/constants';\r\nimport { deleteTestFileIfExists, writeTestCode } from \"../utils/fileUtils\";\r\n\r\nimport { GenResult } from '../types/genResult';\r\nimport { autoFixTestCode } from './autoFix';\r\nimport { checkXapCode } from '../utils/checkXapCode';\r\nimport { detectTestFramework } from '../utils/detectTestFramework';\r\nimport { ensureValidLLMResponse } from './ensureValidLLMResponse';\r\nimport { generateCodeDependency } from '../analyze/generateCodeDependency';\r\nimport { getOrCreatTestFile } from '../utils/getTestFile';\r\nimport { installOrUpdateAnalyzerTool } from '../analyze/installAnalyzerTool';\r\nimport { preGenProcess } from './preGen/preGenProcess';\r\nimport { prepareUtGenPrompt } from '../llm/preparePrompt';\r\nimport { removeFailedTestCasesInTestFile } from '../utils/removeFailedTestMethods';\r\nimport { sendUserUsageEvent } from '../metrics/appInsightTelemetry';\r\n\r\nconst RETRYTIMES = 3;\r\n\r\nexport async function generateCsharpUtCode(\r\n sourceCodePath: string,\r\n testCodePath: string,\r\n enableAutoFix: boolean,\r\n keepFailedTests: boolean,\r\n source: string = CSHARPUTGEN,\r\n isBenchmark: boolean = false,\r\n nugetPackagePath: string = null\r\n): Promise<GenResult> {\r\n const startTime = Date.now();\r\n\r\n console.log(`*****************Generating C# unit test code for: ${sourceCodePath}*****************`);\r\n console.log(`Current work dir: ${process.cwd()}`);\r\n\r\n // send usage metrics\r\n sendUserUsageEvent(source);\r\n\r\n sourceCodePath = path.normalize(sourceCodePath);\r\n if (!fs.existsSync(sourceCodePath)) {\r\n console.error(`Source code file not found: ${sourceCodePath}`);\r\n return;\r\n }\r\n\r\n // install nuget cli tool to analyze code\r\n installOrUpdateAnalyzerTool();\r\n\r\n let sourceCode = fs.readFileSync(sourceCodePath, 'utf-8');\r\n\r\n // check if source code is xap code, if so, use xap code generation prompt\r\n const isXapCode = checkXapCode(sourceCode);\r\n\r\n sourceCode = await preGenProcess(sourceCode, sourceCodePath, isXapCode);\r\n if (!sourceCode) {\r\n console.error(`Skip generate test for source code: ${sourceCodePath}`);\r\n return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n }\r\n\r\n // get code dependencies\r\n let codeDependency = await generateCodeDependency(sourceCodePath, nugetPackagePath);\r\n\r\n // detect existing test file or create a new one by source code path\r\n const { testFilePath, testProjectPath, testFileExist } = getOrCreatTestFile(sourceCodePath, testCodePath, isXapCode);\r\n if (!testFilePath || !testProjectPath) {\r\n console.error(`Failed to get or create test file for source code: ${sourceCodePath}. Please check if the test project exists.`);\r\n return { success: false, testFilePath: undefined, testProjectPath: undefined, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n }\r\n\r\n // get test framework\r\n const testFramework = detectTestFramework(testProjectPath);\r\n\r\n // prepare prompt\r\n let prompt = prepareUtGenPrompt(sourceCodePath, sourceCode, codeDependency, isXapCode, testFramework);\r\n\r\n // call LLM service to gen code with retry\r\n const testCode = await ensureValidLLMResponse(prompt, testFramework, isXapCode);\r\n\r\n // write test code to test project\r\n // To run vstest, need to write the test code to test project first, then build the test project and run the tests\r\n writeTestCode(testCode, testFilePath);\r\n\r\n // autofix\r\n let autoFixResult: GenResult = { success: true, testFilePath, testProjectPath, codeFilePath: sourceCodePath, buildResult: null, testResult: null };\r\n if (enableAutoFix) {\r\n const isVsPlugin = source === CSVSPLUGIN;\r\n autoFixResult = await autoFixTestCode(prompt, sourceCodePath, testCode, testProjectPath, testFilePath, testFramework, isXapCode, isVsPlugin, RETRYTIMES, isBenchmark);\r\n // autoFixResult = await autoRetryTestCode(prompt, sourceCode, testCode, testProjectPath, testFilePath, isXapTest);\r\n }\r\n\r\n if (autoFixResult.success) {\r\n console.log(`Generate UT success time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return autoFixResult;\r\n }\r\n\r\n // if retry max times or test generation failed, and keepFailedTests is false, delete failed test file or remove failed test methods\r\n if (!keepFailedTests) {\r\n // keep succeed test code, or delete test file\r\n if (!autoFixResult.testResult || autoFixResult.testResult.passed === 0) {\r\n !testFileExist && deleteTestFileIfExists(testFilePath);\r\n console.log(`Failed to generate csharp test code, deleted test file: ${testFilePath}`);\r\n } else {\r\n removeFailedTestCasesInTestFile(autoFixResult.testResult, testFilePath);\r\n console.log(`write succeed test code to file: ${testFilePath}`);\r\n }\r\n } else {\r\n console.log(`keep failed test file: ${testFilePath}`);\r\n }\r\n console.log(`Generate UT failed time: ${(Date.now() - startTime) / 1000} seconds`);\r\n return autoFixResult;\r\n}\r\n\r\n// generateCsharpUtCode(\"D:\\\\code\\\\IndexServe\\\\private\\\\indexserve\\\\RecommendationEngine\\\\RecoPS\\\\PSTableClient\\\\PSTableClient.cs\", undefined, false, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelper.cs\", undefined, true, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Plugins\\\\Workflows\\\\Eplant\\\\ResponseBuilders\\\\EplantMigrateResponseBuilder.cs\", undefined, true, true, true);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\UCMDynamics\\\\private\\\\DynamicCode\\\\Plugin\\\\UCMDynamics.AppointmentPlugin\\\\AppointmentOperation.cs\", undefined, false, true, false);\r\n// generateCsharpUtCode(\"D:\\\\code\\\\AIUnitTestExample\\\\src\\\\ToListinator.Analyzers\\\\ToListCountAnalyzer.cs\", undefined, true, true, false);\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function ensureValidLLMResponse(prompt: any[], isXapCode: boolean, retryTimes?: number): Promise<string>;
|
|
1
|
+
export declare function ensureValidLLMResponse(prompt: any[], testFramework: string, isXapCode: boolean, retryTimes?: number): Promise<string>;
|
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ensureValidLLMResponse = ensureValidLLMResponse;
|
|
4
4
|
const postGenProcess_1 = require("./postGen/postGenProcess");
|
|
5
5
|
const sendRequestToLLM_1 = require("../llm/sendRequestToLLM");
|
|
6
|
-
async function ensureValidLLMResponse(prompt, isXapCode, retryTimes = 3) {
|
|
6
|
+
async function ensureValidLLMResponse(prompt, testFramework, isXapCode, retryTimes = 3) {
|
|
7
7
|
for (let i = 0; i < retryTimes; i++) {
|
|
8
8
|
// call LLM service to gen code
|
|
9
9
|
const { content: generatedCode } = await (0, sendRequestToLLM_1.sendRequestToLLM)(prompt);
|
|
10
10
|
// extract valid code from LLM response
|
|
11
|
-
const testCode = (0, postGenProcess_1.postGenProcess)(generatedCode, isXapCode);
|
|
11
|
+
const testCode = (0, postGenProcess_1.postGenProcess)(generatedCode, testFramework, isXapCode);
|
|
12
12
|
if (!!testCode) {
|
|
13
13
|
return testCode;
|
|
14
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureValidLLMResponse.js","sourceRoot":"","sources":["../../src/gen/ensureValidLLMResponse.ts"],"names":[],"mappings":";;AAGA,wDAcC;AAjBD,6DAA0D;AAC1D,8DAA2D;AAEpD,KAAK,UAAU,sBAAsB,CAAC,MAAa,EAAE,SAAkB,EAAE,aAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ensureValidLLMResponse.js","sourceRoot":"","sources":["../../src/gen/ensureValidLLMResponse.ts"],"names":[],"mappings":";;AAGA,wDAcC;AAjBD,6DAA0D;AAC1D,8DAA2D;AAEpD,KAAK,UAAU,sBAAsB,CAAC,MAAa,EAAE,aAAqB,EAAE,SAAkB,EAAE,aAAqB,CAAC;IACzH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,+BAA+B;QAC/B,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,mCAAgB,EAAC,MAAM,CAAC,CAAC;QAElE,uCAAuC;QACvC,MAAM,QAAQ,GAAG,IAAA,+BAAc,EAAC,aAAa,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QACzE,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QACpB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import { postGenProcess } from \"./postGen/postGenProcess\";\r\nimport { sendRequestToLLM } from \"../llm/sendRequestToLLM\";\r\n\r\nexport async function ensureValidLLMResponse(prompt: any[], testFramework: string, isXapCode: boolean, retryTimes: number = 3): Promise<string> {\r\n for (let i = 0; i < retryTimes; i++) {\r\n // call LLM service to gen code\r\n const { content: generatedCode } = await sendRequestToLLM(prompt);\r\n \r\n // extract valid code from LLM response\r\n const testCode = postGenProcess(generatedCode, testFramework, isXapCode);\r\n if (!!testCode) {\r\n return testCode;\r\n }\r\n console.log(`Failed to generate valid test code, retrying... (${i + 1}/${retryTimes})`);\r\n }\r\n\r\n return undefined;\r\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function postGenProcess(generatedCode: string, isXapCode: boolean): string;
|
|
1
|
+
export declare function postGenProcess(generatedCode: string, testFramework: string, isXapCode: boolean): string;
|
|
@@ -6,13 +6,14 @@ const removeSingleLines_1 = require("./removeSingleLines");
|
|
|
6
6
|
const removeComments_1 = require("./removeComments");
|
|
7
7
|
const repairRequiredNameSpaces_1 = require("./repairRequiredNameSpaces");
|
|
8
8
|
const validateTestCode_1 = require("./validateTestCode");
|
|
9
|
-
function postGenProcess(generatedCode, isXapCode) {
|
|
9
|
+
function postGenProcess(generatedCode, testFramework, isXapCode) {
|
|
10
10
|
if (!isValidTestCode(generatedCode)) {
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
13
|
let testCode = (0, extractCodeFromResponse_1.extractCodeFromResponse)(generatedCode);
|
|
14
14
|
testCode = (0, removeComments_1.removeTestCodeComments)(testCode);
|
|
15
15
|
testCode = (0, removeSingleLines_1.removeCSharpOnlyLines)(testCode);
|
|
16
|
+
testCode = (0, repairRequiredNameSpaces_1.repairRequiredNameSpaces)(testCode, testFramework);
|
|
16
17
|
if (isXapCode) {
|
|
17
18
|
testCode = xapCodePostGenProcess(testCode);
|
|
18
19
|
}
|
|
@@ -20,7 +21,7 @@ function postGenProcess(generatedCode, isXapCode) {
|
|
|
20
21
|
return testCode;
|
|
21
22
|
}
|
|
22
23
|
function xapCodePostGenProcess(testCode) {
|
|
23
|
-
const processedCode = (0, repairRequiredNameSpaces_1.
|
|
24
|
+
const processedCode = (0, repairRequiredNameSpaces_1.repairXapRequiredNameSpaces)(testCode);
|
|
24
25
|
return processedCode;
|
|
25
26
|
}
|
|
26
27
|
function isValidTestCode(testCode) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postGenProcess.js","sourceRoot":"","sources":["../../../src/gen/postGen/postGenProcess.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"postGenProcess.js","sourceRoot":"","sources":["../../../src/gen/postGen/postGenProcess.ts"],"names":[],"mappings":";;AAMA,wCAcC;AApBD,uEAAoE;AACpE,2DAA4D;AAC5D,qDAA0D;AAC1D,yEAAmG;AACnG,yDAAsD;AAEtD,SAAgB,cAAc,CAAC,aAAqB,EAAE,aAAqB,EAAE,SAAkB;IAC3F,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,CAAC;QAClC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,QAAQ,GAAG,IAAA,iDAAuB,EAAC,aAAa,CAAC,CAAC;IACtD,QAAQ,GAAG,IAAA,uCAAsB,EAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAA,yCAAqB,EAAC,QAAQ,CAAC,CAAC;IAC3C,QAAQ,GAAG,IAAA,mDAAwB,EAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAC7D,IAAI,SAAS,EAAE,CAAC;QACZ,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,mDAAmD,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAClF,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC3C,MAAM,aAAa,GAAG,IAAA,sDAA2B,EAAC,QAAQ,CAAC,CAAC;IAC5D,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,SAAS,eAAe,CAAC,QAAgB;IACrC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC,CAAC,0BAA0B;IAC5C,CAAC;IACD,0EAA0E;IAC1E,MAAM,OAAO,GAAG,IAAA,mCAAgB,EAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,uMAAuM;AACvM,+BAA+B","sourcesContent":["import { extractCodeFromResponse } from \"./extractCodeFromResponse\";\r\nimport { removeCSharpOnlyLines } from \"./removeSingleLines\";\r\nimport { removeTestCodeComments } from \"./removeComments\";\r\nimport { repairRequiredNameSpaces, repairXapRequiredNameSpaces } from \"./repairRequiredNameSpaces\";\r\nimport { validateTestCode } from \"./validateTestCode\";\r\n\r\nexport function postGenProcess(generatedCode: string, testFramework: string, isXapCode: boolean): string {\r\n if (!isValidTestCode(generatedCode)) {\r\n return undefined;\r\n }\r\n\r\n let testCode = extractCodeFromResponse(generatedCode);\r\n testCode = removeTestCodeComments(testCode);\r\n testCode = removeCSharpOnlyLines(testCode);\r\n testCode = repairRequiredNameSpaces(testCode, testFramework);\r\n if (isXapCode) {\r\n testCode = xapCodePostGenProcess(testCode);\r\n }\r\n console.log(`Post generation process completed, code length: ${testCode.length}`);\r\n return testCode;\r\n}\r\n\r\nfunction xapCodePostGenProcess(testCode: string): string {\r\n const processedCode = repairXapRequiredNameSpaces(testCode);\r\n return processedCode;\r\n}\r\n\r\nfunction isValidTestCode(testCode: string): boolean {\r\n if (!testCode || testCode.trim() === '') {\r\n return false; // Empty code is not valid\r\n }\r\n // Check if the test code contains any test attributes or using statements\r\n const isValid = validateTestCode(testCode);\r\n return isValid;\r\n}\r\n\r\n// const code = fs.readFileSync(\"D:\\\\code\\\\CS.Service.Fundamental\\\\SharedSegments\\\\SharedSegments\\\\SharedSegments.Tests\\\\Workflows\\\\Overview\\\\HttpRequestParser\\\\Utils\\\\SqmidHelperTests.cs\", 'utf-8');\r\n// postGenProcess(code, false);\r\n"]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function repairRequiredNameSpaces(code: string): string;
|
|
1
|
+
export declare function repairRequiredNameSpaces(code: string, testFramework: string): string;
|
|
2
|
+
export declare function repairXapRequiredNameSpaces(code: string): string;
|
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.repairRequiredNameSpaces = repairRequiredNameSpaces;
|
|
4
|
-
|
|
4
|
+
exports.repairXapRequiredNameSpaces = repairXapRequiredNameSpaces;
|
|
5
|
+
const constants_1 = require("../../types/constants");
|
|
6
|
+
function repairRequiredNameSpaces(code, testFramework) {
|
|
7
|
+
const testFrameworkUsing = getTestFrameworkNameSpaces(testFramework);
|
|
5
8
|
const requiredUsings = [
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
testFrameworkUsing,
|
|
10
|
+
];
|
|
11
|
+
code = repairMissingUsings(code, requiredUsings);
|
|
12
|
+
return code;
|
|
13
|
+
}
|
|
14
|
+
function repairXapRequiredNameSpaces(code) {
|
|
15
|
+
const xapUsings = [
|
|
8
16
|
"using System;",
|
|
9
17
|
"using System.Threading.Tasks;",
|
|
10
18
|
"using System.Collections.Generic;",
|
|
19
|
+
"using Xap.ExecutionFramework;",
|
|
20
|
+
"using Xap.PluginFramework;",
|
|
11
21
|
"using EMPTY = Microsoft.Bing.Xap.Plugins.Void;",
|
|
12
|
-
"using Microsoft.VisualStudio.TestTools.UnitTesting;"
|
|
13
22
|
];
|
|
23
|
+
code = repairMissingUsings(code, xapUsings);
|
|
24
|
+
return code;
|
|
25
|
+
}
|
|
26
|
+
function repairMissingUsings(code, requiredUsings) {
|
|
14
27
|
// get all using lines
|
|
15
28
|
const usingRegex = /^\s*using\s+[^\r\n;]+;/gm;
|
|
16
29
|
const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());
|
|
@@ -37,6 +50,18 @@ function repairRequiredNameSpaces(code) {
|
|
|
37
50
|
console.log("repaired namespaces:", missingUsings);
|
|
38
51
|
return newLines.join('\n');
|
|
39
52
|
}
|
|
53
|
+
function getTestFrameworkNameSpaces(testFramework) {
|
|
54
|
+
const msTestUsing = "using Microsoft.VisualStudio.TestTools.UnitTesting;";
|
|
55
|
+
if (!testFramework) {
|
|
56
|
+
return msTestUsing;
|
|
57
|
+
}
|
|
58
|
+
const FRAMEWORK_USINGS = {
|
|
59
|
+
[constants_1.MSTESTFRAMEWORK]: msTestUsing,
|
|
60
|
+
[constants_1.NUNITTESTFRAMEWORK]: "using NUnit.Framework;",
|
|
61
|
+
[constants_1.XUNITTESTFRAMEWORK]: "using Xunit;"
|
|
62
|
+
};
|
|
63
|
+
return FRAMEWORK_USINGS[testFramework] || msTestUsing;
|
|
64
|
+
}
|
|
40
65
|
// const code = `
|
|
41
66
|
// using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
42
67
|
// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repairRequiredNameSpaces.js","sourceRoot":"","sources":["../../../src/gen/postGen/repairRequiredNameSpaces.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"repairRequiredNameSpaces.js","sourceRoot":"","sources":["../../../src/gen/postGen/repairRequiredNameSpaces.ts"],"names":[],"mappings":";;AAEA,4DAQC;AAED,kEAYC;AAxBD,qDAAgG;AAEhG,SAAgB,wBAAwB,CAAC,IAAY,EAAE,aAAqB;IACxE,MAAM,kBAAkB,GAAG,0BAA0B,CAAC,aAAa,CAAC,CAAC;IACrE,MAAM,cAAc,GAAG;QACnB,kBAAkB;KACrB,CAAC;IAEF,IAAI,GAAG,mBAAmB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,2BAA2B,CAAC,IAAY;IACpD,MAAM,SAAS,GAAG;QACd,eAAe;QACf,+BAA+B;QAC/B,mCAAmC;QACnC,+BAA+B;QAC/B,4BAA4B;QAC5B,gDAAgD;KACnD,CAAC;IAEF,IAAI,GAAG,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC5C,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY,EAAE,cAAwB;IAC/D,sBAAsB;IACtB,MAAM,UAAU,GAAG,0BAA0B,CAAC;IAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAE3F,MAAM,aAAa,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAA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../../types/constants';\r\n\r\nexport function repairRequiredNameSpaces(code: string, testFramework: string): string {\r\n const testFrameworkUsing = getTestFrameworkNameSpaces(testFramework);\r\n const requiredUsings = [\r\n testFrameworkUsing,\r\n ];\r\n\r\n code = repairMissingUsings(code, requiredUsings);\r\n return code;\r\n}\r\n\r\nexport function repairXapRequiredNameSpaces(code: string): string {\r\n const xapUsings = [\r\n \"using System;\",\r\n \"using System.Threading.Tasks;\",\r\n \"using System.Collections.Generic;\",\r\n \"using Xap.ExecutionFramework;\",\r\n \"using Xap.PluginFramework;\",\r\n \"using EMPTY = Microsoft.Bing.Xap.Plugins.Void;\",\r\n ];\r\n\r\n code = repairMissingUsings(code, xapUsings);\r\n return code;\r\n}\r\n\r\nfunction repairMissingUsings(code: string, requiredUsings: string[]): string {\r\n // get all using lines\r\n const usingRegex = /^\\s*using\\s+[^\\r\\n;]+;/gm;\r\n const existingUsings = Array.from(code.matchAll(usingRegex)).map(match => match[0].trim());\r\n\r\n const missingUsings = requiredUsings.filter(req => !existingUsings.includes(req));\r\n\r\n if (missingUsings.length === 0) {\r\n return code;\r\n }\r\n\r\n // find the end of the using block: the first non-using line, or the end of the file\r\n const lines = code.split(/\\r?\\n/);\r\n let insertIndex = 0;\r\n\r\n for (let i = 0; i < lines.length; i++) {\r\n if (!lines[i].trim().startsWith(\"using\") && lines[i].trim() !== \"\") {\r\n insertIndex = i;\r\n break;\r\n }\r\n insertIndex = i + 1;\r\n }\r\n\r\n // build new code\r\n const newLines = [\r\n ...lines.slice(0, insertIndex),\r\n ...missingUsings,\r\n ...lines.slice(insertIndex)\r\n ];\r\n\r\n console.log(\"repaired namespaces:\", missingUsings);\r\n\r\n return newLines.join('\\n');\r\n}\r\n\r\nfunction getTestFrameworkNameSpaces(testFramework: string): string {\r\n const msTestUsing = \"using Microsoft.VisualStudio.TestTools.UnitTesting;\";\r\n\r\n if (!testFramework) {\r\n return msTestUsing;\r\n }\r\n\r\n const FRAMEWORK_USINGS = {\r\n [MSTESTFRAMEWORK]: msTestUsing,\r\n [NUNITTESTFRAMEWORK]: \"using NUnit.Framework;\",\r\n [XUNITTESTFRAMEWORK]: \"using Xunit;\"\r\n } as const;\r\n\r\n return FRAMEWORK_USINGS[testFramework] || msTestUsing;\r\n}\r\n\r\n\r\n\r\n// const code = `\r\n// using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n// using SharedSegments.Plugins.Workflows.Overview.HttpRequestParser.Utils;\r\n// using System;\r\n// using System.Collections.Generic;\r\n// using System.Text;\r\n// using Moq;\r\n\r\n// namespace SharedSegments.Plugins.Tests.Workflows.Overview.HttpRequestParser.Utils\r\n// {\r\n// [TestClass]\r\n// public class SqmidHelperTests\r\n// {\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithBlisId_ReturnsDecodedBlisId()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"BID=\" + Convert.ToBase64String(Encoding.UTF8.GetBytes(\"test_decodedBlisId_test\")) }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(\"decodedBlisId\", result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_ValidCookiesWithoutBlisId_ReturnsNull()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"SomeOtherValue=123\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.IsNull(result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_EmptyCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>();\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_NullCookies_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// IDictionary<string, string> cookies = null;\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n\r\n// [TestMethod]\r\n// public void GetSqmidFromCookie_UsrLocWithEmptyValue_ReturnsEmptyString()\r\n// {\r\n// // Arrange\r\n// var cookies = new Dictionary<string, string>\r\n// {\r\n// { \"USRLOC\", \"\" }\r\n// };\r\n\r\n// // Act\r\n// var result = SqmidHelper.GetSqmidFromCookie(cookies);\r\n\r\n// // Assert\r\n// Assert.AreEqual(string.Empty, result);\r\n// }\r\n// }\r\n// }\r\n// `;\r\n\r\n// const cleanedCode = repairRequiredNameSpaces(code);\r\n// console.log(cleanedCode);"]}
|
package/out/index.d.ts
CHANGED
package/out/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setup = exports.generateCsharpUtCode = void 0;
|
|
3
|
+
exports.setup = exports.generateBatchTests = exports.generateCsharpUtCode = void 0;
|
|
4
4
|
var csharpUtGen_1 = require("./gen/csharpUtGen");
|
|
5
5
|
Object.defineProperty(exports, "generateCsharpUtCode", { enumerable: true, get: function () { return csharpUtGen_1.generateCsharpUtCode; } });
|
|
6
|
+
var generateCodeTests_1 = require("./batch/generateCodeTests");
|
|
7
|
+
Object.defineProperty(exports, "generateBatchTests", { enumerable: true, get: function () { return generateCodeTests_1.generateBatchTests; } });
|
|
6
8
|
var setup_1 = require("./setup/setup");
|
|
7
9
|
Object.defineProperty(exports, "setup", { enumerable: true, get: function () { return setup_1.setup; } });
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;AAAhD,mHAAA,oBAAoB,OAAA;AAC7B,uCAAsC;AAA7B,8FAAA,KAAK,OAAA","sourcesContent":["export { generateCsharpUtCode } from './gen/csharpUtGen';\r\nexport { setup } from './setup/setup';"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAyD;AAAhD,mHAAA,oBAAoB,OAAA;AAC7B,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAC3B,uCAAsC;AAA7B,8FAAA,KAAK,OAAA","sourcesContent":["export { generateCsharpUtCode } from './gen/csharpUtGen';\r\nexport { generateBatchTests } from './batch/generateCodeTests';\r\nexport { setup } from './setup/setup';"]}
|
|
@@ -10,7 +10,8 @@ const runCommand_1 = require("../../utils/runCommand");
|
|
|
10
10
|
let cachedToken = null;
|
|
11
11
|
let tokenExpiration = null;
|
|
12
12
|
// platform provided endpoint
|
|
13
|
-
const gptEndpoint = "https://
|
|
13
|
+
const gptEndpoint = "https://weatherutswedencentral.cognitiveservices.azure.com/openai/deployments/gpt-5-chat/chat/completions?api-version=2025-01-01-preview";
|
|
14
|
+
// const gptEndpoint = "https://weatherut.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview";
|
|
14
15
|
// const gptEndpoint = "https://autogenerate-unit-tests-draft-1.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview";
|
|
15
16
|
// const gptEndpoint = "https://weathergptv4.openai.azure.com/openai/deployments/gpt-4.1/chat/completions?api-version=2025-01-01-preview";
|
|
16
17
|
// const gptEndpoint = "https://takht-m99407ib-swedencentral.cognitiveservices.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview";
|
|
@@ -21,7 +22,8 @@ async function getToken() {
|
|
|
21
22
|
return cachedToken;
|
|
22
23
|
}
|
|
23
24
|
try {
|
|
24
|
-
const credential = new identity_1.ChainedTokenCredential(new identity_1.AzureCliCredential(), new identity_1.ManagedIdentityCredential(), new identity_1.DefaultAzureCredential()
|
|
25
|
+
const credential = new identity_1.ChainedTokenCredential(new identity_1.AzureCliCredential(), new identity_1.ManagedIdentityCredential(), new identity_1.DefaultAzureCredential() // CodeQL [SM05138] This is non-production testing code which is not deployed.
|
|
26
|
+
);
|
|
25
27
|
const tokenResponse = await credential.getToken('https://cognitiveservices.azure.com/.default');
|
|
26
28
|
if (tokenResponse) {
|
|
27
29
|
cachedToken = tokenResponse.token;
|
|
@@ -88,4 +90,4 @@ async function getLLMResponse(prompt) {
|
|
|
88
90
|
// getLLMResponse("Generate xUnit tests for the ToListCountAnalyzer class.").then((response) => {
|
|
89
91
|
// console.log(response.choices[0]?.message?.content)
|
|
90
92
|
// });
|
|
91
|
-
//# sourceMappingURL=
|
|
93
|
+
//# sourceMappingURL=Gpt.js.map
|