diff --git a/core/src/main/kotlin/org/jetbrains/research/testspark/core/generation/llm/LLMWithFeedbackCycle.kt b/core/src/main/kotlin/org/jetbrains/research/testspark/core/generation/llm/LLMWithFeedbackCycle.kt index 2aa764100..e12dbfbe2 100644 --- a/core/src/main/kotlin/org/jetbrains/research/testspark/core/generation/llm/LLMWithFeedbackCycle.kt +++ b/core/src/main/kotlin/org/jetbrains/research/testspark/core/generation/llm/LLMWithFeedbackCycle.kt @@ -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!!}" } @@ -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!!)}" } diff --git a/src/main/kotlin/org/jetbrains/research/testspark/tools/ToolUtils.kt b/src/main/kotlin/org/jetbrains/research/testspark/tools/ToolUtils.kt index 4d4aff983..226fff5ba 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/tools/ToolUtils.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/tools/ToolUtils.kt @@ -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 diff --git a/src/main/kotlin/org/jetbrains/research/testspark/tools/llm/generation/openai/OpenAIRequestManager.kt b/src/main/kotlin/org/jetbrains/research/testspark/tools/llm/generation/openai/OpenAIRequestManager.kt index 1d9d6a9a4..b71138a98 100644 --- a/src/main/kotlin/org/jetbrains/research/testspark/tools/llm/generation/openai/OpenAIRequestManager.kt +++ b/src/main/kotlin/org/jetbrains/research/testspark/tools/llm/generation/openai/OpenAIRequestManager.kt @@ -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 -> { @@ -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()