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

Migrate testing/test #2639

Closed
wants to merge 3 commits into from
Closed
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 @@ -20,7 +20,9 @@ import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.testFramework.runInEdtAndWait
import com.sourcegraph.cody.agent.CodyAgentService
import com.sourcegraph.cody.agent.protocol_generated.ProtocolAuthenticatedAuthStatus
import com.sourcegraph.cody.agent.protocol_generated.ProtocolCodeLens
import com.sourcegraph.cody.agent.protocol_generated.ProtocolUnauthenticatedAuthStatus
import com.sourcegraph.cody.auth.CodyAccount
import com.sourcegraph.cody.auth.SourcegraphServerPath
import com.sourcegraph.cody.edit.lenses.LensListener
Expand Down Expand Up @@ -59,9 +61,10 @@ open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener {

val recordingsFuture = CompletableFuture<Void>()
CodyAgentService.withAgent(project) { agent ->
val errors = agent.server.testingRequestErrors().get()
val errors = agent.server.testing_requestErrors(null).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 }
val missingRecordings =
errors.errors.filter { it.error?.contains("`recordIfMissing` is") == true }
missingRecordings.forEach { missing ->
logger.error(
"""Recording is missing: ${missing.error}
Expand Down Expand Up @@ -109,6 +112,8 @@ open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener {
}

private fun checkInitialConditions() {
isAuthenticated()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not matter.


With the check the tests fail with User is not authenticated assertion error.

Without it it fails with:

junit.framework.ComparisonFailure: Action description should be empty expected:<[]> but was:<[Log in to Sourcegraph to enable Cody features]>
	at junit.framework.Assert.assertEquals(Assert.java:100)
	at junit.framework.TestCase.assertEquals(TestCase.java:253)
	at com.sourcegraph.cody.util.CodyIntegrationTextFixture.checkInitialConditions(CodyIntegrationTextFixture.kt:140)


// If you don't specify this system property with this setting when running the tests,
// the tests will fail, because IntelliJ will run them from the EDT, which can't block.
// Setting this property invokes the tests from an executor pool thread, which lets us
Expand Down Expand Up @@ -137,6 +142,29 @@ open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener {
assertTrue("Action should be visible", presentation.isVisible)
}

private fun isAuthenticated() {
val authenticate = CompletableFuture<Boolean>()
CodyAgentService.withAgent(project) { agent ->
var retries = 10
var statusCompletable = agent.server.extensionConfiguration_status(null)

while (retries-- > 0 && !authenticate.isDone) {
when (statusCompletable.getNow(null)) {
is ProtocolAuthenticatedAuthStatus -> authenticate.complete(true)
is ProtocolUnauthenticatedAuthStatus ->
statusCompletable = agent.server.extensionConfiguration_status(null)
else -> {}
}

Thread.sleep(1000L)
}
}

assertTrue(
"User is not authenticated",
authenticate.completeOnTimeout(false, ASYNC_WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS).get())
}

private fun createEditorContext(editor: Editor): DataContext {
return (editor as? EditorEx)?.dataContext ?: DataContext.EMPTY_CONTEXT
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ data class TestingCredentials(
token = System.getenv("SRC_ENTERPRISE_ACCESS_TOKEN"),
redactedToken =
"REDACTED_b20717265e7ab1d132874d8ff0be053ab9c1dacccec8dce0bbba76888b6a0a69",
serverEndpoint = "https://demo.sourcegraph.com/")
serverEndpoint = "http://demo.sourcegraph.com/")
val s2 =
TestingCredentials(
token = System.getenv("SRC_S2_ACCESS_TOKEN"),
redactedToken =
"REDACTED_964f5256e709a8c5c151a63d8696d5c7ac81604d179405864d88ff48a9232364",
serverEndpoint = "https://sourcegraph.sourcegraph.com/")
serverEndpoint = "http://sourcegraph.sourcegraph.com/")
}
}
Loading
Loading