Skip to content

Commit

Permalink
Merge branch 'development' into arksap2002/bugs/fix-error-window-size
Browse files Browse the repository at this point in the history
  • Loading branch information
arksap2002 authored Jun 28, 2024
2 parents fa48a97 + a5c0e7a commit c91275f
Show file tree
Hide file tree
Showing 65 changed files with 2,348 additions and 934 deletions.
7 changes: 5 additions & 2 deletions .run/Run IDE for UI Tests.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="runIdeForUiTests" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list />
<list>
<option value=":runIdeForUiTests" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
24 changes: 21 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import java.util.zip.ZipInputStream

fun properties(key: String) = project.findProperty(key).toString()

// Space credentials
val spaceUsername =
System.getProperty("space.username")?.toString() ?: project.properties["spaceUsername"]?.toString() ?: ""
val spacePassword =
System.getProperty("space.pass")?.toString() ?: project.properties["spacePassword"]?.toString() ?: ""

// the test generation module for interacting with Grazie (used when the space credentials are provided)
val grazieTestGenerationVersion = "1.0.5"

plugins {
// Java support
id("java")
Expand Down Expand Up @@ -64,7 +68,7 @@ if (spaceCredentialsProvided()) {

tasks.register("checkCredentials") {
configurations.detachedConfiguration(
dependencies.create("org.jetbrains.research:grazie-test-generation:1.0.1"),
dependencies.create("org.jetbrains.research:grazie-test-generation:$grazieTestGenerationVersion"),
).files()
}

Expand Down Expand Up @@ -105,6 +109,9 @@ dependencies {
implementation(files("lib/JUnitRunner.jar"))

implementation(project(":core"))
implementation(project(":langwrappers")) // Needed to use Psi related interfaces and load proper implementation
implementation(project(":kotlin")) // Needed to load the testspark-kotlin.xml
implementation(project(":java")) // Needed to load the testspark-java.xml
if (spaceCredentialsProvided()) {
"hasGrazieAccessCompileOnly"(project(":core"))
}
Expand Down Expand Up @@ -165,7 +172,7 @@ dependencies {
// Dependencies for hasGrazieAccess variant
"hasGrazieAccessImplementation"(kotlin("stdlib"))
"hasGrazieAccessImplementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
"hasGrazieAccessImplementation"("org.jetbrains.research:grazie-test-generation:1.0.4")
"hasGrazieAccessImplementation"("org.jetbrains.research:grazie-test-generation:$grazieTestGenerationVersion")
}
}

Expand Down Expand Up @@ -200,6 +207,7 @@ tasks {
dependsOn("copyJUnitRunnerLib")
dependsOn(":core:compileKotlin")
}

// Set the JVM compatibility versions
properties("javaVersion").let {
withType<JavaCompile> {
Expand Down Expand Up @@ -377,6 +385,14 @@ tasks.register<Copy>("copyJUnitRunnerLib") {
into(libDestDir)
}

/**
* Returns the original string if it is not null, or the default string if the original string is null.
*
* @param default the default string to return if the original string is null
* @return the original string if it is not null, or the default string if the original string is null
*/
fun String?.orDefault(default: String): String = this ?: default

/**
* This code sets up a Gradle task for running the plugin in headless mode
*
Expand All @@ -388,6 +404,7 @@ tasks.register<Copy>("copyJUnitRunnerLib") {
* @param token The token for using LLM.
* @param prompt a txt file containing the LLM's prompt template
* @param out The output directory for the project.
* @param enableCoverage flag to enable/disable coverage computation
*/
tasks.create<RunIdeTask>("headless") {
val root: String? by project
Expand All @@ -399,8 +416,9 @@ tasks.create<RunIdeTask>("headless") {
val token: String? by project
val prompt: String? by project
val out: String? by project
val enableCoverage: String? by project

args = listOfNotNull("testspark", root, file, cut, cp, junitv, llm, token, prompt, out)
args = listOfNotNull("testspark", root, file, cut, cp, junitv, llm, token, prompt, out, enableCoverage.orDefault("false"))

jvmArgs(
"-Xmx16G",
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(17)
jvmToolchain(rootProject.properties["jvmToolchainVersion"].toString().toInt())
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package org.jetbrains.research.testspark.core.data

data class ChatMessage(
val role: String,
open class ChatMessage protected constructor(
val role: ChatRole,
val content: String,
)
) {
enum class ChatRole {
User,
Assistant,
}
}

class ChatUserMessage(content: String) : ChatMessage(ChatRole.User, content)
class ChatAssistantMessage(content: String) : ChatMessage(ChatRole.Assistant, content)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.jetbrains.research.testspark.core.data

/**
* Enumeration representing different types of classes.
*
* @param representation The string representation of the class type.
*/
enum class ClassType(val representation: String) {
INTERFACE("interface"),
ABSTRACT_CLASS("abstract class"),
CLASS("class"),
DATA_CLASS("data class"),
INLINE_VALUE_CLASS("inline value class"),
OBJECT("object"),
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.jetbrains.research.testspark.core.generation.llm.network

import io.github.oshai.kotlinlogging.KotlinLogging
import org.jetbrains.research.testspark.core.data.ChatAssistantMessage
import org.jetbrains.research.testspark.core.data.ChatMessage
import org.jetbrains.research.testspark.core.data.ChatUserMessage
import org.jetbrains.research.testspark.core.monitor.DefaultErrorMonitor
import org.jetbrains.research.testspark.core.monitor.ErrorMonitor
import org.jetbrains.research.testspark.core.progress.CustomProgressIndicator
Expand Down Expand Up @@ -36,8 +38,7 @@ abstract class RequestManager(var token: String) {
errorMonitor: ErrorMonitor = DefaultErrorMonitor(), // The plugin for other IDEs can send LLM requests without passing an errorMonitor
): LLMResponse {
// save the prompt in chat history
// TODO: make role to be an enum class
chatHistory.add(ChatMessage("user", prompt))
chatHistory.add(ChatUserMessage(prompt))

// Send Request to LLM
log.info { "Sending Request..." }
Expand Down Expand Up @@ -67,9 +68,9 @@ abstract class RequestManager(var token: String) {
val response = testsAssembler.getContent()

log.info { "The full response: \n $response" }
chatHistory.add(ChatMessage("assistant", response))
chatHistory.add(ChatAssistantMessage(response))

// check if response is empty
// check if the response is empty
if (response.isEmpty() || response.isBlank()) {
return LLMResponse(ResponseErrorCode.EMPTY_LLM_RESPONSE, null)
}
Expand Down Expand Up @@ -98,7 +99,7 @@ abstract class RequestManager(var token: String) {

log.info { "The full response: \n $response" }

// check if response is empty
// check if the response is empty
if (response.isEmpty() || response.isBlank()) {
return LLMResponse(ResponseErrorCode.EMPTY_LLM_RESPONSE, null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jetbrains.research.testspark.core.generation.llm.prompt

import org.jetbrains.research.testspark.core.data.ClassType
import org.jetbrains.research.testspark.core.generation.llm.prompt.configuration.ClassRepresentation

internal class PromptBuilder(private var prompt: String) {
Expand Down Expand Up @@ -109,7 +110,15 @@ internal class PromptBuilder(private var prompt: String) {

polymorphismRelations.forEach { entry ->
for (currentSubClass in entry.value) {
fullText += "${currentSubClass.qualifiedName} is a sub-class of ${entry.key.qualifiedName}.\n"
val subClassTypeName = when (currentSubClass.classType) {
ClassType.INTERFACE -> "an interface implementing"
ClassType.ABSTRACT_CLASS -> "an abstract sub-class of"
ClassType.CLASS -> "a sub-class of"
ClassType.DATA_CLASS -> "a sub data class of"
ClassType.INLINE_VALUE_CLASS -> "a sub inline value class class of"
ClassType.OBJECT -> "a sub object of"
}
fullText += "${currentSubClass.qualifiedName} is $subClassTypeName ${entry.key.qualifiedName}.\n"
}
}
prompt = prompt.replace(keyword, fullText, ignoreCase = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PromptGenerator(
.insertTestSample(testSamplesCode)
.build()

println("Prompt: $prompt")
return prompt
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jetbrains.research.testspark.core.generation.llm.prompt.configuration

import org.jetbrains.research.testspark.core.data.ClassType

/**
* Represents the context for generating prompts for generating unit tests.
*
Expand Down Expand Up @@ -39,6 +41,7 @@ data class ClassRepresentation(
val qualifiedName: String,
val fullText: String,
val allMethods: List<MethodRepresentation>,
val classType: ClassType,
)

/**
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ platformVersion = 2024.1

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = com.intellij.java, org.jetbrains.kotlin
platformPlugins = com.intellij.java, org.jetbrains.kotlin, maven, gradle

# Java language level used to compile sources and to generate the files for - Java 17 is required since 2023.1
javaVersion = 17
Expand All @@ -31,3 +31,5 @@ gradleVersion = 8.2.1
# See https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library for details.
# suppress inspection "UnusedProperty"
kotlin.stdlib.default.dependency = false

jvmToolchainVersion = 17
34 changes: 34 additions & 0 deletions java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
kotlin("jvm")
id("org.jetbrains.intellij")
}

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))

implementation(project(":langwrappers")) // Interfaces that cover language-specific logic
implementation(project(":core"))
}

intellij {
rootProject.properties["platformVersion"]?.let { version.set(it.toString()) }
plugins.set(listOf("java"))
}

tasks.named("verifyPlugin") { enabled = false }
tasks.named("runIde") { enabled = false }
tasks.named("runPluginVerifier") { enabled = false }

tasks {
buildSearchableOptions {
enabled = false
}
}

kotlin {
jvmToolchain(rootProject.properties["jvmToolchainVersion"].toString().toInt())
}
Loading

0 comments on commit c91275f

Please sign in to comment.