Skip to content

Commit ea45613

Browse files
committed
Address coderabbit suggestions
1 parent 5271e21 commit ea45613

File tree

3 files changed

+28
-42
lines changed
  • workspaces/ballerina

3 files changed

+28
-42
lines changed

workspaces/ballerina/ballerina-extension/src/features/test-explorer/runner.ts

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ function buildTestCommand(test: TestItem, executor: string, projectName: string
129129
}
130130
}
131131

132+
/**
133+
* Handle AI evaluation report display after tests complete
134+
* @param test - The test item
135+
* @param workingDirectory - The working directory where evaluation-reports are generated
136+
*/
137+
async function handleAiEvaluationReport(test: TestItem, workingDirectory: string): Promise<void> {
138+
if (isAiEvaluations(test)) {
139+
const reportUri = await findLatestEvaluationReport(workingDirectory);
140+
if (reportUri) {
141+
await openEvaluationReport(reportUri);
142+
}
143+
}
144+
}
145+
132146
export async function runHandler(request: TestRunRequest, token: CancellationToken) {
133147
if (!request.include) {
134148
return;
@@ -208,12 +222,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
208222
const timeElapsed = calculateTimeElapsed(startTime, endTime, testItems);
209223

210224
reportTestResults(run, testItems, timeElapsed, projectPath).then(async () => {
211-
if (isAiEvaluations(test)) {
212-
const reportUri = await findLatestEvaluationReport(workingDirectory);
213-
if (reportUri) {
214-
await openEvaluationReport(reportUri);
215-
}
216-
}
225+
await handleAiEvaluationReport(test, workingDirectory);
217226
endGroup(test, true, run);
218227
}).catch(() => {
219228
endGroup(test, false, run);
@@ -223,12 +232,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
223232
const timeElapsed = calculateTimeElapsed(startTime, endTime, testItems);
224233

225234
reportTestResults(run, testItems, timeElapsed, projectPath).then(async () => {
226-
if (isAiEvaluations(test)) {
227-
const reportUri = await findLatestEvaluationReport(workingDirectory);
228-
if (reportUri) {
229-
await openEvaluationReport(reportUri);
230-
}
231-
}
235+
await handleAiEvaluationReport(test, workingDirectory);
232236
endGroup(test, true, run);
233237
}).catch(() => {
234238
endGroup(test, false, run);
@@ -254,12 +258,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
254258
const timeElapsed = calculateTimeElapsed(startTime, endTime, testItems);
255259

256260
reportTestResults(run, testItems, timeElapsed, projectPath).then(async () => {
257-
if (isAiEvaluations(test)) {
258-
const reportUri = await findLatestEvaluationReport(workingDirectory);
259-
if (reportUri) {
260-
await openEvaluationReport(reportUri);
261-
}
262-
}
261+
await handleAiEvaluationReport(test, workingDirectory);
263262
endGroup(test, true, run);
264263
}).catch(() => {
265264
endGroup(test, false, run);
@@ -269,12 +268,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
269268
const timeElapsed = calculateTimeElapsed(startTime, endTime, testItems);
270269

271270
reportTestResults(run, testItems, timeElapsed, projectPath).then(async () => {
272-
if (isAiEvaluations(test)) {
273-
const reportUri = await findLatestEvaluationReport(workingDirectory);
274-
if (reportUri) {
275-
await openEvaluationReport(reportUri);
276-
}
277-
}
271+
await handleAiEvaluationReport(test, workingDirectory);
278272
endGroup(test, true, run);
279273
}).catch(() => {
280274
endGroup(test, false, run);
@@ -301,12 +295,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
301295
const timeElapsed = calculateTimeElapsed(startTime, endTime, testItems);
302296

303297
reportTestResults(run, testItems, timeElapsed, projectPath, true).then(async () => {
304-
if (isAiEvaluations(test)) {
305-
const reportUri = await findLatestEvaluationReport(workingDirectory);
306-
if (reportUri) {
307-
await openEvaluationReport(reportUri);
308-
}
309-
}
298+
await handleAiEvaluationReport(test, workingDirectory);
310299
endGroup(test, true, run);
311300
}).catch(() => {
312301
endGroup(test, false, run);
@@ -316,12 +305,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
316305
const timeElapsed = calculateTimeElapsed(startTime, endTime, testItems);
317306

318307
reportTestResults(run, testItems, timeElapsed, projectPath, true).then(async () => {
319-
if (isAiEvaluations(test)) {
320-
const reportUri = await findLatestEvaluationReport(workingDirectory);
321-
if (reportUri) {
322-
await openEvaluationReport(reportUri);
323-
}
324-
}
308+
await handleAiEvaluationReport(test, workingDirectory);
325309
endGroup(test, true, run);
326310
}).catch(() => {
327311
endGroup(test, false, run);

workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-agent/rpc-manager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,10 @@ export class AiAgentRpcManager implements AIAgentAPI {
451451
} else {
452452
toolsValue = `[${mcpToolKitVarName}]`;
453453
}
454-
} else {
454+
} else if (typeof mcpToolKitVarName === "string") {
455455
toolsValue = `[${mcpToolKitVarName}]`;
456+
} else {
457+
toolsValue = "[]";
456458
}
457459

458460
// Set the updated tools value

workspaces/ballerina/ballerina-visualizer/src/views/BI/DiagramWrapper/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export function DiagramWrapper(param: DiagramWrapperProps) {
231231
};
232232

233233
const handleEdit = (fileUri?: string, position?: NodePosition) => {
234-
const isTestFunction = parentCodedata?.sourceCode.includes("@test:Config");
235-
const isAIEvaluation = isTestFunction && parentCodedata?.sourceCode.includes('"evaluations"');
234+
const isTestFunction = parentCodedata?.sourceCode?.includes("@test:Config");
235+
const isAIEvaluation = isTestFunction && parentCodedata?.sourceCode?.includes('"evaluations"');
236236

237237
if (isAIEvaluation) {
238238
rpcClient.getVisualizerRpcClient().openView({
@@ -289,9 +289,9 @@ export function DiagramWrapper(param: DiagramWrapperProps) {
289289
const getTitle = () => {
290290
if (isNPFunction) return "Natural Function";
291291
if (isAutomation) return "Automation";
292-
if (parentCodedata?.sourceCode.includes("@ai:AgentTool")) return "Agent Tool";
293-
if ((parentCodedata?.sourceCode.includes("@test:Config")) && parentCodedata?.sourceCode.includes("\"evaluations\"")) return "AI Evaluation";
294-
if (parentCodedata?.sourceCode.includes("@test:Config")) return "Test";
292+
if (parentCodedata?.sourceCode?.includes("@ai:AgentTool")) return "Agent Tool";
293+
if ((parentCodedata?.sourceCode?.includes("@test:Config")) && parentCodedata?.sourceCode?.includes("\"evaluations\"")) return "AI Evaluation";
294+
if (parentCodedata?.sourceCode?.includes("@test:Config")) return "Test";
295295
return parentMetadata?.kind || "";
296296
};
297297

0 commit comments

Comments
 (0)