Skip to content

Commit 5ac5653

Browse files
committed
@W-18964528@ Added test coverage for run_code_analyzer
1 parent f9cd3dd commit 5ac5653

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import path from "node:path";
2+
import {fileURLToPath} from "node:url";
3+
import { describeEval } from 'vitest-evals';
4+
import { TaskRunner } from './utils.js';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const pathToTarget: string = path.join(__dirname, '..', 'fixtures', 'sample-targets', 'SampleTarget1.cls');
10+
11+
describeEval('run_code_analyzer', {
12+
data: async () => [{
13+
input: `Run code analysis against ${pathToTarget}, and tell me the number of violations in that file using the response format "There are X violations".` ,
14+
expected: [6]
15+
}],
16+
task: TaskRunner(),
17+
scorers: [(opts: {output: string, expected: number}) => {
18+
const score: number = opts.output === `There are ${opts.expected} violations.` ? 1 : 0;
19+
return {score};
20+
}],
21+
threshold: 0.9,
22+
timeout: 60_000
23+
});

packages/mcp/test/evals/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ export function TaskRunner(model: LanguageModel = defaultModel) {
8080

8181
export function outputIncludesExpectationArray(opts: {input: string, output: string, expected: string[]}) {
8282
let score: number = 0;
83+
//console.log(`output is ${opts.output}`);
8384
const increment: number = 1/opts.expected.length;
8485
for (const expected of opts.expected) {
8586
if (opts.output.toLowerCase().includes(expected.toLowerCase())) {
87+
//console.log(`contained ${expected}, icnrementing`);
8688
score += increment;
8789
}
90+
//console.log(`score is now ${score}`)
8891
}
8992
return {
9093
score
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class SampleTarget1 {
2+
public static boolean doSomething() {
3+
Integer i = 0;
4+
for (i = 0; i < 10; i++) {
5+
Account[] accs = [SELECT Name FROM Account WITH SYSTEM_MODE];
6+
}
7+
return false;
8+
}
9+
}

0 commit comments

Comments
 (0)