@@ -19,15 +19,16 @@ import { getErrorMessage } from "../utils";
1919import { generateTest , getDiagnostics } from "../../testGenerator" ;
2020import { URI } from "vscode-uri" ;
2121import * as fs from "fs" ;
22+ import * as path from "path" ;
2223import { CopilotEventHandler , createWebviewEventHandler } from "../event" ;
2324import { getCurrentProjectRoot } from "../../../../utils/project-utils" ;
25+ import { StateMachine } from "../../../../stateMachine" ;
2426
2527// Core function test generation that emits events
2628export async function generateFunctionTestsCore (
2729 params : TestGeneratorIntermediaryState ,
2830 eventHandler : CopilotEventHandler
2931) : Promise < void > {
30- const testPath = "tests/test.bal" ;
3132 const functionIdentifier = params . resourceFunction ;
3233
3334 eventHandler ( {
@@ -48,6 +49,22 @@ export async function generateFunctionTestsCore(
4849 return ;
4950 }
5051
52+ // Compute workspace-relative paths for test files (for display in UI)
53+ const context = StateMachine . context ( ) ;
54+ const workspacePath = context . workspacePath ;
55+ let testPathForDisplay = "tests/test.bal" ;
56+ let configPathForDisplay = "tests/Config.toml" ;
57+
58+ if ( workspacePath ) {
59+ // Workspace project: include package path prefix (e.g., "foo/tests/test.bal")
60+ const relativeProjectPath = path . relative ( workspacePath , projectPath ) ;
61+ testPathForDisplay = path . join ( relativeProjectPath , "tests/test.bal" ) ;
62+ configPathForDisplay = path . join ( relativeProjectPath , "tests/Config.toml" ) ;
63+ }
64+
65+ // Use project-relative path for file operations
66+ const testPath = "tests/test.bal" ;
67+
5168 const response = await generateTest ( projectPath , {
5269 targetType : TestGenerationTarget . Function ,
5370 targetIdentifier : functionIdentifier ,
@@ -102,12 +119,12 @@ export async function generateFunctionTestsCore(
102119 } ) ;
103120 eventHandler ( {
104121 type : "content_block" ,
105- content : `\n\n<code filename="${ testPath } " type="test">\n\`\`\`ballerina\n${ testCode } \n\`\`\`\n</code>` ,
122+ content : `\n\n<code filename="${ testPathForDisplay } " type="test">\n\`\`\`ballerina\n${ testCode } \n\`\`\`\n</code>` ,
106123 } ) ;
107124 if ( testConfig ) {
108125 eventHandler ( {
109126 type : "content_block" ,
110- content : `\n\n<code filename="tests/Config.toml " type="test">\n\`\`\`ballerina\n${ testConfig } \n\`\`\`\n</code>` ,
127+ content : `\n\n<code filename="${ configPathForDisplay } " type="test">\n\`\`\`ballerina\n${ testConfig } \n\`\`\`\n</code>` ,
111128 } ) ;
112129 }
113130
0 commit comments