-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for the chat (context files) (#1930)
This is a follow up PR for #1928. ## Test plan 1. Green CI
- Loading branch information
1 parent
1897c8b
commit b4672ed
Showing
17 changed files
with
2,649 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
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(DocumentCodeTest::class) class AllSuites | ||
@RunWith(RepeatableSuite::class) | ||
@Suite.SuiteClasses(ChatTest::class, DocumentCodeTest::class) | ||
class AllSuites |
102 changes: 102 additions & 0 deletions
102
src/integrationTest/kotlin/com/sourcegraph/cody/chat/ChatTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.sourcegraph.cody.chat | ||
|
||
import com.intellij.testFramework.runInEdtAndGet | ||
import com.intellij.testFramework.runInEdtAndWait | ||
import com.sourcegraph.cody.chat.ui.ContextFileActionLink | ||
import com.sourcegraph.cody.context.ui.EnterpriseEnhancedContextPanel | ||
import com.sourcegraph.cody.history.HistoryService | ||
import com.sourcegraph.cody.history.state.EnhancedContextState | ||
import com.sourcegraph.cody.history.state.RemoteRepositoryState | ||
import com.sourcegraph.cody.util.CodyIntegrationTestFixture | ||
import com.sourcegraph.cody.util.CustomJunitClassRunner | ||
import com.sourcegraph.cody.util.TestingCredentials | ||
import java.awt.Component | ||
import java.awt.Container | ||
import java.util.concurrent.TimeUnit | ||
import junit.framework.TestCase | ||
import org.awaitility.kotlin.await | ||
import org.awaitility.kotlin.until | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(CustomJunitClassRunner::class) | ||
class ChatTest : CodyIntegrationTestFixture() { | ||
override fun recordingName() = "chat" | ||
|
||
override fun credentials() = TestingCredentials.enterprise | ||
|
||
override fun checkSuiteSpecificInitialConditions() = Unit | ||
|
||
@Test | ||
fun testRemoteContextFileItems() { | ||
val enhancedContextState = | ||
EnhancedContextState().apply { | ||
remoteRepositories.add( | ||
RemoteRepositoryState().apply { | ||
isEnabled = true | ||
remoteUrl = "github.com/sourcegraph/cody" | ||
codebaseName = "github.com/sourcegraph/cody" | ||
}) | ||
} | ||
HistoryService.getInstance(project).updateDefaultContextState(enhancedContextState) | ||
|
||
val session = runInEdtAndGet { AgentChatSession.createNew(project) } | ||
|
||
await.atMost(30, TimeUnit.SECONDS) until | ||
{ | ||
(session.getPanel().contextView as EnterpriseEnhancedContextPanel) | ||
.controller | ||
.getConfiguredState() | ||
.find { it.name == "github.com/sourcegraph/cody" && !it.isIgnored } != null | ||
} | ||
|
||
runInEdtAndWait { session.sendMessage("What is JSON RPC?", emptyList()) } | ||
|
||
await.atMost(30, TimeUnit.SECONDS) until { !session.messages[0].contextFiles.isNullOrEmpty() } | ||
await.atMost(30, TimeUnit.SECONDS) until { session.messages.size == 2 } | ||
await.atMost(30, TimeUnit.SECONDS) until { session.messages[1].text?.isNotBlank() == true } | ||
|
||
val linkPanels = | ||
findComponentsRecursively(session.getPanel(), ContextFileActionLink::class.java) | ||
|
||
TestCase.assertEquals( | ||
listOf( | ||
"cody agent/CHANGELOG.md", | ||
"cody agent/README.md", | ||
"cody agent/src/__tests__/chat-response-quality/README.md", | ||
"cody agent/src/cli/command-jsonrpc-stdio.ts", | ||
"cody agent/src/cli/command-jsonrpc-websocket.ts", | ||
"cody agent/src/cli/command-root.ts", | ||
"cody agent/src/cli/scip-codegen/JvmCodegen.ts", | ||
"cody agent/src/cli/scip-codegen/JvmFormatter.ts", | ||
"cody agent/src/jsonrpc-alias.ts", | ||
"cody agent/src/local-e2e/README.md", | ||
"cody lib/icons/README.md", | ||
"cody vscode/src/graph/bfg/spawn-bfg.ts", | ||
"cody vscode/src/jsonrpc/bfg-protocol.ts", | ||
"cody vscode/src/jsonrpc/CodyJsonRpcErrorCode.ts", | ||
"cody vscode/src/jsonrpc/embeddings-protocol.ts", | ||
"cody vscode/src/jsonrpc/isRunningInsideAgent.ts", | ||
"cody vscode/src/jsonrpc/jsonrpc.ts", | ||
"cody vscode/src/jsonrpc/TextDocumentWithUri.test.ts", | ||
"cody vscode/src/jsonrpc/TextDocumentWithUri.ts", | ||
"cody web/lib/agent/agent.client.ts"), | ||
linkPanels.map { panel -> panel.text }) | ||
} | ||
|
||
private fun <A> findComponentsRecursively(parent: Component, targetClass: Class<A>): List<A> { | ||
val result = mutableListOf<A>() | ||
|
||
if (targetClass.isInstance(parent)) { | ||
result.add(parent as A) | ||
} | ||
|
||
if (parent is Container) { | ||
for (component in parent.components) { | ||
result.addAll(findComponentsRecursively(component, targetClass)) | ||
} | ||
} | ||
|
||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.