Skip to content

Commit

Permalink
Revert "Add integration tests for the chat (context files)" (#2030)
Browse files Browse the repository at this point in the history
Reverts #1930

Changes not ready yet.

## Test plan 
- Green CI
  • Loading branch information
mkondratek authored Aug 10, 2024
1 parent b4672ed commit 53f24b0
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 2,649 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ fun Test.sharedIntegrationTestConfig(buildCodyDir: File, mode: String) {

environment(
"CODY_RECORDING_MODE" to mode,
"CODY_RECORDING_NAME" to "integration-test",
"CODY_RECORDING_DIRECTORY" to resourcesDir.resolve("recordings").absolutePath,
"CODY_SHIM_TESTING" to "true",
"CODY_TEMPERATURE_ZERO" to "true",
Expand Down
5 changes: 1 addition & 4 deletions src/integrationTest/kotlin/com/sourcegraph/cody/AllSuites.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.sourcegraph.cody

import com.sourcegraph.cody.chat.ChatTest
import com.sourcegraph.cody.edit.DocumentCodeTest
import com.sourcegraph.cody.util.RepeatableSuite
import org.junit.runner.RunWith
import org.junit.runners.Suite

@RunWith(RepeatableSuite::class)
@Suite.SuiteClasses(ChatTest::class, DocumentCodeTest::class)
class AllSuites
@RunWith(RepeatableSuite::class) @Suite.SuiteClasses(DocumentCodeTest::class) class AllSuites
102 changes: 0 additions & 102 deletions src/integrationTest/kotlin/com/sourcegraph/cody/chat/ChatTest.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.sourcegraph.cody.edit

import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
import com.sourcegraph.cody.edit.actions.DocumentCodeAction
import com.sourcegraph.cody.edit.actions.lenses.EditAcceptAction
import com.sourcegraph.cody.edit.actions.lenses.EditCancelAction
Expand All @@ -15,35 +10,15 @@ import com.sourcegraph.cody.edit.widget.LensIcon
import com.sourcegraph.cody.edit.widget.LensLabel
import com.sourcegraph.cody.edit.widget.LensSpinner
import com.sourcegraph.cody.edit.widget.LensWidgetGroup
import com.sourcegraph.cody.util.CodyIntegrationTestFixture
import com.sourcegraph.cody.util.CodyIntegrationTextFixture
import com.sourcegraph.cody.util.CustomJunitClassRunner
import com.sourcegraph.cody.util.TestingCredentials
import org.hamcrest.Matchers.startsWith
import org.junit.Assert.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(CustomJunitClassRunner::class)
class DocumentCodeTest : CodyIntegrationTestFixture() {
override fun recordingName() = "documentCode"

override fun credentials() = TestingCredentials.dotcom

override fun checkSuiteSpecificInitialConditions() {
// Check the initial state of the action's presentation
val action = ActionManager.getInstance().getAction("cody.documentCodeAction")
val event =
AnActionEvent.createFromAnAction(action, null, "", createEditorContext(myFixture.editor))
action.update(event)
val presentation = event.presentation
assertTrue("Action should be enabled", presentation.isEnabled)
assertTrue("Action should be visible", presentation.isVisible)
}

private fun createEditorContext(editor: Editor): DataContext {
return (editor as? EditorEx)?.dataContext ?: DataContext.EMPTY_CONTEXT
}

class DocumentCodeTest : CodyIntegrationTextFixture() {
@Test
fun testGetsWorkingGroupLens() {
val codeLensGroup = runAndWaitForLenses(DocumentCodeAction.ID, EditCancelAction.ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.sourcegraph.cody.util

import com.intellij.ide.lightEdit.LightEdit
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.DumbService
import com.intellij.openapi.project.Project
Expand All @@ -26,8 +31,8 @@ import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import junit.framework.TestCase

abstract class CodyIntegrationTestFixture : BasePlatformTestCase(), LensListener {
private val logger = Logger.getInstance(CodyIntegrationTestFixture::class.java)
open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener {
private val logger = Logger.getInstance(CodyIntegrationTextFixture::class.java)
private val lensSubscribers =
mutableListOf<
Pair<(List<ProtocolCodeLens>) -> Boolean, CompletableFuture<LensWidgetGroup?>>>()
Expand Down Expand Up @@ -56,7 +61,23 @@ abstract class CodyIntegrationTestFixture : BasePlatformTestCase(), LensListener

val recordingsFuture = CompletableFuture<Void>()
CodyAgentService.withAgent(project) { agent ->
agent.server.testing_requestErrors(params = null).get()
val errors = agent.server.testingRequestErrors().get()
// We extract polly.js errors to notify users about the missing recordings, if any
val missingRecordings = errors.filter { it.error?.contains("`recordIfMissing` is") == true }
missingRecordings.forEach { missing ->
logger.error(
"""Recording is missing: ${missing.error}
|
|${missing.body}
|
|------------------------------------------------------------------------------------------
|To fix this problem please run `./gradlew :recordingIntegrationTest`.
|You need to export access tokens first, using script from the `sourcegraph/cody` repository:
|`agent/scripts/export-cody-http-recording-tokens.sh`
|------------------------------------------------------------------------------------------
"""
.trimMargin())
}
recordingsFuture.complete(null)
}
recordingsFuture.get(ASYNC_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
Expand All @@ -74,26 +95,22 @@ abstract class CodyIntegrationTestFixture : BasePlatformTestCase(), LensListener
// Methods there are mostly idempotent though, so calling again for every test case should not
// change anything.
private fun initCredentialsAndAgent() {
assertNotNull(
"Unable to start agent in a timely fashion!",
CodyAgentService.getInstance(project)
.startAgent(project, additionalEnvs = mapOf("CODY_RECORDING_NAME" to recordingName()))
.completeOnTimeout(null, ASYNC_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.get())

val credentials = credentials()
val credentials = TestingCredentials.dotcom
CodyPersistentAccountsHost(project)
.addAccount(
SourcegraphServerPath.from(credentials.serverEndpoint, ""),
login = "test_user",
displayName = "Test User",
token = credentials.token ?: credentials.redactedToken,
id = "random-unique-testing-id-1337")
}

abstract fun recordingName(): String

abstract fun credentials(): TestingCredentials
assertNotNull(
"Unable to start agent in a timely fashion!",
CodyAgentService.getInstance(project)
.startAgent(project)
.completeOnTimeout(null, ASYNC_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.get())
}

private fun checkInitialConditions() {
// If you don't specify this system property with this setting when running the tests,
Expand All @@ -113,10 +130,19 @@ abstract class CodyIntegrationTestFixture : BasePlatformTestCase(), LensListener
val isLightEditMode = LightEdit.owns(project)
assertFalse("Project should not be in LightEdit mode", isLightEditMode)

checkSuiteSpecificInitialConditions()
// Check the initial state of the action's presentation
val action = ActionManager.getInstance().getAction("cody.documentCodeAction")
val event =
AnActionEvent.createFromAnAction(action, null, "", createEditorContext(myFixture.editor))
action.update(event)
val presentation = event.presentation
assertTrue("Action should be enabled", presentation.isEnabled)
assertTrue("Action should be visible", presentation.isVisible)
}

abstract fun checkSuiteSpecificInitialConditions()
private fun createEditorContext(editor: Editor): DataContext {
return (editor as? EditorEx)?.dataContext ?: DataContext.EMPTY_CONTEXT
}

// This provides a crude mechanism for specifying the caret position in the test file.
private fun initCaretPosition() {
Expand Down
Loading

0 comments on commit 53f24b0

Please sign in to comment.