Skip to content

Commit 50c6caf

Browse files
committed
feat(core): add create_test_for_file tool for AutoDev
- Implement CreateTestForFileTool to generate tests for specific files - Add tool to HostMcpToolManager for registration - Update AutoDevMcpTools to include new functionality
1 parent b047edd commit 50c6caf

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

core/src/main/kotlin/cc/unitmesh/devti/mcp/host/AutoDevMcpTools.kt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import cc.unitmesh.devti.gui.AutoDevToolWindowFactory
44
import cc.unitmesh.devti.gui.chat.message.ChatActionType
55
import cc.unitmesh.devti.observer.agent.AgentStateService
66
import cc.unitmesh.devti.observer.plan.reviewPlan
7+
import cc.unitmesh.devti.provider.AutoTestService
78
import cc.unitmesh.devti.sketch.AutoSketchMode
89
import cc.unitmesh.devti.sketch.AutoSketchModeListener
910
import cc.unitmesh.devti.util.parser.CodeFence
@@ -12,6 +13,7 @@ import com.intellij.openapi.project.Project
1213
import kotlinx.serialization.Serializable
1314
import com.intellij.openapi.application.runInEdt
1415
import com.intellij.openapi.util.Disposer
16+
import com.intellij.psi.PsiManager
1517
import java.util.concurrent.CompletableFuture
1618

1719
@Serializable
@@ -44,7 +46,7 @@ class IssueEvaluateTool : AbstractMcpTool<IssueArgs>() {
4446
connection.subscribe(AutoSketchModeListener.TOPIC, object : AutoSketchModeListener {
4547
override fun done() {
4648
val messages = project.getService(AgentStateService::class.java).getAllMessages()
47-
var plan: String = ""
49+
var plan = ""
4850
messages.lastOrNull()?.content?.also {
4951
plan = CodeFence.parseAll(it).firstOrNull {
5052
it.originLanguage == "plan"
@@ -65,7 +67,36 @@ class IssueEvaluateTool : AbstractMcpTool<IssueArgs>() {
6567
}
6668
})
6769

68-
6970
return Response(future.get())
7071
}
71-
}
72+
}
73+
74+
@Serializable
75+
data class CreateTestForFileArgs(val fileName: String)
76+
77+
class CreateTestForFileTool : AbstractMcpTool<CreateTestForFileArgs>() {
78+
override val name: String = "create_test_for_file"
79+
override val description: String = """
80+
This tool is used to create a test for a file.
81+
Requires a file_name parameter containing the file name.
82+
Returns a the test code for this file.
83+
""".trimIndent()
84+
85+
override fun handle(
86+
project: Project,
87+
args: CreateTestForFileArgs
88+
): Response {
89+
val fileName = args.fileName
90+
val file = project.baseDir.findFileByRelativePath(fileName)
91+
?: return Response(error = "File not found")
92+
val psiFile = PsiManager.getInstance(project).findFile(file)
93+
?: return Response(error = "Current IDE don't support this file type")
94+
val context = AutoTestService.context(psiFile)
95+
?: return Response(error = "AutoDev don't support this file type")
96+
97+
val result = context.runFileAsync(project, file, psiFile)
98+
?: return Response(error = "Failed to create test for file")
99+
100+
return Response(result)
101+
}
102+
}

core/src/main/kotlin/cc/unitmesh/devti/mcp/host/HostMcpToolManager.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class HostMcpToolManager {
3838
ExecuteActionByIdTool(),
3939
GetProgressIndicatorsTool(),
4040
WaitTool(),
41+
42+
/// autodev code
4143
IssueEvaluateTool(),
44+
CreateTestForFileTool(),
4245
)
4346
}
4447
}

0 commit comments

Comments
 (0)