Skip to content

Commit

Permalink
Fix incorrect state after indicator cancellation (#346)
Browse files Browse the repository at this point in the history
* fix incorrect state after indicator cancellation

* publish: core module version `5.0.1`

The patch version changed due to fixes in the internal implementation of the `LLMWithFeedbackCycle.run` method.

---------

Co-authored-by: Vladislav Artiukhov <[email protected]>
  • Loading branch information
arksap2002 and Vladislav Artiukhov authored Oct 10, 2024
1 parent c1afd2b commit 4d61f12
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ publishing {
create<MavenPublication>("maven") {
groupId = group as String
artifactId = "testspark-core"
version = "5.0.0"
version = "5.0.1"
from(components["java"])

artifact(tasks["sourcesJar"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ class LLMWithFeedbackCycle(
errorMonitor,
)

// Process stopped checking
if (indicator.isCanceled()) {
executionResult = FeedbackCycleExecutionResult.CANCELED
break
}

when (response.errorCode) {
ResponseErrorCode.OK -> {
log.info { "Test suite generated successfully: ${response.testSuite!!}" }
Expand Down Expand Up @@ -264,6 +270,12 @@ class LLMWithFeedbackCycle(
// saving the compilable test cases
compilableTestCases.addAll(testCasesCompilationResult.compilableTestCases)

// Process stopped checking
if (indicator.isCanceled()) {
executionResult = FeedbackCycleExecutionResult.CANCELED
break
}

if (!testCasesCompilationResult.allTestCasesCompilable && !isLastIteration(requestsCount)) {
log.info { "Non-compilable test suite: \n${testsPresenter.representTestSuite(generatedTestSuite!!)}" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ object ToolUtils {
* @return true if the process has been stopped, false otherwise
*/
fun isProcessStopped(errorMonitor: ErrorMonitor, indicator: CustomProgressIndicator): Boolean {
return errorMonitor.hasErrorOccurred() || isProcessCanceled(indicator)
return errorMonitor.hasErrorOccurred() || isProcessCanceled(errorMonitor, indicator)
}

fun isProcessCanceled(indicator: CustomProgressIndicator): Boolean {
fun isProcessCanceled(errorMonitor: ErrorMonitor, indicator: CustomProgressIndicator): Boolean {
if (indicator.isCanceled()) {
// TODO: we must not stop this indicator! cancellation MAY imply stoppage
errorMonitor.notifyErrorOccurrence()
// TODO: we must not stop this indicator! cancellation MAY already imply stoppage
// See: https://github.com/JetBrains-Research/TestSpark/issues/375
indicator.stop()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class OpenAIRequestManager(project: Project) : IJRequestManager(project) {
// check response
when (val responseCode = connection.responseCode) {
HttpURLConnection.HTTP_OK -> {
assembleLlmResponse(request, testsAssembler, indicator)
assembleLlmResponse(request, testsAssembler, indicator, errorMonitor)
}

HttpURLConnection.HTTP_INTERNAL_ERROR -> {
Expand Down Expand Up @@ -115,9 +115,10 @@ class OpenAIRequestManager(project: Project) : IJRequestManager(project) {
httpRequest: HttpRequests.Request,
testsAssembler: TestsAssembler,
indicator: CustomProgressIndicator,
errorMonitor: ErrorMonitor,
) {
while (true) {
if (ToolUtils.isProcessCanceled(indicator)) return
if (ToolUtils.isProcessCanceled(errorMonitor, indicator)) return

var text = httpRequest.reader.readLine()

Expand Down

0 comments on commit 4d61f12

Please sign in to comment.