Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect state after indicator cancellation #346

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,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 @@ -222,6 +228,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 @@ -113,6 +113,9 @@ class Pipeline(
super.onFinished()
testGenerationController.finished()

// Process stopped checking
if (testGenerationController.errorMonitor.hasErrorOccurred()) return

updateEditor(uiContext!!.testGenerationOutput.fileUrl)

if (editor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ 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()) {
errorMonitor.notifyErrorOccurrence()
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
Loading