Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit bda3bbe

Browse files
author
Steve Yegge
committed
more progress on integration test
they still don't pass but they are getting closer
1 parent 540560d commit bda3bbe

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

src/integrationTest/kotlin/com/sourcegraph/cody/DocumentSynchronizationTest.kt

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.sourcegraph.cody
22

33
import com.intellij.openapi.command.WriteCommandAction
4+
import com.intellij.openapi.vfs.VirtualFile
45
import com.sourcegraph.cody.agent.CodyAgentService
56
import com.sourcegraph.cody.agent.protocol.GetDocumentsParams
67
import com.sourcegraph.cody.util.CodyIntegrationTestFixture
78
import org.junit.Test
9+
import java.util.concurrent.CompletableFuture
810

911
class DocumentSynchronizationTest : CodyIntegrationTestFixture() {
1012

@@ -16,59 +18,68 @@ class DocumentSynchronizationTest : CodyIntegrationTestFixture() {
1618
console.log(\"hello there@\")
1719
}
1820
"""
19-
.trimIndent()
20-
.removePrefix("\n")
21+
.trimIndent()
22+
.removePrefix("\n")
2123

2224
val expectedContent =
23-
"""
25+
"""
2426
class Foo {
2527
console.log(\"hello there!\")
2628
}
2729
"""
28-
.trimIndent()
29-
.removePrefix("\n")
30+
.trimIndent()
31+
.removePrefix("\n")
3032

3133
val tempFile = myFixture.createFile("tempFile.java", beforeContent)
32-
val myUri = tempFile.url
33-
myFixture.configureByText("tempFile.java", beforeContent)
34-
35-
insertBeforeText(beforeContent)
34+
configureFixtureWithFile(tempFile)
35+
setCaretAndSelection()
3636

37-
val document = myFixture.editor.document
38-
// Write our initial content to the Editor
39-
WriteCommandAction.runWriteCommandAction(project) { document.setText(beforeContent) }
37+
val editor = myFixture.editor // Will not be set until we configure the fixture above.
38+
val document = editor.document
4039

41-
// Perform our editing action.
4240
WriteCommandAction.runWriteCommandAction(project) {
43-
val offset = document.text.indexOf('@')
44-
document.replaceString(offset, offset + 1, "!")
41+
// This is the test-specific editing operation to test.
42+
// TODO: Move everything else here except before/after text, into the test fixture.
43+
document.insertString(editor.caretModel.offset, "!")
4544
}
4645

47-
// Ensure that the Editor's after-text matches expected
46+
// Make sure our own copy of the document was edited properly.
4847
assertEquals(expectedContent, document.text)
4948

49+
checkAgentResults(tempFile, expectedContent)
50+
}
51+
52+
private fun checkAgentResults(tempFile: VirtualFile, expectedContent: String) {
53+
// Verify that Agent has the correct content, caret, and optionally, selection.
54+
val future = CompletableFuture<Void>()
5055
CodyAgentService.withAgent(project) { agent ->
51-
agent.server.awaitPendingPromises() // Wait for Agent to complete its computations.
56+
agent.server.awaitPendingPromises()
5257

5358
val result =
54-
agent.server.testingRequestWorkspaceDocuments(GetDocumentsParams(uris = listOf(myUri)))
59+
agent.server.testingRequestWorkspaceDocuments(
60+
GetDocumentsParams(uris = listOf(tempFile.url)))
5561

5662
result.thenAccept { response ->
5763
// There should be one document in the response.
5864
assertEquals(1, response.documents.size)
5965
// It should have our URI.
6066
val agentDocument = response.documents[0]
61-
assertEquals(myUri, agentDocument.uri)
67+
assertEquals(tempFile.url, agentDocument.uri)
6268

6369
// It should have the same content as the Editor's after-text.
6470
assertEquals(expectedContent, agentDocument.content)
71+
future.complete(null)
72+
}.exceptionally { ex ->
73+
future.completeExceptionally(ex)
74+
null
6575
}
6676
}
77+
future.get() // Wait for the CompletableFuture to complete
6778
}
6879

69-
private fun insertBeforeText(content: String) {
80+
private fun setCaretAndSelection() {
7081
WriteCommandAction.runWriteCommandAction(project) {
71-
var text = content
82+
var text = myFixture.editor.document.text
7283
var caretOffset = -1
7384
var selectionStart = -1
7485
var selectionEnd = -1

src/integrationTest/kotlin/com/sourcegraph/cody/util/CodyIntegrationTestFixture.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.intellij.openapi.editor.ex.EditorEx
1010
import com.intellij.openapi.fileEditor.FileDocumentManager
1111
import com.intellij.openapi.project.DumbService
1212
import com.intellij.openapi.project.Project
13+
import com.intellij.openapi.vfs.VirtualFile
1314
import com.intellij.testFramework.EditorTestUtil
1415
import com.intellij.testFramework.PlatformTestUtil
1516
import com.intellij.testFramework.fixtures.BasePlatformTestCase
@@ -22,13 +23,13 @@ import com.sourcegraph.cody.edit.CodyInlineEditActionNotifier
2223
import com.sourcegraph.cody.edit.FixupService
2324
import com.sourcegraph.cody.edit.sessions.FixupSession
2425
import com.sourcegraph.config.ConfigUtil
26+
import org.junit.runner.RunWith
27+
import org.junit.runners.JUnit4
2528
import java.io.File
2629
import java.nio.file.Paths
2730
import java.util.concurrent.CompletableFuture
2831
import java.util.concurrent.TimeUnit
2932
import java.util.regex.Pattern
30-
import org.junit.runner.RunWith
31-
import org.junit.runners.JUnit4
3233

3334
@RunWith(JUnit4::class)
3435
abstract class CodyIntegrationTestFixture : BasePlatformTestCase() {
@@ -91,6 +92,16 @@ abstract class CodyIntegrationTestFixture : BasePlatformTestCase() {
9192
initCaretPosition()
9293
}
9394

95+
protected fun configureFixtureWithFile(testFile: VirtualFile) {
96+
val policy = System.getProperty("idea.test.execution.policy")
97+
assertTrue(policy == "com.sourcegraph.cody.test.NonEdtIdeaTestExecutionPolicy")
98+
99+
myFixture.configureFromExistingVirtualFile(testFile)
100+
101+
initCredentialsAndAgent()
102+
initCaretPosition()
103+
}
104+
94105
override fun getTestDataPath(): String {
95106
if (project == null) {
96107
return super.getTestDataPath()

src/main/kotlin/com/sourcegraph/cody/agent/CodyAgent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import com.intellij.util.system.CpuArch
1212
import com.sourcegraph.cody.agent.protocol.*
1313
import com.sourcegraph.cody.vscode.CancellationToken
1414
import com.sourcegraph.config.ConfigUtil
15+
import org.eclipse.lsp4j.jsonrpc.Launcher
1516
import java.io.*
1617
import java.net.Socket
1718
import java.net.URI
1819
import java.nio.file.*
1920
import java.util.*
2021
import java.util.concurrent.*
21-
import org.eclipse.lsp4j.jsonrpc.Launcher
2222

2323
/**
2424
* Orchestrator for the Cody agent, which is a Node.js program that implements the prompt logic for
@@ -192,7 +192,7 @@ private constructor(
192192

193193
logger.info("starting Cody agent ${command.joinToString(" ")}")
194194
logger.info(
195-
"Cody agent proxyUrl ${proxyUrl} PROXY_TYPE_IS_SOCKS ${proxy.PROXY_TYPE_IS_SOCKS}")
195+
"Cody agent proxyUrl $proxyUrl PROXY_TYPE_IS_SOCKS ${proxy.PROXY_TYPE_IS_SOCKS}")
196196

197197
val process =
198198
processBuilder

0 commit comments

Comments
 (0)